Search in sources :

Example 6 with ListTablesResponse

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

the class AsyncPagination method useThirdPartySubscriber_Reactor.

private static void useThirdPartySubscriber_Reactor() {
    System.out.println("running AutoPagination - using third party subscriber...\n");
    DynamoDbAsyncClient asyncClient = DynamoDbAsyncClient.create();
    ListTablesPublisher publisher = asyncClient.listTablesPaginator(ListTablesRequest.builder().build());
    // The Flux class has many helper methods that work with any reactive streams compatible publisher implementation
    List<String> tables = Flux.from(publisher).flatMapIterable(ListTablesResponse::tableNames).collectList().block();
    System.out.println(tables);
}
Also used : DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) ListTablesResponse(software.amazon.awssdk.services.dynamodb.model.ListTablesResponse) ListTablesPublisher(software.amazon.awssdk.services.dynamodb.paginators.ListTablesPublisher)

Example 7 with ListTablesResponse

use of software.amazon.awssdk.services.dynamodb.model.ListTablesResponse 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)

Example 8 with ListTablesResponse

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

the class ListTables method listAllTables.

// snippet-start:[dynamodb.java2.list_tables.main]
public static void listAllTables(DynamoDbClient ddb) {
    boolean moreTables = true;
    String lastName = null;
    while (moreTables) {
        try {
            ListTablesResponse response = null;
            if (lastName == null) {
                ListTablesRequest request = ListTablesRequest.builder().build();
                response = ddb.listTables(request);
            } else {
                ListTablesRequest request = ListTablesRequest.builder().exclusiveStartTableName(lastName).build();
                response = ddb.listTables(request);
            }
            List<String> tableNames = response.tableNames();
            if (tableNames.size() > 0) {
                for (String curName : tableNames) {
                    System.out.format("* %s\n", curName);
                }
            } else {
                System.out.println("No tables found!");
                System.exit(0);
            }
            lastName = response.lastEvaluatedTableName();
            if (lastName == null) {
                moreTables = false;
            }
        } catch (DynamoDbException e) {
            System.err.println(e.getMessage());
            System.exit(1);
        }
    }
    System.out.println("\nDone!");
}
Also used : 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 9 with ListTablesResponse

use of software.amazon.awssdk.services.dynamodb.model.ListTablesResponse in project syndesis-qe by syndesisio.

the class DynamoDbUtils method deleteTable.

public void deleteTable() {
    log.info("deleting the AWS dynamoDb: " + tableName);
    ListTablesResponse listTables = dynamoDb.listTables(ListTablesRequest.builder().build());
    if (listTables.tableNames().contains(tableName)) {
        dynamoDb.deleteTable(DeleteTableRequest.builder().tableName(tableName).build());
    } else {
        log.debug("The AWS dynamoDb table {} doesn't exist, continuing.", tableName);
    }
}
Also used : ListTablesResponse(software.amazon.awssdk.services.dynamodb.model.ListTablesResponse)

Aggregations

ListTablesResponse (software.amazon.awssdk.services.dynamodb.model.ListTablesResponse)9 ListTablesRequest (software.amazon.awssdk.services.dynamodb.model.ListTablesRequest)5 DynamoDbAsyncClient (software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient)4 DynamoDbException (software.amazon.awssdk.services.dynamodb.model.DynamoDbException)3 ListTablesPublisher (software.amazon.awssdk.services.dynamodb.paginators.ListTablesPublisher)3 ListTablesIterable (software.amazon.awssdk.services.dynamodb.paginators.ListTablesIterable)2 List (java.util.List)1 Subscription (org.reactivestreams.Subscription)1 Region (software.amazon.awssdk.regions.Region)1 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)1