org.apache.ojb.odmg
Class TransactionImpl

java.lang.Object
  extended byorg.apache.ojb.odmg.TransactionImpl
All Implemented Interfaces:
org.apache.ojb.broker.util.configuration.Configurable, HasBroker, org.apache.ojb.broker.accesslayer.MaterializationListener, Transaction, TransactionExt
Direct Known Subclasses:
J2EETransactionImpl

public class TransactionImpl
extends java.lang.Object
implements Transaction, org.apache.ojb.broker.accesslayer.MaterializationListener, org.apache.ojb.broker.util.configuration.Configurable, TransactionExt

Implementation of Transaction for org.odmg.Transaction.

Version:
$Id: TransactionImpl.java,v 1.53 2004/02/10 15:28:18 arminw Exp $
Author:
Thomas Mahler & David Dixon-Peugh, Matthew Baird, Armin Waibel

Field Summary
 
Fields inherited from interface org.odmg.Transaction
READ, UPGRADE, WRITE
 
Constructor Summary
TransactionImpl(DatabaseImpl theCurrentDB)
          Creates new Transaction
 
Method Summary
 void abort()
          Abort and close the transaction.
 void afterMaterialization(org.apache.ojb.broker.accesslayer.IndirectionHandler handler, java.lang.Object materializedObject)
          this callback is invoked after an Object is materialized within an IndirectionHandler.
 void beforeMaterialization(org.apache.ojb.broker.accesslayer.IndirectionHandler handler, Identity oid)
          this callback is invoked before an Object is materialized within an IndirectionHandler.
 void begin()
          Start a transaction.
 void checkpoint()
          Commit the transaction, but reopen the transaction, retaining all locks.
 void commit()
          Commit and close the transaction.
 void configure(org.apache.ojb.broker.util.configuration.Configuration config)
           
 void flush()
           Calling flush flushes persistent object modifications made within the ODMG transaction since the last checkpoint to the underlying database transaction, but does commit the database transaction.
 DatabaseImpl getAssociatedDatabase()
          Returns the associated database
 PersistenceBroker getBroker()
          Gets the broker associated with the transaction.
 java.lang.String getGUID()
           
 java.lang.Object getObjectByIdentity(Identity id)
          Get object by identity.
 boolean isDeleted(Identity id)
          Checks if the object with the given identity has been deleted within the transaction.
 boolean isOpen()
          Determine whether the transaction is open or not.
 void join()
          Attach the caller's thread to this Transaction and detach the thread from any former Transaction the thread may have been associated with.
 void leave()
          Detach the caller's thread from this Transaction , but do not attach the thread to another Transaction .
 void lock(java.lang.Object obj, int lockMode)
          Upgrade the lock on the given object to the given lock mode.
 void markDelete(java.lang.Object anObject)
          marks an object for deletion without locking the object.
 void markDirty(java.lang.Object anObject)
          marks an object as dirty without locking the object.
 void setImplicitLocking(boolean value)
          This method can be used to activate or deactivate the implicit locking mechanism for the current transaction.
 boolean tryLock(java.lang.Object obj, int lockMode)
          Upgrade the lock on the given object to the given lock mode.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TransactionImpl

public TransactionImpl(DatabaseImpl theCurrentDB)
Creates new Transaction

Parameters:
theCurrentDB - - create a transaction that is associated with the database.
Method Detail

getAssociatedDatabase

public DatabaseImpl getAssociatedDatabase()
Returns the associated database


isOpen

public boolean isOpen()
Determine whether the transaction is open or not. A transaction is open if a call has been made to begin , but a subsequent call to either commit or abort has not been made.

Specified by:
isOpen in interface Transaction
Returns:
True if the transaction is open, otherwise false.

join

public void join()
Attach the caller's thread to this Transaction and detach the thread from any former Transaction the thread may have been associated with.

Specified by:
join in interface Transaction

lock

public void lock(java.lang.Object obj,
                 int lockMode)
          throws LockNotGrantedException
Upgrade the lock on the given object to the given lock mode. The call has no effect if the object's current lock is already at or above that level of lock mode.

Specified by:
lock in interface Transaction
Parameters:
obj - object to acquire a lock on.
lockMode - lock mode to acquire. The lock modes are READ , UPGRADE , and WRITE .
Throws:
LockNotGrantedException - Description of Exception

leave

public void leave()
Detach the caller's thread from this Transaction , but do not attach the thread to another Transaction .

Specified by:
leave in interface Transaction

checkpoint

public void checkpoint()
Commit the transaction, but reopen the transaction, retaining all locks. Calling checkpoint commits persistent object modifications made within the transaction since the last checkpoint to the database. The transaction retains all locks it held on those objects at the time the checkpoint was invoked.

Specified by:
checkpoint in interface Transaction

flush

public void flush()
Description copied from interface: TransactionExt

Calling flush flushes persistent object modifications made within the ODMG transaction since the last checkpoint to the underlying database transaction, but does commit the database transaction. The ODMG transaction retains all locks it held on those objects at the time the flush was invoked.

This method is very similair to Transaction.checkpoint().

Specified by:
flush in interface TransactionExt
See Also:
TransactionExt.flush()

markDelete

public void markDelete(java.lang.Object anObject)
Description copied from interface: TransactionExt
marks an object for deletion without locking the object.

Specified by:
markDelete in interface TransactionExt
Parameters:
anObject - Object to be marked
See Also:
TransactionExt.markDelete(java.lang.Object)

markDirty

public void markDirty(java.lang.Object anObject)
Description copied from interface: TransactionExt
marks an object as dirty without locking the object.

Specified by:
markDirty in interface TransactionExt
Parameters:
anObject - Object to be marked
See Also:
TransactionExt.markDirty(java.lang.Object)

tryLock

public boolean tryLock(java.lang.Object obj,
                       int lockMode)
Upgrade the lock on the given object to the given lock mode. Method tryLock is the same as lock except it returns a boolean indicating whether the lock was granted instead of generating an exception.

Specified by:
tryLock in interface Transaction
Parameters:
obj - Description of Parameter
lockMode - Description of Parameter
Returns:
Description of the Returned Value , UPGRADE , and WRITE .

commit

public void commit()
Commit and close the transaction. Calling commit commits to the database all persistent object modifications within the transaction and releases any locks held by the transaction. A persistent object modification is an update of any field of an existing persistent object, or an update or creation of a new named object in the database. If a persistent object modification results in a reference from an existing persistent object to a transient object, the transient object is moved to the database, and all references to it updated accordingly. Note that the act of moving a transient object to the database may create still more persistent references to transient objects, so its referents must be examined and moved as well. This process continues until the database contains no references to transient objects, a condition that is guaranteed as part of transaction commit. Committing a transaction does not remove from memory transient objects created during the transaction. The updateObjectList contains a list of all objects for which this transaction has write privledge to. We need to update these objects.

Specified by:
commit in interface Transaction

abort

public void abort()
Abort and close the transaction. Calling abort abandons all persistent object modifications and releases the associated locks. Aborting a transaction does not restore the state of modified transient objects

Specified by:
abort in interface Transaction

begin

public void begin()
Start a transaction. Calling begin multiple times on the same transaction object, without an intervening call to commit or abort , causes the exception TransactionInProgressException to be thrown on the second and subsequent calls. Operations executed before a transaction has been opened, or before reopening after a transaction is aborted or committed, have undefined results; these may throw a TransactionNotInProgressException exception.

Specified by:
begin in interface Transaction

getGUID

public java.lang.String getGUID()

getObjectByIdentity

public java.lang.Object getObjectByIdentity(Identity id)
                                     throws PersistenceBrokerException
Get object by identity. First lookup among objects registered in the transaction, then in persistent storage.

Parameters:
id - The identity
Returns:
The object
Throws:
PersistenceBrokerException

isDeleted

public boolean isDeleted(Identity id)
Checks if the object with the given identity has been deleted within the transaction.

Parameters:
id - The identity
Returns:
true if the object has been deleted
Throws:
PersistenceBrokerException

beforeMaterialization

public void beforeMaterialization(org.apache.ojb.broker.accesslayer.IndirectionHandler handler,
                                  Identity oid)
this callback is invoked before an Object is materialized within an IndirectionHandler.

Specified by:
beforeMaterialization in interface org.apache.ojb.broker.accesslayer.MaterializationListener
Parameters:
handler - the invoking handler
oid - the identity of the object to be materialized

afterMaterialization

public void afterMaterialization(org.apache.ojb.broker.accesslayer.IndirectionHandler handler,
                                 java.lang.Object materializedObject)
this callback is invoked after an Object is materialized within an IndirectionHandler. this callback allows to defer registration of objects until it's really neccessary.

Specified by:
afterMaterialization in interface org.apache.ojb.broker.accesslayer.MaterializationListener
Parameters:
handler - the invoking handler
materializedObject - the materialized Object

getBroker

public PersistenceBroker getBroker()
Gets the broker associated with the transaction. MBAIRD: only return the associated broker if the transaction is open, if it's closed, throw a TransactionNotInProgressException. If we allow brokers to be reaquired by an already closed transaction, there is a very good chance the broker will be leaked as the doClose() method of transactionImpl will never be called and thus the broker will never be closed and returned to the pool.

Specified by:
getBroker in interface HasBroker
Returns:
Returns a PersistenceBroker
Throws:
TransactionNotInProgressException - is the transaction is not open;

configure

public void configure(org.apache.ojb.broker.util.configuration.Configuration config)
               throws org.apache.ojb.broker.util.configuration.ConfigurationException
Specified by:
configure in interface org.apache.ojb.broker.util.configuration.Configurable
Throws:
org.apache.ojb.broker.util.configuration.ConfigurationException

setImplicitLocking

public void setImplicitLocking(boolean value)
Description copied from interface: TransactionExt
This method can be used to activate or deactivate the implicit locking mechanism for the current transaction. turning of implicit locking may improve performance but requires additional care to make sure all changed objects are properly registered to the transaction.

Specified by:
setImplicitLocking in interface TransactionExt
Parameters:
value - if set to true implicit locking is enabled, if false, implicit locking is disabled.
See Also:
TransactionExt.setImplicitLocking(boolean)


Authors: Thomas Mahler and others. (C) 2000 - 2003 Apache Software Foundation
All rights reserved. Published under the Apache License.
http://db.apache.org/ojb
Version: 1.0.rc5, 2003-12-14