We are trying to use WebSphere as a transaction
manager for OJB, and it has been very difficult.  Here
are the instructions that one of the folks here put
together on how to achieve this.

Any comments?  Are others doing this, and have you had
to follow similar procedures?  Are we making it more
complicated than it really is (and if so, how can we
simplify)?



Instructions for Using OJB with WebSphere 5
We are trying to use the WebSphere transaction manager
(UserTransaction) to manage our transactions.  I could
not find any documentation on how to do this.  I
looked at the instructions on how to use OJB with EJB
on JBoss and WebLogic, and through trial an error I
have discovered the following method :

 

Follow the instructions for creating a servlet based
OJB application.


On the WebSphere server created an XA DataSource for
the database connection.  This assumes the JDBC driver
you are using supports XA.


In the applications Web Deployment Descriptor create a
resource reference that points to the data source. 
Remember the name.  The JNDI name for this reference
will be java:comp/env/{your name goes here}.


Make the following modifications in the OJB.Properties
file: 
Set the Connection Factory to
ConnectionFactoryManagedImpl  . 
Set the  JTATransactionManagerClass  to a factory 
that will return the WebSphere 5 TransactionManager. 
The one that is documented in the OJB.Properties files
works with WebSphere 4, and does not work with
WebSphere 5.  I wrote one of my own and inserted the
class name into the OJB.properties file.  See below
for details.


Declare the datasources in the repository file
(repository.xml), using the JNDI name of the
DataSource that you named in step 3. 
 

<jdbc-connection-descriptor

      jcd-alias="default"

      default-connection="true"

      platform="Oracle"

      jdbc-level="2.0"

     
jndi-datasource-name="java:comp/env/MyDataSource"

      protocol="jdbc"

      username="myUser"

      password="myPassword"

      eager-release="true"

      batch-mode="false"

      useAutoCommit="1"

      ignoreAutoCommitExceptions="false">

      

      <connection-pool maxActive="21"
validationQuery=""/>

 

      <sequence-manager className=

     
"org.apache.ojb.broker.util.sequence.SequenceManagerNextValImpl">

      </sequence-manager>

</jdbc-connection-descriptor>

 

 

Use  org.apache.ojb.odmg.OJBJ2EE_2 for the ODMG
instance.  Use the currentTransaction() method to join
the JTA transaction.


// Begin the JTA Transaction

Context myContext = new InitialContext();       

UserTransaction tranObject
=(UserTransaction)myContext.lookup("java:comp/UserTransaction");

tranObject.begin();     

 

. . .

 

// Doing the OJB Stuff

odmg = OJBJ2EE_2.getInstance();

// Join the JTA transaction

Transaction tx = odmg.currentTransaction();

// Acquire write lock on new object

tx.lock(obj, Transaction.WRITE);

 

. . .

 

// Commit the transaction

tranObject.commit();

 

 

TransactionManagerFactory
The TransactionManagerFactory
org.apache.ojb.odmg.transaction.WebSphereTransactionManagerFactory
does not work with WebSphere 5.  The TrasactionFactory
was renamed and is in a new package in WebSphere 5.  I
wrote a TransactionManagerFactory that returns the
WebSphere5 TransactionManager:

 

import java.lang.reflect.*;

import javax.transaction.TransactionManager;

 

import
org.apache.ojb.odmg.transaction.TransactionManagerFactory;

import
org.apache.ojb.odmg.transaction.TransactionManagerFactoryException;

 

import org.apache.ojb.broker.util.logging.Logger;

import
org.apache.ojb.broker.util.logging.LoggerFactory;

 

/**

 * @author AWA01

 *

 * A WebSphere 5 TransactionManagerFactory.  Based on
the class

 *
org.apache.ojb.odmg.transaction.WebSphereTransactionManagerFactory.

 * 

 * WHAT CHANGED:

 * In WebSphere 4 TransactionManagerFactory was named 

 * com.ibm.ejcs.jts.jta.JTSXA.  In WebSphere 5 the
TransactionManagerFactory was   

 * moved to
com.ibm.ejs.jts.jta.TransactionManagerFactory, but the

 * getTransactionManager() method used to get the
TransactionManager is still

 * the same.

 */

public class WebSphere5TransactionManagerFactory

      implements TransactionManagerFactory {

      

      private static Logger log;

 

      private static final String
TM_NAME="com.ibm.ejs.jts.jta.TransactionManagerFactory";

      protected static final String TM_METHOD_NAME
="getTransactionManager";

 

      /**

       * Constructor for
WebSphereTransactionManagerFactory.

       */

      public WebSphere5TransactionManagerFactory()

      {

            super();

            log =
LoggerFactory.getLogger(WebSphere5TransactionManagerFactory.class);

      }     

      

      /**

       * @see
org.apache.ojb.odmg.transaction.TransactionManagerFactory#getTransactionManager()

       */

      public TransactionManager
getTransactionManager()

            throws TransactionManagerFactoryException
{

            

            if (log.isDebugEnabled())

                  log.debug(

                       
"Weblogic5TransactionManagerFactory.getTransactionManager
called");

            TransactionManager retval = null;

            try {

                  

                  /**

                   * call the method on the class
because it is static.

                   */               

                  Class TransactionManagerFactory =
Class.forName(TM_NAME);               

                  Method method =
TransactionManagerFactory.getMethod(TM_METHOD_NAME,
null);

                  retval = (TransactionManager)
method.invoke(TransactionManagerFactory, null);

                  

            } catch (IllegalAccessException iae) {

                  throw new
TransactionManagerFactoryException(

                        "IllegalAccessException: " +
iae.getMessage());

            } catch (ClassNotFoundException cnfe) {

                  throw new
TransactionManagerFactoryException(

                        "ClassNotFoundException: " +
cnfe.getMessage());

            } catch (InvocationTargetException ite) {

                  throw new
TransactionManagerFactoryException(

                        "InvocationTargetException: "
+ ite.getMessage());

            } catch (NoSuchMethodException nsme) {

                  throw new
TransactionManagerFactoryException(

                        "NoSuchMethodException: " +
nsme.getMessage());

            }

            return retval;

      }

}

 


__________________________________
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to