public class Txn extends Object
Nested transaction are not supported but calling inside an existing transaction, which must be compatible, (i.e. a write needs a WRITE transaction). causes the exising transaction to be used.
| Constructor and Description |
|---|
Txn() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends Transactional,X> |
calc(T txn,
TxnType txnType,
Supplier<X> r)
Execute and return a value in a transaction with the given
trasnaction type. |
static <T extends Transactional,X> |
calculate(T txn,
Supplier<X> r)
Execute in a "read" transaction that can promote to "write" and return some calculated value.
|
static <T extends Transactional,X> |
calculateRead(T txn,
Supplier<X> r)
Execute and return a value in a read transaction
|
static <T extends Transactional,X> |
calculateWrite(T txn,
Supplier<X> r)
Execute and return a value in a write transaction.
|
static <T extends Transactional> |
exec(T txn,
TxnType txnType,
Runnable r)
Execute application code in a transaction with the given
trasnaction type. |
static <T extends Transactional> |
execute(T txn,
Runnable r)
Execute in a "read" transaction that can promote to "write".
|
static <T extends Transactional> |
executeRead(T txn,
Runnable r)
Execute in a read transaction
|
static <T extends Transactional> |
executeWrite(T txn,
Runnable r)
Execute the Runnable in a write transaction
|
public static <T extends Transactional> void execute(T txn, Runnable r)
Such a transaction may abort if an update is executed
by another thread before this one is promoted to "write" mode.
If so, the data protected by txn is unchanged.
If the application knows updates will be needed, consider using executeWrite(T, java.lang.Runnable)
which starts in "write" mode.
The application code can call Transactional.promote() to attempt to
change from "read" to "write"; the promote method
returns a boolean indicating whether the promotion was possible or not.
public static <T extends Transactional,X> X calculate(T txn, Supplier<X> r)
Such a transaction may abort if an update is executed
by another thread before this one is promoted to "write" mode.
If so, the data protected by txn is unchanged.
If the application knows updates will be needed, consider using executeWrite(T, java.lang.Runnable)
which starts in "write" mode.
The application code can call Transactional.promote() to attempt to
change from "read" to "write"; the promote method
returns a boolean indicating whether the promotion was possible or not.
public static <T extends Transactional> void exec(T txn, TxnType txnType, Runnable r)
trasnaction type.public static <T extends Transactional,X> X calc(T txn, TxnType txnType, Supplier<X> r)
trasnaction type.public static <T extends Transactional> void executeRead(T txn, Runnable r)
public static <T extends Transactional,X> X calculateRead(T txn, Supplier<X> r)
public static <T extends Transactional> void executeWrite(T txn, Runnable r)
public static <T extends Transactional,X> X calculateWrite(T txn, Supplier<X> r)
Licenced under the Apache License, Version 2.0