本文整理汇总了Java中org.bson.codecs.configuration.CodecRegistries类的典型用法代码示例。如果您正苦于以下问题:Java CodecRegistries类的具体用法?Java CodecRegistries怎么用?Java CodecRegistries使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CodecRegistries类属于org.bson.codecs.configuration包,在下文中一共展示了CodecRegistries类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@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());
}
示例2: Repository
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
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);
}
示例3: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@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());
}
示例4: buildCodecRegistries
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
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;
}
示例5: MongoStorage
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@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();
}
示例6: MongoClientWrapper
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@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);
}
}
示例7: parse
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
private BsonDocument parse(String where) {
Bson bson = sqlParser.get(Bson.class, where);
return bson.toBsonDocument(
BsonDocument.class,
CodecRegistries.fromProviders(new BsonValueCodecProvider(), new ValueCodecProvider()));
}
示例8: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@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());
}
示例9: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@Bean()
public static CodecRegistry getCodecRegistry() {
return CodecRegistries.fromRegistries(
CodecRegistries.fromProviders(
new EnumCodecProvider(),
PojoCodecProvider.builder()
.register(NoDiscriminatorForPolymorphicLeafClassesTest.class)
.build()
),
MongoClient.getDefaultCodecRegistry());
}
示例10: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@Bean()
public static CodecRegistry getCodecRegistry() {
return CodecRegistries.fromRegistries(
CodecRegistries.fromProviders(
new EnumCodecProvider(),
PojoCodecProvider.builder().register("de.bild.codec.model").build()
),
MongoClient.getDefaultCodecRegistry());
}
示例11: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@Bean()
public static CodecRegistry getCodecRegistry() {
return CodecRegistries.fromRegistries(
CodecRegistries.fromProviders(
new EnumCodecProvider(),
PojoCodecProvider.builder().register(PolymorphicTest.class).build()
),
MongoClient.getDefaultCodecRegistry());
}
示例12: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@Bean()
public static CodecRegistry getCodecRegistry() {
return CodecRegistries.fromRegistries(
CodecRegistries.fromProviders(
new EnumCodecProvider(),
PojoCodecProvider.builder()
.register(UpdateTest.class)
.build()
),
MongoClient.getDefaultCodecRegistry());
}
示例13: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@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());
}
示例14: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
@Bean()
public static CodecRegistry getCodecRegistry() {
return CodecRegistries.fromRegistries(
CodecRegistries.fromProviders(
new EnumCodecProvider(),
PojoCodecProvider.builder()
.register("de.bild.codec.nonregisteredmodel.model")
.build()
),
MongoClient.getDefaultCodecRegistry());
}
示例15: getCodecRegistry
import org.bson.codecs.configuration.CodecRegistries; //导入依赖的package包/类
/**
*
* @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());
}