Java Reference
In-Depth Information
14.3.1
Constructing the user information entity bean
The single entity bean—the user information
EJB
—will provide the persistence
mechanism for the user data. Remember from the problem description that this
EJB
counts the number of user logins and provides permissions for the user.
Every entity bean needs a primary key, which references the
EJB
's row in the data-
base. For the user information
EJB
, the primary key is a user name value.
The home interface
Listing 14.1 is the home interface for the entity bean. The home interface declares
methods for creating and locating this type of
EJB
. (Again, for more information
Listing 14.1
UserInfoHome.java
package jmxbook.ch14;
import javax.ejb.*;
import java.rmi.*;
import java.util.*;
public interface UserInfoHome extends EJBHome
{
public UserInfo create( String userName )
throws CreateException, RemoteException;
public UserInfo findByPrimaryKey( String userName )
throws FinderException, RemoteException;
}
The home interface provides a
create()
method for creating a new instance of
the
EJB
and a
findByPrimaryKey()
method for locating an existing instance.
Because the
EJB
's primary key is a user name, it is passed in to both the
create()
and
findByPrimaryKey()
methods.
The remote interface
Listing 14.2 shows the remote interface for the entity bean. The remote interface
declares the methods an
EJB
client uses to interact with an entity bean. The
EJB
create()
and
findByPrimaryKey()
methods of the home interface return an
instance of the
EJB
's remote interface. The remote interface declares the busi-
ness methods of the application.