org.opensubsystems.core.persist.db.transaction
Class J2EETransactionFactoryImpl

java.lang.Object
  extended by org.opensubsystems.core.persist.db.DatabaseTransactionFactoryImpl
      extended by org.opensubsystems.core.persist.db.transaction.J2EETransactionFactoryImpl
All Implemented Interfaces:
DatabaseTransactionFactory, TransactionFactory

public class J2EETransactionFactoryImpl
extends DatabaseTransactionFactoryImpl

Transaction factory using J2EE transaction manager. It will connect and expose the existing transaction manager of the J2EE server under which it currently runs.

Version:
$Id: J2EETransactionFactoryImpl.java,v 1.9 2007/01/07 06:14:21 bastafidli Exp $
Author:
Julo Legeny
Code reviewer:
Miroslav Halas
Code reviewed:
1.7 2006/05/15 05:12:15 bastafidli

Field Summary
static java.lang.String[] ARR_TRAN_MANAGER
          An array of object references to the JNDI location of TransactionManager.
static java.lang.String[] ARR_USER_TRAN
          An array of object references to the JNDI location of UserTransaction.
protected  javax.transaction.TransactionManager m_currentTransactionManager
          Current TransactionManager that is used for actual j2ee server.
protected  javax.transaction.UserTransaction m_currentUserTransaction
          Current UserTransaction that is used for actual j2ee server.
 
Fields inherited from class org.opensubsystems.core.persist.db.DatabaseTransactionFactoryImpl
s_bTransactionMonitor, s_iTransactionTimeout, TRANSACTION_MONITOR, TRANSACTION_MONITOR_DEFAULT, TRANSACTION_TIMEOUT, TRANSACTION_TIMEOUT_DEFAULT
 
Constructor Summary
J2EETransactionFactoryImpl()
           
 
Method Summary
 javax.transaction.TransactionManager getTransactionManager()
          Get transaction manager for this factory.
protected  javax.transaction.TransactionManager lookupTransactionManager(java.lang.String transactionManagerName)
          Look up the TransactionManager in JNDI via the configured name.
protected  javax.transaction.UserTransaction lookupUserTransaction(java.lang.String userTransactionName)
          Look up the UserTransaction in JNDI via the configured name.
 javax.transaction.UserTransaction requestTransaction()
          Get transaction object which we can use to begin/commit/rollback transactions.
protected  java.sql.Connection requestTransactionalConnection(boolean bAutoCommit, java.lang.String strDataSourceName, java.lang.String strUser, java.lang.String strPassword, DatabaseConnectionFactoryImpl connectionFactory)
          This method should be exclusively used by DatabaseConnectionFactoryImpl to get a transaction aware version of a connection.
 void reset()
          This method is here mainly for testing and it should reset the transaction manager to initial status to that tests can start from known environment instead of being influenced by other tests.
protected  void returnTransactionalConnection(java.sql.Connection cntDBConnection, DatabaseConnectionFactoryImpl connectionFactory)
          This method should be exclusively used by DatabaseConnectionFactoryImpl to get a transaction aware version of a connection.
 void stop()
          Stop the transaction factory.
 
Methods inherited from class org.opensubsystems.core.persist.db.DatabaseTransactionFactoryImpl
commitTransaction, getInstance, isTransactionInProgress, isTransactionMonitored, rollbackTransaction, setInstance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARR_TRAN_MANAGER

public static final java.lang.String[] ARR_TRAN_MANAGER
An array of object references to the JNDI location of TransactionManager. The values are for the following servers (in order): a.) JBoss and JRun4 servers b.) Resin, Orion (Oracle OC4J), JOnAS (JOTM), BEA WebLogic (unofficial) servers. c.) BEA WebLogic Server (official)


ARR_USER_TRAN

public static final java.lang.String[] ARR_USER_TRAN
An array of object references to the JNDI location of UserTransaction. The values are for the following servers (in order): a.) JBoss server b.) JOnAS (JOTM), BEA WebLogic IBM WebSphere servers


m_currentUserTransaction

protected javax.transaction.UserTransaction m_currentUserTransaction
Current UserTransaction that is used for actual j2ee server. Once it is initialized it should not try to do the lookup again.


m_currentTransactionManager

protected javax.transaction.TransactionManager m_currentTransactionManager
Current TransactionManager that is used for actual j2ee server. Once it is initialized it should not try to do the lookup again.

Constructor Detail

J2EETransactionFactoryImpl

public J2EETransactionFactoryImpl()
Method Detail

requestTransaction

public javax.transaction.UserTransaction requestTransaction()
                                                     throws OSSException
Get transaction object which we can use to begin/commit/rollback transactions. This operation is valid only if the transaction factory support explicit transaction across multiple connections.

Returns:
UserTransaction - null if explicit transactions are not supported.
Throws:
OSSException - - an error has occured

getTransactionManager

public javax.transaction.TransactionManager getTransactionManager()
Get transaction manager for this factory.

Returns:
TransactionManager

reset

public void reset()
           throws OSSException
This method is here mainly for testing and it should reset the transaction manager to initial status to that tests can start from known environment instead of being influenced by other tests.

Throws:
OSSException - - an error has occured during reset

stop

public void stop()
          throws OSSException
Stop the transaction factory.

Throws:
OSSException - - problem stoping transaction factory.

lookupUserTransaction

protected javax.transaction.UserTransaction lookupUserTransaction(java.lang.String userTransactionName)
Look up the UserTransaction in JNDI via the configured name.

Parameters:
userTransactionName - - the JNDI name of the UserTransaction
Returns:
UserTransaction - the UserTransaction object or null if not found

lookupTransactionManager

protected javax.transaction.TransactionManager lookupTransactionManager(java.lang.String transactionManagerName)
Look up the TransactionManager in JNDI via the configured name.

Parameters:
transactionManagerName - - the JNDI name of the TransactionManager
Returns:
TransactionManager - the TransactionManager object or null if not found

requestTransactionalConnection

protected java.sql.Connection requestTransactionalConnection(boolean bAutoCommit,
                                                             java.lang.String strDataSourceName,
                                                             java.lang.String strUser,
                                                             java.lang.String strPassword,
                                                             DatabaseConnectionFactoryImpl connectionFactory)
                                                      throws OSSDatabaseAccessException
This method should be exclusively used by DatabaseConnectionFactoryImpl to get a transaction aware version of a connection. If there one already exists (such as there is one associated with the current pending transaction managed by the database transaction factory) then this method will return that one and there is no need to allocate a new one. If there is not one, then this method will call back the database connection factory which allocated the connection and then create a transaction aware version of it. This method is protected so that only classes in this package can access it.

Overrides:
requestTransactionalConnection in class DatabaseTransactionFactoryImpl
Parameters:
bAutoCommit - - The desired autocommit state of the connection. If this connection is invoked in global (JTA) transaction then the autocommit is false regardless of what value is specified here. Use true here if the client only reads the data and false if the client also modifies the data.
strDataSourceName - - datasource for which the connection was requested, if null then it is requested for default data source
strUser - - user for which the connection was requested, if null then it is requested for default user
strPassword - - password for which the connection was requested, if null then it is requested for default passwoed
connectionFactory - - connection factory which is requesting the connection
Returns:
Connection - transaction aware version of connection
Throws:
OSSDatabaseAccessException - - an error has occured

returnTransactionalConnection

protected void returnTransactionalConnection(java.sql.Connection cntDBConnection,
                                             DatabaseConnectionFactoryImpl connectionFactory)
This method should be exclusively used by DatabaseConnectionFactoryImpl to get a transaction aware version of a connection. If the connection is transaction aware then it will be realy returned if it is not involved in a pending transaction. This method is protected so that only classes from this package can access it.

Overrides:
returnTransactionalConnection in class DatabaseTransactionFactoryImpl
Parameters:
cntDBConnection - - connection to return, can be null
connectionFactory - - connection factory to which the connection should be returned


Copyright © 2003 - 2006 OpenSubsystems s.r.o.