當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。