Search in sources :

Example 1 with ListTablesIterable

use of software.amazon.awssdk.services.dynamodb.paginators.ListTablesIterable in project aws-doc-sdk-examples by awsdocs.

the class SyncPagination method autoPaginationWithResume.

public static void autoPaginationWithResume(DynamoDbClient client) {
    System.out.println("running AutoPagination with resume in case of errors...\n");
    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 (DynamoDbException exception) {
        if (lastSuccessfulPage != null) {
            System.out.println(exception.getMessage());
        }
    }
}
Also used : ListTablesIterable(software.amazon.awssdk.services.dynamodb.paginators.ListTablesIterable) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) ListTablesRequest(software.amazon.awssdk.services.dynamodb.model.ListTablesRequest) ListTablesResponse(software.amazon.awssdk.services.dynamodb.model.ListTablesResponse)

Example 2 with ListTablesIterable

use of software.amazon.awssdk.services.dynamodb.paginators.ListTablesIterable in project aws-doc-sdk-examples by awsdocs.

the class SyncPagination method autoPagination.

public static void autoPagination(DynamoDbClient client) {
    System.out.println("running AutoPagination...\n");
    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);
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) ListTablesRequest(software.amazon.awssdk.services.dynamodb.model.ListTablesRequest) DynamoDbException(software.amazon.awssdk.services.dynamodb.model.DynamoDbException) Region(software.amazon.awssdk.regions.Region) ListTablesResponse(software.amazon.awssdk.services.dynamodb.model.ListTablesResponse) ListTablesIterable(software.amazon.awssdk.services.dynamodb.paginators.ListTablesIterable) ListTablesIterable(software.amazon.awssdk.services.dynamodb.paginators.ListTablesIterable) ListTablesRequest(software.amazon.awssdk.services.dynamodb.model.ListTablesRequest) ListTablesResponse(software.amazon.awssdk.services.dynamodb.model.ListTablesResponse)

Aggregations

DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)2 ListTablesRequest (software.amazon.awssdk.services.dynamodb.model.ListTablesRequest)2 ListTablesResponse (software.amazon.awssdk.services.dynamodb.model.ListTablesResponse)2 ListTablesIterable (software.amazon.awssdk.services.dynamodb.paginators.ListTablesIterable)2 Region (software.amazon.awssdk.regions.Region)1 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)1