Package org.bson

Examples of org.bson.BasicBSONObject


        collection = new MemoryCollection("db", "coll", "_id");
    }

    @Test
    public void testConvertSelector() throws Exception {
        BasicBSONObject selector = new BasicBSONObject();

        assertThat(collection.convertSelectorToDocument(selector)) //
                .isEqualTo(new BasicBSONObject());

        selector = new BasicBSONObject("_id", 1);
        assertThat(collection.convertSelectorToDocument(selector)) //
                .isEqualTo(new BasicBSONObject("_id", 1));

        selector = new BasicBSONObject("_id", 1).append("$set", new BasicBSONObject("foo", "bar"));
        assertThat(collection.convertSelectorToDocument(selector)) //
                .isEqualTo(new BasicBSONObject("_id", 1));

        selector = new BasicBSONObject("_id", 1).append("e.i", 14);
        assertThat(collection.convertSelectorToDocument(selector)) //
                .isEqualTo(new BasicBSONObject("_id", 1).append("e", new BasicBSONObject("i", 14)));

        selector = new BasicBSONObject("_id", 1).append("e.i.y", new BasicBSONObject("foo", "bar"));
        assertThat(collection.convertSelectorToDocument(selector)) //
                .isEqualTo(new BasicBSONObject("_id", 1).append("e", //
                        new BasicBSONObject("i", new BasicBSONObject("y", //
                                new BasicBSONObject("foo", "bar")))));
    }
View Full Code Here


        assertThat(Utils.addNumbers(100000000000000l, 100000000000000l)).isEqualTo(Long.valueOf(200000000000000l));
    }

    @Test
    public void testMarkOkay() throws Exception {
        BSONObject obj = new BasicBSONObject();
        Utils.markOkay(obj);
        assertThat(obj.get("ok")).isEqualTo(Integer.valueOf(1));
    }
View Full Code Here

                                new BasicBSONObject("foo", "bar")))));
    }

    @Test
    public void testDeriveDocumentId() throws Exception {
        assertThat(collection.deriveDocumentId(new BasicBSONObject())).isInstanceOf(ObjectId.class);

        assertThat(collection.deriveDocumentId(new BasicBSONObject("a", 1))) //
                .isInstanceOf(ObjectId.class);

        assertThat(collection.deriveDocumentId(new BasicBSONObject("_id", 1))) //
                .isEqualTo(1);

        assertThat(collection.deriveDocumentId(new BasicBSONObject("_id", new BasicDBObject("$in", Arrays.asList(1))))) //
                .isEqualTo(1);

        assertThat(collection.deriveDocumentId(new BasicBSONObject("_id", new BasicDBObject("$in", Arrays.asList())))) //
                .isInstanceOf(ObjectId.class);
    }
View Full Code Here

        assertThat(Utils.nullAwareEquals(Float.valueOf(3.0f), Double.valueOf(3.0))).isTrue();
    }

    @Test
    public void testCalculateSize() {
        assertThat(Utils.calculateSize(new BasicBSONObject())).isEqualTo(5);
        assertThat(Utils.calculateSize(new BasicBSONObject("_id", 7))).isEqualTo(14);
    }
View Full Code Here

        assertThat(Utils.calculateSize(new BasicBSONObject("_id", 7))).isEqualTo(14);
    }

    @Test
    public void testGetSubdocumentValue() throws Exception {
        BSONObject document = new BasicBSONObject("foo", 25);
        assertThat(Utils.getSubdocumentValue(document, "foo")).isEqualTo(25);
        assertThat(Utils.getSubdocumentValue(document, "foo.bar")).isNull();
        assertThat(Utils.getSubdocumentValue(document, "foo.bar.x")).isNull();

        document.put("foo", new BasicDBObject("a", 10).append("b", new BasicDBObject("x", 29).append("z", 17)));
        assertThat(Utils.getSubdocumentValue(document, "foo.a")).isEqualTo(10);
        assertThat(Utils.getSubdocumentValue(document, "foo.b.x")).isEqualTo(29);
        assertThat(Utils.getSubdocumentValue(document, "foo.b.z")).isEqualTo(17);
        assertThat(Utils.getSubdocumentValue(document, "foo.c")).isNull();
    }
View Full Code Here

  {
    //added the limit and skip
    if (_createCursor && ( _cursor == null )){

      DBObject query = null;
      BasicBSONObject queryObj =(BasicBSONObject) _querySpec.get("$query");
      BasicBSONObject minObj = (BasicBSONObject) _querySpec.get("$min");
      BasicBSONObject maxObj = (BasicBSONObject) _querySpec.get("$max");
      if (null == queryObj) {
        if ((null != minObj) || (null != maxObj)) { // one of min/max specified
          query = new BasicDBObject();
        }
        else { // no $query, $max or $min => this is the query
          query = _querySpec;
        }
      }
      else {
        query = new BasicDBObject(queryObj);
      }
      _cursor = InfiniteMongoConfigUtil.getCollection( _mongoURI ).find( query, _fieldSpec ).sort( _sortSpec ).limit(_limit).skip(_skip);
     
      if (null != minObj) {
       
        Iterator<Map.Entry<String, Object>> it = minObj.entrySet().iterator();
        while (it.hasNext()) { // remove upper/lower limit objects because not sure about new mongo syntax
          Map.Entry<String, Object> keyVal = it.next();
          if (keyVal.getValue() instanceof org.bson.types.MinKey) {
            it.remove();
          }
        }
        if (!minObj.isEmpty()) {
          _cursor = _cursor.addSpecial("$min", new BasicDBObject(minObj));
        }
      }
      if (null != maxObj) {
        Iterator<Map.Entry<String, Object>> it = maxObj.entrySet().iterator();
        while (it.hasNext()) { // remove upper/lower limit objects because not sure about new mongo syntax
          Map.Entry<String, Object> keyVal = it.next();
          if (keyVal.getValue() instanceof org.bson.types.MaxKey) {
            it.remove();
          }
        }
        if (!maxObj.isEmpty()) {
          _cursor = _cursor.addSpecial("$max", new BasicDBObject(maxObj));
        }
      }
     
      //DEBUG
View Full Code Here

        _secManager.setSecureFlag(false);       
      }
    }
    protected void combine(BSONWritable key, Iterable<BSONWritable> values)
    {
      _engine.put("_combine_input_key", JSON.serialize(new BasicBSONObject(key.toMap())));
      if (!this.isMemoryOptimized()) {
       
        ArrayList<BasicBSONObject> tmpValues = new ArrayList<BasicBSONObject>();
        for (BSONWritable val: values) {
          tmpValues.add(new BasicBSONObject(val.toMap()));
        }
        _engine.put("_combine_input_values", JSON.serialize(tmpValues));
      }
      try {
        _secManager.setSecureFlag(true);
View Full Code Here

        _secManager.setSecureFlag(false);       
      }
    }
    protected void reduce(BSONWritable key, Iterable<BSONWritable> values)
    {
      _engine.put("_reduce_input_key", JSON.serialize(new BasicBSONObject(key.toMap())));
      if (!this.isMemoryOptimized()) {
        ArrayList<BasicBSONObject> tmpValues = new ArrayList<BasicBSONObject>();
        for (BSONWritable val: values) {
          tmpValues.add(new BasicBSONObject(val.toMap()));
        }
        _engine.put("_reduce_input_values", JSON.serialize(tmpValues));
      }
      try {
        _secManager.setSecureFlag(true);
View Full Code Here

  /**
   * findAndModify を実行します。
   * @return
   */
  public BSONObject execute() {
    BSONObject command = new BasicBSONObject("findAndModify", collectionName)
        .append("query", query)
        .append("update", update);
    if (sort != null) {
      command.put("sort", sort);
    }
View Full Code Here

    return this;
  }
 
  public Query field(String key) {
    if (returnFieldSelector == null) {
      returnFieldSelector = new BasicBSONObject();
    }
    returnFieldSelector.put(key, 1);
    return this;
  }
View Full Code Here

TOP

Related Classes of org.bson.BasicBSONObject

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.