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



Wednesday, February 01, 2006


Deployment Presentation Services Project (OTN's Jdeveloper Tutorial Pages ) to remote OC4J instance on Linux Box (CentOS 4.1)



Project described in [1],[2] has been modified to work as standalone OC4J's
Web Application in UNIX/LINUX enviromment.

Modify file:

C:\JDEV10gR2\jdev\mywork\BusinessServices\TopLinkObjects\Project\toplink-mapping.mwp

to replace "localhost:1521:ORCL" with real connecting string to remote database .

For example : "ServerCentOS41:1523:rawdbase"

Then start Jdeveloper 10.1.2 and open project ToplinkObjects.jws

Just to be able to acquire database Server Session add view :-



create view TeamDriverID as
select a.id,a.constructorname,b.homeCountry,b.yrsExperience,b.name,b.salary
from team_order a,drivers b
where a.driver1_id=b.id
order by a.constructorname




to RACING schema.

Import View TeamDriverID as Toplink Java object to PersistenceServices.jpr

Regenerate Toplink-Deployment-Descriptor.

Create new session.xml and define data control for TeamDriverID.java though session.xml file.



Performing following step from [1] :-



Add a Method to Get a Server Session
1.In the EJB Diagram, double-click racingFacade EJB to launch the EJB Module editor.

2.Expand racingFacade in the left hand navigator and select Methods. On the right hand side panel,choose Business Methods in the Method category and click Add.

3.In the Business Method Details dialog set the following:
Name getServerSession
Return Type oracle.toplink.threetier.Server

// Deselect the check boxes for Expose through Remote Interface and Expose through Local Interface.




Do select the check boxes for Expose through Remote Interface and Expose through.Local Interface.




Click OK, then click OK in the EJB Module Editor.




4.Right-click racingFacade EJB in the Applications Navigator and choose Go To Bean Class from the context menu.

The section shown bellow (inside RacingFacadeBean.java file) should be modified as follows:-


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




Keep getServerSession() method exactly as advised in [1]:



public Server getServerSession()
{
String tl_ddFileName ="/META-INF/PersistenceServices/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;
}




Add the following import statements:

import oracle.toplink.sessions.DatabaseLogin;

import oracle.toplink.tools.workbench.XMLProjectReader;

Then run RacingFacadeClient1.Java.It will successfully acquire the Unit Of Work

and add the row to "team_order" table on remote database server.

Proceed with working on project as advised in [1],[2]


Create ejb1.deploy as EJB deployment profile for BusinessServices.jpr for standalone OC4J.

Create webapp1.deploy as WAR deployment profile for PresentationServices.jpr for standalone OC4J.

Create application1.deploy as EAR deployment profile for PresentationServices.jpr for standalone OC4J.

Application Assembly should include both ejb1.deploy,webapp1.deploy.

At this point project may be deployed to remote OC4J instance or OAS10gR2
(J2EE&WebCashe) on Linux Box and work with remote box hosting
Oracle 9i or 10g database on Linux,exactly as it works with local database on Windows.




Adding new Toplink Query against view TeamDriverID to RacingFacade EJB




1.In the PersistenceServices project, select Teamdriverid.java in the racing.objectmodel

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.



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

Select racingFacade > 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:



Name: TeamConsService

Return Type: java.util.Collection

Parameters: String constructorname



Select the checkboxes for Expose through Remote Interface and Expose

through Local Interface. Click OK, then click OK in the EJB Module editor.






3. Add to RacingFacadeBean.java Class :



public Collection TeamConsService(String constructorname)
{
oracle.toplink.threetier.Server server = getServerSession();
Session tlsession = (Session) server.acquireClientSession();
tlsession.logMessages();
UnitOfWork uow = tlsession.acquireUnitOfWork();
Expression exp = new ExpressionBuilder().get("constructorname").equal(constructorname);
Vector teamdriverid = tlsession.readAllObjects(Teamdriverid.class, exp);
return teamdriverid;
}





1. Recreate Data Control for Racing Facade EJB

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

3. Redefine java beans for nodes TeamDriverService ,TeamConsService,

GrandPrixResultsService in Structure window



Data Controls should be fine now



Create new client RacingFacadeClient3.java:

Add right bellow // RacingFacade.constructTeam( racing.objectmodel.Drivers driver ):

in RacingFacadeClient3.java



String constructorname = new String("TestTeam");
Collection col = RacingFacade.TeamConsService(constructorname);
Iterator it = col.iterator();
while (it.hasNext())
{
Teamdriverid teamdriverid = (Teamdriverid)it.next();
System.out.println("Id: " + teamdriverid.getId());
System.out.println("Name: " +teamdriverid.getName());
System.out.println("Constructorname:" +teamdriverid.getConstructorname());
}

import java.util.Collection;
import java.util.Iterator;
import racing.objectmodel.Teamdriverid;




Right click on RacingFacadeClient3.java and watch log window.





One more sample:-

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

Select racingFacade > 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:



Name: TeamCons2Service

Return Type: java.util.Collection

Parameters: String constructorname ,String name



Select the checkboxes for Expose through Remote Interface and Expose

through Local Interface. Click OK, then click OK in the EJB Module editor.

Add to RacinFacade bean Class



public Collection TeamCons2Service(String constructorname, String name)
{
oracle.toplink.threetier.Server server = getServerSession();
Session tlsession = (Session) server.acquireClientSession();
tlsession.logMessages();
UnitOfWork uow = tlsession.acquireUnitOfWork();
Expression exp1 = new ExpressionBuilder().get("constructorname").like(constructorname);
Expression exp2 = new ExpressionBuilder().get("name").like(name);
Vector teamdriverid = tlsession.readAllObjects(TeamdriverId.class, exp1.and(exp2));
return teamdriverid;
}




Create new client RacingFacadeClient.java

Add right bellow comment

// RacingFacade.constructTeam( racing.objectmodel.Drivers driver )


String constructorname = new String("%A%");
String name = new String("%Ralf%");
Collection col = RacingFacade.TeamCons2Service(constructorname,name);
Iterator it = col.iterator();
while (it.hasNext())
{
TeamdriverId teamdriverid = (TeamdriverId)it.next();
System.out.println("Id: " + teamdriverid.getId());
System.out.println("Name: " +teamdriverid.getName());
System.out.println("Constructorname:" +teamdriverid.getConstructorname());
}




In case of deployment to OAS 10.1.2 the URL for RMI Server

should contain port value 12401. It's important when looking up EJBs








References:

1.Create Business Services using Enterprise JavaBeans

http://www.oracle.com/technology/obe/obe_as_1012/j2ee/develop/business/businessservices_obe/businessservices.html

2.Create Presentation Services Using JSP pages, Struts and ADF Databinding

http://www.oracle.com/technology/obe/obe_as_1012/j2ee/develop/client/presentationservices_obe/presentationservices.htm