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