|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.odi.Transaction
PSE/PSE Pro uses the Transaction class to represent a logical unit of work. A transaction is a consistent and reliable portion of the execution of a program. In your code, you place calls to the PSE/PSE Pro API to mark the beginning and end of transactions. In an application, the initial access to a persistent object must always occur inside a transaction. Modifications to persistent objects must occur in a transaction when you want to save them.
Either all of a transaction's changes to persistent objects are made successfully, or none is made at all. If a failure occurs in the middle of a transaction, none of its database updates is made.
Transaction is an abstract class. When you invoke the Transaction.begin() method, PSE/PSE Pro automatically finds the subclass of Transaction, creates an instance of that subclass, and uses it to represent your transaction. You are not expected to extend the Transaction class, and PSE/PSE Pro will not work if you do.
If an application terminates at any time other than during a Transaction.commit() operation, PSE/PSE Pro returns the database to the state it was in before the transaction started. If an application terminates during a call to Transaction.commit()
A Control-C or a system crash can cause an application to terminate during a call to Transaction.commit().
Field Summary | |
static int |
readOnly
Deprecated. This constant has been changed to ObjectStore.READONLY. |
static int |
update
Deprecated. This constant has been changed to ObjectStore.UPDATE. |
Fields inherited from interface com.odi.ObjectStoreConstants |
ALL_EXECUTE, ALL_READ, ALL_WRITE, DEFAULT, DISABLE_AUTO_OPEN, GROUP_EXECUTE, GROUP_READ, GROUP_WRITE, INSTALL_SCHEMA_BATCH, INSTALL_SCHEMA_INCREMENTAL, MULTI_DB_MVCC, MVCC, OBJECTSTORE, OTHER_EXECUTE, OTHER_READ, OTHER_WRITE, OWNER_EXECUTE, OWNER_READ, OWNER_WRITE, PSE, PSE_PRO, READONLY, READONLY_NON_BLOCKING, RETAIN_HOLLOW, RETAIN_READONLY, RETAIN_STALE, RETAIN_TRANSIENT, RETAIN_UPDATE, UPDATE, UPDATE_NON_BLOCKING, WAIT_FOREVER, XA_TRANSACTION |
Method Summary | |
abstract void |
abort()
Aborts a transaction. |
abstract void |
abort(int retain)
Aborts a transaction and retains objects that were referenced in the transaction. |
static Transaction |
begin(int type)
Starts a transaction. |
abstract void |
checkpoint()
Checkpoints a transaction. |
abstract void |
checkpoint(int retain)
Checkpoints a transaction. |
abstract void |
commit()
Commits a transaction. |
abstract void |
commit(int retain)
Commits a transaction and specifies what should happen to persistent objects after the transaction is over. |
static Transaction |
current()
Obtains the instance of Transaction that is associated with the current thread. |
static int |
getPriority()
Gets the priority specified for transactions started by the current session. |
abstract Session |
getSession()
Returns the session associated with this Transaction. |
abstract int |
getType()
Obtains the type of a transaction. |
static boolean |
hasLockContention()
Indicates whether or not a Server involved in the current transaction has experienced contention for some persistent objects that the application is using. |
static boolean |
inTransaction()
Determines whether or not there is a transaction in progress in the session to which the current thread belongs. |
abstract boolean |
isAborted()
Returns true if the transaction has been aborted, otherwise false. |
abstract boolean |
isActive()
Returns true if the transaction has not been aborted or committed, otherwise false. |
static void |
setDefaultAbortRetain(int retain)
Sets the default retain operation for the current session for calls to Transaction.abort() that have no argument. |
static void |
setDefaultCommitRetain(int retain)
Sets the default retain operation for the current session for calls to Transaction.checkpoint() and Transaction.commit() that have no argument. |
static void |
setDefaultRetain(int retain)
Sets the default retain operation for the current session for calls to Transaction.abort(), Transaction.commit() and Transaction.checkpoint() that have no argument. |
static void |
setPriority(int priority)
Sets the priority for transactions started by the current session. |
Field Detail |
public static final int readOnly
public static final int update
Method Detail |
public static Transaction begin(int type)
PSE/PSE Pro grants a lock on a database when it starts a transaction or when it opens a database inside a transaction. Your application can open a database inside or outside a transaction. If you open a database inside a transaction, and if the lock you want is available, PSE/PSE Pro immediately grants the lock. PSE/PSE Pro releases the lock when you end the transaction in which you acquired the lock.
type
- The type of transaction to start. This value must
be one of the following:
DatabaseLockedException
- If you specify a nonblocking
transaction begin type and the kind of lock needed for the database
is not available.
IllegalArgumentException
- If the transaction type is not
ObjectStore.READONLY, ObjectStore.UPDATE,
ObjectStore.READONLY_NON_BLOCKING, or
ObjectStore.UPDATE_NON_BLOCKING.
ObjectStoreException
- If the current thread is not
associated with a session and there is no global session.
TransactionInProgressException
- If there is already a
transaction in progress.public static Transaction current()
NoTransactionInProgressException
- If no transaction is in
progress for the current thread.
ObjectStoreException
- If the current thread is not
associated with a session and there is no global session.public static boolean inTransaction()
public abstract void commit()
Objects that were referenced in the transaction are retained according to the value set by the most recent call to either Transaction.setDefaultCommitRetain() or setDefaultRetain(). If neither of these methods has been called, calling commit() is the same as calling commit(ObjectStore.RETAIN_STALE).
AbortException
- If PSE/PSE Pro
reaches an object while it is performing transitive persistence and
that object is not persistence-capable.
NoTransactionInProgressException
- If a transaction
is not in progress.
NoSessionException
- If the session implied by the transaction
has been terminated.
WrongSessionException
- If the current thread is associated with a
session other than the session implied by the transaction.public abstract void commit(int retain)
The retain argument provides a mechanism for using persistent objects between transactions. When you start a new transaction, you can use the references to retained objects. However, if you retained the contents of the objects, (if you specified ObjectStore.RETAIN_READONLY or ObjectStore.RETAIN_UPDATE) the state of these objects might have been changed since the commit operation by another process. PSE/PSE Pro automatically refreshes the state of any modified objects, when they are first touched in the new transaction. This means that the application code cannot assume that the state of a retained object remains constant even when a new transaction is started. It is also possible that trying to read or write a retained object in a new transaction could result in a transaction waiting for a lock.
retain
- Possible values
are:
Additional information about hollow, active, and stale object state is the API User Guide.
For additional information about retaining persistent objects, see the API User Guide.
AbortException
- If PSE/PSE Pro
reaches an object while it is performing transitive persistence and
that object is not persistence-capable.
IllegalArgumentException
- If retain is not
one of ObjectStore.RETAIN_STALE, ObjectStore.RETAIN_HOLLOW,
ObjectStore.RETAIN_READONLY, ObjectStore.RETAIN_UPDATE or
ObjectStore.RETAIN_TRANSIENT.
NoTransactionInProgressException
- If a transaction
is not in progress.
ObjectStoreException
- If the session implied by the transaction
has been terminated or if the current thread is associated with a
session other than the session implied by the transaction.public abstract void abort()
Objects that were referenced in the transaction are retained according to the value of Transaction.setDefaultAbortRetain(). If Transaction.setDefaultAbortRetain() has not been called, calling abort() is the same as calling abort(ObjectStore.RETAIN_STALE).
Sometimes, when PSE/PSE Pro throws an exception, it also aborts the current transaction. If it does, you must not call the abort() method if you catch the exception. The exceptions that can abort transactions are
You can call Transaction.isAborted() to determine if the transaction has been aborted. You can call Transaction.isActive() to verify that the transaction has not been aborted or committed.
NoTransactionInProgressException
- If a transaction
is not in progress.
ObjectStoreException
- If the session implied by the transaction
has been terminated or if the current thread is associated with a
session other than the session implied by the transaction.public abstract void abort(int retain)
The retain argument provides a mechanism for using persistent objects between transactions. When you start a new transaction, you can use the references to retained objects. However, if you retained the contents of the objects, (if you specified ObjectStore.RETAIN_READONLY or ObjectStore.RETAIN_UPDATE) the state of these objects might have been changed since the abort operation by another process. PSE/PSE Pro automatically refreshes the state of any modified objects, when they are first touched in the new transaction. This means that the application code cannot assume that the state of a retained object remains constant even when a new transaction is started. It is also possible that trying to read or write a retained object in a new transaction could result in a transaction waiting for a lock, or a transaction abort due to a deadlock situation.
Sometimes, when PSE/PSE Pro throws an exception, it also aborts the current transaction. If it does, you must not call the abort() method if you catch the exception. The exceptions that can abort transactions are
If you set up an exception handler that handles one of these exceptions, the handler body must not call abort() unless it has determined that there is still a transaction in progress. You can call Transaction.inTransaction() to determine if there is a transaction in progress.
You can call Transaction.isAborted() to determine if the transaction has been aborted. You can call Transaction.isActive() to verify that the transaction has not been aborted or committed.
retain
- Possible values are:
IllegalArgumentException
- If the value of the retain
argument is not one of ObjectStore.RETAIN_STALE,
ObjectStore.RETAIN_HOLLOW, ObjectStore.RETAIN_READONLY,
ObjectStore.RETAIN_UPDATE or ObjectStore.RETAIN_TRANSIENT.
NoTransactionInProgressException
- If a transaction
is not in progress.
ObjectStoreException
- If the session implied by the transaction
has been terminated or if the current thread is associated with a
session other than the session implied by the transaction.public abstract void checkpoint()
Objects that were referenced in the transaction are retained according to the value of Transaction.setDefaultCommitRetain() or setDefaultRetain(). If neither of these methods has been called, calling checkpoint() is the same as calling checkpoint(ObjectStore.RETAIN_STALE).
AbortException
- If PSE/PSE Pro detects a reference from an
object in one segment to an unexported object in another segment, or if
PSE/PSE Pro
reaches an object while it is performing transitive persistence and that
object is not persistence-capable.
NoTransactionInProgressException
- If a transaction
is not in progress.
ObjectStoreException
- If the session implied by the transaction
has been terminated or if the current thread is associated with a
session other than the session implied by the transaction.public abstract void checkpoint(int retain)
The retain argument determines the disposition of persistent objects after the checkpoint. Because checkpoint() immediately starts a new transaction after committing the current one, the retain argument does not affect the behavior of persistent objects outside of a transaction.
retain
- Possible values are:
AbortException
- If PSE/PSE Pro detects a reference from an
object in one segment to an unexported object in another segment, or if
PSE/PSE Pro
reaches an object while it is performing transitive persistence and that
object is not persistence-capable.
IllegalArgumentException
- If retain is not
one of ObjectStore.RETAIN_STALE or ObjectStore.RETAIN_HOLLOW.
NoTransactionInProgressException
- If a transaction
is not in progress.
ObjectStoreException
- If the session implied by the transaction
has been terminated or if the current thread is associated with a
session other than the session implied by the transaction.public static void setDefaultRetain(int retain)
The default retain type for aborts, commits and checkpoints is set by the most recent call to setDefaultRetain(int), setDefaultAbortRetain(int) or setDefaultCommitRetain(int) as appropriate. For example, calling setDefaultAbortRetain(int) after calling setDefaultRetain(int) will set the default retain value for aborts to be that specified by setDefaultAbortRetain(int). Similarly calling setDefaultRetain(int) after calling setDefaultCommitRetain(int) will set the default retain value for checkpoints and commits to be that specified by setDefaultRetain(int).
retain
- The retain type.
See Transaction.abort(int retainType) or
Transaction.commit(int retainType) for a description
of the retain types.
NoSessionException
- If the calling thread is not joined
to a session.
IllegalArgumentException
- If retain is not
one of ObjectStore.RETAIN_STALE, ObjectStore.RETAIN_HOLLOW,
ObjectStore.RETAIN_READONLY, ObjectStore.RETAIN_UPDATE or
ObjectStore.RETAIN_TRANSIENT.Transaction.setDefaultAbortRetain(int)
,
Transaction.setDefaultCommitRetain(int)
,
Transaction.abort()
,
Transaction.commit()
public static void setDefaultAbortRetain(int retain)
retain
- Possible values are:
NoSessionException
- If the calling thread is not joined
to a session.
IllegalArgumentException
- If retain is not
one of ObjectStore.RETAIN_STALE, ObjectStore.RETAIN_HOLLOW,
ObjectStore.RETAIN_READONLY, ObjectStore.RETAIN_UPDATE or
ObjectStore.RETAIN_TRANSIENT.public static void setDefaultCommitRetain(int retain)
retain
- Possible values are:
The default retain type for aborts, commits and checkpoints is set by the most recent call to setDefaultRetain(int), setDefaultAbortRetain(int) or setDefaultCommitRetain(int) as appropriate. For example, calling setDefaultAbortRetain(int) after calling setDefaultRetain(int) will set the default retain value for aborts to be that specified by setDefaultAbortRetain(int). Similarly calling setDefaultRetain(int) after calling setDefaultCommitRetain(int) will set the default retain value for checkpoints and commits to be that specified by setDefaultRetain(int).
NoSessionException
- If the calling thread is not joined
to a session.
IllegalArgumentException
- If retain is not
one of ObjectStore.RETAIN_STALE, ObjectStore.RETAIN_HOLLOW,
ObjectStore.RETAIN_READONLY, ObjectStore.RETAIN_UPDATE or
ObjectStore.RETAIN_TRANSIENT.public abstract int getType()
NoTransactionInProgressException
- If a transaction
is not in progress.
ObjectStoreException
- If the session implied by the transaction
has been terminated or if the current thread is associated with a
session other than the session implied by the transaction.public static boolean hasLockContention()
This function can be used in conjunction with MVCC to help determine whether or not to start a new transaction to make available more up-to-date data. If your application has a database open for MVCC, and during the current transaction another application has write-locked an object read by your application, hasLockContention() returns true.
This method is advisory; it does not have to be called and its return value can be ignored without jeopardizing the correctness of PSE/PSE Pro's behavior.
NoTransactionInProgressException
- If a transaction
is not in progress.
ObjectStoreException
- If the session implied by the transaction
has been terminated or if the current thread is associated with a
session other than the session implied by the transaction.public static int getPriority()
ObjectStoreException
- If the current thread is not associated
with a session and there is no global session.Transaction.setPriority(int)
public static void setPriority(int priority)
This method has no effect in PSE or PSE Pro.
priority
- The transaction priority.
IllegalArgumentException
- If the priority argument is
negative or greater than 0xffff.
ObjectStoreException
- If the current thread is not associated
with a session and there is no global session.public abstract Session getSession()
public abstract boolean isAborted()
public abstract boolean isActive()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |