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