|
Berkeley DB Java Edition version 4.1.21 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sleepycat.je.Transaction
public class Transaction
The Transaction object is the handle for a transaction. Methods off the transaction handle are used to configure, abort and commit the transaction. Transaction handles are provided to other Berkeley DB methods in order to transactionally protect those operations.
A single Transaction may be used to protect operations for any number of Databases in a given environment. However, a single Transaction may not be used for operations in more than one distinct environment.
Transaction handles are free-threaded; transactions handles may be used
concurrently by multiple threads. Once the Transaction.abort
or Transaction.commit
method
is called, the handle may not be accessed again, regardless of the success
or failure of the method, with one exception: the abort
method may
be called any number of times to simplify error handling.
To obtain a transaction with default attributes:
Transaction txn = myEnvironment.beginTransaction(null, null);
To customize the attributes of a transaction:
TransactionConfig config = new TransactionConfig(); config.setReadUncommitted(true); Transaction txn = myEnvironment.beginTransaction(null, config);
Constructor Summary | |
---|---|
protected |
Transaction(Environment env,
com.sleepycat.je.txn.Txn txn)
Creates a transaction. |
Method Summary | |
---|---|
void |
abort()
Cause an abnormal termination of the transaction. |
void |
commit()
End the transaction. |
void |
commit(Durability durability)
End the transaction using the specified durability requirements. |
void |
commitNoSync()
End the transaction, not writing to stable storage and not committing synchronously. |
void |
commitSync()
End the transaction, writing to stable storage and committing synchronously. |
void |
commitWriteNoSync()
End the transaction, writing to stable storage but not committing synchronously. |
CommitToken |
getCommitToken()
This method is intended for use with a replicated environment. |
long |
getId()
Return the transaction's unique ID. |
long |
getLockTimeout(TimeUnit unit)
Returns the lock request timeout value for the transaction. |
String |
getName()
Get the user visible name for the transaction. |
long |
getTxnTimeout(TimeUnit unit)
Returns the timeout value for the transaction lifetime. |
boolean |
isValid()
Returns whether this Transaction is open, valid and can be used. |
void |
setLockTimeout(long timeOut)
Deprecated. as of 4.0, replaced by setLockTimeout(long,
TimeUnit) . |
void |
setLockTimeout(long timeOut,
TimeUnit unit)
Configures the lock request timeout value for the transaction. |
void |
setName(String name)
Set the user visible name for the transaction. |
void |
setTxnTimeout(long timeOut)
Deprecated. as of 4.0, replaced by setTxnTimeout(long,
TimeUnit) . |
void |
setTxnTimeout(long timeOut,
TimeUnit unit)
Configures the timeout value for the transaction lifetime. |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected Transaction(Environment env, com.sleepycat.je.txn.Txn txn)
Method Detail |
---|
public void abort() throws DatabaseException
The log is played backward, and any necessary undo operations are done. Before Transaction.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 this method has been called, regardless of its return, the
Transaction
handle may not be accessed again, with one
exception: the abort
method itself may be called any number of
times to simplify error handling.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the environment has been closed, or
cursors associated with the transaction are still open.
DatabaseException
public long getId()
public CommitToken getCommitToken() throws IllegalStateException
It returns the commitToken associated with a successful replicated commit. A null value is returned if the txn was not associated with a replicated environment, or the txn did not result in any changes to the environment. This method should only be called after the transaction has finished.
This method is typically used in conjunction with the
CommitPointConsistencyPolicy
.
IllegalStateException
- if the method is called before the
transaction has committed or aborted.CommitPointConsistencyPolicy
public void commit() throws DatabaseException
If the environment is not configured for synchronous commit, the commit will not necessarily have been committed to stable storage before the call returns. 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 this transaction may be undone during recovery.
All cursors opened within the transaction must be closed before the transaction is committed.
If the method encounters an error, the transaction will have been aborted when the call returns.
After this method has been called, regardless of its return, the
Transaction
handle may not be accessed again, with one
exception: the abort
method may be called any number of times
to simplify error handling.
InsufficientReplicasException
- if the master
in a replicated environment could not contact a quorum of replicas as
determined by the Durability.ReplicaAckPolicy
. The application must abort
the transaction and can choose to retry it.
InsufficientAcksException
- if the master in
a replicated environment did not receive enough replica acknowledgments,
although the commit succeeded locally.
ReplicaWriteException
- if a write operation
was performed with this transaction, but this node is now a Replica.
OperationFailureException
- if this exception occurred earlier and
caused the transaction to be invalidated.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the transaction or environment has been
closed, or cursors associated with the transaction are still open.
DatabaseException
public void commit(Durability durability) throws DatabaseException
Durability
for specific exceptions that could result when the
durability requirements cannot be satisfied.
All cursors opened within the transaction must be closed before the transaction is committed.
If the method encounters an error, the transaction will have been aborted when the call returns.
After this method has been called, regardless of its return, the
Transaction
handle may not be accessed again, with one
exception: the abort
method may be called any number of times
to simplify error handling.
durability
- the durability requirements for this transaction
InsufficientReplicasException
- if the master
in a replicated environment could not contact enough replicas to
initiate the commit.
InsufficientAcksException
- if the master in
a replicated environment did not receive enough replica acknowledgments,
althought the commit succeeded locally.
ReplicaWriteException
- if a write operation
was performed with this transaction, but this node is now a Replica.
OperationFailureException
- if this exception occurred earlier and
caused the transaction to be invalidated.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the transaction or environment has been
closed, or cursors associated with the transaction are still open.
IllegalArgumentException
- if an invalid parameter is specified.
DatabaseException
public void commitSync() throws DatabaseException
This behavior is the default for database environments unless
otherwise configured using the EnvironmentConfig.setTxnNoSync
method. This behavior may also be set
for a single transaction using the Environment.beginTransaction
method. Any value specified to this
method overrides both of those settings.
All cursors opened within the transaction must be closed before the transaction is committed.
If the method encounters an error, the transaction will have been aborted when the call returns.
After this method has been called, regardless of its return, the
Transaction
handle may not be accessed again, with one
exception: the abort
method may be called any number of times
to simplify error handling.
InsufficientReplicasException
- if the master
in a replicated environment could not contact enough replicas to
initiate the commit.
InsufficientAcksException
- if the master in
a replicated environment did not receive enough replica acknowledgments,
althought the commit succeeded locally.
ReplicaWriteException
- if a write operation
was performed with this transaction, but this node is now a Replica.
OperationFailureException
- if this exception occurred earlier and
caused the transaction to be invalidated.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the transaction or environment has been
closed, or cursors associated with the transaction are still open.
DatabaseException
public void commitNoSync() throws DatabaseException
This behavior may be set for a database environment using the EnvironmentConfig.setTxnNoSync
method or for a single transaction using
the Environment.beginTransaction
method. Any value specified to this
method overrides both of those settings.
All cursors opened within the transaction must be closed before the transaction is committed.
If the method encounters an error, the transaction will have been aborted when the call returns.
After this method has been called, regardless of its return, the
Transaction
handle may not be accessed again, with one
exception: the abort
method may be called any number of times
to simplify error handling.
InsufficientReplicasException
- if the master
in a replicated environment could not contact enough replicas to
initiate the commit.
InsufficientAcksException
- if the master in
a replicated environment did not receive enough replica acknowledgments,
althought the commit succeeded locally.
ReplicaWriteException
- if a write operation
was performed with this transaction, but this node is now a Replica.
OperationFailureException
- if this exception occurred earlier and
caused the transaction to be invalidated.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the transaction or environment has been
closed, or cursors associated with the transaction are still open.
DatabaseException
public void commitWriteNoSync() throws DatabaseException
This behavior is the default for database environments unless
otherwise configured using the EnvironmentConfig.setTxnNoSync
method. This behavior may also be set
for a single transaction using the Environment.beginTransaction
method. Any value specified to this
method overrides both of those settings.
All cursors opened within the transaction must be closed before the transaction is committed.
If the method encounters an error, the transaction will have been aborted when the call returns.
After this method has been called, regardless of its return, the
Transaction
handle may not be accessed again, with one
exception: the abort
method may be called any number of times
to simplify error handling.
InsufficientReplicasException
- if the master
in a replicated environment could not contact enough replicas to
initiate the commit.
InsufficientAcksException
- if the master in
a replicated environment did not receive enough replica acknowledgments,
althought the commit succeeded locally.
ReplicaWriteException
- if a write operation
was performed with this transaction, but this node is now a Replica.
OperationFailureException
- if this exception occurred earlier and
caused the transaction to be invalidated.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the transaction or environment has been
closed, or cursors associated with the transaction are still open.
DatabaseException
public long getTxnTimeout(TimeUnit unit) throws EnvironmentFailureException, IllegalStateException, IllegalArgumentException
If setTxnTimeout(long,TimeUnit)
has not been called to
configure the timeout, the environment configuration value (EnvironmentConfig.TXN_TIMEOUT
)is returned.
unit
- the TimeUnit
of the returned value. May not be null.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the transaction or environment has been
closed.
IllegalArgumentException
- if the unit is null.public void setTxnTimeout(long timeOut, TimeUnit unit) throws IllegalArgumentException, DatabaseException
If the transaction runs longer than this time, the transaction may
throw TransactionTimeoutException
.
Transaction timeouts are checked whenever a thread of control blocks on a lock or when deadlock detection is performed. For this reason, the accuracy of the timeout depends on the length of the lock timeout and how often deadlock detection is performed.
timeOut
- The timeout value for the transaction lifetime. A value
of 0 disables timeouts for the transaction, meaning that no limit on the
duration of the transaction is enforced.unit
- the TimeUnit
of the timeOut value. May be null only
if timeOut is zero.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the transaction or environment has been
closed.
IllegalArgumentException
- if timeOut or unit is invalid.
DatabaseException
public void setTxnTimeout(long timeOut) throws IllegalArgumentException, DatabaseException
setTxnTimeout(long,
TimeUnit)
.
setTxnTimeout(long, TimeUnit.MICROSECONDS);
IllegalArgumentException
DatabaseException
public long getLockTimeout(TimeUnit unit) throws EnvironmentFailureException, IllegalStateException, IllegalArgumentException
If setLockTimeout(long,TimeUnit)
has not been called to
configure the timeout, the environment configuration value (EnvironmentConfig.LOCK_TIMEOUT
) is returned.
unit
- the TimeUnit
of the returned value. May not be null.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the transaction or environment has been
closed.
IllegalArgumentException
- if the unit is null.public void setLockTimeout(long timeOut, TimeUnit unit) throws IllegalArgumentException, DatabaseException
If a lock request cannot be granted in this time, the transaction may
throw LockTimeoutException
.
This method may be called at any time during the life of the application.
timeOut
- The lock request timeout value for this transaction. A
value of zero turns off transaction timeouts, meaning that no lock wait
time limit is enforced and a deadlocked operation will block
indefinitely. We strongly recommend that a large timeout value, rather
than a zero value, is used when deadlocks are not expected. That way, a
timeout exception will be thrown when an unexpected deadlock occurs.unit
- the TimeUnit
of the timeOut value. May be null only
if timeOut is zero.
EnvironmentFailureException
- if an unexpected, internal or
environment-wide failure occurs.
IllegalStateException
- if the transaction or environment has been
closed.
IllegalArgumentException
- if timeOut or unit is invalid.
DatabaseException
public void setLockTimeout(long timeOut) throws IllegalArgumentException, DatabaseException
setLockTimeout(long,
TimeUnit)
.
setLockTimeout(long, TimeUnit.MICROSECONDS);
IllegalArgumentException
DatabaseException
public void setName(String name)
name
- The user visible name for the transaction.public String getName()
public String toString()
toString
in class Object
public boolean isValid()
Transaction
is open, valid and can be used.
If this method returns false, abort()
should be called as soon as
possible.
When an OperationFailureException
, or one of its
subclasses, is caught, the isValid
method should be called to
determine whether the Transaction
can continue to be used, or
should be aborted.
|
Berkeley DB Java Edition version 4.1.21 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |