TransactionContext
GlobalTransactionContext
, LocalTransactionContext
public abstract class AbstractTransactionContext extends java.lang.Object implements TransactionContext
XAResourceImpl
.Constructor | Description |
---|---|
AbstractTransactionContext(Database db) |
Create a new transaction context.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addTxSynchronizable(TxSynchronizable synchronizable) |
Register a listener which wants to synchronize its state to the state of the
transaction.
|
protected void |
clearConnections() |
|
void |
close() |
Closes all Connections.
|
protected abstract void |
closeConnections() |
The derived class must implement this method and close all the connections
used in this transaction.
|
void |
commit() |
Commits all changes and closes the transaction releasing all locks on all
objects.
|
protected abstract void |
commitConnections() |
The derived class must implement this method and commit all the connections
used in this transaction.
|
protected java.util.Iterator<java.sql.Connection> |
connectionsIterator() |
|
void |
create(ClassMolder molder,
java.lang.Object object,
OID depended) |
Creates a new object in persistent storage.
|
protected abstract java.sql.Connection |
createConnection(LockEngine engine) |
|
void |
delete(java.lang.Object object) |
Deletes the object from persistent storage.
|
void |
expireCache(ClassMolder molder,
Identity identity) |
Expire object from the cache.
|
java.lang.Object |
fetch(ClassMolder molder,
Identity identity,
AccessMode suggestedAccessMode) |
|
java.lang.ClassLoader |
getClassLoader() |
Get the current application ClassLoader.
|
java.sql.Connection |
getConnection(LockEngine engine) |
Return an open connection for the specified engine.
|
DbMetaInfo |
getConnectionInfo(LockEngine engine) |
Returns meta-data related to the RDBMS used.
|
Database |
getDatabase() |
|
InstanceFactory |
getInstanceFactory() |
|
int |
getLockTimeout() |
Returns the timeout waiting to acquire a lock.
|
NamedNativeQuery |
getNamedNativeQuery(ClassMolder molder,
java.lang.String name) |
Returns a NamedNativeQuery instance query based upon a named query as defined in the
mapping file.
|
java.lang.String |
getNamedQuery(ClassMolder molder,
java.lang.String name) |
Creates an OQL query based upon a named query as defined in the
mapping file.
|
int |
getStatus() |
Returns the status of this transaction.
|
int |
getTransactionTimeout() |
Returns the timeout of this transaction.
|
ObjectLock |
getWaitOnLock() |
Returns the lock which this transaction attempts to acquire.
|
boolean |
isAutoStore() |
Test if autoStore option is enabled or not.
|
boolean |
isCached(ClassMolder molder,
java.lang.Class cls,
Identity identity) |
|
boolean |
isCreated(java.lang.Object object) |
Returns true if the object is marked as created in this transaction.
|
boolean |
isDeleted(java.lang.Object object) |
Returns true if and only if the specified object is loaded or created in this
transaction and is deleted.
|
boolean |
isDeletedByOID(OID oid) |
|
boolean |
isDepended(OID master,
java.lang.Object dependent) |
|
boolean |
isLocked(java.lang.Class cls,
Identity identity,
LockEngine lockEngine) |
Returns true if the object given is locked.
|
boolean |
isOpen() |
Returns true if the transaction is open.
|
boolean |
isPersistent(java.lang.Object object) |
Returns true if the object is persistent in this transaction.
|
boolean |
isReadOnly(java.lang.Object object) |
Check to see whether this transaction considers an object to have been marked
read-only.
|
boolean |
isRecorded(java.lang.Object object) |
Returns true if the object has been previously queried/loaded/updated/created in
this transaction.
|
boolean |
isUpdateCacheNeeded(java.lang.Object object) |
Retrieves the state of the object in this transaction.
|
boolean |
isUpdatePersistNeeded(java.lang.Object object) |
Retrieves the state of the object in this transaction.
|
java.util.Iterator |
iterateReadWriteObjectsInTransaction() |
Expose an enumeration of the commited object entries to allow TxSynchronizable
to iterate through the objects.
|
java.lang.Object |
load(Identity identity,
ProposedEntity proposedObject,
AccessMode suggestedAccessMode) |
Load an object for use within the transaction.
|
java.lang.Object |
load(Identity identity,
ProposedEntity proposedObject,
AccessMode suggestedAccessMode,
QueryResults results) |
Load an object for use within the transaction.
|
void |
markCreate(ClassMolder molder,
java.lang.Object object,
OID rootObjectOID) |
Walk a data object tree starting from the specified object, and mark all
objects to be created.
|
void |
markModified(java.lang.Object object,
boolean updatePersist,
boolean updateCache) |
|
boolean |
markUpdate(ClassMolder molder,
java.lang.Object object,
OID depended) |
Update a new object in persistent storage and returns the object's OID.
|
boolean |
prepare() |
Prepares the transaction prior to committing it.
|
QueryResults |
query(LockEngine engine,
PersistenceQuery query,
AccessMode accessMode,
boolean scrollable) |
Perform a query using the query mechanism with the specified access mode.
|
void |
removeTxSynchronizable(TxSynchronizable synchronizable) |
Unregister a listener which wants to synchronize its state to the state of the
transaction.
|
void |
rollback() |
Rolls back all changes and closes the transaction releasing all locks on
all objects.
|
protected abstract void |
rollbackConnections() |
The derived class must implement this method and rollback all the
connections used in this transaction.
|
void |
setAutoStore(boolean autoStore) |
Enable or disable autoStore.
|
void |
setCallback(CallbackInterceptor callback) |
Overrides the default callback interceptor by a custom interceptor for this
database source.
|
void |
setInstanceFactory(InstanceFactory factory) |
Overrides the default instance factory by a custom one for this database
source.
|
void |
setLockTimeout(int timeout) |
Sets the timeout waiting to acquire a lock.
|
void |
setStatus(int status) |
Sets the status of the current transaction to the given one.
|
void |
setTransactionTimeout(int timeout) |
Sets the timeout of this transaction.
|
void |
setWaitOnLock(ObjectLock lock) |
Indicates which lock this transaction is waiting for.
|
void |
trackObject(ClassMolder molder,
OID oid,
java.lang.Object object) |
|
void |
untrackObject(java.lang.Object object) |
|
void |
update(ClassMolder molder,
java.lang.Object object,
OID depended) |
Update a new object in persistent storage and returns the object's OID.
|
void |
writeLock(java.lang.Object object,
int timeout) |
Acquire a write lock on the object.
|
public AbstractTransactionContext(Database db)
db
- Database instancepublic final void addTxSynchronizable(TxSynchronizable synchronizable)
addTxSynchronizable
in interface TransactionContext
synchronizable
- The TxSynchronizable implementation to register.TransactionContext.addTxSynchronizable(
org.exolab.castor.persist.TxSynchronizable)
public final void removeTxSynchronizable(TxSynchronizable synchronizable)
removeTxSynchronizable
in interface TransactionContext
synchronizable
- The TxSynchronizable implementation to unregister.TransactionContext.removeTxSynchronizable(
org.exolab.castor.persist.TxSynchronizable)
public final void setAutoStore(boolean autoStore)
setAutoStore
in interface TransactionContext
autoStore
- When set to true
autoStore will be enabled.TransactionContext.setAutoStore(boolean)
public final boolean isAutoStore()
isAutoStore
in interface TransactionContext
true
if autoStore option is enabled.TransactionContext.isAutoStore()
public final void setCallback(CallbackInterceptor callback)
The interceptor is a callback that notifies data objects on persistent state events.
If callback interceptor is not overriden, events will be sent to data object that implements the org.exolab.castor.jdo.Persistent interface.
setCallback
in interface TransactionContext
callback
- The callback interceptor, disabled if null.TransactionContext.setCallback(
org.exolab.castor.persist.spi.CallbackInterceptor)
public final void setInstanceFactory(InstanceFactory factory)
The factory is used to obatain a new instance of data object when it is needed during loading.
setInstanceFactory
in interface TransactionContext
factory
- The instanceFactory to be used, disable if null.TransactionContext.setInstanceFactory(
org.exolab.castor.persist.spi.InstanceFactory)
public final InstanceFactory getInstanceFactory()
public final void setTransactionTimeout(int timeout)
setTransactionTimeout
in interface TransactionContext
timeout
- The timeout for this transaction in seconds.TransactionContext.setTransactionTimeout(int)
public final int getTransactionTimeout()
getTransactionTimeout
in interface TransactionContext
TransactionContext.getTransactionTimeout()
public final int getLockTimeout()
getLockTimeout
in interface TransactionContext
TransactionContext.getLockTimeout()
public final void setLockTimeout(int timeout)
setLockTimeout
in interface TransactionContext
timeout
- The timeout waiting to acquire a lock in seconds.TransactionContext.setLockTimeout(int)
public final void setStatus(int status)
setStatus
in interface TransactionContext
status
- The status to set for this transaction.TransactionContext.setStatus(int)
public final java.sql.Connection getConnection(LockEngine engine) throws ConnectionFailedException
getConnection
in interface TransactionContext
engine
- The persistence engine.ConnectionFailedException
TransactionContext.getConnection(
org.exolab.castor.persist.LockEngine)
protected abstract java.sql.Connection createConnection(LockEngine engine) throws ConnectionFailedException
ConnectionFailedException
protected final java.util.Iterator<java.sql.Connection> connectionsIterator()
protected final void clearConnections()
protected abstract void commitConnections() throws TransactionAbortedException
TransactionAbortedException
,
causing a rollback to occur as the next step.TransactionAbortedException
- The transaction could not commit fully
or partially and should be rolled back.protected abstract void closeConnections() throws TransactionAbortedException
TransactionAbortedException
- The transaction could not close all the
connections.protected abstract void rollbackConnections()
public final DbMetaInfo getConnectionInfo(LockEngine engine) throws PersistenceException
getConnectionInfo
in interface TransactionContext
engine
- LockEngine instance used.PersistenceException
- An error occured talking to the persistence engine.TransactionContext.getConnectionInfo(
org.exolab.castor.persist.LockEngine)
public final java.lang.Object fetch(ClassMolder molder, Identity identity, AccessMode suggestedAccessMode) throws PersistenceException
fetch
in interface TransactionContext
PersistenceException
#fetch(org.exolab.castor.persist.ClassMolder,
org.exolab.castor.persist.spi.Identity,
org.exolab.castor.mapping.AccessMode)
public final java.lang.Object load(Identity identity, ProposedEntity proposedObject, AccessMode suggestedAccessMode) throws PersistenceException
This method is similar to TransactionContext.fetch(org.exolab.castor.persist.ClassMolder, org.exolab.castor.persist.spi.Identity, org.exolab.castor.mapping.AccessMode)
except that it will load the object
only once within a transaction and always return the same instance.
If the object is loaded for read-only then no lock is acquired and updates to the object are not reflected at commit time. If the object is loaded for read-write then a read lock is acquired (unless timeout or deadlock detected) and the object is stored at commit time. The object is then considered persistent and may be deleted or upgraded to write lock. If the object is loaded for exclusive access then a write lock is acquired and the object is synchronized with the persistent copy.
Attempting to load the object twice in the same transaction, once with exclusive lock and once with read-write lock will result in an exception.
load
in interface TransactionContext
identity
- The object's identity.proposedObject
- The object to fetch (single instance per transaction).suggestedAccessMode
- The access mode (see AccessMode
) the values
in persistent storage.PersistenceException
- Timeout or deadlock occured attempting to acquire
lock on object. The object was not found in persistent storage. An error
reported by the persistence engine.TransactionContext.load(
org.exolab.castor.persist.spi.Identity, org.castor.persist.ProposedEntity,
org.exolab.castor.mapping.AccessMode)
public final java.lang.Object load(Identity identity, ProposedEntity proposedObject, AccessMode suggestedAccessMode, QueryResults results) throws PersistenceException
In addition to TransactionContext.load(Identity,ProposedEntity,AccessMode)
a QueryResults can be specified.
load
in interface TransactionContext
identity
- The object's identity.proposedObject
- The object to fetch (single instance per transaction).suggestedAccessMode
- The access mode (see AccessMode
) the values
in persistent storage.results
- The QueryResult that the data to be loaded from.PersistenceException
- Timeout or deadlock occured attempting to acquire
lock on object. The object was not found in persistent storage. An error
reported by the persistence engine.TransactionContext.load(
org.exolab.castor.persist.spi.Identity, org.castor.persist.ProposedEntity,
org.exolab.castor.mapping.AccessMode, org.exolab.castor.persist.QueryResults)
public void untrackObject(java.lang.Object object)
public void trackObject(ClassMolder molder, OID oid, java.lang.Object object)
public final QueryResults query(LockEngine engine, PersistenceQuery query, AccessMode accessMode, boolean scrollable) throws PersistenceException
query
in interface TransactionContext
engine
- The persistence engine.query
- A query against the persistence engine.accessMode
- The access mode.scrollable
- The db cursor mode.PersistenceException
- An error reported by the persistence engine or
an invalid query.TransactionContext.query(
org.exolab.castor.persist.LockEngine,
org.exolab.castor.persist.spi.PersistenceQuery,
org.exolab.castor.mapping.AccessMode, boolean)
public final void markCreate(ClassMolder molder, java.lang.Object object, OID rootObjectOID) throws PersistenceException
markCreate
in interface TransactionContext
molder
- The class persistence molder.object
- The object to persist.rootObjectOID
- The OID of the root object to start walking.PersistenceException
- An object with this identity already exists in
persistent storage. The class is not persistent capable. An error
reported by the persistence engine.TransactionContext.markCreate(
org.exolab.castor.persist.ClassMolder,
java.lang.Object, org.exolab.castor.persist.OID)
public final void create(ClassMolder molder, java.lang.Object object, OID depended) throws PersistenceException
create
in interface TransactionContext
molder
- The molder of the creating class.object
- The object to persist.depended
- The master object's OID if exist.PersistenceException
- An object with this identity already exists in
persistent storage. The class is not persistent capable. An error
reported by the persistence engine.TransactionContext.create(
org.exolab.castor.persist.ClassMolder,
java.lang.Object, org.exolab.castor.persist.OID)
public final boolean markUpdate(ClassMolder molder, java.lang.Object object, OID depended) throws PersistenceException
Update will also mark objects to be created if the TIMESTAMP equals to NO_TIMESTAMP.
markUpdate
in interface TransactionContext
molder
- The object's molder.object
- The object to persist.depended
- The master objects of the specified object to be created if
exisit.PersistenceException
- An object with this identity already exists in
persistent storage. The class is not persistent capable. Dirty checking
mechanism may immediately report that the object was modified in the
database during the long transaction. An error reported by the
persistence engine.TransactionContext.markUpdate(
org.exolab.castor.persist.ClassMolder,
java.lang.Object, org.exolab.castor.persist.OID)
public final void update(ClassMolder molder, java.lang.Object object, OID depended) throws PersistenceException
Update will also mark objects to be created if the TIMESTAMP equals to NO_TIMESTAMP.
update
in interface TransactionContext
molder
- The object's molder.object
- The object to persist.depended
- The master objects of the specified object to be created if
exisit.PersistenceException
- An object with this identity already exists in
persistent storage. The class is not persistent capable. Dirty checking
mechanism may immediately report that the object was modified in the
database during the long transaction. An error reported by the persistence
engine.TransactionContext.update(
org.exolab.castor.persist.ClassMolder,
java.lang.Object, org.exolab.castor.persist.OID)
public final void delete(java.lang.Object object) throws PersistenceException
delete
in interface TransactionContext
object
- The object to delete from persistent storage.PersistenceException
- The object has not been queried or created in this
transaction. Timeout or deadlock occured attempting to acquire lock on
object. An error reported by the persistence engine.TransactionContext.delete(java.lang.Object)
public final void writeLock(java.lang.Object object, int timeout) throws PersistenceException
writeLock
in interface TransactionContext
object
- The object to lock.timeout
- Timeout waiting to acquire lock, specified in seconds, zero
for no waiting, negative to use the default timeout for this transaction.PersistenceException
- The object has not been queried or created in this
transaction. Timeout or deadlock occured attempting to acquire lock on
object. An error reported by the persistence engine.TransactionContext.writeLock(java.lang.Object, int)
public final void markModified(java.lang.Object object, boolean updatePersist, boolean updateCache)
markModified
in interface TransactionContext
TransactionContext.markModified(
java.lang.Object, boolean, boolean)
public final boolean prepare() throws TransactionAbortedException
prepare
in interface TransactionContext
TransactionAbortedException
- The transaction has been aborted due to
inconsistency, duplicate object identity, error with the persistence
engine or any other reason.TransactionContext.prepare()
public final void commit() throws TransactionAbortedException
TransactionContext.prepare()
has returned successfully. Throws an IllegalStateException
when called without calling TransactionContext.prepare()
first.commit
in interface TransactionContext
TransactionAbortedException
- The transaction has been aborted due to
inconsistency, duplicate object identity, error with the persistence
engine or any other reason.TransactionContext.commit()
public final java.util.Iterator iterateReadWriteObjectsInTransaction()
iterateReadWriteObjectsInTransaction
in interface TransactionContext
TransactionContext.iterateReadWriteObjectsInTransaction()
public final void rollback()
rollback
in interface TransactionContext
TransactionContext.rollback()
public final void close() throws TransactionAbortedException
close
in interface TransactionContext
TransactionAbortedException
- The transaction has been aborted due to
inconsistency, duplicate object identity, error with the persistence
engine or any other reason.TransactionContext.close()
public final boolean isCreated(java.lang.Object object)
isCreated
in interface TransactionContext
object
- The object to test the state of in this transaction.true
if the object is marked as created within this
transaction.TransactionContext.isCreated(java.lang.Object)
public final boolean isUpdateCacheNeeded(java.lang.Object object)
isUpdateCacheNeeded
in interface TransactionContext
object
- The object to test the state of in this transaction.true
if the object is recorded in this transaction with
the requested state.TransactionContext.isUpdateCacheNeeded(java.lang.Object)
public final boolean isUpdatePersistNeeded(java.lang.Object object)
isUpdatePersistNeeded
in interface TransactionContext
object
- The object to test the state of in this transaction.true
if the object is recorded in this transaction with
the requested state.TransactionContext.isUpdatePersistNeeded(java.lang.Object)
public final boolean isPersistent(java.lang.Object object)
isPersistent
in interface TransactionContext
object
- The object.true
if persistent in transaction.TransactionContext.isPersistent(java.lang.Object)
public final boolean isRecorded(java.lang.Object object)
isRecorded
in interface TransactionContext
object
- The object to investigate.true
if recorded in this transaction.TransactionContext.isRecorded(java.lang.Object)
public final boolean isDepended(OID master, java.lang.Object dependent)
isDepended
in interface TransactionContext
TransactionContext.isDepended(
org.exolab.castor.persist.OID, java.lang.Object)
public final int getStatus()
getStatus
in interface TransactionContext
TransactionContext.getStatus()
public final boolean isOpen()
isOpen
in interface TransactionContext
true
if the transaction is open.TransactionContext.isOpen()
public final void setWaitOnLock(ObjectLock lock)
ObjectLock
before entering the temporary lock-acquire state.setWaitOnLock
in interface TransactionContext
lock
- The lock which this transaction attempts to acquireTransactionContext.setWaitOnLock(
org.exolab.castor.persist.ObjectLock)
public final ObjectLock getWaitOnLock()
getWaitOnLock
in interface TransactionContext
TransactionContext.getWaitOnLock()
public final boolean isDeleted(java.lang.Object object)
isDeleted
in interface TransactionContext
object
- The object to test the state of in this transaction.true
if the object is deleted.TransactionContext.isDeleted(java.lang.Object)
public final boolean isDeletedByOID(OID oid)
isDeletedByOID
in interface TransactionContext
TransactionContext.isDeletedByOID(
org.exolab.castor.persist.OID)
public final java.lang.ClassLoader getClassLoader()
getClassLoader
in interface TransactionContext
null
if none
has been providedTransactionContext.getClassLoader()
public final void expireCache(ClassMolder molder, Identity identity) throws PersistenceException
expireCache
in interface TransactionContext
molder
- The class persistence molder.identity
- The object's identity.PersistenceException
- If identity is null or any problem that happens
during expiration of cache values.TransactionContext.expireCache(
org.exolab.castor.persist.ClassMolder,
org.exolab.castor.persist.spi.Identity)
public final boolean isCached(ClassMolder molder, java.lang.Class cls, Identity identity) throws PersistenceException
isCached
in interface TransactionContext
PersistenceException
TransactionContext.isCached(
org.exolab.castor.persist.ClassMolder,
java.lang.Class, org.exolab.castor.persist.spi.Identity)
public final boolean isReadOnly(java.lang.Object object)
isReadOnly
in interface TransactionContext
object
- The object to test for read-only statustrue
if the object is marked read-only in this transaction;
otherwise, false
.TransactionContext.isReadOnly(java.lang.Object)
public final Database getDatabase()
getDatabase
in interface TransactionContext
TransactionContext.getDatabase()
public final boolean isLocked(java.lang.Class cls, Identity identity, LockEngine lockEngine)
isLocked
in interface TransactionContext
cls
- Class instance of the object to be investigated.identity
- Identity of the object to be investigated.lockEngine
- Current LcokEngine instancepublic final java.lang.String getNamedQuery(ClassMolder molder, java.lang.String name) throws QueryException
getNamedQuery
in interface TransactionContext
molder
- Specific class molder.name
- Name of the (named) query to create.QueryException
- If the named query can not be foundpublic final NamedNativeQuery getNamedNativeQuery(ClassMolder molder, java.lang.String name) throws QueryException
getNamedNativeQuery
in interface TransactionContext
molder
- Specific class molder.name
- Name of the (named) query to create.QueryException
- If the named query can not be found.Intalio Inc. (C) 1999-2008. All rights reserved http://www.intalio.com