Example usage for org.springframework.data.mongodb.core.query Query with

List of usage examples for org.springframework.data.mongodb.core.query Query with

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.query Query with.

Prototype

public Query with(Sort sort) 

Source Link

Document

Adds a Sort to the Query instance.

Usage

From source file:com.trenako.repositories.mongo.RollingStockQueryBuilder.java

/**
 * Builds a new query applying the range request to the
 * provided selection criteria.//  www. j a  va  2  s  .  c  om
 *
 * @param criteria the selection {@code Criteria}
 * @param range    the range information
 * @return a {@code Query}
 */
public static Query buildQuery(Criteria criteria, RangeRequest range) {
    String prop = range.getSortProperty();

    if (range.getSince() != null && range.getMax() != null) {
        criteria.and(prop).lt(range.getSince()).gt(range.getMax());
    } else if (range.getSince() != null) {
        criteria.and(prop).lt(range.getSince());
    } else if (range.getMax() != null) {
        criteria.and(prop).gt(range.getMax());
    }

    final Query q = query(criteria);
    q.limit(range.getSize() + 1);
    q.with(range.getSort());

    return q;
}

From source file:com.card.loop.xyz.dao.OldLODAO.java

public List<OldLO> getAllDownloadableLO() throws UnknownHostException {
    Query query = new Query();
    query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "dateUploaded")));
    return (mongoOps.find(query(where("rating").is(5)), OldLO.class));
}

From source file:io.gravitee.repository.mongodb.management.internal.page.PageMongoRepositoryImpl.java

public int findMaxPageOrderByApi(String apiId) {
    Query query = new Query();
    query.limit(1);/* w ww  .  ja va  2s  . c o m*/
    query.with(new Sort(Sort.Direction.DESC, "order"));
    query.addCriteria(Criteria.where("api").is(apiId));

    PageMongo page = mongoTemplate.findOne(query, PageMongo.class);
    return (page != null) ? page.getOrder() : 0;
}

From source file:com.github.camellabs.iot.cloudlet.webcam.service.DefaultWebcamService.java

@Override
public WebcamImage latestImage(String deviceId, String webcamName) {
    Query query = new Query();
    query.limit(1);/*from ww  w.j  a  v  a  2s. c  o m*/
    query.with(new Sort(Sort.Direction.DESC, "timestamp"));
    query.addCriteria(where("deleted").is(null)).addCriteria(where("deviceId").is(deviceId));
    return mongoTemplate.findOne(query, WebcamImage.class);
}

From source file:com.github.carlomicieli.nerdmovies.services.MongoMovieService.java

public List<Movie> getRecentMovies(int numOfMovies) {
    Query query = new Query().limit(numOfMovies);
    query.with(new Sort(Sort.Direction.DESC, "savedAt"));
    return mongoTemplate.find(query, Movie.class);
}

From source file:strat.mining.multipool.stats.persistence.dao.coinshift.impl.GlobalStatsDAOMongo.java

@Override
public GlobalStats getLastGlobalStats() {
    Query query = new Query();
    query.with(new Sort(Sort.Direction.DESC, "refreshTime"));
    return mongoOperation.findOne(query, GlobalStats.class);
}

From source file:strat.mining.multipool.stats.persistence.dao.coinshift.impl.GlobalStatsDAOMongo.java

@Override
public List<GlobalStats> getAllGlobalStats() {
    Query query = new Query();
    query.with(new Sort(Sort.Direction.ASC, "refreshTime"));
    return mongoOperation.find(query, GlobalStats.class);
}

From source file:com.trenako.repositories.mongo.BrowseRepositoryImpl.java

private <T> Iterable<T> findAll(Class<T> clazz) {
    Query query = new Query();
    query.with(NAME_SORT);
    return mongo.find(query, clazz);
}

From source file:strat.mining.multipool.stats.persistence.dao.coinshift.impl.TransactionDAOMongo.java

@Override
public List<Transaction> getAllTransactions(Integer addressId) {
    Query query = new Query(Criteria.where("addressId").is(addressId));
    query.with(new Sort(Sort.Direction.ASC, "date"));
    return mongoOperation.find(query, Transaction.class);
}

From source file:strat.mining.multipool.stats.persistence.dao.coinshift.impl.TransactionDAOMongo.java

@Override
public Transaction getLastTransaction(Integer addressId) {
    Query query = new Query(Criteria.where("addressId").is(addressId));
    query.with(new Sort(Sort.Direction.DESC, "date"));
    return mongoOperation.findOne(query, Transaction.class);
}