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

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

Introduction

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

Prototype

LocalSecondaryIndex

Source Link

Usage

From source file:amazon.dynamodb.util.GeoTableUtil.java

License:Open Source License

/**
 * <p>//from  w w w .  j a  va  2s .co m
 * Construct a create table request object based on GeoDataManagerConfiguration. The users can update any aspect of
 * the request and call it.
 * </p>
 * Example:
 * 
 * <pre>
 * AmazonDynamoDBClient ddb = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
 * Region usWest2 = Region.getRegion(Regions.US_WEST_2);
 * ddb.setRegion(usWest2);
 * 
 * CreateTableRequest createTableRequest = GeoTableUtil.getCreateTableRequest(config);
 * CreateTableResult createTableResult = ddb.createTable(createTableRequest);
 * </pre>
 * 
 * @return Generated create table request.
 */
public static CreateTableRequest getCreateTableRequest(GeoDataManagerConfiguration config) {
    CreateTableRequest createTableRequest = new CreateTableRequest().withTableName(config.getTableName())
            .withProvisionedThroughput(
                    new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L))
            .withKeySchema(
                    new KeySchemaElement().withKeyType(KeyType.HASH)
                            .withAttributeName(config.getHashKeyAttributeName()),
                    new KeySchemaElement().withKeyType(KeyType.RANGE)
                            .withAttributeName(config.getRangeKeyAttributeName()))
            .withAttributeDefinitions(
                    new AttributeDefinition().withAttributeType(ScalarAttributeType.N)
                            .withAttributeName(config.getHashKeyAttributeName()),
                    new AttributeDefinition().withAttributeType(ScalarAttributeType.S)
                            .withAttributeName(config.getRangeKeyAttributeName()),
                    new AttributeDefinition().withAttributeType(ScalarAttributeType.N)
                            .withAttributeName(config.getGeohashAttributeName()))
            .withLocalSecondaryIndexes(new LocalSecondaryIndex().withIndexName(config.getGeohashIndexName())
                    .withKeySchema(
                            new KeySchemaElement().withKeyType(KeyType.HASH)
                                    .withAttributeName(config.getHashKeyAttributeName()),
                            new KeySchemaElement().withKeyType(KeyType.RANGE)
                                    .withAttributeName(config.getGeohashAttributeName()))
                    .withProjection(new Projection().withProjectionType(ProjectionType.ALL)));

    return createTableRequest;
}

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.ja v  a 2 s . com
    ///////////////////////
    //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:DynamoDB.sample.CreateTablesLoadData.java

License:Open Source License

private static void createTable(String tableName, long readCapacityUnits, long writeCapacityUnits,
        String partitionKeyName, String partitionKeyType, String sortKeyName, String sortKeyType) {

    try {// www  .  ja  v  a2 s  .c om

        ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
        keySchema.add(new KeySchemaElement().withAttributeName(partitionKeyName).withKeyType(KeyType.HASH)); //Partition key

        ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
        attributeDefinitions.add(new AttributeDefinition().withAttributeName(partitionKeyName)
                .withAttributeType(partitionKeyType));

        if (sortKeyName != null) {
            keySchema.add(new KeySchemaElement().withAttributeName(sortKeyName).withKeyType(KeyType.RANGE)); //Sort key
            attributeDefinitions.add(
                    new AttributeDefinition().withAttributeName(sortKeyName).withAttributeType(sortKeyType));
        }

        CreateTableRequest request = new CreateTableRequest().withTableName(tableName).withKeySchema(keySchema)
                .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits)
                        .withWriteCapacityUnits(writeCapacityUnits));

        // If this is the Reply table, define a local secondary index
        if (replyTableName.equals(tableName)) {

            attributeDefinitions
                    .add(new AttributeDefinition().withAttributeName("PostedBy").withAttributeType("S"));

            ArrayList<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<LocalSecondaryIndex>();
            localSecondaryIndexes.add(new LocalSecondaryIndex().withIndexName("PostedBy-Index")
                    .withKeySchema(
                            new KeySchemaElement().withAttributeName(partitionKeyName)
                                    .withKeyType(KeyType.HASH), //Partition key
                            new KeySchemaElement().withAttributeName("PostedBy").withKeyType(KeyType.RANGE)) //Sort key
                    .withProjection(new Projection().withProjectionType(ProjectionType.KEYS_ONLY)));

            request.setLocalSecondaryIndexes(localSecondaryIndexes);
        }

        request.setAttributeDefinitions(attributeDefinitions);

        System.out.println("Issuing CreateTable request for " + tableName);
        Table table = dynamoDB.createTable(request);
        System.out.println("Waiting for " + tableName + " to be created...this may take a while...");
        table.waitForActive();

    } catch (Exception e) {
        System.err.println("CreateTable request failed for " + tableName);
        System.err.println(e.getMessage());
    }
}

From source file:io.venable.amazonaws.dynamo.table.builder.LocalSecondaryIndexBuilderImpl.java

License:Apache License

void buildSecondaryIndexes(KeySchemaElement primaryHashKeySchemaElement,
        Collection<LocalSecondaryIndex> localSecondaryIndexCollection,
        Collection<AttributeDefinition> attributeDefinitionCollection) {
    LocalSecondaryIndex localSecondaryIndex = new LocalSecondaryIndex();

    localSecondaryIndex.setIndexName(indexName);
    Collection<KeySchemaElement> keySchemaElementCollection = new ArrayList<>();
    keySchemaElementCollection.add(primaryHashKeySchemaElement);
    buildRangeKey(keySchemaElementCollection, attributeDefinitionCollection);
    localSecondaryIndex.setKeySchema(keySchemaElementCollection);

    projection.build(localSecondaryIndex);

    localSecondaryIndexCollection.add(localSecondaryIndex);
}

From source file:org.diksha.common.dyutils.SchedulerDynamoTable.java

License:Apache License

public void createDynamoTable(DynamoDB dynamoDB) {

    try {/*  w w  w.  j  av a  2 s  .c o m*/
        System.out.println(toString());

        ArrayList<KeySchemaElement> keySchema = new ArrayList<KeySchemaElement>();
        keySchema.add(new KeySchemaElement().withAttributeName(hashKeyName).withKeyType(KeyType.HASH));

        ArrayList<AttributeDefinition> attributeDefinitions = new ArrayList<AttributeDefinition>();
        attributeDefinitions
                .add(new AttributeDefinition().withAttributeName(hashKeyName).withAttributeType(hashKeyType));
        if (rangeKeyType != null) {
            if (!rangeKeyType.isEmpty()) {
                attributeDefinitions.add(new AttributeDefinition().withAttributeName(rangeKeyName)
                        .withAttributeType(rangeKeyType));
            }
        }

        if (additionalAttributes.size() > 0) {
            for (int cnt = 0; cnt < additionalAttributes.size(); cnt++) {
                String[] args = (additionalAttributes.get(cnt).toString()).split(":");
                if (args.length == 2) {
                    attributeDefinitions.add(
                            new AttributeDefinition().withAttributeName(args[0]).withAttributeType(args[1]));

                }

            }
        }

        CreateTableRequest request = new CreateTableRequest().withTableName(tableName).withKeySchema(keySchema)
                .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(readCapacityUnits)
                        .withWriteCapacityUnits(writeCapacityUnits));

        ArrayList<LocalSecondaryIndex> localSecondaryIndexes = new ArrayList<LocalSecondaryIndex>();
        ArrayList<GlobalSecondaryIndex> globalSecondaryIndexes = new ArrayList<GlobalSecondaryIndex>();

        if (rangeKeyType != null) {
            if (!rangeKeyType.isEmpty()) {
                if (rangeKeyTypeGlobalOrLocal.equals("L")) {
                    localSecondaryIndexes
                            .add(new LocalSecondaryIndex().withIndexName(rangeKeyName + "-Index")
                                    .withKeySchema(
                                            new KeySchemaElement().withAttributeName(hashKeyName)
                                                    .withKeyType(KeyType.HASH),
                                            new KeySchemaElement().withAttributeName(rangeKeyName)
                                                    .withKeyType(KeyType.RANGE))
                                    .withProjection(
                                            new Projection().withProjectionType(ProjectionType.KEYS_ONLY)));
                } else {
                    globalSecondaryIndexes
                            .add(new GlobalSecondaryIndex().withIndexName(rangeKeyName + "-Index")
                                    .withKeySchema(
                                            new KeySchemaElement().withAttributeName(hashKeyName)
                                                    .withKeyType(KeyType.HASH),
                                            new KeySchemaElement().withAttributeName(rangeKeyName)
                                                    .withKeyType(KeyType.RANGE))
                                    .withProvisionedThroughput(new ProvisionedThroughput()
                                            .withReadCapacityUnits(indexReadCapacityUnits)
                                            .withWriteCapacityUnits(indexWriteCapacityUnits))
                                    .withProjection(
                                            new Projection().withProjectionType(ProjectionType.KEYS_ONLY)));
                }
            }
        }

        if (indices.size() > 0) {

            for (int cnt = 0; cnt < indices.size(); cnt++) {
                SchedulerDynamoTableIndex schedulerDynamoTableIndex = indices.get(cnt);

                if (schedulerDynamoTableIndex.isGlobal()) {
                    //         System.out.println("IS GLOBAL");
                    globalSecondaryIndexes.add(schedulerDynamoTableIndex.getGlobalSecondaryIndex());
                    //         System.out.println("size = " + globalSecondaryIndexes.size());
                }

            }

        }

        if (localSecondaryIndexes.size() > 0)
            request.setLocalSecondaryIndexes(localSecondaryIndexes);
        if (globalSecondaryIndexes.size() > 0)
            request.setGlobalSecondaryIndexes(globalSecondaryIndexes);

        request.setAttributeDefinitions(attributeDefinitions);
        System.out.println("Issuing CreateTable request for " + tableName);
        Table table = dynamoDB.createTable(request);
        System.out.println("Waiting for " + tableName + " to be created...this may take a while...");
        table.waitForActive();

    } catch (Exception e) {
        System.err.println("CreateTable request failed for " + tableName);
        System.err.println(e.getMessage());
    }

}

From source file:org.iternine.jeppetto.dao.dynamodb.extra.TableBuilder.java

License:Apache License

public TableBuilder withLsi(String indexKey, ScalarAttributeType indexKeyType) {
    if (localSecondaryIndexes == null) {
        localSecondaryIndexes = new ArrayList<LocalSecondaryIndex>();
    }//from w  w w .java 2s  .  c  om

    attributeDefinitions.add(new AttributeDefinition(indexKey, indexKeyType));

    localSecondaryIndexes.add(new LocalSecondaryIndex().withIndexName(indexKey + "-index")
            .withKeySchema(new KeySchemaElement(keySchema.get(0).getAttributeName(), KeyType.HASH),
                    new KeySchemaElement(indexKey, KeyType.RANGE))
            .withProjection(new Projection().withProjectionType(ProjectionType.ALL)));

    return this;
}

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

License:BSD License

protected LocalSecondaryIndex parseLocalSecondaryIndex(XValue xv)
        throws InvalidArgumentException, UnexpectedException {

    if (!xv.isXdmNode())
        throw new InvalidArgumentException(
                "Unexpected argument type for global secondary index: " + xv.describe());
    XdmNode node = xv.asXdmNode();/*  w ww  . j  ava 2  s.  c o  m*/
    if (!node.getNodeName().getLocalName().equals("local-secondary-index"))
        throw new InvalidArgumentException(
                "Unexpected element: " + node.getNodeName().toString() + " expected: local-secondary-index");

    LocalSecondaryIndex li = new LocalSecondaryIndex()
            .withIndexName(node.getAttributeValue(new QName("index-name")));

    li.setKeySchema(parseKeySchemaList(xpath(xv, "./key-schema")));
    return li;

}