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

项目: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))
    );
}
项目:mongowg    文件:ProcessingProtectedRegionCodecTest.java   
@Before
public void prepare() {
    CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(new ValueCodecProvider(), new DocumentCodecProvider()),
            CodecRegistries.fromCodecs(new BlockVector2DCodec(), new BlockVectorCodec(), new DefaultDomainCodec())
    );
    codec = new ProcessingProtectedRegionCodec(codecRegistry);
}