• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  *  http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 package software.amazon.awssdk.enhanced.dynamodb.model;
17 
18 import software.amazon.awssdk.annotations.SdkPublicApi;
19 import software.amazon.awssdk.annotations.ThreadSafe;
20 import software.amazon.awssdk.core.pagination.sync.PaginatedItemsIterable;
21 import software.amazon.awssdk.core.pagination.sync.SdkIterable;
22 import software.amazon.awssdk.enhanced.dynamodb.DynamoDbEnhancedClient;
23 import software.amazon.awssdk.enhanced.dynamodb.MappedTableResource;
24 
25 /**
26  * Defines the result of {@link DynamoDbEnhancedClient#batchGetItem} operation.
27  *
28  * <p>
29  * The result can be accessed either through iterable {@link BatchGetResultPage}s or flattened items
30  * across <b>all</b>  pages via {@link #resultsForTable}
31  *
32  * <p>
33  * Example:
34  * <p>
35  * 1) Iterating through pages
36  *
37  * <pre>
38  * {@code
39  * batchResults.forEach(page -> {
40  *     page.resultsForTable(firstItemTable).forEach(item -> System.out.println(item));
41  *     page.resultsForTable(secondItemTable).forEach(item -> System.out.println(item));
42  * });
43  * }
44  * </pre>
45  *
46  * 2) Iterating through items across all pages
47  *
48  * <pre>
49  * {@code
50  * results.resultsForTable(firstItemTable).forEach(item -> System.out.println(item));
51  * results.resultsForTable(secondItemTable).forEach(item -> System.out.println(item));
52  * }
53  * </pre>
54  */
55 @SdkPublicApi
56 @ThreadSafe
57 public interface BatchGetResultPageIterable extends SdkIterable<BatchGetResultPage> {
58 
create(SdkIterable<BatchGetResultPage> pageIterable)59     static BatchGetResultPageIterable create(SdkIterable<BatchGetResultPage> pageIterable) {
60         return pageIterable::iterator;
61     }
62 
63     /**
64      * Retrieve all items belonging to the supplied table across <b>all</b> pages.
65      *
66      * @param mappedTable the table to retrieve items for
67      * @param <T> the type of the table items
68      * @return iterable items
69      */
resultsForTable(MappedTableResource<T> mappedTable)70     default <T> SdkIterable<T> resultsForTable(MappedTableResource<T> mappedTable) {
71         return PaginatedItemsIterable.<BatchGetResultPage, T>builder()
72             .pagesIterable(this)
73             .itemIteratorFunction(page -> page.resultsForTable(mappedTable).iterator())
74             .build();
75     }
76 }
77