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

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

Introduction

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

Prototype

public Streamable<Part> getParts() 

Source Link

Document

Returns an Iterable of all parts contained in the PartTree .

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();/*  ww  w.jav  a  2 s . c  o m*/

    for (Part part : tree.getParts()) {
        if (GEOSPATIAL_TYPES.contains(part.getType())) {
            return;
        }
        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));
}