Package com.mongodb

Examples of com.mongodb.BasicDBObjectBuilder


    }


    public void putNext(final Tuple tuple) throws IOException {
        LOG.info("writing " + tuple.toString());
        final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();

        ResourceFieldSchema[] fields = this.schema.getFields();
        for (int i = 0; i < fields.length; i++) {
            writeField(builder, fields[i], tuple.get(i));
        }

        LOG.info("writing out:" + builder.get().toString());
        //noinspection unchecked
        recordWriter.write(null, builder.get());
    }
View Full Code Here


    }

    @Override
    public void putNext(final Tuple tuple) throws IOException {
        try {
            final BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
            ResourceFieldSchema[] fields = null;
            if (schema != null) {
                fields = schema.getFields();
            }
            if (fields != null) {
                for (int i = 0; i < fields.length; i++) {
                    writeField(builder, fields[i], tuple.get(i));
                }
            } else {
                for (int i = 0; i < tuple.size(); i++) {
                    writeField(builder, null, tuple.get(i));
                }
            }

            out.write(null, builder.get());
        } catch (Exception e) {
            throw new IOException("Couldn't convert tuple to bson: ", e);
        }
    }
View Full Code Here

public class MongoStorageTest {
    @Test
    public void testMap() throws Exception {
        MongoStorage ms = new MongoStorage();
        BasicDBObjectBuilder builder = BasicDBObjectBuilder.start();
        ResourceSchema schema = new ResourceSchema(Utils.getSchemaFromString("m:map[]"));

        Map<String, Object> val = new HashMap<String, Object>();
        val.put("f1", 1);
        val.put("f2", "2");

        ms.writeField(builder, schema.getFields()[0], val);

        DBObject out = builder.get();

        Set<String> outKeySet = out.keySet();

        assertEquals(2, outKeySet.size());
        assertEquals(1, out.get("f1"));
View Full Code Here

  public void createsNotNestedGeoSpatialIndexCorrectly() {

    MongoMappingContext mappingContext = prepareMappingContext(Wrapper.class);
    new MongoPersistentEntityIndexCreator(mappingContext, factory);

    assertThat(keysCaptor.getValue(), equalTo(new BasicDBObjectBuilder().add("company.address.location", "2d").get()));
    assertThat(optionsCaptor.getValue(), equalTo(new BasicDBObjectBuilder().add("name", "company.address.location")
        .add("min", -180).add("max", 180).add("bits", 26).get()));
  }
View Full Code Here

    MongoMappingContext mappingContext = prepareMappingContext(EntityWithGeneratedIndexName.class);
    new MongoPersistentEntityIndexCreator(mappingContext, factory);

    assertThat(keysCaptor.getValue().containsField("name"), is(false));
    assertThat(keysCaptor.getValue().keySet(), hasItem("lastname"));
    assertThat(optionsCaptor.getValue(), is(new BasicDBObjectBuilder().get()));
  }
View Full Code Here

        context.getPersistentEntity(DocumentWithDBRefCollection.class));

    DBObject $pull = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$pull");
    DBObject list = DBObjectTestUtils.getAsDBObject($pull, "dbRefAnnotatedList");

    assertThat(list, equalTo(new BasicDBObjectBuilder().add("_id", "1").get()));
  }
View Full Code Here

    DBObject mappedUpdate = mapper.getMappedObject(update.getUpdateObject(),
        context.getPersistentEntity(DocumentWithDBRefCollection.class));

    DBObject $unset = DBObjectTestUtils.getAsDBObject(mappedUpdate, "$unset");

    assertThat($unset, equalTo(new BasicDBObjectBuilder().add("dbRefAnnotatedList.$", 1).get()));
  }
View Full Code Here

    DBObject dbo = (DBObject) JSON.parse(keyDefinitionString);
    if (!StringUtils.hasText(dotPath)) {
      return dbo;
    }

    BasicDBObjectBuilder dboBuilder = new BasicDBObjectBuilder();

    for (String key : dbo.keySet()) {
      dboBuilder.add(dotPath + "." + key, dbo.get(key));
    }
    return dboBuilder.get();
  }
View Full Code Here

   * @see org.springframework.data.mongodb.core.query.CriteriaDefinition#getCriteriaObject()
   */
  @Override
  public DBObject getCriteriaObject() {

    BasicDBObjectBuilder builder = new BasicDBObjectBuilder();

    if (StringUtils.hasText(language)) {
      builder.add("$language", language);
    }

    if (!terms.isEmpty()) {
      builder.add("$search", join(terms));
    }

    return new BasicDBObject("$text", builder.get());
  }
View Full Code Here

    DBObject sink = new BasicDBObject();
    converter.write(source, sink);

    assertThat((String) sink.get("_id"), is("rootId"));
    assertThat((DBObject) sink.get("nested"), is(new BasicDBObjectBuilder().add("id", "nestedId").get()));
  }
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.