Skip to content
Permalink
Browse files
IGNITE-16148 Enrich IgniteTransactions javadoc with tx examples. Fixes
  • Loading branch information
sk0x50 committed Feb 8, 2022
1 parent ca09fba commit 9aaaf48e80bb732410ec349cd8639b4d027ef00d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
@@ -20,9 +20,42 @@
import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.function.Function;
import org.apache.ignite.table.Table;

/**
* Ignite Transactions facade.
* Ignite Transactions facade that allows to perform distributed transactions when working with tables.
* This interface provides the ability to perform transactions in both synchronous and asynchronous ways.
* <pre><code>
* // Synchronous transactional API to update the balance.
* client.transactions().runInTransaction(tx -&gt; {
* Account account = accounts.get(tx, key);
*
* account.balance += 200.0d;
*
* accounts.put(tx, key, account);
* });
* </code></pre>
* There is no need to call {@link Transaction#commit()} explicitly.
* The transaction is automatically committed when the closure is successfully executed.
*
* <pre><code>
* // Using asynchronous transactional API to update the balance.
* CompletableFuture&lt;Void&gt; fut = client.transactions().beginAsync().thenCompose(tx -&gt;
* accounts
* .getAsync(tx, key)
* .thenCompose(account -&gt; {
* account.balance += 200.0d;
*
* return accounts.putAsync(tx, key, account);
* })
* .thenCompose(ignored -&gt; tx.commitAsync())
* );
*
* // Wait for completion.
* fut.join();
* </code></pre>
*
* @see Table
*/
public interface IgniteTransactions {
/**
@@ -26,7 +26,7 @@ public interface Transaction {
/**
* Synchronously commits a transaction.
*
* @throws TransactionException If a transaction can't be commited.
* @throws TransactionException If a transaction can't be committed.
*/
void commit() throws TransactionException;

0 comments on commit 9aaaf48

Please sign in to comment.