com.objectwave.transactionalSupport
Class TransactionLog

java.lang.Object
  |
  +--com.objectwave.transactionalSupport.TransactionLog
Direct Known Subclasses:
BrokerTransactionLog

public class TransactionLog
extends java.lang.Object

A key piece of a the TransactionalSupport is the transaction log. All changes made to an object are associated with a transaction log. If no transaction exists, changes are not logged and the transactional object is directly updated.

Version:
$Id: TransactionLog.java,v 2.3 2002/03/23 13:42:11 dave_hoag Exp $
Author:
Dave Hoag

Nested Class Summary
static class TransactionLog.Test
          Unit tests for the tranasaction log.
 
Field Summary
protected  boolean committing
           
protected  ObjectEditingView[] editedObjects
          It is a requirement that the editedObjects collection contain UNIQUE objects!!! No dups allowed.
protected  int editedObjectsCount
           
protected  ObjectEditingView lastObj
          A cache of the last object added to the editedObjects
protected  TransactionLog parentTransaction
           
protected  TransactionLog subTransaction
           
protected static TransactionManager transactionManager
           
 
Constructor Summary
TransactionLog()
           
 
Method Summary
protected  void actualCommit()
          Actually commit all of my known changes.
protected  void addObject(ObjectEditingView obj)
          Add the object to the list of modified transactions.
protected  void addSubTransaction(TransactionLog log)
          Create a nested transaction.
static void addTransactionSupport(java.lang.String name, java.lang.Class transactionClass)
          Register the 'name' with the class.
 void chainCommit()
          Similar to commit, however, the current transaction is not removed.
protected  void clearUpChanges()
          Remove the changes from this object.
 void commit()
          If this is a subtransaction (created via startTransaction) don't actually commit the changes.
protected  void commit(Session context)
          If using sessions, there is no need to manage a contextList.
protected  void commitRootLevelTransaction()
          This is a root level transaction, actually do what need to do to commit.
protected  void commitSubTransaction()
          A sub transaction just migrates changes to the parent transaction.
protected static boolean contains(java.lang.Object obj, ObjectEditingView[] v, int count)
          An identity contains.
 boolean contains(TransactionalObjectIF domainObject)
          Can the domainObject be found in the current transaction?
 void forceCommit()
          Commit the values ignoring any transaction conflicts.
static TransactionLog getCurrentInstance()
          Find the most nested transaction.
 java.util.ArrayList getEditedObjects()
           
static TransactionLog getNewTransaction(java.lang.String name)
          Attempt to create a new TransactionLog for the transaction type of 'name'.
 TransactionLog getParentTransaction()
          If I am a subtransaction, then I have a parent transaction.
 TransactionLog getSubTransaction()
          As a parent, I may have a subtransaction.
static boolean hasTransactions()
           
 void limitedRollback()
          Return the object back to it's original state, but do not discard the changes made in this transaction.
 void migrateChangesTo(TransactionLog parent)
          This was refactored from commit subtransaction.
protected  void removeObject(ObjectEditingView obj)
          Remove the obj as a modified object of this transaction.
protected  void reset()
          When not using session context we keep a hash collection of contexts, these need to be reset when a root level transaction is commited.
 void rollback()
          Return the object back to it's original state, and discard the changes made in this transaction.
protected  void rollback(Session context)
          Return the object back to it's original state, and discard the changes made in this transaction.
 void setAllowNesting(boolean b)
          Remove the final keyword on the allowNesting variable if this method is to be used.
static void setContext(java.lang.Object obj)
          Transactions can have multiple contexts.
protected static void setDefaultInstance(TransactionLog log)
          Use this method sparingly.
static void setTransactionManager(TransactionManager mgr)
          Allow one to change the TransactionManager.
static TransactionLog startRootTransaction(java.lang.String name, java.lang.Object context)
          Used to provide seperation between a particular transaction instance and the desire to have a transaction.
static TransactionLog startRootTransaction(java.lang.String name, Session session)
          Used to provide seperation between a particular transaction instance and the desire to have a transaction.
static void startRootTransaction(TransactionLog log, java.lang.Object context)
          Only use this method if you KNOW that you want the provided transaction to be a root transaction.
static TransactionLog startTransaction(java.lang.String name, java.lang.Object context)
          Used to provide seperation between a particular transaction instance and the desire to have a transaction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

transactionManager

protected static TransactionManager transactionManager

editedObjects

protected ObjectEditingView[] editedObjects
It is a requirement that the editedObjects collection contain UNIQUE objects!!! No dups allowed.


editedObjectsCount

protected int editedObjectsCount

committing

protected boolean committing

lastObj

protected transient ObjectEditingView lastObj
A cache of the last object added to the editedObjects


subTransaction

protected TransactionLog subTransaction

parentTransaction

protected TransactionLog parentTransaction
Constructor Detail

TransactionLog

public TransactionLog()
Method Detail

setTransactionManager

public static void setTransactionManager(TransactionManager mgr)
Allow one to change the TransactionManager.

Parameters:
mgr - The new TransactionManager value

setContext

public static void setContext(java.lang.Object obj)
Transactions can have multiple contexts. This may be driven by thread, by window activation, or some way I haven't even dreamed of.

Parameters:
obj - The new Context value

setDefaultInstance

protected static void setDefaultInstance(TransactionLog log)
Use this method sparingly. Good only for root transactions. Existing transactions could/would be lost. Actually, I now think that you shouldn't use this method. Start transaction works MUCH better.

Parameters:
log - The new DefaultInstance value

getCurrentInstance

public static TransactionLog getCurrentInstance()
Find the most nested transaction. This is the one without any subtransactions. The defaultInstance will always be the root transaction.

Returns:
The CurrentInstance value

getNewTransaction

public static TransactionLog getNewTransaction(java.lang.String name)
Attempt to create a new TransactionLog for the transaction type of 'name'.

Parameters:
name -
Returns:
The NewTransaction value

addTransactionSupport

public static void addTransactionSupport(java.lang.String name,
                                         java.lang.Class transactionClass)
Register the 'name' with the class. This will allow the application to create a transaction simply by specifying a transaction name. This seperates implementation from usage. Similar to Java's security support.

Parameters:
transactionClass - must be an instance of TransactionLog. Must also have a default constructor.
name - The feature to be added to the TransactionSupport attribute

hasTransactions

public static boolean hasTransactions()
Returns:

startRootTransaction

public static void startRootTransaction(TransactionLog log,
                                        java.lang.Object context)
Only use this method if you KNOW that you want the provided transaction to be a root transaction.

Parameters:
log - The transaction that is to be the root transaction for the provided context.
context - The context of the transaction.

startRootTransaction

public static TransactionLog startRootTransaction(java.lang.String name,
                                                  java.lang.Object context)
Used to provide seperation between a particular transaction instance and the desire to have a transaction. The 'name' must have a registered transaction type.

Parameters:
context - The context of the transaction.
name - The name of a registered transaction type.
Returns:
See Also:
addTransactionSupport(java.lang.String, java.lang.Class)

startRootTransaction

public static TransactionLog startRootTransaction(java.lang.String name,
                                                  Session session)
Used to provide seperation between a particular transaction instance and the desire to have a transaction. The 'name' must have a registered transaction type. This implementation is specific to session support.

Parameters:
name - The name of a registered transaction type.
session -
Returns:
See Also:
addTransactionSupport(java.lang.String, java.lang.Class)

startTransaction

public static TransactionLog startTransaction(java.lang.String name,
                                              java.lang.Object context)
Used to provide seperation between a particular transaction instance and the desire to have a transaction. The 'name' must have a registered transaction type.

Parameters:
context - The context of the transaction.
name - The name of a registered transaction type.
Returns:
See Also:
addTransactionSupport(java.lang.String, java.lang.Class)

contains

protected static final boolean contains(java.lang.Object obj,
                                        ObjectEditingView[] v,
                                        int count)
An identity contains.

Parameters:
obj - java.lang.Object
v -
count -
Returns:
boolean

setAllowNesting

public void setAllowNesting(boolean b)
Remove the final keyword on the allowNesting variable if this method is to be used.

Parameters:
b - The new AllowNesting value

getEditedObjects

public java.util.ArrayList getEditedObjects()
Returns:
Vector of all TransactionalObjects modified in this transaction.

getParentTransaction

public TransactionLog getParentTransaction()
If I am a subtransaction, then I have a parent transaction.

Returns:
The ParentTransaction value

getSubTransaction

public TransactionLog getSubTransaction()
As a parent, I may have a subtransaction.

Returns:
The SubTransaction value

chainCommit

public void chainCommit()
                 throws UpdateException
Similar to commit, however, the current transaction is not removed. The changes are simple commited and a 'new' transaction continues to exist.

Throws:
UpdateException

commit

public void commit()
            throws UpdateException
If this is a subtransaction (created via startTransaction) don't actually commit the changes. Just migrate them to the parent transaction.

Throws:
UpdateException

contains

public boolean contains(TransactionalObjectIF domainObject)
Can the domainObject be found in the current transaction?

Parameters:
domainObject - The object in question.
Returns:
True if domainObject was modified in this transaction.

forceCommit

public void forceCommit()
Commit the values ignoring any transaction conflicts.


limitedRollback

public void limitedRollback()
Return the object back to it's original state, but do not discard the changes made in this transaction.

See Also:
#rollit(boolean )

rollback

public void rollback()
Return the object back to it's original state, and discard the changes made in this transaction.


commitRootLevelTransaction

protected void commitRootLevelTransaction()
                                   throws UpdateException
This is a root level transaction, actually do what need to do to commit.

Throws:
UpdateException

clearUpChanges

protected void clearUpChanges()
Remove the changes from this object.


commitSubTransaction

protected void commitSubTransaction()
A sub transaction just migrates changes to the parent transaction. Assumes that the instance variable 'parentTransaction' is not null.


actualCommit

protected void actualCommit()
                     throws UpdateException
Actually commit all of my known changes. This should only happen for Parent (or root) transactions.

Throws:
UpdateException - Any exception that occured during the commit.

addObject

protected final void addObject(ObjectEditingView obj)
Add the object to the list of modified transactions. Note, I am using the keys to a hashtable as way to implement a 'Set' collection. There is one ObjectEditingView object per instance of TransactionalObject.

Parameters:
obj - The feature to be added to the Object attribute

addSubTransaction

protected void addSubTransaction(TransactionLog log)
Create a nested transaction.

Parameters:
log - The feature to be added to the SubTransaction attribute

commit

protected void commit(Session context)
               throws UpdateException
If using sessions, there is no need to manage a contextList.

Parameters:
context -
Throws:
UpdateException

removeObject

protected void removeObject(ObjectEditingView obj)
Remove the obj as a modified object of this transaction. This is an extremely rare operation. No where in the core code is method called.

Parameters:
obj - The object to remove from the list of edited objects.

reset

protected void reset()
When not using session context we keep a hash collection of contexts, these need to be reset when a root level transaction is commited.


rollback

protected void rollback(Session context)
Return the object back to it's original state, and discard the changes made in this transaction.

Parameters:
context -

migrateChangesTo

public void migrateChangesTo(TransactionLog parent)
This was refactored from commit subtransaction. This method takes changes in the edited objects and pushes them into the specified parent transaction log.

Parameters:
parent -