HHH-14020 - Allow Hibernate Types to have access to ServiceRegistry during initialization
This commit is contained in:
parent
e23dad19ca
commit
abad664218
|
@ -17,6 +17,7 @@ import org.hibernate.classic.Lifecycle;
|
|||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.tuple.component.ComponentMetamodel;
|
||||
import org.hibernate.type.spi.TypeBootstrapContext;
|
||||
import org.hibernate.type.spi.TypeConfiguration;
|
||||
|
@ -94,15 +95,24 @@ public final class TypeFactory implements Serializable, TypeBootstrapContext {
|
|||
try {
|
||||
final Type type;
|
||||
|
||||
final Constructor<Type> bootstrapContextAwareTypeConstructor = ReflectHelper.getConstructor(
|
||||
Constructor<Type> contextAwareTypeConstructor = ReflectHelper.getConstructor(
|
||||
typeClass,
|
||||
TypeBootstrapContext.class
|
||||
ServiceRegistry.class
|
||||
);
|
||||
if ( bootstrapContextAwareTypeConstructor != null ) {
|
||||
type = bootstrapContextAwareTypeConstructor.newInstance( this );
|
||||
if ( contextAwareTypeConstructor != null ) {
|
||||
type = contextAwareTypeConstructor.newInstance( this.typeConfiguration.getServiceRegistry() );
|
||||
}
|
||||
else {
|
||||
type = typeClass.newInstance();
|
||||
contextAwareTypeConstructor = ReflectHelper.getConstructor(
|
||||
typeClass,
|
||||
TypeBootstrapContext.class
|
||||
);
|
||||
if ( contextAwareTypeConstructor != null ) {
|
||||
type = contextAwareTypeConstructor.newInstance( this );
|
||||
}
|
||||
else {
|
||||
type = typeClass.newInstance();
|
||||
}
|
||||
}
|
||||
|
||||
injectParameters( type, parameters );
|
||||
|
|
|
@ -3,10 +3,11 @@ package org.hibernate.test.type.contributor;
|
|||
import java.util.Map;
|
||||
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
|
||||
import org.hibernate.type.DiscriminatorType;
|
||||
import org.hibernate.type.descriptor.sql.VarcharTypeDescriptor;
|
||||
import org.hibernate.type.spi.TypeBootstrapContext;
|
||||
|
||||
/**
|
||||
* @author Vlad Mihalcea
|
||||
|
@ -23,9 +24,10 @@ public class ArrayType
|
|||
super( VarcharTypeDescriptor.INSTANCE, ArrayTypeDescriptor.INSTANCE );
|
||||
}
|
||||
|
||||
public ArrayType(TypeBootstrapContext typeBootstrapContext) {
|
||||
public ArrayType(ServiceRegistry serviceRegistry) {
|
||||
super( VarcharTypeDescriptor.INSTANCE, ArrayTypeDescriptor.INSTANCE );
|
||||
this.settings = typeBootstrapContext.getConfigurationSettings();
|
||||
ConfigurationService configurationService = serviceRegistry.getService( ConfigurationService.class );
|
||||
this.settings = configurationService.getSettings();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue