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/08/15 01:16:28 UTC
cvs commit: db-ojb/src/ejb/org/apache/ojb/ejb BeanConstants.java
arminw 2004/08/14 16:16:28
Modified: src/doc/forrest/src/documentation/content/xdocs/docu/guides
Tag: OJB_1_0_RELEASE deployment.xml
src/ejb/org/apache/ojb/ejb/odmg Tag: OJB_1_0_RELEASE
ODMGBaseBeanImpl.java ODMGSessionBean.java
Added: src/ejb/org/apache/ojb/ejb/odmg Tag: OJB_1_0_RELEASE
ODMGHelper.java
Removed: src/ejb/org/apache/ojb/ejb Tag: OJB_1_0_RELEASE
BeanConstants.java
Log:
update EJB examples, add note to bind OJB main/access classes to JNDI
instead of direct use
Revision Changes Path
No revision
No revision
1.1.2.2 +36 -46 db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/guides/deployment.xml
Index: deployment.xml
===================================================================
RCS file: /home/cvs/db-ojb/src/doc/forrest/src/documentation/content/xdocs/docu/guides/deployment.xml,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- deployment.xml 27 Jul 2004 00:29:31 -0000 1.1.2.1
+++ deployment.xml 14 Aug 2004 23:16:28 -0000 1.1.2.2
@@ -727,7 +727,7 @@
//ODMG-api
Implementation odmg = OJB.getInstance();]]></source>
<p>
- But it is also possible to bind OJB api access classes to JNDI and
+ But it is recommended to bind OJB api access classes to JNDI and
lookup the the api entry <link href="#bind-to-jndi">classes via JNDI</link>.
</p>
</section>
@@ -775,11 +775,11 @@
<anchor id="example-beans"/>
<section>
- <title>Build example beans</title>
+ <title>Example Session Beans</title>
+
+ <anchor id="example-introduction"/>
<section>
- <title>
- <strong>Generate the sample session beans</strong>
- </title>
+ <title>Introduction</title>
<p>
The OJB source distribution was shipped with a bunch of sample
session beans and client classes for testing. Please recognize that we don't say that
@@ -787,6 +787,18 @@
only one way to make it work.
</p>
<p>
+ To keep the examples as simple as possible we directly use the OJB main classes
+ via static lookup or helper classes on each <em>ejbCreate()</em> call. But we recommend to
+ <link href="#bind-to-jndi">bind the OJB main classes</link> in JNDI instead of direct use
+ in the session beans.
+ </p>
+ </section>
+
+ <section>
+ <title>
+ <strong>Generate the sample session beans</strong>
+ </title>
+ <p>
The source code of the sample beans is stored in directory
<br/>
<code>[db-ojb]/src/ejb/org/apache/ojb/ejb</code>
@@ -979,21 +991,21 @@
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:
+ To make the OJB api's accessible via JNDI, you have bind them to JNDI. How to do
+ this depends on the used environment. The main classes/methods to bind are:
</p>
<ul>
<li>
- Class
- <code>org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory</code> for PB-api.
- Make method
- <code>PersistenceBrokerFactoryFactory.instance()</code> accessible.
+ PB-api:<br/>
+ Method <code>org.apache.ojb.broker.core.PersistenceBrokerFactoryFactory#instance()</code>
+ returns the used <code>org.apache.ojb.broker.core.PersistenceBrokerFactoryIF</code>. Make
+ this instance accessible via JNDI.
</li>
<li>
- Class
- <code>org.apache.ojb.odmg.OJB</code> for ODMG-api. Make method
- <code>OJB.getInstance()</code> accessible.
+ ODMG-api:<br/>
+ Method <code>org.apache.ojb.odmg.OJB#getInstance()</code> returns a new instance of
+ the <code>org.odmg.Implementation</code> instance. Open a new <code>Database</code>and
+ make this instance and the <code>Database</code> instance accessible via JNDI.
</li>
</ul>
@@ -1002,31 +1014,12 @@
<strong>JBoss</strong>
</title>
<p>
- 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:
- </p>
- <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>
+ In JBoss you can write <em>mbean</em> classes to bind OJB main/access classes to JNDI,
+ similar to the <link href="#pb.factory"><em>Weblogic</em> example</link> below.
+ <br/>
+ Let JBoss know about the new mbeans, so declare them in a
+ <code>jboss-service.xml</code> file:
+ </p>
</section>
<section>
@@ -1035,11 +1028,8 @@
</title>
<p>
In other application server you can do similar steps to bind OJB main api classes to
- JNDI. For example in Weblogic you can use
- <em>startup class
- </em> implementation
- (see
- <link href="#weblogic">below</link>).
+ JNDI. For example in Weblogic you can use <em>startup class</em> implementation
+ (see <link href="#weblogic">below</link>).
</p>
</section>
</section>
No revision
No revision
1.5.2.1 +27 -43 db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGBaseBeanImpl.java
Index: ODMGBaseBeanImpl.java
===================================================================
RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGBaseBeanImpl.java,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -r1.5 -r1.5.2.1
--- ODMGBaseBeanImpl.java 3 May 2004 23:06:56 -0000 1.5
+++ ODMGBaseBeanImpl.java 14 Aug 2004 23:16:28 -0000 1.5.2.1
@@ -23,15 +23,12 @@
import org.apache.ojb.broker.query.QueryByCriteria;
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
-import org.apache.ojb.ejb.BeanConstants;
import org.apache.ojb.ejb.SessionBeanImpl;
import org.apache.ojb.odmg.HasBroker;
-import org.apache.ojb.odmg.OJB;
import org.apache.ojb.odmg.TransactionExt;
import org.odmg.Database;
import org.odmg.Implementation;
import org.odmg.LockNotGrantedException;
-import org.odmg.ODMGException;
import org.odmg.OQLQuery;
import org.odmg.Transaction;
@@ -40,8 +37,11 @@
* subclass this class to implement your own bean
* implementations.
*
- * Do not close the Database instance after use, this
- * was done on ejbRemove.
+ * To keep this example as simple as possible, we lookup a static OJB ODMG
+ * implementation instance from an helper class.
+ * But it's recommended to bind an instances of the ODMG main/access classes in JNDI
+ * (at appServer start), open the database and lookup these instances instance via JNDI in
+ * ejbCreate(), instead of lookup a static instance on each bean creation.
*
* To get the {@link org.odmg.Database} or
* {@link org.odmg.Implementation} instance use
@@ -61,6 +61,27 @@
private Implementation odmg;
/**
+ * Lookup the OJB ODMG implementation.
+ * It's recommended to bind an instance of the Implementation class in JNDI
+ * (at appServer start), open the database and lookup this instance via JNDI in
+ * ejbCreate().
+ */
+ public void ejbCreate()
+ {
+ if (log.isDebugEnabled()) log.debug("ejbCreate was called");
+ odmg = ODMGHelper.getODMG();
+ }
+
+ /**
+ * Here we do the OJB cleanup.
+ */
+ public void ejbRemove()
+ {
+ super.ejbRemove();
+ odmg = null;
+ }
+
+ /**
* Return the Database associated with
* this bean.
*/
@@ -166,42 +187,5 @@
log.error("OQLQuery failed", e);
throw new OJBRuntimeException("OQLQuery failed", e);
}
- }
-
-
- public void ejbCreate()
- {
- if (log.isDebugEnabled()) log.debug("ejbCreate was called");
- ojbPrepare();
- }
-
- /**
- * Prepare using of the ODMG-api
- */
- private void ojbPrepare()
- {
- odmg = OJB.getInstance();
- Database db = odmg.newDatabase();
- try
- {
- if (log.isDebugEnabled())
- log.debug("open new database " +
- db + " using databaseName name " + BeanConstants.DEF_DATABASE_NAME);
- db.open(BeanConstants.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
- }
- catch (ODMGException e)
- {
- log.error("Database open failed", e);
- throw new OJBRuntimeException("Unable to open database using ODMG api", e);
- }
- }
-
- /**
- * Here we do the OJB cleanup.
- */
- public void ejbRemove()
- {
- super.ejbRemove();
- odmg = null;
}
}
1.5.2.1 +24 -37 db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGSessionBean.java
Index: ODMGSessionBean.java
===================================================================
RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGSessionBean.java,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -r1.5 -r1.5.2.1
--- ODMGSessionBean.java 3 May 2004 23:06:56 -0000 1.5
+++ ODMGSessionBean.java 14 Aug 2004 23:16:28 -0000 1.5.2.1
@@ -31,7 +31,6 @@
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
import org.apache.ojb.ejb.ArticleVO;
-import org.apache.ojb.ejb.BeanConstants;
import org.apache.ojb.ejb.PersonVO;
import org.apache.ojb.odmg.OJB;
import org.apache.ojb.odmg.TransactionExt;
@@ -53,17 +52,17 @@
* {@link org.apache.ojb.ejb.pb.PBBaseBeanImpl}
* <p>
* <b>How to use ODMG</b> <br>
- * In every bean method you must start with one of following operations: <br>
+ *
+ * To keep this example as simple as possible, we lookup a static OJB ODMG implementation instance
+ * on each bean instance.
+ * But it's recommended to bind an instance of the Implementation class in JNDI
+ * (at appServer start), open the database and lookup this instances via JNDI in
+ * ejbCreate().
+ *
+ * To use the odmg-api within your bean, you can do:
*
* <ol type="a">
* <li>
- * Open a new Database using the Implementation instance.<br><i>
- * Database db = odmg.newDatabase();<br>
- * db.open(...);<br>
- * // ... do something <br>
- * db.close();
- * </i></li>
- * <li>
* Obtain the current Database from the Implementation instance - Attend<br>
* that there must be already a Database opened before.<br><i>
* db = odmg.getDatabase(null);<br>
@@ -115,21 +114,24 @@
{
}
+ /**
+ * Lookup the OJB ODMG implementation.
+ * It's recommended to bind an instance of the Implementation class in JNDI
+ * (at appServer start), open the database and lookup this instance via JNDI in
+ * ejbCreate().
+ */
public void ejbCreate()
{
log.info("ejbCreate was called");
- odmg = OJB.getInstance();
- db = odmg.newDatabase();
- try
- {
- log.info("open new database " + db + " using databaseName name " + BeanConstants.DEF_DATABASE_NAME);
- db.open(BeanConstants.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
- }
- catch (ODMGException e)
- {
- log.error("Database open failed", e);
- }
- log.info("ejbCreate end");
+ odmg = ODMGHelper.getODMG();
+ db = odmg.getDatabase(null);
+ }
+
+ public void ejbRemove()
+ {
+ db = null;
+ odmg = null;
+ ctx = null;
}
/**
@@ -333,21 +335,6 @@
log.error("OQLQuery failed", e);
throw new OJBRuntimeException("OQLQuery failed", e);
}
- }
-
- public void ejbRemove()
- {
- try
- {
- if(odmg.currentTransaction() == null) db.close();
- }
- catch (ODMGException e)
- {
- log.error("Closing of database failed", e);
- }
- db = null;
- odmg = null;
- ctx = null;
}
public void ejbActivate()
No revision
Index: ODMGSessionBean.java
===================================================================
RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGSessionBean.java,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -r1.5 -r1.5.2.1
--- ODMGSessionBean.java 3 May 2004 23:06:56 -0000 1.5
+++ ODMGSessionBean.java 14 Aug 2004 23:16:28 -0000 1.5.2.1
@@ -31,7 +31,6 @@
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
import org.apache.ojb.ejb.ArticleVO;
-import org.apache.ojb.ejb.BeanConstants;
import org.apache.ojb.ejb.PersonVO;
import org.apache.ojb.odmg.OJB;
import org.apache.ojb.odmg.TransactionExt;
@@ -53,17 +52,17 @@
* {@link org.apache.ojb.ejb.pb.PBBaseBeanImpl}
* <p>
* <b>How to use ODMG</b> <br>
- * In every bean method you must start with one of following operations: <br>
+ *
+ * To keep this example as simple as possible, we lookup a static OJB ODMG implementation instance
+ * on each bean instance.
+ * But it's recommended to bind an instance of the Implementation class in JNDI
+ * (at appServer start), open the database and lookup this instances via JNDI in
+ * ejbCreate().
+ *
+ * To use the odmg-api within your bean, you can do:
*
* <ol type="a">
* <li>
- * Open a new Database using the Implementation instance.<br><i>
- * Database db = odmg.newDatabase();<br>
- * db.open(...);<br>
- * // ... do something <br>
- * db.close();
- * </i></li>
- * <li>
* Obtain the current Database from the Implementation instance - Attend<br>
* that there must be already a Database opened before.<br><i>
* db = odmg.getDatabase(null);<br>
@@ -115,21 +114,24 @@
{
}
+ /**
+ * Lookup the OJB ODMG implementation.
+ * It's recommended to bind an instance of the Implementation class in JNDI
+ * (at appServer start), open the database and lookup this instance via JNDI in
+ * ejbCreate().
+ */
public void ejbCreate()
{
log.info("ejbCreate was called");
- odmg = OJB.getInstance();
- db = odmg.newDatabase();
- try
- {
- log.info("open new database " + db + " using databaseName name " + BeanConstants.DEF_DATABASE_NAME);
- db.open(BeanConstants.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
- }
- catch (ODMGException e)
- {
- log.error("Database open failed", e);
- }
- log.info("ejbCreate end");
+ odmg = ODMGHelper.getODMG();
+ db = odmg.getDatabase(null);
+ }
+
+ public void ejbRemove()
+ {
+ db = null;
+ odmg = null;
+ ctx = null;
}
/**
@@ -333,21 +335,6 @@
log.error("OQLQuery failed", e);
throw new OJBRuntimeException("OQLQuery failed", e);
}
- }
-
- public void ejbRemove()
- {
- try
- {
- if(odmg.currentTransaction() == null) db.close();
- }
- catch (ODMGException e)
- {
- log.error("Closing of database failed", e);
- }
- db = null;
- odmg = null;
- ctx = null;
}
public void ejbActivate()
No revision
Index: ODMGSessionBean.java
===================================================================
RCS file: /home/cvs/db-ojb/src/ejb/org/apache/ojb/ejb/odmg/ODMGSessionBean.java,v
retrieving revision 1.5
retrieving revision 1.5.2.1
diff -u -r1.5 -r1.5.2.1
--- ODMGSessionBean.java 3 May 2004 23:06:56 -0000 1.5
+++ ODMGSessionBean.java 14 Aug 2004 23:16:28 -0000 1.5.2.1
@@ -31,7 +31,6 @@
import org.apache.ojb.broker.util.logging.Logger;
import org.apache.ojb.broker.util.logging.LoggerFactory;
import org.apache.ojb.ejb.ArticleVO;
-import org.apache.ojb.ejb.BeanConstants;
import org.apache.ojb.ejb.PersonVO;
import org.apache.ojb.odmg.OJB;
import org.apache.ojb.odmg.TransactionExt;
@@ -53,17 +52,17 @@
* {@link org.apache.ojb.ejb.pb.PBBaseBeanImpl}
* <p>
* <b>How to use ODMG</b> <br>
- * In every bean method you must start with one of following operations: <br>
+ *
+ * To keep this example as simple as possible, we lookup a static OJB ODMG implementation instance
+ * on each bean instance.
+ * But it's recommended to bind an instance of the Implementation class in JNDI
+ * (at appServer start), open the database and lookup this instances via JNDI in
+ * ejbCreate().
+ *
+ * To use the odmg-api within your bean, you can do:
*
* <ol type="a">
* <li>
- * Open a new Database using the Implementation instance.<br><i>
- * Database db = odmg.newDatabase();<br>
- * db.open(...);<br>
- * // ... do something <br>
- * db.close();
- * </i></li>
- * <li>
* Obtain the current Database from the Implementation instance - Attend<br>
* that there must be already a Database opened before.<br><i>
* db = odmg.getDatabase(null);<br>
@@ -115,21 +114,24 @@
{
}
+ /**
+ * Lookup the OJB ODMG implementation.
+ * It's recommended to bind an instance of the Implementation class in JNDI
+ * (at appServer start), open the database and lookup this instance via JNDI in
+ * ejbCreate().
+ */
public void ejbCreate()
{
log.info("ejbCreate was called");
- odmg = OJB.getInstance();
- db = odmg.newDatabase();
- try
- {
- log.info("open new database " + db + " using databaseName name " + BeanConstants.DEF_DATABASE_NAME);
- db.open(BeanConstants.DEF_DATABASE_NAME, Database.OPEN_READ_WRITE);
- }
- catch (ODMGException e)
- {
- log.error("Database open failed", e);
- }
- log.info("ejbCreate end");
+ odmg = ODMGHelper.getODMG();
+ db = odmg.getDatabase(null);
+ }
+
+ public void ejbRemove()
+ {
+ db = null;
+ odmg = null;
+ ctx = null;
}
/**
@@ -333,21 +335,6 @@
log.error("OQLQuery failed", e);
throw new OJBRuntimeException("OQLQuery failed", e);
}
- }
-
- public void ejbRemove()
- {
- try
- {
- if(odmg.currentTransaction() == null) db.close();
- }
- catch (ODMGException e)
- {
- log.error("Closing of database failed", e);
- }
- db = null;
- odmg = null;
- ctx = null;
}
public void ejbActivate()
1.1.2.1 +61 -0 db-ojb/src/ejb/org/apache/ojb/ejb/odmg/Attic/ODMGHelper.java
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org