Example usage for com.amazonaws.services.dynamodbv2.document.spec UpdateTableSpec withGlobalSecondaryIndexUpdates

List of usage examples for com.amazonaws.services.dynamodbv2.document.spec UpdateTableSpec withGlobalSecondaryIndexUpdates

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.document.spec UpdateTableSpec withGlobalSecondaryIndexUpdates.

Prototype

public UpdateTableSpec withGlobalSecondaryIndexUpdates(
            Collection<GlobalSecondaryIndexUpdate> globalSecondaryIndexUpdates) 

Source Link

Usage

From source file:jp.classmethod.aws.dynamodb.DynamoDbRepository.java

License:Open Source License

private TableDescription updateTable(TableDescription desc) {
    Preconditions.checkNotNull(desc, "table description must not be null");
    UpdateTableSpec spec = null;
    if (false == ptMap.get(tableNameSuffix).equals(convert(desc.getProvisionedThroughput()))) {
        //if the throughput of the table is not the same as the throughput in the ptMap configuration,
        //update the thruput of the table
        spec = new UpdateTableSpec().withProvisionedThroughput(ptMap.get(tableNameSuffix));
    }//ww  w.  jav a2 s  .c o  m
    final List<GlobalSecondaryIndexUpdate> gsiUpdates = new ArrayList<>();
    if (desc.getGlobalSecondaryIndexes() != null && false == desc.getGlobalSecondaryIndexes().isEmpty()) {
        //if the table description has updates to secondary indexes
        desc.getGlobalSecondaryIndexes().forEach(gsi -> {
            //for each gsi in the table description
            final String indexName = gsi.getIndexName();
            ProvisionedThroughput pt = ptMap.get(indexName);
            if (pt != null && false == pt.equals(convert(gsi.getProvisionedThroughput()))) {
                //if the throughput of the gsi in the description is not the same as the throughput in the pt map
                //add an update to the gsi's thruput
                gsiUpdates
                        .add(new GlobalSecondaryIndexUpdate().withUpdate(new UpdateGlobalSecondaryIndexAction()
                                .withIndexName(indexName).withProvisionedThroughput(pt)));
            }
        });
    }
    if (false == gsiUpdates.isEmpty()) {
        if (spec == null) {
            spec = new UpdateTableSpec();
        }
        spec.withGlobalSecondaryIndexUpdates(gsiUpdates);
    }
    return spec == null ? null : table.updateTable(spec);
}