private static void AutoPagination() { System.out.println("running AutoPagination...\n"); final DynamoDbClient client = DynamoDbClient.create(); ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build(); ListTablesIterable responses = client.listTablesPaginator(listTablesRequest); System.out.println("AutoPagination: using for loop"); for (final ListTablesResponse response : responses) { System.out.println(response.tableNames()); } // Print the table names using the responses stream System.out.println("AutoPagination: using stream"); responses.stream().forEach(response -> System.out.println(response.tableNames())); // Convert the stream of responses to stream of table names, then print the table names System.out.println("AutoPagination: using flatmap to get stream of table names"); responses.stream() .flatMap(response -> response.tableNames().stream()) .forEach(System.out::println); System.out.println("AutoPagination: iterating directly on the table names"); Iterable<String> tableNames = responses.tableNames(); tableNames.forEach(System.out::println); }
private static void AutoPaginationWithResume() { System.out.println("running AutoPagination with resume in case of errors...\n"); final DynamoDbClient client = DynamoDbClient.create(); ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build(); ListTablesIterable responses = client.listTablesPaginator(listTablesRequest); ListTablesResponse lastSuccessfulPage = null; try { for (ListTablesResponse response : responses) { response.tableNames().forEach(System.out::println); lastSuccessfulPage = response; } } catch (Exception exception) { if (lastSuccessfulPage != null) { System.out.println(exception.getMessage()); } } } }
return listTablesPaginator(ListTablesRequest.builder().applyMutation(listTablesRequest).build());
return listTablesPaginator(ListTablesRequest.builder().build());
return listTablesPaginator(ListTablesRequest.builder().build());
return listTablesPaginator(ListTablesRequest.builder().applyMutation(listTablesRequest).build());
return listTables(ListTablesRequest.builder().applyMutation(listTablesRequest).build());
return listTables(ListTablesRequest.builder().applyMutation(listTablesRequest).build());
/** * <p> * Returns an array of table names associated with the current account and endpoint. The output from * <code>ListTables</code> is paginated, with each page returning a maximum of 100 table names. * </p> * * @return A Java Future containing the result of the ListTables operation returned by the service.<br/> * The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. * <ul> * <li>InternalServerErrorException An error occurred on the server side.</li> * <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.</li> * <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.</li> * <li>DynamoDbException Base class for all service exceptions. Unknown exceptions will be thrown as an * instance of this type.</li> * </ul> * @sample DynamoDbAsyncClient.ListTables * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/dynamodb-2012-08-10/ListTables" target="_top">AWS API * Documentation</a> */ default CompletableFuture<ListTablesResponse> listTables() { return listTables(ListTablesRequest.builder().build()); }
/** * <p> * Returns an array of table names associated with the current account and endpoint. The output from * <code>ListTables</code> is paginated, with each page returning a maximum of 100 table names. * </p> * * @return Result of the ListTables operation returned by the service. * @throws InternalServerErrorException * An error occurred on the server side. * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws DynamoDbException * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample DynamoDbClient.ListTables * @see #listTables(ListTablesRequest) * @see <a href="http://docs.aws.amazon.com/goto/WebAPI/dynamodb-2012-08-10/ListTables" target="_top">AWS API * Documentation</a> */ default ListTablesResponse listTables() throws InternalServerErrorException, AwsServiceException, SdkClientException, DynamoDbException { return listTables(ListTablesRequest.builder().build()); }
/** * <p> * A helper method to resume the pages in case of unexpected failures. The method takes the last successful response * page as input and returns an instance of {@link ListTablesPublisher} that can be used to retrieve the consecutive * pages that follows the input page. * </p> */ private final ListTablesPublisher resume(ListTablesResponse lastSuccessfulPage) { if (nextPageFetcher.hasNextPage(lastSuccessfulPage)) { return new ListTablesPublisher(client, firstRequest.toBuilder() .exclusiveStartTableName(lastSuccessfulPage.lastEvaluatedTableName()).build()); } return new ListTablesPublisher(client, firstRequest, true) { @Override public void subscribe(Subscriber<? super ListTablesResponse> subscriber) { subscriber.onSubscribe(new EmptySubscription(subscriber)); } }; }
/** * <p> * A helper method to resume the pages in case of unexpected failures. The method takes the last successful response * page as input and returns an instance of {@link ListTablesIterable} that can be used to retrieve the consecutive * pages that follows the input page. * </p> */ private final ListTablesIterable resume(ListTablesResponse lastSuccessfulPage) { if (nextPageFetcher.hasNextPage(lastSuccessfulPage)) { return new ListTablesIterable(client, firstRequest.toBuilder() .exclusiveStartTableName(lastSuccessfulPage.lastEvaluatedTableName()).build()); } return new ListTablesIterable(client, firstRequest) { @Override public Iterator<ListTablesResponse> iterator() { return Collections.emptyIterator(); } }; }
@Override public CompletableFuture<ListTablesResponse> nextPage(final ListTablesResponse previousPage) { if (previousPage == null) { return client.listTables(firstRequest); } return client.listTables(firstRequest.toBuilder().exclusiveStartTableName(previousPage.lastEvaluatedTableName()) .build()); } }
@Override public ListTablesResponse nextPage(ListTablesResponse previousPage) { if (previousPage == null) { return client.listTables(firstRequest); } return client.listTables(firstRequest.toBuilder().exclusiveStartTableName(previousPage.lastEvaluatedTableName()) .build()); } }
private static void ManualPagination() { System.out.println("running ManualPagination...\n"); final DynamoDbClient client = DynamoDbClient.create(); ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build(); boolean done = false; while (!done) { ListTablesResponse listTablesResponse = client.listTables(listTablesRequest); System.out.println(listTablesResponse.tableNames()); if (listTablesResponse.lastEvaluatedTableName() == null) { done = true; } listTablesRequest = listTablesRequest.toBuilder() .exclusiveStartTableName(listTablesResponse.lastEvaluatedTableName()) .build(); } }