/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * * http://aws.amazon.com/apache2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ package software.amazon.awssdk.enhanced.dynamodb; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import software.amazon.awssdk.annotations.SdkPublicApi; import software.amazon.awssdk.annotations.ThreadSafe; import software.amazon.awssdk.enhanced.dynamodb.model.CreateTableEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.DeleteItemEnhancedResponse; import software.amazon.awssdk.enhanced.dynamodb.model.DescribeTableEnhancedResponse; import software.amazon.awssdk.enhanced.dynamodb.model.GetItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.Page; import software.amazon.awssdk.enhanced.dynamodb.model.PagePublisher; import software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.PutItemEnhancedResponse; import software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional; import software.amazon.awssdk.enhanced.dynamodb.model.QueryEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.ScanEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedRequest; import software.amazon.awssdk.enhanced.dynamodb.model.UpdateItemEnhancedResponse; import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient; import software.amazon.awssdk.services.dynamodb.model.ConsumedCapacity; import software.amazon.awssdk.services.dynamodb.model.DescribeTableRequest; import software.amazon.awssdk.services.dynamodb.waiters.DynamoDbAsyncWaiter; /** * Asynchronous interface for running commands against an object that is linked to a specific DynamoDb table resource * and therefore knows how to map records from that table into a modelled object. *
* By default, all command methods throw an {@link UnsupportedOperationException} to prevent interface extensions from breaking
* implementing classes.
*
* @param
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
*
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous operation and that
* the table may not immediately be available for writes and reads.
* You can use {@link DynamoDbAsyncWaiter#waitUntilTableExists(DescribeTableRequest)} to wait for the resource to be ready.
*
* Example:
*
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
*
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous operation and that
* the table may not immediately be available for writes and reads. You can use
* {@link DynamoDbAsyncWaiter#waitUntilTableExists(DescribeTableRequest)} to wait for the resource to be ready.
*
* Note: This is a convenience method that creates an instance of the request builder avoiding the need to create one
* manually via {@link CreateTableEnhancedRequest#builder()}.
*
* Example:
*
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
*
* This operation calls the low-level DynamoDB API CreateTable operation. Note that this is an asynchronous operation and that
* the table may not immediately be available for writes and reads. You can use
* {@link DynamoDbAsyncWaiter#waitUntilTableExists(DescribeTableRequest)} to wait for the resource to be ready.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link DeleteItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API DeleteItem operation. Consult the DeleteItem documentation for
* further details and constraints.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link DeleteItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API DeleteItem operation. Consult the DeleteItem documentation for
* further details and constraints.
*
* Note: This is a convenience method that creates an instance of the request builder avoiding the need to create one
* manually via {@link DeleteItemEnhancedRequest#builder()}.
*
* Example:
*
* This operation calls the low-level DynamoDB API DeleteItem operation. Consult the DeleteItem documentation for
* further details and constraints.
*
* Example:
*
* This operation calls the low-level DynamoDB API DeleteItem operation. Consult the DeleteItem documentation for
* further details and constraints.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link DeleteItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API DeleteItem operation. Consult the DeleteItem documentation for
* further details and constraints. Unlike {@link #deleteItem(DeleteItemEnhancedRequest)}, this returns a response object,
* allowing the user to retrieve additional information from DynamoDB related to the API call, such as
* {@link ConsumedCapacity} if specified on the request.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link DeleteItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API DeleteItem operation. Consult the DeleteItem documentation for
* further details and constraints. Unlike {@link #deleteItem(Consumer)}, this returns a response object, allowing the user to
* retrieve additional information from DynamoDB related to the API call, such as {@link ConsumedCapacity} if specified on
* the request.
*
* Note: This is a convenience method that creates an instance of the request builder avoiding the need to
* create one manually via {@link DeleteItemEnhancedRequest#builder()}.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link GetItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API GetItem operation. Consult the GetItem documentation for
* further details and constraints.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link GetItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API GetItem operation. Consult the GetItem documentation for
* further details and constraints.
*
* Note: This is a convenience method that creates an instance of the request builder avoiding the need to create one
* manually via {@link GetItemEnhancedRequest#builder()}.
*
* Example:
*
* This operation calls the low-level DynamoDB API GetItem operation. Consult the GetItem documentation for
* further details and constraints.
*
* Example:
*
* This operation calls the low-level DynamoDB API GetItem operation. Consult the GetItem documentation for
* further details and constraints.
*
* Example:
*
* The return type is a custom publisher that can be subscribed to request a stream of {@link Page}s or
* a stream of items across all pages. Results are sorted by sort key value in
* ascending order by default; this behavior can be overridden in the {@link QueryEnhancedRequest}.
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link QueryEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API Query operation. Consult the Query documentation
* {@link DynamoDbAsyncClient#queryPaginator} for further details and constraints.
*
* Example:
*
* 1) Subscribing to {@link Page}s
*
* 2) Subscribing to items across all pages
*
* Note: This is a convenience method that creates an instance of the request builder avoiding the need to create one
* manually via {@link QueryEnhancedRequest#builder()}.
*
* Example:
*
* The result is accessed through iterable pages (see {@link Page}) in an interactive way; each time a
* result page is retrieved, a query call is made to DynamoDb to get those entries. If no matches are found,
* the resulting iterator will contain an empty page. Results are sorted by sort key value in
* ascending order.
*
* This operation calls the low-level DynamoDB API Query operation. Consult the Query documentation for
* further details and constraints.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link PutItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API PutItem operation. Consult the PutItem documentation for
* further details and constraints.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link PutItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API PutItem operation. Consult the PutItem documentation for
* further details and constraints.
*
* Example:
*
* This operation calls the low-level DynamoDB API PutItem operation. Consult the PutItem documentation for
* further details and constraints.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link PutItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API PutItem operation. Consult the PutItem documentation for
* further details and constraints.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link PutItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API PutItem operation. Consult the PutItem documentation for
* further details and constraints.
*
* Example:
*
* The return type is a custom publisher that can be subscribed to request a stream of {@link Page}s or
* a stream of flattened items across all pages. Each time a result page is retrieved, a scan call is made
* to DynamoDb to get those entries. If no matches are found, the resulting iterator will contain an empty page.
*
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link ScanEnhancedRequest}.
*
* Example:
*
* 1) Subscribing to {@link Page}s
*
* 2) Subscribing to items across all pages.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link UpdateItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API UpdateItem operation. Consult the UpdateItem documentation for
* further details and constraints.
*
* Example:
*
* The additional configuration parameters that the enhanced client supports are defined
* in the {@link UpdateItemEnhancedRequest}.
*
* This operation calls the low-level DynamoDB API UpdateItem operation. Consult the UpdateItem documentation for
* further details and constraints.
*
* Example:
*
* This operation calls the low-level DynamoDB API UpdateItem operation. Consult the UpdateItem documentation for
* further details and constraints.
*
* Example:
*
* This operation calls the low-level DynamoDB API UpdateItem operation. Consult the UpdateItem documentation for
* further details and constraints.
*
* Example:
*
*
*
* @param request the modelled item to be inserted into or updated in the database table.
* @return A {@link CompletableFuture} containing the response from DynamoDB.
*/
default CompletableFuture
* This operation calls the low-level DynamoDB API UpdateItem operation. Consult the UpdateItem documentation for
* further details and constraints.
*
* Example:
*
*
*
* @param requestConsumer A {@link Consumer} of {@link UpdateItemEnhancedRequest.Builder} that includes the item
* * to be updated, its class and optional directives.
* @return A {@link CompletableFuture} containing the response from DynamoDB.
*/
default CompletableFuture
* Use {@link DynamoDbEnhancedClient#table(String, TableSchema)} to define the mapped table resource.
*
* This operation calls the low-level DynamoDB API DeleteTable operation.
* Note that this is an asynchronous operation and that the table may not immediately deleted. You can use
* {@link software.amazon.awssdk.services.dynamodb.waiters.DynamoDbAsyncWaiter#waitUntilTableNotExists}
* in the underlying client.
*
* Example:
*
* Example:
*
* {@code
*
* ProvisionedThroughput provisionedThroughput = ProvisionedThroughput.builder()
* .readCapacityUnits(50L)
* .writeCapacityUnits(50L)
* .build();
* mappedTable.createTable(CreateTableEnhancedRequest.builder()
* .provisionedThroughput(provisionedThroughput)
* .build())
* .join();
* asyncClient.waiter().waitUntilTableExists(b -> b.tableName(tableName)).join();
* }
*
*
* @param request A {@link CreateTableEnhancedRequest} containing optional parameters for table creation.
* @return a {@link CompletableFuture} of {@link Void}.
*/
default CompletableFuture
* {@code
*
* ProvisionedThroughput provisionedThroughput = ProvisionedThroughput.builder()
* .readCapacityUnits(50L)
* .writeCapacityUnits(50L)
* .build();
* mappedTable.createTable(r -> r.provisionedThroughput(provisionedThroughput)).join();
* asyncClient.waiter().waitUntilTableExists(b -> b.tableName(tableName)).join();
* }
*
*
* @param requestConsumer A {@link Consumer} of {@link CreateTableEnhancedRequest.Builder} containing optional parameters
* for table creation.
* @return a {@link CompletableFuture} of {@link Void}.
*/
default CompletableFuture
* {@code
*
* mappedTable.createTable().join();
* asyncClient.waiter().waitUntilTableExists(b -> b.tableName(tableName)).join();
* }
*
*
* @return a {@link CompletableFuture} of {@link Void}.
*/
default CompletableFuture
* {@code
*
* MyItem previouslyPersistedItem = mappedTable.delete(DeleteItemEnhancedRequest.builder().key(key).build()).join();
* }
*
*
* @param request A {@link DeleteItemEnhancedRequest} with key and optional directives for deleting an item from the table.
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
*/
default CompletableFuture
* {@code
*
* MyItem previouslyPersistedItem = mappedTable.delete(r -> r.key(key)).join();
* }
*
*
* @param requestConsumer A {@link Consumer} of {@link DeleteItemEnhancedRequest} with key and
* optional directives for deleting an item from the table.
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
*/
default CompletableFuture
* {@code
*
* MyItem previouslyPersistedItem = mappedTable.delete(key).join;
* }
*
*
* @param key A {@link Key} that will be used to match a specific record to delete from the database table.
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
*/
default CompletableFuture
* {@code
*
* MyItem previouslyPersistedItem = mappedTable.deleteItem(keyItem).join();
* }
*
*
* @param keyItem A modelled item with the primary key fields set that will be used to match a specific record to
* delete from the database table.
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
*/
default CompletableFuture
* {@code
*
* DeleteItemEnhancedRequest request = DeleteItemEnhancedRequest.builder().key(key).build();
* DeleteItemEnhancedResponse
*
* @param request A {@link DeleteItemEnhancedRequest} with key and optional directives for deleting an item from the
* table.
* @return A {@code CompletableFuture} containing the response returned by DynamoDB.
*/
default CompletableFuture
* {@code
*
* DeleteItemEnhancedResponse
*
* @param requestConsumer A {@link Consumer} of {@link DeleteItemEnhancedRequest} with key and
* optional directives for deleting an item from the table.
* @return A {@code CompletableFuture} containing the response returned by DynamoDB.
*/
default CompletableFuture
* {@code
*
* MyItem item = mappedTable.getItem(GetItemEnhancedRequest.builder().key(key).build()).join();
* }
*
*
* @param request A {@link GetItemEnhancedRequest} with key and optional directives for retrieving an item from the table.
* @return a {@link CompletableFuture} of the item that was persisted in the database before it was deleted.
*/
default CompletableFuture
* {@code
*
* MyItem item = mappedTable.getItem(r -> r.key(key)).join();
* }
*
*
* @param requestConsumer A {@link Consumer} of {@link GetItemEnhancedRequest.Builder} with key and optional directives
* for retrieving an item from the table.
* @return a {@link CompletableFuture} of the retrieved item
*/
default CompletableFuture
* {@code
*
* MyItem item = mappedTable.getItem(key).join();
* }
*
*
* @param key A {@link Key} that will be used to match a specific record to retrieve from the database table.
* @return a {@link CompletableFuture} of the retrieved item
*/
default CompletableFuture
* {@code
*
* MyItem item = mappedTable.getItem(keyItem).join();
* }
*
*
* @param keyItem A modelled item with the primary key fields set that will be used to match a specific record to
* retrieve from the database table.
* @return a {@link CompletableFuture} of the retrieved item
*/
default CompletableFuture
* {@code
*
* QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue("id-value").build());
* PagePublisher
*
* {@code
*
* QueryConditional queryConditional = QueryConditional.keyEqualTo(Key.builder().partitionValue("id-value").build());
* PagePublisher
*
* @see #query(Consumer)
* @see #query(QueryConditional)
* @see DynamoDbAsyncClient#queryPaginator
* @param request A {@link QueryEnhancedRequest} defining the query conditions and how
* to handle the results.
* @return a publisher {@link PagePublisher} with paginated results (see {@link Page}).
*/
default PagePublisher
* {@code
*
* PagePublisher
*
* @see #query(QueryEnhancedRequest)
* @see #query(QueryConditional)
* @see DynamoDbAsyncClient#queryPaginator
* @param requestConsumer A {@link Consumer} of {@link QueryEnhancedRequest} defining the query conditions and how to
* handle the results.
* @return a publisher {@link PagePublisher} with paginated results (see {@link Page}).
*/
default PagePublisher
* {@code
*
* PagePublisher
*
* @see #query(QueryEnhancedRequest)
* @see #query(Consumer)
* @see DynamoDbAsyncClient#queryPaginator
* @param queryConditional A {@link QueryConditional} defining the matching criteria for records to be queried.
* @return a publisher {@link PagePublisher} with paginated results (see {@link Page}).
*/
default PagePublisher
* {@code
*
* mappedTable.putItem(PutItemEnhancedRequest.builder(MyItem.class).item(item).build()).join();
* }
*
*
* @param request A {@link PutItemEnhancedRequest} that includes the item to enter into
* the table, its class and optional directives.
* @return a {@link CompletableFuture} that returns no results which will complete when the operation is done.
*/
default CompletableFuture
* {@code
*
* mappedTable.putItem(r -> r.item(item)).join();
* }
*
*
* @param requestConsumer A {@link Consumer} of {@link PutItemEnhancedRequest.Builder} that includes the item
* to enter into the table, its class and optional directives.
* @return a {@link CompletableFuture} that returns no results which will complete when the operation is done.
*/
default CompletableFuture
* {@code
*
* mappedTable.putItem(item);
* }
*
*
* @param item the modelled item to be inserted into or overwritten in the database table.
* @return a {@link CompletableFuture} that returns no results which will complete when the operation is done.
*/
default CompletableFuture
* {@code
*
* mappedTable.putItem(PutItemEnhancedRequest.builder(MyItem.class).item(item).build());
* }
*
*
* @param request A {@link PutItemEnhancedRequest} that includes the item to enter into
* the table, its class and optional directives.
*
* @return A {@link CompletableFuture} that contains the response returned by DynamoDB.
*/
default CompletableFuture
* {@code
*
* mappedTable.putItem(PutItemEnhancedRequest.builder(MyItem.class).item(item).build());
* }
*
*
* @param requestConsumer A {@link Consumer} of {@link PutItemEnhancedRequest.Builder} that includes the item
* to enter into the table, its class and optional directives.
*
* @return A {@link CompletableFuture} that contains the response returned by DynamoDB.
*/
default CompletableFuture
* {@code
*
* PagePublisher
*
*
* {@code
*
* PagePublisher
*
* @see #scan(Consumer)
* @see #scan()
* @see DynamoDbAsyncClient#scanPaginator
* @param request A {@link ScanEnhancedRequest} defining how to handle the results.
* @return a publisher {@link PagePublisher} with paginated results (see {@link Page}).
*/
default PagePublisher
* {@code
*
* PagePublisher
*
* @see #scan(ScanEnhancedRequest)
* @see #scan()
* @see DynamoDbAsyncClient#scanPaginator
* @param requestConsumer A {@link Consumer} of {@link ScanEnhancedRequest} defining the query conditions and how to
* handle the results.
* @return a publisher {@link PagePublisher} with paginated results (see {@link Page}).
*/
default PagePublisher
* {@code
*
* PagePublisher
* @see #scan(ScanEnhancedRequest)
* @see #scan(Consumer)
* @see DynamoDbAsyncClient#scanPaginator
* @return a publisher {@link PagePublisher} with paginated results (see {@link Page}).
*/
default PagePublisher
* {@code
*
* MyItem item = mappedTable.updateItem(UpdateItemEnhancedRequest.builder(MyItem.class).item(item).build()).join();
* }
*
*
* @param request A {@link UpdateItemEnhancedRequest} that includes the item to be updated,
* its class and optional directives.
* @return a {@link CompletableFuture} of the updated item
*/
default CompletableFuture
* {@code
*
* MyItem item = mappedTable.updateItem(r -> r.item(item)).join();
* }
*
*
* @param requestConsumer A {@link Consumer} of {@link UpdateItemEnhancedRequest.Builder} that includes the item
* to be updated, its class and optional directives.
* @return a {@link CompletableFuture} of the updated item
*/
default CompletableFuture
* {@code
*
* MyItem item = mappedTable.updateItem(item).join();
* }
*
*
* @param item the modelled item to be inserted into or updated in the database table.
* @return a {@link CompletableFuture} of the updated item
*/
default CompletableFuture
* {@code
* UpdateItemEnhancedRequest
*
* {@code
*
* UpdateItemEnhancedResponse
*
* {@code
*
* mappedTable.deleteTable().join();
* }
*
*
* @return a {@link CompletableFuture} of {@link Void}.
*/
default CompletableFuture
* {@code
*
* DescribeTableEnhancedResponse response = mappedTable.describeTable().join();
* }
*
*/
default CompletableFuture