public interface Transaction
All changes made in a transaction are atomic and consistent if they are successfully flushed or committed.
Along with snapshot isolation and configurable durability, transaction are fully
ACID-compliant.
By default, transaction durability is turned off since it significantly slows down flush()and
commit(). To turn it on, pass true to EnvironmentConfig.setLogDurableWrite(boolean).
Transactions can be read-only or not, exclusive or not. Read-only transactions are used to only read data. Exclusive transactions are used to have successive access to database. If you have an exclusive transaction, no other transaction (except read-only) can be started against the same Environment unless you finish (commit or abort) your exclusive one.
Given you have an instance of Environment you can start new transaction:
final Transaction txn = environment.beginTransaction();Starting read-only transaction:
final Transaction txn = environment.beginReadonlyTransaction();Starting exclusive transaction:
final Transaction txn = environment.beginExclusiveTransaction();
| Modifier and Type | Method and Description |
|---|---|
void |
abort()
Drops all changes and finishes the transaction.
|
boolean |
commit()
Tries to flush all changes accumulated to the moment in the transaction and finish the transaction.
|
boolean |
flush()
Tries to flush all changes accumulated to the moment in the transaction.
|
@NotNull Environment |
getEnvironment() |
long |
getHighAddress() |
Transaction |
getReadonlySnapshot()
Creates new read-only transaction holding the same database snapshot as this one holds.
|
Transaction |
getSnapshot()
Creates new transaction holding the same database snapshot as this one holds.
|
Transaction |
getSnapshot(@Nullable java.lang.Runnable beginHook)
Creates new transaction with specified begin hook holding the same database snapshot as this one holds.
|
long |
getStartTime()
Time when the transaction acquired its database snapshot, i.e.
|
@Nullable java.lang.Object |
getUserObject(@NotNull java.lang.Object key)
Returns an user object identified by the specified key and bound to the transaction, or
null if no
object is bound to the transaction by the specified key. |
boolean |
isExclusive() |
boolean |
isFinished() |
boolean |
isIdempotent()
Idempotent transaction changes nothing in database.
|
boolean |
isReadonly() |
void |
revert()
Drops all changes without finishing the transaction and holds the newest database snapshot.
|
void |
setCommitHook(@Nullable java.lang.Runnable hook)
Provides transaction with commit hook.
|
void |
setUserObject(@NotNull java.lang.Object key,
@NotNull java.lang.Object value)
Bind an user object (
value) identified by a key to the transaction. |
boolean isIdempotent()
true. Each newly created
transaction is idempotent.void abort()
commit(),
flush(),
revert(),
isFinished()boolean commit()
true all changes are flushed and transaction is finished, otherwise nothing is flushed and
transaction is not finished.true if transaction is committedflush(),
abort(),
revert(),
isFinished()boolean flush()
true if flush succeeded.
In that case, transaction remains unfinished and holds the newest database snapshot.true if transaction is flushedcommit(),
abort(),
revert(),
isFinished()void revert()
commit(),
abort(),
flush(),
isFinished()Transaction getSnapshot()
Environment.beginTransaction()Transaction getSnapshot(@Nullable @Nullable java.lang.Runnable beginHook)
beginHook - begin hookEnvironment.beginTransaction(Runnable)Transaction getReadonlySnapshot()
Environment.beginReadonlyTransaction()@NotNull @NotNull Environment getEnvironment()
void setCommitHook(@Nullable
@Nullable java.lang.Runnable hook)
long getStartTime()
long getHighAddress()
boolean isReadonly()
boolean isExclusive()
Environment.beginExclusiveTransaction()boolean isFinished()
@Nullable
@Nullable java.lang.Object getUserObject(@NotNull
@NotNull java.lang.Object key)
null if no
object is bound to the transaction by the specified key.key - a key identifying the user objectvoid setUserObject(@NotNull
@NotNull java.lang.Object key,
@NotNull
@NotNull java.lang.Object value)
value) identified by a key to the transaction.key - a key identifying the user objectvalue - user object bound to the transaction