private BsonDocument parse(String where) { Bson bson = sqlParser.get(Bson.class, where); return bson.toBsonDocument( BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider(), new ValueCodecProvider())); }
@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; }
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)) ); }
@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); }
private BsonDocument toBsonDocument(Bson bson) { return bson.toBsonDocument( BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider(), new ValueCodecProvider())); }