By Brett McLaughlin
Price: $39.95 USD
£28.50 GBP
Cover | Table of Contents | Colophon
http://java.sun.com/j2ee. I also highly
recommend that you download the J2EE SDK (essentially
the reference implementation), which can be used for running the
example code.
OFFICES table from last
chapter? The table structure is shown again in Figure 4-1 for reference.
USERS table. For the time being,
it's enough to know that this office structure is as
simple as it gets. You need to store the ID (an
int), the city (a String), and
the state (another String).
DOCTYPE
declaration refers to a Sun file, ensuring that no vendors add their
own tags or extensions to the descriptor. If your server requires you
to use a different DTD, you may have a serious problem on your hands;
you may want to consider switching to a standards-based application
server immediately. And if DTDs, elements, tags, and these other XML
terms are Greek to you, pick up Java and XML(O'Reilly), by yours truly, to get
answers to your XML-related questions.
OfficeBean class. We also
give the bean a name to be used, OfficeBean.
assembly-descriptor
element and related subelements that allow permission specification
for beans and their methods. That's so you can focus
on the bean right now, and deal with security later.
Don't worry, though; I'll get to
all of this before we're done with our application.
Leaving it out for now will allow the container to generate default
permissions.
OfficeHome interface, which has a create(
) method that looks like this:
public Office create(Integer id, String city, String state)
throws CreateException, RemoteException;
ejbCreate(
)
method that directly interfaces with the database. This logic varies
from selecting a random number to obtaining the next number from a
database sequence (particularly common in Oracle databases) or
retrieving the highest value in use and adding 1. There are so many
different problems with this approach, though, that it should
immediately be thrown out as an option in your bean programming. The
first and most important problem is that this method is not
vendor-neutral or database-neutral, and leaves your code working only
on the specific setup you are using. Additionally, going to the
database for a sequence value or the highest existing value results
in additional JDBC calls, slowing the entire application. And the
logic of picking a random or semi-random number is unreliable, at
best.
Object ref = context.lookup("java:comp/env/ejb/OfficeHome");
OfficeHome home = (OfficeHome)
PortableRemoteObject.narrow(ref, OfficeHome.class);
Office office = home.create("Dallas", "TX");
String city = office.getCity( ); String state = office.getState( );
String sku = product.getSKU( ); String name = product.getName( ); String description = product.getDescription( ); float price = product.getPrice( ); // etc...