wt.pom
Class TransactionManager

java.lang.Object
  extended bywt.pom.TransactionManager
Direct Known Subclasses:
OracleTransactionManager

public class TransactionManager
extends Object

TransactionManager manages nested transactions for a user thread. An instance of TransactionManager is held by each user connection. The TransactionManager handles nested transaction blocks and only forwards the actual datastore commit when a commit which matchs an outer level start is received. If a commit is received which does not match a corresponding start, an exception is thrown. A rollback is invoked immediately and if the rollback occurs at a nested level, a "rollback in process" state is triggered. In this case, further start or commit actions will throw an exception until a rollback matching the outer block is received. The interface to transaction blocks is through wt.pom.Transaction.


 Example 1 - normal commit
    Transaction trx1 = new Transaction();
    trx1.start();
    anObj1.insert();
       Transaction trx2 = new Transaction();
       trx2.start();
       anObj2.delete();
       trx2.commit();       // commit is pending
    trx1.commit();          // commit happens

 Example 2 - rollback
    Transaction trx1 = new Transaction();
    trx1.start();
    anObj1.insert();
       Transaction trx2 = new Transaction();
       trx2.start();
       anObj2.delete();
       trx2.rollback();     // rollback happens
    trx1.rollback();        // transaction is cleared (commit not allowed)
 

See Also:
WTConnection, Transaction

Nested Class Summary
(package private) static class TransactionManager.BeforeCompletionTransactionListener
           
(package private) static class TransactionManager.FinishTransactionListener
           
(package private) static interface TransactionManager.FireTransactionListener
           
(package private) static class TransactionManager.NotifyCommitTransactionListener
           
(package private) static class TransactionManager.NotifyRollbackTransactionListener
           
 
Field Summary
(package private) static TransactionManager.BeforeCompletionTransactionListener BEFORE_COMPLETION
           
(package private) static BeforeCompletionValidationListener BEFORE_COMPLETION_VALIDATION_LISTENER
           
private  RefreshCache cache
           
private static String CLASSNAME
           
private  HashMap classoidmap
           
private  int count
           
static boolean DEBUG
           
(package private) static TransactionManager.FinishTransactionListener FINISH
           
private static DebugWriter LOG
           
private  HashMap map
           
(package private) static TransactionManager.NotifyCommitTransactionListener NOTIFY_COMMIT
           
(package private) static TransactionManager.NotifyRollbackTransactionListener NOTIFY_ROLLBACK
           
private  ArrayList pomOperationListeners
           
private static String RESOURCE
           
private  boolean rollbackInProgress
           
private  int transactionLevel
           
private  ArrayList transactionListeners
           
private  int transactionMode
           
private  ArrayList transactionStack
           
 
Constructor Summary
TransactionManager()
           
 
Method Summary
protected  void addEntryInCache(ObjectIdentifier a_oid)
           
 void addEntryInCache(Persistable a_obj)
          Adds the specified Persistable to the RefreshCache.
protected  void addPOMOperationListener(POMOperationListener listener)
           
protected  void addTransactionListener(TransactionListener listener)
           
protected  void commitTransaction(int aHandle)
          Commit a transaction flushing changes to the datastore.
protected  boolean containOidInCache(ObjectIdentifier a_oid)
           
private  void executeCommitTransaction(Savepoint a_savepoint)
           
private  void executeRollbackTransaction(Savepoint a_savepoint)
           
private  void executeTransactionOperation(boolean a_commit, Savepoint a_savepoint, String a_traceTimingName)
           
protected  List findAll(Object a_key)
          Returns a List of Transactions with a local Map that contains the specified key.
protected  Transaction findFirst(Object a_key)
          Returns the first Transaction with a local Map that contains the specified key.
protected  void fireTransactionListener(boolean callCommit)
           
(package private) static void fireTransactionListener(List a_listeners, TransactionManager.FireTransactionListener a_fireListener)
           
protected  List getContext()
          Returns Transactions context.
protected  Transaction getCurrentTransaction()
          Returns the current Transaction.
 Persistable getEntryFromCache(ObjectIdentifier a_oid, Persistable a_target)
          Returns a Persistable from the RefreshCache, if it exists.
protected  Map getGlobalTransactionMap()
          Returns the global Transaction Map.
protected  List getLocalPOMOperationListeners()
           
protected  boolean getrollbackInProgress()
           
private  Savepoint getSavepoint()
           
private  Savepoint getSavepoint(int a_level)
           
protected  int getTransactionId()
           
protected  int getTransactionLevel()
           
protected  boolean hasGlobalTransactionMap()
          Indicates if a global transaction Map exists.
protected  boolean isTransactionActive()
           
protected  void releaseSavepoint(Connection a_connection, Savepoint a_savepoint)
           
protected  void removeEntriesFromCache(String a_className)
           
protected  void removeEntryFromCache(ObjectIdentifier a_oid)
           
protected  void removeEntryFromCache(Persistable a_obj)
           
protected  void removePOMOperationListener(POMOperationListener listener)
           
protected  void removeTransactionListener(TransactionListener listener)
           
protected  void rollbackTransaction()
           
protected  void rollbackTransaction(int aHandle)
          Rollback a transaction cancelling pending changes to the datastore.
protected  void setrollbackInProgress(boolean state)
           
protected  void setTransactionIsolation(int a_mode)
           
protected  void setTransactionLevel(int level)
           
protected  int startTransaction(Transaction a_transaction)
          Start a transaction.
private  void validateCommit(int aHandle)
           
private  void validateStart()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLASSNAME

private static final String CLASSNAME

DEBUG

public static final boolean DEBUG

LOG

private static final DebugWriter LOG

transactionLevel

private int transactionLevel

transactionMode

private int transactionMode

rollbackInProgress

private boolean rollbackInProgress

transactionListeners

private ArrayList transactionListeners

pomOperationListeners

private ArrayList pomOperationListeners

cache

private RefreshCache cache

count

private int count

transactionStack

private ArrayList transactionStack

map

private HashMap map

classoidmap

private HashMap classoidmap

RESOURCE

private static final String RESOURCE
See Also:
Constant Field Values

FINISH

static final TransactionManager.FinishTransactionListener FINISH

BEFORE_COMPLETION

static final TransactionManager.BeforeCompletionTransactionListener BEFORE_COMPLETION

NOTIFY_COMMIT

static final TransactionManager.NotifyCommitTransactionListener NOTIFY_COMMIT

NOTIFY_ROLLBACK

static final TransactionManager.NotifyRollbackTransactionListener NOTIFY_ROLLBACK

BEFORE_COMPLETION_VALIDATION_LISTENER

static final BeforeCompletionValidationListener BEFORE_COMPLETION_VALIDATION_LISTENER
Constructor Detail

TransactionManager

public TransactionManager()
Method Detail

hasGlobalTransactionMap

protected boolean hasGlobalTransactionMap()
Indicates if a global transaction Map exists.


getGlobalTransactionMap

protected Map getGlobalTransactionMap()
Returns the global Transaction Map.


getCurrentTransaction

protected Transaction getCurrentTransaction()
Returns the current Transaction.

Returns:
current local Transaction or null if no Transaction exists.

findFirst

protected Transaction findFirst(Object a_key)
Returns the first Transaction with a local Map that contains the specified key. The Transaction stack is searched from inner-most to outer-most.


findAll

protected List findAll(Object a_key)
Returns a List of Transactions with a local Map that contains the specified key. The List is ordered from inner-most (index=0) to outer-most (index=size() - 1). If no keys are found, then a null value is returned.


getContext

protected List getContext()
Returns Transactions context.


startTransaction

protected int startTransaction(Transaction a_transaction)
                        throws PersistenceException
Start a transaction.

Returns:
transaction id
Throws:
PersistenceException - Occurs if the persistent object manager cannot start the transaction.

commitTransaction

protected void commitTransaction(int aHandle)
                          throws PersistenceException
Commit a transaction flushing changes to the datastore.

Throws:
PersistenceException - Occurs if the persistent object manager cannot end the transaction.

rollbackTransaction

protected void rollbackTransaction(int aHandle)
                            throws PersistenceException
Rollback a transaction cancelling pending changes to the datastore.

Throws:
PersistenceException - Occurs if the persistent object manager cannot drop the transaction.

rollbackTransaction

protected void rollbackTransaction()
                            throws PersistenceException
Throws:
PersistenceException

addEntryInCache

public void addEntryInCache(Persistable a_obj)
Adds the specified Persistable to the RefreshCache.

Parameters:
a_obj - Persistable object to add

addEntryInCache

protected void addEntryInCache(ObjectIdentifier a_oid)

removeEntryFromCache

protected void removeEntryFromCache(ObjectIdentifier a_oid)

removeEntryFromCache

protected void removeEntryFromCache(Persistable a_obj)

removeEntriesFromCache

protected void removeEntriesFromCache(String a_className)

containOidInCache

protected boolean containOidInCache(ObjectIdentifier a_oid)

getEntryFromCache

public Persistable getEntryFromCache(ObjectIdentifier a_oid,
                                     Persistable a_target)
Returns a Persistable from the RefreshCache, if it exists. The Persitable is specified by ObjectIdentfier. The optional target Persistable can be specified for an in-place refresh.

Parameters:
a_oid - ObjectIdentifier that specifies the Persistable
a_target - Persistable to use for in-place refresh (optional)

addPOMOperationListener

protected void addPOMOperationListener(POMOperationListener listener)
                                throws PersistenceException
Throws:
PersistenceException

removePOMOperationListener

protected void removePOMOperationListener(POMOperationListener listener)
                                   throws PersistenceException
Throws:
PersistenceException

getLocalPOMOperationListeners

protected List getLocalPOMOperationListeners()

addTransactionListener

protected void addTransactionListener(TransactionListener listener)
                               throws PersistenceException
Throws:
PersistenceException

removeTransactionListener

protected void removeTransactionListener(TransactionListener listener)
                                  throws PersistenceException
Throws:
PersistenceException

fireTransactionListener

protected void fireTransactionListener(boolean callCommit)
                                throws PersistenceException
Throws:
PersistenceException

getSavepoint

private Savepoint getSavepoint(int a_level)

getSavepoint

private Savepoint getSavepoint()

executeCommitTransaction

private void executeCommitTransaction(Savepoint a_savepoint)
                               throws PersistenceException
Throws:
PersistenceException

executeRollbackTransaction

private void executeRollbackTransaction(Savepoint a_savepoint)
                                 throws PersistenceException
Throws:
PersistenceException

executeTransactionOperation

private void executeTransactionOperation(boolean a_commit,
                                         Savepoint a_savepoint,
                                         String a_traceTimingName)
                                  throws PersistenceException
Throws:
PersistenceException

releaseSavepoint

protected void releaseSavepoint(Connection a_connection,
                                Savepoint a_savepoint)
                         throws SQLException
Throws:
SQLException

validateStart

private void validateStart()
                    throws PersistenceException
Throws:
PersistenceException

validateCommit

private void validateCommit(int aHandle)
                     throws PersistenceException
Throws:
PersistenceException

isTransactionActive

protected boolean isTransactionActive()

getTransactionId

protected int getTransactionId()

getTransactionLevel

protected int getTransactionLevel()

setTransactionLevel

protected void setTransactionLevel(int level)

getrollbackInProgress

protected boolean getrollbackInProgress()

setrollbackInProgress

protected void setrollbackInProgress(boolean state)

setTransactionIsolation

protected void setTransactionIsolation(int a_mode)
                                throws PersistenceException
Throws:
PersistenceException

fireTransactionListener

static void fireTransactionListener(List a_listeners,
                                    TransactionManager.FireTransactionListener a_fireListener)
                             throws PersistenceException
Throws:
PersistenceException