List of usage examples for com.amazonaws.services.dynamodbv2.model QueryRequest QueryRequest
public QueryRequest()
From source file:org.apache.hadoop.dynamodb.DynamoDBClient.java
License:Open Source License
public RetryResult<QueryResult> queryTable(String tableName, DynamoDBQueryFilter dynamoDBQueryFilter, Map<String, AttributeValue> exclusiveStartKey, long limit, Reporter reporter) { final QueryRequest queryRequest = new QueryRequest().withTableName(tableName) .withExclusiveStartKey(exclusiveStartKey).withKeyConditions(dynamoDBQueryFilter.getKeyConditions()) .withLimit(Ints.checkedCast(limit)).withReturnConsumedCapacity(ReturnConsumedCapacity.TOTAL); RetryResult<QueryResult> retryResult = getRetryDriver().runWithRetry(new Callable<QueryResult>() { @Override//from w w w.j a va2 s .c o m public QueryResult call() { log.debug("Executing DynamoDB query: " + queryRequest); return dynamoDB.query(queryRequest); } }, reporter, PrintCounter.DynamoDBReadThrottle); return retryResult; }
From source file:org.selman.tweetamo.PersistentStore.java
License:Apache License
public QueryResult getLatestTweetsForScreenName(String screenName, long timestamp) throws Exception { try {//from w ww . j a va2 s .co m long startDateMilli = System.currentTimeMillis(); Map<String, Condition> keyConditions = new HashMap<String, Condition>(); keyConditions.put(COL_SCREENNAME, new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(screenName))); keyConditions.put(COL_CREATEDAT, new Condition().withComparisonOperator(ComparisonOperator.BETWEEN).withAttributeValueList( new AttributeValue().withN(Long.toString(timestamp)), new AttributeValue().withN(Long.toString(startDateMilli)))); QueryRequest queryRequest = new QueryRequest().withTableName(TABLE_NAME).withIndexName(INDEX_SCREENNAME) .withKeyConditions(keyConditions).withSelect(Select.ALL_ATTRIBUTES).withScanIndexForward(true); QueryResult result = dynamoDB.query(queryRequest); return result; } catch (Exception e) { handleException(e); } return null; }
From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.java
License:Apache License
protected QueryRequest buildQueryRequest(String tableName, String theIndexName, String hashKeyAttributeName, String rangeKeyAttributeName, String rangeKeyPropertyName, List<Condition> hashKeyConditions, List<Condition> rangeKeyConditions) { // TODO Set other query request properties based on config QueryRequest queryRequest = new QueryRequest(); queryRequest.setTableName(tableName); queryRequest.setIndexName(theIndexName); if (isApplicableForGlobalSecondaryIndex()) { List<String> allowedSortProperties = new ArrayList<String>(); for (Entry<String, List<Condition>> singlePropertyCondition : propertyConditions.entrySet()) { if (entityInformation.getGlobalSecondaryIndexNamesByPropertyName().keySet() .contains(singlePropertyCondition.getKey())) { allowedSortProperties.add(singlePropertyCondition.getKey()); }// w w w.j ava 2s . c o m } HashMap<String, Condition> keyConditions = new HashMap<String, Condition>(); if (hashKeyConditions != null && hashKeyConditions.size() > 0) { for (Condition hashKeyCondition : hashKeyConditions) { keyConditions.put(hashKeyAttributeName, hashKeyCondition); allowedSortProperties.add(hashKeyPropertyName); } } if (rangeKeyConditions != null && rangeKeyConditions.size() > 0) { for (Condition rangeKeyCondition : rangeKeyConditions) { keyConditions.put(rangeKeyAttributeName, rangeKeyCondition); allowedSortProperties.add(rangeKeyPropertyName); } } for (Entry<String, List<Condition>> singleAttributeConditions : attributeConditions.entrySet()) { for (Condition condition : singleAttributeConditions.getValue()) { keyConditions.put(singleAttributeConditions.getKey(), condition); } } if (sort != null) { for (Order order : sort) { final String sortProperty = order.getProperty(); if (entityInformation.isGlobalIndexRangeKeyProperty(sortProperty)) { allowedSortProperties.add(sortProperty); } } } queryRequest.setKeyConditions(keyConditions); queryRequest.setSelect(Select.ALL_PROJECTED_ATTRIBUTES); applySortIfSpecified(queryRequest, new ArrayList<String>(new HashSet<String>(allowedSortProperties))); } return queryRequest; }