You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by ar...@apache.org on 2004/03/05 00:40:36 UTC
cvs commit: db-ojb/src/ejb/org/apache/ojb/ejb/pb PBSessionBean.java
arminw 2004/03/04 15:40:35
Modified: . build-ejb-examples.xml
xdocs deployment.xml
src/ejb/org/apache/ojb/ejb ContextHelper.java
src/ejb/org/apache/ojb/ejb/pb PBSessionBean.java
Log:
- update documentation for ejb-examples
- minor changes in sample classes
Revision Changes Path
1.2 +82 -20 db-ojb/build-ejb-examples.xml
Index: build-ejb-examples.xml
===================================================================
RCS file: /home/cvs/db-ojb/build-ejb-examples.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- build-ejb-examples.xml 28 Feb 2004 10:48:03 -0000 1.1
+++ build-ejb-examples.xml 4 Mar 2004 23:40:35 -0000 1.2
@@ -32,8 +32,9 @@
<target name="classes-exist">
<available file="${build.dest}/org" property="build.classes.exist"/>
</target>
+
<target name="check" unless="build.classes.exist" depends="classes-exist">
- <fail message="Run target 'main-opt' before run current target"/>
+ <fail message="Run target 'main-opt' or 'jar' before run current target"/>
</target>
<!-- =================================================================== -->
@@ -72,12 +73,50 @@
<deploymentdescriptor destdir="${generated.descriptor.dir}"/>
<jboss version="3.0"
xmlencoding="UTF-8"
- typemapping="Hypersonic SQL"
- datasource="java:/DefaultDS"
+ destdir="${generated.descriptor.dir}"/>
+ <jonas version="3.0"
+ xmlencoding="UTF-8"
destdir="${generated.descriptor.dir}"/>
</ejbdoclet>
</target>
+
+ <!-- =================================================================== -->
+ <!-- Build jonas deployment files -->
+ <!-- -->
+ <!-- =================================================================== -->
+ <!-- pass jonas.root as property, path to jonas root directory
+ This target generates the stubs and skeletons for JOnAS appServer beans.
+ But I get problems with xdoclet tags 'compile_beans' and in this target not
+ all classes are included in .jar file
+ -->
+ <!--
+ <target name="jonas" depends="compile_beans">
+ <ejbjar srcdir="${generated.ejb.classes.dir}"
+ descriptordir="${generated.descriptor.dir}"
+ basejarname="${ojb-filename-prefix}-jonas"
+ genericjarsuffix=""
+ >
+ <jonas destdir="${jar.dir}"
+ jonasroot="${jonas.root}"
+ nogenic="false"
+ >
+ <classpath>
+ <path refid="ojb.classpath"/>
+ <pathelement location="${jar.dir}/${jar.name.beans}"/>
+ <pathelement location="${jonas.root}/lib/common/ow_jonas.jar"/>
+ <pathelement location="${jonas.root}/lib/jonas.jar"/>
+ <pathelement location="${jonas.root}/lib/common/ow_jonas_bootstrap.jar"/>
+ </classpath>
+ </jonas>
+
+ <include name="**/ejb-jar.xml"/>
+ <include name="**/*.class"/>
+ <exclude name="**/jonas-ejb-jar.xml"/>
+ </ejbjar>
+ </target>
+ -->
+
<!-- =================================================================== -->
<!-- Compiles the source directory and copy all xml -->
<!-- files in src to classes.dir -->
@@ -103,23 +142,13 @@
deprecation="${deprecation}">
<classpath refid="ojb.classpath"/>
</javac>
-
- <!-- copy todir="${generated.ejb.classes.dir}/META-INF">
- <fileset dir="${generated.descriptor.dir}" includes="**/*.xml"/>
- </copy -->
-
- <!-- delete>
- <fileset dir="${generated.src.dir}">
- <include name="**/*Bean.java" />
- <include name="**/*BO.java" />
- <include name="**/*BeanImpl.java" />
- </fileset>
- </delete -->
</target>
<!-- =================================================================== -->
<!-- jboss mbeans, workaround till JCA works -->
<!-- =================================================================== -->
+ <!-- DEPRECATED, was no longer used - since ejb-examples no longer
+ bind OJB api's to JNDI -->
<target name="prepare-jboss">
<copy todir="${build.src}">
<fileset dir="${src.dir}/connector/main">
@@ -142,12 +171,26 @@
<manifest>
<!-- attribute name="classpath" value="db-ojb-1.0.rc2.jar ${classpath.attributes}"/ -->
</manifest>
- <!-- fileset dir="${jar.dir}"
- includes="${jar.name.junit}"
- / -->
</jar>
</target>
+
+ <!-- =================================================================== -->
+ <!-- Prepare ejb jar -->
+ <!-- =================================================================== -->
+ <target name="prepare-ejb-jar"
+ description="Extends the generated ejb sample jar with OJB config files">
+ <!-- ojb.files pass the directory with modified OJB config files -->
+ <jar jarfile="${jar.dir}/${jar.name.beans}"
+ basedir="${ojb.files}"
+ update="true">
+ <fileset dir="${lib}">
+ <include name="commons-*.jar *regexp*.jar antlr*.jar"/>
+ </fileset>
+ </jar>
+ </target>
+
+
<!-- =================================================================== -->
<!-- Build the client jar -->
<!-- =================================================================== -->
@@ -156,7 +199,6 @@
<copy todir="${client.src.dir}">
<fileset dir="${java.src.dir}"
excludes="**/*Bean.class,
- **/*VO.class,
**/*BeanImpl.class,
**/*.xml,
**/*.properties">
@@ -174,7 +216,6 @@
<jar jarfile="${jar.dir}/${jar.name.client}"
basedir="${generated.ejb.classes.dir}"
excludes="**/*Bean.class,
- **/*VO.class,
**/*BeanImpl.class,
**/*.xml,
**/*.properties">
@@ -182,4 +223,25 @@
</target>
+
+ <!-- =================================================================== -->
+ <!-- Run the test client -->
+ <!-- =================================================================== -->
+ <target name="ejb-examples-run" depends="" description="Run the ejb-examples test clients" >
+ <!-- client.class pass the class name of the class to run -->
+ <java fork="yes"
+ classname="${client.class}"
+ dir="${build.test}/ojb"
+ taskname="ojb-client"
+ failonerror="true"
+ >
+ <classpath>
+ <pathelement location="${jar.dir}/${jar.name.client}"/>
+ <path refid="ojb.classpath"/>
+ </classpath>
+ <jvmarg value="-Xms64m"/>
+ <jvmarg value="-Xmx256m"/>
+ </java>
+
+ </target>
</project>
1.32 +445 -304 db-ojb/xdocs/deployment.xml
Index: deployment.xml
===================================================================
RCS file: /home/cvs/db-ojb/xdocs/deployment.xml,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -r1.31 -r1.32
--- deployment.xml 11 Feb 2004 18:27:07 -0000 1.31
+++ deployment.xml 4 Mar 2004 23:40:35 -0000 1.32
@@ -32,8 +32,10 @@
<li>
<a href="#Deployment in EJB based applications">Deployment in EJB based applications</a>
<ul>
- <li><a href="#Example: Instructions for JBoss">Example: Instructions for JBoss</a></li>
- <li><a href="#Build the OJB sample session beans">Build the OJB sample session beans</a></li>
+ <li><a href="#Configure OJB for managed environments considering as JBoss example">Configure OJB for managed environments considering as JBoss example</a></li>
+ <li><a href="#Build example beans">Build example beans</a></li>
+ <li><a href="#Packing an .ear file">Packing an .ear file</a></li>
+ <li><a href="#Make OJB accessible via JNDI">Make OJB accessible via JNDI</a></li>
<li><a href="#Instructions for Weblogic">Instructions for Weblogic</a></li>
</ul>
</li>
@@ -58,8 +60,7 @@
You'll find this file in the lib directory of the binary distribution.
If you are working with the source distribution you can assemble the binary jar archive
- By calling <B><code>build[.sh]
- jar </code></B>. This ant task generates the binary jar to the dist directory.
+ By calling <b><code>ant jar </code></b>. This ant task generates the binary jar to the dist directory.
</P>
</subsection>
@@ -109,8 +110,6 @@
</li>
<li><code>xalan.jar</code>
</li>
- <li><code>crossdb.jar</code>
- </li>
<li><code>ejb.jar</code>
</li>
<li><code>servlet.jar</code>
@@ -209,8 +208,7 @@
</OL>
<p>
- By executing <code>build[.sh]
- war</code> you can generate a sample servlet application assembled
+ By executing <code>ant war</code> you can generate a sample servlet application assembled
to a valid WAR file. The resulting <code>ojb-servlet.war</code>
file is written to the dist directory. You can deploy this WAR file to
your servlet engine or unzip it to have a look at its
@@ -225,6 +223,8 @@
+
+
<section name="Deployment in EJB based applications">
<p>
@@ -232,7 +232,7 @@
jar files and placing of the OJB.properties and the repository.xml
are valid for EJB environments as well.
But apart from these basic steps you'll have to perform some additional
-configurations to integrate OJB into the container mechanisms.
+configurations to integrate OJB into a managed environment.
</p>
<p>
The instructions to make OJB running within your application server
@@ -246,169 +246,39 @@
<li><b>Connection handling:</b> Lookup DataSource from your AppServer, only these
connections will be enlisted in running transactions</li>
<li><b>Caching:</b> Do you need distributed caching?</li>
- <li><b>Locking:</b> Do you need distributed locking (e.g. when using odmg-api)?</li>
+ <li><b>Locking:</b> Do you need distributed locking (when using odmg-api)?</li>
</ul>
</P>
-<subsection name="Example: Instructions for JBoss">
+<subsection name="Configure OJB for managed environments considering as JBoss example">
<br/>
<font size="-1"><i>The eight step guide to felicity (or insanity in some cases)</i></font>
<br/>
<p>
-<b>1. Get the missed jar files</b>
-<br/>
-As a result of different licence models we could not ship all necessary
-jar files with OJB. Thus you need some extra jar files to make the ejb
-examples target run:
-<ul>
- <li>JBoss jar files to support the OJB mbeans (jars depend on used version, so trial and error)</li>
- <li>jboss-j2ee.jar or use j2ee jars fron SUN</li>
- <li>XDoclet jar file and modules for generating ejb's and jboss deployment descriptor (modules: jboss, jmx, ejb, web)</li>
-</ul>
-Put these jar files in the <code>lib</code> directory of OJB if you want to generate the ejb-examples.
-</p>
-
-
-<p>
-<b>2. Bind OJB api-main classes to JNDI</b>
-<br/>
-To make the OJB api's accessible via JNDI, we need to bind them to JNDI. How to do
- that depends on the used environment. In JBoss you can use <code>mbean</code> classes
- to do that <code>org.apache.ojb.jboss.PBFactory</code> and <code>org.apache.ojb.jboss.ODMGFactory</code>.
-<br/>
-Let JBoss know about the new mbeans, so declare them in a <code>jboss-service.xml</code> file:
-<source><![CDATA[
-<?xml version="1.0" encoding="UTF-8"?>
-
-<server>
- <mbean code="org.apache.ojb.jboss.PBFactory"
- name="DefaultDomain:service=PBAPI,name=ojb/PBAPI">
- <depends>jboss.jca:service=RARDeployer</depends>
- <attribute name="JndiName">ojb/PBAPI</attribute>
- </mbean>
-
- <mbean code="org.apache.ojb.jboss.ODMGFactory"
- name="DefaultDomain:service=ODMG,name=ojb/defaultODMG">
- <depends>jboss.jca:service=RARDeployer</depends>
- <attribute name="JndiName">ojb/defaultODMG</attribute>
- </mbean>
-</server>
-]]></source>
-
-These step makes OJB accessible via JNDI. In other application server you should do
-a similar step and bind the OJB api-main classes to JNDI. The main classes to bind
-are:
- <ul>
- <li>
- <code>org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory</code> for PB-api.
- Make method <code>PersistenceBrokerFactoryFactory.instance()</code> accessible.
- </li>
- <li>
- <code>org.apache.ojb.odmg.OJBJ2EE_2</code> for ODMG-api. Make method
- <code>OJBJ2EE_2.getInstance()</code> accessible.
- </li>
- </ul>
-</p>
-
-
-<p>
-<b>3. Enclose all libraries OJB depend on and put them into a .sar-directory</b>
-<br/>
-Make a <code>ojb.sar</code> directory under <code>[jboss.home]/server/default/deploy</code>
-<br/>
-Add a <code>META-INF</code> directory under <code>ojb.sar</code>.
-<br/>
-Put a simple <code>MANIFEST.MF</code> file and the <code>jboss-service.xml</code>
-file in this directory.
-<br/>
-To make OJB run and (re-)deployable you have to put all libraries
-OJB depend on into the <code>ojb.sar</code> directory:
-<ul>
-<li>The jakarta commons libraries files (all commons-xxx.jar)</li>
-<li>The antlr jar file (antlr-xxx.jar)</li>
-</ul>
-(This was tested with jboss 3.2.2)
-</p>
-
-<p>
-<b>4. Prepare OJB code base</b>
-<br/>
-With <code>bin\build.bat prepare-jboss jar</code>
-using windows or<br/>
-<code>bin/build.sh prepare-jboss jar</code> we rebuild OJB
-jars including the jboss MBeans.
-<br/>
-The <code>prepare-jboss</code> target copy the jboss MBeans to the OJB code
-base. After running the <code>jar</code> target you could find the new
-<code>db-ojb-xxx.jar</code>, including the MBeans, in the <code>dist</code>
-directory.
-<br/>
-(If you need a OJB jar file without the MBeans, clean the <code>target</code>
-directory e.g. by calling the <code>clean</code> ant target and invoke the
-<code>jar</code> ant target again).
-<br/>
-Copy the <code>db-ojb-xxx.jar</code> file into the <code>ojb.sar</code> directory.
-</p>
-
-
-<p>
-<b>5. Copy OJB configuration files into the <code>ojb.sar</code> directory</b>
-<br/>
-OJB.properties, repository.dtd, repository.xml, repository_internal.xml, repository_database.xml,
-repository_ejb.xml (if you want to run the ejb examples). The repository.xml
-should rather look like:
-<source><![CDATA[
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- This is a sample metadata repository for the ObJectBridge
-System. Use this file as a template for building your own
-mappings-->
-
-<!-- defining entities for include-files -->
-<!DOCTYPE descriptor-repository SYSTEM "repository.dtd" [
-<!ENTITY database SYSTEM "repository_database.xml">
-<!ENTITY internal SYSTEM "repository_internal.xml">
-<!ENTITY junit SYSTEM "repository_junit.xml">
-<!ENTITY user SYSTEM "repository_user.xml">
-<!ENTITY ejb SYSTEM "repository_ejb.xml">
-<!ENTITY jdo SYSTEM "repository_jdo.xml">
-]>
-
-
-<descriptor-repository version="1.0"
- isolation-level="read-uncommitted">
-
- <!-- include all used database connections -->
- &database;
-
- <!-- include ojb internal mappings here -->
- &internal;
-
- <!-- include mappings for the EJB-examples -->
- &ejb;
-
-</descriptor-repository>
-]]></source>
+ The following steps describe how to configure OJB for managed environments and
+ deploy on a ejb conform Application Server (JBoss) on the basis of the
+ <a href="#OJB sample session beans">shipped ejb-examples</a>. In managed environments
+ OJB needs some specific properties.
</p>
<p>
<a name="jboss-ojb.properties"/>
-<b>6. Adapt OJB.properties file</b>
+<b>1. Adapt OJB.properties file</b>
<p>
-If the PB-api is the only persistence API being used (no ODMG nor JDO),
+If the PB-api is the only persistence API being used (no ODMG nor JDO)
and it is <b>only</b> being used in a managed environment, it is
recommended to use a special PersistenceBrokerFactory class, which
enables PersistenceBroker instances to participate in the running JTA
transaction (e.g. this makes PBStateListener proper work in managed
-environments and enables use of 'autoSync' property in
-ObjectCacheDefaultImpl):
+environments and enables use of 'autoSync' property in ObjectCacheDefaultImpl):
<source>
PersistenceBrokerFactoryClass=
org.apache.ojb.broker.core.PersistenceBrokerFactorySyncImpl
</source>
-Don't use this setting in conjunction with the ODMG-api.
+Don't use this setting in conjunction with any other top-level api (e.g. ODMG-api).
</p>
<p>
Your OJB.properties file need the following additional settings to work within
@@ -422,16 +292,23 @@
OJBTxManagerClass=org.apache.ojb.odmg.JTATxManager
...
+# set used application server TM access class
JTATransactionManagerClass=
org.apache.ojb.otm.transaction.factory.JBossTransactionManagerFactory
]]></source>
+ A specific <i>ConnectionFactory</i> implementation was used to by-pass all
+ forbidden method calls in managed environments. The <i>JTATransactionManagerClass</i>
+ set the used implementation class for transaction manager lookup, necessary for participation
+ in JTA transaction.
</p>
</p>
+
<p>
-<b>7a. Declare datasources in the repository (repository_database) file and do additional configuration</b>
-<br/>
-Do only use <code>DataSource</code> from the application server to connect your databases.
+<b>2. Declare datasource in the repository (repository_database) file and do additional configuration</b>
+<p>
+Do only use <code>DataSource</code> from the application server to connect to your database
+(Local used connections do not participate in JTA transactions).
<br/>
<font color="#0000FF">
NOTE: We strongly recommend to use JBoss 3.2.2 or higher of the 3.x series of JBoss. With earlier versions of
@@ -439,6 +316,8 @@
introduce a jboss specific attribute <i>eager-release</i> for version before 3.2.2, but it seems that this
attribute can cause side-effects. Again, this problem seems to be fixed in 3.2.2.
</font>
+<br/>
+Define OJB to use a DataSource:
<source><![CDATA[
<!-- Datasource example -->
<jdbc-connection-descriptor
@@ -468,17 +347,100 @@
in managed environments, because it's in most cases not
allowed to change autoCommit state.
</p>
+</p>
+
<p>
In managed environments you can't use the default sequence manager (SequenceManagerHighLowImpl)
of OJB. For alternative sequence manager implemetation <a href="sequencemanager.html">see here</a>.
</p>
+
+<p>
+<b>[2b. How to deploy ojb test hsqldb database to jboss]</b>
+<p>
+If you use hsql database for testing you can easy setup the DB on jboss.
+After creating the database in OJB test directory with <code>ant prepare-testdb</code>,
+take the generated <code>.../target/test/OJB.script</code> file and rename it to <code>default.script</code>.
+Then replace the jboss default.script file in <code>.../jboss-3.x.y/server/default/db/hypersonic</code>
+with this file.
+</p>
+</p>
+
+
+
+<p>
+<b>3. Include all OJB configuration files in classpath</b>
+<p>
+Include the all needed OJB configuration files in your classpath:
+<p>
+- OJB.properties
+<br/>- repository.dtd
+<br/>- repository.xml
+<br/>- repository_internal.xml
+<br/>- repository_database.xml,
+<br/>- repository_ejb.xml (if you want to run the ejb examples)
+</p>
+To deploy the ejb-examples beans we include all configuration files in a
+ejb jar file - more info about this see <a href="#Put all together">below</a>.
+<p>
+The repository.xml for the <a href="#Build example beans">ejb-example beans</a> look like:
+<source><![CDATA[
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- This is a sample metadata repository for the ObJectBridge
+System. Use this file as a template for building your own
+mappings-->
+
+<!-- defining entities for include-files -->
+<!DOCTYPE descriptor-repository SYSTEM "repository.dtd" [
+<!ENTITY database SYSTEM "repository_database.xml">
+<!ENTITY internal SYSTEM "repository_internal.xml">
+<!ENTITY ejb SYSTEM "repository_ejb.xml">
+]>
+
+
+<descriptor-repository version="1.0"
+ isolation-level="read-uncommitted">
+
+ <!-- include all used database connections -->
+ &database;
+
+ <!-- include ojb internal mappings here -->
+ &internal;
+
+ <!-- include mappings for the EJB-examples -->
+ &ejb;
+
+</descriptor-repository>
+]]></source>
+</p>
+</p>
+</p>
+
+
+<p>
+<b>4. Enclose all libraries OJB depend on</b>
+<p>
+In most cases it is recommended to include all libraries OJB depend on
+in the application .ear/.sar or ejb .jar file to make OJB run and
+(re-)deployable.
+Here are the libraries needed to make the ojb sample session beans run on JBoss:
+<ul>
+<li>The jakarta commons libraries files (all commons-xxx.jar) from OJB /lib directory</li>
+<li>The antlr jar file (antlr-xxx.jar) from OJB /lib directory</li>
+<li>jakarta-regexp-xxx.jar from OJB /lib directory</li>
+<li>[jakarta turbine jcs.jar from OJB /lib directory, only if ObjectCacheJCSImpl was used]</li>
+</ul>
+(This was tested with jboss 3.2.2)
+</p>
+</p>
+
+
+<p>
+<b>5. Take care of caching</b>
<p>
-<b>7b. Take care of caching</b>
-<br/>
Very important thing is cache synchronization with the database.
-When using the ODMG-api or PB-api (with <a href="#jboss-ojb.properties">special PBF (see 6.)</a> setting)
+When using the ODMG-api or PB-api (with <a href="#jboss-ojb.properties">special PBF (see 1.)</a> setting)
it's possible to use all <code>ObjectCache</code> implementations as long as OJB doesn't run
in a clustered mode. When the <code>ObjectCacheDefaultImpl</code> cache implementation was used it's
recommended to enable the <code>autoSync</code> mode.
@@ -490,6 +452,7 @@
<br/><code>ObjectCacheClass=org.apache.ojb.broker.cache.ObjectCacheEmptyImpl</code>.
The cache is pluggable, so you can write your own ObjectCache implementation to accomplish
your expectations.
+</p>
<p>
More info you can find in
<a href="howto-work-with-clustering.html">clustering</a> and
@@ -499,61 +462,56 @@
<p>
-<b>7c. Take care of locking</b>
-<br/>
-If the used api supports <tt>Object Locking</tt> (e.g. ODMG-api), in clustered environments
-(OJB run on different AppServer nodes) a distributed lock management is necessary.
-<br/>
-
+<b>6. Take care of locking</b>
+<p>
+If the used api supports <tt>Object Locking</tt> (e.g. ODMG-api, PB-api does not), in clustered environments
+(OJB run on different AppServer nodes) a distributed <a href="lockmanager.html">lock management</a> is necessary.
+</p>
</p>
+
<p>
-<b>[7d. How to deploy ojb test hsqldb database to jboss]</b>
-<br/>
-After creating the database with
-<code>bin\build.bat prepare-testdb</code> or <code>bin/build.sh prepare-testdb</code>.
-<br/>
-Take the generated <code>OJB.script</code> file from <code>.../target/test</code>
-and rename the file to <code>default.script</code>.
-Replace the jboss default.script file in
-<code>...\jboss-3.x.y\server\default\db\hypersonic</code>
-with this file.
+<a name="Put all together"/>
+<b>7. Put all together</b>
+<p>
+Now put all files together. We keep the examples as simple as possible, thus we deploy only
+a ejb .jar file. <a href="#Packing an .ear file">Below</a> you can find a short instruction
+how to pack an ejb application .ear file including OJB.
</p>
-
-
<p>
-<b>8a. Inside your EJB's you can get a handle on the ODMG like this:</b>
+Generate the ejb-examples <a href="#Build example beans">described below</a> or build your own ejb .jar file
+including all beans, ejb-jar.xml and appServer dependend files. Then add all OJB configuration files,
+the db-ojb jar file and all libraries OJB depends on into this ejb .jar file.
+<br/>
+The structure of the ejb .jar file should now look like this:
<source><![CDATA[
-ODMGFactory factory =
-(ODMGFactory) context.lookup("java:/ojb/defaultODMG");
-odmg = factory.getInstance();
-]]></source>
-</p>
+/OJB.properties
+/repository.dtd
+/repository.xml
+/all used repository-XYZ.xml
+/META-INF
+.../Manifest.mf
+.../ejb-jar.xml
+.../jboss.xml
+/all ejb classes
-<p>
-<b>8b. Inside your EJB's you can get a handle on the PB like this:</b>
-<source><![CDATA[
-context = new InitialContext();
-pbf = ((PBFactoryIF) context.lookup(
- PBFactoryIF.PBFACTORY_JNDI_NAME)).getInstance();
+/db-ojb-1.X.jar
+/all used libraries
]]></source>
</p>
-
-<p>
-Check out the ejb's provided in the OJB distro at: <code>[db-ojb]/src/ejb/org/apache/ojb/ejb</code>
-for an example of working beans.
-</p>
-<p>
-<b>
-This solution should be re-deployable in jboss.
-If you will get any problems, please let me know.
-</b>
+This solution should be re-deployable in JBoss.
+<b>If you will get any problems, please let me know.</b>
+<br/>(The author is not a "great deployer", so all suggestions are welcome)
</p>
+
+
+
+<p>
+<b>8. OJB logging within JBoss</b><br/>
<p>
-<b>8c. OJB logging within JBoss</b><br/>
Jboss use <a href="http://jakarta.apache.org/log4j">log4j</a> as standard logging api.
<br/>
In summary, to use log4j logging with OJB within jBoss,
@@ -585,19 +543,38 @@
]]></source>
</p>
</p>
+</p>
+
</subsection>
-<subsection name="Build the OJB sample session beans">
+<subsection name="Build example beans">
<p>
+<b>Generate the sample session beans</b>
+<br/>
The OJB source distribution was shipped with a bunch of sample
-beans. We are using xdoclet to build the necessary classes and deployment
-descriptors.
+session beans and client classes for testing. Please recognize that we don't say that these examples
+show "best practices" of using OJB within enterprise java beans - it's
+only one way to make it work.
</p>
-
<p>
-To run xdoclet properly you need the following xdoclet jar files
+The source code of the sample beans is stored in directory
+<br/>
+<code>[db-ojb]/src/ejb/org/apache/ojb/ejb</code>
+<br/>
+To generate the sample beans call
+<source><![CDATA[
+ant ejb-examples
+]]></source>
+This ant target copies the bean sources to
+<code>[db-ojb]/target/srcejb</code> generates all needed bean classes and
+deployment descriptor (by using xdoclet) to the same directory, compiles the sources and
+build an ejb .jar file called <code>[db-ojb]/dist/db-ojb-XXX-beans.jar</code>. Test clients
+for the generated beans included in the <code>[db-ojb]/dist/db-ojb-XXX-client.jar</code>.
+</p>
+<p>
+To run xdoclet properly the following xdoclet jar files needed
in <code>[db-ojb]/lib</code> directory (xdoclet version 1.2xx or higher):
<source>
xdoclet-xxx.jar
@@ -608,87 +585,139 @@
xdoclet-xjavadoc-module-xxx.jar
</source>
</p>
+
<p>
-You could find the source code of the beans under
-<br/>
-<code>[db-ojb]/src/ejb/org/apache/ojb/ejb</code>
-<br/>
-and after running the <code>ejb-examples</code> ant target (see below),
-you will find the complete sources (including the generated interfaces)
-under
+If you using a different application server than JBoss, you have to modifiy the <i>xdoclet</i> ant target in
+<code>[db-ojb]/build-ejb-examples.xml</code> to force xdoclet to generate the appServer specific files.
+See xdoclet documentation for further information.
+</p>
+
+
+
+<p>
+<b>How to run test clients for PB / ODMG - api</b>
<br/>
-<code>[db-ojb]/target/srcejb</code>
+If the "extended ejb .jar" file was successfully deployed we need a test client to
+invoke the ejb-examples. As said above, the <i>ejb-examples</i> target generates a
+test client jar too. It's called <code>[db-ojb]/dist/db-ojb-XXX-client.jar</code> and
+contains junit based test clients for the PB-/ODMG-api.
<br/>
-in three sub-dirs.
+The main test classes are:
+<ul>
+ <li>org.apache.ojb.ejb.AllODMGTests</li>
+ <li>org.apache.ojb.ejb.AllPBTests</li>
+</ul>
+OJB provide an ant target to run the client side bean tests. Include all needed appServer
+libraries in <code>[db-ojb]/lib</code> (e.g. for JBoss jbossall-client.jar do the job, beside
+the "j2ee jars"). To run the PB-api test clients (access running JBoss server with default
+settings) call
+<source>
+ ant ejb-examples-run -Dclient.class=org.apache.ojb.ejb.AllPBTests
+</source>
+To run the test clients on an arbitrary appServer pass the JNDI properties for naming context
+initalisation too, e.g.
+<ul>
+ <li>-Djava.naming.factory.initial="org.jnp.interfaces.NamingContextFactory"</li>
+ <li>-Djava.naming.provider.url="jnp://localhost:1099"</li>
+ <li>-Djava.naming.factory.url.pkgs="org.jboss.naming:org.jnp.interfaces"</li>
+</ul>
+Then the target call may looks like
+<source>
+ ant ejb-examples-run -Dclient.class=org.apache.ojb.ejb.AllPBTests
+ -Djava.naming.factory.initial="org.jnp.interfaces.NamingContextFactory"
+ -Djava.naming.provider.url="jnp://localhost:1099"
+ -Djava.naming.factory.url.pkgs="org.jboss.naming:org.jnp.interfaces"
+</source>
</p>
+</subsection>
+
+
+<subsection name="Packing an .ear file">
<p>
-Run the following ant target
+Here is a sample how a .ear file should be packed with OJB:
<source><![CDATA[
-bin/build.sh ejb-examples
-or
-bin\build.bat ejb-examples
+/ejb.jar/
+...EJBs
+...DAOs
+...META-INF/
+......ejb-jar.xml
+......jboss.xml
+......MANIFEST.MF [Class-Path: /lib/ojb.jar<CRLF>] <--- VERY IMPORTANT
+
+/lib/
+...ojb.jar
+
+/web-app.war/
+...JSP
+...WEB-INF/
+......web.xml [ejb-refs to EJBs]
+
+/META-INF/
+...application.xml
+
+/OJB.properties
+/repository.xml
+/repository_database.xml
+/repository_user.xml
]]></source>
-to generate the the bean and client jars prepared for use in JBoss. If you using
-a different application server, you have to modifiy the xdoclet ant target in
-<code>[db-ojb]/build-xdoclet.xml</code> to generate files specified for your
-application server. See xdoclet documentation for further information.
-</p>
-<p>
-After running the ant target you will find a <code>db-ojb-XXX-beans.jar</code>
-and a <code>db-ojb-XXX-client.jar</code> in the [db-ojb]/dist directory.
-Put the bean jar in the <code>ojb.sar</code> directory.
-<br/>
-To run the ejb-example test cases use the
-<code>org.apache.ojb.ejb.AllTests</code> class.
+I'm not sure, but in some cases you may need the libraries OJB depends on too in the
+<code>/lib</code> directory to make the .ear file proper re-deployable.
</p>
+</subsection>
+
+
+<subsection name="Make OJB accessible via JNDI">
<p>
-<font color="#0000FF">
-NOTE:
-<br/>
-When using JBoss 3.2.x the generated beans cause
-start up problems (re-deployment works fine). The problem
-is that in JBoss 3.2.x an ejb shouldn't be deployed until its
-declared invokers have started. Thus the jboss.xml
-file in the generated <code>db-ojb-XXX-beans.jar</code> needs
-a new element called 'depends' in each session bean declaration:
-<source><![CDATA[
-...
-<session>
- <ejb-name>ODMGSessionBean</ejb-name>
- <jndi-name>org.apache.ojb.ejb.ODMGSessionBean</jndi-name>
- <local-jndi-name>org.apache.ojb.ejb.ODMGSessionBeanLocal</local-jndi-name>
- <depends optional-attribute-name="Invoker">jboss:service=invoker,type=jrmp</depends>
-</session>
-...
-]]></source>
-We hope with the next version of xdoclet this can be done
-automatic.
-<br/>
-(Many thanks to Alex Bates)
-</font>
+ Current bean examples do directly use OJB main classes, but it's also possible to make
+ OJB accessible via JNDI and use a JNDI-lookup to access OJB api's in your beans.
+ <br/>
+ To make the OJB api's accessible via JNDI, you can bind them to JNDI. How to do
+ this depends on the used environment.
+ The main classes/method to bind are:
+ <ul>
+ <li>
+ Class <code>org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory</code> for PB-api.
+ Make method <code>PersistenceBrokerFactoryFactory.instance()</code> accessible.
+ </li>
+ <li>
+ Class <code>org.apache.ojb.odmg.OJBJ2EE_2</code> for ODMG-api. Make method
+ <code>OJBJ2EE_2.getInstance()</code> accessible.
+ </li>
+ </ul>
</p>
<p>
-<b>How to run client org.apache.ojb.ejb.AllTests</b>
-<br/>
-Numerous jars are required for the client. One possibility is to
-modify <code>build.bat</code>/<code>build.sh</code> to set this up properly
-and called it e.g. <code>.\runEJBClient.bat</code>.
-A sample srict could look like this:
-<source>
-@echo off
-REM Please let JAVA_HOME point to your JDK base directory
-if "%JAVA_HOME%" == "" set JAVA_HOME=C:\j2sdk1.4.1
-set JAVA=%JAVA_HOME%\bin\java
-set JBOSS_HOME=D:\jboss-3.0.6
-set cp=
-for %%i in (%JBOSS_HOME%\client\*.jar) do call bin\cp.bat %%i
-for %%i in (dist\*.jar) do call bin\cp.bat %%i
-for %%i in (lib\*.jar) do call bin\cp.bat %%i
-"%JAVA%" -classpath "%CP%" org.apache.ojb.ejb.AllTests
-</source>
+ <b>JBoss</b><br/>
+ In JBoss you can use <code>mbean</code> classes.
+ <code>org.apache.ojb.jboss.PBFactory</code> and <code>org.apache.ojb.jboss.ODMGFactory</code>
+ are mbean implementations bind PB-api and ODMG-api main classes to JNDI.
+ <br/>
+ Let JBoss know about the new mbeans, so declare them in a <code>jboss-service.xml</code> file:
+ <source><![CDATA[
+ <?xml version="1.0" encoding="UTF-8"?>
+
+ <server>
+ <mbean code="org.apache.ojb.jboss.PBFactory"
+ name="DefaultDomain:service=PBAPI,name=ojb/PBAPI">
+ <depends>jboss.jca:service=RARDeployer</depends>
+ <attribute name="JndiName">ojb/PBAPI</attribute>
+ </mbean>
+
+ <mbean code="org.apache.ojb.jboss.ODMGFactory"
+ name="DefaultDomain:service=ODMG,name=ojb/defaultODMG">
+ <depends>jboss.jca:service=RARDeployer</depends>
+ <attribute name="JndiName">ojb/defaultODMG</attribute>
+ </mbean>
+ </server>
+ ]]></source>
+</p>
+<p>
+ <b>Other Application Server</b><br/>
+ In other application server you can do similar steps to bind OJB main api classes to
+ JNDI. For example in Weblogic you can use <i>startup class</i> implementation
+ (see <a href="#Instructions for Weblogic">below</a>).
</p>
</subsection>
@@ -699,41 +728,15 @@
<font size="-1">(Thanks Christophe Lombart and Lucy Zhao)</font>
<p>
<ul>
+
<li>
Add the OJB jar files and depedencies into the Weblogic classpath
</li>
-<li>
-Compile the following classes (see at the <a href="#pb.factory">end of this section</a>) and add
-them to the weblogic classpath. This allows to access the PB-api via
-JNDI lookup.
-</li>
-<li>
-Register via the weblogic console the startup class
-(see <code>OjbPbStartup</code> class below).
-The JNDI name and the OJB.properties file path can be specified as
-parameters in this startup class.
-<br/>
-<br/>
-To use the ODMG-api you have to write a similar startup class.
-This shouldn't be too complicated.
-Take a look in <code>org.apache.ojb.jboss</code> package
-(dir <code>src/connector/main</code>). Here you could find the jboss mbeans.
-All you have to do is bound a similar class to JNDI in weblogic.
-<br/>
-Implement <code>ODMGJ2EEFactory</code> Interface in your class bound this class
-to JNDI (in the ejb-examples the beans try to lookup the <code>Implementation</code>
-instance via <code>"java:/ojb/defaultODMG"</code>).
-Your ODMGFactory class should implement this method
-<source>
-public Implementation getInstance()
-{
- return OJBJ2EE_2.getInstance();
-}
-</source>
-</li>
+
<li>
As usual create the connection pool and the datasource.
</li>
+
<li>
Prepare the OJB.properties file. Should be similar to
<a href="#jboss-ojb.properties">jboss</a>. Expect the
@@ -745,9 +748,11 @@
org.apache.ojb.odmg.transaction.WeblogicTransactionManagerFactory
</source>
</li>
+
<li>
Modify the connection information in the repository.xml (specify the
-datasource name):
+datasource name). SequenceManager implementation depends on the used DB, more info
+<a href="sequencemanager.html">see here</a>:
<source><![CDATA[
<jdbc-connection-descriptor
jcd-alias="default"
@@ -770,17 +775,52 @@
</jdbc-connection-descriptor>
]]></source>
</li>
+
+<li>
+<p>
+<b>NOTE</b>: Following step is only neccessary if you want to bind OJB main api classes to JNDI.
+<br/>
+Compile the following classes (see at the <a href="#pb.factory">end of this section</a>) and add
+them to the weblogic classpath. This allows to access the PB-api via
+JNDI lookup. Register via the weblogic console the startup class
+(see <code>OjbPbStartup</code> class below). The JNDI name and the OJB.properties file path can be specified as
+parameters in this startup class.
+</p>
+<p>
+To use the ODMG-api you have to write a similar startup class.
+This shouldn't be too complicated.
+Take a look in <code>org.apache.ojb.jboss</code> package
+(dir <code>src/connector/main</code>). Here you could find the jboss mbeans.
+All you have to do is bound a similar class to JNDI in weblogic.
+<br/>
+Implement <code>ODMGJ2EEFactory</code> Interface in your class bound this class
+to JNDI (in the ejb-examples the beans try to lookup the <code>Implementation</code>
+instance via <code>"java:/ojb/defaultODMG"</code>).
+Your ODMGFactory class should implement this method
+<source>
+public Implementation getInstance()
+{
+ return OJBJ2EE_2.getInstance();
+}
+</source>
+</p>
+</li>
+
</ul>
</p>
<p>
-Write a session bean similar to thoses provided for the JBOSS samples.
-It is also possible to use the ejb-example beans doing minor modifications
-when the JNDI lookup was done.
+Write a session bean similar to those provided for the JBOSS samples.
+It is also possible to use the ejb-example beans (doing minor modifications
+when the JNDI lookup should be used).
</p>
+
<p>
-Write an OJB startup class can look like (I couldn't test this sample class, so
-don't know if it will work ;-)):
<a name="pb.factory"/>
+<i>Webolgic startup class</i>
+<br/>
+Write an OJB startup class to make OJB accessible via JNDI can look like (I couldn't test this sample class, so
+don't know if it will work ;-)):
+
<source>
package org.apache.ojb.weblogic;
@@ -882,6 +922,107 @@
</source>
</p>
</subsection>
+
+<!-- UNUSED SNIP
+<p>
+<font color="#0000FF">
+NOTE:
+<br/>
+When using JBoss 3.2.x the generated beans cause
+start up problems (re-deployment works fine). The problem
+is that in JBoss 3.2.x an ejb shouldn't be deployed until its
+declared invokers have started. Thus the jboss.xml
+file in the generated <code>db-ojb-XXX-beans.jar</code> needs
+a new element called 'depends' in each session bean declaration:
+<source><![CDATA[
+...
+<session>
+ <ejb-name>ODMGSessionBean</ejb-name>
+ <jndi-name>org.apache.ojb.ejb.odmg.ODMGSessionBean</jndi-name>
+ <local-jndi-name>org.apache.ojb.ejb.odmg.ODMGSessionBeanLocal</local-jndi-name>
+ <depends optional-attribute-name="Invoker">jboss:service=invoker,type=jrmp</depends>
+</session>
+...
+]]></source>
+We hope with the next version of xdoclet this can be done
+automatic.
+<br/>
+(Many thanks to Alex Bates)
+</font>
+</p>
+-->
+
+<!-- UNUSED SNIP
+<p>
+<b>1. Get the missed jar files</b>
+<br/>
+As a result of different licence models we could not ship all necessary
+jar files with OJB. Thus you need some extra jar files to make the <i>ejb-examples</i> target run:
+<ul>
+ <li>JBoss jar files (jars depend on used version, so trial and error)</li>
+ <li>jboss-j2ee.jar or use j2ee jars fron SUN</li>
+ <li>XDoclet jar file and modules for generating ejb's and jboss
+ deployment descriptor (modules: jboss, jmx, ejb, web)</li>
+</ul>
+Put these jar files in the <code>lib</code> directory of OJB if you want to generate the ejb-examples.
+</p>
+
+
+
+
+
+<p>
+<b>4. Prepare OJB code base</b>
+<br/>
+With <code>ant prepare-jboss jar</code> we rebuild OJB
+jars including the jboss MBeans.
+<br/>
+The <code>prepare-jboss</code> target copy the jboss MBeans to the OJB code
+base. After running the <code>jar</code> target you could find the new
+<code>db-ojb-xxx.jar</code>, including the MBeans, in the <code>dist</code>
+directory.
+<br/>
+(If you need a OJB jar file without the MBeans, clean the <code>target</code>
+directory e.g. by calling the <code>clean</code> ant target and invoke the
+<code>jar</code> ant target again).
+<br/>
+Copy the <code>db-ojb-xxx.jar</code> file into the <code>ojb.sar</code> directory.
+</p>
+
+
+<p>
+<b>8a. Inside your EJB's you can get a handle on the ODMG like this:</b>
+<source><![CDATA[
+ODMGFactory factory =
+(ODMGFactory) context.lookup("java:/ojb/defaultODMG");
+odmg = factory.getInstance();
+]]></source>
+</p>
+
+
+<p>
+<b>8b. Inside your EJB's you can get a handle on the PB like this:</b>
+<source><![CDATA[
+context = new InitialContext();
+pbf = ((PBFactoryIF) context.lookup(
+ PBFactoryIF.PBFACTORY_JNDI_NAME)).getInstance();
+]]></source>
+</p>
+
+
+<p>
+Check out the ejb's provided in the OJB distro at: <code>[db-ojb]/src/ejb/org/apache/ojb/ejb</code>
+for an example of working beans.
+</p>
+<p>
+<b>
+This solution should be re-deployable in jboss.
+If you will get any problems, please let me know.
+</b>
+</p>
+
+-->
+
</section>
1.3 +53 -30 db-ojb/src/ejb/org/apache/ojb/ejb/ContextHelper.java
Index: ContextHelper.java
===================================================================
RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/ContextHelper.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ContextHelper.java 28 Feb 2004 10:42:35 -0000 1.2
+++ ContextHelper.java 4 Mar 2004 23:40:35 -0000 1.3
@@ -3,52 +3,74 @@
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
+import javax.naming.NamingEnumeration;
import java.util.Properties;
/**
* Helper class for client side JNDI context lookup.
+ * This class lookup system properties for {@link Context#INITIAL_CONTEXT_FACTORY},
+ * {@link Context#PROVIDER_URL} and {@link Context#URL_PKG_PREFIXES}. If not set,
+ * InitialContext for JBoss (with default settings) was instantiated.
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
* @version $Id$
*/
public class ContextHelper
{
- private static Context ctx;
+ private static InitialContext ctx;
public synchronized static Context getContext()
{
- if(ctx != null)
- {
- return ctx;
- }
- Properties prop = System.getProperties();
- // if jndi-properties not set as system properties, take jboss/jonas jndi
- // properties as default
- if (prop.getProperty("java.naming.factory.initial") == null)
- {
- ctx = jbossJNDI();
- if(ctx == null) ctx = jonasJNDI();
- if(ctx == null) throw new RuntimeException("Can't initialize naming context");
- }
- else
+ if(ctx == null)
{
+ Properties prop = System.getProperties();
+ // if jndi-properties not set as system properties, take jboss/jonas jndi
+ // properties as default
+ if (prop.getProperty(Context.INITIAL_CONTEXT_FACTORY) == null)
+ {
+ System.out.println("System property " + Context.INITIAL_CONTEXT_FACTORY
+ + " is not set. Try to use default setting for JNDI lookup");
+ ctx = jbossJNDI();
+ if(ctx == null) ctx = jonasJNDI();
+ if(ctx == null) throw new RuntimeException("Can't initialize naming context");
+ }
+ else
+ {
+ try
+ {
+ ctx = new InitialContext(prop);
+ }
+ catch (NamingException e)
+ {
+ e.printStackTrace();
+ }
+ }
try
{
- ctx = new InitialContext(prop);
+ System.out.println("Used JNDI Context: " + ctx.getEnvironment());
+ System.out.println("Namespace: " + ctx.getNameInNamespace());
+ System.out.println("Bindings: ==>");
+ NamingEnumeration enu = ctx.listBindings(ctx.getNameInNamespace());
+ while(enu.hasMoreElements())
+ {
+ System.out.println("element: " + enu.nextElement());
+ }
}
- catch (NamingException e)
+ catch(NamingException e)
{
- e.printStackTrace();
+ // e.printStackTrace();
}
}
+
return ctx;
}
- private static Context jbossJNDI()
+ private static InitialContext jbossJNDI()
{
- Context ctx = null;
+ InitialContext ctx = null;
try
{
+ System.out.println("Try to use JBoss naming service");
Properties prop = jbossNamingProperties();
ctx = new InitialContext(prop);
}
@@ -59,18 +81,19 @@
return ctx;
}
- private static Context jonasJNDI()
+ private static InitialContext jonasJNDI()
{
- Context ctx = null;
+ InitialContext ctx = null;
try
{
+ System.out.println("Try to use JOnAS naming service");
Properties prop = jonasNamingProperties();
ctx = new InitialContext(prop);
}
catch(NamingException e)
{
- e.printStackTrace();
System.err.println("JonAS JNDI lookup failed: " + e.getMessage());
+ e.printStackTrace();
}
return ctx;
}
@@ -78,18 +101,18 @@
private static Properties jbossNamingProperties()
{
Properties prop = new Properties();
- prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
- prop.setProperty("java.naming.provider.url", "jnp://localhost:1099/");
- prop.setProperty("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
+ prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ prop.setProperty(Context.PROVIDER_URL, "jnp://localhost:1099");
+ prop.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
return prop;
}
private static Properties jonasNamingProperties()
{
Properties prop = new Properties();
- prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
- prop.setProperty("java.naming.provider.url", "rmi://localhost:1099/");
- prop.setProperty("java.naming.factory.url.pkgs", "org.objectweb.jonas.naming");
+ prop.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.objectweb.carol.jndi.spi.MultiOrbInitialContextFactory");
+ //prop.setProperty(Context.PROVIDER_URL, "jrmi://localhost:2000");
+ //prop.setProperty(Context.URL_PKG_PREFIXES, "org.objectweb.jonas.naming");
return prop;
}
}
1.2 +4 -1 db-ojb/src/ejb/org/apache/ojb/ejb/pb/PBSessionBean.java
Index: PBSessionBean.java
===================================================================
RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/pb/PBSessionBean.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PBSessionBean.java 28 Feb 2004 10:42:35 -0000 1.1
+++ PBSessionBean.java 4 Mar 2004 23:40:35 -0000 1.2
@@ -102,6 +102,9 @@
* @ejb:transaction
* type="Required"
*
+ * @jonas.bean
+ * ejb-name="org.apache.ojb.ejb.pb.PBSessionBean"
+ * jndi-name="org.apache.ojb.ejb.pb.PBSessionBean"
*
* @author <a href="mailto:armin@codeAuLait.de">Armin Waibel</a>
* @version $Id$
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org