Example usage for com.amazonaws.services.dynamodbv2.model BatchGetItemRequest addRequestItemsEntry

List of usage examples for com.amazonaws.services.dynamodbv2.model BatchGetItemRequest addRequestItemsEntry

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model BatchGetItemRequest addRequestItemsEntry.

Prototype

public BatchGetItemRequest addRequestItemsEntry(String key, KeysAndAttributes value) 

Source Link

Usage

From source file:com.dell.doradus.db.dynamodb.DDBRowIterator.java

License:Apache License

/**
 * Create a row iterator that returns specific rows and columns for the given table. A
 * series of batch requests are made if needed.
 * //  www .  j  av a 2  s.  co  m
 * @param tableName Name for which to get rows for.
 * @param rowKeys   Collection of row keys to get.
 * @param colNames  Set of column names to fetch. If null or empty, all columns are
 *                  fetched.
 */
public DDBRowIterator(String tableName, Collection<String> rowKeys, Collection<String> colNames) {
    Iterator<String> rowKeyIter = rowKeys.iterator();
    KeysAndAttributes keysAndAttributes = makeKeyBatch(rowKeyIter);

    while (true) {
        BatchGetItemRequest batchRequest = new BatchGetItemRequest();
        batchRequest.addRequestItemsEntry(tableName, keysAndAttributes);

        BatchGetItemResult batchResult = DynamoDBService.instance().batchGetItem(batchRequest);
        Map<String, List<Map<String, AttributeValue>>> responseMap = batchResult.getResponses();

        List<Map<String, AttributeValue>> itemsList = responseMap.get(tableName);
        if (itemsList == null || itemsList.size() == 0) {
            break;
        }
        for (Map<String, AttributeValue> attributeMap : itemsList) {
            AttributeValue rowAttr = attributeMap.get(DynamoDBService.ROW_KEY_ATTR_NAME);
            m_rowList.add(new DDBRow(rowAttr.getS(), new DDBColumnIterator(attributeMap, colNames)));
        }

        Map<String, KeysAndAttributes> unprocessedKeys = batchResult.getUnprocessedKeys();
        if (unprocessedKeys != null && unprocessedKeys.containsKey(tableName)) {
            keysAndAttributes = unprocessedKeys.get(tableName);
        } else if (rowKeyIter.hasNext()) {
            keysAndAttributes = makeKeyBatch(rowKeyIter);
        } else {
            break;
        }
    }
}

From source file:com.dell.doradus.db.dynamodb.DDBRowIterator.java

License:Apache License

/**
 * Create a row iterator that returns specific rows and column ranges for the given
 * table. A series of batch item requests are made if needed.
 * /* w  ww. j  a v a2  s.c o  m*/
 * @param tableName Name for which to get rows for.
 * @param rowKeys   Collection of row keys to get.
 * @param startCol  If non-null/empty, only column names greater than or equal to this
 *                  name are captured.
 * @param endCol    If non-null/empty, only column names less than or equal to this
 *                  name are captured.
 */
public DDBRowIterator(String tableName, Collection<String> rowKeys, String startCol, String endCol) {
    Iterator<String> rowKeyIter = rowKeys.iterator();
    KeysAndAttributes keysAndAttributes = makeKeyBatch(rowKeyIter);
    while (true) {
        BatchGetItemRequest batchRequest = new BatchGetItemRequest();
        batchRequest.addRequestItemsEntry(tableName, keysAndAttributes);

        BatchGetItemResult batchResult = DynamoDBService.instance().batchGetItem(batchRequest);
        Map<String, List<Map<String, AttributeValue>>> responseMap = batchResult.getResponses();

        List<Map<String, AttributeValue>> itemsList = responseMap.get(tableName);
        if (itemsList == null || itemsList.size() == 0) {
            break;
        }
        for (Map<String, AttributeValue> attributeMap : itemsList) {
            AttributeValue rowAttr = attributeMap.get(DynamoDBService.ROW_KEY_ATTR_NAME);
            m_rowList.add(new DDBRow(rowAttr.getS(), new DDBColumnIterator(attributeMap, startCol, endCol)));
        }

        Map<String, KeysAndAttributes> unprocessedKeys = batchResult.getUnprocessedKeys();
        if (unprocessedKeys != null && unprocessedKeys.containsKey(tableName)) {
            keysAndAttributes = unprocessedKeys.get(tableName);
        } else if (rowKeyIter.hasNext()) {
            keysAndAttributes = makeKeyBatch(rowKeyIter);
        } else {
            break;
        }
    }
}