Example usage for com.mongodb DBCursor setDecoderFactory

List of usage examples for com.mongodb DBCursor setDecoderFactory

Introduction

In this page you can find the example usage for com.mongodb DBCursor setDecoderFactory.

Prototype

public DBCursor setDecoderFactory(final DBDecoderFactory factory) 

Source Link

Document

Sets the factory that will be used create a DBDecoder that will be used to decode BSON documents into DBObject instances.

Usage

From source file:org.envirocar.server.mongo.dao.MongoMeasurementDao.java

License:Open Source License

private Measurements query(DBObject query, Pagination p) {
    final Mapper mapper = this.mongoDB.getMapper();
    final Datastore ds = this.mongoDB.getDatastore();
    final DBCollection coll = ds.getCollection(MongoMeasurement.class);

    DBCursor cursor = coll.find(query, null);
    long count = 0;

    cursor.setDecoderFactory(ds.getDecoderFact());
    if (p != null) {
        count = coll.count(query);/* ww  w .j a  v  a2 s. c  om*/
        if (p.getOffset() > 0) {
            cursor.skip(p.getOffset());
        }
        if (p.getLimit() > 0) {
            cursor.limit(p.getLimit());
        }
    }
    cursor.sort(QueryImpl.parseFieldsString(MongoMeasurement.TIME, MongoMeasurement.class, mapper, true));
    Iterable<MongoMeasurement> i = new MorphiaIterator<MongoMeasurement, MongoMeasurement>(cursor, mapper,
            MongoMeasurement.class, coll.getName(), mapper.createEntityCache());
    return createPaginatedIterable(i, p, count);
}