addObjectEntry
(package private) TransactionContext.ObjectEntry addObjectEntry(OID oid,
Object object)
Adds a new entry recording the use of the object in this
transaction. This is a copy of the object that is only visible
(or deleted) in the context of this transaction. The object is
not persisted if it has not been recorded in this transaction.
oid
- The object's OIDobject
- The object to record
addTxSynchronizable
public void addTxSynchronizable(TxSynchronizable synchronizable)
Register a listener which wants to synchronize its state
to the state of the transaction.
close
public void close()
throws TransactionAbortedException
Closes all Connections.
Must be called before the end of the transaction in EJB environment or after commit in standalone case.
TransactionAbortedException
- The transaction has been
aborted due to inconsistency, duplicate object identity, error
with the persistence engine or any other reason
closeConnections
protected abstract void closeConnections()
throws TransactionAbortedException
The derived class must implement this method and close all the
connections used in this transaction.
commit
public void commit()
throws TransactionAbortedException
Commits all changes and closes the transaction releasing all
locks on all objects. All objects are now transient. Must be
called after a call to
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
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.
create
public void create(LockEngine engine,
ClassMolder molder,
Object object,
OID depended)
throws DuplicateIdentityException,
PersistenceException
Creates a new object in persistent storage. The object will
be persisted only if the transaction commits. If an identity
is provided then duplicate identity check happens in this
method, if no identity is provided then duplicate identity
check occurs when the transaction completes and the object
is not visible in this transaction.
engine
- The persistence enginemolder
- The molder of the creating classobject
- The object to persistdepended
- The master object's OID if exist
delete
public void delete(Object object)
throws ObjectNotPersistentException,
LockNotGrantedException,
PersistenceException
Deletes the object from persistent storage. The deletion will
take effect only if the transaction is committed, but the
object is no longer viewable for the current transaction and
locks for access from other transactions will block until this
transaction completes. A write lock is acquired in order to
assure the object can be deleted.
object
- The object to delete from persistent storage
getClassLoader
public ClassLoader getClassLoader()
Get the current application ClassLoader.
- the current ClassLoader's instance.
null
if none
has been provided
getConnection
public abstract Object getConnection(LockEngine engine)
throws PersistenceException
The derived class must implement this method and return an open
connection for the specified engine. The connection should be
created only one for a given engine in the same transaction.
engine
- The persistence engine
getDatabase
public Database getDatabase()
getIdentity
public Object getIdentity(Object object)
Returns the object's identity. If the identity was determined when
the object was created, or if the object was retrieved, that identity
is returned. If the identity has been modified, this will not be
reflected until the transaction commits. Null is returned if the
identity is null, the object does not have any identity, or the
object is not persistent.
- The object's identity, or null
getLockTimeout
public int getLockTimeout()
Returns the timeout waiting to acquire a lock. The timeout is
specified in seconds.
getObjectEntry
(package private) TransactionContext.ObjectEntry getObjectEntry(Object object)
Returns the entry for the object from the object. If the entry
does not exist, the object is not persistent in this
transaction. An entry will be returned even if the object has
been deleted in this transaction.
object
- The object to locate
- The object's entry or null if not persistent
getObjectEntry
(package private) TransactionContext.ObjectEntry getObjectEntry(LockEngine engine,
OID oid)
Retrieves the object entry for the specified object.
engine
- The persistence engine used to create this objectoid
- The object's OID
getObjectState
public int getObjectState(Object object)
getStatus
public int getStatus()
Returns the status of this transaction.
getTransactionTimeout
public int getTransactionTimeout()
Returns the timeout of this transaction. The timeout is specified
in seconds.
getWaitOnLock
(package private) ObjectLock getWaitOnLock()
Returns the lock which this transaction attempts to acquire.
- The lock which this transaction attempts to acquire
getXid
protected Xid getXid()
isAutoStore
public boolean isAutoStore()
Test if autoStore options is enabled or not.
isDeleted
public boolean isDeleted(Object object)
True if and only if the specified object is loaded or created
in this transaction and is deleted.
isDeletedByOID
public boolean isDeletedByOID(OID oid)
isDepended
public boolean isDepended(OID master,
Object dependent)
isOpen
public boolean isOpen()
Returns true if the transaction is open.
isPersistent
public boolean isPersistent(Object object)
Returns true if the object is persistent in this transaction.
- True if persistent in transaction
isReadOnly
public boolean isReadOnly(Object object)
isRecorded
public boolean isRecorded(Object object)
Returns true if the object is previously queried/loaded/update/create
in this transaction
load
public Object load(LockEngine engine,
ClassMolder molder,
Object identity,
Object objectToBeLoaded,
AccessMode suggestedAccessMode)
throws ObjectNotFoundException,
LockNotGrantedException,
PersistenceException
Load an object for use within the transaction. Multiple access
to the same object within the transaction will return the same
object instance (except for read-only access).
This method is similar to
fetch(LockEngine,ClassMolder,Object,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 identity
load
public Object load(LockEngine engine,
ClassMolder molder,
Object identity,
Object objectToBeLoaded,
AccessMode suggestedAccessMode,
QueryResults results)
throws ObjectNotFoundException,
LockNotGrantedException,
PersistenceException
Load an object for use within the transaction. Multiple access
to the same object within the transaction will return the same
object instance (except for read-only access).
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 identityresults
- The QueryResult that the data to be loaded from.
makeReadOnly
(package private) void makeReadOnly(Object object)
Makes the object read-only: move it to the hashtable of readonly objects
The object must be already in the transaction.
Readonly objects should be unique in bounds of the transaction,
otherwise they may be loaded twice (e.g.: one dependent object
contains reference to another).
markDelete
(package private) void markDelete(LockEngine engine,
Class type,
Object identity)
throws LockNotGrantedException,
PersistenceException
Marks an object for deletion. Used during the preparation stage to
delete an attached relation by marking the object for deletion
(if not already deleted) and preparing it a second time.
markModified
public void markModified(Object object,
boolean updatePersist,
boolean updateCache)
markUpdate
public boolean markUpdate(LockEngine engine,
ClassMolder molder,
Object object,
OID depended)
throws DuplicateIdentityException,
ObjectModifiedException,
ClassNotPersistenceCapableException,
PersistenceException
Update a new object in persistent storage and returns the
object's OID. The object will be persisted only if the
transaction commits. If an identity is provided then duplicate
identity check happens in this method, if no identity is
provided then duplicate identity check occurs when the
transaction completes and the object is not visible in this
transaction.
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
- true if the object is marked to be created
prepare
public boolean prepare()
throws TransactionAbortedException
Prepares the transaction prior to committing it. Indicates
whether the transaction is read-only (i.e. no modified objects),
can commit, or an error has occured and the transaction must
be rolled back. This method performs actual storage into the
persistence storage. Multiple calls to this method can be done,
and do not release locks, allowing checkpoint to
occur.
- True if the transaction can commit, false if the
transaction is read only
TransactionAbortedException
- The transaction has been
aborted due to inconsistency, duplicate object identity, error
with the persistence engine or any other reason
query
public QueryResults query(LockEngine engine,
PersistenceQuery query,
AccessMode accessMode,
boolean scrollable)
throws QueryException,
PersistenceException
Perform a query using the query mechanism and in the specified
access mode. The query is performed in this transaction, and
the returned query results can only be used while this
transaction is open. It is assumed that the query mechanism is
compatible with the persistence engine.
engine
- The persistence enginequery
- A query against the persistence engineaccessMode
- The access mode
release
public void release(Object object)
throws ObjectNotPersistentException,
PersistenceException
Releases the lock granted on the object. The object is removed
from this transaction and will not participate in transaction
commit/abort. Any changes done to the object are lost.
object
- The object to release the lock
removeObjectEntry
(package private) TransactionContext.ObjectEntry removeObjectEntry(Object object)
Removes the entry for an object and returns it. The object is
no longer part of the transaction.
object
- The object to remove
removeTxSynchronizable
public void removeTxSynchronizable(TxSynchronizable synchronizable)
rollback
public void rollback()
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 void setAutoStore(boolean autoStore)
Enable or disable autoStore.
If enabled, all new objects, which is reachable from other
object that is quried, loaded, created in the transaction,
will be created when the transaction is committed.
setCallback
public void setCallback(CallbackInterceptor callback)
Overrides the default callback interceptor by a custom
interceptor for this database source.
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 disabled
setInstanceFactory
public void setInstanceFactory(InstanceFactory factory)
Overrides the default instance factory by a custom one for
this database source.
The factory is used to obatain a new instance of data object
when it is needed during loading.
setLockTimeout
public void setLockTimeout(int timeout)
Sets the timeout waiting to acquire a lock. The timeout is
specified in seconds.
setTransactionTimeout
public void setTransactionTimeout(int timeout)
Sets the timeout of this transaction. The timeout is specified
in seconds.
setWaitOnLock
(package private) void setWaitOnLock(ObjectLock lock)
Indicates which lock this transaction is waiting for. When a
transaction attempts to acquire a lock it must indicate which
lock it attempts to acquire in order to perform dead-lock
detection. This method is called by
ObjectLock
before entering the temporary lock-acquire state.
lock
- The lock which this transaction attempts to acquire
softLock
public void softLock(Object object,
int timeout)
throws LockNotGrantedException,
ObjectNotPersistentException
Acquire a write lock on the object. Read locks are implicitly
available when the object is queried. A write lock is only
granted for objects that are created or deleted or for objects
loaded in exclusive mode - this method can obtain such a lock
explicitly. If the object already has a write lock in this
transaction or a read lock in this transaction but no read lock
in any other transaction, a write lock is obtained. If this
object has a read lock in any other transaction this method
will block until the other transaction will release its lock.
If the specified timeout has elapsed or a deadlock has been
detected, an exception will be thrown but the current lock will
be retained.
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
toDatabaseAccessMode
(package private) static short toDatabaseAccessMode(AccessMode mode)
Converts AccessMode constant to Database short constant
txcommitted
protected void txcommitted()
Inform all registered listeners that the transaction was committed.
txrolledback
protected void txrolledback()
Inform all registered listeners that the transaction was rolled back.
update
public void update(LockEngine engine,
ClassMolder molder,
Object object,
OID depended)
throws DuplicateIdentityException,
ObjectModifiedException,
ClassNotPersistenceCapableException,
PersistenceException
Update a new object in persistent storage and returns the
object's OID. The object will be persisted only if the
transaction commits. If an identity is provided then duplicate
identity check happens in this method, if no identity is
provided then duplicate identity check occurs when the
transaction completes and the object is not visible in this
transaction.
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
writeLock
public void writeLock(Object object,
int timeout)
throws ObjectNotPersistentException,
LockNotGrantedException,
PersistenceException
Acquire a write lock on the object. Read locks are implicitly
available when the object is queried. A write lock is only
granted for objects that are created or deleted or for objects
loaded in exclusive mode - this method can obtain such a lock
explicitly. If the object already has a write lock in this
transaction or a read lock in this transaction but no read lock
in any other transaction, a write lock is obtained. If this
object has a read lock in any other transaction this method
will block until the other transaction will release its lock.
If the specified timeout has elapsed or a deadlock has been
detected, an exception will be thrown but the current lock will
be retained.
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