Search in sources :

Example 6 with ListTablesRequest

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

Aggregations

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