Class TransactWriteBuilder
Obtain via DynamoSimplifiedClient.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
ConstructorsConstructorDescriptionTransactWriteBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient enhancedClient, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient) Constructs a transactional write builder. -
Method Summary
Modifier and TypeMethodDescription<T> @NonNull TransactWriteBuilderconditionCheck(@NonNull Table<T> table, @NonNull Object partitionKey, @Nullable Object sortKey, @NonNull Consumer<ConditionExpression.Builder> condition) Adds a condition check action with sort key.<T> @NonNull TransactWriteBuilderconditionCheck(@NonNull Table<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 TransactWriteBuilderAdds a delete action by partition key.<T> @NonNull TransactWriteBuilderAdds a delete action by partition and sort key.voidexecute()Executes the transactional write operation.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 TransactWriteBuilderAdds a put action to insert or replace an item.@NonNull TransactWriteBuilderreturnConsumedCapacity(@NonNull software.amazon.awssdk.services.dynamodb.model.ReturnConsumedCapacity returnConsumedCapacity) Configures whether to return consumed capacity information for the operation.protected @NonNull TransactWriteBuilderself()Returnsthistyped asSfor fluent chaining.<T> @NonNull TransactWriteBuilderAdds an update action to modify an existing item.<T> @NonNull TransactWriteBuilderupdate(@NonNull Table<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
-
TransactWriteBuilder
public TransactWriteBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient enhancedClient, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient) Constructs a transactional write builder.Typically obtained via
DynamoSimplifiedClient.transactWrite().- Parameters:
enhancedClient- the enhanced DynamoDB clientdynamoDbClient- the low-level DynamoDB client (used for expression-based update fallback)
-
-
Method Details
-
self
Description copied from class:AbstractTransactWriteBuilderReturnsthistyped asSfor fluent chaining.- Specified by:
selfin classAbstractTransactWriteBuilder<TransactWriteBuilder>- Returns:
- this builder
-
getTableName
Description copied from class:AbstractTransactWriteBuilderExtracts the DynamoDB table name from an operation's table reference.- Specified by:
getTableNamein classAbstractTransactWriteBuilder<TransactWriteBuilder>- 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<TransactWriteBuilder>- 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<TransactWriteBuilder>- 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 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 table to updateitem- the item with updated values- Returns:
- this builder
-
update
public <T> @NonNull TransactWriteBuilder update(@NonNull Table<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 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 TransactWriteBuilder delete(@NonNull Table<T> table, @NonNull Object partitionKey) Adds a delete action by partition key.- Type Parameters:
T- the item type- Parameters:
table- the typed table to delete frompartitionKey- the partition key value- Returns:
- this builder
-
delete
public <T> @NonNull TransactWriteBuilder delete(@NonNull Table<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 table to delete frompartitionKey- the partition key valuesortKey- the sort key value- Returns:
- this builder
-
conditionCheck
public <T> @NonNull TransactWriteBuilder conditionCheck(@NonNull Table<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 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 TransactWriteBuilder conditionCheck(@NonNull Table<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 table to checkpartitionKey- the partition key valuesortKey- the sort key valuecondition- a consumer to build the condition expression- Returns:
- this builder
-
returnConsumedCapacity
public @NonNull TransactWriteBuilder 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
public void execute()Executes the transactional write operation.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.
-