Example usage for org.springframework.data.mongodb.core.index Index named

List of usage examples for org.springframework.data.mongodb.core.index Index named

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.index Index named.

Prototype

public Index named(String name) 

Source Link

Usage

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

public void onCreation(PartTreeMongoQuery query) {

    PartTree tree = query.getTree();//from  w  w w  .  j  ava  2s  .c o  m
    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;
        }
        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));
}