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

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

Introduction

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

Prototype

public DynamoDBQueryExpression<T> withRangeKeyConditions(Map<String, Condition> rangeKeyConditions) 

Source Link

Document

Sets the range key condition for 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>());
    }/*from www  . ja v a  2s .c om*/

    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;
}