List of usage examples for com.amazonaws.services.dynamodbv2.model KeysAndAttributes setAttributesToGet
public void setAttributesToGet(java.util.Collection<String> attributesToGet)
This is a legacy parameter.
From source file:com.erudika.para.persistence.AWSDynamoDAO.java
License:Apache License
@Override public <P extends ParaObject> Map<String, P> readAll(String appid, List<String> keys, boolean getAllColumns) { if (keys == null || keys.isEmpty() || StringUtils.isBlank(appid)) { return new LinkedHashMap<String, P>(); }/*from w ww . j av a2s . c om*/ // DynamoDB doesn't allow duplicate keys in batch requests Set<String> keySet = new TreeSet<String>(keys); if (keySet.size() < keys.size() && !keySet.isEmpty()) { logger.debug("Duplicate keys found - readAll({})", keys); } Map<String, P> results = new LinkedHashMap<String, P>(keySet.size(), 0.75f, true); ArrayList<Map<String, AttributeValue>> keyz = new ArrayList<Map<String, AttributeValue>>(MAX_KEYS_PER_READ); try { int batchSteps = 1; if ((keySet.size() > MAX_KEYS_PER_READ)) { batchSteps = (keySet.size() / MAX_KEYS_PER_READ) + ((keySet.size() % MAX_KEYS_PER_READ > 0) ? 1 : 0); } Iterator<String> it = keySet.iterator(); int j = 0; for (int i = 0; i < batchSteps; i++) { while (it.hasNext() && j < MAX_KEYS_PER_READ) { String key = it.next(); results.put(key, null); keyz.add(Collections.singletonMap(Config._KEY, new AttributeValue(getKeyForAppid(key, appid)))); j++; } KeysAndAttributes kna = new KeysAndAttributes().withKeys(keyz); if (!getAllColumns) { kna.setAttributesToGet(Arrays.asList(Config._KEY, Config._TYPE)); } batchGet(Collections.singletonMap(getTableNameForAppid(appid), kna), results); keyz.clear(); j = 0; } logger.debug("DAO.readAll({}) {}", keySet, results.size()); } catch (Exception e) { logger.error("Failed to readAll({}), {}", keys, e); } return results; }