Java Reference
In-Depth Information
The container manages the transaction context and client/server connection on
behalf of the client. The client does not need to be directly involved in details of the
transaction semantics, such as begin transaction, commit, or rollback. Instead, the
container creates a simplified client view of the EJB for the client, and the client can
access the EJB as if it were a simple remote object. If the client needs to, however, it
can adjust the default transaction behavior of the EJB.
What's more, the EJB specification requires that the EJB server container pro-
vides extensive supporting software. This includes database connection pooling
and transaction services. This code shouldn't have to be rewritten for every appli-
cation. Once it is right, it will be right for everybody. You don't have to reinvent the
wheel.
T HE I NTERFACES AND THE I MPLEMENTATION C LASS
Actually developing an EJB (of whatever type) requires that the developer code two
interfaces and the implementation class. You might expect some relationship to
exist between the interfaces and the class. There is a relationship, but it is not the
usual relationship between classes and interfaces. The implementation class does
not implement (in the Java sense) either of the two interfaces you have to code. You
will grow accustomed eventually to the somewhat nonstandard relationship be-
tween the interfaces and the class. Initially the relationship is confusing. Keep in
mind that the interfaces are for the client—the application that will be using the
EJB—and things will be clearer.
The first interface you need to code is the remote interface. Believe it or not,
this is what your implementation class will implement in reality, although it does
not need to implement the interface in the Java sense of the word. The remote in-
terface is intended for the client. It is a description of the business methods that are
accessible to the client once the EJB is created.
public interface MyEJBInterface extends EJBObject
{
public String getMyEJBValue() throws RemoteException;
}
The second interface you code is the home interface. The home interface is
what the client will use to create the reference to the EJB. In fact, the home inter-
face returns the remote interface but triggers in the EJB container the entire sup-
porting infrastructure required to create or instantiate the implementation class.
Search WWH ::




Custom Search