Package com.couchbase.transactions
Class TransactionsReactive
- java.lang.Object
-
- com.couchbase.transactions.TransactionsReactive
-
public class TransactionsReactive extends java.lang.Object
An asynchronous version ofTransactions
, allowing transactions to be created and run in an asynchronous manner.The main method to run transactions is
run(java.util.function.Function<com.couchbase.transactions.AttemptContextReactive, reactor.core.publisher.Mono<java.lang.Void>>, com.couchbase.transactions.config.PerTransactionConfig)
.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description reactor.core.publisher.Mono<TransactionResult>
commit(TransactionSerializedContext serialized, PerTransactionConfig perConfig)
TransactionConfig
config()
reactor.core.publisher.Mono<ReactiveSingleQueryTransactionResult>
query(com.couchbase.client.java.ReactiveScope scope, java.lang.String statement)
Performs a single query transaction, with a scope context and default configuration.reactor.core.publisher.Mono<ReactiveSingleQueryTransactionResult>
query(com.couchbase.client.java.ReactiveScope scope, java.lang.String statement, SingleQueryTransactionConfig queryOptions)
Performs a single query transaction, with a scope context and custom configuration.reactor.core.publisher.Mono<ReactiveSingleQueryTransactionResult>
query(java.lang.String statement)
Performs a single query transaction, with default configuration.reactor.core.publisher.Mono<ReactiveSingleQueryTransactionResult>
query(java.lang.String statement, SingleQueryTransactionConfig queryOptions)
Performs a single query transaction, with a custom configuration.reactor.core.publisher.Mono<TransactionResult>
rollback(TransactionSerializedContext serialized, PerTransactionConfig perConfig)
reactor.core.publisher.Mono<TransactionResult>
run(java.util.function.Function<AttemptContextReactive,reactor.core.publisher.Mono<java.lang.Void>> transactionLogic)
Convenience overload that runsrun(java.util.function.Function<com.couchbase.transactions.AttemptContextReactive, reactor.core.publisher.Mono<java.lang.Void>>, com.couchbase.transactions.config.PerTransactionConfig)
with a defaultPerTransactionConfig
.reactor.core.publisher.Mono<TransactionResult>
run(java.util.function.Function<AttemptContextReactive,reactor.core.publisher.Mono<java.lang.Void>> transactionLogic, PerTransactionConfig perConfig)
Runs the supplied transactional logic until success or failure.
-
-
-
Method Detail
-
run
public reactor.core.publisher.Mono<TransactionResult> run(java.util.function.Function<AttemptContextReactive,reactor.core.publisher.Mono<java.lang.Void>> transactionLogic, PerTransactionConfig perConfig)
Runs the supplied transactional logic until success or failure.This is the asynchronous version of
Transactions.run(java.util.function.Consumer<com.couchbase.transactions.AttemptContext>, com.couchbase.transactions.config.PerTransactionConfig)
, so to cover the differences:- The transaction logic is supplied with a
AttemptContextReactive
, which contains asynchronous methods to allow it to read, mutate, insert and delete documents, as well as commit or rollback the transactions. - The transaction logic should run these methods as a Reactor chain.
- The transaction logic should return a
Mono<Void>
. AnyFlux
orMono
can be converted to aMono<Void>
by calling.then()
on it. - This method returns a
Mono<TransactionResult>
, which should be handled as a normal Reactor Mono.
- Parameters:
transactionLogic
- the application's transaction logicperConfig
- the configuration to use for this transaction- Returns:
- there is no need to check the returned
TransactionResult
, as success is implied by the lack of a thrown exception. It contains information useful only for debugging and logging. - Throws:
TransactionFailed
- or a derived exception if the transaction fails to commit for any reason, possibly after multiple retries. The exception contains further details of the error. Not
- The transaction logic is supplied with a
-
run
public reactor.core.publisher.Mono<TransactionResult> run(java.util.function.Function<AttemptContextReactive,reactor.core.publisher.Mono<java.lang.Void>> transactionLogic)
Convenience overload that runsrun(java.util.function.Function<com.couchbase.transactions.AttemptContextReactive, reactor.core.publisher.Mono<java.lang.Void>>, com.couchbase.transactions.config.PerTransactionConfig)
with a defaultPerTransactionConfig
.
-
commit
@Volatile public reactor.core.publisher.Mono<TransactionResult> commit(TransactionSerializedContext serialized, PerTransactionConfig perConfig)
-
rollback
@Volatile public reactor.core.publisher.Mono<TransactionResult> rollback(TransactionSerializedContext serialized, PerTransactionConfig perConfig)
-
config
public TransactionConfig config()
-
query
@Uncommitted public reactor.core.publisher.Mono<ReactiveSingleQueryTransactionResult> query(java.lang.String statement)
Performs a single query transaction, with default configuration.- Parameters:
statement
- the statement to execute.- Returns:
- a ReactiveSingleQueryTransactionResult
-
query
@Uncommitted public reactor.core.publisher.Mono<ReactiveSingleQueryTransactionResult> query(java.lang.String statement, SingleQueryTransactionConfig queryOptions)
Performs a single query transaction, with a custom configuration.- Parameters:
statement
- the statement to execute.queryOptions
- configuration options.- Returns:
- a ReactiveSingleQueryTransactionResult
-
query
@Uncommitted public reactor.core.publisher.Mono<ReactiveSingleQueryTransactionResult> query(com.couchbase.client.java.ReactiveScope scope, java.lang.String statement)
Performs a single query transaction, with a scope context and default configuration.- Parameters:
statement
- the statement to execute.scope
- the query will be executed in the context of this scope, so it can refer to a collection on this scope rather than needed to provide the full keyspace.- Returns:
- a ReactiveSingleQueryTransactionResult
-
query
@Uncommitted public reactor.core.publisher.Mono<ReactiveSingleQueryTransactionResult> query(com.couchbase.client.java.ReactiveScope scope, java.lang.String statement, SingleQueryTransactionConfig queryOptions)
Performs a single query transaction, with a scope context and custom configuration.- Parameters:
statement
- the statement to execute.scope
- the query will be executed in the context of this scope, so it can refer to a collection on this scope rather than needed to provide the full keyspace.queryOptions
- configuration options.- Returns:
- a ReactiveSingleQueryTransactionResult
-
-