@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); }
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); }
public CompletableFuture<Map<String, List<Map<String, Object>>>> batchGetItem(final BatchGetItemRequest batchGetItemRequest) { return asyncExecutor.execute(new Callable<Map<String, List<Map<String, Object>>>>() { @Override public Map<String, List<Map<String, Object>>> call() throws Exception { return dbExecutor.batchGetItem(batchGetItemRequest); } }); }
public <T> CompletableFuture<Map<String, List<T>>> batchGetItem(final Class<T> targetClass, final BatchGetItemRequest batchGetItemRequest) { return asyncExecutor.execute(new Callable<Map<String, List<T>>>() { @Override public Map<String, List<T>> call() throws Exception { return dbExecutor.batchGetItem(targetClass, batchGetItemRequest); } }); }
@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); }
/** * 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); } }
@SuppressWarnings("rawtypes") public Map<String, List<Map<String, Object>>> batchGetItem(final BatchGetItemRequest batchGetItemRequest) { return (Map) batchGetItem(Map.class, batchGetItemRequest); }
public <T> Map<String, List<T>> batchGetItem(final Class<T> targetClass, final BatchGetItemRequest batchGetItemRequest) { return toEntities(targetClass, dynamoDB.batchGetItem(batchGetItemRequest).getResponses()); }