Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2014-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.dynamodbv2.document;
 
 import java.util.List;
 import java.util.Map;
 
 
Represents a secondary index on a DynamoDB table. This covers both GSI (Global Secondary Index) and LSI (Local Secondary Index). Instance of this class can be obtained via Table.getIndex(java.lang.String).
 
 public class Index implements QueryApiScanApi {
     private static final long SLEEP_TIME_MILLIS = 5000;
     private final Table table;
     private final String indexName;
     private final QueryApi queryDelegate;
     private final ScanImpl scanDelegate;
 
     Index(AmazonDynamoDB clientString indexNameTable table) {
         if (client == null)
             throw new IllegalArgumentException("client must be specified");
         if (indexName == null || indexName.trim().length() == 0)
             throw new IllegalArgumentException("index name must not be null or empty");
         if (table == null)
             throw new IllegalArgumentException("table must be specified");
         this. = table;
         this. = indexName;
         this. = new IndexQueryImpl(clientthis);
         this.  = new IndexScanImpl(clientthis);
     }

    
Returns the owning table.
 
     public final Table getTable() {
         return ;
     }

    

Returns:
the name of this index
 
     public final String getIndexName() {
         return ;
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(KeyAttribute hashKey,
             RangeKeyCondition rangeKeyCondition) {
         return .query(hashKeyrangeKeyCondition);
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(KeyAttribute hashKey,
             RangeKeyCondition rangeKeyConditionQueryFilter... queryFilters) {
         return .query(hashKeyrangeKeyConditionqueryFilters);
     }
 
     @Override
     public ItemCollection<QueryOutcomequery(KeyAttribute hashKey,
             RangeKeyCondition rangeKeyConditionString filterExpression,
             Map<StringStringnameMapMap<StringObjectvalueMap) {
         return .query(hashKeyrangeKeyCondition,
                filterExpressionnameMapvalueMap);
    }
    @Override
    public ItemCollection<QueryOutcomequery(KeyAttribute hashKey,
            RangeKeyCondition rangeKeyConditionString projectionExpression,
            String filterExpressionMap<StringStringnameMap,
            Map<StringObjectvalueMap) {
        return .query(hashKeyrangeKeyCondition,
                projectionExpressionfilterExpressionnameMapvalueMap);
    }
    @Beta
    public ItemCollection<QueryOutcomequery(KeyAttribute hashKey,
            RangeKeyCondition rangeKeyConditionQueryExpressionSpec queryExpressions) {
        return .query(hashKeyrangeKeyCondition,
                queryExpressions.getProjectionExpression(),
                queryExpressions.getFilterExpression(),
                queryExpressions.getNameMap(), queryExpressions.getValueMap());
    }
    @Override
    public ItemCollection<QueryOutcomequery(QuerySpec spec) {
        return .query(spec);
    }
    @Override
            String hashKeyNameObject hashKeyValue) {
        return .query(hashKeyNamehashKeyValue);
    }
    @Override
    public ItemCollection<QueryOutcomequery(String hashKeyName,
            Object hashKeyValueRangeKeyCondition rangeKeyCondition) {
        return .query(hashKeyNamehashKeyValuerangeKeyCondition);
    }
    @Override
    public ItemCollection<QueryOutcomequery(String hashKeyName,
            Object hashKeyValueRangeKeyCondition rangeKeyCondition,
            QueryFilter... queryFilters) {
        return .query(hashKeyNamehashKeyValue,
                rangeKeyConditionqueryFilters);
    }
    @Override
    public ItemCollection<QueryOutcomequery(String hashKeyName,
            Object hashKeyValueRangeKeyCondition rangeKeyCondition,
            String filterExpressionMap<StringStringnameMap,
            Map<StringObjectvalueMap) {
        return .query(hashKeyNamehashKeyValue,
                rangeKeyConditionfilterExpressionnameMapvalueMap);
    }
    @Override
    public ItemCollection<QueryOutcomequery(String hashKeyName,
            Object hashKeyValueRangeKeyCondition rangeKeyCondition,
            String filterExpressionString projectionExpression,
            Map<StringStringnameMapMap<StringObjectvalueMap) {
        return .query(hashKeyNamehashKeyValue,
                rangeKeyConditionfilterExpressionprojectionExpression,
                nameMapvalueMap);
    }
    @Override
    public ItemCollection<QueryOutcomequery(KeyAttribute hashKey) {
        return .query(hashKey);
    }

    
Updates the provisioned throughput for this global secondary index (GSI). Setting the throughput for an index helps you manage performance and is part of the provisioned throughput feature of DynamoDB.

The provisioned throughput values can be upgraded or downgraded based on the maximums and minimums listed in the Limits section in the Amazon DynamoDB Developer Guide.

This index must be a global secondary index and in the ACTIVE state for this operation to succeed. Updating a GSI is an asynchronous operation; while executing the operation, the index is in the UPDATING state. While the index is in the UPDATING state, the index still has the provisioned throughput from before the call. The new provisioned throughput setting is in effect only when the index returns to the ACTIVE state after the update is complete.

Parameters:
provisionedThroughput target provisioned throughput
Returns:
the updated table description returned from DynamoDB.
    public TableDescription updateGSI(
            ProvisionedThroughput provisionedThroughput) {
        return .updateTable(new UpdateTableSpec()
            .withGlobalSecondaryIndexUpdates(
                new GlobalSecondaryIndexUpdate().withUpdate(
                    new UpdateGlobalSecondaryIndexAction()
                    .withIndexName()
                    .withProvisionedThroughput(provisionedThroughput))));
    }

    
Deletes this global secondary index (GSI) from the DynamoDB table. Involves network calls.

This index must be a global secondary index and in the ACTIVE state for this operation to succeed. Deleting a GSI is an asynchronous operation; while executing the operation, the index is in the DELETING state.

Returns:
the updated table description returned from DynamoDB.
    public TableDescription deleteGSI() {
        return .updateTable(new UpdateTableSpec()
            .withGlobalSecondaryIndexUpdates(
                new GlobalSecondaryIndexUpdate().withDelete(
                    new DeleteGlobalSecondaryIndexAction()
                    .withIndexName())));
    }

    
A convenient blocking call that can be used, typically during index creation, to wait for the index to become active by polling the table every 5 seconds.

Currently online index creation is only supported for Global Secondary Index (GSI). Calling this method on a Local Secondary Index (LSI) would result in IllegalArgumentException.

Returns:
the table description when the index has become active
Throws:
java.lang.IllegalArgumentException if the table is being deleted, or if the GSI is not being created or updated, or if the GSI doesn't exist
com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException if the table doesn't exist
        final Table table = getTable();
        final String tableName = table.getTableName();
        final String indexName = getIndexName();
        retry: for (;;) {
            TableDescription desc = table.waitForActive();
            final List<GlobalSecondaryIndexDescriptionlist = desc.getGlobalSecondaryIndexes();
            if (list != null) {
                for (GlobalSecondaryIndexDescription dlist) {
                    if (d.getIndexName().equals(indexName)) {
                        final String status = d.getIndexStatus();
                        switch(IndexStatus.fromValue(status)) {
                            case :
                                return desc;
                            case :
                            case :
                                Thread.sleep();
                                continue retry;
                            default:
                                throw new IllegalArgumentException(
                                    "Global Secondary Index "
                                    + indexName
                                    + " is not being created or updated (with status="
                                    + status + ")");
                        }
                    }
                }
            }
            throw new IllegalArgumentException("Global Secondary Index "
                    + indexName + " does not exist in Table " + tableName + ")");
        }
    }

    
A convenient blocking call that can be used, typically during index deletion on an active table, to wait for the index to become deleted by polling the table every 5 seconds.

Currently online index deletion is only supported for Global Secondary Index (GSI). The behavior of calling this method on a Local Secondary Index (LSI) would result in returning the latest table description.

Returns:
the table description if this GSI has been deleted; or null if the underlying table has been deleted.
Throws:
java.lang.IllegalArgumentException if the table is being deleted, or if the GSI is not being deleted.
com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException if the table doesn't exist
        final String indexName = getIndexName();
        retry: for (;;) {
            final TableDescription desc = getTable().waitForActive();
            if (desc == null)
                return desc;
            List<GlobalSecondaryIndexDescriptionlist = desc.getGlobalSecondaryIndexes();
            if (list != null) {
                for (GlobalSecondaryIndexDescription dlist) {
                    if (d.getIndexName().equals(indexName)) {
                        final String status = d.getIndexStatus();
                        if (IndexStatus.fromValue(status) == .) {
                            Thread.sleep();
                            continue retry;
                        }
                        throw new IllegalArgumentException(
                            "Global Secondary Index " + indexName
                            + " is not being deleted (with status=" + status + ")");
                    }
                }
            }
            return desc;
        }
    }

    
A convenient blocking call that can be used to wait on an index until it has either become active or deleted (ie no longer exists) by polling the table every 5 seconds.

Currently online index creation/deletion is only supported for Global Secondary Index (GSI). The behavior of calling this method on a Local Secondary Index (LSI) would result in returning the latest table description.

Returns:
the table description when the index has become either active or deleted
Throws:
java.lang.IllegalArgumentException if the table is being deleted
com.amazonaws.services.dynamodbv2.model.ResourceNotFoundException if the table doesn't exist
        final Table table = getTable();
        final String indexName = getIndexName();
        retry: for (;;) {
            TableDescription desc = table.waitForActive();
            List<GlobalSecondaryIndexDescriptionlist = desc.getGlobalSecondaryIndexes();
            if (list != null) {
                for (GlobalSecondaryIndexDescription ddesc.getGlobalSecondaryIndexes()) {
                    if (d.getIndexName().equals(indexName)) {
                        final String status = d.getIndexStatus();
                        if (IndexStatus.fromValue(status) == .)
                            return desc;
                        Thread.sleep();
                        continue retry;
                    }
                }
            }
            return desc;
        }
    }
    @Override
    public ItemCollection<ScanOutcomescan(ScanFilter... scanFilters) {
        return .scan(scanFilters);
    }
    @Override
    public ItemCollection<ScanOutcomescan(String filterExpression,
            Map<StringStringnameMapMap<StringObjectvalueMap) {
        return .scan(filterExpressionnameMapvalueMap);
    }
    @Override
    public ItemCollection<ScanOutcomescan(String filterExpression,
            String projectionExpressionMap<StringStringnameMap,
            Map<StringObjectvalueMap) {
        return .scan(filterExpressionprojectionExpressionnameMapvalueMap);
    }
    @Beta
        return .scan(xspec.getFilterExpression(), 
                xspec.getProjectionExpression(),
                xspec.getNameMap(), 
                xspec.getValueMap());
    }
    @Override
    public ItemCollection<ScanOutcomescan(ScanSpec params) {
        return .scan(params);
    }
New to GrepCode? Check out our FAQ X