本文整理汇总了Java中com.mongodb.MapReduceCommand.setFinalize方法的典型用法代码示例。如果您正苦于以下问题:Java MapReduceCommand.setFinalize方法的具体用法?Java MapReduceCommand.setFinalize怎么用?Java MapReduceCommand.setFinalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mongodb.MapReduceCommand
的用法示例。
在下文中一共展示了MapReduceCommand.setFinalize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mapReduce
import com.mongodb.MapReduceCommand; //导入方法依赖的package包/类
/**
* runs a map-reduce-job on the collection. The functions are read from the classpath in the folder mongodb. The systems reads them from
* files called <name>.map.js, <name>.reduce.js and optionally <name>.finalize.js. After this the result is converted
* using the given {@link MapReduceResultHandler}
*
* @param <R> the type of the result class
* @param name the name of the map-reduce functions
* @param query the query to filter the elements used for the map-reduce
* @param sort sort query to sort elements before running map-reduce
* @param scope the global scope for the JavaScript run
* @param conv the converter to convert the result
* @return an {@link Iterable} with the result entries
* @throws RuntimeException if resources cannot be read
*/
protected final <R> Iterable<R> mapReduce(String name, DBObject query, DBObject sort, Map<String, Object> scope, final MapReduceResultHandler<R> conv) {
String map = this.getMRFunction(name, "map");
String reduce = this.getMRFunction(name, "reduce");
MapReduceCommand mrc = new MapReduceCommand(this.collection.getDBCollection(), map, reduce, null, OutputType.INLINE, query);
String finalizeFunction = this.getMRFunction(name, "finalize");
if (finalizeFunction != null) {
mrc.setFinalize(finalizeFunction);
}
if (sort != null) {
mrc.setSort(sort);
}
if (scope != null) {
mrc.setScope(scope);
}
MapReduceOutput mr = this.collection.getDBCollection().mapReduce(mrc);
return new ConverterIterable<R>(mr.results().iterator(), conv);
}
示例2: toCommand
import com.mongodb.MapReduceCommand; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
MapReduceCommand toCommand(final Mapper mapper) {
if (query.getOffset() != 0 || query.getFieldsObject() != null) {
throw new QueryException("mapReduce does not allow the offset/retrievedFields query ");
}
final DBCollection dbColl = inputCollection != null ? getQuery().getCollection().getDB().getCollection(inputCollection)
: query.getCollection();
final String target = outputCollection != null ? outputCollection : mapper.getMappedClass(resultType).getCollectionName();
final MapReduceCommand command = new MapReduceCommand(dbColl, map, reduce, target, outputType, query.getQueryObject());
command.setBypassDocumentValidation(bypassDocumentValidation);
command.setCollation(collation);
command.setFinalize(finalize);
command.setJsMode(jsMode);
command.setLimit(limit);
command.setMaxTime(maxTimeMS, TimeUnit.MILLISECONDS);
command.setOutputDB(outputDB);
command.setReadPreference(readPreference);
command.setScope(scope);
command.setSort(query.getSortObject());
command.setVerbose(verbose);
return command;
}
示例3: mapReduce
import com.mongodb.MapReduceCommand; //导入方法依赖的package包/类
@Override
@Deprecated
public <T> MapreduceResults<T> mapReduce(final MapreduceType type, final Query query, final String map, final String reduce,
final String finalize, final Map<String, Object> scopeFields, final Class<T> outputType) {
final DBCollection dbColl = query.getCollection();
final String outColl = mapper.getCollectionName(outputType);
final MapReduceCommand cmd = new MapReduceCommand(dbColl, map, reduce, outColl, type.toOutputType(), query.getQueryObject());
if (query.getLimit() > 0) {
cmd.setLimit(query.getLimit());
}
if (query.getSortObject() != null) {
cmd.setSort(query.getSortObject());
}
if (finalize != null && finalize.length() != 0) {
cmd.setFinalize(finalize);
}
if (scopeFields != null && !scopeFields.isEmpty()) {
cmd.setScope(scopeFields);
}
return mapReduce(type, query, outputType, cmd);
}