You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sk...@apache.org on 2022/02/08 14:21:49 UTC
[ignite-3] branch main updated: IGNITE-16148 Enrich IgniteTransactions javadoc with tx examples. Fixes #641
This is an automated email from the ASF dual-hosted git repository.
sk0x50 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git
The following commit(s) were added to refs/heads/main by this push:
new 9aaaf48 IGNITE-16148 Enrich IgniteTransactions javadoc with tx examples. Fixes #641
9aaaf48 is described below
commit 9aaaf48e80bb732410ec349cd8639b4d027ef00d
Author: Slava Koptilin <sl...@gmail.com>
AuthorDate: Tue Feb 8 17:21:20 2022 +0300
IGNITE-16148 Enrich IgniteTransactions javadoc with tx examples. Fixes #641
---
.../org/apache/ignite/tx/IgniteTransactions.java | 35 +++++++++++++++++++++-
.../java/org/apache/ignite/tx/Transaction.java | 2 +-
2 files changed, 35 insertions(+), 2 deletions(-)
diff --git a/modules/api/src/main/java/org/apache/ignite/tx/IgniteTransactions.java b/modules/api/src/main/java/org/apache/ignite/tx/IgniteTransactions.java
index 1d4f92b..21ccff2 100644
--- a/modules/api/src/main/java/org/apache/ignite/tx/IgniteTransactions.java
+++ b/modules/api/src/main/java/org/apache/ignite/tx/IgniteTransactions.java
@@ -20,9 +20,42 @@ package org.apache.ignite.tx;
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 -> {
+ * 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<Void> fut = client.transactions().beginAsync().thenCompose(tx ->
+ * accounts
+ * .getAsync(tx, key)
+ * .thenCompose(account -> {
+ * account.balance += 200.0d;
+ *
+ * return accounts.putAsync(tx, key, account);
+ * })
+ * .thenCompose(ignored -> tx.commitAsync())
+ * );
+ *
+ * // Wait for completion.
+ * fut.join();
+ * </code></pre>
+ *
+ * @see Table
*/
public interface IgniteTransactions {
/**
diff --git a/modules/api/src/main/java/org/apache/ignite/tx/Transaction.java b/modules/api/src/main/java/org/apache/ignite/tx/Transaction.java
index 29c2b3a..f80260e 100644
--- a/modules/api/src/main/java/org/apache/ignite/tx/Transaction.java
+++ b/modules/api/src/main/java/org/apache/ignite/tx/Transaction.java
@@ -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;