}
protected ItemCollection<QueryOutcome> doQuery(QuerySpec spec) {
// set the table name
String tableName = getTable().getTableName();
QueryRequest req = spec.getRequest().withTableName(tableName);
// hash key
final KeyAttribute hashKey = spec.getHashKey();
req.addKeyConditionsEntry(hashKey.getName(),
new Condition()
.withComparisonOperator(ComparisonOperator.EQ)
.withAttributeValueList(InternalUtils.toAttributeValue(hashKey.getValue()))
);
// range key condition
RangeKeyCondition rangeKeyCond = spec.getRangeKeyCondition();
if (rangeKeyCond != null) {
KeyConditions keyCond = rangeKeyCond.getKeyCondition();
if (keyCond == null)
throw new IllegalArgumentException("key condition not specified in range key condition");
Object[] values = rangeKeyCond.getValues();
if (values == null)
throw new IllegalArgumentException("key condition values not specified in range key condition");
req.addKeyConditionsEntry(rangeKeyCond.getAttrName(),
new Condition()
.withComparisonOperator(keyCond.toComparisonOperator())
.withAttributeValueList(InternalUtils.toAttributeValues(values))
);
}
// query filters;
Collection<QueryFilter> filters = spec.getQueryFilters();
if (filters != null) {
req.setQueryFilter(InternalUtils.toAttributeConditionMap(filters));
}
// set up the start key, if any
Collection<KeyAttribute> startKey = spec.getExclusiveStartKey();
if (startKey != null)
req.setExclusiveStartKey(InternalUtils.toAttributeValueMap(startKey));
// set up the value map, if any (when expression API is used)
final Map<String,AttributeValue> attrValMap = InternalUtils.fromSimpleMap(spec.getValueMap());
// set up expressions, if any
req.withConditionalOperator(spec.getConditionalOperator())
.withFilterExpression(spec.getFilterExpression())
.withProjectionExpression(spec.getProjectionExpression())
.withExpressionAttributeNames(spec.getNameMap())
.withExpressionAttributeValues(attrValMap)
;