Java Reference
In-Depth Information
* @version: 1.0
*/
package java_database.MemberEBean;
import java.rmi.*;
import javax.ejb.*;
public interface Member extends EJBObject {
// accessors
public String getLastName() throws RemoteException;
public String getFirstName() throws RemoteException;
public int getMembershipYear() throws RemoteException;
// mutators
public void setLastName(String s) throws RemoteException;
public void setFirstName(String s) throws RemoteException;
public void setMembershipYear(int n) throws RemoteException;
}
Note that the
MemberEJB
is a simplified example intended to illustrate the fundamentals of EJB. For a
real-life entity bean, more business methods are defined in the remote interface. For example, the yacht
club may allow the members who leave the club and then rejoin to reinstate their seniority after they
have been members for more than three years recently. To implement this business logic, a business
method may be added as follows:
void reinstateMembershipYear(int formerYear) thorws YachtException
{
if (membershipYear < 3) {
throw new YachtException("Have not stayed 3 years this round!");
}
membershipYear =+ formerYear;
}
But then you have to add more logic to make sure the seniority is only reinstated once. The code must
prevent a member from reinstating his seniority multiple times.
The following requirements for the signature of an entity bean business method are the same as those
for session beans:
The method name must not conflict with a method name defined by the EJB architecture. For
example, you cannot call a business method
ejbCreate
or
ejbActivate
.
The methods must be public because clients call them.
The method modifier cannot be final or static.
The arguments and return types must be legal types for the Java RMI API. Typically, that means
the arguments and return types must either be Java datatypes or implement the
Serilizable
interface.
The
throws
clause must include
java.rmi.RemoteException
.
The
throws
clause may include the exceptions that you define for your application. The
reinstateMembershipYear
method, for example, throws
YachtException
. To indicate a system-
level problem, a business method should throw
EJBException
.