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;
}
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;
}
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;
}
Aggregations