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

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

Introduction

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

Prototype

public void setExpressionAttributeValues(java.util.Map<String, AttributeValue> expressionAttributeValues) 

Source Link

Document

One or more values that can be substituted in an expression.

Usage

From source file:org.openhab.persistence.dynamodb.internal.DynamoDBPersistenceService.java

License:Open Source License

private void maybeAddStateFilter(FilterCriteria filter,
        final DynamoDBQueryExpression<DynamoDBItem<?>> queryExpression) {
    if (filter.getOperator() != null && filter.getState() != null) {
        // Convert filter's state to DynamoDBItem in order get suitable string representation for the state
        final DynamoDBItem<?> filterState = AbstractDynamoDBItem.fromState(filter.getItemName(),
                filter.getState(), new Date());
        queryExpression.setFilterExpression(String.format("%s %s :opstate",
                DynamoDBItem.ATTRIBUTE_NAME_ITEMSTATE, operatorAsString(filter.getOperator())));

        filterState.accept(new DynamoDBItemVisitor() {

            @Override/*from  w  w w.j ava  2s .co  m*/
            public void visit(DynamoDBStringItem dynamoStringItem) {
                queryExpression.setExpressionAttributeValues(
                        ImmutableMap.of(":opstate", new AttributeValue().withS(dynamoStringItem.getState())));
            }

            @Override
            public void visit(DynamoDBBigDecimalItem dynamoBigDecimalItem) {
                queryExpression.setExpressionAttributeValues(ImmutableMap.of(":opstate",
                        new AttributeValue().withN(dynamoBigDecimalItem.getState().toPlainString())));
            }
        });

    }
}