Package org.nutz.mongo.entity

Examples of org.nutz.mongo.entity.MongoEntity.toDBObject()


        return val;
      }
      if (eleType.isAssignableFrom(val.getClass())) {
        MongoEntity en = Mongos.entity(eleType);
        if (en instanceof StaticMongoEntity)
          return en.toDBObject(val);
        return Mongos.obj2dbo(val);
      }
      // 否则 ...
      if (!check)
        return val;
View Full Code Here


      Object ele = Array.get(val, i);
      // 如果是POJO或者容器
      if (Mirror.me(ele.getClass()).isObj()) {
        if (field.isRef()) {
          MongoEntity en = Mongos.entity(val.getClass().getComponentType());
          DBObject dbo = en.toDBObject(ele);
          if (dbo.containsField("_id")) {
            array[i] = new DBRef(null, en.getCollectionName(null), dbo.get("_id"));
            continue;
          } else {
            if (log.isWarnEnabled())
View Full Code Here

              log.warn("!!obj without _id but using as ref field value!! fallback to embed doc!!");
          }
        } else {
          MongoEntity en = Mongos.entity(val.getClass().getComponentType());
          if (en instanceof StaticMongoEntity)
            array[i] = en.toDBObject(ele);
          else
            array[i] = Mongos.obj2dbo(ele);
        }
      }
      // 否则直接设置
View Full Code Here

  @Override
  public Object adaptForGet(Object val, boolean check) {
    if (val == null)
      return null;
    MongoEntity en = Mongos.entity(val);
    DBObject dbo = en.toDBObject(val);
    if (!field.isRef())
      return dbo;

    if (!dbo.containsField("_id")) {
      if (log.isWarnEnabled())
View Full Code Here

  public <T extends Object> T save(T obj) {
    MongoEntity moe = Mongos.entity(obj);
    String collName = moe.getCollectionName(obj);
    if (db.collectionExists(collName)) {
      moe.fillIdIfNoexits(obj);
      DBObject dbo = moe.toDBObject(obj);
      DBCollection coll = db.getCollection(collName);
      coll.save(dbo);
      return obj;
    }
    return null;
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.