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

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

Introduction

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

Prototype

public long getSkip() 

Source Link

Document

Get the number of documents to skip.

Usage

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");
        }//ww w  .j  a  va2 s .  c  o m
        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   w  w  w . j a v  a 2 s . c  om
            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;
}