Package com.mongodb

Examples of com.mongodb.BasicDBObjectBuilder


  public void multiFieldJsonIncludeRestrictionShouldBeConsidered() {

    org.springframework.data.mongodb.core.query.Query query = deriveQueryFromMethod("findByFirstnameAndLastname",
        new Object[] { "foo", "bar" });

    assertThat(query.getFieldsObject(), is(new BasicDBObjectBuilder().add("firstname", 1).add("lastname", 1).get()));
  }
View Full Code Here


  public void multiFieldJsonExcludeRestrictionShouldBeConsidered() {

    org.springframework.data.mongodb.core.query.Query query = deriveQueryFromMethod("findPersonByFirstnameAndLastname",
        new Object[] { "foo", "bar" });

    assertThat(query.getFieldsObject(), is(new BasicDBObjectBuilder().add("firstname", 0).add("lastname", 0).get()));
  }
View Full Code Here

    if (currentVersion == null) {
      try {
        MongoClient client;
        client = new MongoClient(host, port);
        DB db = client.getDB("test");
        CommandResult result = db.command(new BasicDBObjectBuilder().add("buildInfo", 1).get());
        this.currentVersion = Version.parse(result.get("version").toString());
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
View Full Code Here

      }
    });

    ArgumentCaptor<DBObject> captor = ArgumentCaptor.forClass(DBObject.class);
    verify(cursor, times(1)).sort(captor.capture());
    assertThat(captor.getValue(), equalTo(new BasicDBObjectBuilder().add("foo", 1).get()));
  }
View Full Code Here

      logger.error("Unable to update document without an ID: "+d);
      return false;
    }
    mdq.requireID(md.getID());
   
    BasicDBObjectBuilder bob = new BasicDBObjectBuilder();
   
    if(md.isActionTouched()) {
      bob.add(MongoDocument.ACTION_KEY, md.getAction().toString());
    }
   
    for(String s : md.getTouchedContent()) {
      if(md.getContentField(s)!=null) {
        bob.add(MongoDocument.CONTENTS_KEY+"."+s, md.getContentField(s));
      }
    }
    for(String s : md.getTouchedMetadata()){
      bob.add(MongoDocument.METADATA_KEY+"."+s, md.getMetadataField(s));
    }
   
    DBObject updateObject = getUpdateObject(bob.get());
    updateObject.putAll(getUnsetObject(getNullFields(md)));
   
    try {
      WriteResult wr = documents.update(mdq.toDBObject(), updateObject, true, false, concern);
      return wr.getN()==1;
View Full Code Here

    return splits;
  }
 
  private IParam createParamSplit(IParam param, DBObject q, DBObject min, DBObject max) {
    IParam p = param.clone();
    BasicDBObjectBuilder b = BasicDBObjectBuilder.start("$query", q);
   
    // The min() value is included in the range and the max() value is excluded.
    if (null != min) {
      b.append("$min", min);
    }
    if (null != max) {
      b.append("$max", max);
    }
   
    final DBObject query = b.get();
        log.debug( "Assembled Query: " + query );
       
        p.putValue(ParamKey.inputQuery, JSON.serialize(query));
    return p;
  }
View Full Code Here

        // Authenticate - optional
        // boolean auth = db.authenticate("foo", "bar");

        // Add some sample data
        DBCollection coll = db.getCollection("aggregationExample");
        coll.insert(new BasicDBObjectBuilder()
                .add("employee", 1)
                .add("department", "Sales")
                .add("amount", 71)
                .add("type", "airfare")
                .get());
        coll.insert(new BasicDBObjectBuilder()
                .add("employee", 2)
                .add("department", "Engineering")
                .add("amount", 15)
                .add("type", "airfare")
                .get());
        coll.insert(new BasicDBObjectBuilder()
                .add("employee", 4)
                .add("department", "Human Resources")
                .add("amount", 5)
                .add("type", "airfare")
                .get());
        coll.insert(new BasicDBObjectBuilder()
                .add("employee", 42)
                .add("department", "Sales")
                .add("amount", 77)
                .add("type", "airfare")
                .get());
View Full Code Here

                {
                case MAP:
                    Map mapObj = (Map) valueObject;
                    // BasicDBObjectBuilder builder =
                    // BasicDBObjectBuilder.start(mapObj);
                    BasicDBObjectBuilder b = new BasicDBObjectBuilder();
                    Iterator i = mapObj.entrySet().iterator();
                    while (i.hasNext())
                    {
                        Map.Entry entry = (Map.Entry) i.next();
                        b.add(entry.getKey().toString(),
                                MongoDBUtils.populateValue(entry.getValue(), entry.getValue().getClass()));
                    }
                    dbObj.put(((AbstractAttribute) column).getJPAColumnName(), b.get());
                    break;
                case SET:
                case LIST:
                    Collection collection = (Collection) valueObject;
                    BasicDBList basicDBList = new BasicDBList();
View Full Code Here

    public synchronized boolean setHead(RecordId base, RecordId head) {
        if (!base.equals(getHead())) {
            return false;
        }

        BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
        builder.add("_id", name);
        if (state.containsField("parent")) {
            builder.add("parent", state.get("parent"));
        }
        if (state.containsField("base")) {
            builder.add("base", state.get("base"));
        }
        builder.add("head", head.toString());
        DBObject nextState = builder.get();

        WriteResult result =
                journals.update(state, nextState, false, false, concern);
        if (result.getN() == 1) {
            state = nextState;
View Full Code Here

                head = newHead;
            }

            base = head;

            BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
            builder.add("_id", name);
            builder.add("parent", state.get("parent"));
            builder.add("base", base.toString());
            builder.add("head", head.toString());
            // TODO: concurrent updates?
            journals.update(state, builder.get(), false, false, concern);
        }
    }
View Full Code Here

TOP

Related Classes of com.mongodb.BasicDBObjectBuilder

Copyright © 2018 www.massapicom. 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.