@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder() .register(CodecResolverTest.class) .registerCodecResolver((CodecResolver) (type, typeCodecRegistry, codecConfiguration) -> { if (TypeUtils.isAssignable(type, Base.class)) { return new DocumentCodec((Class<? extends Base>) type, typeCodecRegistry, codecConfiguration); } return null; }) .build() ), MongoClient.getDefaultCodecRegistry()); }
protected Repository( RepositorySetup configuration, String collectionName, Class<T> type) { this.configuration = checkNotNull(configuration, "configuration"); checkNotNull(collectionName, "collectionName"); checkNotNull(type, "type"); final TypeAdapter<T> adapter = checkAdapter(configuration.gson.getAdapter(type), type); final MongoCollection<Document> collection = configuration.database.getCollection(collectionName); // combine default and immutables codec registries final CodecRegistry registry = CodecRegistries.fromRegistries(collection.getCodecRegistry(), BsonEncoding.registryFor(type, adapter)); this.collection = collection .withCodecRegistry(registry) .withDocumentClass(type); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder() .register(Pojo.class.getPackage().getName()) .registerCodecResolver((CodecResolver) (type, typeCodecRegistry, codecConfiguration) -> { if (TypeUtils.isAssignable(type, CustomId.class)) { return new CustomIdCodec((Class<CustomId>)type, typeCodecRegistry, codecConfiguration); } return null; }).build() ), MongoClient.getDefaultCodecRegistry()); }
/** * Customizations for the document.toJson output. * <p> * http://mongodb.github.io/mongo-java-driver/3.0/bson/codecs/ * * @return the toJson encoder. */ private Encoder<Document> getEncoder() { ArrayList<Codec<?>> codecs = new ArrayList<>(); if (config.getElastic().getDateFormat() != null) { // Replace default DateCodec class to use the custom date formatter. codecs.add(new CustomDateCodec(config.getElastic().getDateFormat())); } if (config.getElastic().getLongToString()) { // Replace default LongCodec class codecs.add(new CustomLongCodec()); } if (codecs.size() > 0) { BsonTypeClassMap bsonTypeClassMap = new BsonTypeClassMap(); CodecRegistry codecRegistry = CodecRegistries.fromRegistries( CodecRegistries.fromCodecs(codecs), MongoClient.getDefaultCodecRegistry()); return new DocumentCodec(codecRegistry, bsonTypeClassMap); } else { return new DocumentCodec(); } }
private CodecRegistry buildCodecRegistries() { Codec<Document> defaultDocumentCodec = MongoClient.getDefaultCodecRegistry().get(Document.class); CodecRegistry codecRegistry = CodecRegistries.fromRegistries( MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromCodecs( new BibleCodec(defaultDocumentCodec), new BookCodec(defaultDocumentCodec), new ChapterCodec(defaultDocumentCodec), new VerseCodec(defaultDocumentCodec), new UserCodec(defaultDocumentCodec) ) ); return codecRegistry; }
@SuppressWarnings( "unchecked" ) public MongoStorage( oap.storage.MongoClient mongoClient, String database, String table, LockStrategy lockStrategy ) { super( IdentifierBuilder .annotation() .suggestion( ar -> ObjectId.get().toString() ) .size( 24 ) .idOptions() .build(), lockStrategy ); this.database = mongoClient.getDatabase( database ); final Object o = new TypeReference<Metadata<T>>() {}; final CodecRegistry codecRegistry = CodecRegistries.fromRegistries( CodecRegistries.fromCodecs( new JsonCodec<>( ( TypeReference<Metadata> ) o, Metadata.class, ( m ) -> identifier.get( ( T ) m.object ) ) ), this.database.getCodecRegistry() ); final Object metadataMongoCollection = this.database .getCollection( table, Metadata.class ) .withCodecRegistry( codecRegistry ); this.collection = ( MongoCollection<Metadata<T>> ) metadataMongoCollection; load(); }
@Inject public MongoClientWrapper(MongoClientConfiguration configuration) throws UnreachableMongoServerException { try { MongoClientOptions options = toMongoClientOptions(configuration); ImmutableList<MongoCredential> credentials = toMongoCredentials(configuration); testAddress(configuration.getHostAndPort(), options); this.configuration = configuration; this.driverClient = new com.mongodb.MongoClient( new ServerAddress( configuration.getHostAndPort().getHostText(), configuration.getHostAndPort().getPort()), credentials, options ); version = calculateVersion(); codecRegistry = CodecRegistries.fromCodecs(new DocumentCodec()); closed = false; } catch (com.mongodb.MongoException ex) { throw new UnreachableMongoServerException(configuration.getHostAndPort(), ex); } }
private BsonDocument parse(String where) { Bson bson = sqlParser.get(Bson.class, where); return bson.toBsonDocument( BsonDocument.class, CodecRegistries.fromProviders(new BsonValueCodecProvider(), new ValueCodecProvider())); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder() .register(TypeCodecProviderTest.class) .register(new CustomTypeCodecProvider(), new SetOfStringTypeCodecProvider()) .build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder() .register(NoDiscriminatorForPolymorphicLeafClassesTest.class) .build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder().register("de.bild.codec.model").build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder().register(PolymorphicTest.class).build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder() .register(UpdateTest.class) .build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder() .register(NullHandlingTest.class) .encodeNulls(false) .decodeUndefinedHandlingStrategy(DecodeUndefinedHandlingStrategy.Strategy.KEEP_POJO_DEFAULT) .encodeNullHandlingStrategy(EncodeNullHandlingStrategy.Strategy.KEEP_NULL) .build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder() .register("de.bild.codec.nonregisteredmodel.model") .build() ), MongoClient.getDefaultCodecRegistry()); }
/** * * @return a CodecRegistry build from the model package and the DefaultCodecRegistry from the mongo driver */ public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder() .register("de.bild.codec.tutorial.model") .build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), new CustomIdCodecProvider(), PojoCodecProvider.builder() .register(Pojo.class.getPackage().getName()) .ignoreTypesAnnotatedWith(IgnoreAnnotation.class) .build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder().register(SpecialFieldsMapCodecTest.class).build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder().register(IdTest.class.getPackage().getName()).build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder().register(ListTypeCodecTest.class).build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder().register(BaseTest.class).build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder().register(PreSaveHookTest.class).build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), new CustomIdCodecProvider(), PojoCodecProvider.builder() .register(Pojo.class.getPackage().getName()) .ignoreTypesAnnotatedWith(IgnoreType.class) .build() ), MongoClient.getDefaultCodecRegistry()); }
@Bean() public static CodecRegistry getCodecRegistry() { return CodecRegistries.fromRegistries( CodecRegistries.fromProviders( new EnumCodecProvider(), PojoCodecProvider.builder() .register("de.bild.codec.enums.model") .build() ), MongoClient.getDefaultCodecRegistry()); }
private BsonArray parseJsonArray(String json) { final CodecRegistry codecRegistry = CodecRegistries.fromProviders(Arrays.asList( new ValueCodecProvider(), new BsonValueCodecProvider(), new DocumentCodecProvider())); JsonReader reader = new JsonReader(json); BsonArrayCodec arrayReader = new BsonArrayCodec(codecRegistry); return arrayReader.decode(reader, DecoderContext.builder().build()); }
@ApplicationScoped @Produces public MongoDatabase getMongoDB() { MongoCredential credential = MongoCredential.createCredential(username, database, password.toCharArray()); CodecRegistry codecRegistry = CodecRegistries.fromRegistries( CodecRegistries.fromProviders(new OtusCodecProvider()), MongoClient.getDefaultCodecRegistry()); MongoClientOptions options = MongoClientOptions.builder().codecRegistry(codecRegistry).build(); ServerAddress serverAddress = new ServerAddress(host, port); return new MongoClient(serverAddress, Arrays.asList(credential), options).getDatabase(database); }
private static MongoClientOptions buildOptions() { final CodecRegistry mongoRegistry = MongoClient.getDefaultCodecRegistry(); final CodecRegistry smofRegistry = SmofParser.getDefaultCodecRegistry(); return MongoClientOptions.builder() .codecRegistry(CodecRegistries.fromRegistries(Arrays.asList(mongoRegistry, smofRegistry))) .build(); }
@Validate private void start() { try { if (mongoClient == null) { serviceController = false; CodecRegistry codecRegistry = CodecRegistries.fromRegistries( CodecRegistries.fromProviders(this), MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromProviders(new BeanCodecProvider())); MongoClientOptions.Builder clientOptions = MongoClientOptions.builder() .codecRegistry(codecRegistry); mongoClient = new MongoClient(new MongoClientURI(connectionString, clientOptions)); MongoDatabase adminDatabase = mongoClient.getDatabase("admin"); Document document = adminDatabase.runCommand(new Document("serverStatus", 1)); logger.debug("Server Started: \n" + document.toJson()); logger.info("Started up MongoClient!"); serviceController = true; } else { logger.warn("Unable to startup, MongoClient instance already exists?"); } } catch (Exception ex) { logger.error("Unable to start MongoClient!", ex); } }
<T extends Enum<T>> CodecRegistry codecRegistry() { List<Codec<?>> codecs = new ArrayList<>(this.codecs.values()); codecs.add(new LocalDateTimeCodec()); codecs.add(new ZonedDateTimeCodec()); for (Class<? extends Enum<?>> enumClass : enumClasses) { @SuppressWarnings("unchecked") Class<T> codecClass = (Class<T>) enumClass; codecs.add(new EnumCodec<>(codecClass)); } return CodecRegistries.fromCodecs(codecs); }
@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; }
public EntityCodec(Class<T> clazz, EntityInfo info) { this.clazz = clazz; this.info = info; idGenerator = Assertions.notNull("idGenerator", new ObjectIdGenerator()); registry = CodecRegistries.fromProviders(MongoMapper.getProviders()); documentCodec = new DocumentCodec(registry, new BsonTypeClassMap()); bsonTypeClassMap = new BsonTypeClassMap(); }
@Before public void setUp() throws Exception { CodecRegistry codecRegistry = CodecRegistries.fromProviders(MongoMapper.getProviders()); MongoClientOptions settings = MongoClientOptions.builder().codecRegistry(codecRegistry).build(); String port = System.getProperty("embedMongoPort"); Assert.assertNotNull("Please, set system property 'embedMongoPort' to run this test outside Maven.", port); client = new MongoClient(new ServerAddress("127.0.0.1", Integer.parseInt(port)), settings); dbName = "mapper_test" + UUID.randomUUID(); db = client.getDatabase(dbName); }
@Bean public MongoDatabase mongoDatabase(MongoClient mongoClient, MongoProperties properties) { MongoClientURI uri = new MongoClientURI(properties.getUri()); return mongoClient.getDatabase(uri.getDatabase()) .withCodecRegistry(CodecRegistries.fromRegistries( MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromProviders(new ListCodec.Provider()), CodecRegistries.fromProviders( new ch.rasc.eds.starter.config.PojoCodecProvider()))); }
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 MongoDatabase connect() { CodecRegistry codecRegistry = CodecRegistries.fromRegistries( MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromCodecs(new UserCodec(new ObjectIdGenerator()))); MongoDatabase db = getMongoClient().getDatabase("pojo") .withCodecRegistry(codecRegistry); return db; }
private MongoDatabase connect() { CodecRegistry codecRegistry = CodecRegistries.fromRegistries( MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromCodecs(new Array1PojoCodec(new ObjectIdGenerator()), new Array1PojoFixedCodec(new ObjectIdGenerator()), new Array2PojoCodec(new ObjectIdGenerator()), new Array2PojoFixedCodec(new ObjectIdGenerator()), new Array3PojoCodec(new ObjectIdGenerator()))); MongoDatabase db = getMongoClient().getDatabase("pojo") .withCodecRegistry(codecRegistry); return db; }
private MongoDatabase connect() { CodecRegistry codecRegistry = CodecRegistries.fromRegistries( MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromProviders(new PojoCodecProvider())); MongoDatabase db = getMongoClient().getDatabase("pojo") .withCodecRegistry(codecRegistry); return db; }