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)) ); }
private BsonDocument toBsonDocument(Bson bson) { return bson.toBsonDocument( BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider())); }
private BsonDocument toBsonDocument(Bson bson) { return bson.toBsonDocument( BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider(), new ValueCodecProvider())); }
private BsonDocument parse(String select) { Bson bson = sqlParser.get(Bson.class, select); return bson.toBsonDocument( BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider())); }
private BsonDocument parse(String orderBy) { Bson bson = sqlParser.get(Bson.class, orderBy); return bson.toBsonDocument( BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider())); }
private static BsonArray parseBsonArray(final String json) { return new BsonArrayCodec(CodecRegistries.fromProviders(new BsonValueCodecProvider())).decode(new JsonReader(json), DecoderContext.builder().build()); }
/** * 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); }
/** * 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() ); }