org.castor.persist

Class AbstractTransactionContext

Implemented Interfaces:
TransactionContext
Known Direct Subclasses:
GlobalTransactionContext, LocalTransactionContext

public abstract class AbstractTransactionContext
extends java.lang.Object
implements TransactionContext

A transaction context is required in order to perform operations against the database. The transaction context is mapped to an API transaction or an XA transaction. The only way to begin a new transaction is through the creation of a new transaction context. A transaction context is created from an implementation class directly or through XAResourceImpl.
Version:
$Revision: 6230 $ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
Authors:
Assaf Arkin
Ralf Joachim
Werner Guttmann
Gregory Block
Since:
1.0

Constructor Summary

AbstractTransactionContext(Database db)
Create a new transaction context.

Method Summary

void
addTxSynchronizable(TxSynchronizable synchronizable)
protected void
clearConnections()
void
close()
protected abstract void
closeConnections()
The derived class must implement this method and close all the connections used in this transaction.
void
commit()
protected abstract void
commitConnections()
The derived class must implement this method and commit all the connections used in this transaction.
protected Iterator
connectionsIterator()
void
create(ClassMolder molder, Object object, OID depended)
protected abstract Connection
createConnection(LockEngine engine)
void
delete(Object object)
void
expireCache(ClassMolder molder, Identity identity)
Object
fetch(ClassMolder molder, Identity identity, AccessMode suggestedAccessMode)
ClassLoader
getClassLoader()
Connection
getConnection(LockEngine engine)
DbMetaInfo
getConnectionInfo(LockEngine engine)
Database
getDatabase()
int
getLockTimeout()
String
getNamedQuery(ClassMolder molder, String name)
int
getStatus()
int
getTransactionTimeout()
ObjectLock
getWaitOnLock()
boolean
isAutoStore()
boolean
isCached(ClassMolder molder, Class cls, Identity identity)
boolean
isCreated(Object object)
boolean
isDeleted(Object object)
boolean
isDeletedByOID(OID oid)
boolean
isDepended(OID master, Object dependent)
boolean
isLocked(Class cls, Identity identity, LockEngine lockEngine)
Returns true if the object given is locked.
boolean
isOpen()
boolean
isPersistent(Object object)
boolean
isReadOnly(Object object)
boolean
isRecorded(Object object)
boolean
isUpdateCacheNeeded(Object object)
boolean
isUpdatePersistNeeded(Object object)
Iterator
iterateReadWriteObjectsInTransaction()
Object
load(Identity identity, ProposedEntity proposedObject, AccessMode suggestedAccessMode)
Object
load(Identity identity, ProposedEntity proposedObject, AccessMode suggestedAccessMode, QueryResults results)
void
markCreate(ClassMolder molder, Object object, OID rootObjectOID)
void
markModified(Object object, boolean updatePersist, boolean updateCache)
boolean
markUpdate(ClassMolder molder, Object object, OID depended)
boolean
prepare()
QueryResults
query(LockEngine engine, PersistenceQuery query, AccessMode accessMode, boolean scrollable)
void
removeTxSynchronizable(TxSynchronizable synchronizable)
void
rollback()
protected abstract void
rollbackConnections()
The derived class must implement this method and rollback all the connections used in this transaction.
void
setAutoStore(boolean autoStore)
void
setCallback(CallbackInterceptor callback)
void
setInstanceFactory(InstanceFactory factory)
void
setLockTimeout(int timeout)
void
setStatus(int status)
void
setTransactionTimeout(int timeout)
void
setWaitOnLock(ObjectLock lock)
void
update(ClassMolder molder, Object object, OID depended)
void
writeLock(Object object, int timeout)

Constructor Details

AbstractTransactionContext

public AbstractTransactionContext(Database db)
Create a new transaction context. This method is used by the explicit transaction model.
Parameters:
db - Database instance

Method Details

addTxSynchronizable

public final void addTxSynchronizable(TxSynchronizable synchronizable)
Specified by:
addTxSynchronizable in interface TransactionContext

clearConnections

protected final void clearConnections()

close

public final void close()
            throws TransactionAbortedException
Specified by:
close in interface TransactionContext

closeConnections

protected abstract void closeConnections()
            throws TransactionAbortedException
The derived class must implement this method and close all the connections used in this transaction.
Throws:
TransactionAbortedException - The transaction could not close all the connections.

commit

public final void commit()
            throws TransactionAbortedException
Specified by:
commit in interface TransactionContext

commitConnections

protected abstract void commitConnections()
            throws TransactionAbortedException
The derived class must implement this method and commit all the connections used in this transaction. If the transaction could not commit fully or partially, this method will throw an TransactionAbortedException, causing a rollback to occur as the next step.
Throws:
TransactionAbortedException - The transaction could not commit fully or partially and should be rolled back.

connectionsIterator

protected final Iterator connectionsIterator()

create

public final void create(ClassMolder molder,
                         Object object,
                         OID depended)
            throws PersistenceException
Specified by:
create in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.create( org.exolab.castor.persist.ClassMolder, java.lang.Object, org.exolab.castor.persist.OID)

createConnection

protected abstract Connection createConnection(LockEngine engine)
            throws PersistenceException

delete

public final void delete(Object object)
            throws PersistenceException
Specified by:
delete in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.delete(java.lang.Object)

expireCache

public final void expireCache(ClassMolder molder,
                              Identity identity)
            throws PersistenceException
Specified by:
expireCache in interface TransactionContext

fetch

public final Object fetch(ClassMolder molder,
                          Identity identity,
                          AccessMode suggestedAccessMode)
            throws PersistenceException
Specified by:
fetch in interface TransactionContext

getClassLoader

public final ClassLoader getClassLoader()
Specified by:
getClassLoader in interface TransactionContext

getConnection

public final Connection getConnection(LockEngine engine)
            throws PersistenceException
Specified by:
getConnection in interface TransactionContext

getConnectionInfo

public final DbMetaInfo getConnectionInfo(LockEngine engine)
            throws PersistenceException
Specified by:
getConnectionInfo in interface TransactionContext

getDatabase

public final Database getDatabase()
Specified by:
getDatabase in interface TransactionContext

getLockTimeout

public final int getLockTimeout()
Specified by:
getLockTimeout in interface TransactionContext

getNamedQuery

public String getNamedQuery(ClassMolder molder,
                            String name)
            throws QueryException
Specified by:
getNamedQuery in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.getNamedQuery( org.exolab.castor.persist.ClassMolder, java.lang.String)

getStatus

public final int getStatus()
Specified by:
getStatus in interface TransactionContext

getTransactionTimeout

public final int getTransactionTimeout()
Specified by:
getTransactionTimeout in interface TransactionContext

getWaitOnLock

public final ObjectLock getWaitOnLock()
Specified by:
getWaitOnLock in interface TransactionContext

isAutoStore

public final boolean isAutoStore()
Specified by:
isAutoStore in interface TransactionContext

isCached

public final boolean isCached(ClassMolder molder,
                              Class cls,
                              Identity identity)
            throws PersistenceException
Specified by:
isCached in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.isCached( org.exolab.castor.persist.ClassMolder, java.lang.Class, org.exolab.castor.persist.spi.Identity)

isCreated

public final boolean isCreated(Object object)
Specified by:
isCreated in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.isCreated(java.lang.Object)

isDeleted

public final boolean isDeleted(Object object)
Specified by:
isDeleted in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.isDeleted(java.lang.Object)

isDeletedByOID

public final boolean isDeletedByOID(OID oid)
Specified by:
isDeletedByOID in interface TransactionContext

isDepended

public final boolean isDepended(OID master,
                                Object dependent)
Specified by:
isDepended in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.isDepended( org.exolab.castor.persist.OID, java.lang.Object)

isLocked

public final boolean isLocked(Class cls,
                              Identity identity,
                              LockEngine lockEngine)
Returns true if the object given is locked.
Specified by:
isLocked in interface TransactionContext
Parameters:
cls - Class instance of the object to be investigated.
identity - Identity of the object to be investigated.
lockEngine - Current LcokEngine instance
Returns:
True if the object in question is locked.

isOpen

public final boolean isOpen()
Specified by:
isOpen in interface TransactionContext

isPersistent

public final boolean isPersistent(Object object)
Specified by:
isPersistent in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.isPersistent(java.lang.Object)

isReadOnly

public final boolean isReadOnly(Object object)
Specified by:
isReadOnly in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.isReadOnly(java.lang.Object)

isRecorded

public final boolean isRecorded(Object object)
Specified by:
isRecorded in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.isRecorded(java.lang.Object)

isUpdateCacheNeeded

public final boolean isUpdateCacheNeeded(Object object)
Specified by:
isUpdateCacheNeeded in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.isUpdateCacheNeeded(java.lang.Object)

isUpdatePersistNeeded

public final boolean isUpdatePersistNeeded(Object object)
Specified by:
isUpdatePersistNeeded in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.isUpdatePersistNeeded(java.lang.Object)

iterateReadWriteObjectsInTransaction

public final Iterator iterateReadWriteObjectsInTransaction()
Specified by:
iterateReadWriteObjectsInTransaction in interface TransactionContext

load

public final Object load(Identity identity,
                         ProposedEntity proposedObject,
                         AccessMode suggestedAccessMode)
            throws PersistenceException
Specified by:
load in interface TransactionContext

load

public final Object load(Identity identity,
                         ProposedEntity proposedObject,
                         AccessMode suggestedAccessMode,
                         QueryResults results)
            throws PersistenceException
Specified by:
load in interface TransactionContext

markCreate

public final void markCreate(ClassMolder molder,
                             Object object,
                             OID rootObjectOID)
            throws PersistenceException
Specified by:
markCreate in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.markCreate( org.exolab.castor.persist.ClassMolder, java.lang.Object, org.exolab.castor.persist.OID)

markModified

public final void markModified(Object object,
                               boolean updatePersist,
                               boolean updateCache)
Specified by:
markModified in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.markModified( java.lang.Object, boolean, boolean)

markUpdate

public final boolean markUpdate(ClassMolder molder,
                                Object object,
                                OID depended)
            throws PersistenceException
Specified by:
markUpdate in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.markUpdate( org.exolab.castor.persist.ClassMolder, java.lang.Object, org.exolab.castor.persist.OID)

prepare

public final boolean prepare()
            throws TransactionAbortedException
Specified by:
prepare in interface TransactionContext

query

public final QueryResults query(LockEngine engine,
                                PersistenceQuery query,
                                AccessMode accessMode,
                                boolean scrollable)
            throws PersistenceException
Specified by:
query in interface TransactionContext

removeTxSynchronizable

public final void removeTxSynchronizable(TxSynchronizable synchronizable)
Specified by:
removeTxSynchronizable in interface TransactionContext

rollback

public final void rollback()
Specified by:
rollback in interface TransactionContext

rollbackConnections

protected abstract void rollbackConnections()
The derived class must implement this method and rollback all the connections used in this transaction. The connections may be closed, as they will not be reused in this transaction. This operation is guaranteed to succeed.

setAutoStore

public final void setAutoStore(boolean autoStore)
Specified by:
setAutoStore in interface TransactionContext

setCallback

public final void setCallback(CallbackInterceptor callback)
Specified by:
setCallback in interface TransactionContext

setInstanceFactory

public final void setInstanceFactory(InstanceFactory factory)
Specified by:
setInstanceFactory in interface TransactionContext

setLockTimeout

public final void setLockTimeout(int timeout)
Specified by:
setLockTimeout in interface TransactionContext

setStatus

public final void setStatus(int status)
Specified by:
setStatus in interface TransactionContext

setTransactionTimeout

public final void setTransactionTimeout(int timeout)
Specified by:
setTransactionTimeout in interface TransactionContext

setWaitOnLock

public final void setWaitOnLock(ObjectLock lock)
Specified by:
setWaitOnLock in interface TransactionContext

update

public final void update(ClassMolder molder,
                         Object object,
                         OID depended)
            throws PersistenceException
Specified by:
update in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.update( org.exolab.castor.persist.ClassMolder, java.lang.Object, org.exolab.castor.persist.OID)

writeLock

public final void writeLock(Object object,
                            int timeout)
            throws PersistenceException
Specified by:
writeLock in interface TransactionContext
See Also:
org.castor.persist.TransactionContext.writeLock(java.lang.Object, int)

Intalio Inc. (C) 1999-2006. All rights reserved http://www.intalio.com