Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>();
Map<String, Class<?>> classesByTableName = new HashMap<String, Class<?>>();
Map<String, List<Object>> resultSet = new HashMap<String, List<Object>>();
int count = 0;
KeysAndAttributes keysAndAttributes = new KeysAndAttributes();
List<Key> keys = new LinkedList<Key>();
for (Class<?> clazz : itemsToGet.keySet()) {
String tableName = getTableName(clazz, config);
List<KeyPair> keyPairs = itemsToGet.get(clazz);
if (keyPairs == null) {
continue;
}
classesByTableName.put(tableName, clazz);
Method hashKeyGetter = reflector.getHashKeyGetter(clazz);
for (KeyPair keyPair : keyPairs) {
AttributeValue hashKeyElement = getHashKeyElement(keyPair.getHashKey(), hashKeyGetter);
// Determine the range key, if provided
AttributeValue rangeKeyElement = null;
if (keyPair.getRangeKey() != null) {
Method rangeKeyMethod = reflector.getRangeKeyGetter(clazz);
if (rangeKeyMethod == null) {
throw new DynamoDBMappingException("Zero-parameter range key property must be annotated with "
+ DynamoDBRangeKey.class);
}
rangeKeyElement = getRangeKeyElement(keyPair.getRangeKey(), rangeKeyMethod);
}
keys.add(new Key().withHashKeyElement(hashKeyElement).withRangeKeyElement(rangeKeyElement));
count++;
// Reach the maximum number which can be handled in a single
// batchGet
if (count == 100) {
requestItems.put(tableName, new KeysAndAttributes().withKeys(keys).withConsistentRead(consistentReads));
processBatchGetRequest(classesByTableName, requestItems, resultSet);
keys.clear();
requestItems.clear();
count = 0;
}
}
keysAndAttributes.setKeys(keys);
requestItems.put(tableName, new KeysAndAttributes().withKeys(new ArrayList<Key>(keys)));
keys.clear();
}
if (count > 0) {
processBatchGetRequest(classesByTableName, requestItems, resultSet);