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

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

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

Query.getQueryObject介绍

暂无

代码示例

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

@Override
public DBObject getQueryObject() {
  return mq.getQueryObject();
}

代码示例来源:origin: BlackLabs/play-morphia

public DBObject getQueryObject() {
  return q_.getQueryObject();
}

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

@Override
public AggregationPipeline match(final Query query) {
  stages.add(new BasicDBObject("$match", query.getQueryObject()));
  return this;
}

代码示例来源:origin: stackoverflow.com

DB db = mongoTemplate.getDb();
DBCollection collection = db.getCollection(collectionName);
DBObject query = upsertQuery.getQueryObject();
DBObject update = new BasicDBObject("$set", JSON.parse(jsonStr));
collection.update(query, update, true, false);

代码示例来源:origin: BlackLabs/play-morphia

public Map<String, Long> cloud(String field) {
  field = MorphiaPlugin.mongoColName(c_, field);
  String map = String.format("function() {if (!this.%1$s) return; for (index in this.%1$s) emit(this.%1$s[index], 1);}", field);
  String reduce = "function(previous, current) {var count = 0; for (index in current) count += current[index]; return count;}";
  MapReduceCommand cmd = new MapReduceCommand(col(), map, reduce, null, MapReduceCommand.OutputType.INLINE, q_.getQueryObject());
  MapReduceOutput out = col().mapReduce(cmd);
  Map<String, Long> m = new HashMap<String, Long>();
  for (Iterator<DBObject> itr = out.results().iterator(); itr.hasNext(); ) {
    DBObject dbo = itr.next();
    m.put((String) dbo.get("_id"), ((Double) dbo.get("value")).longValue());
  }
  return m;
}

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

@SuppressWarnings("unchecked")
public <T> List<T> distinct(MorphiaQuery q, String field) {
  return collection().distinct(field, q.morphiaQuery().getQueryObject());
}

代码示例来源:origin: BlackLabs/play-morphia

/**
 *
 * @param groupKeys
 *            could be either "f1Andf2.." or "f1 f2" or "f1,f2"
 * @return
 */
public List<BasicDBObject> group(String groupKeys, DBObject initial,
    String reduce, String finalize) {
  DBObject key = new BasicDBObject();
  if (!S.empty(groupKeys)) {
    if (groupKeys.startsWith("by"))
      groupKeys = groupKeys.substring(2);
    String[] sa = groupKeys.split("(And|[\\s,;]+)");
    for (String s : sa) {
      key.put(MorphiaPlugin.mongoColName(c_, s), true);
    }
  }
  return (List<BasicDBObject>) ds().getCollection(c_).group(key,
      q_.getQueryObject(), initial, reduce, finalize);
}

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

private List<BasicDBObject> group(String groupKeys, DBObject initial,
                 String reduce, String finalize) {
  DBObject key = new BasicDBObject();
  if (!S.empty(groupKeys)) {
    String[] sa = MorphiaService.splitGroupKeys(groupKeys);
    for (String s : sa) {
      key.put(s, true);
    }
  }
  return (List<BasicDBObject>) ds.getCollection(modelType).group(key, mq.getQueryObject(), initial, reduce, finalize);
}

代码示例来源: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
@SuppressWarnings("deprecation")
public AggregationPipeline geoNear(final GeoNear geoNear) {
  DBObject geo = new BasicDBObject();
  GeometryShapeConverter.PointConverter pointConverter = new GeometryShapeConverter.PointConverter();
  pointConverter.setMapper(mapper);
  putIfNull(geo, "near", geoNear.getNearAsDBObject(pointConverter));
  putIfNull(geo, "distanceField", geoNear.getDistanceField());
  putIfNull(geo, "limit", geoNear.getLimit());
  putIfNull(geo, "num", geoNear.getMaxDocuments());
  putIfNull(geo, "maxDistance", geoNear.getMaxDistance());
  if (geoNear.getQuery() != null) {
    geo.put("query", geoNear.getQuery().getQueryObject());
  }
  putIfNull(geo, "spherical", geoNear.getSpherical());
  putIfNull(geo, "distanceMultiplier", geoNear.getDistanceMultiplier());
  putIfNull(geo, "includeLocs", geoNear.getIncludeLocations());
  putIfNull(geo, "uniqueDocs", geoNear.getUniqueDocuments());
  stages.add(new BasicDBObject("$geoNear", geo));
  return this;
}

代码示例来源: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

DBObject queryObject = query.getQueryObject();

代码示例来源: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

@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

baseCommand.getOutputTarget(), outType, query.getQueryObject());
cmd.setFinalize(baseCommand.getFinalize());
cmd.setScope(baseCommand.getScope());

相关文章