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

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

Introduction

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

Prototype

public int getLimit() 

Source Link

Document

Get the maximum number of documents to be return.

Usage

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

private void assertLimit(Query query, int count) {
    assertEquals(count, query.getLimit());
}

From source file:org.springframework.data.mongodb.core.MongoTemplate.java

private DBObject copyQuery(Query query, DBObject copyMapReduceOptions) {
    if (query != null) {
        if (query.getSkip() != 0 || query.getFieldsObject() != null) {
            throw new InvalidDataAccessApiUsageException(
                    "Can not use skip or field specification with map reduce operations");
        }//from ww w  . j  a  va  2 s  . c om
        if (query.getQueryObject() != null) {
            copyMapReduceOptions.put("query", query.getQueryObject());
        }
        if (query.getLimit() > 0) {
            copyMapReduceOptions.put("limit", query.getLimit());
        }
        if (query.getSortObject() != null) {
            copyMapReduceOptions.put("sort", query.getSortObject());
        }
    }
    return copyMapReduceOptions;
}

From source file:piecework.repository.concrete.ProcessInstanceRepositoryCustomImpl.java

@Override
public Page<ProcessInstance> findByQuery(Query query, Pageable request, boolean includeTotal) {
    long start = 0;
    if (LOG.isDebugEnabled())
        start = System.currentTimeMillis();

    List<ProcessInstance> processInstances = mongoOperations.find(query.with(request), ProcessInstance.class);

    long total = 0;

    // We only need to look up a total if we're not on the first page or the page is full
    if (includeTotal) {
        if (query.getSkip() > 0 || processInstances.size() == query.getLimit())
            total = mongoOperations.count(query, ProcessInstance.class);
        else/*from ww w.  ja va 2 s . c o  m*/
            total = processInstances.size();
    }

    Page<ProcessInstance> page = new PageImpl<ProcessInstance>(processInstances, request, total);
    if (LOG.isDebugEnabled())
        LOG.debug("Retrieved instances by criteria in " + (System.currentTimeMillis() - start) + " ms");

    return page;
}