diff --git a/documentation/src/main/asciidoc/introduction/Configuration.adoc b/documentation/src/main/asciidoc/introduction/Configuration.adoc index 161b8799a0..cd7585f111 100644 --- a/documentation/src/main/asciidoc/introduction/Configuration.adoc +++ b/documentation/src/main/asciidoc/introduction/Configuration.adoc @@ -221,9 +221,9 @@ SessionFactory sessionFactory = .setProperty(AvailableSettings.JAKARTA_HBM2DDL_DATABASE_ACTION, Action.SPEC_ACTION_DROP_AND_CREATE) // SQL statement logging - .setProperty(AvailableSettings.SHOW_SQL, TRUE.toString()) - .setProperty(AvailableSettings.FORMAT_SQL, TRUE.toString()) - .setProperty(AvailableSettings.HIGHLIGHT_SQL, TRUE.toString()) + .setProperty(AvailableSettings.SHOW_SQL, true) + .setProperty(AvailableSettings.FORMAT_SQL, true) + .setProperty(AvailableSettings.HIGHLIGHT_SQL, true) // Create a new SessionFactory .buildSessionFactory(); ---- diff --git a/documentation/src/main/asciidoc/introduction/Introduction.adoc b/documentation/src/main/asciidoc/introduction/Introduction.adoc index 7269e08b20..d7d33e0978 100644 --- a/documentation/src/main/asciidoc/introduction/Introduction.adoc +++ b/documentation/src/main/asciidoc/introduction/Introduction.adoc @@ -254,11 +254,11 @@ public class Main { .setProperty(USER, "sa") .setProperty(PASS, "") // use Agroal connection pool - .setProperty("hibernate.agroal.maxSize", "20") + .setProperty("hibernate.agroal.maxSize", 20) // display SQL in console - .setProperty(SHOW_SQL, TRUE.toString()) - .setProperty(FORMAT_SQL, TRUE.toString()) - .setProperty(HIGHLIGHT_SQL, TRUE.toString()) + .setProperty(SHOW_SQL, true) + .setProperty(FORMAT_SQL, true) + .setProperty(HIGHLIGHT_SQL, true) .buildSessionFactory(); // export the inferred database schema diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java index 0619c813d0..99a54a2842 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java @@ -129,6 +129,7 @@ import static org.hibernate.cfg.AvailableSettings.USE_SQL_COMMENTS; import static org.hibernate.cfg.AvailableSettings.USE_STRUCTURED_CACHE; import static org.hibernate.cfg.AvailableSettings.USE_SUBSELECT_FETCH; import static org.hibernate.cfg.CacheSettings.QUERY_CACHE_LAYOUT; +import static org.hibernate.cfg.QuerySettings.DEFAULT_NULL_ORDERING; import static org.hibernate.cfg.QuerySettings.PORTABLE_INTEGER_DIVISION; import static org.hibernate.engine.config.spi.StandardConverters.BOOLEAN; import static org.hibernate.internal.CoreLogging.messageLogger; @@ -377,10 +378,19 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { this.defaultBatchFetchSize = getInt( DEFAULT_BATCH_FETCH_SIZE, configurationSettings, -1 ); this.subselectFetchEnabled = getBoolean( USE_SUBSELECT_FETCH, configurationSettings ); this.maximumFetchDepth = getInteger( MAX_FETCH_DEPTH, configurationSettings ); - final String defaultNullPrecedence = getString( - AvailableSettings.DEFAULT_NULL_ORDERING, configurationSettings, "none", "first", "last" - ); - this.defaultNullPrecedence = NullPrecedence.parse( defaultNullPrecedence ); + + final Object defaultNullPrecedence = configurationSettings.get( DEFAULT_NULL_ORDERING ); + if ( defaultNullPrecedence instanceof NullPrecedence ) { + this.defaultNullPrecedence = (NullPrecedence) defaultNullPrecedence; + } + else if ( defaultNullPrecedence instanceof String ) { + this.defaultNullPrecedence = NullPrecedence.parse( (String) defaultNullPrecedence ); + } + else if ( defaultNullPrecedence != null ) { + throw new IllegalArgumentException( "Configuration property " + DEFAULT_NULL_ORDERING + + " value [" + defaultNullPrecedence + "] is not supported" ); + } + this.orderUpdatesEnabled = getBoolean( ORDER_UPDATES, configurationSettings ); this.orderInsertsEnabled = getBoolean( ORDER_INSERTS, configurationSettings ); @@ -558,7 +568,8 @@ public class SessionFactoryOptionsBuilder implements SessionFactoryOptions { this.jdbcTimeZone = TimeZone.getTimeZone( ZoneId.of((String) jdbcTimeZoneValue) ); } else if ( jdbcTimeZoneValue != null ) { - throw new IllegalArgumentException( "Configuration property " + JDBC_TIME_ZONE + " value [" + jdbcTimeZoneValue + "] is not supported" ); + throw new IllegalArgumentException( "Configuration property " + JDBC_TIME_ZONE + + " value [" + jdbcTimeZoneValue + "] is not supported" ); } this.criteriaValueHandlingMode = ValueHandlingMode.interpret( diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java index 74aa2d1a67..ae9028a827 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/Configuration.java @@ -283,6 +283,62 @@ public class Configuration { return this; } + /** + * Set a property to a boolean value by name + * + * @param propertyName The name of the property to set + * @param value The new boolean property value + * + * @return {@code this} for method chaining + * + * @since 6.5 + */ + public Configuration setProperty(String propertyName, boolean value) { + return setProperty( propertyName, Boolean.toString(value) ); + } + + /** + * Set a property to a Java class name + * + * @param propertyName The name of the property to set + * @param value The Java class + * + * @return {@code this} for method chaining + * + * @since 6.5 + */ + public Configuration setProperty(String propertyName, Class value) { + return setProperty( propertyName, value.getName() ); + } + + /** + * Set a property to the name of a value of an enumerated type + * + * @param propertyName The name of the property to set + * @param value A value of an enumerated type + * + * @return {@code this} for method chaining + * + * @since 6.5 + */ + public Configuration setProperty(String propertyName, Enum value) { + return setProperty( propertyName, value.name() ); + } + + /** + * Set a property to an integer value by name + * + * @param propertyName The name of the property to set + * @param value The new integer property value + * + * @return {@code this} for method chaining + * + * @since 6.5 + */ + public Configuration setProperty(String propertyName, int value) { + return setProperty( propertyName, Integer.toString(value) ); + } + /** * Add the given properties to ours. * diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/QuerySettings.java b/hibernate-core/src/main/java/org/hibernate/cfg/QuerySettings.java index 28422dfbaa..0590cc0295 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/QuerySettings.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/QuerySettings.java @@ -98,8 +98,9 @@ public interface QuerySettings { String CRITERIA_VALUE_HANDLING_MODE = "hibernate.criteria.value_handling_mode"; /** - * Specifies the default {@linkplain NullPrecedence precedence of null values} in the HQL - * {@code ORDER BY} clause, either {@code none}, {@code first}, or {@code last}. + * Specifies the default {@linkplain NullPrecedence precedence of null values} in the + * HQL {@code ORDER BY} clause, either {@code none}, {@code first}, or {@code last}, + * or an instance of {@link NullPrecedence}. *

* The default is {@code none}. * diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/config/ConfigurationHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/config/ConfigurationHelper.java index 9cc4716db5..9b7bd2a29d 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/config/ConfigurationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/config/ConfigurationHelper.java @@ -88,30 +88,6 @@ public final class ConfigurationHelper { return defaultValueSupplier.get(); } - /** - * Get the config value as a {@link String}. - * - * @param name The config setting name. - * @param values The map of config parameters. - * @param defaultValue The default value to use if not found. - * @param otherSupportedValues List of other supported values. Does not need to contain the default one. - * - * @return The value. - * - * @throws ConfigurationException Unsupported value provided. - * - */ - public static String getString(String name, Map values, String defaultValue, String ... otherSupportedValues) { - final String value = getString( name, values, defaultValue ); - if ( !defaultValue.equals( value ) && ArrayHelper.indexOf( otherSupportedValues, value ) == -1 ) { - throw new ConfigurationException( - "Unsupported configuration [name=" + name + ", value=" + value + "]. " + - "Choose value between: '" + defaultValue + "', '" + String.join( "', '", otherSupportedValues ) + "'." - ); - } - return value; - } - /** * Get the config value as a boolean (default of false) * diff --git a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java index 670359cf1b..ba703aabb7 100644 --- a/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java +++ b/hibernate-testing/src/main/java/org/hibernate/testing/junit4/BaseCoreFunctionalTestCase.java @@ -191,10 +191,10 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase { } } configuration.setImplicitNamingStrategy( ImplicitNamingStrategyLegacyJpaImpl.INSTANCE ); - configuration.setProperty( Environment.DIALECT, getDialect().getClass().getName() ); - configuration.getProperties().put( PersistentTableStrategy.DROP_ID_TABLES, "true" ); - configuration.getProperties().put( GlobalTemporaryTableMutationStrategy.DROP_ID_TABLES, "true" ); - configuration.getProperties().put( LocalTemporaryTableMutationStrategy.DROP_ID_TABLES, "true" ); + configuration.setProperty( Environment.DIALECT, getDialect().getClass() ); + configuration.getProperties().put( PersistentTableStrategy.DROP_ID_TABLES, true ); + configuration.getProperties().put( GlobalTemporaryTableMutationStrategy.DROP_ID_TABLES, true ); + configuration.getProperties().put( LocalTemporaryTableMutationStrategy.DROP_ID_TABLES, true ); ServiceRegistryUtil.applySettings( configuration.getStandardServiceRegistryBuilder() ); return configuration; }