Example usage for org.springframework.data.repository.query.parser PartTree getSort

List of usage examples for org.springframework.data.repository.query.parser PartTree getSort

Introduction

In this page you can find the example usage for org.springframework.data.repository.query.parser PartTree getSort.

Prototype

public Sort getSort() 

Source Link

Document

Returns the Sort specification parsed from the source.

Usage

From source file:org.springframework.data.mongodb.repository.support.IndexEnsuringQueryCreationListener.java

public void onCreation(PartTreeMongoQuery query) {

    PartTree tree = query.getTree();
    Index index = new Index();
    index.named(query.getQueryMethod().getName());
    Sort sort = tree.getSort();

    for (Part part : tree.getParts()) {
        if (GEOSPATIAL_TYPES.contains(part.getType())) {
            return;
        }// ww w.j  a va 2  s  .c  om
        String property = part.getProperty().toDotPath();
        Order order = toOrder(sort, property);
        index.on(property, order);
    }

    // Add fixed sorting criteria to index
    if (sort != null) {
        for (Sort.Order order : sort) {
            index.on(order.getProperty(), QueryUtils.toOrder(order));
        }
    }

    MongoEntityInformation<?, ?> metadata = query.getQueryMethod().getEntityInformation();
    operations.indexOps(metadata.getCollectionName()).ensureIndex(index);
    LOG.debug(String.format("Created %s!", index));
}