public class Transactions extends Object
The main methods to run transactions are run(java.util.function.Consumer<com.couchbase.client.java.transactions.TransactionAttemptContext>, com.couchbase.client.java.transactions.config.TransactionOptions)
and reactive
.
Constructor and Description |
---|
Transactions(com.couchbase.client.core.Core core,
JsonSerializer serializer) |
Modifier and Type | Method and Description |
---|---|
TransactionResult |
run(Consumer<TransactionAttemptContext> transactionLogic)
Runs supplied transactional logic until success or failure.
|
TransactionResult |
run(Consumer<TransactionAttemptContext> transactionLogic,
TransactionOptions options)
Runs supplied transactional logic until success or failure.
|
@Stability.Internal public Transactions(com.couchbase.client.core.Core core, JsonSerializer serializer)
public TransactionResult run(Consumer<TransactionAttemptContext> transactionLogic, @Nullable TransactionOptions options)
The supplied transactional logic will be run if necessary multiple times, until either:
The transaction logic Consumer
is provided a TransactionAttemptContext
, which contains methods allowing it
to perform all operations that are possible inside a transaction.
Commit will be performed automatically if the lambda successfully reaches its end.
transactionLogic
- the application's transaction logicoptions
- the configuration to use for this transactionTransactionResult
, as success is implied by the lack of a
thrown exception. It contains information useful only for debugging and logging.TransactionFailedException
- or a derived exception if the transaction fails to commit for any reason, possibly
after multiple retries. The exception contains further details of the errorpublic TransactionResult run(Consumer<TransactionAttemptContext> transactionLogic)
run(java.util.function.Consumer<com.couchbase.client.java.transactions.TransactionAttemptContext>, com.couchbase.client.java.transactions.config.TransactionOptions)
that provides a default TransactionOptions
Copyright © 2024 Couchbase, Inc.. All rights reserved.