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


Java BsonDocumentReader类代码示例

本文整理汇总了Java中org.bson.BsonDocumentReader的典型用法代码示例。如果您正苦于以下问题:Java BsonDocumentReader类的具体用法?Java BsonDocumentReader怎么用?Java BsonDocumentReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testArrayOfDocumentType

import org.bson.BsonDocumentReader; //导入依赖的package包/类
@Test
public void testArrayOfDocumentType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  BsonWriter bw = new BsonDocumentWriter(bsonDoc);
  bw.writeStartDocument();
  bw.writeName("a");
  bw.writeString("MongoDB");
  bw.writeName("b");
  bw.writeStartArray();
  bw.writeStartDocument();
  bw.writeName("c");
  bw.writeInt32(1);
  bw.writeEndDocument();
  bw.writeEndArray();
  bw.writeEndDocument();
  bw.flush();
  writer.reset();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  FieldReader reader = writer.getMapVector().getReader();
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) reader;
  FieldReader reader3 = mapReader.reader("b");
  assertEquals("MongoDB", mapReader.reader("a").readText().toString());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:24,代码来源:TestBsonRecordReader.java

示例2: testRecursiveDocuments

import org.bson.BsonDocumentReader; //导入依赖的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: testArrayType

import org.bson.BsonDocumentReader; //导入依赖的package包/类
@Test
public void testArrayType() throws IOException {
  BsonDocument bsonDoc = new BsonDocument();
  BsonWriter bw = new BsonDocumentWriter(bsonDoc);
  bw.writeStartDocument();
  bw.writeName("arrayKey");
  bw.writeStartArray();
  bw.writeInt32(1);
  bw.writeInt32(2);
  bw.writeInt32(3);
  bw.writeEndArray();
  bw.writeEndDocument();
  bw.flush();
  bsonReader.write(writer, new BsonDocumentReader(bsonDoc));
  SingleMapReaderImpl mapReader = (SingleMapReaderImpl) writer.getMapVector().getReader();
  FieldReader reader = mapReader.reader("arrayKey");
  assertEquals(3, reader.size());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:19,代码来源:TestBsonRecordReader.java

示例4: readFirstValue

import org.bson.BsonDocumentReader; //导入依赖的package包/类
/**
 * Reads the first value in the given {@link BsonValue}, assuming that it is a
 * {@link BsonDocument}.
 * 
 * @param bsonValue the BsonDocument to read
 * @return the first value
 */
private Object readFirstValue(final BsonValue bsonValue) {
  if (bsonValue == null) {
    throw new ConversionException("Expected a BsonDocument but the given value was a null");

  } else if (!bsonValue.isDocument()) {
    throw new ConversionException(
        "Expected a BsonDocument but the given value was a " + bsonValue.getBsonType().name());
  }
  try (final BsonDocumentReader reader = new BsonDocumentReader((BsonDocument) bsonValue)) {
    reader.readStartDocument();
    reader.readName();
    final Object value =
        decodeValue(readBsonValue(reader, DecoderContext.builder().build()), null);
    return value;
  }
}
 
开发者ID:lambdamatic,项目名称:lambdamatic-project,代码行数:24,代码来源:DocumentDecoder.java

示例5: writeLogicalOperation

import org.bson.BsonDocumentReader; //导入依赖的package包/类
/**
 * Writes a logical operation of the following form:
 * 
 * <pre>
 * { $operator: [ { &lt;operand1&gt; }, { &lt;operand2&gt; } , ... , {&lt;operandN&gt; } ] }
 * </pre>
 * 
 * @param operator the operator to write
 * @param operands the operands to write
 */
private void writeLogicalOperation(final MongoOperator operator,
    final List<Expression> operands) {
  this.writer.writeStartArray(operator.getLiteral());
  for (Expression operand : operands) {

    final BsonDocument operandDocument = new BsonDocument();
    try (final BsonDocumentWriter operandBsonWriter = new BsonDocumentWriter(operandDocument);) {
      try (
          final BsonDocumentReader operandBsonReader = new BsonDocumentReader(operandDocument);) {
        final FilterExpressionEncoder operandEncoder =
            new FilterExpressionEncoder(this.queryMetadataClass, this.queryMetadataVarName,
                operandBsonWriter, this.encoderContext);
        operand.accept(operandEncoder);
        this.writer.pipe(operandBsonReader);
      }
    }
  }
  this.writer.writeEndArray();
}
 
开发者ID:lambdamatic,项目名称:lambdamatic-project,代码行数:30,代码来源:FilterExpressionEncoder.java

示例6: convertUpsertId

import org.bson.BsonDocumentReader; //导入依赖的package包/类
@Nullable
private JsonObject convertUpsertId(@Nullable BsonValue upsertId) {
  JsonObject jsonUpsertId;
  if (upsertId != null) {
    JsonObjectCodec jsonObjectCodec = new JsonObjectCodec(new JsonObject());

    BsonDocument upsertIdDocument = new BsonDocument();
    upsertIdDocument.append(ID_FIELD, upsertId);

    BsonDocumentReader bsonDocumentReader = new BsonDocumentReader(upsertIdDocument);
    jsonUpsertId = jsonObjectCodec.decode(bsonDocumentReader, DecoderContext.builder().build());
  } else {
    jsonUpsertId = null;
  }
  return jsonUpsertId;
}
 
开发者ID:vert-x3,项目名称:vertx-mongo-client,代码行数:17,代码来源:MongoClientImpl.java

示例7: bsonToGson

import org.bson.BsonDocumentReader; //导入依赖的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

示例8: readFrom1

import org.bson.BsonDocumentReader; //导入依赖的package包/类
@Test
public void readFrom1() throws Exception {
    BsonDocument bsonDocument = getBsonDocument();
    BsonDocumentConverter bsonDocumentConverter = BsonValueConverterRepertory.getBsonDocumentConverter();
    long start = System.nanoTime();
    BsonDocumentReader bsonDocumentReader = new BsonDocumentReader(bsonDocument);
    BsonTest bsonTest = bsonDocumentConverter.decode(bsonDocumentReader, BsonTest.class, BsonMapperConfig.DEFALUT);
    System.out.println(System.nanoTime() - start);
    long start2 = System.nanoTime();
    BsonTest bsonTest1 = bsonDocumentConverter.decode(bsonDocument, BsonTest.class, BsonMapperConfig.DEFALUT);
    System.out.println(System.nanoTime() - start2);
    System.out.println(bsonTest);
    System.out.println(bsonTest1);
}
 
开发者ID:welkinbai,项目名称:BsonMapper,代码行数:15,代码来源:DefaultBsonMapperTest.java

示例9: deserializeWithCodec

import org.bson.BsonDocumentReader; //导入依赖的package包/类
protected final <T> T deserializeWithCodec(Codec<T> codec, BsonValue value) {
	checkArgument(codec != null, "Cannot find a valid codec to deserialize: " + value);
	final BsonDocument document = new BsonDocument("result", value);
	final BsonReader reader = new BsonDocumentReader(document);
	reader.readStartDocument();
	reader.readName();
	return codec.decode(reader, DecoderContext.builder().build());
}
 
开发者ID:JPDSousa,项目名称:mongo-obj-framework,代码行数:9,代码来源:AbstractBsonParser.java

示例10: testIntType

import org.bson.BsonDocumentReader; //导入依赖的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

示例11: testTimeStampType

import org.bson.BsonDocumentReader; //导入依赖的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

示例12: testSymbolType

import org.bson.BsonDocumentReader; //导入依赖的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

示例13: testStringType

import org.bson.BsonDocumentReader; //导入依赖的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

示例14: testSpecialCharStringType

import org.bson.BsonDocumentReader; //导入依赖的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

示例15: testObjectIdType

import org.bson.BsonDocumentReader; //导入依赖的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


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