當前位置: 首頁>>代碼示例>>Java>>正文


Java CodecRegistry類代碼示例

本文整理匯總了Java中org.bson.codecs.configuration.CodecRegistry的典型用法代碼示例。如果您正苦於以下問題:Java CodecRegistry類的具體用法?Java CodecRegistry怎麽用?Java CodecRegistry使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CodecRegistry類屬於org.bson.codecs.configuration包,在下文中一共展示了CodecRegistry類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getCodecRegistry

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的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());
}
 
開發者ID:axelspringer,項目名稱:polymorphia,代碼行數:18,代碼來源:CodecResolverTest.java

示例2: Repository

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:Repositories.java

示例3: registryFor

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的package包/類
/**
 * "Smart" registry just for this particular {@code type}. It is typically composed with existing
 * registries using {@link org.bson.codecs.configuration.CodecRegistries#fromRegistries(CodecRegistry...)} method.
 */
public static <T> CodecRegistry registryFor(final Class<T> type, final TypeAdapter<T> adapter) {
  return new CodecRegistry() {
    @SuppressWarnings("unchecked")
    @Override
    public <X> Codec<X> get(Class<X> clazz) {
      // TODO is this a safe assumption with polymorphism (in repositories) ?
      if (type.isAssignableFrom(clazz)) {
        return (Codec<X>) codecFor(type, adapter);
      } else {
        // let other registries decide
        throw new CodecConfigurationException(String.format("Type %s not supported by this registry", type.getName()));
      }
    }
  };
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:BsonEncoding.java

示例4: get

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
	if (clazz == BigDecimal.class) {
		return (Codec<T>) bigDecimalCodec;
	}
	if (clazz == BigInteger.class) {
		return (Codec<T>) bigIntegerCodec;
	}
	if (clazz == InetAddress.class || clazz == Inet4Address.class || clazz == Inet6Address.class) {
		return (Codec<T>) inetAddressCodec;
	}
	if (clazz.isArray()) {
		return (Codec<T>) arrayCodec;
	}
	return null;
}
 
開發者ID:berkesa,項目名稱:datatree-adapters,代碼行數:18,代碼來源:JsonBson.java

示例5: get

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的package包/類
@Override
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
    // if clazz has type parameters, we warn the user that generic class definitions are problematic
    Codec<T> codec = pojoContext.get(clazz, registry);
    if (codec instanceof TypeCodec) {
        if (clazz != null && clazz.getTypeParameters().length > 0) {
            LOGGER.warn("Generic classes will only be encoded/decoded with their upper bounds! " +
                    "We could prohibit handling of the pojo codec for those generic classes, " +
                    "but then user would loose flexibility when subclassing such classes. Class: " + clazz.toGenericString());
        }
        TypeCodec typeCodec = (TypeCodec) codec;
        // generate dynamic proxy to add CollectibleCodec functionality
        if (typeCodec.isCollectible()) {
            LOGGER.debug("Enhancing {} to be collectible codec.", typeCodec);
            Class[] proxyInterfaces = new Class[]{CollectibleCodec.class};
            CollectibleCodec collectibleCodec = (CollectibleCodec) Proxy.newProxyInstance(
                    PojoCodecProvider.class.getClassLoader(),
                    proxyInterfaces,
                    new CollectibleCodecDelegator(typeCodec));

            return collectibleCodec;
        }
    }
    return codec;
}
 
開發者ID:axelspringer,項目名稱:polymorphia,代碼行數:26,代碼來源:PojoCodecProvider.java

示例6: getCodecRegistry

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的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());
}
 
開發者ID:axelspringer,項目名稱:polymorphia,代碼行數:17,代碼來源:ExternalIdCodecProviderTest.java

示例7: get

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
    // Optimistic get to avoid using dynamic memory
    Codec<?> ret = codecs.get(clazz);
    if (ret != null) {
        return (Codec<T>) ret;
    }
    if (clazz.isEnum()) {
        return (Codec<T>) codecs.computeIfAbsent(clazz, c -> new EnumCodec<>((Class<? extends Enum>) c));
    }
    if (clazz.isArray()) {
        Class<?> componentType = clazz.getComponentType();
        Codec componentCodec = get(componentType, registry);
        if (componentCodec != null) {
            return (Codec<T>) codecs.computeIfAbsent(clazz, c -> new ArrayCodec(clazz, componentCodec));
        }
    }
    return registry.get(clazz);
}
 
開發者ID:egopulse,項目名稱:java-code-gen,代碼行數:21,代碼來源:ExtraCodecProvider.java

示例8: toMongoClientOptions

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的package包/類
public MongoClientOptions toMongoClientOptions(final CodecRegistry codecRegistry) {
    return builder()
            .sslEnabled(sslEnabled)
            .codecRegistry(codecRegistry)
            .readPreference(ReadPreference.valueOf(readPreference))
            .connectTimeout(connectTimeout)
            .serverSelectionTimeout(serverSelectionTimeout)
            .cursorFinalizerEnabled(true)
            .maxWaitTime(maxWaitTime)
            .maxConnectionLifeTime(connectionpool.getMaxLifeTime())
            .threadsAllowedToBlockForConnectionMultiplier(connectionpool.getBlockedConnectionMultiplier())
            .maxConnectionIdleTime(connectionpool.getMaxIdleTime())
            .minConnectionsPerHost(connectionpool.getMinSize())
            .connectionsPerHost(connectionpool.getMaxSize())
            .build();
}
 
開發者ID:otto-de,項目名稱:edison-microservice,代碼行數:17,代碼來源:MongoProperties.java

示例9: buildCodecRegistries

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的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;
}
 
開發者ID:aureliano,項目名稱:verbum-domini,代碼行數:17,代碼來源:PersistenceManagerImpl.java

示例10: addEncodeStatements

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的package包/類
@Override
public void addEncodeStatements(TypeMirror type, CodeGeneratorContext ctx) {
	ctx.builder()
			.addStatement("Codec codec = this.registry.get($L.getClass())",
					ctx.getter())
			.addStatement("encoderContext.encodeWithChildContext(codec, writer, $L)",
					ctx.getter());

	// ctx.builder()
	// .addAnnotation(AnnotationSpec.builder(SuppressWarnings.class)
	// .addMember("value", "$S", "unchecked")
	// .addMember("value", "$S", "rawtypes").build());

	ctx.instanceFields().add(ImmutableInstanceField.builder()
			.type(ClassName.get(CodecRegistry.class)).name("registry").build());

	ctx.instanceFields()
			.add(ImmutableInstanceField.builder()
					.type(ClassName.get(BsonTypeClassMap.class))
					.name("bsonTypeClassMap").build());

}
 
開發者ID:ralscha,項目名稱:bsoncodec-apt,代碼行數:23,代碼來源:UnknownCodecDelegate.java

示例11: MongoStorage

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的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();
}
 
開發者ID:oaplatform,項目名稱:oap,代碼行數:27,代碼來源:MongoStorage.java

示例12: toBsonDocument

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的package包/類
@Override
public <TDocument> BsonDocument toBsonDocument(Class<TDocument> arg0,
		CodecRegistry codecRegistry) {
	System.out.println("toBsonDocument called");
	return new BsonDocumentWrapper<SyncConnectionInfo>(this,
			codecRegistry.get(SyncConnectionInfo.class));
}
 
開發者ID:gagoyal01,項目名稱:mongodb-rdbms-sync,代碼行數:8,代碼來源:SyncConnectionInfo.java

示例13: get

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的package包/類
@Override
public <T> Codec<T> get(Class<T> clazz, CodecRegistry registry) {
    if (clazz.isEnum()) {
        return new EnumCodec(clazz);
    }
    return null;
}
 
開發者ID:axelspringer,項目名稱:polymorphia,代碼行數:8,代碼來源:EnumCodecProvider.java

示例14: getCodecRegistry

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的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());
}
 
開發者ID:axelspringer,項目名稱:polymorphia,代碼行數:13,代碼來源:TypeCodecProviderTest.java

示例15: getCodecRegistry

import org.bson.codecs.configuration.CodecRegistry; //導入依賴的package包/類
@Bean()
public static CodecRegistry getCodecRegistry() {
    return CodecRegistries.fromRegistries(
            CodecRegistries.fromProviders(
                    new EnumCodecProvider(),
                    PojoCodecProvider.builder()
                            .register(NoDiscriminatorForPolymorphicLeafClassesTest.class)
                            .build()
            ),
            MongoClient.getDefaultCodecRegistry());
}
 
開發者ID:axelspringer,項目名稱:polymorphia,代碼行數:12,代碼來源:NoDiscriminatorForPolymorphicLeafClassesTest.java


注:本文中的org.bson.codecs.configuration.CodecRegistry類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。