Java 类org.bson.codecs.configuration.CodecRegistries 实例源码

项目:polymorphia    文件:CodecResolverTest.java   
@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());
}
项目:GitHub    文件:Repositories.java   
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);
}
项目:polymorphia    文件:ExternalIdCodecProviderTest.java   
@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());
}
项目:mongolastic    文件:ElasticBulkService.java   
/**
 * 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();
    }
}
项目:verbum-domini    文件:PersistenceManagerImpl.java   
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;
}
项目:oap    文件:MongoStorage.java   
@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();
}
项目:mongowp    文件:MongoClientWrapper.java   
@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);
  }
}
项目:immutables    文件:Repositories.java   
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);
}
项目: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()));
}
项目:polymorphia    文件:TypeCodecProviderTest.java   
@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());
}
项目:polymorphia    文件:NoDiscriminatorForPolymorphicLeafClassesTest.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder()
                            .register(NoDiscriminatorForPolymorphicLeafClassesTest.class)
                            .build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:TypesModelPackageTest.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder().register("de.bild.codec.model").build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:PolymorphicTest.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder().register(PolymorphicTest.class).build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:UpdateTest.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder()
                            .register(UpdateTest.class)
                            .build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:NullHandlingTest.java   
@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());
}
项目:polymorphia    文件:NonRegisteredModelClassTest.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder()
                            .register("de.bild.codec.nonregisteredmodel.model")
                            .build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:Tutorial.java   
/**
 *
 * @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());
}
项目:polymorphia    文件:ExternalIdCodecProviderTest.java   
@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());
}
项目:polymorphia    文件:SpecialFieldsMapCodecTest.java   
@Bean
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder().register(SpecialFieldsMapCodecTest.class).build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:IdTest.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder().register(IdTest.class.getPackage().getName()).build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:ListTypeCodecTest.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder().register(ListTypeCodecTest.class).build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:BaseTest.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder().register(BaseTest.class).build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:PreSaveHookTest.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder().register(PreSaveHookTest.class).build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:polymorphia    文件:ExternalIdCodecProviderTest.java   
@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());
}
项目:polymorphia    文件:TestEnums.java   
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder()
                            .register("de.bild.codec.enums.model")
                            .build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
项目:digital-display-garden-iteration-2-spraguesanborn    文件:UserControllerSpec.java   
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());
}
项目:digital-display-garden-iteration-2-spraguesanborn    文件:FlowerControllerSpec.java   
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());
}
项目:otus-api    文件:MongoDBFactory.java   
@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);
}
项目:mongo-obj-framework    文件:Smof.java   
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();
}
项目:awplab-core    文件:MongoProvider.java   
@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);
    }
}
项目:core-ng-project    文件:EntityCodecs.java   
<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);
}
项目: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;
}
项目:mongo-mapper    文件:EntityCodec.java   
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();
}
项目:mongo-mapper    文件:AbstractMongoIT.java   
@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);
}
项目:eds-starter6-mongodb    文件:MongoConfig.java   
@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())));
}
项目: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);
}
项目:bsoncodec-apt    文件:HierarchyTest.java   
private MongoDatabase connect() {
    CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
            MongoClient.getDefaultCodecRegistry(),
            CodecRegistries.fromCodecs(new UserCodec(new ObjectIdGenerator())));

    MongoDatabase db = getMongoClient().getDatabase("pojo")
            .withCodecRegistry(codecRegistry);
    return db;
}
项目:bsoncodec-apt    文件:ArrayTest.java   
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;
}
项目:bsoncodec-apt    文件:MetaAnnotationTest.java   
private MongoDatabase connect() {
    CodecRegistry codecRegistry = CodecRegistries.fromRegistries(
            MongoClient.getDefaultCodecRegistry(),
            CodecRegistries.fromProviders(new PojoCodecProvider()));

    MongoDatabase db = getMongoClient().getDatabase("pojo")
            .withCodecRegistry(codecRegistry);
    return db;
}