Package org.apache.ignite
Interface IgniteTransactions
-
public interface IgniteTransactionsTransactions facade provides ACID-compliant semantic when working with caches. You can create a transaction when working with one cache or across multiple caches. Caches with different cache modes, likePARTITIONEDorREPLICATED, can also participate in the same transaction.Transactions are
AutoCloseable, so they will automatically rollback unless explicitly committed.Here is an example of a transaction:
try (Transaction tx = Ignition.ignite().transactions().txStart()) { Account acct = cache.get(acctId); // Current balance. double balance = acct.getBalance(); // Deposit $100 into account. acct.setBalance(balance + 100); // Store updated account in cache. cache.put(acctId, acct); tx.commit(); }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Collection<Transaction>localActiveTransactions()Returns a list of active transactions initiated by this node.TransactionMetricsmetrics()voidresetMetrics()Resets transaction metrics.Transactiontx()Gets transaction started by this thread ornullif this thread does not have a transaction.TransactiontxStart()Starts transaction with default isolation, concurrency, timeout, and invalidation policy.TransactiontxStart(TransactionConcurrency concurrency, TransactionIsolation isolation)Starts new transaction with the specified concurrency and isolation.TransactiontxStart(TransactionConcurrency concurrency, TransactionIsolation isolation, long timeout, int txSize)Starts transaction with specified isolation, concurrency, timeout, invalidation flag, and number of participating entries.IgniteTransactionswithLabel(String lb)Returns instance of Ignite Transactions to mark a transaction with a special label.IgniteTransactionswithTracing()Returns an instance ofIgniteTransactionstran will trace every transaction.
-
-
-
Method Detail
-
txStart
Transaction txStart() throws IllegalStateException
Starts transaction with default isolation, concurrency, timeout, and invalidation policy. All defaults are set inTransactionConfigurationat startup.- Returns:
- New transaction
- Throws:
IllegalStateException- If transaction is already started by this thread.
-
txStart
Transaction txStart(TransactionConcurrency concurrency, TransactionIsolation isolation)
Starts new transaction with the specified concurrency and isolation.- Parameters:
concurrency- Concurrency.isolation- Isolation.- Returns:
- New transaction.
- Throws:
IllegalStateException- If transaction is already started by this thread.
-
txStart
Transaction txStart(TransactionConcurrency concurrency, TransactionIsolation isolation, long timeout, int txSize)
Starts transaction with specified isolation, concurrency, timeout, invalidation flag, and number of participating entries.- Parameters:
concurrency- Concurrency.isolation- Isolation.timeout- Timeout.txSize- Number of entries participating in transaction (may be approximate).- Returns:
- New transaction.
- Throws:
IllegalStateException- If transaction is already started by this thread.
-
tx
Transaction tx()
Gets transaction started by this thread ornullif this thread does not have a transaction.- Returns:
- Transaction started by this thread or
nullif this thread does not have a transaction.
-
metrics
TransactionMetrics metrics()
- Returns:
- Transaction metrics.
-
resetMetrics
void resetMetrics()
Resets transaction metrics.
-
localActiveTransactions
Collection<Transaction> localActiveTransactions()
Returns a list of active transactions initiated by this node.Note: returned transaction handle will only support getters,
Transaction.close(),Transaction.rollback(),Transaction.rollbackAsync()methods. Trying to invoke other methods will lead to UnsupportedOperationException.- Returns:
- Transactions started on local node.
-
withLabel
IgniteTransactions withLabel(String lb)
Returns instance of Ignite Transactions to mark a transaction with a special label. The label can be obtained viaTransaction.label()method.- Parameters:
lb- label.- Returns:
Thisfor chaining.- Throws:
NullPointerException- if label is null.- See Also:
Transaction.label()
-
withTracing
IgniteTransactions withTracing()
Returns an instance ofIgniteTransactionstran will trace every transaction.- Returns:
- Trace-enabled transactions intance.
-
-