Class Table<T>
- Type Parameters:
T- the item type mapped to this table
Obtained via DynamoSimplifiedClient.table(String, Class).
Provides fluent builder access (query, scan, put, get, update, delete)
and convenience direct methods (putItem, getItem, updateItem, deleteItem).
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NonNull BatchGetBuilder<T> batchGet()Starts building a batch get operation to retrieve multiple items by key.@NonNull BatchWriteBuilder<T> Starts building a batch write operation to put and delete multiple items.voidcreate()Creates the DynamoDB table corresponding to thisTableinstance.voidcreate(@NonNull Consumer<software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest.Builder> configurator) Creates the DynamoDB table with options configured by a consumer.voidcreate(@NonNull software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest request) Creates the DynamoDB table with additional options.voiddelete()Deletes the DynamoDB table corresponding to thisTableinstance permanently.@NonNull DeleteBuilder<T> Starts building a delete operation by partition key with optional conditions.@NonNull DeleteBuilder<T> Starts building a delete operation by partition and sort key with optional conditions.@Nullable TdeleteItem(@NonNull Object partitionKey) Deletes an item by partition key directly.@Nullable TdeleteItem(@NonNull Object partitionKey, @NonNull Object sortKey) Deletes an item by partition and sort key directly.@NonNull software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponsedescribe()Returns information about the DynamoDB table, including its status, schema, throughput settings, and indexes.@NonNull software.amazon.awssdk.services.dynamodb.model.TimeToLiveDescriptionDescribes the current TTL configuration for this table.voiddisableTtl(@NonNull String attributeName) Disables TTL on this table for the given attribute name.voidEnables Time To Live (TTL) on this table with the given attribute name.booleanexists()Checks whether the DynamoDB table exists.@NonNull GetItemBuilder<T> Starts building a get operation by partition key.@NonNull GetItemBuilder<T> Starts building a get operation by partition and sort key.@NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClientReturns the underlying low-levelDynamoDbClient.@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClientReturns the underlyingDynamoDbEnhancedClientfor advanced operations.Fetches an item by partition key directly.Fetches an item by partition and sort key directly.@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable<T> Returns the underlyingDynamoDbTablefor advanced operations.Returns a typed wrapper for the named secondary index (GSI or LSI).@NonNull PutBuilder<T> Starts building a put operation with optional conditions.@NonNull BatchWriteResultputAll(@NonNull Collection<T> items) Puts all items in a single batch write operation.voidPuts an item directly without conditions.@NonNull QueryBuilder<T> query()Starts building a query operation.@NonNull ScanBuilder<T> scan()Starts building a scan operation.@NonNull UpdateBuilder<T> Starts building an update operation with optional conditions and partial expressions.@NonNull UpdateBuilder<T> update(@NonNull T item, @NonNull Consumer<UpdateExpression> expressionConsumer) Starts building a partial update operation with an expression consumer.voidupdate(@NonNull Object partitionKey, @Nullable Object sortKey, @NonNull Consumer<UpdateExpression> expressionConsumer) Updates an item identified by partition and sort key using a partial update expression.@Nullable TupdateItem(@NonNull T item) Updates an item directly without conditions or partial expressions.voidupdateTable(@NonNull Consumer<software.amazon.awssdk.services.dynamodb.model.UpdateTableRequest.Builder> requestConsumer) Updates the DynamoDB table with the specified configuration.
-
Constructor Details
-
Table
public Table(software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient enhancedClient, software.amazon.awssdk.enhanced.dynamodb.DynamoDbTable<T> dynamoDbTable, software.amazon.awssdk.services.dynamodb.DynamoDbClient dynamoDbClient) Constructs a typed table wrapper.Typically obtained via
DynamoSimplifiedClient.table(String, Class)rather than constructed directly.- Parameters:
enhancedClient- the enhanced DynamoDB clientdynamoDbTable- the typed enhanced DynamoDB tabledynamoDbClient- the low-level DynamoDB client (used for fallback operations)
-
-
Method Details
-
query
Starts building a query operation.Use the returned builder to set the partition key, sort key conditions, filters, and other options, then call
execute().- Returns:
- a query builder for chaining
-
scan
Starts building a scan operation.Use the returned builder to set filters and other options, then call
execute().- Returns:
- a scan builder for chaining
-
get
Starts building a get operation by partition key.Use the returned builder to set projection and consistent read options, then call
execute().- Parameters:
partitionKey- the partition key value- Returns:
- a get builder for chaining
-
get
Starts building a get operation by partition and sort key.Use the returned builder to set projection and consistent read options, then call
execute().- Parameters:
partitionKey- the partition key valuesortKey- the sort key value- Returns:
- a get builder for chaining
-
getItem
-
getItem
-
put
Starts building a put operation with optional conditions.Use the returned builder to set condition expressions and other options, then call
execute().- Parameters:
item- the item to put- Returns:
- a put builder for chaining
-
putItem
Puts an item directly without conditions.- Parameters:
item- the item to put
-
update
Starts building an update operation with optional conditions and partial expressions.Use the returned builder to set condition expressions, update expressions, and other options, then call
execute().- Parameters:
item- the item with updated values- Returns:
- an update builder for chaining
-
update
public @NonNull UpdateBuilder<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 update builder for further configuration and execution
-
update
public 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
-
updateItem
-
delete
Starts building a delete operation by partition key with optional conditions.Use the returned builder to set condition expressions and other options, then call
execute().- Parameters:
partitionKey- the partition key value- Returns:
- a delete builder for chaining
-
delete
Starts building a delete operation by partition and sort key with optional conditions.Use the returned builder to set condition expressions and other options, then call
execute().- Parameters:
partitionKey- the partition key valuesortKey- the sort key value- Returns:
- a delete builder for chaining
-
deleteItem
-
deleteItem
-
index
Returns a typed wrapper for the named secondary index (GSI or LSI).Use the returned
Indexto perform query and scan operations scoped to that index.- Parameters:
indexName- the name of the secondary index- Returns:
- an
Index<T>for the specified index
-
batchGet
Starts building a batch get operation to retrieve multiple items by key.Use the returned builder to add keys and set options, then call
execute()to retrieve the items.- Returns:
- a batch get builder for chaining
-
batchWrite
Starts building a batch write operation to put and delete multiple items.Use the returned builder to add put and delete operations, then call
execute()to submit them.- Returns:
- a batch write builder for chaining
-
putAll
Puts all items in a single batch write operation.Equivalent to creating a
BatchWriteBuilder, adding all items, and executing it. At most 25 items per call are allowed by DynamoDB.- Parameters:
items- the items to put- Returns:
- the batch write result
- Throws:
IllegalArgumentException- if more than 25 items are provided
-
getRawTable
Returns the underlyingDynamoDbTablefor advanced operations.- Returns:
- the raw DynamoDB table instance
-
getEnhancedClient
public @NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient getEnhancedClient()Returns the underlyingDynamoDbEnhancedClientfor advanced operations.- Returns:
- the enhanced DynamoDB client
-
getDynamoDbClient
public @NonNull software.amazon.awssdk.services.dynamodb.DynamoDbClient getDynamoDbClient()Returns the underlying low-levelDynamoDbClient.- Returns:
- the low-level DynamoDB client
-
create
public void create()Creates the DynamoDB table corresponding to thisTableinstance.Uses the table schema defined during
DynamoSimplifiedClient.table(String, Class)to create the table. -
create
public void create(@NonNull software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest request) Creates the DynamoDB table with additional options.- Parameters:
request- the create table request options
-
create
public 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:
table.create(b -> b .provisionedThroughput(p -> p .readCapacityUnits(10L) .writeCapacityUnits(10L)));- Parameters:
configurator- a consumer to configure theCreateTableEnhancedRequest.Builder
-
delete
public void delete()Deletes the DynamoDB table corresponding to thisTableinstance permanently. -
describe
public @NonNull software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse describe()Returns information about the DynamoDB table, including its status, schema, throughput settings, and indexes.- Returns:
- the table description response
-
updateTable
public void updateTable(@NonNull Consumer<software.amazon.awssdk.services.dynamodb.model.UpdateTableRequest.Builder> requestConsumer) Updates the DynamoDB table with the specified configuration.Example usage:
table.updateTable(b -> b .provisionedThroughput(p -> p .readCapacityUnits(10L) .writeCapacityUnits(10L)));- Parameters:
requestConsumer- a consumer to configure theUpdateTableRequest.Builder- Throws:
OperationFailedException- if the DynamoDB API call fails
-
exists
public boolean exists()Checks whether the DynamoDB table exists.Returns
trueif the table exists,falseif it does not.- Returns:
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- Throws:
OperationFailedException- if the DynamoDB API call fails
-
disableTtl
Disables TTL on this table for the given attribute name.- Parameters:
attributeName- the TTL attribute name to disable- Throws:
OperationFailedException- if the DynamoDB API call fails
-
describeTtl
public @NonNull software.amazon.awssdk.services.dynamodb.model.TimeToLiveDescription describeTtl()Describes the current TTL configuration for this table.- Returns:
- the TTL description
- Throws:
OperationFailedException- if the DynamoDB API call fails
-