Example usage for com.amazonaws.services.dynamodbv2.model Select ALL_PROJECTED_ATTRIBUTES

List of usage examples for com.amazonaws.services.dynamodbv2.model Select ALL_PROJECTED_ATTRIBUTES

Introduction

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

Prototype

Select ALL_PROJECTED_ATTRIBUTES

To view the source code for com.amazonaws.services.dynamodbv2.model Select ALL_PROJECTED_ATTRIBUTES.

Click Source Link

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   ww w . jav a  2s .  c  om
        }

        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;
}