List of usage examples for com.amazonaws.services.dynamodbv2.model ReturnConsumedCapacity TOTAL
ReturnConsumedCapacity TOTAL
To view the source code for com.amazonaws.services.dynamodbv2.model ReturnConsumedCapacity TOTAL.
Click Source Link
From source file:amazon.dynamodb.config.DynamoDBManager.java
License:Open Source License
/** * Query Amazon DynamoDB//from w w w. java2s . com * * @param hashKey Hash key for the query request. * * @param range The range of geohashs to query. * * @return The query result. */ public List<QueryResult> queryGeohash(QueryRequest queryRequest, long hashKey, GeoHashRango range) { List<QueryResult> queryResults = new ArrayList<QueryResult>(); Map<String, AttributeValue> lastEvaluatedKey = null; do { Map<String, Condition> keyConditions = new HashMap<String, Condition>(); Condition hashKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withN(String.valueOf(hashKey))); keyConditions.put(config.getHashKeyAttributeName(), hashKeyCondition); AttributeValue minRange = new AttributeValue().withN(Long.toString(range.getRangeMin())); AttributeValue maxRange = new AttributeValue().withN(Long.toString(range.getRangeMax())); Condition geohashCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN) .withAttributeValueList(minRange, maxRange); keyConditions.put(config.getGeohashAttributeName(), geohashCondition); queryRequest.withTableName(config.getTableName()).withKeyConditions(keyConditions) .withIndexName(config.getGeohashIndexName()).withConsistentRead(true) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL) .withExclusiveStartKey(lastEvaluatedKey); QueryResult queryResult = config.getDynamoDBClient().query(queryRequest); queryResults.add(queryResult); lastEvaluatedKey = queryResult.getLastEvaluatedKey(); } while (lastEvaluatedKey != null); return queryResults; }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.AbstractDynamoDbStore.java
License:Open Source License
protected UpdateItemRequest createUpdateItemRequest() { return new UpdateItemRequest().withTableName(tableName) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.AbstractDynamoDbStore.java
License:Open Source License
protected GetItemRequest createGetItemRequest() { return new GetItemRequest().withTableName(tableName).withConsistentRead(forceConsistentRead) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.AbstractDynamoDbStore.java
License:Open Source License
protected DeleteItemRequest createDeleteItemRequest() { return new DeleteItemRequest().withTableName(tableName) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.AbstractDynamoDbStore.java
License:Open Source License
protected QueryRequest createQueryRequest() { return new QueryRequest().withTableName(tableName).withConsistentRead(forceConsistentRead) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); }
From source file:com.amazon.janusgraph.diskstorage.dynamodb.AbstractDynamoDbStore.java
License:Open Source License
protected ScanRequest createScanRequest() { return new ScanRequest().withTableName(tableName).withConsistentRead(forceConsistentRead) .withLimit(client.scanLimit(tableName)).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); }
From source file:com.erudika.para.persistence.AWSDynamoDAO.java
License:Apache License
private <P extends ParaObject> String readPageFromTable(String appid, Pager pager, LinkedList<P> results) { ScanRequest scanRequest = new ScanRequest().withTableName(getTableNameForAppid(appid)) .withLimit(pager.getLimit()).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); if (!StringUtils.isBlank(pager.getLastKey())) { scanRequest = scanRequest.withExclusiveStartKey( Collections.singletonMap(Config._KEY, new AttributeValue(pager.getLastKey()))); }//from w w w . ja v a2 s . c o m ScanResult result = client().scan(scanRequest); for (Map<String, AttributeValue> item : result.getItems()) { P obj = fromRow(item); if (obj != null) { results.add(obj); } } if (result.getLastEvaluatedKey() != null) { return result.getLastEvaluatedKey().get(Config._KEY).getS(); } else { return null; } }
From source file:com.erudika.para.persistence.AWSDynamoDAO.java
License:Apache License
private <P extends ParaObject> void batchGet(Map<String, KeysAndAttributes> kna, Map<String, P> results) { if (kna == null || kna.isEmpty() || results == null) { return;// w w w . j a va 2 s. c o m } try { BatchGetItemResult result = client().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 {}", result.getUnprocessedKeys().size()); batchGet(result.getUnprocessedKeys(), results); } } catch (Exception e) { logger.error(null, e); } }
From source file:com.erudika.para.persistence.AWSDynamoDAO.java
License:Apache License
private void batchWrite(Map<String, List<WriteRequest>> items) { if (items == null || items.isEmpty()) { return;/*from w w w .j av a 2 s. co m*/ } try { BatchWriteItemResult result = client().batchWriteItem(new BatchWriteItemRequest() .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL).withRequestItems(items)); if (result == null) { return; } logger.debug("batchWrite(): total {}, cc {}", items.size(), result.getConsumedCapacity()); if (result.getUnprocessedItems() != null && !result.getUnprocessedItems().isEmpty()) { Thread.sleep(1000); logger.warn("UNPROCESSED {0}", result.getUnprocessedItems().size()); batchWrite(result.getUnprocessedItems()); } } catch (Exception e) { logger.error(null, e); } }
From source file:com.grublr.geo.dynamodb.internal.DynamoDBManager.java
License:Open Source License
/** * Query Amazon DynamoDB/*from w w w .ja v a 2 s. com*/ * * @param hashKey * Hash key for the query request. * * @param range * The range of geohashs to query. * * @return The query result. */ public List<QueryResult> queryGeohash(QueryRequest queryRequest, long hashKey, GeohashRange range) { List<QueryResult> queryResults = new ArrayList<QueryResult>(); Map<String, AttributeValue> lastEvaluatedKey = null; do { Map<String, Condition> keyConditions = new HashMap<String, Condition>(); Condition hashKeyCondition = new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withN(String.valueOf(hashKey))); keyConditions.put(config.getHashKeyAttributeName(), hashKeyCondition); AttributeValue minRange = new AttributeValue().withN(Long.toString(range.getRangeMin())); AttributeValue maxRange = new AttributeValue().withN(Long.toString(range.getRangeMax())); Condition geohashCondition = new Condition().withComparisonOperator(ComparisonOperator.BETWEEN) .withAttributeValueList(minRange, maxRange); keyConditions.put(config.getGeohashAttributeName(), geohashCondition); queryRequest.withTableName(config.getTableName()).withKeyConditions(keyConditions) .withIndexName(config.getGeohashIndexName()).withConsistentRead(true) .withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL) .withExclusiveStartKey(lastEvaluatedKey); QueryResult queryResult = config.getDynamoDBClient().query(queryRequest); queryResults.add(queryResult); lastEvaluatedKey = queryResult.getLastEvaluatedKey(); } while (lastEvaluatedKey != null); return queryResults; }