org.mongodb.morphia.query.Query.getCollection()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.7k)|赞(0)|评价(0)|浏览(150)

本文整理了Java中org.mongodb.morphia.query.Query.getCollection方法的一些代码示例,展示了Query.getCollection的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getCollection方法的具体详情如下:
包路径:org.mongodb.morphia.query.Query
类名称:Query
方法名:getCollection

Query.getCollection介绍

暂无

代码示例

代码示例来源:origin: org.actframework/act-morphia

@Override
public DBCollection getCollection() {
  return mq.getCollection();
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

public void removeAllDocuments() {
  DBCollection LGAdapterURLs = createQuery().getCollection();
  DBCursor cursor = LGAdapterURLs.find();
  while (cursor.hasNext()) {
    LGAdapterURLs.remove(cursor.next());
  }
}

代码示例来源:origin: NationalSecurityAgency/lemongrenade

public void removeAllDocuments () {
  DBCollection lgDBValue = createQuery().getCollection();
  DBCursor cursor = lgDBValue.find();
  while (cursor.hasNext()) {
    lgDBValue.remove(cursor. next());
  }
}

代码示例来源:origin: org.mongodb.morphia/morphia

@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);
}

代码示例来源:origin: org.mongodb.morphia/morphia

@Override
public <T> WriteResult delete(final Query<T> query, final DeleteOptions options) {
  DBCollection dbColl = query.getCollection();
  // TODO remove this after testing.
  if (dbColl == null) {
    dbColl = getCollection(query.getEntityClass());
  }
  if (query.getSortObject() != null || query.getOffset() != 0 || query.getLimit() > 0) {
    throw new QueryException("Delete does not allow sort/offset/limit query options.");
  }
  return dbColl.remove(query.getQueryObject(), enforceWriteConcern(options, query.getEntityClass()).getOptions());
}

代码示例来源:origin: org.mongodb.morphia/morphia

@Override
public <T> UpdateResults update(final Query<T> query, final UpdateOperations<T> operations, final UpdateOptions options) {
  DBCollection dbColl = query.getCollection();
  // TODO remove this after testing.
  if (dbColl == null) {
    dbColl = getCollection(query.getEntityClass());
  }
  final MappedClass mc = getMapper().getMappedClass(query.getEntityClass());
  final List<MappedField> fields = mc.getFieldsAnnotatedWith(Version.class);
  DBObject queryObject = query.getQueryObject();
  if (operations.isIsolated()) {
    queryObject.put("$isolated", true);
  }
  if (!fields.isEmpty()) {
    operations.inc(fields.get(0).getNameToStore(), 1);
  }
  final BasicDBObject update = (BasicDBObject) ((UpdateOpsImpl) operations).getOps();
  if (LOG.isTraceEnabled()) {
    LOG.trace(format("Executing update(%s) for query: %s, ops: %s, multi: %s, upsert: %s",
             dbColl.getName(), queryObject, update, options.isMulti(), options.isUpsert()));
  }
  return new UpdateResults(dbColl.update(queryObject, update,
                      enforceWriteConcern(options, query.getEntityClass())
                        .getOptions()));
}

代码示例来源:origin: org.mongodb.morphia/morphia

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

代码示例来源:origin: org.mongodb.morphia/morphia

@SuppressWarnings("unchecked")
private <T> UpdateResults update(final Query<T> query, final DBObject update, final UpdateOptions options) {
  DBCollection dbColl = query.getCollection();

代码示例来源:origin: org.mongodb.morphia/morphia

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

代码示例来源:origin: org.mongodb.morphia/morphia

@Override
public <T> T findAndModify(final Query<T> query, final UpdateOperations<T> operations, final FindAndModifyOptions options) {
  DBCollection dbColl = query.getCollection();
  // TODO remove this after testing.
  if (dbColl == null) {
    dbColl = getCollection(query.getEntityClass());
  }
  if (LOG.isTraceEnabled()) {
    LOG.info("Executing findAndModify(" + dbColl.getName() + ") with update ");
  }
  updateForVersioning(query, operations);
  DBObject res = dbColl.findAndModify(query.getQueryObject(), options.copy()
                                    .sort(query.getSortObject())
                                    .projection(query.getFieldsObject())
                                    .update(((UpdateOpsImpl<T>) operations).getOps())
                    .getOptions());
  return res == null ? null : mapper.fromDBObject(this, query.getEntityClass(), res, createCache());
}

代码示例来源:origin: org.mongodb.morphia/morphia

@Override
public <T> T findAndDelete(final Query<T> query, final FindAndModifyOptions options) {
  DBCollection dbColl = query.getCollection();
  if (dbColl == null) {
    dbColl = getCollection(query.getEntityClass());
  }
  if (LOG.isTraceEnabled()) {
    LOG.trace("Executing findAndModify(" + dbColl.getName() + ") with delete ...");
  }
  FindAndModifyOptions copy = enforceWriteConcern(options, query.getEntityClass())
    .copy()
    .projection(query.getFieldsObject())
    .sort(query.getSortObject())
    .returnNew(false)
    .upsert(false)
    .remove(true);
  final DBObject result = dbColl.findAndModify(query.getQueryObject(), copy.getOptions());
  return result == null ? null : mapper.fromDBObject(this, query.getEntityClass(), result, createCache());
}

代码示例来源:origin: org.mongodb.morphia/morphia

final DBCollection dbColl = query.getCollection();

相关文章