Single Query Transactions
Learn how to perform bulk-loading transactions with the SDK.
Unresolved include directive in modules/howtos/pages/transactions-single-query.adoc - include::7.1.2@sdk:shared:partial$acid-transactions.adoc[]
try {
var result = cluster.query(bulkLoadStatement, QueryOptions.queryOptions().asTransaction());
} catch (TransactionCommitAmbiguousException e) {
throw logCommitAmbiguousError(e);
} catch (TransactionFailedException e) {
throw logFailure(e);
} catch (CouchbaseException e) {
// Any standard query errors can be raised here too, such as ParsingFailureException. In these cases the
// transaction definitely did not reach commit point.
logger.warning("Transaction did not reach commit point");
throw e;
}
You can also run a single query transaction against a particular Scope
(these examples will exclude the full error handling for brevity):
Bucket travelSample = cluster.bucket("travel-sample");
Scope inventory = travelSample.scope("inventory");
inventory.query(bulkLoadStatement, QueryOptions.queryOptions().asTransaction());
and configure it:
cluster.query(bulkLoadStatement, QueryOptions.queryOptions()
// Single query transactions will often want to increase the default timeout
.timeout(Duration.ofSeconds(360))
.asTransaction(singleQueryTransactionOptions()
.durabilityLevel(DurabilityLevel.PERSIST_TO_MAJORITY)));