public synchronized BatchGetItemResult batchGetItem(BatchGetItemRequest request) {
BatchGetItemResult batchGetItemResult = new BatchGetItemResult();
Map<String, BatchResponse> response = new HashMap<String, BatchResponse>();
for (String tableName : request.getRequestItems().keySet()) {
BatchResponse batchResponse = new BatchResponse();
List<Map<String, AttributeValue>> items = new ArrayList<Map<String, AttributeValue>>();
KeysAndAttributes keysAndAttributes = request.getRequestItems().get(tableName);
List<Key> itemKeys = keysAndAttributes.getKeys();
List<String> attributeToGet = keysAndAttributes.getAttributesToGet();
try {
for (Key itemKey : itemKeys) {
try {
String hashKeyValue = getKeyValue(itemKey.getHashKeyElement());
String rangeKeyValue = getKeyValue(itemKey.getRangeKeyElement());
Map<String, AttributeValue> item = this.tables.get(tableName).getItem(hashKeyValue, rangeKeyValue);
item = getItemWithAttributesToGet(item, attributeToGet);
if (item != null)
items.add(item);
} catch (NullPointerException e) {
System.err.println("Caught NullPointerException: " + e.getMessage());
}
}
} catch (NullPointerException e) {
System.err.println("Caught NullPointerException: " + e.getMessage());
}
batchResponse.setConsumedCapacityUnits(1.0);
if (items.size() != 0) {
batchResponse.setItems(items);
response.put(tableName, batchResponse);
batchGetItemResult.setResponses(response);
batchGetItemResult.getResponses().put(tableName, batchResponse);
}
}