下面列出了org.hibernate.usertype.UserType#org.hibernate.boot.model.TypeContributions 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
// account for Oracle's deprecated support for LONGVARBINARY...
// prefer BLOB, unless the user opts out of it
boolean preferLong = serviceRegistry.getService( ConfigurationService.class ).getSetting(
PREFER_LONG_RAW,
StandardConverters.BOOLEAN,
false
);
if ( !preferLong ) {
typeContributions.contributeType( MaterializedBlobType.INSTANCE, "byte[]", byte[].class.getName() );
typeContributions.contributeType( WrappedMaterializedBlobType.INSTANCE, "Byte[]", Byte[].class.getName() );
}
}
@Override
protected void additionalProperties(Properties properties) {
CustomObjectMapperSupplier customObjectMapperSupplier = new CustomObjectMapperSupplier();
final JsonBinaryType jsonBinaryType = new JsonBinaryType(customObjectMapperSupplier.get(), Location.class);
properties.put( "hibernate.type_contributors", new TypeContributorList() {
@Override
public List<TypeContributor> getTypeContributors() {
List<TypeContributor> typeContributors = new ArrayList<TypeContributor>();
typeContributors.add(new TypeContributor() {
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
typeContributions.contributeType(
jsonBinaryType, "location"
);
}
});
return typeContributors;
}
});
}
@Override
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes( typeContributions, serviceRegistry );
// HHH-9562
typeContributions.contributeType( PostgresUUIDType.INSTANCE );
}
@Override
public void contributeTypes(
TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
super.contributeTypes(typeContributions, serviceRegistry);
typeContributions.contributeJavaTypeDescriptor(StringCollectionDescriptor.getInstance());
typeContributions.contributeSqlTypeDescriptor(StringCollectionDescriptor.getInstance());
typeContributions.contributeJavaTypeDescriptor(StringMapDescriptor.getInstance());
typeContributions.contributeSqlTypeDescriptor(StringMapDescriptor.getInstance());
}
@Override
protected void additionalProperties(Properties properties) {
TypeContributor typeContributor = new TypeContributor() {
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
typeContributions.contributeType(JsonNodeBinaryType.INSTANCE);
typeContributions.contributeSqlTypeDescriptor(JsonNodeBinaryType.INSTANCE .getSqlTypeDescriptor());
}
};
properties.put(
"hibernate.type_contributors",
(TypeContributorList) () -> Collections.singletonList(typeContributor)
);
}
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
if ( ReactiveModeCheck.isReactiveRegistry( serviceRegistry ) ) {
registerReactiveChanges( typeContributions, serviceRegistry );
}
}
private void registerReactiveChanges(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
BasicTypeRegistry basicTypeRegistry = typeContributions.getTypeConfiguration().getBasicTypeRegistry();
Dialect dialect = serviceRegistry.getService(JdbcEnvironment.class).getDialect();
basicTypeRegistry.register( new BlobType(dialect) );
basicTypeRegistry.register( new ClobType(dialect) );
}
private SessionFactory newLegacySessionFactory() {
Properties properties = properties();
Configuration configuration = new Configuration().addProperties(properties);
for (Class<?> entityClass : entities()) {
configuration.addAnnotatedClass(entityClass);
}
String[] packages = packages();
if (packages != null) {
for (String scannedPackage : packages) {
configuration.addPackage(scannedPackage);
}
}
String[] resources = resources();
if (resources != null) {
for (String resource : resources) {
configuration.addResource(resource);
}
}
Interceptor interceptor = interceptor();
if (interceptor != null) {
configuration.setInterceptor(interceptor);
}
final List<Type> additionalTypes = additionalTypes();
if (additionalTypes != null) {
configuration.registerTypeContributor(new TypeContributor() {
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
for (Type type : additionalTypes) {
if (type instanceof BasicType) {
typeContributions.contributeType((BasicType) type);
} else if (type instanceof UserType) {
typeContributions.contributeType((UserType) type);
} else if (type instanceof CompositeUserType) {
typeContributions.contributeType((CompositeUserType) type);
}
}
}
});
}
return configuration.buildSessionFactory(
new StandardServiceRegistryBuilder()
.applySettings(properties)
.build()
);
}
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
System.out.println("TypeContributor#contribute");
}
@Override
public void contribute(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
System.out.println("TypeContributor#contribute");
}
@Override
public void contributeTypes(TypeContributions typeContributions,
ServiceRegistry serviceRegistry) {
getInstance().contributeTypes(typeContributions, serviceRegistry);
}
/**
* Allows the Dialect to contribute additional types
*
* @param typeContributions Callback to contribute the types
* @param serviceRegistry The service registry
*/
public void contributeTypes(TypeContributions typeContributions, ServiceRegistry serviceRegistry) {
resolveLegacyLimitHandlerBehavior( serviceRegistry );
}