Search in sources :

Example 1 with OutputType

use of com.mongodb.MapReduceCommand.OutputType 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)

Aggregations

DBCollection (com.mongodb.DBCollection)1 MapReduceCommand (com.mongodb.MapReduceCommand)1 OutputType (com.mongodb.MapReduceCommand.OutputType)1 EntityCache (org.mongodb.morphia.mapping.cache.EntityCache)1 QueryException (org.mongodb.morphia.query.QueryException)1