HHH-10837 - Changed new setting name to hibernate.jpa.static_metamodel.population

This commit is contained in:
Andrea Boriero 2016-06-21 17:11:13 +02:00
parent 1558eb73a6
commit 2d9caaf030
3 changed files with 85 additions and 18 deletions

View File

@ -230,23 +230,42 @@ public interface AvailableSettings {
@Deprecated
String JPA_METAMODEL_GENERATION = "hibernate.ejb.metamodel.generation";
/**
* Setting that indicates whether to build the JPA types. Accepts
* 3 values:<ul>
* <li>
* <b>enabled</b> - Do the build
* </li>
* <li>
* <b>disabled</b> - Do not so the build
* </li>
* <li>
* <b>ignoreUnsupported</b> - Do the build, but ignore any non-JPA features that would otherwise
* result in a failure.
* </li>
* </ul>
*
*
*/
@Deprecated
String JPA_METAMODEL_POPULATION = "hibernate.ejb.metamodel.population";
/**
* Setting that controls whether we seek out JPA "static metamodel" classes and populate them. Accepts
* 3 values:<ul>
* <li>
* <b>enabled</b> - Do the population
* <b>enabled</b> -Do the population
* </li>
* <li>
* <b>disabled</b> - Do not do the population
* </li>
* <li>
* <b>ignoreUnsupported</b> - Do the population, but ignore any non-JPA features that would otherwise
* <b>skipUnsupported</b> - Do the population, but ignore any non-JPA features that would otherwise
* result in the population failing.
* </li>
* </ul>
*
*/
String JPA_METAMODEL_POPULATION = "hibernate.ejb.metamodel.population";
String STATIC_METAMODEL_POPULATION = "hibernate.jpa.static_metamodel.population";
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -1492,11 +1511,4 @@ public interface AvailableSettings {
*/
String ALLOW_JTA_TRANSACTION_ACCESS = "hibernate.jta.allowTransactionAccess";
/**
* A setting to control whether Hibernate should scan for a static metamodel
* or not. The default is {@code true}, i.e. Hibernate scans for static metamodel.
* If you don't use a static metamodel in your project, then you can set this setting
* to {@code false} to speed up deployment of your project.
*/
String STATIC_METAMODEL_ENABLED = "hibernate.static_metamodel.enabled";
}

View File

@ -0,0 +1,57 @@
/*
* 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.metamodel.internal;
import java.util.Map;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.internal.util.config.ConfigurationHelper;
/**
* Enumerated setting used to control whether Hibernate looks for and populates
* JPA static metamodel models of application's domain model.
*
* @author Andrea Boriero
*/
public enum JpaStaticMetaModelPopulationSetting {
/**
* ENABLED indicates that Hibernate will look for the JPA static metamodel description
* of the application domain model and populate it.
*/
ENABLED,
/**
* DISABLED indicates that Hibernate will not look for the JPA static metamodel description
* of the application domain model.
*/
DISABLED,
/**
* SKIP_UNSUPPORTED works as ENABLED but ignores any non-JPA features that would otherwise
* result in the population failing.
*/
SKIP_UNSUPPORTED;
public static JpaStaticMetaModelPopulationSetting parse(String setting) {
if ( "enabled".equalsIgnoreCase( setting ) ) {
return ENABLED;
}
else if ( "disabled".equalsIgnoreCase( setting ) ) {
return DISABLED;
}
else {
return SKIP_UNSUPPORTED;
}
}
public static JpaStaticMetaModelPopulationSetting determineJpaMetaModelPopulationSetting(Map configurationValues) {
String setting = ConfigurationHelper.getString(
AvailableSettings.STATIC_METAMODEL_POPULATION,
configurationValues,
null
);
return JpaStaticMetaModelPopulationSetting.parse( setting );
}
}

View File

@ -22,7 +22,6 @@ import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type;
import org.hibernate.annotations.common.AssertionFailure;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.EntityManagerMessageLogger;
import org.hibernate.internal.HEMLogging;
@ -183,9 +182,8 @@ class MetadataContext {
LOG.trace( "Wrapping up metadata context..." );
}
boolean staticMetamodelEnabled = Boolean.parseBoolean(
sessionFactory.getProperties().getOrDefault(
AvailableSettings.STATIC_METAMODEL_ENABLED, "true" ).toString() );
boolean staticMetamodelScanEnabled = JpaStaticMetaModelPopulationSetting
.determineJpaMetaModelPopulationSetting( sessionFactory.getProperties() ) != JpaStaticMetaModelPopulationSetting.DISABLED;
//we need to process types from superclasses to subclasses
for ( Object mapping : orderedMappings ) {
@ -218,7 +216,7 @@ class MetadataContext {
}
}
jpa2Mapping.lock();
if ( staticMetamodelEnabled ) {
if ( staticMetamodelScanEnabled ) {
populateStaticMetamodel( jpa2Mapping );
}
}
@ -253,7 +251,7 @@ class MetadataContext {
}
}
jpa2Mapping.lock();
if ( staticMetamodelEnabled ) {
if ( staticMetamodelScanEnabled ) {
populateStaticMetamodel( jpa2Mapping );
}
}
@ -268,7 +266,7 @@ class MetadataContext {
}
}
if ( staticMetamodelEnabled ) {
if ( staticMetamodelScanEnabled ) {
for ( EmbeddableTypeImpl embeddable : embeddables.values() ) {
populateStaticMetamodel( embeddable );
}