Search in sources :

Example 16 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project aws-doc-sdk-examples by awsdocs.

the class ListTables method main.

public static void main(String[] args) {
    System.out.println("Your DynamoDB tables:\n");
    final AmazonDynamoDB ddb = AmazonDynamoDBClientBuilder.defaultClient();
    boolean more_tables = true;
    while (more_tables) {
        String last_name = null;
        try {
            ListTablesResult table_list = null;
            if (last_name == null) {
                table_list = ddb.listTables();
            }
            List<String> table_names = table_list.getTableNames();
            if (table_names.size() > 0) {
                for (String cur_name : table_names) {
                    System.out.format("* %s\n", cur_name);
                }
            } else {
                System.out.println("No tables found!");
                System.exit(0);
            }
            last_name = table_list.getLastEvaluatedTableName();
            if (last_name == null) {
                more_tables = false;
            }
        } catch (AmazonServiceException e) {
            System.err.println(e.getErrorMessage());
            System.exit(1);
        }
    }
    System.out.println("\nDone!");
}
Also used : ListTablesResult(com.amazonaws.services.dynamodbv2.model.ListTablesResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 17 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project tutorials by eugenp.

the class SavePersonHandler method initDynamoDbClient.

private void initDynamoDbClient() {
    AmazonDynamoDBClient client = new AmazonDynamoDBClient();
    client.setRegion(Region.getRegion(REGION));
    this.dynamoDb = new DynamoDB(client);
}
Also used : DynamoDB(com.amazonaws.services.dynamodbv2.document.DynamoDB) AmazonDynamoDBClient(com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)

Example 18 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project jcabi-dynamo by jcabi.

the class MadeTable method exists.

/**
 * The table exists?
 * @return TRUE if it exists in DynamoDB
 * @since 0.9
 */
public boolean exists() {
    final AmazonDynamoDB aws = this.region.aws();
    final String name = this.request.getTableName();
    boolean exists;
    try {
        aws.describeTable(name);
        exists = true;
        Logger.info(this, "DynamoDB table '%s' already exists", name);
    } catch (final ResourceNotFoundException ex) {
        exists = false;
        Logger.info(this, "DynamoDB table '%s' doesn't exist: %s", name, ex.getLocalizedMessage());
    }
    return exists;
}
Also used : AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) ResourceNotFoundException(com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException)

Example 19 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project jcabi-dynamo by jcabi.

the class MadeTable method drop.

/**
 * Drop table.
 * @throws InterruptedException If something fails
 */
public void drop() throws InterruptedException {
    final AmazonDynamoDB aws = this.region.aws();
    final String name = this.request.getTableName();
    aws.deleteTable(new DeleteTableRequest().withTableName(name));
    Logger.info(this, "DynamoDB table '%s' deletion requested", name);
    while (this.exists()) {
        Logger.info(this, "DynamoDB table '%s' still exists", name);
        TimeUnit.SECONDS.sleep((long) Tv.TEN);
    }
    Logger.info(this, "DynamoDB table '%s' deleted", name);
}
Also used : DeleteTableRequest(com.amazonaws.services.dynamodbv2.model.DeleteTableRequest) AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB)

Example 20 with DynamoDB

use of com.amazonaws.services.dynamodbv2.document.DynamoDB in project jcabi-dynamo by jcabi.

the class MadeTable method create.

/**
 * Create table.
 * @throws InterruptedException If something fails
 */
public void create() throws InterruptedException {
    final AmazonDynamoDB aws = this.region.aws();
    final String name = this.request.getTableName();
    aws.createTable(this.request);
    Logger.info(this, "DynamoDB table '%s' creation requested...", name);
    final DescribeTableRequest req = new DescribeTableRequest().withTableName(name);
    while (true) {
        final DescribeTableResult result = aws.describeTable(req);
        if ("ACTIVE".equals(result.getTable().getTableStatus())) {
            Logger.info(this, "DynamoDB table '%s' is %s", name, result.getTable().getTableStatus());
            break;
        }
        Logger.info(this, "waiting for DynamoDB table '%s': %s", name, result.getTable().getTableStatus());
        TimeUnit.SECONDS.sleep((long) Tv.TEN);
    }
}
Also used : AmazonDynamoDB(com.amazonaws.services.dynamodbv2.AmazonDynamoDB) DescribeTableRequest(com.amazonaws.services.dynamodbv2.model.DescribeTableRequest) DescribeTableResult(com.amazonaws.services.dynamodbv2.model.DescribeTableResult)

Aggregations

DynamoDB (com.amazonaws.services.dynamodbv2.document.DynamoDB)24 Test (org.junit.Test)16 TestRunner (org.apache.nifi.util.TestRunner)15 MockFlowFile (org.apache.nifi.util.MockFlowFile)14 AmazonClientException (com.amazonaws.AmazonClientException)12 AmazonServiceException (com.amazonaws.AmazonServiceException)10 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)10 TableWriteItems (com.amazonaws.services.dynamodbv2.document.TableWriteItems)10 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)9 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)9 List (java.util.List)9 TableKeysAndAttributes (com.amazonaws.services.dynamodbv2.document.TableKeysAndAttributes)8 Map (java.util.Map)8 IOException (java.io.IOException)6 AmazonDynamoDBClient (com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient)5 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)5 BatchGetItemOutcome (com.amazonaws.services.dynamodbv2.document.BatchGetItemOutcome)5 CreateTableRequest (com.amazonaws.services.dynamodbv2.model.CreateTableRequest)5 DescribeTableRequest (com.amazonaws.services.dynamodbv2.model.DescribeTableRequest)5