From 2d9caaf030bb49c132733751687d686bf1f48074 Mon Sep 17 00:00:00 2001 From: Andrea Boriero Date: Tue, 21 Jun 2016 17:11:13 +0200 Subject: [PATCH] HHH-10837 - Changed new setting name to hibernate.jpa.static_metamodel.population --- .../org/hibernate/cfg/AvailableSettings.java | 34 +++++++---- .../JpaStaticMetaModelPopulationSetting.java | 57 +++++++++++++++++++ .../metamodel/internal/MetadataContext.java | 12 ++-- 3 files changed, 85 insertions(+), 18 deletions(-) create mode 100644 hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaStaticMetaModelPopulationSetting.java diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java index d2333da20d..b34e16b61a 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/AvailableSettings.java @@ -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: + * + * + */ + @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: - * */ - 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"; } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaStaticMetaModelPopulationSetting.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaStaticMetaModelPopulationSetting.java new file mode 100644 index 0000000000..d08dcb1d11 --- /dev/null +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/JpaStaticMetaModelPopulationSetting.java @@ -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 . + */ +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 ); + } +} diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index f9652496f3..bfaaf5f511 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -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 ); }