*/
if (rangeKeyConditions.size() > 1) {
// The current DynamoDB service only supports queries using hash key equal condition
// plus ONE range key condition.
// This range key could be either the primary key or any index key.
throw new AmazonClientException("Conditions on multiple range keys ("
+ rangeKeyConditions.keySet().toString()
+ ") are found in the query. DynamoDB service only accepts up to ONE range key condition.");
}
String assignedIndexName = queryRequest.getIndexName();
for (String rangeKey : rangeKeyConditions.keySet()) {
/**
* If it is a primary range key, checks whether the user has specified
* an unnecessary index name.
*/
if (rangeKey.equals(reflector.getPrimaryRangeKeyName(clazz))) {
if ( null != assignedIndexName )
throw new AmazonClientException("The range key ("
+ rangeKey + ") in the query is the primary key of the table, not the range key of index ("
+ assignedIndexName + ").");
}
else {
List<String> annotatedIndexNames = reflector.getIndexNameByIndexRangeKeyName(clazz, rangeKey);
/**
* If it is an index range key,
* check whether the provided index name matches the @DynamoDBIndexRangeKey annotation,
* or try to infer the index name according to @DynamoDBIndexRangeKey annotation
* if it is not provided in the query.
*/
if ( null != annotatedIndexNames) {
if (null == assignedIndexName) {
// infer the index name if the range key is used only in one index
if ( 1 == annotatedIndexNames.size()) {
queryRequest.setIndexName(annotatedIndexNames.get(0));
} else {
throw new AmazonClientException("Please specify which index to be used for this query. "
+ "(Choose from " + annotatedIndexNames.toString() + ").");
}
} else {
// check whether the provided index name in the query matches the @DyanmoDBIndexRangeKey annotation
if ( !annotatedIndexNames.contains(assignedIndexName)) {
throw new AmazonClientException(assignedIndexName
+ " is not annotated as an index in the @DynamoDBIndexRangeKey annotation on "
+ rangeKey + "(Choose from " + annotatedIndexNames.toString() + ").");
}
}
}
else {
throw new AmazonClientException("The range key used in the query (" + rangeKey + ") is not annotated with " +
"either @DynamoDBRangeKey or @DynamoDBIndexRangeKey in class (" + clazz.getName() + ").");
}
}
}
}