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

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

Introduction

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

Prototype

public DynamoDBQueryExpression<T> withRangeKeyCondition(String rangeKeyAttributeName,
        Condition rangeKeyCondition) 

Source Link

Document

Sets one range key condition for this query, using the attribute name of the range key.

Usage

From source file:com.makariev.dynamodb.preferences.UserPreferenceObjectMapperService.java

License:Open Source License

private List<UserPreference> queryByNames(String firstName, String lastName) {

    DynamoDBQueryExpression<UserPreference> dynamoDBQueryExpression = new DynamoDBQueryExpression<>();
    dynamoDBQueryExpression.withIndexName(UserPreference.NAME_INDEX);

    dynamoDBQueryExpression.withRangeKeyCondition("firstName",
            new Condition().withComparisonOperator(ComparisonOperator.EQ)
                    .withAttributeValueList(new AttributeValue().withS(firstName)));

    dynamoDBQueryExpression.withRangeKeyCondition("lastName",
            new Condition().withComparisonOperator(ComparisonOperator.EQ)
                    .withAttributeValueList(new AttributeValue().withS(lastName)));

    final List<UserPreference> list = mapper.query(UserPreference.class, dynamoDBQueryExpression);

    return list;/*w  w w.ja v  a2 s. com*/
}

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