List of usage examples for com.amazonaws.services.dynamodbv2.model QueryRequest setKeyConditions
public void setKeyConditions(java.util.Map<String, Condition> keyConditions)
This is a legacy parameter.
From source file:com.makariev.dynamodb.preferences.UserPreferenceLowLevelAPIService.java
License:Open Source License
@Override public List<UserPreference> queryByFirstName(String firstName, String lastName) { QueryRequest queryRequest = new QueryRequest().withTableName(UserPreference.TABLE_NAME) .withIndexName(UserPreference.NAME_INDEX).withSelect("ALL_ATTRIBUTES").withScanIndexForward(true); final HashMap<String, Condition> keyConditions = new HashMap<>(); //ComparisonOperator.CONTAINS) cannot be used with indexes ( no query, only scan ) keyConditions.put("firstName", new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(firstName))); keyConditions.put("lastName", new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(lastName))); queryRequest.setKeyConditions(keyConditions); QueryResult result = dynamoDb.query(queryRequest); List<Map<String, AttributeValue>> items = result.getItems(); return toUserPreferenceList(items); }
From source file:com.makariev.dynamodb.preferences.UserPreferenceObjectMapperService.java
License:Open Source License
private List<UserPreference> queryByFirstAndLastNameMixedLevel(String firstName, String lastName) { QueryRequest queryRequest = new QueryRequest().withTableName(UserPreference.TABLE_NAME) .withIndexName(UserPreference.NAME_INDEX).withSelect("ALL_ATTRIBUTES").withScanIndexForward(true); final HashMap<String, Condition> keyConditions = new HashMap<>(); //ComparisonOperator.CONTAINS) cannot be used with indexes ( no query, only scan ) keyConditions.put("firstName", new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(firstName))); keyConditions.put("lastName", new Condition().withComparisonOperator(ComparisonOperator.EQ) .withAttributeValueList(new AttributeValue().withS(lastName))); queryRequest.setKeyConditions(keyConditions); final QueryResult result = dynamoDb.query(queryRequest); final List<Map<String, AttributeValue>> items = result.getItems(); final List<UserPreference> list = mapper.marshallIntoObjects(UserPreference.class, items); return list;/*from w w w . j ava 2s .com*/ }
From source file:org.iternine.jeppetto.dao.dynamodb.DynamoDBQueryModelDAO.java
License:Apache License
private Iterable<T> queryItems(QueryModel queryModel, ConditionExpressionBuilder conditionExpressionBuilder) { QueryRequest queryRequest = new QueryRequest(tableName); queryRequest.setKeyConditions(conditionExpressionBuilder.getKeyConditions()); queryRequest.setConsistentRead(consistentRead); if (queryModel.getFirstResult() > 0) { logger.warn(//from w w w . j ava 2 s .co m "DynamoDB does not support skipping results. Call setPosition() on DynamoDBIterable instead."); } if (queryModel.getMaxResults() > 0) { queryRequest.setLimit(queryModel.getMaxResults()); } List<String> keyFields = applyIndexAndGetKeyFields(conditionExpressionBuilder, queryRequest, queryModel.getSorts()); applyExpressions(conditionExpressionBuilder, queryRequest); return new QueryIterable<T>(dynamoDB, persistableEnhancer, queryRequest, keyFields.get(0), keyFields); }
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()); }/*from w w w. ja v a 2 s.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; }