Oracle8i Enterprise JavaBeans and CORBA Developer's Guide Release 8.1.5 A64683-01 |
|
The EJB deployment process consists of the following steps:
deployejb
tool, which
The enterprise bean deployer supplies a deployment descriptor for each EJB in the application.
To make it simpler to compose the deployment descriptor, there is a text form of the descriptor, which is described in this section. You can also use the Oracle8i JServer ejbdescriptor
command-line tool to convert a text form deployment descriptor to the serialized class, or to convert back from the serialized object to a text file. The ejbdescriptor
is documented in "ejbdescriptor".
The text form of the session bean descriptor follows the conventions of Java code-- the descriptor has the syntax of a Java class. It always begins with a SessionBean
keyword, which is followed by the fully-qualified class name of the bean. The body of the declaration contains a list of descriptor attributes and their values. For example:
SessionBean ejb.test.server.ExampleBeanImpl { <attribute>=<value> ... }
In this example, ejb.test.server
is the name of the package that contains the implementation of the bean class ExampleBean
.
There are three different kinds of bean attributes:
Note that the transaction and security properties can apply to the bean as a whole, or can be specified on a method-by-method basis.
The attributes of a session bean descriptor correspond to the attributes of the class javax.ejb.deployment.SessionDescriptor
and its super class javax.ejb.deployment.DeploymentDescriptor.
Table 2-2 lists the attributes that can be used in the deployment descriptor.
Attribute Name |
Values |
Required? |
---|---|---|
BeanHomeName |
A Java String that represents the published name of the bean. |
|
HomeInterfaceClassName |
The fully-qualified name of the bean home interface class. |
|
RemoteInterfaceClassName |
The fully-qualified name of the bean remote interface class. |
|
Reentrant |
The literal "true" or "false". For entity beans. |
|
SessionTimeout |
In seconds from the time that the last bean client disconnects. The default value is 0, which means that the session terminates when the last connection has terminated. |
|
StateManagementType |
STATEFUL_SESSION |
|
TransactionAttribute |
TX_BEAN_MANAGED |
|
IsolationLevel |
TRANSACTION_READ_COMMITTED | |
|
RunAsMode |
CLIENT_IDENTITY | |
|
RunAsIdentity |
A username in the database. Cannot be a role. |
|
AllowedIdentities |
A list of usernames or roles in the database, enclosed in braces. Example: {SCOTT, WENDY, OTTO}. |
The example below shows a more complete deployment descriptor than in the example earlier in this chapter:
SessionBean ejb.test.server.DatabaseWorkImpl { BeanHomeName = "test/dbwork"; // this is the published name of the bean RemoteInterfaceClassName = ejb.test.DatabaseWork; HomeInterfaceClassName = ejb.test.DatabaseWorkHome; AllowedIdentities = {SCOTT}; SessionTimeout = 30; // in seconds StateManagementType = STATEFUL_SESSION; RunAsMode = CLIENT_IDENTITY; TransactionAttribute = TX_REQUIRES_NEW; // Add any environment properties that the bean requires EnvironmentProperties { prop1 = value1; prop2 = "value two"; } public ejb.test.EmpRecord getEmployee(int e) throws TestException{ RunAsMode = CLIENT_IDENTITY; AllowedIdentities = { SCOTT }; } public void update(int e, double s) throws TestException{ RunAsMode = SPECIFIED_IDENTITY; AllowedIdentities = { OTTO }; } }
The deployejb
command-line tool creates a JAR file to use on the client side to access the bean.
One of the requirements that a bean provider must meet is to make the bean's home interface available for JNDI lookup, so that clients can find and activate the bean. In JServer, this is done by publishing the bean home interface in an Oracle8i database. The deployejb
command-line tool takes care of this you. It publishes the bean in the instance CosNaming namespace under the name that you specify in the BeanHomeName
attribute of the deployment descriptor.
Drop an EJB from the database by following these steps:
dropjava
tool to delete those classes from the database.
See Chapter 6, "Tools" for documentation of the dropjava
and session shell tools.
Enterprise JavaBeans are inherently transactional. In the normal, easiest-to-code cases, transaction support is handled for the bean by the EJB container. This way, you do not need to code explicit transaction methods in the bean, or call transaction services from the client.
EJBs have declarative transaction support. This means that the bean deployer can specify, in the deployment descriptor, the transaction attributes for a bean, or even for an individual method in a bean. For example, if the deployment descriptor for a bean declares that the bean has the transaction attribute TX_REQUIRES_NEW, then the bean container starts a transaction before each method call to the bean, and attempts to commit the transaction when the method ends.
The bean deployer declares the transaction handling characteristics of a bean in the deployment descriptor. This is specified in the transaction attribute, which has six possible values:
"Transaction Management for EJBs" describes the semantics of these attribute values.
The EJB deployment descriptor allows you to specify access control lists. Access control can be specified either on the entire bean, or on individual methods of the bean.
In the text form of the deployment descriptor, specify the AllowedIdentities
attribute with a list containing usernames, roles, or a mixture of the two. Only users or users with the roles specified in the AllowedIdentities
attribute can access the bean, or the methods that are restricted by the attribute. For example:
AllowedIdentities = {SCOTT}; // only SCOTT can access the bean AllowedIdentities = {PUBLIC}; // all users can access the bean public int Rmethod (int p1, double p2) throws TestException{ RunAsMode = CLIENT_IDENTITY; AllowedIdentities = { ROGERS }; // only ROGERS can invoke this method }
When you specify method access control, the method must be a public business method of the bean, or the ejbCreate()
method.
The transaction isolation level attribute is not supported in this release. On the basis of recent informal communication from Sun Microsystems, it is likely that this attribute will not be supported in future EJB specifications, as part of the EJB descriptor.
An EJB can optionally implement the session synchronization interface, to be notified by the container of the transactional state of the bean. Use this interface to save the bean state in the database at transaction boundaries. "session Synchronization" describes this interface.
The format used to package EJBs is defined by the EJB specification. The format is adaptable--you can use it to distribute a single EJB or to distribute a complete server-side application made up of tens or even hundreds of beans. This section describes the steps that the EJB developer and the EJB deployer take to compile, package, and deploy an EJB. Oracle8i supplies a deployment tool, deployejb
, that automatically performs most of the steps required to deploy an EJB. This tool is described in "deployejb". Deployejb deploys only one bean at a time.
To deploy an EJB, follow these four steps:
Use the standard client-side Java compiler to compile the bean source files. A bean typically consists of one or more Java source files, and might have associated resource files.
Oracle8i supports the Sun Java Developer's Kit version 1.1.6 compiler. You might be able to use another JCK-tested Java compiler to create EJBs to run in the Oracle8i server, but Oracle only supports JDK 1.1.6.
deployejb
.
deployejb
tool (see "deployejb")
to load and publish the JAR'd bean.