|
Berkeley DB version 4.2.52 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.sleepycat.db.DbTxn
The DbTxn object is the handle for a transaction. Methods off the DbTxn handle are used to configure, abort and commit the transaction. DbTxn handles are provided to Db
methods in order to transactionally protect those database operations.
DbTxn handles are not free-threaded; transactions handles may be used by multiple threads, but only serially, that is, the application must serialize access to the DbTxn handle. Once the DbTxn.abort
or DbTxn.commit
methods are called, the handle may not be accessed again, regardless of the method's return. In addition, parent transactions may not issue any Berkeley DB operations while they have active child transactions (child transactions that have not yet been committed or aborted) except for DbEnv.txnBegin
, DbTxn.abort
and DbTxn.commit
.
Method Summary | |
void |
abort()
The DbTxn.abort method causes an abnormal termination of the transaction. |
void |
commit(int flags)
The DbTxn.commit method ends the transaction. |
void |
discard(int flags)
The DbTxn.discard method frees up all the per-process resources associated with the specified DbTxn handle, neither committing nor aborting the transaction. |
boolean |
equals(Object obj)
|
int |
hashCode()
|
int |
id()
The DbTxn.id method returns the unique transaction id associated with the specified transaction. |
void |
prepare(byte[] gid)
The DbTxn.prepare method initiates the beginning of a two-phase commit. |
void |
set_timeout(long timeout,
int flags)
Deprecated. As of Berkeley DB 4.2, replaced by setTimeout(long,int) |
void |
setTimeout(long timeout,
int flags)
The DbTxn.setTimeout method sets timeout values for locks or transactions for the specified transaction. |
Methods inherited from class java.lang.Object |
getClass, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public void abort() throws DbException
DbEnv.setAppDispatch
. Before DbTxn.abort returns, any locks held by the transaction will have been released. In the case of nested transactions, aborting a parent transaction causes all children (unresolved or not) of the parent transaction to be aborted.
All cursors opened within the transaction must be closed before the transaction is aborted.
After DbTxn.abort has been called, regardless of its return, the DbTxn
handle may not be accessed again.
DbException
- Signals that an exception of some sort has occurred.public void commit(int flags) throws DbException
In the case of nested transactions, if the transaction is a parent transaction, committing the parent transaction causes all unresolved children of the parent to be committed. In the case of nested transactions, if the transaction is a child transaction, its locks are not released, but are acquired by its parent. Although the commit of the child transaction will succeed, the actual resolution of the child transaction is postponed until the parent transaction is committed or aborted; that is, if its parent transaction commits, it will be committed; and if its parent transaction aborts, it will be aborted.
All cursors opened within the transaction must be closed before the transaction is committed.
After DbTxn.commit has been called, regardless of its return, the DbTxn
handle may not be accessed again. If DbTxn.commit encounters an error, the transaction and all child transactions of the transaction are aborted.
flags
- must be set to 0 or one of the following values: Db.DB_TXN_NOSYNC
Do not synchronously flush the log. This means the transaction will exhibit the ACI (atomicity, consistency, and isolation) properties, but not D (durability); that is, database integrity will be maintained, but it is possible that this transaction may be undone during recovery.
This behavior may be set for a Berkeley DB environment using the DbEnv.setFlags
method or for a single transaction using the DbEnv.txnBegin
method. Any value specified to this method overrides both of those settings.
Db.DB_TXN_SYNC
Synchronously flush the log. This means the transaction will exhibit all of the ACID (atomicity, consistency, isolation, and durability) properties.
This behavior is the default for Berkeley DB environments unless the
flag was specified to the Db.DB_TXN_NOSYNC
DbEnv.setFlags
method. This behavior may also be set for a single transaction using the DbEnv.txnBegin
method. Any value specified to this method overrides both of those settings.
DbException
- Signals that an exception of some sort has occurred.public void discard(int flags) throws DbException
DbTxn
handle, neither committing nor aborting the transaction. This call may be used only after calls to DbEnv.txnRecover
when there are multiple global transaction managers recovering transactions in a single Berkeley DB environment. Any transactions returned by DbEnv.txnRecover
that are not handled by the current global transaction manager should be discarded using DbTxn.discard. After DbTxn.discard has been called, regardless of its return, the DbTxn
handle may not be accessed again.
flags
- currently unused, and must be set to 0.
DbException
IllegalArgumentException
- The DbTxn.discard method will fail and throw a IllegalArgumentException exception if the transaction handle does not refer to a transaction that was recovered into a prepared but not yet completed state; or if an invalid flag value or parameter was specified.public boolean equals(Object obj)
equals
in class Object
public int hashCode()
hashCode
in class Object
public int id() throws DbException
DbEnv.lockGet
or DbEnv.lockVector
calls.
DbException
- Signals that an exception of some sort has occurred.public void prepare(byte[] gid) throws DbException
In a distributed transaction environment, Berkeley DB can be used as a local transaction manager. In this case, the distributed transaction manager must send prepare messages to each local manager. The local manager must then issue a DbTxn.prepare and await its successful return before responding to the distributed transaction manager. Only after the distributed transaction manager receives successful responses from all of its prepare messages should it issue any commit messages.
In the case of nested transactions, preparing the parent causes all unresolved children of the parent transaction to be committed. Child transactions should never be explicitly prepared. Their fate will be resolved along with their parent's during global recovery.
gid
- specifies the global transaction ID by which this transaction will be known. This global transaction ID will be returned in calls to DbEnv.txnRecover
, telling the application which global transactions must be resolved. Db.DB_XIDDATASIZE
must be sized at least Db.DB_XIDDATASIZE
(currently 128) bytes; only the first Db.DB_XIDDATASIZE
bytes are used.
DbException
- Signals that an exception of some sort has occurred.public void set_timeout(long timeout, int flags) throws DbException
setTimeout(long,int)
DbException
public void setTimeout(long timeout, int flags) throws DbException
Timeouts are checked whenever a thread of control blocks on a lock or when deadlock detection is performed. (In the case of Db.DB_SET_LOCK_TIMEOUT, the lock is one requested explicitly through the Lock subsystem interfaces. In the case of Db.DB_SET_TXN_TIMEOUT, the lock is one requested on behalf of a transaction. In either case, it may be a lock requested by the database access methods underlying the application.) As timeouts are only checked when the lock request first blocks or when deadlock detection is performed, the accuracy of the timeout depends on how often deadlock detection is performed.
Timeout values may be specified for the database environment as a whole. See DbEnv.setTimeout
and for more information.
The DbTxn.setTimeout method configures operations performed on the underlying transaction, not only operations performed using the specified DbTxn
handle.
The DbTxn.setTimeout method may be called at any time during the life of the application.
flags
- must be set to one of the following values: Db.DB_SET_LOCK_TIMEOUT
Set the timeout value for locks in this transaction.
Db.DB_SET_TXN_TIMEOUT
Set the timeout value for this transaction.
timeout
- specified as an unsigned 32-bit number of microseconds, limiting the maximum timeout to roughly 71 minutes. A value of 0 disables timeouts for the transaction.
DbException
IllegalArgumentException
- The DbTxn.setTimeout method will fail and throw a IllegalArgumentException exception if an invalid flag value or parameter was specified.
|
Berkeley DB version 4.2.52 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |