Pramati Technologies

Creating Entity Beans with BMP 2.0

This chapter describes how to create entity beans with bean managed persistence using the Bean Wizard. Entity beans with bean managed persistence requires ejbHome, ejbFind, and business methods, all of which can be created using the Bean Wizard.

Start Bean wizard using Tools > Bean Wizard from the main menu. In the following sections, we will describe all the steps involved in creating BMP beans in the Expert mode.

Defining Beans

In the first panel that comes up, define the bean as follows:

Module Name All the EJB modules existing in the active Desk are displayed here. Choose one from the list available in the combo-box. The bean that is created is placed under the module chosen here.

Bean Type Select the bean type as Entity - Bean Managed. This field defines the type of bean to be created. The user can choose from a list of types available in the combo box.

Transaction Type Transactions are defined only for session beans and message driven beans. This field is therefore disabled when the user chooses Entity -Bean Managed as the bean type.

Use Database Check against this checkbox if you decide to use the existing tables available. To generate code when a table does not exist, un-check the checkbox. This checkbox is checked, by default.

Re-entrant This checkbox is enabled only for entity beans and by default is un-checked. The entity bean when specified as a non-reentrant, makes the container reject any attempt made by entity bean's component interface while the instance is executing a business method.

Bean Class Name The name of the bean class is entered in this field. If the bean is included under a package, the complete Java class name, including the package name, must be entered.

EJB Name The logical name assigned to each bean in the ejb-jar is entered here. This name is automatically added when the developer adds the bean class name. The developer, if required can modify the name.

JNDI Name Entering the bean class name automatically adds the JNDI name in this field. The developer, if required can modify the name. The JNDI Name locates the entity bean's home interface. This name is linked to the actual JNDI Name of the target enterprises' home interface during deployment.

The JNDI Name is named as [Bean Name_Module_Name_Desk Name], where Bean Name is the name of the bean, Module Name is the name of the bean and Desk_Name is the name of the Desk. Naming the JNDI Name with all these components makes it unique.

Expert Mode Beans in Studio can be created in two modes - Expert and Non-Expert. The Expert Mode guides the user through all the 9 steps of creating a bean. This is to be used by experienced developers, who want to create the bean with specific details.

The Non-Expert mode guides the user in 4 simple steps and creates the cmp 2.0 bean. This mode gives default values for the interfaces and also does not create methods like ejbSelect. The following are the panels, which appear in the Non-Expert mode of the Bean Wizard, after the initial step where the bean is defined.

  1. Define Container Managed Fields
  2. Define CREATE Methods
  3. Define FINDER Methods

Once all the fields have been filled in the panel described above, click Next. This takes the user to the next panel. The next panel can be either of the two panels given below:

In the following sections, the Expert Mode for creating BMP Beans has been discussed. For knowing how to create the Bean using the Non Expert mode, just un-check the option Expert Mode and read the specific panel headings.

Defining Bean Managed Fields

(with database)

If the option Use Database is checked in the Bean Definition panel, this is the next panel to come up. Enter the following information in this panel:

Resource Name Select from the existing data resource names available in the dropdown combo box. To create new resources, click on the New button.

URL The location of the driver is displayed here. This field cannot be edited.

Table Filter This field is used to filter and display the tables in the Tables field.

Example

To view all tables starting with the letters IS, type is* in this field and click "Get". This displays all the tables starting with IS in the Tables field.

To view all the existing tables in the database, type * in the Table Filter field.

Tables Select from one of the tables in the dropdown combo box. This displays all the columns in the table. Use hot keys to jump to the desired table name in the list.

BMP Fields Check the options under this field, which are to be persisted.

DB Field Name This field displays the database fields of the tables existing in the database. This field is not editable.

DB Field Type This field displays the database type of the fields. This field is not editable.

DB PK The database fields, which act as the primary key, have a yellow key as an icon. This field is not editable.

Bean Field Name This field displays the Bean names. The bean type declared in the database is then mapped on to Java types it is compatible with and the same appears in the drop-down list against each variable.

Bean Field Type Select from one of the Java types available in the dropdown combo box. The Java type specifies the type of the bean.

Bean PK Check the options for the bean, which act as the primary key. There can be more than one primary key here.

After filling in all the information required in this panel, click Next. This takes the developer to the next panel called Define Create Methods.

Defining Bean Managed Fields (without database)

If the option Use Database is un-checked in the Bean Definition panel, then this is the next panel to come up. This panel requires the developer to fill information about the database and its table (the table is created at a later point) to be used by the entity bean.

This information is used to fill the deployment information like OR-Mapping, Finder Queries automatically by the Express Development tool. Entering this information keeps the module (holding the bean) in a "ready-to-deploy" state.

Follow the given steps to define the table with its data types:

Table Name Enter the name of the table in this field.

Add Columns Once the name of the table is added, click on the + (plus symbol) button. This adds a column to the table.

DB Field Enter the name of the database field in this panel.

DB Type Select from the database types available in the dropdown combo box. The DB type defines the types of data that the column holds.

Bean Field Name Enter the bean name here.

Bean Field Type Select from one of the Java types available in the dropdown combo box.

Bean PK Check against the name of the bean which acts as the primary key. More than one column in the table can act as the primary key.

To add more columns in the table, click on + as many times. To delete columns that have been already defines, select it and click on -. After completing the table definition, click Next. This takes the developer to the next panel called Define Create Methods.

Creating Methods Page

This panel allows creation of ejbCreate Methods for the BMP entity beans. The ejbCreate methods are responsible for creating new database data and initializing the bean.

To create the ejbCreate methods using the Fields, do the following:

Fields in Bean Select the Bean managed fields from the list available in this section. These fields are those that are to be implemented by the EJB.

Fields for Create Method Click on the forward arrow icon. This moves the fields from the Fields in Bean section to this section. To move the fields from here back to the previous section, use the back arrow icon.

EJB Create Methods Click on + in the panel and the fields get added to the EJB Create Methods section. This creates the ejbCreate Method with the parameters as the fields from the Selected CMFs section.

This process can be repeated to define all the methods required. To delete the methods from the EJB Create Methods section, select the method and click on -. Clicking Next takes you to the next panel called Define Home Methods.

Defining Home Methods

This panel does not appear if the module selected is of the type EJB 1.1 or Java Module, because BMP 1.1 beans do not contain ejbHome Methods. When the module selected is of the type EJB 2.0, then this panel comes up and is used in creating the skeleton code for the EJB Home methods. These methods correspond to the home business methods specified in the bean's home interface. Each home method on the entity bean's remote home or local home interface should have the EJB Home method.

To create the skeleton EJB Home methods, follow the given steps:

Method Name Enter the name of the Home method that is to be created. The method name must have ejbHome as its prefix followed by the method name where the first character has been upper-cased.

Return Type Enter the return type of the method in this field. If the business method corresponds to a method of the entity bean's home and remote interface, then the return type value has to be the acceptable types for RMI-IIOP.

Parameters Enter the parameters with their respective Java types. Separate the parameters with commas.

Example

int ID, String Name

Exceptions Enter any arbitrary application specific exceptions here.

Use + to add the home method. This displays the method added in the Methods section of the panel. To remove any method that has been added, select the method in the Methods section and click on -.

After entering all the information required for the Home Methods Page, click on Next. This takes you to the next panel called Define Business Methods.

Defining Business Methods

Use this panel to create skeleton code for business methods of the bean.

Method Name Enter the business method name here. The name can be anything, but should not start with the word ejb. This avoids conflicts with the callback methods used by the EJB architecture.

Return Type Enter the return types of the business method in this field. If the business method corresponds to a method of the entity bean's remote interface, then the return type value has to be the acceptable types for RMI-IIOP.

Parameters Enter the parameters with their respective return types. Separate the parameters with commas. If the business method corresponds to a method of the entity bean's remote interface, then the argument type value has to be the acceptable types for RMI-IIOP.

Exceptions Enter the exceptions that the business method needs to throw in this field. The exception java.rmi. RemoteException cannot be used here.

Add the business method by clicking on +. This displays the method added in the Methods section of the panel. To remove any method that has been added, select the method in the Methods section and click on -.

After entering all the information required for the Business Methods Page, click on Next. This takes you to the next panel called Define Finder Methods.

Defining Finder Methods

Use this panel to define the skeleton code of finder methods for beans with bean managed persistence, and version 1.1 or 2.0. The finder methods created are always prefixed with ejbFind before the method name.

Key-in the following information to create the skeleton code for finder methods:

Method Name Enter the name of the Finder method that is to be created.

The wizard prefixes Find to the name of the finder method if the finder method name does not begin with the word Find.

Return Type Select from the two valid return types for finder methods - java.util.Collection and Local or Remote Interface.

Parameters Enter any valid parameters preceded by the Java type of the parameter.

Exceptions Enter the exceptions as any arbitrary application specific exceptions.

To add the finder method, click on +. To remove an already added finder method, click on -. Clicking Next takes you to the panel called Select Bean Interfaces.

Selecting Bean Interfaces

This panel assists in defining interfaces for the bean. The EJB name and the bean class are already selected for the bean and cannot be modified. These display the current bean's EJB Name and Bean Class name.

Beans with ejb-version 1.1 do not have local interfaces, while beans with ejb-version 2.0 can have both local and remote interfaces.

EJB Name This displays the EJB Name of the bean being crated. This field cannot be edited in this panel.

Bean Class This fields displays the class of the bean being created as a non-editable field.

Remote Interfaces A remote interface defines the business methods that are callable by remote clients. An entity bean's remote interface must extend the javax.ejb.EJBObject interface. Check this checkbox if the remote interfaces are to be created along with the bean.

Local Interfaces Local interfaces are defined only for beans with ejb-version 2.0. A local client can access an entity object through the entity bean's local interface. An entity bean's local interface must extend the javax.ejb.EJBLocalObject interface. A local interface defines the business methods that are callable by local clients. Check this checkbox if the local interfaces are to be created along with the bean.

After entering all the information required, click Next. This displays the next panel called Methods to publish in Home Interface(s).

Methods to publish in Interface(s) - Home and Local Home

This panel is used for placing methods in the home and local home interface of the bean. If the bean being created has an ejb-version of 1.1, only the Home Interface field is displayed. Check the options for the create, and finder methods that are to be placed in the home interface, nd click Next.

If the bean being created has an ejb-version of 2.0, both Home interface, and Local Home interface fields are displayed. Check the options for the create, home, and finder methods that are to be placed in the home and local home interfaces, and click Next.

Methods published in Remote, Local Interfaces

This panel displays all the get and set methods, and also the business methods that were defined earlier. Check the remote and local interfaces for those methods that are to be placed in the local interface. Clicking Finish generates the skeleton code of the bean, with its interfaces.

BMP 1.1 beans do not have local interfaces, and therefore the Local interface field does not appear for the 1.1 beans.

The setXXX() methods for the primary key fields is not displayed in this panel. This method is also not available for selection in the Interface Wizard.


Pramati Technologies  © Copyright   TOCPREVNEXTINDEX