Wednesday, February 22, 2006


Embedding Toplink Queries into Session EJB in JDeveloper 10.1.2 environment.




Suppose that JSP displaying Customer_WS_VIEW based on Toplink mapping

exactly as in [1] has been created.

Stop doing workshop [1] and switch to adding Session EJB to CustomerMaintenance

Workspace with intend to encapsulate into newly created OEFacade (SessionEJB) methods

performing queries against Customer_WS_VIEW based on Toplink API



1.Select CustomerMaintenance Workspace and right click on it.

In the New Gallery, select Empty Project in the Items list and click OK.

In the Create Project dialog, rename the project as BusinessServices and click OK.



Common > Input Paths > Default Package: oe.business

Common > Dependencies: ViewController.jpr ,Model.jpr

Common > Technology Scope



Select Enterprise JavaBeans in the Available Technologies and click the shuttle button

to move to Selected Technologies



Libraries:

Select TopLink in the Available Libraries and click the shuttle button to move to Selected Libraries



2.In the Applications Navigator, right-click the BusinessServices project and choose New from the context menu.

In the New Gallery, expand the Business Tier node in the Categories list and select Enterprise JavaBeans.

In the Items list, select EJB Diagram and click OK.

In the Create EJB Diagram dialog, set the following:



Name: OE EJB Diagram

Package: oe.business.uml



In the Component Palette, select Session Bean and click on the EJB Diagram surface.

(If the Component Palette is not visible, launch it by choosing

View | Component Palette from the menu.) Skip the Welcome page,

and in Step 1 of 4 of the Create Enterprise JavaBean Wizard,

select Enterprise JavaBeans 2.0 from the drop down list, then click Next.

In Step 2 of 4 of the wizard, rename the EJB as OEFacade, then click Next.

In Step 3 of 4 of the wizard, accept the defaults and click Next.In Step 4 of 4

of the wizard, select both check boxes to include both types of interfaces (local and remote),

click Next, and then click Finish on the summary page.



3. In the Model project, select CustomersWsView.java in the model

package and choose Tools | Implement Interface.... from the menu.



From the Available interface list select the java.io.Serializable class and click OK.

Click the Save All button to save your work.



4. In the EJB Diagram, double-click the OEFacade EJB to launch the EJB Module editor.

Select OEFacade : Methods in the left hand navigator

On the right hand side panel , choose Business Methods in Method category and click Add.

In the Business Method Details dialog, set the following method :





Name : getServerSession
Return type: oracle.toplink.threetier.Server
Select both :Expose through Local & Remote interfaces




Go to OEFacade Bean Class and add:-



public void setServerSession(Server serverSession)
{
//this.serverSession = serverSession;
ServerSession aSession = (ServerSession)SessionManager.getManager().getSession("ServerSession");
}

public Server getServerSession()
{
String tl_ddFileName =
"/META-INF/Model/toplink-deployment-descriptor.xml";
ClassLoader appClassLoader = Thread.currentThread().getContextClassLoader();
oracle.toplink.sessions.Project project = XMLProjectReader.read(tl_ddFileName,
appClassLoader);
DatabaseLogin loginInfo = project.getLogin();
loginInfo.getPlatform().getConversionManager().setLoader(appClassLoader);
oracle.toplink.threetier.Server server = project.createServerSession();
server.login();
return server;
}






In the EJB Diagram, double-click the OEFacade EJB to launch the EJB Module editor.

Select OEFacade : Methods in the left hand navigator

On the right hand side panel , choose Business Methods in Method category and click Add.

In the Business Method Details dialog, set the following method



Name: CustService
Return Type: java.util.Collection
Parameters: Integer custId
Select both :Expose through Local & Remote interfaces




Go to OEFacade Bean Class and add:-


public Collection CustService(Integer custId)
{
oracle.toplink.threetier.Server server = getServerSession();
Session tlsession = (Session) server.acquireClientSession();
tlsession.logMessages();
UnitOfWork uow = tlsession.acquireUnitOfWork();
Expression exp = new ExpressionBuilder().get("custId").equal(custId);
Vector customerswsview = tlsession.readAllObjects(CustomersWsView.class, exp);
return customerswsview;
}




In the EJB Diagram, double-click the OEFacade EJB to launch the EJB Module editor.

Select OEFacade : Methods in the left hand navigator

On the right hand side panel , choose Business Methods in Method category and click Add.

In the Business Method Details dialog, set the following method :



Name: CustLNService
Return Type: java.util.Collection
Parameters: String custNameLast
Select both :Expose through Local & Remote interfaces




Go to OEFacade Bean Class and add:-


public Collection CustLNService(String custNameLast)
{
oracle.toplink.threetier.Server server = getServerSession();
Session tlsession = (Session) server.acquireClientSession();
tlsession.logMessages();
UnitOfWork uow = tlsession.acquireUnitOfWork();
Expression exp = new ExpressionBuilder().get("custNameLast ").like(custNameLast);
Vector customerswsview = tlsession.readAllObjects(CustomersWsView.class, exp);
return customerswsview;
}




1. Create Data Control for Racing Façade EJB

2. Click on OEFacadeDataControl.xml and switch to Structure window.

3. Define java bean for nodes CustService and CustNLService as model.CustomersWsView.java



Data Controls should be fine now



Test method been added:-


Create new client OEFacadeClient.java.

Add to OEFacadeClient.java:



String custNameLast = new String(“%S%”);

Collection col = oEFacade.CustLNService(custNameLast);
Iterator it = col.iterator();
while (it.hasNext())
{
CustomersWsView customerswsview = (CustomersWsView)it.next();
System.out.println("Id: " + customerswsview. getCustId());
System.out.println("First Name: " + customerswsview. getCustNameFirst ());
System.out.println("Last Name: " + customerswsview. getCustNameLast ());
}

import java.util.Collection;
import java.util.Iterator;
import model.CustomersWsView;





References.

Building Oracle ADF Applications: Workshop

1.http://www.oracle.com/technology/obe/obe9051jdev/ide1012/adfworkshop/buildingadfapplicationsworkshop.htm