org.apache.lenya.transaction
Class UnitOfWorkImpl

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.lenya.transaction.UnitOfWorkImpl
All Implemented Interfaces:
org.apache.avalon.framework.logger.LogEnabled, UnitOfWork

public class UnitOfWorkImpl
extends org.apache.avalon.framework.logger.AbstractLogEnabled
implements UnitOfWork

Default implementation of a unit of work.

Version:
$Id: UnitOfWorkImpl.java 574827 2007-09-12 08:00:57Z andreas $

Constructor Summary
UnitOfWorkImpl(IdentityMap map, Identity identity, org.apache.avalon.framework.logger.Logger logger)
          Ctor.
 
Method Summary
 void commit()
          Commit the transaction.
 Lock createLock(Lockable lockable, int version)
          Creates a lock.
protected  Identity getIdentity()
           
 IdentityMap getIdentityMap()
           
 boolean isDirty(Transactionable transactionable)
           
 void registerDirty(Transactionable object)
          Registers an object as modified.
 void registerNew(Transactionable object)
          Registers an object as new.
 void registerRemoved(Transactionable object)
          Registers an object as removed.
 void removeLock(Lockable lockable)
          Removes a lock.
protected  void resetTransaction()
           
 void rollback()
          Rollback the transaction.
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UnitOfWorkImpl

public UnitOfWorkImpl(IdentityMap map,
                      Identity identity,
                      org.apache.avalon.framework.logger.Logger logger)
Ctor.

Parameters:
map - The identity map to use.
identity - The identity.
logger - The logger.
Method Detail

getIdentityMap

public IdentityMap getIdentityMap()
Returns:
The identity map.

registerNew

public void registerNew(Transactionable object)
                 throws TransactionException
Description copied from interface: UnitOfWork
Registers an object as new.

Specified by:
registerNew in interface UnitOfWork
Parameters:
object - The object.
Throws:
TransactionException - if an error occurs.
See Also:
UnitOfWork.registerNew(org.apache.lenya.transaction.Transactionable)

registerDirty

public void registerDirty(Transactionable object)
                   throws TransactionException
Description copied from interface: UnitOfWork
Registers an object as modified.

Specified by:
registerDirty in interface UnitOfWork
Parameters:
object - The object.
Throws:
TransactionException
LockException
See Also:
UnitOfWork.registerDirty(org.apache.lenya.transaction.Transactionable)

registerRemoved

public void registerRemoved(Transactionable object)
                     throws TransactionException
Description copied from interface: UnitOfWork
Registers an object as removed.

Specified by:
registerRemoved in interface UnitOfWork
Parameters:
object - The object.
Throws:
TransactionException - if an error occurs.
See Also:
UnitOfWork.registerRemoved(org.apache.lenya.transaction.Transactionable)

commit

public void commit()
            throws TransactionException
Commit the transaction. We lock this method for the whole class to avoid synchronization problems.

Specified by:
commit in interface UnitOfWork
Throws:
TransactionException - if an error occurs.
See Also:
UnitOfWork.commit()

resetTransaction

protected void resetTransaction()

getIdentity

protected Identity getIdentity()

isDirty

public boolean isDirty(Transactionable transactionable)
Specified by:
isDirty in interface UnitOfWork
Parameters:
transactionable - A transactionable.
Returns:
If the transactionable is registered as dirty.
See Also:
UnitOfWork.isDirty(org.apache.lenya.transaction.Transactionable)

rollback

public void rollback()
              throws TransactionException
Rollback the transaction. We lock this method for the whole class to avoid synchronization problems.

Specified by:
rollback in interface UnitOfWork
Throws:
TransactionException - if an error occurs.
See Also:
UnitOfWork.rollback()

createLock

public Lock createLock(Lockable lockable,
                       int version)
                throws TransactionException
Description copied from interface: UnitOfWork
Creates a lock.

Specified by:
createLock in interface UnitOfWork
Parameters:
lockable - The lockable.
version - The version.
Returns:
A lock.
Throws:
TransactionException - if a lock is already placed on this transactionable.

removeLock

public void removeLock(Lockable lockable)
                throws TransactionException
Description copied from interface: UnitOfWork
Removes a lock.

Specified by:
removeLock in interface UnitOfWork
Parameters:
lockable - The lockable.
Throws:
TransactionException - if no lock is placed on this transactionable.


Copyright 1999-2006 Apache Software Foundation. All Rights Reserved.