Search This Blog

Tuesday, September 12, 2006

How to Convert JDeveloper CMT Application to Sun Application Server

Create the EJB using the Jdeveloper , say based on the Emp table
from Scott schema.
Change the following methods , so that they throw the CreateException
For example ,
public Long ejbCreate() throws CreateException {
return null;
}
public Long ejbCreate(Long empno) throws CreateException {
setEmpno(empno);
return empno;
}
Create the JAR file and open the Sun Deploy tool ,
File -> Open and select the jar file created by the previous method.
here select Emp Entity object , here click on the General TAB
And Click on Sun Specific Settings , select the View as CMP DataBase
Create DataBase Mappings , and select the DataSource Vendor as Oracle and select OK.
Now Click on the Table Generation Settings and unselect Create Table and Drop Table check boxes.
Change the JNDI name to jdbc/OracleDS.
Now Click on Tools -> Deploy menu option , and select the
option return Client Jar in some directory. After this deploy the application.
This creates the file empClient.jar in the directory you have specified in the above step.
Create the file EmpClient.java file ,
package project2;
import java.util.Collection;
import java.util.Iterator;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
public class EmpClient {
public static void main(String [] args) {
try {
final Context context = getInitialContext();
final EmpHome empHome =
(EmpHome) PortableRemoteObject.narrow( context.lookup( "Emp" ), EmpHome.class );
Emp emp;
// Use one of the create() methods below to create a new instance
// emp = empHome.create( );
// emp = empHome.create( empno );
// Retrieve all instances using the findAll() method (CMP Entity beans only)
final Collection coll = empHome.findAll();
final Iterator iter = coll.iterator();
while ( iter.hasNext() ) {
emp = ( Emp ) iter.next();
System.out.println( "empno = " + emp.getEmpno() );
System.out.println( "ename = " + emp.getEname() );
System.out.println( "job = " + emp.getJob() );
System.out.println( "mgr = " + emp.getMgr() );
System.out.println( "hiredate = " + emp.getHiredate() );
System.out.println( "sal = " + emp.getSal() );
System.out.println( "comm = " + emp.getComm() );
System.out.println( "deptno = " + emp.getDeptno() );
System.out.println();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static Context getInitialContext() throws NamingException {
// Get InitialContext for Embedded OC4J
// The embedded server must be running for lookups to succeed.
return new InitialContext();
}
}

2. Create the file META-INF\application-client.xml



ConverterClient

ejb/Emp
Session
project2.EmpHome
project2.Emp



3. Create the file , META-INF\sun-application-client.xml






ejb/Emp
Emp



Compile the above file using the command ,
set classpath=c:\empClient.jar;.;c:\sun\AppServer14\lib\j2ee.jar;c:\sun\AppServer14\lib\appserv-rt.jar
javac -d *.java
Now run the file using the command ,
java project2.EmpClient

No comments: