下面列出了怎么用com.amazonaws.services.dynamodbv2.model.KeysAndAttributes的API类实例代码及写法,或者点击链接到github查看源代码。
private BatchGetItemResult getResults(
final Map<String, KeysAndAttributes> requestItems,
final short adapterId,
final Map<ByteArray, GeoWaveRow> resultMap) {
final BatchGetItemRequest request = new BatchGetItemRequest(requestItems);
final BatchGetItemResult result = client.batchGetItem(request);
result.getResponses().values().forEach(results -> results.stream().forEach(objMap -> {
final byte[] dataId = objMap.get(DynamoDBRow.GW_PARTITION_ID_KEY).getB().array();
final AttributeValue valueAttr = objMap.get(DynamoDBRow.GW_VALUE_KEY);
final byte[] value = valueAttr == null ? null : valueAttr.getB().array();
final AttributeValue visAttr = objMap.get(DynamoDBRow.GW_VISIBILITY_KEY);
final byte[] vis = visAttr == null ? new byte[0] : visAttr.getB().array();
resultMap.put(
new ByteArray(dataId),
DataIndexUtils.deserializeDataIndexRow(dataId, adapterId, value, vis));
}));
return result;
}
@Before
public void setUp() {
outcome = new BatchGetItemOutcome(result);
KeysAndAttributes kaa = new KeysAndAttributes();
Map<String,AttributeValue> map = new HashMap<>();
map.put("hashS", new AttributeValue("h1"));
map.put("rangeS", new AttributeValue("r1"));
kaa.withKeys(map);
unprocessed = new HashMap<>();
unprocessed.put(stringHashStringRangeTableName, kaa);
result.withUnprocessedKeys(unprocessed);
Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
List<Map<String,AttributeValue>> items = new ArrayList<>();
responses.put("StringHashStringRangeTable", items);
result.withResponses(responses);
final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {
@Override
public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
return outcome;
}
};
getDynamoDB = new GetDynamoDB() {
@Override
protected DynamoDB getDynamoDB() {
return mockDynamoDB;
}
};
}
@Test
public void testStringHashStringNoRangeGetUnprocessed() {
unprocessed.clear();
KeysAndAttributes kaa = new KeysAndAttributes();
Map<String,AttributeValue> map = new HashMap<>();
map.put("hashS", new AttributeValue("h1"));
kaa.withKeys(map);
unprocessed.put(stringHashStringRangeTableName, kaa);
final TestRunner getRunner = TestRunners.newTestRunner(getDynamoDB);
getRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
getRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
getRunner.enqueue(new byte[] {});
getRunner.run(1);
getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_UNPROCESSED, 1);
List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_UNPROCESSED);
for (MockFlowFile flowFile : flowFiles) {
assertNotNull(flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_UNPROCESSED));
}
}
@Test
public void test_batchGetItem_WithAllParameters() throws Exception {
String TEST_ATTRIBUTE_2 = "Attribute2";
String TEST_ATTRIBUTE_VALUE_2 = "AttributeValue2";
createTable();
putItem(TEST_ATTRIBUTE, TEST_ATTRIBUTE_VALUE);
putItem(TEST_ATTRIBUTE_2, TEST_ATTRIBUTE_VALUE_2);
List<Map<String, AttributeValue>> keys = new ArrayList<Map<String, AttributeValue>>();
Map<String, AttributeValue> key1 = new HashMap<String, AttributeValue>();
key1.put(TEST_ATTRIBUTE, new AttributeValue()
.withS(TEST_ATTRIBUTE_VALUE));
keys.add(key1);
Map<String, AttributeValue> key2 = new HashMap<String, AttributeValue>();
key2.put(TEST_ATTRIBUTE_2, new AttributeValue()
.withS(TEST_ATTRIBUTE_VALUE_2));
keys.add(key2);
Map<String, KeysAndAttributes> requestItems = new HashMap<String, KeysAndAttributes>();
requestItems.put(TEST_TABLE_NAME, new KeysAndAttributes()
.withKeys(keys));
String returnConsumedCapacity = "";
BatchGetItemResult result = dynamoDb.batchGetItem(requestItems,returnConsumedCapacity);
String tableName = result.getResponses().keySet().toArray(new String[1])[0];
List<Map<String, AttributeValue>> items = result.getResponses().get(tableName);
AttributeValue value1 = items.get(0).get(TEST_ATTRIBUTE);
AttributeValue value2 = items.get(1).get(TEST_ATTRIBUTE_2);
assertThat(tableName, equalTo(TEST_TABLE_NAME));
assertThat(items.size(), equalTo(keys.size()));
assertThat(value1.getS(), equalTo(TEST_ATTRIBUTE_VALUE));
assertThat(value2.getS(), equalTo(TEST_ATTRIBUTE_VALUE_2));
}
public Iterator<GeoWaveRow> getRowsFromDataIndex(
final byte[][] dataIds,
final short adapterId,
final String typeName) {
final Map<ByteArray, GeoWaveRow> resultMap = new HashMap<>();
final Iterator<byte[]> dataIdIterator = Arrays.stream(dataIds).iterator();
while (dataIdIterator.hasNext()) {
// fill result map
final Collection<Map<String, AttributeValue>> dataIdsForRequest = new ArrayList<>();
int i = 0;
while (dataIdIterator.hasNext() && (i < MAX_ROWS_FOR_BATCHGETITEM)) {
dataIdsForRequest.add(
Collections.singletonMap(
DynamoDBRow.GW_PARTITION_ID_KEY,
new AttributeValue().withB(ByteBuffer.wrap(dataIdIterator.next()))));
i++;
}
BatchGetItemResult result =
getResults(
Collections.singletonMap(
typeName + "_" + getQualifiedTableName(DataIndexUtils.DATA_ID_INDEX.getName()),
new KeysAndAttributes().withKeys(dataIdsForRequest)),
adapterId,
resultMap);
while (!result.getUnprocessedKeys().isEmpty()) {
result = getResults(result.getUnprocessedKeys(), adapterId, resultMap);
}
}
return Arrays.stream(dataIds).map(d -> resultMap.get(new ByteArray(d))).filter(
r -> r != null).iterator();
}
@Before
public void setUp() {
outcome = new BatchGetItemOutcome(result);
KeysAndAttributes kaa = new KeysAndAttributes();
Map<String,AttributeValue> map = new HashMap<>();
map.put("hashS", new AttributeValue("h1"));
map.put("rangeS", new AttributeValue("r1"));
kaa.withKeys(map);
unprocessed = new HashMap<>();
unprocessed.put(stringHashStringRangeTableName, kaa);
result.withUnprocessedKeys(unprocessed);
Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
List<Map<String,AttributeValue>> items = new ArrayList<>();
responses.put("StringHashStringRangeTable", items);
result.withResponses(responses);
final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {
@Override
public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
return outcome;
}
};
getDynamoDB = new GetDynamoDB() {
@Override
protected DynamoDB getDynamoDB() {
return mockDynamoDB;
}
};
}
@Test
public void testStringHashStringNoRangeGetUnprocessed() {
unprocessed.clear();
KeysAndAttributes kaa = new KeysAndAttributes();
Map<String,AttributeValue> map = new HashMap<>();
map.put("hashS", new AttributeValue("h1"));
kaa.withKeys(map);
unprocessed.put(stringHashStringRangeTableName, kaa);
final TestRunner getRunner = TestRunners.newTestRunner(getDynamoDB);
getRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
getRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
getRunner.enqueue(new byte[] {});
getRunner.run(1);
getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_UNPROCESSED, 1);
List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_UNPROCESSED);
for (MockFlowFile flowFile : flowFiles) {
assertNotNull(flowFile.getAttribute(AbstractDynamoDBProcessor.DYNAMODB_KEY_ERROR_UNPROCESSED));
}
}
private BatchGetItemRequest createBatchGetItemRequest(final boolean filterAttributes) {
KeysAndAttributes keysAndAttributes = new KeysAndAttributes()
.withKeys(key0);
if (filterAttributes) {
keysAndAttributes.withAttributesToGet(attributesToGet);
}
return new BatchGetItemRequest()
.withRequestItems(
Collections.singletonMap(
INTEG_HASH_TABLE_NAME,
keysAndAttributes));
}
@Override
public BatchGetItemResult batchGetItem(
Map<String, KeysAndAttributes> requestItems,
String returnConsumedCapacity) throws AmazonServiceException,
AmazonClientException {
BatchGetItemRequest request = new BatchGetItemRequest()
.withRequestItems(requestItems)
.withReturnConsumedCapacity(returnConsumedCapacity);
return batchGetItem(request);
}
@Override
public BatchGetItemResult batchGetItem(
Map<String, KeysAndAttributes> requestItems)
throws AmazonServiceException, AmazonClientException {
BatchGetItemRequest request = new BatchGetItemRequest()
.withRequestItems(requestItems);
return batchGetItem(request);
}
@Override
public BatchGetItemResult batchGetItem(
Map<String, KeysAndAttributes> requestItems,
String returnConsumedCapacity) throws AmazonServiceException,
AmazonClientException {
throw new UnsupportedOperationException("Use the underlying client instance instead");
}
@Test
public void testStringHashStringRangeGetJsonObjectNull() {
outcome = new BatchGetItemOutcome(result);
KeysAndAttributes kaa = new KeysAndAttributes();
Map<String,AttributeValue> map = new HashMap<>();
map.put("hashS", new AttributeValue("h1"));
map.put("rangeS", new AttributeValue("r1"));
kaa.withKeys(map);
unprocessed = new HashMap<>();
result.withUnprocessedKeys(unprocessed);
Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
List<Map<String,AttributeValue>> items = new ArrayList<>();
Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
item.put("j1",null);
item.put("hashS", new AttributeValue("h1"));
item.put("rangeS", new AttributeValue("r1"));
items.add(item);
responses.put("StringHashStringRangeTable", items);
result.withResponses(responses);
final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {
@Override
public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
return outcome;
}
};
getDynamoDB = new GetDynamoDB() {
@Override
protected DynamoDB getDynamoDB() {
return mockDynamoDB;
}
};
final TestRunner getRunner = TestRunners.newTestRunner(getDynamoDB);
getRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
getRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
getRunner.enqueue(new byte[] {});
getRunner.run(1);
getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_SUCCESS, 1);
List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS);
for (MockFlowFile flowFile : flowFiles) {
assertNull(flowFile.getContentClaim());
}
}
@Test
public void testStringHashStringRangeGetJsonObjectValid() throws IOException {
outcome = new BatchGetItemOutcome(result);
KeysAndAttributes kaa = new KeysAndAttributes();
Map<String,AttributeValue> map = new HashMap<>();
map.put("hashS", new AttributeValue("h1"));
map.put("rangeS", new AttributeValue("r1"));
kaa.withKeys(map);
unprocessed = new HashMap<>();
result.withUnprocessedKeys(unprocessed);
Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
List<Map<String,AttributeValue>> items = new ArrayList<>();
Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
String jsonDocument = "{\"name\": \"john\"}";
item.put("j1",new AttributeValue(jsonDocument));
item.put("hashS", new AttributeValue("h1"));
item.put("rangeS", new AttributeValue("r1"));
items.add(item);
responses.put("StringHashStringRangeTable", items);
result.withResponses(responses);
final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {
@Override
public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
return outcome;
}
};
getDynamoDB = new GetDynamoDB() {
@Override
protected DynamoDB getDynamoDB() {
return mockDynamoDB;
}
};
final TestRunner getRunner = TestRunners.newTestRunner(getDynamoDB);
getRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
getRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
getRunner.enqueue(new byte[] {});
getRunner.run(1);
getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_SUCCESS, 1);
}
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems, String returnConsumedCapacity) {
throw new UnsupportedOperationException();
}
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems) {
throw new UnsupportedOperationException();
}
private static void retrieveMultipleItemsBatchGet() {
try {
TableKeysAndAttributes forumTableKeysAndAttributes = new TableKeysAndAttributes(forumTableName);
// Add a partition key
forumTableKeysAndAttributes.addHashOnlyPrimaryKeys("Name", "Amazon S3", "Amazon DynamoDB");
TableKeysAndAttributes threadTableKeysAndAttributes = new TableKeysAndAttributes(threadTableName);
// Add a partition key and a sort key
threadTableKeysAndAttributes.addHashAndRangePrimaryKeys("ForumName", "Subject", "Amazon DynamoDB",
"DynamoDB Thread 1", "Amazon DynamoDB", "DynamoDB Thread 2", "Amazon S3", "S3 Thread 1");
System.out.println("Making the request.");
BatchGetItemOutcome outcome = dynamoDB.batchGetItem(forumTableKeysAndAttributes,
threadTableKeysAndAttributes);
Map<String, KeysAndAttributes> unprocessed = null;
do {
for (String tableName : outcome.getTableItems().keySet()) {
System.out.println("Items in table " + tableName);
List<Item> items = outcome.getTableItems().get(tableName);
for (Item item : items) {
System.out.println(item.toJSONPretty());
}
}
// Check for unprocessed keys which could happen if you exceed
// provisioned
// throughput or reach the limit on response size.
unprocessed = outcome.getUnprocessedKeys();
if (unprocessed.isEmpty()) {
System.out.println("No unprocessed keys found");
}
else {
System.out.println("Retrieving the unprocessed keys");
outcome = dynamoDB.batchGetItemUnprocessed(unprocessed);
}
} while (!unprocessed.isEmpty());
}
catch (Exception e) {
System.err.println("Failed to retrieve items.");
System.err.println(e.getMessage());
}
}
@Test
public void testStringHashStringRangeGetJsonObjectNull() {
outcome = new BatchGetItemOutcome(result);
KeysAndAttributes kaa = new KeysAndAttributes();
Map<String,AttributeValue> map = new HashMap<>();
map.put("hashS", new AttributeValue("h1"));
map.put("rangeS", new AttributeValue("r1"));
kaa.withKeys(map);
unprocessed = new HashMap<>();
result.withUnprocessedKeys(unprocessed);
Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
List<Map<String,AttributeValue>> items = new ArrayList<>();
Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
item.put("j1",null);
item.put("hashS", new AttributeValue("h1"));
item.put("rangeS", new AttributeValue("r1"));
items.add(item);
responses.put("StringHashStringRangeTable", items);
result.withResponses(responses);
final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {
@Override
public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
return outcome;
}
};
getDynamoDB = new GetDynamoDB() {
@Override
protected DynamoDB getDynamoDB() {
return mockDynamoDB;
}
};
final TestRunner getRunner = TestRunners.newTestRunner(getDynamoDB);
getRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
getRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
getRunner.enqueue(new byte[] {});
getRunner.run(1);
getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_SUCCESS, 1);
List<MockFlowFile> flowFiles = getRunner.getFlowFilesForRelationship(AbstractDynamoDBProcessor.REL_SUCCESS);
for (MockFlowFile flowFile : flowFiles) {
assertNull(flowFile.getContentClaim());
}
}
@Test
public void testStringHashStringRangeGetJsonObjectValid() throws IOException {
outcome = new BatchGetItemOutcome(result);
KeysAndAttributes kaa = new KeysAndAttributes();
Map<String,AttributeValue> map = new HashMap<>();
map.put("hashS", new AttributeValue("h1"));
map.put("rangeS", new AttributeValue("r1"));
kaa.withKeys(map);
unprocessed = new HashMap<>();
result.withUnprocessedKeys(unprocessed);
Map<String,List<Map<String,AttributeValue>>> responses = new HashMap<>();
List<Map<String,AttributeValue>> items = new ArrayList<>();
Map<String,AttributeValue> item = new HashMap<String,AttributeValue>();
String jsonDocument = "{\"name\": \"john\"}";
item.put("j1",new AttributeValue(jsonDocument));
item.put("hashS", new AttributeValue("h1"));
item.put("rangeS", new AttributeValue("r1"));
items.add(item);
responses.put("StringHashStringRangeTable", items);
result.withResponses(responses);
final DynamoDB mockDynamoDB = new DynamoDB(Regions.AP_NORTHEAST_1) {
@Override
public BatchGetItemOutcome batchGetItem(TableKeysAndAttributes... tableKeysAndAttributes) {
return outcome;
}
};
getDynamoDB = new GetDynamoDB() {
@Override
protected DynamoDB getDynamoDB() {
return mockDynamoDB;
}
};
final TestRunner getRunner = TestRunners.newTestRunner(getDynamoDB);
getRunner.setProperty(AbstractDynamoDBProcessor.ACCESS_KEY,"abcd");
getRunner.setProperty(AbstractDynamoDBProcessor.SECRET_KEY, "cdef");
getRunner.setProperty(AbstractDynamoDBProcessor.REGION, REGION);
getRunner.setProperty(AbstractDynamoDBProcessor.TABLE, stringHashStringRangeTableName);
getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_NAME, "rangeS");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_NAME, "hashS");
getRunner.setProperty(AbstractDynamoDBProcessor.RANGE_KEY_VALUE, "r1");
getRunner.setProperty(AbstractDynamoDBProcessor.HASH_KEY_VALUE, "h1");
getRunner.setProperty(AbstractDynamoDBProcessor.JSON_DOCUMENT, "j1");
getRunner.enqueue(new byte[] {});
getRunner.run(1);
getRunner.assertAllFlowFilesTransferred(AbstractDynamoDBProcessor.REL_SUCCESS, 1);
}
private static void retrieveMultipleItemsBatchGet() {
try {
TableKeysAndAttributes forumTableKeysAndAttributes = new TableKeysAndAttributes(forumTableName);
forumTableKeysAndAttributes.addHashOnlyPrimaryKeys("Name", "Amazon S3", "Amazon DynamoDB");
TableKeysAndAttributes threadTableKeysAndAttributes = new TableKeysAndAttributes(threadTableName);
threadTableKeysAndAttributes.addHashAndRangePrimaryKeys("ForumName", "Subject",
"Amazon DynamoDB","DynamoDB Thread 1",
"Amazon DynamoDB","DynamoDB Thread 2",
"Amazon S3","S3 Thread 1");
Map<String, TableKeysAndAttributes> requestItems = new HashMap<String, TableKeysAndAttributes>();
requestItems.put(forumTableName, forumTableKeysAndAttributes);
requestItems.put(threadTableName, threadTableKeysAndAttributes);
System.out.println("Making the request.");
BatchGetItemOutcome outcome = dynamoDB.batchGetItem(forumTableKeysAndAttributes,
threadTableKeysAndAttributes);
do {
for (String tableName : outcome.getTableItems().keySet()) {
System.out.println("Items in table " + tableName);
List<Item> items = outcome.getTableItems().get(tableName);
for (Item item : items) {
System.out.println(item.toJSONPretty());
}
}
// Check for unprocessed keys which could happen if you exceed provisioned
// throughput or reach the limit on response size.
Map<String, KeysAndAttributes> unprocessedKeys = outcome.getUnprocessedKeys();
if (outcome.getUnprocessedKeys().size() == 0) {
System.out.println("No unprocessed keys found");
} else {
System.out.println("Retrieving the unprocessed keys");
outcome = dynamoDB.batchGetItemUnprocessed(unprocessedKeys);
}
} while (outcome.getUnprocessedKeys().size() > 0);
} catch (Exception e) {
System.err.println("Failed to retrieve items.");
System.err.println(e.getMessage());
}
}
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems, String returnConsumedCapacity) throws AmazonServiceException, AmazonClientException {
return getBackend().batchGetItem(requestItems, returnConsumedCapacity);
}
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems) throws AmazonServiceException, AmazonClientException {
return getBackend().batchGetItem(requestItems);
}
@Override
public BatchGetItemResult batchGetItem(
Map<String, KeysAndAttributes> requestItems)
throws AmazonServiceException, AmazonClientException {
throw new UnsupportedOperationException("Use the underlying client instance instead");
}