|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.exolab.castor.persist.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
.
Nested Class Summary | |
static class |
TransactionContext.ObjectEntry
A transaction records all objects accessed during the lifetime of the transaction in this record (queries and created). |
Field Summary | |
static int |
OBJECT_STATE_HOLLOW
|
static int |
OBJECT_STATE_PERSISTENT
|
static int |
OBJECT_STATE_PERSISTENT_DELETED
|
static int |
OBJECT_STATE_PERSISTENT_NEW
|
static int |
OBJECT_STATE_PERSISTENT_NEW_DELETED
|
static int |
OBJECT_STATE_READ_ONLY
|
static int |
OBJECT_STATE_TRANSIENT
|
Constructor Summary | |
TransactionContext(Database db)
Create a new transaction context. |
|
TransactionContext(Database db,
javax.transaction.Transaction transaction)
|
Method Summary | |
(package private) TransactionContext.ObjectEntry |
addObjectEntry(OID oid,
java.lang.Object object)
Adds a new entry recording the use of the object in this transaction. |
void |
addTxSynchronizable(TxSynchronizable synchronizable)
Register a listener which wants to synchronize its state to the state of the transaction. |
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. |
void |
create(LockEngine engine,
ClassMolder molder,
java.lang.Object object,
OID depended)
Creates a new object in persistent storage. |
void |
delete(java.lang.Object object)
Deletes the object from persistent storage. |
void |
expireCache(LockEngine engine,
ClassMolder molder,
java.lang.Object identity)
Expire object from the cache. |
java.lang.Object |
fetch(LockEngine engine,
ClassMolder molder,
java.lang.Object identity,
AccessMode suggestedAccessMode)
|
java.lang.ClassLoader |
getClassLoader()
Get the current application ClassLoader. |
abstract java.lang.Object |
getConnection(LockEngine engine)
The derived class must implement this method and return an open connection for the specified engine. |
abstract DbMetaInfo |
getConnectionInfo(LockEngine engine)
Returns meta-data related to the RDBMS used. |
Database |
getDatabase()
|
java.lang.Object |
getIdentity(java.lang.Object object)
Returns the object's identity. |
int |
getLockTimeout()
Returns the timeout waiting to acquire a lock. |
java.util.Enumeration |
getObjectEntries()
Expose an enumeration of the commited object entries to allow TxSynchronizable to iterate through the objects. |
(package private) TransactionContext.ObjectEntry |
getObjectEntry(LockEngine engine,
OID oid)
Retrieves the object entry for the specified object. |
(package private) TransactionContext.ObjectEntry |
getObjectEntry(java.lang.Object object)
Returns the entry for the object from the object. |
int |
getObjectState(java.lang.Object object)
|
(package private) TransactionContext.ObjectEntry |
getReadOnlyObjectEntry(OID oid)
|
PersistenceInfoGroup |
getScope()
|
int |
getStatus()
Returns the status of this transaction. |
int |
getTransactionTimeout()
Returns the timeout of this transaction. |
(package private) ObjectLock |
getWaitOnLock()
Returns the lock which this transaction attempts to acquire. |
protected javax.transaction.xa.Xid |
getXid()
|
boolean |
isAutoStore()
Test if autoStore options is enabled or not. |
boolean |
isCached(LockEngine engine,
ClassMolder molder,
java.lang.Class cls,
java.lang.Object identity)
|
boolean |
isDeleted(java.lang.Object object)
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 |
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)
|
boolean |
isRecorded(java.lang.Object object)
Returns true if the object is previously queried/loaded/update/create in this transaction |
java.lang.Object |
load(LockEngine engine,
ClassMolder molder,
java.lang.Object identity,
java.lang.Object objectToBeLoaded,
AccessMode suggestedAccessMode)
Load an object for use within the transaction. |
java.lang.Object |
load(LockEngine engine,
ClassMolder molder,
java.lang.Object identity,
java.lang.Object objectToBeLoaded,
AccessMode suggestedAccessMode,
QueryResults results)
Load an object for use within the transaction. |
(package private) void |
makeReadOnly(java.lang.Object object)
Makes the object read-only: move it to the hashtable of readonly objects The object must be already in the transaction. |
void |
markCreate(LockEngine engine,
ClassMolder molder,
java.lang.Object object,
OID depended)
Walk a data object tree starting from the specified object, and mark all object to be created. |
(package private) void |
markDelete(LockEngine engine,
java.lang.Class type,
java.lang.Object identity)
Marks an object for deletion. |
void |
markModified(java.lang.Object object,
boolean updatePersist,
boolean updateCache)
|
boolean |
markUpdate(LockEngine engine,
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)
|
QueryResults |
query(LockEngine engine,
PersistenceQuery query,
AccessMode accessMode,
boolean scrollable)
Perform a query using the query mechanism and in the specified access mode. |
(package private) TransactionContext.ObjectEntry |
rehash(java.lang.Object object,
OID oid)
|
void |
release(java.lang.Object object)
Releases the lock granted on the object. |
(package private) TransactionContext.ObjectEntry |
removeObjectEntry(java.lang.Object object)
Removes the entry for an object and returns it. |
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)
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 |
setStatusActive()
Sets the status of the current transaction to STATUS_ATIVE |
void |
setTransactionTimeout(int timeout)
Sets the timeout of this transaction. |
(package private) void |
setWaitOnLock(ObjectLock lock)
Indicates which lock this transaction is waiting for. |
void |
softLock(java.lang.Object object,
int timeout)
Acquire a write lock on the object. |
(package private) static short |
toDatabaseAccessMode(AccessMode mode)
Converts AccessMode constant to Database short constant |
protected void |
txcommitted()
Inform all registered listeners that the transaction was committed. |
protected void |
txrolledback()
Inform all registered listeners that the transaction was rolled back. |
void |
update(LockEngine engine,
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static int OBJECT_STATE_TRANSIENT
public static int OBJECT_STATE_HOLLOW
public static int OBJECT_STATE_READ_ONLY
public static int OBJECT_STATE_PERSISTENT
public static int OBJECT_STATE_PERSISTENT_NEW
public static int OBJECT_STATE_PERSISTENT_DELETED
public static int OBJECT_STATE_PERSISTENT_NEW_DELETED
Constructor Detail |
public TransactionContext(Database db)
public TransactionContext(Database db, javax.transaction.Transaction transaction) throws javax.transaction.SystemException
Method Detail |
public void addTxSynchronizable(TxSynchronizable synchronizable)
public void removeTxSynchronizable(TxSynchronizable synchronizable)
addTxSynchronizable(org.exolab.castor.persist.TxSynchronizable)
protected void txcommitted()
protected void txrolledback()
public void setAutoStore(boolean autoStore)
public boolean isAutoStore()
public void setCallback(CallbackInterceptor callback)
The interceptor is a callback that notifies data objects on persistent state events.
If callback interceptor is not overrided, events will be sent to data object that implements the org.exolab.castor.jdo.Persistent interface.
callback
- The callback interceptor, null if disabledpublic void setInstanceFactory(InstanceFactory factory)
The factory is used to obatain a new instance of data object when it is needed during loading.
public PersistenceInfoGroup getScope()
public void setTransactionTimeout(int timeout)
public int getTransactionTimeout()
public int getLockTimeout()
public void setLockTimeout(int timeout)
public void setStatusActive()
public abstract java.lang.Object getConnection(LockEngine engine) throws PersistenceException
engine
- The persistence engine
PersistenceException
- An error occured talking to the
persistence enginepublic abstract DbMetaInfo getConnectionInfo(LockEngine engine) throws PersistenceException
engine
- LockEngine instance used.
PersistenceException
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 backprotected abstract void closeConnections() throws TransactionAbortedException
TransactionAbortedException
- The transaction could not
close all the connectionsprotected abstract void rollbackConnections()
public java.lang.Object fetch(LockEngine engine, ClassMolder molder, java.lang.Object identity, AccessMode suggestedAccessMode) throws ObjectNotFoundException, LockNotGrantedException, PersistenceException
ObjectNotFoundException
LockNotGrantedException
PersistenceException
public java.lang.Object load(LockEngine engine, ClassMolder molder, java.lang.Object identity, java.lang.Object objectToBeLoaded, AccessMode suggestedAccessMode) throws ObjectNotFoundException, LockNotGrantedException, PersistenceException
This method is similar to fetch(org.exolab.castor.persist.LockEngine, org.exolab.castor.persist.ClassMolder, java.lang.Object, 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.
engine
- The persistence enginemolder
- The class persistence molderidentity
- The object's identityobjectToBeLoaded
- The object to fetch (single instance per transaction)suggestedAccessMode
- The access mode (see AccessMode
)
the values in persistent storage
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on object
ObjectNotFoundException
- The object was not found in
persistent storage
PersistenceException
- An error reported by the
persistence enginepublic java.lang.Object load(LockEngine engine, ClassMolder molder, java.lang.Object identity, java.lang.Object objectToBeLoaded, AccessMode suggestedAccessMode, QueryResults results) throws ObjectNotFoundException, LockNotGrantedException, PersistenceException
This method work the same as load(LockEngine,ClassMolder,Object,Object,AccessMode)
,
except a QueryResults can be specified.
engine
- The persistence enginemolder
- The class persistence molderidentity
- The object's identityobjectToBeLoaded
- The object to fetch (single instance per transaction)suggestedAccessMode
- The access mode (see AccessMode
)
the values in persistent storageresults
- The QueryResult that the data to be loaded from.
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on object
ObjectNotFoundException
- The object was not found in
persistent storage
PersistenceException
- An error reported by the
persistence enginepublic QueryResults query(LockEngine engine, PersistenceQuery query, AccessMode accessMode, boolean scrollable) throws QueryException, PersistenceException
engine
- The persistence enginequery
- A query against the persistence engineaccessMode
- The access mode
QueryException
- An invalid query
PersistenceException
- An error reported by the
persistence enginepublic QueryResults query(LockEngine engine, PersistenceQuery query, AccessMode accessMode) throws QueryException, PersistenceException
QueryException
PersistenceException
public void markCreate(LockEngine engine, ClassMolder molder, java.lang.Object object, OID depended) throws DuplicateIdentityException, PersistenceException
engine
- The persistence engineobject
- The object to persist
DuplicateIdentityException
- An object with this identity
already exists in persistent storage
PersistenceException
- An error reported by the
persistence engine
ClassNotPersistenceCapableException
- The class is not
persistent capablepublic void create(LockEngine engine, ClassMolder molder, java.lang.Object object, OID depended) throws DuplicateIdentityException, PersistenceException
engine
- The persistence enginemolder
- The molder of the creating classobject
- The object to persistdepended
- The master object's OID if exist
DuplicateIdentityException
- An object with this identity
already exists in persistent storage
PersistenceException
- An error reported by the
persistence engine
ClassNotPersistenceCapableException
- The class is not
persistent capablepublic boolean markUpdate(LockEngine engine, ClassMolder molder, java.lang.Object object, OID depended) throws DuplicateIdentityException, ObjectModifiedException, ClassNotPersistenceCapableException, PersistenceException
Update will also mark object to be created if the TIMESTAMP equals to NO_TIMESTAMP.
engine
- The persistence enginemolder
- The object's molderobject
- The object to persistdepended
- The master objects of the specified object to be
created if exisit
DuplicateIdentityException
- An object with this identity
already exists in persistent storage
PersistenceException
- An error reported by the
persistence engine
ClassNotPersistenceCapableException
- The class is not
persistent capable
ObjectModifiedException
- Dirty checking mechanism may immediately
report that the object was modified in the database during the long
transaction.public void update(LockEngine engine, ClassMolder molder, java.lang.Object object, OID depended) throws DuplicateIdentityException, ObjectModifiedException, ClassNotPersistenceCapableException, PersistenceException
Update will also mark object to be created if the TIMESTAMP equals to NO_TIMESTAMP.
engine
- The persistence enginemolder
- The object's molderobject
- The object to persistdepended
- The master objects of the specified object to be
created if exisit
DuplicateIdentityException
- An object with this identity
already exists in persistent storage
PersistenceException
- An error reported by the
persistence engine
ClassNotPersistenceCapableException
- The class is not
persistent capable
ObjectModifiedException
- Dirty checking mechanism may immediately
report that the object was modified in the database during the long
transaction.public void delete(java.lang.Object object) throws ObjectNotPersistentException, LockNotGrantedException, PersistenceException
object
- The object to delete from persistent storage
ObjectNotPersistentException
- The object has not been
queried or created in this transaction
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on object
PersistenceException
- An error reported by the
persistence enginepublic void writeLock(java.lang.Object object, int timeout) throws ObjectNotPersistentException, LockNotGrantedException, PersistenceException
object
- The object to locktimeout
- Timeout waiting to acquire lock, specified in
seconds, zero for no waiting, negative to use the default
timeout for this transaction
ObjectNotPersistentException
- The object has not been
queried or created in this transaction
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on object
PersistenceException
- An error reported by the
persistence enginepublic void markModified(java.lang.Object object, boolean updatePersist, boolean updateCache)
public void softLock(java.lang.Object object, int timeout) throws LockNotGrantedException, ObjectNotPersistentException
object
- The object to locktimeout
- Timeout waiting to acquire lock, specified in
seconds, zero for no waiting, negative to use the default
timeout for this transaction
ObjectNotPersistentException
- The object has not been
queried or created in this transaction
LockNotGrantedException
- Timeout or deadlock occured
attempting to acquire lock on objectpublic void release(java.lang.Object object) throws ObjectNotPersistentException, PersistenceException
object
- The object to release the lock
ObjectNotPersistentException
- The object was not queried
or created in this transaction
PersistenceException
- An error occured talking to the
persistence enginepublic boolean prepare() throws TransactionAbortedException
java.lang.IllegalStateException
- Method called if transaction is
not in the proper state to perform this operation
TransactionAbortedException
- The transaction has been
aborted due to inconsistency, duplicate object identity, error
with the persistence engine or any other reasonpublic void commit() throws TransactionAbortedException
prepare()
has returned successfully.
TransactionAbortedException
- The transaction has been
aborted due to inconsistency, duplicate object identity, error
with the persistence engine or any other reason
java.lang.IllegalStateException
- This method has been called
without calling prepare()
firstpublic java.util.Enumeration getObjectEntries()
public void rollback()
public void close() throws TransactionAbortedException
TransactionAbortedException
- The transaction has been
aborted due to inconsistency, duplicate object identity, error
with the persistence engine or any other reason
java.lang.IllegalStateException
- This method has been called
after the end of the transaction.public boolean isPersistent(java.lang.Object object)
object
- The object
public boolean isRecorded(java.lang.Object object)
public boolean isDepended(OID master, java.lang.Object dependent)
public java.lang.Object getIdentity(java.lang.Object object)
object
- The object
public int getStatus()
public boolean isOpen()
protected javax.transaction.xa.Xid getXid()
void setWaitOnLock(ObjectLock lock)
ObjectLock
before entering the temporary lock-acquire state.
lock
- The lock which this transaction attempts to acquireObjectLock getWaitOnLock()
public boolean isDeleted(java.lang.Object object)
public boolean isDeletedByOID(OID oid)
public int getObjectState(java.lang.Object object)
public java.lang.ClassLoader getClassLoader()
null
if none
has been providedvoid markDelete(LockEngine engine, java.lang.Class type, java.lang.Object identity) throws LockNotGrantedException, PersistenceException
LockNotGrantedException
PersistenceException
TransactionContext.ObjectEntry addObjectEntry(OID oid, java.lang.Object object)
object
- The object to recordoid
- The object's OIDTransactionContext.ObjectEntry getObjectEntry(LockEngine engine, OID oid)
engine
- The persistence engine used to create this objectoid
- The object's OID
TransactionContext.ObjectEntry rehash(java.lang.Object object, OID oid)
TransactionContext.ObjectEntry getObjectEntry(java.lang.Object object)
object
- The object to locate
public void expireCache(LockEngine engine, ClassMolder molder, java.lang.Object identity) throws PersistenceException, LockNotGrantedException
engine
- The persistence enginemolder
- The class persistence molderidentity
- The object's identity
PersistenceException
LockNotGrantedException
public boolean isCached(LockEngine engine, ClassMolder molder, java.lang.Class cls, java.lang.Object identity) throws PersistenceException
PersistenceException
TransactionContext.ObjectEntry removeObjectEntry(java.lang.Object object)
object
- The object to remove
void makeReadOnly(java.lang.Object object)
TransactionContext.ObjectEntry getReadOnlyObjectEntry(OID oid)
public boolean isReadOnly(java.lang.Object object)
static short toDatabaseAccessMode(AccessMode mode)
public Database getDatabase()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |