Java 类com.amazonaws.services.dynamodbv2.model.BatchGetItemResult 实例源码

项目:Camel    文件:AmazonDDBClientMock.java   
@SuppressWarnings("unchecked")
@Override
public BatchGetItemResult batchGetItem(BatchGetItemRequest batchGetItemRequest) {
    this.batchGetItemRequest = batchGetItemRequest;
    Map<String, List<Map<String, AttributeValue>>> responseMap = new HashMap<String, List<Map<String, AttributeValue>>>();
    List<Map<String, AttributeValue>> p = new ArrayList<Map<String, AttributeValue>>();
    p.add(getAttributes());
    responseMap.put("DOMAIN1", p);
    Map<String, AttributeValue> keysMap = new HashMap<String, AttributeValue>();
    keysMap.put("1", new AttributeValue("UNPROCESSED_KEY"));
    Map<String, KeysAndAttributes> unprocessedKeys = new HashMap<String, KeysAndAttributes>();
    unprocessedKeys.put("DOMAIN1", new KeysAndAttributes().withKeys(keysMap));

    return new BatchGetItemResult()
            .withResponses(responseMap)
            .withUnprocessedKeys(unprocessedKeys);
}
项目:amazon-kinesis-aggregators    文件:DynamoQueryEngine.java   
private List<Map<String, AttributeValue>> batchGetDataByKeys(
        final String tableName, final KeysAndAttributes keys) {
    Map<String, KeysAndAttributes> requestMap = new HashMap<>();
    keys.setConsistentRead(true);
    requestMap.put(tableName, keys);

    BatchGetItemResult result = null;
    try {
        result = dynamoClient.batchGetItem(new BatchGetItemRequest(
                requestMap));
    } catch (AmazonServiceException e) {
        LOG.error(e);
        throw e;
    }

    return result.getResponses().get(this.tableName);
}
项目:Camel    文件:BatchGetItemsCommand.java   
@Override
public void execute() {
    BatchGetItemResult result = ddbClient.batchGetItem(
            new BatchGetItemRequest().withRequestItems(determineBatchItems()));

    Map tmp = new HashMap<>();
    tmp.put(DdbConstants.BATCH_RESPONSE, result.getResponses());
    tmp.put(DdbConstants.UNPROCESSED_KEYS, result.getUnprocessedKeys());
    addToResults(tmp);        
}
项目:aws-java-sdk-stubs    文件:AmazonDynamoDBStubTest.java   
@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));
}
项目:para    文件:AWSDynamoUtils.java   
/**
 * Reads multiple items from DynamoDB, in batch.
 * @param <P> type of object
 * @param kna a map of row key->data
 * @param results a map of ID->ParaObject
 */
protected static <P extends ParaObject> void batchGet(Map<String, KeysAndAttributes> kna, Map<String, P> results) {
    if (kna == null || kna.isEmpty() || results == null) {
        return;
    }
    try {
        BatchGetItemResult result = getClient().batchGetItem(new BatchGetItemRequest().
                withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withRequestItems(kna));
        if (result == null) {
            return;
        }

        List<Map<String, AttributeValue>> res = result.getResponses().get(kna.keySet().iterator().next());

        for (Map<String, AttributeValue> item : res) {
            P obj = fromRow(item);
            if (obj != null) {
                results.put(obj.getId(), obj);
            }
        }
        logger.debug("batchGet(): total {}, cc {}", res.size(), result.getConsumedCapacity());

        if (result.getUnprocessedKeys() != null && !result.getUnprocessedKeys().isEmpty()) {
            Thread.sleep(1000);
            logger.warn("{} UNPROCESSED read requests!", result.getUnprocessedKeys().size());
            batchGet(result.getUnprocessedKeys(), results);
        }
    } catch (Exception e) {
        logger.error(null, e);
    }
}
项目:spring-security-oauth2-dynamodb    文件:DynamoDBTemplate.java   
public <T> List<T> batchGet(String tableName, KeysAndAttributes keysAndAttributes, final ObjectExtractor<T> extractor) throws EmptyResultDataAccessException {
    Assert.notNull(tableName, "Table must not be null");
    Assert.notNull(extractor, "ObjectExtractor must not be null");
    if (logger.isDebugEnabled()) {
        logger.debug("Executing batch get on " + tableName + " for " + keysAndAttributes.toString());
    }

    List<T> results = new ArrayList<T>(keysAndAttributes.getKeys().size());

    Map<String, KeysAndAttributes> unprocessedKeys = Collections.singletonMap(tableName, keysAndAttributes);
    while (unprocessedKeys.size() > 0) {
        BatchGetItemResult result = client.batchGetItem(unprocessedKeys);
        List<Map<String, AttributeValue>> items = result.getResponses().get(tableName);
        if (items != null) {
            for (Map<String, AttributeValue> item : items) {
                results.add(extractor.extract(item));
            }
        }

        unprocessedKeys = result.getUnprocessedKeys();
    }

    if (results.size() == 0) {
        throw new EmptyResultDataAccessException("No results found in " + tableName + "for " + keysAndAttributes.toString());
    }

    return results;
}