Search in sources :

Example 1 with ComparisonOperator

use of com.amazonaws.services.dynamodbv2.model.ComparisonOperator in project gora by apache.

the class DynamoDBQuery method buildScanExpression.

/**
   * Builds scan query expression using a hash attribute value where to start
   */
public void buildScanExpression() {
    K qKey = getKey();
    if (qKey == null) {
        LOG.warn("No key defined. Trying with startKey.");
        qKey = query.getStartKey();
        if (qKey == null) {
            throw new IllegalStateException("No key has been defined please check");
        }
    }
    ComparisonOperator compOp = getScanCompOp() != null ? getScanCompOp() : DEFAULT_SCAN_OP;
    DynamoDBScanExpression newScanExpression = new DynamoDBScanExpression();
    // hash key condition
    Map<String, AttributeValue> hashAttrVals = buildHashKey(qKey);
    for (Entry<String, AttributeValue> en : hashAttrVals.entrySet()) {
        Condition scanFilterHashCondition = new Condition().withComparisonOperator(compOp.toString()).withAttributeValueList(en.getValue());
        newScanExpression.addFilterCondition(en.getKey(), scanFilterHashCondition);
    }
    // range key condition
    Map<String, AttributeValue> rangeAttrVals = buildRangeKey(qKey);
    for (Entry<String, AttributeValue> en : rangeAttrVals.entrySet()) {
        Condition scanFilterRangeCondition = new Condition().withComparisonOperator(compOp.toString()).withAttributeValueList(en.getValue());
        newScanExpression.addFilterCondition(en.getKey(), scanFilterRangeCondition);
    }
    dynamoDBExpression = newScanExpression;
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) ComparisonOperator(com.amazonaws.services.dynamodbv2.model.ComparisonOperator) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DynamoDBScanExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)

Example 2 with ComparisonOperator

use of com.amazonaws.services.dynamodbv2.model.ComparisonOperator in project gora by apache.

the class DynamoDBQuery method buildRangeExpression.

/**
   * Builds range query expression
   * 
   */
public void buildRangeExpression() {
    DynamoDBScanExpression queryExpression = new DynamoDBScanExpression();
    ComparisonOperator compOp = ComparisonOperator.BETWEEN;
    // hash key range
    Map<String, AttributeValue> hashAttrVals = buildHashKey(query.getStartKey());
    Map<String, AttributeValue> endHashAttrVals = buildHashKey(query.getEndKey());
    for (Entry<String, AttributeValue> en : hashAttrVals.entrySet()) {
        Condition scanFilterHashCondition = new Condition().withComparisonOperator(compOp.toString()).withAttributeValueList(en.getValue(), endHashAttrVals.get(en.getKey()));
        queryExpression.addFilterCondition(en.getKey(), scanFilterHashCondition);
    }
    // range key range
    Map<String, AttributeValue> rangeAttrVals = buildRangeKey(query.getStartKey());
    Map<String, AttributeValue> endRangeAttrVals = buildRangeKey(query.getEndKey());
    for (Entry<String, AttributeValue> en : rangeAttrVals.entrySet()) {
        Condition scanFilterRangeCondition = new Condition().withComparisonOperator(compOp.toString()).withAttributeValueList(en.getValue(), endRangeAttrVals.get(en.getKey()));
        queryExpression.addFilterCondition(en.getKey(), scanFilterRangeCondition);
    }
    dynamoDBExpression = queryExpression;
}
Also used : Condition(com.amazonaws.services.dynamodbv2.model.Condition) ComparisonOperator(com.amazonaws.services.dynamodbv2.model.ComparisonOperator) AttributeValue(com.amazonaws.services.dynamodbv2.model.AttributeValue) DynamoDBScanExpression(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)

Aggregations

DynamoDBScanExpression (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression)2 AttributeValue (com.amazonaws.services.dynamodbv2.model.AttributeValue)2 ComparisonOperator (com.amazonaws.services.dynamodbv2.model.ComparisonOperator)2 Condition (com.amazonaws.services.dynamodbv2.model.Condition)2