HHH-14881 Allow providing attribute converters through CDI when configured through orm.xml
This commit is contained in:
parent
fc636995c3
commit
7cc0c8370b
|
@ -54,7 +54,7 @@ public final class JPAXMLOverriddenMetadataProvider implements MetadataProvider
|
||||||
|
|
||||||
public JPAXMLOverriddenMetadataProvider(BootstrapContext bootstrapContext) {
|
public JPAXMLOverriddenMetadataProvider(BootstrapContext bootstrapContext) {
|
||||||
this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
|
this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
|
||||||
this.xmlContext = new XMLContext( classLoaderAccess );
|
this.xmlContext = new XMLContext( bootstrapContext );
|
||||||
this.xmlMappingEnabled = bootstrapContext.getMetadataBuildingOptions().isXmlMappingEnabled();
|
this.xmlMappingEnabled = bootstrapContext.getMetadataBuildingOptions().isXmlMappingEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import javax.persistence.AccessType;
|
||||||
import javax.persistence.AttributeConverter;
|
import javax.persistence.AttributeConverter;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
import org.hibernate.boot.AttributeConverterInfo;
|
import org.hibernate.boot.internal.ClassmateContext;
|
||||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbConverter;
|
import org.hibernate.boot.jaxb.mapping.spi.JaxbConverter;
|
||||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity;
|
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntity;
|
||||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListener;
|
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityListener;
|
||||||
|
@ -25,10 +25,11 @@ import org.hibernate.boot.jaxb.mapping.spi.JaxbMappedSuperclass;
|
||||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults;
|
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitDefaults;
|
||||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata;
|
import org.hibernate.boot.jaxb.mapping.spi.JaxbPersistenceUnitMetadata;
|
||||||
import org.hibernate.boot.jaxb.mapping.spi.ManagedType;
|
import org.hibernate.boot.jaxb.mapping.spi.ManagedType;
|
||||||
|
import org.hibernate.boot.model.convert.internal.ClassBasedConverterDescriptor;
|
||||||
|
import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
|
||||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||||
import org.hibernate.boot.spi.BootstrapContext;
|
import org.hibernate.boot.spi.BootstrapContext;
|
||||||
import org.hibernate.boot.spi.ClassLoaderAccess;
|
import org.hibernate.boot.spi.ClassLoaderAccess;
|
||||||
import org.hibernate.cfg.AttributeConverterDefinition;
|
|
||||||
import org.hibernate.cfg.annotations.reflection.AttributeConverterDefinitionCollector;
|
import org.hibernate.cfg.annotations.reflection.AttributeConverterDefinitionCollector;
|
||||||
import org.hibernate.internal.CoreLogging;
|
import org.hibernate.internal.CoreLogging;
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
@ -44,6 +45,7 @@ public class XMLContext implements Serializable {
|
||||||
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( XMLContext.class );
|
private static final CoreMessageLogger LOG = CoreLogging.messageLogger( XMLContext.class );
|
||||||
|
|
||||||
private final ClassLoaderAccess classLoaderAccess;
|
private final ClassLoaderAccess classLoaderAccess;
|
||||||
|
private final ClassmateContext classmateContext;
|
||||||
|
|
||||||
private Default globalDefaults;
|
private Default globalDefaults;
|
||||||
private final Map<String, ManagedType> managedTypeOverride = new HashMap<>();
|
private final Map<String, ManagedType> managedTypeOverride = new HashMap<>();
|
||||||
|
@ -53,16 +55,9 @@ public class XMLContext implements Serializable {
|
||||||
private final List<String> defaultEntityListeners = new ArrayList<>();
|
private final List<String> defaultEntityListeners = new ArrayList<>();
|
||||||
private boolean hasContext = false;
|
private boolean hasContext = false;
|
||||||
|
|
||||||
/**
|
|
||||||
* @deprecated Use {@link #XMLContext(BootstrapContext)} instead.
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public XMLContext(ClassLoaderAccess classLoaderAccess) {
|
|
||||||
this.classLoaderAccess = classLoaderAccess;
|
|
||||||
}
|
|
||||||
|
|
||||||
public XMLContext(BootstrapContext bootstrapContext) {
|
public XMLContext(BootstrapContext bootstrapContext) {
|
||||||
this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
|
this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
|
||||||
|
this.classmateContext = bootstrapContext.getClassmateContext();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,8 +172,8 @@ public class XMLContext implements Serializable {
|
||||||
final Class<? extends AttributeConverter> attributeConverterClass = classLoaderAccess.classForName(
|
final Class<? extends AttributeConverter> attributeConverterClass = classLoaderAccess.classForName(
|
||||||
buildSafeClassName( className, packageName )
|
buildSafeClassName( className, packageName )
|
||||||
);
|
);
|
||||||
attributeConverterInfoList.add(
|
converterDescriptors.add(
|
||||||
new AttributeConverterDefinition( attributeConverterClass.newInstance(), autoApply )
|
new ClassBasedConverterDescriptor( attributeConverterClass, autoApply, classmateContext )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (ClassLoadingException e) {
|
catch (ClassLoadingException e) {
|
||||||
|
@ -227,13 +222,13 @@ public class XMLContext implements Serializable {
|
||||||
return hasContext;
|
return hasContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<AttributeConverterInfo> attributeConverterInfoList = new ArrayList<>();
|
private List<ConverterDescriptor> converterDescriptors = new ArrayList<>();
|
||||||
|
|
||||||
public void applyDiscoveredAttributeConverters(AttributeConverterDefinitionCollector collector) {
|
public void applyDiscoveredAttributeConverters(AttributeConverterDefinitionCollector collector) {
|
||||||
for ( AttributeConverterInfo info : attributeConverterInfoList ) {
|
for ( ConverterDescriptor descriptor : converterDescriptors ) {
|
||||||
collector.addAttributeConverter( info );
|
collector.addAttributeConverter( descriptor );
|
||||||
}
|
}
|
||||||
attributeConverterInfoList.clear();
|
converterDescriptors.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Default implements Serializable {
|
public static class Default implements Serializable {
|
||||||
|
|
Loading…
Reference in New Issue