Top
Interstage Studio User's Guide
FUJITSU Software

D.2.2 Creating an Enterprise Bean

Generating Enterprise Beans

To add or generate EJB2.1-compliant enterprise beans, use the Enterprise Bean wizard.

The Enterprise Bean wizard can create the following enterprise beans.

Note

Create an Enterprise Bean in a single source folder.
Since deployment descriptor files are stored in the source folder, if an Enterprise Bean is created in multiple source folders in one project, multiple deployment descriptors are created. When archiving in JAR format under these circumstances, the existence of files with the same name causes an error.

From the [New] wizard, select [EJB] > [J2EE] > [Enterprise Bean]. After the wizard creates the Enterprise Bean, edit the generated Java source, deployment descriptor, and so on.
In the Enterprise Bean wizard, specify basic information on Enterprise Bean generation and the Enterprise Bean type.

Creating Stateless Session Bean

A session bean is the Enterprise Bean to perform a dialogue with client. Write the process (Business logic), which becomes necessary mainly in business process.

Stateless Session Bean does not retain transaction state and the value of the variable defined in Enterprise Bean over multiple methods. Therefore, use when function in one method is provided. Moreover two or more clients can share the instance of same session bean, this reduces the load of the server.

Specify information in the Enterprise Bean wizard as follows:

  1. Specify Basic Information of Enterprise Bean.
    Enter package name, class name.

  2. Specify Session Bean Option.
    Specify the transaction type.

  3. Specify ejbCreate Method Definition.
    Define the method for initializing Enterprise Bean.
    The ejbCreate method for Stateless Session Bean is defined as an initial value. It is necessary to edit an initial value only to perform processing which adds the exception thrown by the ejbCreate method.

  4. Specify Business Method Definition.
    Add a business method. In Stateless Session Bean, it is necessary to create a method in the unit, which completes processing.

Creating Stateful Session Bean

A session Bean is the Enterprise Bean to perform a dialogue with client. Write the process (Business logic), which becomes necessary mainly in business process.

A stateful session bean corresponds to a client in a one-to-one relationship and can retain a transaction state and a variable value defined in an Enterprise Bean over multiple methods called by the client. Therefore, this type of session bean is used when providing a function that requires multiple methods.

Specify information in the Enterprise Bean wizard as follows:

  1. Specify Basic Information of Enterprise Bean.
    Enter package name, class name.

  2. Specify Session Bean Option.
    Specify transaction type and if SessionSynchronization is to be implemented or not.

  3. Specify ejbCreate Method Definition.
    Define the method for initializing Enterprise Bean.
    ejbCreate method without argument is defined as initial value. Add, edit as per the requirement.

  4. Specify Business Method Definition.
    Add Business method.

Creating Bean-managed persistence Entity Bean

Entity Bean maps persistence data of the database in the Java object, and multiple clients can also access it.

Incase of Bean-managed persistence, the access processing to persistence data such as SQL sentence is described in the source of Entity Bean. Since data access processing is described directly, access control according to database classification can be performed.

In the Enterprise Bean wizard, you can generate a template of access process to database using JDBC.

Specify information in the Enterprise Bean wizard as follows:

  1. Specify Basic Information of Enterprise Bean.
    Enter package name, class name.

  2. Specify Entity Bean Option.
    Specify the information related to database access.

    • Reentrant
      Specifies whether to enable Entity Bean to be recursively called.

    • Generate database access process
      Incase of Bean-managed persistence, specify if the database access process template will be generated or not in the Enterprise Bean source.

    • Make the table name in the SQL sentence modifiable
      Incase of Bean-managed persistence, when database access process template generation is performed, generate a source while using the [TableName] value environment property. Specify incase there will be a change in the schema and the table environment.

    • Optimize the retrieval logic
      Entity search process searches two times in the template of database access process of Bean managed persistence based on normal EJB agreement because the timing of acquisition of primary key and acquisition of Persistence field differs at the time of search. Generate source by specifying this option, to acquire the primary key and persistence field information simultaneously to save in the memory.

    • Use record class for getting and setting data
      To get/set the persistence field data once, generate the method that has used the record class.

    • Data source name
      Specify the data source name used in persistence.

  3. Specify Persistence Field Definition.
    Defines the persistence field. You can add to the persistence field by referring to the database.

  4. Specify ejbCreate Method Definition.
    Define the method for inserting persistence data in the database.
    ejbCreate method which has persistence data field or record class in argument is defined as initial value. Add, edit as per the requirement.

  5. Specify Finder Method Definition.
    Define the method for searching persistence data.
    The ejbFindByPrimaryKey method for performing reference by the Primary Key class is defined as initial value. Add, edit as per the requirement.

  6. Specify Home Method Definition.
    This function can be used with EJB2.1. The method is defined for performing the processing independent of the instance of Entity bean. (For example, records count).

  7. Specify Business Method Definition.
    Add Business method.

Creating Container-managed persistence Entity Bean

Entity Bean maps the persistence data of the database in Java object, multiple clients can also access it.

In container managed persistence, this defines mapping process and search process with database as customize information, without the access process to persistence data in entity Bean source. Access process to persistence data is performed by container on the basis of customize information. Therefore it exceeds in priority to different database (data type).

CMP extension information file which is the customize information of the Interstage EJB can be generated in the Enterprise Bean wizard.

Specify information in the Enterprise Bean wizard as follows:

  1. Specify Basic Information of Enterprise Bean.
    Enter package name, class name.

  2. Specify Entity Bean Option.
    Specify the information related to database access.

    • Reentrant
      Specifies whether to enable Entity Bean to be recursively called.

    • Use record class for getting and setting data
      To get/set the persistence field data once, generate the method that has used the record class.

    • Data source name
      Specify the data source name used in persistence.

      Point

      The file to which the data source name is written varies depending on whether the application target runtime is a J2EE container or a Java EE container.

      • For J2EE: <fujitsu-cmp2x-mapping-definition>/ <datasource-name> in the FJCMP_XXX.xml

      • For Java EE: <sun-ejb-jar>/ <enterprise-beans>/ <cmp-resource>/ <jndi-name> in the sun-ejb-jar.xml

  3. Specify Persistence Field Definition.
    Define the persistence field. You can add to the persistence field referring to the database.

  4. Specify ejbCreate Method Definition.
    Define the method for inserting persistence data in the database.

  5. As an initial value, the ejbCreate method that has the persistence field or a record class in an argument is defined. Add, edit if required.

  6. Specify Finder Method Definition.
    Define the method for searching the persistence data.

  7. As an initial value, according to the primary key class, findByPrimaryKey is defined in the method. Add if required.

  8. Specify Home Method Definition.
    This function can be used with EJB2.1. Define the method for performing processing independent of the Entity Bean instance (e.g., record count). Add if required.

  9. Specify ejbSelect Method Definition.
    This function can be used with EJB2.1. Define the method for search processing performed within an Entity Bean method. Add if required.

  10. Specify Business Method Definition.
    Add Business method.

Point

The final deliverables from the CMP Entity Bean vary depending on whether they are for a J2EE container or a Java EE container, as shown below.

Option

JavaEE Container

J2EE Container

CMP extension information file

sun-cmp-mappings.xml

FJCMP_XXXX.xml

Database definition information

sun-ejb-jar.xml

FJCMP_XXXX.xml

Database table information

XXX.dbschema
(If "Use DB Schema" is selected when connecting to the database)

None

Creating Point-To-Point model Message-driven Bean

Message-driven Bean is an Enterprise Bean for carrying out unsynchronized communication process.

In Point-To-Point model Message-driven Bean, just a single receiver processes a message sent from a sender. This type of message-driven bean is used when a single receiver is assigned to a message.

Specify information in the Enterprise Bean wizard as follows:

  1. Specify Basic Information of Enterprise Bean.
    Enter package name, class name.

  2. Specify Message-driven Bean Option.
    Specify transaction type and message selector as per the requirement.

Creating Publish/Subscribe model Message-driven Bean

Message-driven Bean is an Enterprise Bean for carrying out unsynchronized communication process.

In Publish/Subscribe model Message-driven Bean, Multiple receivers process a message sent from a sender. This type of message-driven bean is used when a single message must be delivered to multiple receivers.

Specify information in the Enterprise Bean wizard as follows:

  1. Specify Basic Information of Enterprise Bean.
    Enter package name, class name.

  2. Specify Message-driven Bean Option.
    Specify transaction type, subscription durability and message selector as per the requirement.