Example usage for com.amazonaws.services.dynamodbv2.model GlobalSecondaryIndex GlobalSecondaryIndex

List of usage examples for com.amazonaws.services.dynamodbv2.model GlobalSecondaryIndex GlobalSecondaryIndex

Introduction

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

Prototype

GlobalSecondaryIndex

Source Link

Usage

From source file:org.selman.tweetamo.PersistentStore.java

License:Apache License

private void createTables(long readCapacity, long writeCapacity) throws Exception {
    // ID | createdAt | lat | long | screen name | text |
    // Primary index is by ID
    // Global Secondary index is by screen name + createdAt

    try {//from w  w w .ja  v a2 s  .  co m
        CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(TABLE_NAME)
                .withKeySchema(new KeySchemaElement().withAttributeName(COL_ID).withKeyType(KeyType.HASH))
                .withAttributeDefinitions(
                        new AttributeDefinition().withAttributeName(COL_ID)
                                .withAttributeType(ScalarAttributeType.N),
                        new AttributeDefinition().withAttributeName(COL_CREATEDAT)
                                .withAttributeType(ScalarAttributeType.N),
                        new AttributeDefinition().withAttributeName(COL_SCREENNAME)
                                .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacity)
                        .withWriteCapacityUnits(writeCapacity))
                .withGlobalSecondaryIndexes(new GlobalSecondaryIndex().withIndexName(INDEX_SCREENNAME)
                        .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits((long) 10)
                                .withWriteCapacityUnits((long) 1))
                        .withProjection(new Projection().withProjectionType("ALL")).withKeySchema(
                                new KeySchemaElement().withAttributeName(COL_SCREENNAME)
                                        .withKeyType(KeyType.HASH),
                                new KeySchemaElement().withAttributeName(COL_CREATEDAT)
                                        .withKeyType(KeyType.RANGE)));

        TableDescription createdTableDescription = dynamoDB.createTable(createTableRequest)
                .getTableDescription();
        LOG.info("Created Table: " + createdTableDescription);
    } catch (Exception e) {
        handleException(e);
    }
}

From source file:org.xmlsh.aws.util.AWSDDBCommand.java

License:BSD License

protected GlobalSecondaryIndex parseGlobalSecondaryIndex(XValue xv)
        throws InvalidArgumentException, UnexpectedException {
    if (!xv.isXdmNode())
        throw new InvalidArgumentException(
                "Unexpected argument type for global secondary index: " + xv.describe());

    GlobalSecondaryIndex gi = new GlobalSecondaryIndex();

    gi.setIndexName(xv.xpath(getShell(), "./@name").toString());
    gi.setKeySchema(parseKeySchemaList(xv.xpath(getShell(), "./key-schema")));
    gi.setProjection(parseProjection(xv.xpath(getShell(), "./projection")));
    gi.setProvisionedThroughput(parseProvisionedThroughput(xv.xpath(getShell(), "./provisioned-throughput")));

    return gi;//from  www . j  a  v a2  s  . co m
}