Java 类org.bson.codecs.BsonValueCodecProvider 实例源码

项目:dragoman    文件:MongoWhereClauseListenerTest.java   
private BsonDocument parse(String where) {
  Bson bson = sqlParser.get(Bson.class, where);

  return bson.toBsonDocument(
      BsonDocument.class,
      CodecRegistries.fromProviders(new BsonValueCodecProvider(), new ValueCodecProvider()));
}
项目:baleen    文件:SharedFongoResource.java   
@Override
protected boolean doInitialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
        throws ResourceInitializationException {
    // Work whether it's a list of DB Objects or a single
    if ("{}".equals(fongoData) || "[]".equals(fongoData) || Strings.isNullOrEmpty(fongoData)) {
        return true;
    }

    if (fongoData.trim().startsWith("[")) {
        CodecRegistry codecRegistry = CodecRegistries.fromProviders(Arrays.asList(new ValueCodecProvider(), new BsonValueCodecProvider(), new DocumentCodecProvider()));
        JsonReader reader = new JsonReader(fongoData);
        BsonArrayCodec arrayReader = new BsonArrayCodec(codecRegistry);

        BsonArray docArray = arrayReader.decode(reader, DecoderContext.builder().build());

        for(BsonValue doc : docArray.getValues()){
            fongo.getDatabase(BALEEN).getCollection(fongoCollection).insertOne(Document.parse(doc.asDocument().toJson()));
        }       
    } else if (fongoData.trim().startsWith("{")) {
        Document data = Document.parse(fongoData);
        fongo.getDatabase(BALEEN).getCollection(fongoCollection).insertOne(data);
    } else {
        getMonitor().error("Unsupported type");
        throw new ResourceInitializationException();
    }

    return true;
}
项目:mongowg    文件:MongoWGPlugin.java   
private static CodecRegistry createCodecRegistry() {
    CodecRegistry common = CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(new ValueCodecProvider(), new DocumentCodecProvider(), new BsonValueCodecProvider()),
            CodecRegistries.fromCodecs(new BlockVector2DCodec(), new BlockVectorCodec(), new DefaultDomainCodec())
    );
    return CodecRegistries.fromRegistries(
            common,
            CodecRegistries.fromCodecs(new ProcessingProtectedRegionCodec(common))
    );
}
项目:dragoman    文件:SelectClauseParserTest.java   
private BsonDocument toBsonDocument(Bson bson) {
  return bson.toBsonDocument(
      BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider()));
}
项目:dragoman    文件:WhereClauseParserTest.java   
private BsonDocument toBsonDocument(Bson bson) {
  return bson.toBsonDocument(
      BsonDocument.class,
      CodecRegistries.fromProviders(new BsonValueCodecProvider(), new ValueCodecProvider()));
}
项目:dragoman    文件:OrderByClauseParserTest.java   
private BsonDocument toBsonDocument(Bson bson) {
  return bson.toBsonDocument(
      BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider()));
}
项目:dragoman    文件:MongoSelectClauseListenerTest.java   
private BsonDocument parse(String select) {
  Bson bson = sqlParser.get(Bson.class, select);

  return bson.toBsonDocument(
      BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider()));
}
项目:dragoman    文件:MongoOrderByClauseListenerTest.java   
private BsonDocument parse(String orderBy) {
  Bson bson = sqlParser.get(Bson.class, orderBy);

  return bson.toBsonDocument(
      BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider()));
}
项目:json-parse-helper    文件:JsonParseHelper.java   
private static BsonArray parseBsonArray(final String json) {
    return new BsonArrayCodec(CodecRegistries.fromProviders(new BsonValueCodecProvider())).decode(new JsonReader(json), DecoderContext.builder().build());
}
项目:lambdamatic-project    文件:DocumentDecoder.java   
/**
 * Returns the value of the current reader position.
 *
 * @param reader the read to read the value from
 * @param decoderContext the context
 * @return the non-null value read from the reader
 */
public BsonValue readBsonValue(final BsonReader reader, final DecoderContext decoderContext) {
  final Class<? extends BsonValue> classForBsonType =
      BsonValueCodecProvider.getClassForBsonType(reader.getCurrentBsonType());
  final Codec<? extends BsonValue> codec = this.codecRegistry.get(classForBsonType);
  return codec.decode(reader, decoderContext);
}
项目:cherimodata    文件:EntityCodecProvider.java   
/**
 * creates a RootCodecRegistry with our EntityCodecProvider as sole CodecProvider
 * 
 * @param db
 * @param clazz
 * @return
 */
public static CodecRegistry createCodecRegistry( MongoDatabase db, Class<? extends Entity> clazz )
{
    return CodecRegistries.fromProviders( new EntityCodecProvider( db, clazz ), new BsonValueCodecProvider() );
}