Class AsyncTransactWriteBuilder
Obtain via AsyncDynamoSimplifiedClient.transactWrite(). All actions succeed
or none are applied. If any condition fails or a conflict occurs, the entire transaction
is rejected.
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractTransactWriteBuilder
AbstractTransactWriteBuilder.Operation -
Field Summary
Fields inherited from class AbstractTransactWriteBuilder
operations, returnConsumedCapacity -
Constructor Summary
ConstructorsConstructorDescriptionAsyncTransactWriteBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient enhancedClient, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient) Constructs a newAsyncTransactWriteBuilder. -
Method Summary
Modifier and TypeMethodDescription<T> @NonNull AsyncTransactWriteBuilderconditionCheck(@NonNull AsyncTable<T> table, @NonNull Object partitionKey, @Nullable Object sortKey, @NonNull Consumer<ConditionExpression.Builder> condition) Adds a condition check action with sort key.<T> @NonNull AsyncTransactWriteBuilderconditionCheck(@NonNull AsyncTable<T> table, @NonNull Object partitionKey, @NonNull Consumer<ConditionExpression.Builder> condition) Adds a condition check action that verifies a condition on an item without modifying it.<T> @NonNull AsyncTransactWriteBuilderdelete(@NonNull AsyncTable<T> table, @NonNull Object partitionKey) Adds a delete action by partition key.<T> @NonNull AsyncTransactWriteBuilderdelete(@NonNull AsyncTable<T> table, @NonNull Object partitionKey, @NonNull Object sortKey) Adds a delete action by partition and sort key.@NonNull CompletableFuture<Void> execute()Executes the transactional write operation asynchronously.protected @NonNull StringgetTableName(@NonNull AbstractTransactWriteBuilder.Operation operation) Extracts the DynamoDB table name from an operation's table reference.protected @NonNull software.amazon.awssdk.enhanced.dynamodb.TableSchema<?> getTableSchema(@NonNull AbstractTransactWriteBuilder.Operation operation) Extracts the table schema from an operation's table reference.protected @NonNull software.amazon.awssdk.enhanced.dynamodb.KeykeyFromItem(@NonNull AbstractTransactWriteBuilder.Operation operation, @NonNull Object item) Creates aKeyfrom the given item using the operation's table reference.<T> @NonNull AsyncTransactWriteBuilderput(@NonNull AsyncTable<T> table, @NonNull T item) Adds a put action to insert or replace an item.@NonNull AsyncTransactWriteBuilderreturnConsumedCapacity(@NonNull software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity returnConsumedCapacity) Configures whether to return consumed capacity information for the operation.protected @NonNull AsyncTransactWriteBuilderself()Returnsthistyped asSfor fluent chaining.<T> @NonNull AsyncTransactWriteBuilderupdate(@NonNull AsyncTable<T> table, @NonNull T item) Adds an update action to modify an existing item.<T> @NonNull AsyncTransactWriteBuilderupdate(@NonNull AsyncTable<T> table, @NonNull T item, @NonNull Consumer<UpdateExpression> expressionConfigurator) Adds an update action with a partial update expression for fine-grained attribute modifications.Methods inherited from class AbstractTransactWriteBuilder
buildConditionCheckItem, buildDeleteItem, buildKey, buildPutItem, buildTransactWriteItem, buildUpdateWithExpressionItem, hasExpressionOperation
-
Constructor Details
-
AsyncTransactWriteBuilder
public AsyncTransactWriteBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient enhancedClient, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient) Constructs a newAsyncTransactWriteBuilder.- Parameters:
enhancedClient- the enhanced async DynamoDB clientdynamoDbAsyncClient- the low-level async DynamoDB client
-
-
Method Details
-
self
Description copied from class:AbstractTransactWriteBuilderReturnsthistyped asSfor fluent chaining.- Specified by:
selfin classAbstractTransactWriteBuilder<AsyncTransactWriteBuilder>- Returns:
- this builder
-
getTableName
Description copied from class:AbstractTransactWriteBuilderExtracts the DynamoDB table name from an operation's table reference.- Specified by:
getTableNamein classAbstractTransactWriteBuilder<AsyncTransactWriteBuilder>- Parameters:
operation- the operation whose table name to extract- Returns:
- the DynamoDB table name
-
getTableSchema
protected @NonNull software.amazon.awssdk.enhanced.dynamodb.TableSchema<?> getTableSchema(@NonNull AbstractTransactWriteBuilder.Operation operation) Description copied from class:AbstractTransactWriteBuilderExtracts the table schema from an operation's table reference.- Specified by:
getTableSchemain classAbstractTransactWriteBuilder<AsyncTransactWriteBuilder>- Parameters:
operation- the operation whose table schema to extract- Returns:
- the table schema
-
keyFromItem
protected @NonNull software.amazon.awssdk.enhanced.dynamodb.Key keyFromItem(@NonNull AbstractTransactWriteBuilder.Operation operation, @NonNull Object item) Description copied from class:AbstractTransactWriteBuilderCreates aKeyfrom the given item using the operation's table reference.- Specified by:
keyFromItemin classAbstractTransactWriteBuilder<AsyncTransactWriteBuilder>- Parameters:
operation- the operation providing the table referenceitem- the item from which to extract the key- Returns:
- the constructed key
-
put
Adds a put action to insert or replace an item.- Type Parameters:
T- the item type- Parameters:
table- the typed async table to write toitem- the item to put- Returns:
- this builder
-
update
Adds an update action to modify an existing item.- Type Parameters:
T- the item type- Parameters:
table- the typed async table to updateitem- the item with updated values- Returns:
- this builder
-
update
public <T> @NonNull AsyncTransactWriteBuilder update(@NonNull AsyncTable<T> table, @NonNull T item, @NonNull Consumer<UpdateExpression> expressionConfigurator) Adds an update action with a partial update expression for fine-grained attribute modifications.Use the
expressionConfiguratorto specify SET, REMOVE, ADD, and/or DELETE clauses. When an expression-based update is included in the transaction, the entire transaction is sent via the low-level DynamoDB API rather than the enhanced client.- Type Parameters:
T- the item type- Parameters:
table- the typed async table to updateitem- the item providing the key identifying the item to updateexpressionConfigurator- a consumer to build the update expression- Returns:
- this builder
-
delete
public <T> @NonNull AsyncTransactWriteBuilder delete(@NonNull AsyncTable<T> table, @NonNull Object partitionKey) Adds a delete action by partition key.- Type Parameters:
T- the item type- Parameters:
table- the typed async table to delete frompartitionKey- the partition key value- Returns:
- this builder
-
delete
public <T> @NonNull AsyncTransactWriteBuilder delete(@NonNull AsyncTable<T> table, @NonNull Object partitionKey, @NonNull Object sortKey) Adds a delete action by partition and sort key.- Type Parameters:
T- the item type- Parameters:
table- the typed async table to delete frompartitionKey- the partition key valuesortKey- the sort key value- Returns:
- this builder
-
conditionCheck
public <T> @NonNull AsyncTransactWriteBuilder conditionCheck(@NonNull AsyncTable<T> table, @NonNull Object partitionKey, @NonNull Consumer<ConditionExpression.Builder> condition) Adds a condition check action that verifies a condition on an item without modifying it.If the condition is not satisfied, the entire transaction is rejected.
- Type Parameters:
T- the item type- Parameters:
table- the typed async table to checkpartitionKey- the partition key valuecondition- a consumer to build the condition expression (e.g.expr -> expr.eq("status", "active"))- Returns:
- this builder
-
conditionCheck
public <T> @NonNull AsyncTransactWriteBuilder conditionCheck(@NonNull AsyncTable<T> table, @NonNull Object partitionKey, @Nullable Object sortKey, @NonNull Consumer<ConditionExpression.Builder> condition) Adds a condition check action with sort key.- Type Parameters:
T- the item type- Parameters:
table- the typed async table to checkpartitionKey- the partition key valuesortKey- the sort key valuecondition- a consumer to build the condition expression- Returns:
- this builder
-
returnConsumedCapacity
public @NonNull AsyncTransactWriteBuilder returnConsumedCapacity(@NonNull software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity returnConsumedCapacity) Configures whether to return consumed capacity information for the operation.- Parameters:
returnConsumedCapacity- the consumed capacity reporting level- Returns:
- this builder for chaining
-
execute
Executes the transactional write operation asynchronously.All actions are applied atomically. If any action fails, a
TransactionCanceledExceptionis thrown.If any operation in the transaction uses an
UpdateExpression, the entire transaction is sent via the low-level DynamoDB API. Otherwise, the enhanced DynamoDB client is used.- Returns:
- a
CompletableFuturethat completes when the transaction has been applied
-