Example usage for com.amazonaws.services.dynamodbv2.document.spec QuerySpec withRangeKeyCondition

List of usage examples for com.amazonaws.services.dynamodbv2.document.spec QuerySpec withRangeKeyCondition

Introduction

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

Prototype

public QuerySpec withRangeKeyCondition(RangeKeyCondition rangeKeyCondition) 

Source Link

Usage

From source file:com.clicktravel.infrastructure.persistence.aws.dynamodb.QuerySpecBuilder.java

License:Apache License

private static <T extends Item> void addRangeKeyConditionToQuerySpec(final QuerySpec querySpec,
        final CompoundAttributeQuery compoundAttributeQuery, final Class<T> itemClass) {
    final String supportingConditionStringValue = compoundAttributeQuery.getSupportingCondition().getValues()
            .iterator().next();/*  w ww  .  j ava2s .c  o  m*/
    final Operators comparisonOperator = compoundAttributeQuery.getSupportingCondition()
            .getComparisonOperator();
    final Class<?> supportingAttributeType = compoundAttributeQuery.getSupportingAttributeType(itemClass);

    try {
        final Object supportingConditionValue = supportingAttributeType.getConstructor(String.class)
                .newInstance(supportingConditionStringValue);

        final RangeKeyCondition rangeKeyCondition = RangeKeyConditionBuilder.build(
                compoundAttributeQuery.getSupportingAttributeName(), supportingConditionValue,
                comparisonOperator);
        querySpec.withRangeKeyCondition(rangeKeyCondition);
    } catch (final Exception e) {
        throw new PersistenceResourceFailureException(
                String.format("Could not add range key condition for query: %s on item %s.",
                        compoundAttributeQuery, itemClass.getSimpleName()),
                e);
    }
}