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

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

Introduction

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

Prototype


public void setScanIndexForward(Boolean scanIndexForward) 

Source Link

Document

Specifies the order for index traversal: If true (default), the traversal is performed in ascending order; if false, the traversal is performed in descending order.

Usage

From source file:org.iternine.jeppetto.dao.dynamodb.DynamoDBQueryModelDAO.java

License:Apache License

private List<String> applyIndexAndGetKeyFields(ConditionExpressionBuilder conditionExpressionBuilder,
        QueryRequest queryRequest, List<Sort> sorts) {
    String hashKey = conditionExpressionBuilder.getHashKey();
    String rangeKey = conditionExpressionBuilder.getRangeKey();
    IndexData indexData;/* w  w w .j ava2  s .co  m*/

    if (sorts == null || sorts.isEmpty()) {
        indexData = indexes.get(hashKey).get(rangeKey);
    } else if (sorts.size() == 1) {
        Sort sort = sorts.get(0);
        String sortKey = sort.getField();

        // DynamoDB can only sort on the effective range key.  If a range key is specified, ensure the range key and
        // sort key are the same.
        if (rangeKey != null && !rangeKey.equals(sortKey)) {
            throw new JeppettoException(
                    "DynamoDB can only sort on the effective range key. Unable to sort on: " + sortKey);
        }

        queryRequest.setScanIndexForward(sort.getSortDirection() == SortDirection.Ascending);

        // Index is based off the sort key
        indexData = indexes.get(hashKey).get(sortKey);
    } else {
        throw new JeppettoException("DynamoDB only supports one sort value.");
    }

    if (indexData.indexName != null && !indexData.projectsOverEntity) {
        logger.warn(
                "Query using index {} incurs additional costs to fully fetch a {} type. Use a projected object"
                        + " DAO to avoid this overhead.",
                indexData.indexName, entityClass.getSimpleName());
    }

    queryRequest.setIndexName(indexData.indexName);

    return indexData.keyFields;
}

From source file:org.socialsignin.spring.data.dynamodb.repository.query.AbstractDynamoDBQueryCriteria.java

License:Apache License

protected void applySortIfSpecified(QueryRequest queryRequest, List<String> permittedPropertyNames) {
    if (permittedPropertyNames.size() > 2) {
        throw new UnsupportedOperationException("Can only sort by at most a single global hash and range key");
    }//  ww  w.  j  a va2  s  .  com

    if (sort != null) {
        boolean sortAlreadySet = false;
        for (Order order : sort) {
            if (permittedPropertyNames.contains(order.getProperty())) {
                if (sortAlreadySet) {
                    throw new UnsupportedOperationException("Sorting by multiple attributes not possible");

                }
                if (queryRequest.getKeyConditions().size() > 1 && !hasIndexHashKeyEqualCondition()) {
                    throw new UnsupportedOperationException(
                            "Sorting for global index queries with criteria on both hash and range not possible");

                }
                queryRequest.setScanIndexForward(order.getDirection().equals(Direction.ASC));
                sortAlreadySet = true;
            } else {
                throw new UnsupportedOperationException(
                        "Sorting only possible by " + permittedPropertyNames + " for the criteria specified");
            }
        }
    }
}