Search in sources :

Example 1 with DynamoDBScanExpression

use of com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression in project gora by apache.

the class DynamoDBNativeStore method execute.

/**
   * Executes a query after building a DynamoDB specific query based on the
   * received one
   */
@Override
public Result<K, T> execute(Query<K, T> query) {
    DynamoDBQuery<K, T> dynamoDBQuery = buildDynamoDBQuery(query);
    DynamoDBMapper mapper = new DynamoDBMapper(dynamoDBStoreHandler.getDynamoDbClient());
    List<T> objList = null;
    if (DynamoDBQuery.getType().equals(DynamoDBQuery.RANGE_QUERY))
        objList = mapper.scan(persistentClass, (DynamoDBScanExpression) dynamoDBQuery.getQueryExpression());
    if (DynamoDBQuery.getType().equals(DynamoDBQuery.SCAN_QUERY))
        objList = mapper.scan(persistentClass, (DynamoDBScanExpression) dynamoDBQuery.getQueryExpression());
    return new DynamoDBResult<K, T>(this, query, objList);
}
Also used : DynamoDBResult(org.apache.gora.dynamodb.query.DynamoDBResult) DynamoDBMapper(com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)

Example 2 with DynamoDBScanExpression

use of com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression 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 3 with DynamoDBScanExpression

use of com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBScanExpression 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 DynamoDBMapper (com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper)1 DynamoDBResult (org.apache.gora.dynamodb.query.DynamoDBResult)1