HHH-14563 Remove XmlMappingOptions
We don't need that anymore: XML mapping is either enabled or disabled, there are no other options. So a boolean will do.
This commit is contained in:
parent
6f5f6b32c3
commit
b076216e84
|
@ -30,7 +30,6 @@ import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
|
|||
import org.hibernate.boot.cfgxml.spi.CfgXmlAccessService;
|
||||
import org.hibernate.boot.cfgxml.spi.LoadedConfig;
|
||||
import org.hibernate.boot.cfgxml.spi.MappingReference;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.boot.model.TypeContributor;
|
||||
|
@ -623,7 +622,7 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
private IdGeneratorInterpreterImpl idGenerationTypeInterpreter = new IdGeneratorInterpreterImpl();
|
||||
|
||||
private String schemaCharset;
|
||||
private final XmlMappingOptions xmlMappingOptions;
|
||||
private final boolean xmlMappingEnabled;
|
||||
|
||||
public MetadataBuildingOptionsImpl(StandardServiceRegistry serviceRegistry) {
|
||||
this.serviceRegistry = serviceRegistry;
|
||||
|
@ -635,7 +634,11 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
|
||||
this.multiTenancyStrategy = MultiTenancyStrategy.determineMultiTenancyStrategy( configService.getSettings() );
|
||||
|
||||
xmlMappingOptions = XmlMappingOptions.get( serviceRegistry );
|
||||
this.xmlMappingEnabled = configService.getSetting(
|
||||
AvailableSettings.XML_MAPPING_ENABLED,
|
||||
StandardConverters.BOOLEAN,
|
||||
true
|
||||
);
|
||||
|
||||
this.implicitDiscriminatorsForJoinedInheritanceSupported = configService.getSetting(
|
||||
AvailableSettings.IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS,
|
||||
|
@ -923,8 +926,8 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont
|
|||
}
|
||||
|
||||
@Override
|
||||
public XmlMappingOptions getXmlMappingOptions() {
|
||||
return xmlMappingOptions;
|
||||
public boolean isXmlMappingEnabled() {
|
||||
return xmlMappingEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.boot.jaxb.internal;
|
||||
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
|
||||
public class DefaultXmlMappingOptions implements XmlMappingOptions {
|
||||
}
|
|
@ -19,7 +19,6 @@ import org.hibernate.boot.jaxb.internal.stax.HbmEventReader;
|
|||
import org.hibernate.boot.jaxb.internal.stax.JpaOrmXmlEventReader;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.boot.xsd.MappingXsdSupport;
|
||||
import org.hibernate.internal.util.config.ConfigurationException;
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
/*
|
||||
* Hibernate, Relational Persistence for Idiomatic Java
|
||||
*
|
||||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
|
||||
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
|
||||
*/
|
||||
package org.hibernate.boot.jaxb.spi;
|
||||
|
||||
import org.hibernate.boot.jaxb.internal.DefaultXmlMappingOptions;
|
||||
import org.hibernate.boot.registry.selector.spi.StrategySelector;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
* The options of XML mapping.
|
||||
* <p>
|
||||
* We're using an interface instead of simply configuration properties,
|
||||
* so that we can override the options easily in integrations (Quarkus)
|
||||
* and tests (to run the tests multiple times with different options).
|
||||
*/
|
||||
public interface XmlMappingOptions {
|
||||
|
||||
String DEFAULT_NAME = "default";
|
||||
|
||||
static XmlMappingOptions get(ServiceRegistry serviceRegistry) {
|
||||
final ConfigurationService configService = serviceRegistry.getService( ConfigurationService.class );
|
||||
|
||||
// The config service may be null if we're using a BootstrapServiceRegistry,
|
||||
// since configuration properties are unknown at that point.
|
||||
// That can happen with MetadataSources in particular,
|
||||
// because for some reason we allow MetadataSources to be built before the StandardServiceRegistry
|
||||
// (and Quarkus relies on that).
|
||||
// That's why we prefer to rely on strategies (see below):
|
||||
// they can be customized without relying on configuration properties
|
||||
// through the service loader.
|
||||
boolean xmlMappingEnabled = configService == null || configService.getSetting(
|
||||
AvailableSettings.XML_MAPPING_ENABLED,
|
||||
StandardConverters.BOOLEAN,
|
||||
true
|
||||
);
|
||||
|
||||
XmlMappingOptions result;
|
||||
if ( !xmlMappingEnabled ) {
|
||||
result = new XmlMappingOptions() {
|
||||
@Override
|
||||
public boolean isEnabled() {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
StrategySelector strategySelector = serviceRegistry.getService( StrategySelector.class );
|
||||
result = strategySelector.resolveDefaultableStrategy(
|
||||
XmlMappingOptions.class,
|
||||
XmlMappingOptions.DEFAULT_NAME,
|
||||
new DefaultXmlMappingOptions()
|
||||
);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to skip processing of XML Mapping.
|
||||
* This is for people using exclusively annotations to define their model, and might
|
||||
* be able to improve efficiency of booting Hibernate ORM.
|
||||
* By default, the XML mapping is taken into account.
|
||||
*/
|
||||
default boolean isEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -15,7 +15,6 @@ import org.hibernate.boot.MetadataSources;
|
|||
import org.hibernate.boot.internal.InFlightMetadataCollectorImpl;
|
||||
import org.hibernate.boot.internal.MetadataBuildingContextRootImpl;
|
||||
import org.hibernate.boot.jaxb.internal.MappingBinder;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.TypeContributions;
|
||||
import org.hibernate.boot.model.TypeContributor;
|
||||
import org.hibernate.boot.model.process.internal.ManagedResourcesImpl;
|
||||
|
@ -33,8 +32,11 @@ import org.hibernate.boot.spi.BootstrapContext;
|
|||
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
||||
import org.hibernate.boot.spi.MetadataContributor;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.cfg.MetadataSourceType;
|
||||
import org.hibernate.dialect.Dialect;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.engine.jdbc.spi.JdbcServices;
|
||||
import org.hibernate.type.BasicType;
|
||||
import org.hibernate.type.BasicTypeRegistry;
|
||||
|
@ -96,11 +98,16 @@ public class MetadataBuildingProcess {
|
|||
final MetadataSources sources,
|
||||
final BootstrapContext bootstrapContext) {
|
||||
final ManagedResourcesImpl managedResources = ManagedResourcesImpl.baseline( sources, bootstrapContext );
|
||||
XmlMappingOptions xmlMappingOptions = XmlMappingOptions.get( bootstrapContext.getServiceRegistry() );
|
||||
final ConfigurationService configService = bootstrapContext.getServiceRegistry().getService( ConfigurationService.class );
|
||||
final boolean xmlMappingEnabled = configService.getSetting(
|
||||
AvailableSettings.XML_MAPPING_ENABLED,
|
||||
StandardConverters.BOOLEAN,
|
||||
true
|
||||
);
|
||||
ScanningCoordinator.INSTANCE.coordinateScan(
|
||||
managedResources,
|
||||
bootstrapContext,
|
||||
xmlMappingOptions.isEnabled() ? sources.getXmlMappingBinderAccess() : null
|
||||
xmlMappingEnabled ? sources.getXmlMappingBinderAccess() : null
|
||||
);
|
||||
return managedResources;
|
||||
}
|
||||
|
@ -150,7 +157,7 @@ public class MetadataBuildingProcess {
|
|||
|
||||
final MetadataSourceProcessor processor = new MetadataSourceProcessor() {
|
||||
private final MetadataSourceProcessor hbmProcessor =
|
||||
options.getXmlMappingOptions().isEnabled()
|
||||
options.isXmlMappingEnabled()
|
||||
? new HbmMetadataSourceProcessorImpl( managedResources, rootMetadataBuildingContext )
|
||||
: new NoOpMetadataSourceProcessorImpl();
|
||||
|
||||
|
@ -287,9 +294,8 @@ public class MetadataBuildingProcess {
|
|||
|
||||
metadataCollector.processSecondPasses( rootMetadataBuildingContext );
|
||||
|
||||
XmlMappingOptions xmlMappingOptions = options.getXmlMappingOptions();
|
||||
if ( xmlMappingOptions.isEnabled() ) {
|
||||
Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class );
|
||||
if ( options.isXmlMappingEnabled() ) {
|
||||
final Iterable<AdditionalJaxbMappingProducer> producers = classLoaderService.loadJavaServices( AdditionalJaxbMappingProducer.class );
|
||||
if ( producers != null ) {
|
||||
final EntityHierarchyBuilder hierarchyBuilder = new EntityHierarchyBuilder();
|
||||
// final MappingBinder mappingBinder = new MappingBinder( true );
|
||||
|
|
|
@ -24,7 +24,6 @@ import org.hibernate.boot.AttributeConverterInfo;
|
|||
import org.hibernate.boot.internal.MetadataBuildingContextRootImpl;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.convert.spi.ConverterDescriptor;
|
||||
import org.hibernate.boot.model.process.spi.ManagedResources;
|
||||
import org.hibernate.boot.model.source.spi.MetadataSourceProcessor;
|
||||
|
@ -77,8 +76,7 @@ public class AnnotationMetadataSourceProcessorImpl implements MetadataSourceProc
|
|||
this.classLoaderService = rootMetadataBuildingContext.getBuildingOptions().getServiceRegistry().getService( ClassLoaderService.class );
|
||||
|
||||
MetadataBuildingOptions metadataBuildingOptions = rootMetadataBuildingContext.getBuildingOptions();
|
||||
XmlMappingOptions xmlMappingOptions = metadataBuildingOptions.getXmlMappingOptions();
|
||||
if ( xmlMappingOptions.isEnabled() ) {
|
||||
if ( metadataBuildingOptions.isXmlMappingEnabled() ) {
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
// Ewww. This is temporary until we migrate to Jandex + StAX for annotation binding
|
||||
final JPAXMLOverriddenMetadataProvider jpaMetadataProvider = (JPAXMLOverriddenMetadataProvider) ( (MetadataProviderInjector) reflectionManager )
|
||||
|
|
|
@ -9,8 +9,6 @@ package org.hibernate.boot.registry.selector.internal;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.hibernate.boot.jaxb.internal.DefaultXmlMappingOptions;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
|
||||
|
@ -102,8 +100,6 @@ public class StrategySelectorBuilder {
|
|||
addMultiTableBulkIdStrategies( strategySelector );
|
||||
addImplicitNamingStrategies( strategySelector );
|
||||
addCacheKeysFactories( strategySelector );
|
||||
strategySelector.registerStrategyImplementor( XmlMappingOptions.class, XmlMappingOptions.DEFAULT_NAME,
|
||||
DefaultXmlMappingOptions.class );
|
||||
|
||||
// apply auto-discovered registrations
|
||||
for ( StrategyRegistrationProvider provider : classLoaderService.loadJavaServices( StrategyRegistrationProvider.class ) ) {
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.hibernate.boot.CacheRegionDefinition;
|
|||
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
|
||||
import org.hibernate.boot.archive.scan.spi.ScanOptions;
|
||||
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
|
||||
|
@ -204,8 +203,8 @@ public abstract class AbstractDelegatingMetadataBuildingOptions implements Metad
|
|||
}
|
||||
|
||||
@Override
|
||||
public XmlMappingOptions getXmlMappingOptions() {
|
||||
return delegate.getXmlMappingOptions();
|
||||
public boolean isXmlMappingEnabled() {
|
||||
return delegate.isXmlMappingEnabled();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.hibernate.boot.CacheRegionDefinition;
|
|||
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
|
||||
import org.hibernate.boot.archive.scan.spi.ScanOptions;
|
||||
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.IdGeneratorStrategyInterpreter;
|
||||
import org.hibernate.boot.model.naming.ImplicitNamingStrategy;
|
||||
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
|
||||
|
@ -252,8 +251,8 @@ public interface MetadataBuildingOptions {
|
|||
return null;
|
||||
}
|
||||
|
||||
default XmlMappingOptions getXmlMappingOptions() {
|
||||
return XmlMappingOptions.get( getServiceRegistry() );
|
||||
default boolean isXmlMappingEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,11 +20,7 @@ import org.hibernate.boot.jaxb.internal.InputStreamXmlSource;
|
|||
import org.hibernate.boot.jaxb.internal.MappingBinder;
|
||||
import org.hibernate.boot.jaxb.internal.UrlXmlSource;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
|
||||
import org.hibernate.cfg.AvailableSettings;
|
||||
import org.hibernate.engine.config.spi.ConfigurationService;
|
||||
import org.hibernate.engine.config.spi.StandardConverters;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import org.jboss.logging.Logger;
|
||||
|
|
|
@ -26,7 +26,6 @@ import org.hibernate.annotations.common.reflection.java.JavaMetadataProvider;
|
|||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbSequenceGenerator;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbTableGenerator;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
|
||||
import org.hibernate.boot.spi.BootstrapContext;
|
||||
import org.hibernate.boot.spi.ClassLoaderAccess;
|
||||
|
@ -48,7 +47,7 @@ public final class JPAXMLOverriddenMetadataProvider implements MetadataProvider
|
|||
* We allow fully disabling XML sources so to improve the efficiency of
|
||||
* the boot process for those not using it.
|
||||
*/
|
||||
private final XmlMappingOptions xmlMappingOptions;
|
||||
private final boolean xmlMappingEnabled;
|
||||
|
||||
private Map<Object, Object> defaults;
|
||||
private Map<AnnotatedElement, AnnotationReader> cache;
|
||||
|
@ -56,7 +55,7 @@ public final class JPAXMLOverriddenMetadataProvider implements MetadataProvider
|
|||
public JPAXMLOverriddenMetadataProvider(BootstrapContext bootstrapContext) {
|
||||
this.classLoaderAccess = bootstrapContext.getClassLoaderAccess();
|
||||
this.xmlContext = new XMLContext( classLoaderAccess );
|
||||
this.xmlMappingOptions = bootstrapContext.getMetadataBuildingOptions().getXmlMappingOptions();
|
||||
this.xmlMappingEnabled = bootstrapContext.getMetadataBuildingOptions().isXmlMappingEnabled();
|
||||
}
|
||||
|
||||
//all of the above can be safely rebuilt from XMLContext: only XMLContext this object is serialized
|
||||
|
@ -89,7 +88,7 @@ public final class JPAXMLOverriddenMetadataProvider implements MetadataProvider
|
|||
|
||||
@Override
|
||||
public Map<Object, Object> getDefaults() {
|
||||
if ( !xmlMappingOptions.isEnabled() ) {
|
||||
if ( !xmlMappingEnabled ) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -14,10 +14,6 @@ import org.hibernate.boot.jaxb.SourceType;
|
|||
import org.hibernate.boot.jaxb.internal.MappingBinder;
|
||||
import org.hibernate.boot.jaxb.mapping.spi.JaxbEntityMappings;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistry;
|
||||
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
|
||||
import org.hibernate.service.spi.ServiceRegistryImplementor;
|
||||
|
||||
import org.hibernate.testing.boot.ClassLoaderServiceTestingImpl;
|
||||
import org.junit.Assert;
|
||||
|
|
|
@ -24,21 +24,18 @@ import org.hibernate.boot.jaxb.SourceType;
|
|||
import org.hibernate.boot.jaxb.hbm.spi.JaxbHbmHibernateMapping;
|
||||
import org.hibernate.boot.jaxb.internal.MappingBinder;
|
||||
import org.hibernate.boot.jaxb.spi.Binding;
|
||||
import org.hibernate.boot.jaxb.spi.XmlMappingOptions;
|
||||
import org.hibernate.boot.model.source.internal.hbm.MappingDocument;
|
||||
import org.hibernate.boot.spi.AdditionalJaxbMappingProducer;
|
||||
import org.hibernate.boot.spi.MetadataBuildingContext;
|
||||
import org.hibernate.boot.spi.MetadataBuildingOptions;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.envers.configuration.internal.MappingCollector;
|
||||
import org.hibernate.internal.util.config.ConfigurationHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
import org.jboss.jandex.IndexView;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.io.OutputFormat;
|
||||
import org.dom4j.io.XMLWriter;
|
||||
|
||||
|
@ -65,7 +62,7 @@ public class AdditionalJaxbMappingProducerImpl implements AdditionalJaxbMappingP
|
|||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
if ( !metadataBuildingOptions.getXmlMappingOptions().isEnabled() ) {
|
||||
if ( !metadataBuildingOptions.isXmlMappingEnabled() ) {
|
||||
throw new HibernateException( "Hibernate Envers currently requires XML mapping to be enabled."
|
||||
+ " Please don't disable setting `" + XML_MAPPING_ENABLED
|
||||
+ "`; alternatively disable Hibernate Envers." );
|
||||
|
|
Loading…
Reference in New Issue