当前位置: 首页>>代码示例>>Java>>正文


Java BsonDocument.append方法代码示例

本文整理汇总了Java中org.bson.BsonDocument.append方法的典型用法代码示例。如果您正苦于以下问题:Java BsonDocument.append方法的具体用法?Java BsonDocument.append怎么用?Java BsonDocument.append使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bson.BsonDocument的用法示例。


在下文中一共展示了BsonDocument.append方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromObject

import org.bson.BsonDocument; //导入方法依赖的package包/类
private BsonDocument fromObject(Object value) {
	final BsonDocument document = new BsonDocument();
	final TypeParser<?> metadata = getTypeParser(value.getClass());
	final BsonArray lazyStack = new BsonArray();

	for(PrimaryField field : metadata.getAllFields()) {
		final Object fieldValue = extractValue(value, field);
		final BsonValue parsedValue;

		checkRequired(field, fieldValue);
		parsedValue = topParser.toBson(fieldValue, field);
		if(parsedValue instanceof BsonLazyObjectId) {
			lazyStack.add(parsedValue);
		}
		else {
			document.put(field.getName(), parsedValue);
		}
	}
	document.append(SmofParser.ON_INSERT, lazyStack);
	return document;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:22,代码来源:ObjectParser.java

示例2: testRecursiveDocuments

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testRecursiveDocuments() throws IOException {
  BsonDocument topDoc = new BsonDocument();
  final int count = 3;
  for (int i = 0; i < count; ++i) {
    BsonDocument bsonDoc = new BsonDocument();
    BsonWriter bw = new BsonDocumentWriter(bsonDoc);
    bw.writeStartDocument();
    bw.writeName("k1" + i);
    bw.writeString("drillMongo1" + i);
    bw.writeName("k2" + i);
    bw.writeString("drillMongo2" + i);
    bw.writeEndDocument();
    bw.flush();
    topDoc.append("doc" + i, bsonDoc);
  }
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(topDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  for (int i = 0; i < count; ++i) {
    SingleMapReaderImpl reader = (SingleMapReaderImpl) mapReader.reader("doc" + i);
    assertEquals("drillMongo1" + i, reader.reader("k1" + i).readText().toString());
    assertEquals("drillMongo2" + i, reader.reader("k2" + i).readText().toString());
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:26,代码来源:TestBsonRecordReader.java

示例3: bsonToGson

import org.bson.BsonDocument; //导入方法依赖的package包/类
/**
 * Reading from BSON to GSON
 */
@Test
public void bsonToGson() throws Exception {
    BsonDocument document = new BsonDocument();
    document.append("boolean", new BsonBoolean(true));
    document.append("int32", new BsonInt32(32));
    document.append("int64", new BsonInt64(64));
    document.append("double", new BsonDouble(42.42D));
    document.append("string", new BsonString("foo"));
    document.append("null", new BsonNull());
    document.append("array", new BsonArray());
    document.append("object", new BsonDocument());

    JsonElement element = TypeAdapters.JSON_ELEMENT.read(new BsonReader(new BsonDocumentReader(document)));
    check(element.isJsonObject());

    check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().isBoolean());
    check(element.getAsJsonObject().get("boolean").getAsJsonPrimitive().getAsBoolean());

    check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().isNumber());
    check(element.getAsJsonObject().get("int32").getAsJsonPrimitive().getAsNumber().intValue()).is(32);

    check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().isNumber());
    check(element.getAsJsonObject().get("int64").getAsJsonPrimitive().getAsNumber().longValue()).is(64L);

    check(element.getAsJsonObject().get("double").getAsJsonPrimitive().isNumber());
    check(element.getAsJsonObject().get("double").getAsJsonPrimitive().getAsNumber().doubleValue()).is(42.42D);

    check(element.getAsJsonObject().get("string").getAsJsonPrimitive().isString());
    check(element.getAsJsonObject().get("string").getAsJsonPrimitive().getAsString()).is("foo");

    check(element.getAsJsonObject().get("null").isJsonNull());
    check(element.getAsJsonObject().get("array").isJsonArray());
    check(element.getAsJsonObject().get("object").isJsonObject());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:38,代码来源:BsonReaderTest.java

示例4: get

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Override
public Bson get() {
  List<Projection> projections = getProjections();
  BsonDocument response = new BsonDocument("_id", new BsonInt32(0));
  for (Projection p : projections) {
    response.append(p.getName(), new BsonInt32(1));
  }

  return response;
}
 
开发者ID:glytching,项目名称:dragoman,代码行数:11,代码来源:MongoSelectClauseListener.java

示例5: fromEnum

import org.bson.BsonDocument; //导入方法依赖的package包/类
private BsonDocument fromEnum(Enum<?> value, SerializationContext serContext) {
	final BsonDocument document = fromObject(value);
	final BsonString name = new BsonString(value.name());
	document.append(ENUM_NAME, name);
	serContext.put(value, SmofType.OBJECT, document);
	return document;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:8,代码来源:ObjectParser.java

示例6: fromMap

import org.bson.BsonDocument; //导入方法依赖的package包/类
private BsonDocument fromMap(Map<?, ?> value, PrimaryField mapField, SerializationContext serContext) {
	final Pair<SecondaryField, SecondaryField> fields = getMapFields(mapField);
	final BsonDocument document = new BsonDocument();
	for(Object key : value.keySet()) {
		final Object mapValue = value.get(key);
		final BsonValue parsedValue = topParser.toBson(mapValue, fields.getValue());
		document.append(key.toString(), parsedValue);
	}
	serContext.put(value, SmofType.OBJECT, document);
	return document;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:12,代码来源:ObjectParser.java

示例7: pushAll

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Override
public SmofUpdate<T> pushAll(String fieldName, int index, Collection<?> values) {
	final SmofField field = validateFieldName(fieldName, ARRAY);
	final BsonValue bsonValue = parser.toBson(values, field);
	final BsonDocument bsonDocument = new BsonDocument(EACH.getOperator(), bsonValue);
	bsonDocument.append(POSITION.getOperator(), new BsonInt32(index));
	putOrAppend(PUSH, fieldName, bsonDocument);
	return this;
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:10,代码来源:SmofUpdateImpl.java

示例8: testIntType

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testIntType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  bsonDoc.append("seqNo", new BsonInt64(10));
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  assertEquals(10l, mapReader.reader("seqNo").readLong().longValue());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:10,代码来源:TestBsonRecordReader.java

示例9: testTimeStampType

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testTimeStampType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  bsonDoc.append("ts", new BsonTimestamp(1000, 10));
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  assertEquals(1000l, mapReader.reader("ts").readDateTime().getMillis());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:10,代码来源:TestBsonRecordReader.java

示例10: testSymbolType

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testSymbolType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  bsonDoc.append("symbolKey", new BsonSymbol("test_symbol"));
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  assertEquals("test_symbol", mapReader.reader("symbolKey").readText().toString());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:10,代码来源:TestBsonRecordReader.java

示例11: testStringType

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testStringType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  bsonDoc.append("stringKey", new BsonString("test_string"));
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  assertEquals("test_string", mapReader.reader("stringKey").readText().toString());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:10,代码来源:TestBsonRecordReader.java

示例12: testSpecialCharStringType

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testSpecialCharStringType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  bsonDoc.append("stringKey", new BsonString("§§§§§§§§§1"));
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  assertEquals("§§§§§§§§§1",
      mapReader.reader("stringKey").readText().toString());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:11,代码来源:TestBsonRecordReader.java

示例13: testObjectIdType

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testObjectIdType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  BsonObjectId value = new BsonObjectId(new ObjectId());
  bsonDoc.append("_idKey", value);
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  byte[] readByteArray = mapReader.reader("_idKey").readByteArray();
  assertTrue(Arrays.equals(value.getValue().toByteArray(), readByteArray));
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:12,代码来源:TestBsonRecordReader.java

示例14: testNullType

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testNullType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  bsonDoc.append("nullKey", new BsonNull());
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  assertEquals(null, mapReader.reader("nullKey").readObject());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:10,代码来源:TestBsonRecordReader.java

示例15: testDoubleType

import org.bson.BsonDocument; //导入方法依赖的package包/类
@Test
public void testDoubleType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  bsonDoc.append("doubleKey", new BsonDouble(12.35));
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  assertEquals(12.35d, mapReader.reader("doubleKey").readDouble().doubleValue(), 0.00001);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:10,代码来源:TestBsonRecordReader.java


注:本文中的org.bson.BsonDocument.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。