Search in sources :

Example 1 with EntityCache

use of org.mongodb.morphia.mapping.cache.EntityCache in project morphia by mongodb.

the class DatastoreImpl method mapReduce.

@Override
@Deprecated
public <T> MapreduceResults<T> mapReduce(final MapreduceType type, final Query query, final Class<T> outputType, final MapReduceCommand baseCommand) {
    Assert.parametersNotNull("map", baseCommand.getMap());
    Assert.parameterNotEmpty("map", baseCommand.getMap());
    Assert.parametersNotNull("reduce", baseCommand.getReduce());
    Assert.parameterNotEmpty("reduce", baseCommand.getReduce());
    if (query.getOffset() != 0 || query.getFieldsObject() != null) {
        throw new QueryException("mapReduce does not allow the offset/retrievedFields query options.");
    }
    final OutputType outType = type.toOutputType();
    final DBCollection dbColl = query.getCollection();
    final MapReduceCommand cmd = new MapReduceCommand(dbColl, baseCommand.getMap(), baseCommand.getReduce(), baseCommand.getOutputTarget(), outType, query.getQueryObject());
    cmd.setFinalize(baseCommand.getFinalize());
    cmd.setScope(baseCommand.getScope());
    if (query.getLimit() > 0) {
        cmd.setLimit(query.getLimit());
    }
    if (query.getSortObject() != null) {
        cmd.setSort(query.getSortObject());
    }
    if (LOG.isTraceEnabled()) {
        LOG.info("Executing " + cmd.toString());
    }
    final EntityCache cache = createCache();
    MapreduceResults<T> results = new MapreduceResults<T>(dbColl.mapReduce(baseCommand));
    results.setType(type);
    if (MapreduceType.INLINE.equals(type)) {
        results.setInlineRequiredOptions(this, outputType, getMapper(), cache);
    } else {
        results.setQuery(newQuery(outputType, getDB().getCollection(results.getOutputCollectionName())));
    }
    return results;
}
Also used : DBCollection(com.mongodb.DBCollection) QueryException(org.mongodb.morphia.query.QueryException) EntityCache(org.mongodb.morphia.mapping.cache.EntityCache) MapReduceCommand(com.mongodb.MapReduceCommand) OutputType(com.mongodb.MapReduceCommand.OutputType)

Example 2 with EntityCache

use of org.mongodb.morphia.mapping.cache.EntityCache in project morphia by mongodb.

the class DatastoreImpl method mapReduce.

@Override
public <T> MapreduceResults<T> mapReduce(final MapReduceOptions<T> options) {
    DBCollection collection = options.getQuery().getCollection();
    final EntityCache cache = createCache();
    MapreduceResults<T> results = new MapreduceResults<T>(collection.mapReduce(options.toCommand(getMapper())));
    results.setOutputType(options.getOutputType());
    if (OutputType.INLINE.equals(options.getOutputType())) {
        results.setInlineRequiredOptions(this, options.getResultType(), getMapper(), cache);
    } else {
        results.setQuery(newQuery(options.getResultType(), getDB().getCollection(results.getOutputCollectionName())));
    }
    return results;
}
Also used : DBCollection(com.mongodb.DBCollection) EntityCache(org.mongodb.morphia.mapping.cache.EntityCache)

Example 3 with EntityCache

use of org.mongodb.morphia.mapping.cache.EntityCache in project morphia by mongodb.

the class TestAsListPerf method driverQueryAndMorphiaConverter.

public double driverQueryAndMorphiaConverter(final int nbOfHits) {
    final long start = System.nanoTime();
    final List<DBObject> list = getDs().getDB().getCollection("Address").find().sort(new BasicDBObject("name", 1)).toArray();
    final EntityCache entityCache = new DefaultEntityCache();
    final List<Address> resultList = new LinkedList<Address>();
    for (final DBObject dbObject : list) {
        final Address address = getMorphia().fromDBObject(getDs(), Address.class, dbObject, entityCache);
        resultList.add(address);
    }
    //ns -> ms
    final long duration = (System.nanoTime() - start) / 1000000;
    Assert.assertEquals(nbOfHits, resultList.size());
    return (double) duration / nbOfHits;
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) EntityCache(org.mongodb.morphia.mapping.cache.EntityCache) DefaultEntityCache(org.mongodb.morphia.mapping.cache.DefaultEntityCache) DefaultEntityCache(org.mongodb.morphia.mapping.cache.DefaultEntityCache) BasicDBObject(com.mongodb.BasicDBObject) DBObject(com.mongodb.DBObject) LinkedList(java.util.LinkedList)

Aggregations

EntityCache (org.mongodb.morphia.mapping.cache.EntityCache)3 DBCollection (com.mongodb.DBCollection)2 BasicDBObject (com.mongodb.BasicDBObject)1 DBObject (com.mongodb.DBObject)1 MapReduceCommand (com.mongodb.MapReduceCommand)1 OutputType (com.mongodb.MapReduceCommand.OutputType)1 LinkedList (java.util.LinkedList)1 DefaultEntityCache (org.mongodb.morphia.mapping.cache.DefaultEntityCache)1 QueryException (org.mongodb.morphia.query.QueryException)1