Example usage for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBQueryExpression setIndexName

List of usage examples for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBQueryExpression setIndexName

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.datamodeling DynamoDBQueryExpression setIndexName.

Prototype

public void setIndexName(String indexName) 

Source Link

Document

Sets the name of the index to be used by this query.

Usage

From source file:org.socialsignin.spring.data.dynamodb.repository.query.DynamoDBEntityWithHashAndRangeKeyCriteria.java

License:Apache License

public DynamoDBQueryExpression<T> buildQueryExpression() {
    DynamoDBQueryExpression<T> queryExpression = new DynamoDBQueryExpression<T>();
    if (isHashKeySpecified()) {
        T hashKeyPrototype = entityInformation.getHashKeyPropotypeEntityForHashKey(getHashKeyPropertyValue());
        queryExpression.withHashKeyValues(hashKeyPrototype);
        queryExpression.withRangeKeyConditions(new HashMap<String, Condition>());
    }/* w  ww .j  a  v  a2 s  .  co m*/

    if (isRangeKeySpecified() && !isApplicableForGlobalSecondaryIndex()) {
        Condition rangeKeyCondition = createSingleValueCondition(getRangeKeyPropertyName(),
                ComparisonOperator.EQ, getRangeKeyAttributeValue(), getRangeKeyAttributeValue().getClass(),
                true);
        queryExpression.withRangeKeyCondition(getRangeKeyAttributeName(), rangeKeyCondition);
        applySortIfSpecified(queryExpression, Arrays.asList(new String[] { getRangeKeyPropertyName() }));

    } else if (isOnlyASingleAttributeConditionAndItIsOnEitherRangeOrIndexRangeKey()
            || (isApplicableForGlobalSecondaryIndex())) {

        Entry<String, List<Condition>> singlePropertyConditions = propertyConditions.entrySet().iterator()
                .next();

        List<String> allowedSortProperties = new ArrayList<String>();
        for (Entry<String, List<Condition>> singlePropertyCondition : propertyConditions.entrySet()) {
            if (entityInformation.getGlobalSecondaryIndexNamesByPropertyName().keySet()
                    .contains(singlePropertyCondition.getKey())) {
                allowedSortProperties.add(singlePropertyCondition.getKey());
            }
        }
        if (allowedSortProperties.size() == 0) {
            allowedSortProperties.add(singlePropertyConditions.getKey());
        }

        for (Entry<String, List<Condition>> singleAttributeConditions : attributeConditions.entrySet()) {
            for (Condition condition : singleAttributeConditions.getValue()) {
                queryExpression.withRangeKeyCondition(singleAttributeConditions.getKey(), condition);
            }
        }

        applySortIfSpecified(queryExpression, allowedSortProperties);
        if (getGlobalSecondaryIndexName() != null) {
            queryExpression.setIndexName(getGlobalSecondaryIndexName());
        }
    } else {
        applySortIfSpecified(queryExpression, Arrays.asList(new String[] { getRangeKeyPropertyName() }));
    }

    return queryExpression;
}