Class AsyncScanBuilder<T>
- Type Parameters:
T- the type of the item
Mirrors the sync ScanBuilder but returns CompletableFuture
from all execution methods and uses the AWS SDK's async
PagePublisher under the hood.
-
Field Summary
Fields inherited from class AbstractScanBuilder
consistentRead, exclusiveStartKey, filterExpression, limit, projectionExpression, returnConsumedCapacity, segment, select, totalSegments -
Constructor Summary
ConstructorsConstructorDescriptionAsyncScanBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncIndex<T> index) Constructs a newAsyncScanBuilderfor scanning the given async secondary index.AsyncScanBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncIndex<T> index, @Nullable software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient) Constructs a newAsyncScanBuilderfor the given async index with a low-level client.AsyncScanBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable<T> table) Constructs a newAsyncScanBuilderfor the given async table.AsyncScanBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable<T> table, @Nullable software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient) Constructs a newAsyncScanBuilderfor the given async table with a low-level client. -
Method Summary
Modifier and TypeMethodDescription@NonNull CompletableFuture<Long> count()Returns the total number of items asynchronously by iterating all scan result pages.@NonNull CompletableFuture<List<T>> Executes the scan asynchronously and returns all matching items aggregated from all pages.@NonNull CompletableFuture<Optional<T>> Executes the scan asynchronously and returns the first matching item, if any.@NonNull CompletableFuture<software.amazon.awssdk.core.async.SdkPublisher<T>> Returns a reactive publisher that lazily emits items as pages arrive.@NonNull CompletableFuture<PagedResult<T>> Executes the scan asynchronously and returns only the first page of results along with the last evaluated key for pagination.protected @Nullable StringReturns the DynamoDB index name, ornullif the scan targets the base table.protected @NonNull AsyncScanBuilder<T> self()Returnsthistyped asSfor fluent chaining.protected @NonNull StringReturns the DynamoDB table name.Methods inherited from class AbstractScanBuilder
buildCountRequest, buildScanRequest, consistentRead, filter, filter, filter, limit, parallelScan, project, project, returnConsumedCapacity, select, startFrom
-
Constructor Details
-
AsyncScanBuilder
public AsyncScanBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable<T> table) Constructs a newAsyncScanBuilderfor the given async table.- Parameters:
table- the async DynamoDB table
-
AsyncScanBuilder
public AsyncScanBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncIndex<T> index) Constructs a newAsyncScanBuilderfor scanning the given async secondary index.- Parameters:
index- the async DynamoDB secondary index
-
AsyncScanBuilder
public AsyncScanBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncTable<T> table, @Nullable software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient) Constructs a newAsyncScanBuilderfor the given async table with a low-level client.- Parameters:
table- the async DynamoDB tabledynamoDbAsyncClient- the low-level async DynamoDB client (nullable)
-
AsyncScanBuilder
public AsyncScanBuilder(@NonNull software.amazon.awssdk.enhanced.dynamodb.DynamoDbAsyncIndex<T> index, @Nullable software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient dynamoDbAsyncClient) Constructs a newAsyncScanBuilderfor the given async index with a low-level client.- Parameters:
index- the async DynamoDB secondary indexdynamoDbAsyncClient- the low-level async DynamoDB client (nullable)
-
-
Method Details
-
self
Description copied from class:AbstractScanBuilderReturnsthistyped asSfor fluent chaining.- Specified by:
selfin classAbstractScanBuilder<T, AsyncScanBuilder<T>>- Returns:
- this builder
-
tableName
Description copied from class:AbstractScanBuilderReturns the DynamoDB table name.- Specified by:
tableNamein classAbstractScanBuilder<T, AsyncScanBuilder<T>>- Returns:
- the DynamoDB table name
-
indexName
Description copied from class:AbstractScanBuilderReturns the DynamoDB index name, ornullif the scan targets the base table.- Specified by:
indexNamein classAbstractScanBuilder<T, AsyncScanBuilder<T>>- Returns:
- the index name, or
nullfor the base table
-
executeAll
Executes the scan asynchronously and returns all matching items aggregated from all pages.Memory warning: This method collects all pages into a single in-memory list before returning. For scans that may return a large number of items, consider using
executeWithPagination()or processing pages individually to avoid excessive memory usage.- Returns:
- a
CompletableFuturecontaining a list of matching items
-
executeWithPagination
Executes the scan asynchronously and returns only the first page of results along with the last evaluated key for pagination.- Returns:
- a
CompletableFuturecontaining aPagedResultwith the first page of items and the last evaluated key (may benullif no more pages)
-
executeAndGetFirst
Executes the scan asynchronously and returns the first matching item, if any.Only the first page of results is loaded: subsequent pages are never fetched.
- Returns:
- a
CompletableFuturecontaining anOptionalwith the first item, or empty if no items match
-
executeStream
public @NonNull CompletableFuture<software.amazon.awssdk.core.async.SdkPublisher<T>> executeStream()Returns a reactive publisher that lazily emits items as pages arrive.Unlike
executeAll()which loads all pages into memory, this method streams items one-by-one as each page is received from DynamoDB.- Returns:
- a
CompletableFuturecontaining anSdkPublisherthat emits scan items - Throws:
IllegalStateException- if called with Select.COUNT
-
count
Returns the total number of items asynchronously by iterating all scan result pages.When a low-level
DynamoDbAsyncClientis available, usesSelect.COUNTserver-side to avoid transferring item data. Falls back to the enhanced client page iteration otherwise.- Returns:
- a
CompletableFuturecontaining the total count of scanned items matching the filter
-