Examples of toDBObject()


Examples of org.mongodb.morphia.mapping.Mapper.toDBObject()

        DBObject dbObject = mapper.toDBObject(user);
        Object object = mapper.fromDBObject(User.class, dbObject, new DefaultEntityCache());
        Assert.assertEquals(user.userObject, ((User) object).userObject);
       
        user.userObject = 33;
        dbObject = mapper.toDBObject(user);
        object = mapper.fromDBObject(User.class, dbObject, new DefaultEntityCache());
        Assert.assertEquals(user.userObject, ((User) object).userObject);

        user.userObject = 33.3;
        dbObject = mapper.toDBObject(user);
View Full Code Here

Examples of org.mongodb.morphia.mapping.Mapper.toDBObject()

        dbObject = mapper.toDBObject(user);
        object = mapper.fromDBObject(User.class, dbObject, new DefaultEntityCache());
        Assert.assertEquals(user.userObject, ((User) object).userObject);

        user.userObject = 33.3;
        dbObject = mapper.toDBObject(user);
        object = mapper.fromDBObject(User.class, dbObject, new DefaultEntityCache());
        Assert.assertEquals(user.userObject, ((User) object).userObject);
    }

    @Test
View Full Code Here

Examples of org.mongodb.morphia.mapping.Mapper.toDBObject()

        User user = new User();
        user.id = 1;
        user.userObject = new SerializableObject();

        // when
        DBObject dbObject = mapper.toDBObject(user);
        User object = mapper.fromDBObject(User.class, dbObject, new DefaultEntityCache());

        // then
        assertThat(object.userObject, is(user.userObject));
    }
View Full Code Here

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

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

      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

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

              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

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

  @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

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

  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

Examples of org.springframework.data.mongodb.core.aggregation.ProjectionOperation.ProjectionOperationBuilder.toDBObject()

  public void arithmenticProjectionOperationWithoutAlias() {

    String fieldName = "a";
    ProjectionOperationBuilder operation = new ProjectionOperation().and(fieldName).plus(1);
    DBObject dbObject = operation.toDBObject(Aggregation.DEFAULT_CONTEXT);
    DBObject projectClause = DBObjectTestUtils.getAsDBObject(dbObject, PROJECT);
    DBObject oper = exctractOperation(fieldName, projectClause);

    assertThat(oper.containsField(ADD), is(true));
    assertThat(oper.get(ADD), is((Object) Arrays.<Object> asList("$a", 1)));
View Full Code Here

Examples of org.springframework.data.mongodb.core.query.NearQuery.toDBObject()

    NearQuery query = NearQuery.near(10.0, 10.0);
    GeoNearOperation operation = new GeoNearOperation(query);
    DBObject dbObject = operation.toDBObject(Aggregation.DEFAULT_CONTEXT);

    DBObject nearClause = DBObjectTestUtils.getAsDBObject(dbObject, "$geoNear");
    assertThat(nearClause, is(query.toDBObject()));
  }
}
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.