com.amazonaws.services.dynamodbv2.model.BatchGetItemResult Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.model.BatchGetItemResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AmazonDynamoDBStubTest.java    From aws-java-sdk-stubs with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #2
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #3
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: TransactionManagerDBFacadeIntegrationTest.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
private void testBatchGetItemsContainsItem(
        final TransactionManagerDynamoDBFacade facade,
        final Map<String, AttributeValue> item,
        final boolean filterAttributes) {
    BatchGetItemRequest batchGetItemRequest = createBatchGetItemRequest(filterAttributes);
    BatchGetItemResult batchGetItemResult = facade.batchGetItem(batchGetItemRequest);
    List<Map<String, AttributeValue>> items = batchGetItemResult.getResponses().get(INTEG_HASH_TABLE_NAME);
    assertEquals(1, items.size());
    assertContainsNoTransactionAttributes(items.get(0));
    assertEquals(item, items.get(0));
}
 
Example #5
Source File: TransactionManagerDBFacadeIntegrationTest.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
private void testBatchGetItemsIsEmpty(final TransactionManagerDynamoDBFacade facade) {
    BatchGetItemRequest batchGetItemRequest = createBatchGetItemRequest(false);
    BatchGetItemResult batchGetItemResult = facade.batchGetItem(batchGetItemRequest);
    assertNotNull(batchGetItemResult.getResponses());
    assertEquals(1, batchGetItemResult.getResponses().size());
    assertNotNull(batchGetItemResult.getResponses().get(INTEG_HASH_TABLE_NAME));
    assertEquals(0, batchGetItemResult.getResponses().get(INTEG_HASH_TABLE_NAME).size());

}
 
Example #6
Source File: TransactionManagerDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(
        Map<String, KeysAndAttributes> requestItems,
        String returnConsumedCapacity) throws AmazonServiceException,
        AmazonClientException {
    BatchGetItemRequest request = new BatchGetItemRequest()
            .withRequestItems(requestItems)
            .withReturnConsumedCapacity(returnConsumedCapacity);
    return batchGetItem(request);
}
 
Example #7
Source File: TransactionManagerDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(
        Map<String, KeysAndAttributes> requestItems)
        throws AmazonServiceException, AmazonClientException {
    BatchGetItemRequest request = new BatchGetItemRequest()
            .withRequestItems(requestItems);
    return batchGetItem(request);
}
 
Example #8
Source File: TransactionDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 5 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(
        Map<String, KeysAndAttributes> requestItems,
        String returnConsumedCapacity) throws AmazonServiceException,
        AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}
 
Example #9
Source File: PostgresDynamoDB.java    From podyn with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(BatchGetItemRequest batchGetItemRequest) {
	throw new UnsupportedOperationException();
}
 
Example #10
Source File: PostgresDynamoDB.java    From podyn with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems, String returnConsumedCapacity) {
	throw new UnsupportedOperationException();
}
 
Example #11
Source File: PostgresDynamoDB.java    From podyn with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems) {
	throw new UnsupportedOperationException();
}
 
Example #12
Source File: ThreadLocalDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(BatchGetItemRequest request) throws AmazonServiceException, AmazonClientException {
    return getBackend().batchGetItem(request);
}
 
Example #13
Source File: ThreadLocalDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems, String returnConsumedCapacity) throws AmazonServiceException, AmazonClientException {
    return getBackend().batchGetItem(requestItems, returnConsumedCapacity);
}
 
Example #14
Source File: ThreadLocalDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(Map<String, KeysAndAttributes> requestItems) throws AmazonServiceException, AmazonClientException {
    return getBackend().batchGetItem(requestItems);
}
 
Example #15
Source File: TransactionDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(BatchGetItemRequest arg0)
        throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}
 
Example #16
Source File: TransactionDynamoDBFacade.java    From dynamodb-transactions with Apache License 2.0 4 votes vote down vote up
@Override
public BatchGetItemResult batchGetItem(
        Map<String, KeysAndAttributes> requestItems)
        throws AmazonServiceException, AmazonClientException {
    throw new UnsupportedOperationException("Use the underlying client instance instead");
}