Example usage for com.amazonaws.services.dynamodbv2.model QueryRequest setSelect

List of usage examples for com.amazonaws.services.dynamodbv2.model QueryRequest setSelect

Introduction

In this page you can find the example usage for com.amazonaws.services.dynamodbv2.model QueryRequest setSelect.

Prototype


public void setSelect(Select select) 

Source Link

Document

The attributes to be returned in the result.

Usage

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  ww  .j a va  2s  .  co  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;
}