Java Reference
In-Depth Information
Notice also that the calcMonthlyPayment() method does not take an interest rate as a parame-
ter. This is because the interest rate will be used to illustrate how values can be deployed in a
specific bean's environment and made available to the bean at any time. This will also give you
some understanding of how an EJB system can be configured upon deployment without any
code changes.
Home Interface
The home interface for an EJB defines lifecycle methods. In the case of a session bean the
important lifecycle events are creation and removal. The only thing that you need to worry
about as a bean designer is the creation of session beans. The remove method and functionality
are contained within the base interface.
The home interface for a session bean has slightly more stipulations associated with it than the
remote interface. It must extend javax.ejb.EJBHome . All of the RMI/IIOP regulations that
were in place for the remote interface are also present for the home interface; it is an interface
to a remote object.
The other rules apply specifically to the name and prototypes of the methods contained within
the home interface. The first stipulation on the methods is that there must be one or more cre-
ation methods. Each of these methods must be named create() . They must also include
javax.ejb.CreateException , as well as the RemoteException specified by the RMI/IIOP
rules. Once again there is no rule that limits any other exceptions from being present in the
throws clause.
Each create() method must return the specific remote interface type for that bean. This allows
the client access to the business logic after it has retrieved the home interface and created an
instance of the bean. For example the create() methods for the CalculateLoanHome interface
will return the CalculateLoan interface.
These create() methods provide the first difference you will see between stateless and stateful
session beans. In almost all cases, a stateless session bean will contain only one create()
method that takes no parameters. The reason for this is that any parameters passed to the
create() method would be client-specific information that would need to be stored in the bean
after the creation until the next method invocation. This is a conversational state that the state-
less session bean cannot maintain.
The CalculateLoan bean in Listing 12.2 shows only one create() method because it is being
defined as a stateless session bean.
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import java.rmi.RemoteException;
Search WWH ::

Custom Search