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

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

Introduction

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

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:com.seajas.search.profiler.service.repository.RepositoryService.java

/**
 * Retrieve a paged list of all resources within the repository.
 *
 * @param collection/*from ww w  .j  a  v a2 s . co  m*/
 * @param sourceId
 * @param taxonomyMatch
 * @param startDate
 * @param endDate
 * @param pagerStart
 * @param pagerResults
 * @param parameters
 * @return RepositoryResult
 */
public RepositoryResult findResources(final String collection, final Integer sourceId,
        final String taxonomyMatch, final Date startDate, final Date endDate, final Integer pagerStart,
        final Integer pagerResults, final Map<String, String> parameters) {
    Query query = createQuery(false, collection, sourceId, taxonomyMatch, startDate, endDate, null, parameters);

    query.with(new Sort(Sort.Direction.DESC, "originalContent.dateSubmitted"));

    if (logger.isInfoEnabled())
        logger.info("About to count the number of results - which can potentially take a while - query = "
                + query.toString());

    // First perform a count

    Long totalResults = mongoTemplate.count(query, defaultCollection);

    if (logger.isInfoEnabled())
        logger.info("Counted " + totalResults + " result(s) to be retrieved from the storage back-end");

    // Then add paging parameters to the query

    query.skip(pagerStart);
    query.limit(pagerResults);

    // And build up the result

    List<RepositoryResource> results = new ArrayList<RepositoryResource>(pagerResults);
    List<CompositeEntry> entries = mongoTemplate.find(query, CompositeEntry.class, defaultCollection);

    for (CompositeEntry entry : entries)
        results.add(new RepositoryResource(entry.getOriginalContent().getUri().toString(),
                entry.getSource().getCollection(), entry.getSource().getId(),
                entry.getOriginalContent().getHostname(), entry.getOriginalContent().getDateSubmitted(),
                entry.getId().toString()));

    return new RepositoryResult(pagerStart, pagerResults, totalResults, results);
}