Class AsyncTable<T>
- Type Parameters:
T- the item type mapped to this table
Obtained via AsyncDynamoSimplifiedClient.table(String, Class).
Provides async builders through query(), scan(), get(),
put(), update(), delete(), batchGet(), and
batchWrite(). Their terminal methods return CompletableFuture where
applicable. It also provides convenience direct methods (getItem, putItem, updateItem,
deleteItem) and asynchronous DDL operations (create, delete, describe).
-
Constructor Summary
ConstructorsConstructorDescriptionAsyncTable(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient enhancedAsyncClient, @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable<T> dynamoDbAsyncTable, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient) Creates a newAsyncTablewrapping the given clients and table mapping. -
Method Summary
Modifier and TypeMethodDescription@NonNull AsyncBatchGetBuilder<T> batchGet()Starts building an async batch get operation to retrieve multiple items by their keys.@NonNull AsyncBatchWriteBuilder<T> Starts building an async batch write operation to put and delete multiple items.@NonNull CompletableFuture<Void> create()Creates the DynamoDB table corresponding to thisAsyncTableinstance.@NonNull CompletableFuture<Void> create(@NonNull Consumer<software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest.Builder> configurator) Creates the DynamoDB table with options configured by a consumer.@NonNull CompletableFuture<Void> create(@NonNull software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest request) Creates the DynamoDB table with the given request options.@NonNull CompletableFuture<Void> delete()Deletes the DynamoDB table corresponding to thisAsyncTableinstance permanently.@NonNull AsyncDeleteBuilder<T> Starts building a delete operation by partition key with optional conditions.@NonNull AsyncDeleteBuilder<T> Starts building a delete operation by partition and sort key with optional conditions.@NonNull CompletableFuture<T> deleteItem(@NonNull Object partitionKey) Deletes an item by partition key directly.@NonNull CompletableFuture<T> deleteItem(@NonNull Object partitionKey, @NonNull Object sortKey) Deletes an item by partition and sort key directly.@NonNull CompletableFuture<software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse> describe()Returns information about the DynamoDB table, including its status, schema, throughput settings, and indexes.@NonNull CompletableFuture<software.amazon.awssdk.services.dynamodb.model.TimeToLiveDescription> Describes the current TTL configuration for this table.@NonNull CompletableFuture<Void> disableTtl(@NonNull String attributeName) Disables TTL on this table for the given attribute name.@NonNull CompletableFuture<Void> Enables Time To Live (TTL) on this table with the given attribute name.@NonNull CompletableFuture<Boolean> exists()Checks whether the DynamoDB table exists.@NonNull AsyncGetItemBuilder<T> Starts building a get operation by partition key.@NonNull AsyncGetItemBuilder<T> Starts building a get operation by partition and sort key.@NonNull software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClientReturns the underlying low-levelDynamoDbAsyncClient.@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClientReturns the underlyingDynamoDbEnhancedAsyncClientfor advanced operations.@NonNull CompletableFuture<Optional<T>> Fetches an item by partition key directly.@NonNull CompletableFuture<Optional<T>> Fetches an item by partition and sort key directly.@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable<T> Returns the underlyingDynamoDbAsyncTablefor advanced operations.@NonNull AsyncIndex<T> Returns a typed wrapper for the named secondary index (GSI or LSI).@NonNull AsyncPutBuilder<T> Starts building a put operation with optional conditions.@NonNull CompletableFuture<BatchWriteResult> putAll(@NonNull Collection<T> items) Puts all items in a single async batch write operation.@NonNull CompletableFuture<Void> Puts an item directly without conditions.@NonNull AsyncQueryBuilder<T> query()Starts building an async query operation against this table.@NonNull AsyncScanBuilder<T> scan()Starts building an async scan operation against this table.@NonNull AsyncUpdateBuilder<T> Starts building an update operation with optional conditions and partial expressions.@NonNull AsyncUpdateBuilder<T> update(@NonNull T item, @NonNull Consumer<UpdateExpression> expressionConsumer) Starts building a partial update operation with an expression consumer.@NonNull CompletableFuture<Void> update(@NonNull Object partitionKey, @Nullable Object sortKey, @NonNull Consumer<UpdateExpression> expressionConsumer) Updates an item identified by partition and sort key using a partial update expression.@NonNull CompletableFuture<T> updateItem(@NonNull T item) Updates an item directly without conditions or partial expressions.@NonNull CompletableFuture<Void> updateTable(@NonNull Consumer<software.amazon.awssdk.services.dynamodb.model.UpdateTableRequest.Builder> requestConsumer) Updates the DynamoDB table with the specified configuration.
-
Constructor Details
-
AsyncTable
public AsyncTable(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient enhancedAsyncClient, @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable<T> dynamoDbAsyncTable, @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient) Creates a newAsyncTablewrapping the given clients and table mapping.- Parameters:
enhancedAsyncClient- the enhanced async DynamoDB clientdynamoDbAsyncTable- the async DynamoDB table mappingdynamoDbAsyncClient- the low-level async DynamoDB client
-
-
Method Details
-
query
Starts building an async query operation against this table.- Returns:
- an
AsyncQueryBuilderfor configuring and executing the query
-
scan
Starts building an async scan operation against this table.- Returns:
- an
AsyncScanBuilderfor configuring and executing the scan
-
get
Starts building a get operation by partition key.- Parameters:
partitionKey- the partition key value- Returns:
- an
AsyncGetItemBuilderfor configuring and executing the get
-
get
Starts building a get operation by partition and sort key.- Parameters:
partitionKey- the partition key valuesortKey- the sort key value- Returns:
- an
AsyncGetItemBuilderfor configuring and executing the get
-
getItem
Fetches an item by partition key directly.- Parameters:
partitionKey- the partition key value- Returns:
- a
CompletableFuturecontaining anOptionalwith the item, or empty if not found
-
getItem
public @NonNull CompletableFuture<Optional<T>> getItem(@NonNull Object partitionKey, @NonNull Object sortKey) Fetches an item by partition and sort key directly.- Parameters:
partitionKey- the partition key valuesortKey- the sort key value- Returns:
- a
CompletableFuturecontaining anOptionalwith the item, or empty if not found
-
put
Starts building a put operation with optional conditions.- Parameters:
item- the item to put- Returns:
- an
AsyncPutBuilderfor configuring and executing the put
-
putItem
Puts an item directly without conditions.- Parameters:
item- the item to put- Returns:
- a
CompletableFuturethat completes when the item has been put
-
update
Starts building an update operation with optional conditions and partial expressions.- Parameters:
item- the item with updated values- Returns:
- an
AsyncUpdateBuilderfor configuring and executing the update
-
update
public @NonNull AsyncUpdateBuilder<T> update(@NonNull T item, @NonNull Consumer<UpdateExpression> expressionConsumer) Starts building a partial update operation with an expression consumer.This is a convenience shorthand for
update(item).update(consumer). The returned builder can be further configured before callingexecute().- Parameters:
item- the item identifying the record to update (key fields only)expressionConsumer- a consumer to configure the update expression (SET, REMOVE, ADD, DELETE)- Returns:
- an async update builder for further configuration and execution
-
update
public @NonNull CompletableFuture<Void> update(@NonNull Object partitionKey, @Nullable Object sortKey, @NonNull Consumer<UpdateExpression> expressionConsumer) Updates an item identified by partition and sort key using a partial update expression.This avoids creating a dummy item object when the key is already known. Pass
nullfor the sort key when the table has no sort key.- Parameters:
partitionKey- the partition key valuesortKey- the sort key value, ornullif the table has no sort keyexpressionConsumer- a consumer to build the update expression- Returns:
- a
CompletableFuturethat completes when the update has been executed
-
updateItem
Updates an item directly without conditions or partial expressions.- Parameters:
item- the item with updated values- Returns:
- a
CompletableFuturecontaining the updated item as returned by DynamoDB
-
delete
Starts building a delete operation by partition key with optional conditions.- Parameters:
partitionKey- the partition key value- Returns:
- an
AsyncDeleteBuilderfor configuring and executing the delete
-
delete
Starts building a delete operation by partition and sort key with optional conditions.- Parameters:
partitionKey- the partition key valuesortKey- the sort key value- Returns:
- an
AsyncDeleteBuilderfor configuring and executing the delete
-
deleteItem
Deletes an item by partition key directly.- Parameters:
partitionKey- the partition key value- Returns:
- a
CompletableFuturethat completes with the deleted item, ornullif no item with the given key exists
-
deleteItem
public @NonNull CompletableFuture<T> deleteItem(@NonNull Object partitionKey, @NonNull Object sortKey) Deletes an item by partition and sort key directly.- Parameters:
partitionKey- the partition key valuesortKey- the sort key value- Returns:
- a
CompletableFuturethat completes with the deleted item, ornullif no item with the given key exists
-
index
Returns a typed wrapper for the named secondary index (GSI or LSI).Use the returned
AsyncIndexto perform query and scan operations scoped to that index.- Parameters:
indexName- the name of the secondary index- Returns:
- an
AsyncIndex<T>for the specified index
-
batchGet
Starts building an async batch get operation to retrieve multiple items by their keys.- Returns:
- an
AsyncBatchGetBuilderfor configuring and executing the batch get
-
batchWrite
Starts building an async batch write operation to put and delete multiple items.- Returns:
- an
AsyncBatchWriteBuilderfor configuring and executing the batch write
-
putAll
Puts all items in a single async batch write operation.Equivalent to creating an
AsyncBatchWriteBuilder, adding all items, and executing it. At most 25 items per call are allowed by DynamoDB.- Parameters:
items- the items to put- Returns:
- a future containing the batch write result
- Throws:
IllegalArgumentException- if more than 25 items are provided
-
getRawTable
Returns the underlyingDynamoDbAsyncTablefor advanced operations.- Returns:
- the raw async DynamoDB table instance
-
getEnhancedClient
public @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedAsyncClient getEnhancedClient()Returns the underlyingDynamoDbEnhancedAsyncClientfor advanced operations.- Returns:
- the enhanced async DynamoDB client
-
getDynamoDbClient
public @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient getDynamoDbClient()Returns the underlying low-levelDynamoDbAsyncClient.- Returns:
- the low-level async DynamoDB client
-
create
Creates the DynamoDB table corresponding to thisAsyncTableinstance.Uses the table schema defined during
AsyncDynamoSimplifiedClient.table(String, Class)to create the table.- Returns:
- a
CompletableFuturethat completes when the table has been created
-
create
public @NonNull CompletableFuture<Void> create(@NonNull software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest request) Creates the DynamoDB table with the given request options.- Parameters:
request- the create table request options- Returns:
- a
CompletableFuturethat completes when the table has been created
-
create
public @NonNull CompletableFuture<Void> create(@NonNull Consumer<software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest.Builder> configurator) Creates the DynamoDB table with options configured by a consumer.Example usage:
asyncTable.create(b -> b .provisionedThroughput(p -> p .readCapacityUnits(10L) .writeCapacityUnits(10L)));- Parameters:
configurator- a consumer to configure theCreateTableEnhancedRequest.Builder- Returns:
- a
CompletableFuturethat completes when the table has been created
-
delete
Deletes the DynamoDB table corresponding to thisAsyncTableinstance permanently.- Returns:
- a
CompletableFuturethat completes when the table has been deleted
-
describe
public @NonNull CompletableFuture<software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse> describe()Returns information about the DynamoDB table, including its status, schema, throughput settings, and indexes.- Returns:
- a
CompletableFuturecontaining the table description response
-
updateTable
public @NonNull CompletableFuture<Void> updateTable(@NonNull Consumer<software.amazon.awssdk.services.dynamodb.model.UpdateTableRequest.Builder> requestConsumer) Updates the DynamoDB table with the specified configuration.Example usage:
asyncTable.updateTable(b -> b .provisionedThroughput(p -> p .readCapacityUnits(10L) .writeCapacityUnits(10L)));- Parameters:
requestConsumer- a consumer to configure theUpdateTableRequest.Builder- Returns:
- a
CompletableFuturethat completes when the table has been updated
-
exists
Checks whether the DynamoDB table exists.Returns a
CompletableFuturethat completes withtrueif the table exists, orfalseif it does not.- Returns:
- a future that completes with
trueif the table exists,falseotherwise
-
enableTtl
Enables Time To Live (TTL) on this table with the given attribute name.- Parameters:
attributeName- the attribute that stores the TTL epoch value- Returns:
- a
CompletableFuturethat completes when TTL has been enabled
-
disableTtl
Disables TTL on this table for the given attribute name.- Parameters:
attributeName- the TTL attribute name to disable- Returns:
- a
CompletableFuturethat completes when TTL has been disabled
-
describeTtl
public @NonNull CompletableFuture<software.amazon.awssdk.services.dynamodb.model.TimeToLiveDescription> describeTtl()Describes the current TTL configuration for this table.- Returns:
- a
CompletableFuturecontaining the TTL description
-