| Oracle8i Enterprise JavaBeans Developer's Guide and Reference Release 3 (8.1.7) Part Number A83725-01 |
|
To create an EJB, you must perform the following steps:
javax.ejb.EJBObject.
javax.ejb.EJBHome. In addition, it defines the create method for your bean.
javax.ejb.SessionBean or javax.ejb.EntityBean interfaces. For the differences between these types of beans, see "Definition of an Entity Bean".
ejbCreate method with parameters matching those of the create method defined of the home interface.
| Requirement | Description |
|---|---|
|
RMI conformance |
Because the You can get the RMI specifications from the JavaSoft site, http://www.javasoft.com. |
|
Naming conventions |
The interface names, method names, and constants defined within these interfaces cannot start with an underbar (_) or contain a dollar sign ($). In addition, the application and bean names can include the slash sign (/). |
The remote interface of a bean provides an interface for the methods that the client will invoke. That is, the remote interface defines the methods that you implement for remote access.
javax.ejb.EJBObject interface, which has the following definition:
public interface javax.ejb.EJBObject extends java.rmi.Remote {
public abstract EJBHome getEJBHome()
throws java.rmi.RemoteException // returns reference to home
// interface for this bean
public abstract Handle getHandle()
throws java.rmi.RemoteException // returns serializeable handle
public abstract Object getPrimaryKey()
throws java.rmi.RemoteException // returns key to an entity bean
public abstract boolean isIdentical(EJBObject obj)
throws java.rmi.RemoteException
public abstract void remove()
throws java.rmi.RemoteException, RemoveException //remove EJB object
}
You do not need to implement the methods in the EJBObject interface; these methods are implemented for you by the container.
| Function | Description |
|---|---|
| getEJBHome() |
Retrieves the object reference for the home interface |
| getHandle() |
A serializable Java representation of the EJB object reference can be obtained using the
You use the |
| getPrimaryKey() |
The |
| isIdentical() |
Tests that the object calling this method and the object in the argument are identical (as far as the container is concerned). This identifies that both objects are the same for all purposes. |
| remove() |
Deactivates the EJB bean. This, in turn, destroys the session bean instance (if stateful). |
The following code sample shows a remote interface called Employee, which declares the getEmployee method, which will be implemented in the bean.
package employee; import employee.EmpRecord; import javax.ejb.EJBObject; import java.rmi.RemoteException; public interfaceEmployeeextends EJBObject { public EmpRecordgetEmployee(int empNumber) throws java.sql.SQLException, EmpException, RemoteException; }
The home interface should define the appropriate create method for your bean. The home interface specifies one or more create methods. For each create method, a corresponding ejbCreate method must be defined in the remote interface. All of the create methods return the bean type; all of the ejbCreate methods return void.
The client invokes the create method declared within the home interface. The container turns around and calls the ejbCreate method, with the appropriate parameter signature, within your bean implementation. The parameter arguments can be used to initialize the state of a new EJB object.
javax.ejb.EJBHome interface which has the following definition:
public interface javax.ejb.EJBHome extends java.rmi.Remote { public abstract EJBMetaData getEJBMetaData(); public abstract void remove(Handle handle); public abstract void remove(Object primaryKey);
}
The methods in the EJBHome interface are implemented by the container. A client can remove an EJB object using the remove methods defined in either of its home or remote interfaces.
javax.ejb.EJBMetaData interface or remove the bean instance, given a handle.
create methods must throw the following exceptions:
The following code sample shows a home interface called EmployeeHome. The create method contains no arguments.
package employee;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface EmployeeHome extends EJBHome {
public Employee create()
throws CreateException, RemoteException;
}
Some methods in the Employee class can throw the EmpException exception. For an exception to be transported from the object to the client, you need to define a class for the exception.
The following code defines an exception class and is found in EmpException.java.
package employee; public class EmpException extends RemoteException { public EmpException(String msg) { super(msg); } }
|
|
![]() Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|