org.opensubsystems.core.persist.db
Class DatabaseTransactionFactoryImpl

java.lang.Object
  extended by org.opensubsystems.core.persist.db.DatabaseTransactionFactoryImpl
All Implemented Interfaces:
DatabaseTransactionFactory, TransactionFactory
Direct Known Subclasses:
J2EETransactionFactoryImpl, JOTMTransactionFactoryImpl, SimpleLocalTransactionFactoryImpl

public abstract class DatabaseTransactionFactoryImpl
extends java.lang.Object
implements DatabaseTransactionFactory

Base class for implementation of database transaction factories.

Version:
$Id: DatabaseTransactionFactoryImpl.java,v 1.25 2007/01/07 06:14:18 bastafidli Exp $
Author:
Miro Halas
Code reviewer:
Miro Halas
Code reviewed:
1.18 2006/05/24 15:18:33 bastafidli

Field Summary
protected static boolean s_bTransactionMonitor
          Flag, which is telling us if we should monitor transactions that is use a delegating class which intercepts and monitors calls to UserTransaction class.
protected static int s_iTransactionTimeout
          Transaction timeout, which should be set for a transaction when it is started.
static java.lang.String TRANSACTION_MONITOR
          Boolean flag, which specifies if the system should monitor transactions that is use a delegating class which intercepts and monitors calls to UserTransaction class.
static boolean TRANSACTION_MONITOR_DEFAULT
          Default transaction monitor setting.
static java.lang.String TRANSACTION_TIMEOUT
          Transaction timeout in seconds, which should be set for a transaction when it is started.
static int TRANSACTION_TIMEOUT_DEFAULT
          Default transaction timeout.
 
Constructor Summary
DatabaseTransactionFactoryImpl()
          Default constructor.
 
Method Summary
 void commitTransaction(java.sql.Connection cntConnection)
          Commit implicit transaction for given connection.
static DatabaseTransactionFactory getInstance()
          Get the default factory.
 boolean isTransactionInProgress()
          Test if transaction is in progress.
 boolean isTransactionMonitored()
          Test if transaction should be monitored
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.
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 rollbackTransaction(java.sql.Connection cntConnection)
          Rollback implicit transaction for given connection.
static void setInstance(DatabaseTransactionFactory defaultFactory)
          Set default factory instance.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opensubsystems.core.util.TransactionFactory
getTransactionManager, requestTransaction, reset, stop
 

Field Detail

TRANSACTION_TIMEOUT

public static final java.lang.String TRANSACTION_TIMEOUT
Transaction timeout in seconds, which should be set for a transaction when it is started. If this is set to 0, according to documentation the transaction manager restores the default value.

See Also:
Constant Field Values

TRANSACTION_MONITOR

public static final java.lang.String TRANSACTION_MONITOR
Boolean flag, which specifies if the system should monitor transactions that is use a delegating class which intercepts and monitors calls to UserTransaction class. This is useful for troubleshooting and during development but can affect the system performance.

See Also:
Constant Field Values

TRANSACTION_TIMEOUT_DEFAULT

public static final int TRANSACTION_TIMEOUT_DEFAULT
Default transaction timeout. Keep it longer so that if during debugging we need to step through the code, we have enough time to complete transaction.

See Also:
Constant Field Values

TRANSACTION_MONITOR_DEFAULT

public static final boolean TRANSACTION_MONITOR_DEFAULT
Default transaction monitor setting. Keep it false so that it doesn't affect performance.

See Also:
Constant Field Values

s_iTransactionTimeout

protected static int s_iTransactionTimeout
Transaction timeout, which should be set for a transaction when it is started. If this is set to 0, according to documentation transaction manager restores the default value.


s_bTransactionMonitor

protected static boolean s_bTransactionMonitor
Flag, which is telling us if we should monitor transactions that is use a delegating class which intercepts and monitors calls to UserTransaction class.

Constructor Detail

DatabaseTransactionFactoryImpl

public DatabaseTransactionFactoryImpl()
Default constructor.

Method Detail

getInstance

public static DatabaseTransactionFactory getInstance()
                                              throws OSSException
Get the default factory. This method is here to make the transaction factory is configurable. Once can specify in configuration file derived class to used instead of this one [DatabaseTransactionFactory.class]=new class to use or [TransactionFactory.class]=new class to use

Returns:
DatabaseTransactionFactory
Throws:
OSSException - - an error has occured

setInstance

public static void setInstance(DatabaseTransactionFactory defaultFactory)
Set default factory instance. This instance will be returned by getInstance method until it is changed.

Parameters:
defaultFactory - - new default factory instance
See Also:
getInstance()

commitTransaction

public void commitTransaction(java.sql.Connection cntConnection)
                       throws java.sql.SQLException
Commit implicit transaction for given connection. This operation succeed only if explicit UserTransaction is not in progress. Otherwise it has no effect. The purpose is that a given component doesn't know if a larger transaction is in progress or not. Therefore it asks the database transaction factory to commit the transaction based on connection and the transaction factory since it is aware of the larger transaction may decide to commit the transaction based on connection if no larger transaction is in progress or commit it.

Specified by:
commitTransaction in interface DatabaseTransactionFactory
Parameters:
cntConnection - - the connection to commit transaction for.
Throws:
java.sql.SQLException - - problem commiting transaction

rollbackTransaction

public void rollbackTransaction(java.sql.Connection cntConnection)
                         throws java.sql.SQLException
Rollback implicit transaction for given connection. This operation succeed only if explicit UserTransaction is not in progress. Otherwise it has no effect. The purpose is that a given component doesn't know if a larger transaction is in progress or not. Therefore it asks the database transaction factory to rollback the transaction based on connection and the transaction factory since it is aware of the larger transaction may decide to rollback the transaction based on connection if no larger transaction is in progress or rollback it.

Specified by:
rollbackTransaction in interface DatabaseTransactionFactory
Parameters:
cntConnection - - the connection to rollback transaction for.
Throws:
java.sql.SQLException - - problem rolling back transaction

isTransactionInProgress

public boolean isTransactionInProgress()
                                throws javax.transaction.SystemException,
                                       OSSException
Test if transaction is in progress.

Returns:
boolean - if true then transaction is in progress for curren thread.
Throws:
javax.transaction.SystemException - - error occured while getting the transaction status
OSSException - - error occured while getting the transaction status

isTransactionMonitored

public boolean isTransactionMonitored()
Test if transaction should be monitored

Returns:
boolean - if true then transactions should be monitored and log should capture additional diagnostic information about each transaction

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.

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.

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.