Example usage for com.amazonaws.services.dynamodbv2.model CreateTableRequest getKeySchema

List of usage examples for com.amazonaws.services.dynamodbv2.model CreateTableRequest getKeySchema

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model CreateTableRequest getKeySchema.

Prototype


public java.util.List<KeySchemaElement> getKeySchema() 

Source Link

Document

Specifies the attributes that make up the primary key for a table or an index.

Usage

From source file:awslabs.lab22.SolutionCode.java

License:Open Source License

@Override
public void buildTable(AmazonDynamoDBClient ddbClient, String tableName) {
    System.out.println("Creating table.");
    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName);
    createTableRequest.setAttributeDefinitions(new ArrayList<AttributeDefinition>());
    // Define attributes
    createTableRequest.getAttributeDefinitions()
            .add(new AttributeDefinition().withAttributeName("Company").withAttributeType("S"));
    createTableRequest.getAttributeDefinitions()
            .add(new AttributeDefinition().withAttributeName("Email").withAttributeType("S"));
    // Define key schema
    createTableRequest.setKeySchema(new ArrayList<KeySchemaElement>());
    createTableRequest.getKeySchema()
            .add(new KeySchemaElement().withAttributeName("Company").withKeyType("HASH"));
    createTableRequest.getKeySchema()//  w  w w . j a  va  2 s  .c  o  m
            .add(new KeySchemaElement().withAttributeName("Email").withKeyType("RANGE"));
    // Define provisioned throughput
    createTableRequest.setProvisionedThroughput(
            new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L));

    // Submit create request
    ddbClient.createTable(createTableRequest);
    // Pause until the table is active
    waitForStatus(ddbClient, tableName, "ACTIVE");
    System.out.println("Table created and active.");
}

From source file:awslabs.lab51.SolutionCode.java

License:Open Source License

@Override
public void buildTable(AmazonDynamoDBClient ddbClient, String tableName) {
    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(tableName);
    createTableRequest.setAttributeDefinitions(new ArrayList<AttributeDefinition>());
    // Define attributes
    createTableRequest.getAttributeDefinitions()
            .add(new AttributeDefinition().withAttributeName("Key").withAttributeType("S"));
    createTableRequest.getAttributeDefinitions()
            .add(new AttributeDefinition().withAttributeName("Bucket").withAttributeType("S"));
    // Define key schema
    createTableRequest.setKeySchema(new ArrayList<KeySchemaElement>());
    createTableRequest.getKeySchema().add(new KeySchemaElement().withAttributeName("Key").withKeyType("HASH"));
    createTableRequest.getKeySchema()//from   ww w .j a v a2  s .com
            .add(new KeySchemaElement().withAttributeName("Bucket").withKeyType("RANGE"));
    // Define provisioned throughput
    createTableRequest.setProvisionedThroughput(
            new ProvisionedThroughput().withReadCapacityUnits(5L).withWriteCapacityUnits(5L));

    // Submit create request
    ddbClient.createTable(createTableRequest);
    // Pause until the table is active
    waitForStatus(ddbClient, tableName, "ACTIVE");
    labController.logMessageToPage("Table created and active.");
}

From source file:com.makariev.dynamodb.data.tables.creators.ReplyCreator.java

License:Apache License

@Override
public CreateTableRequest getCreateTableRequest() {
    final String tableName = Reply.TABLE_NAME;
    final String hashKeyName = "Id";
    final ScalarAttributeType hashKeyType = ScalarAttributeType.S;
    final Long readCapacityUnits = 10L;
    final Long writeCapacityUnits = 10L;

    final String rangeKeyName = "ReplyDateTime";
    final ScalarAttributeType rangeKeyType = ScalarAttributeType.S;

    ////////////////
    final CreateTableRequest request = basicTable(tableName, readCapacityUnits, writeCapacityUnits, hashKeyName,
            hashKeyType);//from w w  w.j  a  va 2  s.  c  o  m
    ///////////////////////
    //defining range key 
    request.getKeySchema()
            .add(new KeySchemaElement().withAttributeName(rangeKeyName).withKeyType(KeyType.RANGE));
    //defining range key 
    request.getAttributeDefinitions()
            .add(new AttributeDefinition().withAttributeName(rangeKeyName).withAttributeType(rangeKeyType));
    //////////////////////

    //follows defininig of a local secondary index
    request.getAttributeDefinitions().add(
            new AttributeDefinition().withAttributeName("PostedBy").withAttributeType(ScalarAttributeType.S));

    final List<KeySchemaElement> iks = new ArrayList<>();
    iks.add(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH));
    iks.add(new KeySchemaElement().withAttributeName("PostedBy").withKeyType(KeyType.RANGE));

    final LocalSecondaryIndex localSecondaryIndex = new LocalSecondaryIndex().withIndexName("PostedByIndex")
            .withKeySchema(iks).withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY));

    final List<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<>();
    localSecondaryIndexes.add(localSecondaryIndex);

    request.setLocalSecondaryIndexes(localSecondaryIndexes);

    return request;
}

From source file:com.makariev.dynamodb.data.tables.creators.ThreadCreator.java

License:Apache License

@Override
public CreateTableRequest getCreateTableRequest() {
    final String tableName = Thread.TABLE_NAME;
    final String hashKeyName = "ForumName";
    final ScalarAttributeType hashKeyType = ScalarAttributeType.S;
    final Long readCapacityUnits = 10L;
    final Long writeCapacityUnits = 10L;

    final String rangeKeyName = "Subject";
    final ScalarAttributeType rangeKeyType = ScalarAttributeType.S;

    ////////////////
    final CreateTableRequest request = basicTable(tableName, readCapacityUnits, writeCapacityUnits, hashKeyName,
            hashKeyType);//from  www.jav  a 2 s  .  co  m

    //defining range key 
    request.getKeySchema()
            .add(new KeySchemaElement().withAttributeName(rangeKeyName).withKeyType(KeyType.RANGE));
    //defining range key 
    request.getAttributeDefinitions()
            .add(new AttributeDefinition().withAttributeName(rangeKeyName).withAttributeType(rangeKeyType));

    return request;
}

From source file:org.socialsignin.spring.data.dynamodb.repository.util.Entity2DynamoDBTableSynchronizer.java

License:Apache License

/**
 * @param entityInformation/*from w ww .j a v  a 2  s  .  c  o m*/
 *            The entity to check for it's table
 * @throws IllegalStateException
 *             is thrown if the existing table doesn't match the entity's
 *             annotation
 */
private DescribeTableResult performValidate(DynamoDBEntityInformation<T, ID> entityInformation)
        throws IllegalStateException {
    Class<T> domainType = entityInformation.getJavaType();

    CreateTableRequest expected = mapper.generateCreateTableRequest(domainType);
    DescribeTableResult result = amazonDynamoDB.describeTable(expected.getTableName());
    TableDescription actual = result.getTable();

    if (!expected.getKeySchema().equals(actual.getKeySchema())) {
        throw new IllegalStateException("KeySchema is not as expected. Expected: <" + expected.getKeySchema()
                + "> but found <" + actual.getKeySchema() + ">");
    }
    LOGGER.debug("KeySchema is valid");

    if (expected.getGlobalSecondaryIndexes() != null) {
        if (!Arrays.deepEquals(expected.getGlobalSecondaryIndexes().toArray(),
                actual.getGlobalSecondaryIndexes().toArray())) {
            throw new IllegalStateException("Global Secondary Indexes are not as expected. Expected: <"
                    + expected.getGlobalSecondaryIndexes() + "> but found <"
                    + actual.getGlobalSecondaryIndexes() + ">");
        }
    }
    LOGGER.debug("Global Secondary Indexes are valid");

    LOGGER.info("Validated table {} for entity{}", expected.getTableName(), domainType);
    return result;
}