Working with Verastream Enterprise Java Beans

Enterprise Java Beans (EJBs) are used as the basic building blocks of software applications on the Java EE platform.

For each model and its procedures, Web Builder generates the following files in the <VHI install folder>\projects\<ProjectName>\ejb\src\<ProjectName> folder, along with their corresponding class files in the bld folder and JavaDocs in the javadoc folder:

 

The SessionBean is the actual EJB implementation. The application server deals with the SessionBean for you. You do not interact with it directly. Instead, your application performs a JNDI lookup to obtain the home interface. The home interface method create() returns a session EJB interface. These interfaces extend the business interface, which contains methods that represent the procedures in your project model. The remote interfaces provide the most flexibility and interoperability, but you may achieve better scalability using the local interfaces. Please refer to the generated JavaDocs for details.

Enterprise Java Beans Setup

Prior to using Verastream Enterprise Java Beans for a production application:

  1. Deploy the <VHI install folder>\projects\<projectname>\ejb\<packagename>-ejb.jar file to the application server, or incorporate the jar file into an enterprise application archive file (EAR).
  2. If necessary, deploy the Java EE connector (<VHI install folder>\lib\java\vhi-ra.rar) to the application server.
  3. Create a resource pool in the application server with the JNDI name eis\<projectname>, and set the pool configuration properties to specify the desired production VHI Session Server or domain, resource name (model or session), security, and so on (please refer to the Java EE Connector JavaDocs for configuration details).

Enterprise Java Beans Code Example

This example illustrates how to use Web Builder generated EJBs. The example uses a project named CICSAcctsDemo, which generates Java Beans for the CICSAcctsDemo model. The GetAccount procedure takes an account number as an input parameter and returns account information.

// Obtain the initial JNDI context
Context jndi = new InitialContext()

// Look up the EJB home interface
Object target = jndi.lookup("ejb/CICSAcctsDemoSessionBean");

// Convert it to the home interface type
CICSAcctsDemoSessionRemoteHome ejbRemoteHome =
    (CICSAcctsDemoSessionRemoteHome)PortableRemoteObject.narrow(target,
        CICSAcctsDemoSessionRemoteHome.class);

// Obtain the EJB session interface
CICSAcctsDemoSessionRemote session = ejbRemoteHome.create();



// Create a bean to hold the filter values
GetAccountFilters filters = new GetAccountFilters();

// Initialize the filters bean with the values you want to pass to the host
filters.setAcctNumber(new Integer (20000));

// Call the procedure on the session, passing in the filters
GetAccountRecordSet recordSet = session.getAccount(filters);

// Access the array of records and process through them

GetAccountRecord[] records = recordSet.getGetAccountRecords();
for (int i = 0; i < records.length; i++)
{
       System.out.println(records[i].getAcctNum());
       System.out.println(records[i].getLastName());
        //...
}