// POQueryBean.java package server; import pocommon.*; import java.sql.*; import java.util.*; import java.rmi.RemoteException; import java.io.Serializable; import javax.ejb.*; public class POQueryBean implements EntityBean { private transient EntityContext ctx; public String ponumber; public String status; public String getPONumber() throws RemoteException { return ponumber; } public void setPONumber(String number) throws RemoteException { this.ponumber = number; } public String getStatus() throws RemoteException { return status; } public void setStatus(String status) throws RemoteException { this.status = status; } public void setEntityContext(EntityContext ctx) { this.ctx = ctx; Properties props = ctx.getEnvironment(); } public void unsetEntityContext() { this.ctx = null; } public String ejbCreate(String number, String stat) throws CreateException, RemoteException { try { setPONumber(number); setStatus(stat); } catch (java.rmi.RemoteException e) { throw new CreateException(); } return null; } public String ejbFindByPrimaryKey(String pk) throws RemoteException, FinderException { return null; } public void ejbPostCreate(String number, String stat) throws CreateException { // get primarykey String pk = (String)ctx.getPrimaryKey(); } public void ejbLoad() { // You can get to the primary key String pk = (String)ctx.getPrimaryKey(); } public void ejbActivate() {} public void ejbPassivate() {} public void ejbRemove() {} public void ejbStore() {} } |
// POQueryHome.java package pocommon; import java.rmi.RemoteException; import javax.ejb.*; public interface POQueryHome extends EJBHome { public POQueryRemote findByPrimaryKey(String pk) throws RemoteException, FinderException; public POQueryRemote findByWhere(String whereString) throws RemoteException, FinderException; public java.util.Enumeration findAllPos(String whereString) throws RemoteException, FinderException; public POQueryRemote create(String number, String stat) throws RemoteException, CreateException; } |
// POQueryRemote.java package pocommon; import java.rmi.RemoteException; import javax.ejb.EJBObject; public interface POQueryRemote extends EJBObject { public String getPONumber() throws RemoteException; public String getStatus() throws RemoteException; public void setStatus(String stat) throws RemoteException; } |
// Client.java package client; import pocommon.*; import java.util.Hashtable; import java.util.Enumeration; import java.rmi.RemoteException; import javax.naming.InitialContext; import javax.naming.Context; import javax.naming.NamingException; import javax.ejb.RemoveException; import javax.ejb.CreateException; import javax.ejb.FinderException; import oracle.aurora.jndi.sess_iiop.ServiceCtx; public class Client { public static void main(String[] argv) { System.out.println("client is running"); try { if (argv.length != 4) { System.out.println("usage: Client user password GIOP_SERVICE ejbPubname"); System.exit(1); } String user = argv[0]; String password = argv[1]; String GIOP_SERVICE = argv[2]; String ejbPubname = argv[3]; Hashtable env = new Hashtable(); env.put(Context.URL_PKG_PREFIXES, "oracle.aurora.jndi"); env.put(Context.SECURITY_PRINCIPAL, user); env.put(Context.SECURITY_CREDENTIALS, password); env.put(Context.SECURITY_AUTHENTICATION, ServiceCtx.NON_SSL_LOGIN); Context ic = new InitialContext(env); POQueryHome ch = (POQueryHome) ic.lookup(GIOP_SERVICE + ejbPubname); Enumeration e = ch.findAllPos(""); while(e.hasMoreElements()) { POQueryRemote poquery = (POQueryRemote) e.nextElement(); System.out.println (" ponumber: " + poquery.getPONumber() + " Description: " + poquery.getStatus()); } } catch (RemoteException e) { System.out.println("RemoveException caught:" + e); e.printStackTrace(); } catch (NamingException e) { System.out.println("NamingException caught:" + e); e.printStackTrace(); } catch (FinderException e) { System.out.println("FinderException caught:" + e); e.printStackTrace(); } } } |
<?xml version="1.0"?> <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems Inc.//DTD Enterprise JavaBeans 1.1//EN" "ejb-jar.dtd"> <ejb-jar> <enterprise-beans> <entity> <description>**POQuery Bean**</description> <ejb-name>POQueryBean</ejb-name> <home>pocommon.POQueryHome</home> <remote>pocommon.POQueryRemote</remote> <ejb-class>server.POQueryBean</ejb-class> <persistence-type>Container</persistence-type> <prim-key-class>java.lang.String</prim-key-class> <reentrant>False</reentrant> <cmp-field><field-name>ponumber</field-name></cmp-field> <cmp-field><field-name>status</field-name></cmp-field> <primkey-field>ponumber</primkey-field> <resource-ref> <res-ref-name>DataSource</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Application</res-auth> </resource-ref> </entity> </enterprise-beans> <assembly-descriptor> <security-role> <description>**POQuery Role**</description> <role-name>PUBLIC</role-name> </security-role> <method-permission> <description>**POQuery Permissions**</description> <role-name>PUBLIC</role-name> <method> <ejb-name>POQueryBean</ejb-name> <method-name>*</method-name> </method> </method-permission> <container-transaction> <description>**POQuery Transaction**</description> <method> <ejb-name>POQueryBean</ejb-name> <method-name>*</method-name> </method> <trans-attribute>RequiresNew</trans-attribute> </container-transaction> </assembly-descriptor> </ejb-jar> |
<?xml version="1.0"?> <!DOCTYPE oracle-ejb-jar PUBLIC "-//Sun Microsystems Inc.//DTD Enterprise JavaBeans 1.1//EN" "oracle-ejb-jar.dtd"> <oracle-ejb-jar> <oracle-descriptor> <mappings> <ejb-mapping> <ejb-name>POQueryBean</ejb-name> <jndi-name>test/POQueryBean</jndi-name> </ejb-mapping> <security-role-mapping> <security-role> <description>**POQuery Role**</description> <role-name>OraclePublicRole</role-name> </security-role> <oracle-role>PUBLIC</oracle-role> </security-role-mapping> <resource-ref-mapping> <res-ref-name>DataSource</res-ref-name> <jndi-name>test/DataSource/testds</jndi-name> </resource-ref-mapping> <transaction-manager> <default-enlist>True</default-enlist> </transaction-manager> </mappings> <persistence-provider> <description>**Persistence Provider**</description> <persistence-name>psi-ri</persistence-name> <persistence-deployer>oracle.aurora.ejb.persistence.ocmp.OcmpEntityDeployer</persistence-deployer> </persistence-provider> <persistence-descriptor> <description>**Persistence Descriptor**</description> <ejb-name>POQueryBean</ejb-name> <persistence-name>psi-ri</persistence-name> <persistence-param>test param 1</persistence-param> <persistence-param>test param 2</persistence-param> <psi-ri> <schema>ICS</schema> <table>POS</table> <attr-mapping> <field-name>ponumber</field-name> <column-name>PONUMBER</column-name> </attr-mapping> <attr-mapping> <field-name>status</field-name> <column-name>STATUS</column-name> </attr-mapping> </psi-ri> </persistence-descriptor> </oracle-descriptor> </oracle-ejb-jar> |
REM makeit.bat @echo off @if not "%ECHO%"=="" echo %ECHO% @setlocal & pushd & set RET= set ORACLE_HOME=C:\oracle\ora90 call %ORACLE_HOME%\javavm\demo\common.bat if not "%RET%"=="1" goto :DOSEXIT REM set classpath local to this script set MAKE_CLASSPATH=%JDK12_CLASSPATH% REM published JNDI name of remote object set EJB_PUBNAME=/test/SKUBean set PUBNAME=%EJB_PUBNAME% REM COMMON_CLASS javac -g -classpath %MAKE_CLASSPATH% pocommon/*.java REM SERVER_CLASS javac -g -classpath %MAKE_CLASSPATH% server/*.java REM CLIENT_CLASS javac -g -classpath %MAKE_CLASSPATH% client/*.java REM server.jar jar cf server.jar server/*.class pocommon/*.class REM client.jar jar cfM client.jar client/*.class REM deploy call deployejb -addclasspath %MAKE_CLASSPATH% -republish -temp temp -generated pocommon.jar -u %USER%/%PASS% -s %GIOP_SERVICE% -descriptor POQuery.xml -oracledescriptor POQueryMap.xml server.jar :DOSEXIT @endlocal & popd & set RET=%RET% |
REM runit.bat @echo off @if not "%ECHO%"=="" echo %ECHO% @setlocal & pushd & set RET= set ORACLE_HOME=C:\oracle\ora90 call %ORACLE_HOME%\javavm\demo\common.bat if not "%RET%"=="1" goto :DOSEXIT REM set classpath local to this script set MAKE_CLASSPATH=%JDK12_CLASSPATH% REM published JNDI name of remote object set EJB_PUBNAME=/test/POQueryBean set PUBNAME=%EJB_PUBNAME% REM run java -classpath "%MAKE_CLASSPATH:"=%;pocommon.jar" client.Client %USER% %PASS% %GIOP_SERVICE% %PUBNAME% :DOSEXIT @endlocal & popd & set RET=%RET% |