diff --git a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationEventListener.java b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationEventListener.java index 6e2cc3d9c3..df6c445729 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationEventListener.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/BeanValidationEventListener.java @@ -24,7 +24,6 @@ import org.hibernate.event.spi.PreUpdateEventListener; import org.hibernate.event.spi.PreUpsertEvent; import org.hibernate.event.spi.PreUpsertEventListener; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.RepresentationMode; import org.hibernate.persister.entity.EntityPersister; @@ -33,10 +32,12 @@ import org.jboss.logging.Logger; import jakarta.validation.ConstraintViolation; import jakarta.validation.ConstraintViolationException; import jakarta.validation.TraversableResolver; -import jakarta.validation.Validation; import jakarta.validation.Validator; import jakarta.validation.ValidatorFactory; +import static jakarta.validation.Validation.buildDefaultValidatorFactory; +import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize; + /** * Event listener used to enable Bean Validation for insert/update/delete events. * @@ -71,8 +72,7 @@ public class BeanValidationEventListener public void initialize(Map settings, ClassLoaderService classLoaderService) { if ( !initialized ) { - ValidatorFactory factory = Validation.buildDefaultValidatorFactory(); - init( factory, settings, classLoaderService ); + init( buildDefaultValidatorFactory(), settings, classLoaderService ); } } @@ -138,15 +138,15 @@ public class BeanValidationEventListener final Class[] groups = groupsPerOperation.get( operation ); if ( groups.length > 0 ) { final Set> constraintViolations = validator.validate( object, groups ); - if ( constraintViolations.size() > 0 ) { - Set> propagatedViolations = CollectionHelper.setOfSize( constraintViolations.size() ); - Set classNames = new HashSet<>(); + if ( !constraintViolations.isEmpty() ) { + final Set> propagatedViolations = setOfSize( constraintViolations.size() ); + final Set classNames = new HashSet<>(); for ( ConstraintViolation violation : constraintViolations ) { LOG.trace( violation ); propagatedViolations.add( violation ); classNames.add( violation.getLeafBean().getClass().getName() ); } - StringBuilder builder = new StringBuilder(); + final StringBuilder builder = new StringBuilder(); builder.append( "Validation failed for classes " ); builder.append( classNames ); builder.append( " during " ); @@ -154,20 +154,18 @@ public class BeanValidationEventListener builder.append( " time for groups " ); builder.append( toString( groups ) ); builder.append( "\nList of constraint violations:[\n" ); - for (ConstraintViolation violation : constraintViolations) { + for ( ConstraintViolation violation : constraintViolations ) { builder.append( "\t" ).append( violation.toString() ).append("\n"); } builder.append( "]" ); - throw new ConstraintViolationException( - builder.toString(), propagatedViolations - ); + throw new ConstraintViolationException( builder.toString(), propagatedViolations ); } } } private String toString(Class[] groups) { - StringBuilder toString = new StringBuilder( "[" ); + final StringBuilder toString = new StringBuilder( "[" ); for ( Class group : groups ) { toString.append( group.getName() ).append( ", " ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/GroupsPerOperation.java b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/GroupsPerOperation.java index d16041cfe1..09d86ab2c0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/GroupsPerOperation.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/GroupsPerOperation.java @@ -14,10 +14,11 @@ import org.hibernate.HibernateException; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.spi.ClassLoaderAccess; import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; import jakarta.validation.groups.Default; +import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize; + /** * @author Emmanuel Bernard */ @@ -29,27 +30,25 @@ public class GroupsPerOperation { private static final Class[] DEFAULT_GROUPS = new Class[] { Default.class }; private static final Class[] EMPTY_GROUPS = new Class[] { }; - private final Map[]> groupsPerOperation = CollectionHelper.mapOfSize( 4 ); + private final Map[]> groupsPerOperation = mapOfSize( 4 ); private GroupsPerOperation() { } - public static GroupsPerOperation from(Map settings, ClassLoaderAccess classLoaderAccess) { - GroupsPerOperation groupsPerOperation = new GroupsPerOperation(); - + public static GroupsPerOperation from(Map settings, ClassLoaderAccess classLoaderAccess) { + final GroupsPerOperation groupsPerOperation = new GroupsPerOperation(); applyOperationGrouping( groupsPerOperation, Operation.INSERT, settings, classLoaderAccess ); applyOperationGrouping( groupsPerOperation, Operation.UPDATE, settings, classLoaderAccess ); applyOperationGrouping( groupsPerOperation, Operation.DELETE, settings, classLoaderAccess ); applyOperationGrouping( groupsPerOperation, Operation.UPSERT, settings, classLoaderAccess ); applyOperationGrouping( groupsPerOperation, Operation.DDL, settings, classLoaderAccess ); - return groupsPerOperation; } private static void applyOperationGrouping( GroupsPerOperation groupsPerOperation, Operation operation, - Map settings, + Map settings, ClassLoaderAccess classLoaderAccess) { groupsPerOperation.groupsPerOperation.put( operation, @@ -57,7 +56,8 @@ public class GroupsPerOperation { ); } - public static Class[] buildGroupsForOperation(Operation operation, Map settings, ClassLoaderAccess classLoaderAccess) { + public static Class[] buildGroupsForOperation( + Operation operation, Map settings, ClassLoaderAccess classLoaderAccess) { Object property = settings.get( operation.getJakartaGroupPropertyName() ); if ( property == null ) { property = settings.get( operation.getGroupPropertyName() ); @@ -67,21 +67,20 @@ public class GroupsPerOperation { return operation == Operation.DELETE ? EMPTY_GROUPS : DEFAULT_GROUPS; } - if ( property instanceof Class[] ) { - return (Class[]) property; + if ( property instanceof Class[] classes ) { + return classes; } - if ( property instanceof String ) { - String stringProperty = (String) property; - String[] groupNames = StringHelper.split( ",", stringProperty ); + if ( property instanceof String string ) { + final String[] groupNames = StringHelper.split( ",", string ); if ( groupNames.length == 1 && groupNames[0].isEmpty() ) { return EMPTY_GROUPS; } - List> groupsList = new ArrayList<>(groupNames.length); - for (String groupName : groupNames) { - String cleanedGroupName = groupName.trim(); - if ( cleanedGroupName.length() > 0) { + final List> groupsList = new ArrayList<>( groupNames.length ); + for ( String groupName : groupNames ) { + final String cleanedGroupName = groupName.trim(); + if ( !cleanedGroupName.isEmpty() ) { try { groupsList.add( classLoaderAccess.classForName( cleanedGroupName ) ); } @@ -90,11 +89,13 @@ public class GroupsPerOperation { } } } - return groupsList.toArray( new Class[groupsList.size()] ); + return groupsList.toArray( new Class[0] ); } //null is bad and excluded by instanceof => exception is raised - throw new HibernateException( JAKARTA_JPA_GROUP_PREFIX + operation.getJakartaGroupPropertyName() + " is of unknown type: String or Class[] only"); + throw new HibernateException( JAKARTA_JPA_GROUP_PREFIX + + operation.getJakartaGroupPropertyName() + + " is of unknown type: String or Class[] only"); } public Class[] get(Operation operation) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/HibernateTraversableResolver.java b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/HibernateTraversableResolver.java index c0afa9d0dc..3c81a2d19e 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/HibernateTraversableResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/HibernateTraversableResolver.java @@ -18,7 +18,6 @@ import org.hibernate.persister.entity.EntityPersister; import org.hibernate.type.AnyType; import org.hibernate.type.CollectionType; import org.hibernate.type.ComponentType; -import org.hibernate.type.CompositeType; import org.hibernate.type.EntityType; import org.hibernate.type.Type; @@ -27,9 +26,8 @@ import jakarta.validation.TraversableResolver; /** * Use Hibernate metadata to ignore cascade on entities. - * cascade on embeddable objects or collection of embeddable objects are accepted - * - * Also use Hibernate's native isInitialized method call. + * Cascade on embeddable objects or collection of embeddable objects are accepted + * Also use Hibernate's native {@link Hibernate#isInitialized} method call. * * @author Emmanuel Bernard */ @@ -40,44 +38,43 @@ public class HibernateTraversableResolver implements TraversableResolver { EntityPersister persister, ConcurrentHashMap> associationsPerEntityPersister, SessionFactoryImplementor factory) { - this.associations = associationsPerEntityPersister.get( persister ); - if (this.associations == null) { - this.associations = new HashSet<>(); + associations = associationsPerEntityPersister.get( persister ); + if ( associations == null ) { + associations = new HashSet<>(); addAssociationsToTheSetForAllProperties( persister.getPropertyNames(), persister.getPropertyTypes(), "", factory ); associationsPerEntityPersister.put( persister, associations ); } } - private void addAssociationsToTheSetForAllProperties(String[] names, Type[] types, String prefix, SessionFactoryImplementor factory) { + private void addAssociationsToTheSetForAllProperties( + String[] names, Type[] types, String prefix, SessionFactoryImplementor factory) { final int length = names.length; for( int index = 0 ; index < length; index++ ) { addAssociationsToTheSetForOneProperty( names[index], types[index], prefix, factory ); } } - private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) { - - if ( type instanceof CollectionType ) { - CollectionType collType = (CollectionType) type; - Type assocType = collType.getElementType( factory ); - addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory); + private void addAssociationsToTheSetForOneProperty( + String name, Type type, String prefix, SessionFactoryImplementor factory) { + if ( type instanceof CollectionType collectionType ) { + addAssociationsToTheSetForOneProperty( name, collectionType.getElementType( factory ), prefix, factory ); } //ToOne association else if ( type instanceof EntityType || type instanceof AnyType ) { associations.add( prefix + name ); } - else if ( type instanceof ComponentType ) { - ComponentType componentType = (ComponentType) type; + else if ( type instanceof ComponentType componentType ) { addAssociationsToTheSetForAllProperties( componentType.getPropertyNames(), componentType.getSubtypes(), ( prefix.isEmpty() ? name : prefix + name ) + '.', - factory); + factory + ); } } private String getStringBasedPath(Path.Node traversableProperty, Path pathToTraversableObject) { - StringBuilder path = new StringBuilder( ); + final StringBuilder path = new StringBuilder( ); for ( Path.Node node : pathToTraversableObject ) { if (node.getName() != null) { path.append( node.getName() ).append( '.' ); @@ -89,7 +86,6 @@ public class HibernateTraversableResolver implements TraversableResolver { + path ); } path.append( traversableProperty.getName() ); - return path.toString(); } @@ -100,7 +96,7 @@ public class HibernateTraversableResolver implements TraversableResolver { ElementType elementType) { //lazy, don't load return Hibernate.isInitialized( traversableObject ) - && Hibernate.isPropertyInitialized( traversableObject, traversableProperty.getName() ); + && Hibernate.isPropertyInitialized( traversableObject, traversableProperty.getName() ); } public boolean isCascadable(Object traversableObject, @@ -108,7 +104,6 @@ public class HibernateTraversableResolver implements TraversableResolver { Class rootBeanType, Path pathToTraversableObject, ElementType elementType) { - String path = getStringBasedPath( traversableProperty, pathToTraversableObject ); - return ! associations.contains(path); + return !associations.contains( getStringBasedPath( traversableProperty, pathToTraversableObject ) ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java index 875ac91f38..d5a831a3d1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java @@ -279,10 +279,9 @@ class TypeSafeActivator { final long min = minConstraint.getAnnotation().value(); for ( Selectable selectable : property.getSelectables() ) { - if ( selectable instanceof Column ) { - Column col = (Column) selectable; - String checkConstraint = col.getQuotedName(dialect) + ">=" + min; - applySQLCheck( col, checkConstraint ); + if ( selectable instanceof Column column ) { + final String checkConstraint = column.getQuotedName( dialect ) + ">=" + min; + applySQLCheck( column, checkConstraint ); } } } @@ -295,10 +294,9 @@ class TypeSafeActivator { final long max = maxConstraint.getAnnotation().value(); for ( Selectable selectable : property.getSelectables() ) { - if ( selectable instanceof Column ) { - Column col = (Column) selectable; - String checkConstraint = col.getQuotedName( dialect ) + "<=" + max; - applySQLCheck( col, checkConstraint ); + if ( selectable instanceof Column column ) { + final String checkConstraint = column.getQuotedName( dialect ) + "<=" + max; + applySQLCheck( column, checkConstraint ); } } } @@ -354,10 +352,9 @@ class TypeSafeActivator { int fractionalDigits = digitsConstraint.getAnnotation().fraction(); for ( Selectable selectable : property.getSelectables() ) { - if ( selectable instanceof Column ) { - Column col = (Column) selectable; - col.setPrecision( integerDigits + fractionalDigits ); - col.setScale( fractionalDigits ); + if ( selectable instanceof Column column ) { + column.setPrecision( integerDigits + fractionalDigits ); + column.setScale( fractionalDigits ); } } @@ -387,10 +384,9 @@ class TypeSafeActivator { int max = (Integer) descriptor.getAttributes().get( "max" ); for ( Selectable selectable : property.getSelectables() ) { - if ( selectable instanceof Column ) { - Column col = (Column) selectable; + if ( selectable instanceof Column column ) { if ( max < Integer.MAX_VALUE ) { - col.setLength( max ); + column.setLength( max ); } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/ValidationMode.java b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/ValidationMode.java index 31ecba5bbe..dddfcef461 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/ValidationMode.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/ValidationMode.java @@ -10,44 +10,50 @@ import java.util.Locale; import java.util.Set; import org.hibernate.HibernateException; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; + +import static org.hibernate.internal.util.StringHelper.split; +import static org.hibernate.internal.util.collections.CollectionHelper.setOfSize; /** - * Duplicates the jakarta.validation enum (because javax validation might not be on the runtime classpath) + * Duplicates the {@code jakarta.validation} enumeration. + * (Because Jakarta Validation might not be on the runtime classpath.) * * @author Steve Ebersole */ public enum ValidationMode { - AUTO( "auto" ), - CALLBACK( "callback" ), - NONE( "none" ), - DDL( "ddl" ); + AUTO, + CALLBACK, + NONE, + DDL; - private final String externalForm; - - ValidationMode(String externalForm) { - this.externalForm = externalForm; + private String externalForm() { + return switch (this) { + case AUTO -> "auto"; + case CALLBACK -> "callback"; + case NONE -> "none"; + case DDL -> "ddl"; + }; } public static Set getModes(Object modeProperty) { - Set modes = CollectionHelper.setOfSize( 3); - if (modeProperty == null) { + final Set modes = setOfSize( 3); + if ( modeProperty == null ) { modes.add( ValidationMode.AUTO ); } else { - for ( String modeInString : StringHelper.split( ",", modeProperty.toString() ) ) { + for ( String modeInString : split( ",", modeProperty.toString() ) ) { modes.add( getMode(modeInString) ); } } - if ( modes.size() > 1 && ( modes.contains( ValidationMode.AUTO ) || modes.contains( ValidationMode.NONE ) ) ) { + if ( modes.size() > 1 + && ( modes.contains( ValidationMode.AUTO ) || modes.contains( ValidationMode.NONE ) ) ) { throw new HibernateException( "Incompatible validation modes mixed: " + loggable( modes ) ); } return modes; } private static ValidationMode getMode(String modeProperty) { - if (modeProperty == null || modeProperty.length() == 0) { + if ( modeProperty == null || modeProperty.isEmpty() ) { return AUTO; } else { @@ -55,7 +61,9 @@ public enum ValidationMode { return valueOf( modeProperty.trim().toUpperCase(Locale.ROOT) ); } catch ( IllegalArgumentException e ) { - throw new HibernateException( "Unknown validation mode in " + BeanValidationIntegrator.JAKARTA_MODE_PROPERTY + ": " + modeProperty ); + throw new HibernateException( "Unknown validation mode in " + + BeanValidationIntegrator.JAKARTA_MODE_PROPERTY + + ": " + modeProperty ); } } } @@ -64,12 +72,12 @@ public enum ValidationMode { if ( modes == null || modes.isEmpty() ) { return "[]"; } - StringBuilder buffer = new StringBuilder( "[" ); + final StringBuilder result = new StringBuilder( "[" ); String sep = ""; for ( ValidationMode mode : modes ) { - buffer.append( sep ).append( mode.externalForm ); + result.append( sep ).append( mode.externalForm() ); sep = ", "; } - return buffer.append( "]" ).toString(); + return result.append( "]" ).toString(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderService.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderService.java index a599960aa6..e86c6cf0a3 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderService.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/DefaultSessionFactoryBuilderService.java @@ -16,7 +16,7 @@ import org.hibernate.boot.spi.SessionFactoryBuilderService; */ public final class DefaultSessionFactoryBuilderService implements SessionFactoryBuilderService { - protected static final DefaultSessionFactoryBuilderService INSTANCE = new DefaultSessionFactoryBuilderService(); + static final DefaultSessionFactoryBuilderService INSTANCE = new DefaultSessionFactoryBuilderService(); private DefaultSessionFactoryBuilderService() { } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java index d298c70b8a..a17b9f33ab 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java @@ -662,45 +662,41 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont final StrategySelector strategySelector = serviceRegistry.requireService( StrategySelector.class ); final ConfigurationService configService = serviceRegistry.requireService( ConfigurationService.class ); - this.mappingDefaults = new MappingDefaultsImpl( serviceRegistry ); + mappingDefaults = new MappingDefaultsImpl( serviceRegistry ); - this.defaultTimezoneStorage = resolveTimeZoneStorageStrategy( configService ); - this.wrapperArrayHandling = resolveWrapperArrayHandling( configService, serviceRegistry ); - this.multiTenancyEnabled = JdbcEnvironmentImpl.isMultiTenancyEnabled( serviceRegistry ); + defaultTimezoneStorage = resolveTimeZoneStorageStrategy( configService ); + wrapperArrayHandling = resolveWrapperArrayHandling( configService, serviceRegistry ); + multiTenancyEnabled = JdbcEnvironmentImpl.isMultiTenancyEnabled( serviceRegistry ); - this.xmlMappingEnabled = configService.getSetting( + xmlMappingEnabled = configService.getSetting( AvailableSettings.XML_MAPPING_ENABLED, BOOLEAN, true ); - this.implicitDiscriminatorsForJoinedInheritanceSupported = configService.getSetting( + implicitDiscriminatorsForJoinedInheritanceSupported = configService.getSetting( AvailableSettings.IMPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS, BOOLEAN, false ); - this.explicitDiscriminatorsForJoinedInheritanceSupported = !configService.getSetting( + explicitDiscriminatorsForJoinedInheritanceSupported = !configService.getSetting( AvailableSettings.IGNORE_EXPLICIT_DISCRIMINATOR_COLUMNS_FOR_JOINED_SUBCLASS, BOOLEAN, false ); - this.implicitlyForceDiscriminatorInSelect = configService.getSetting( + implicitlyForceDiscriminatorInSelect = configService.getSetting( AvailableSettings.FORCE_DISCRIMINATOR_IN_SELECTS_BY_DEFAULT, BOOLEAN, false ); - this.sharedCacheMode = configService.getSetting( + sharedCacheMode = configService.getSetting( AvailableSettings.JAKARTA_SHARED_CACHE_MODE, - value -> { - if ( value instanceof SharedCacheMode ) { - return (SharedCacheMode) value; - } - - return SharedCacheMode.valueOf( value.toString() ); - }, + value -> value instanceof SharedCacheMode cacheMode + ? cacheMode + : SharedCacheMode.valueOf( value.toString() ), configService.getSetting( AvailableSettings.JPA_SHARED_CACHE_MODE, value -> { @@ -713,52 +709,48 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont AvailableSettings.JAKARTA_SHARED_CACHE_MODE ); - if ( value instanceof SharedCacheMode ) { - return (SharedCacheMode) value; - } - - return SharedCacheMode.valueOf( value.toString() ); + return value instanceof SharedCacheMode cacheMode + ? cacheMode + : SharedCacheMode.valueOf( value.toString() ); }, SharedCacheMode.UNSPECIFIED ) ); - this.defaultCacheAccessType = configService.getSetting( + final RegionFactory regionFactory = serviceRegistry.getService( RegionFactory.class ); + defaultCacheAccessType = configService.getSetting( AvailableSettings.DEFAULT_CACHE_CONCURRENCY_STRATEGY, value -> { if ( value == null ) { return null; } - - if ( value instanceof CacheConcurrencyStrategy ) { - return ( (CacheConcurrencyStrategy) value ).toAccessType(); + else if ( value instanceof CacheConcurrencyStrategy cacheConcurrencyStrategy ) { + return cacheConcurrencyStrategy.toAccessType(); } - - if ( value instanceof AccessType ) { - return (AccessType) value; + else if ( value instanceof AccessType accessType ) { + return accessType; + } + else { + return AccessType.fromExternalName( value.toString() ); } - - return AccessType.fromExternalName( value.toString() ); }, // by default, see if the defined RegionFactory (if one) defines a default - serviceRegistry.getService( RegionFactory.class ) == null - ? null - : serviceRegistry.requireService( RegionFactory.class ).getDefaultAccessType() + regionFactory == null ? null : regionFactory.getDefaultAccessType() ); - this.specjProprietarySyntaxEnabled = configService.getSetting( + specjProprietarySyntaxEnabled = configService.getSetting( "hibernate.enable_specj_proprietary_syntax", BOOLEAN, false ); - this.noConstraintByDefault = ConstraintMode.NO_CONSTRAINT.name().equalsIgnoreCase( configService.getSetting( + noConstraintByDefault = ConstraintMode.NO_CONSTRAINT.name().equalsIgnoreCase( configService.getSetting( AvailableSettings.HBM2DDL_DEFAULT_CONSTRAINT_MODE, String.class, null ) ); - this.implicitNamingStrategy = strategySelector.resolveDefaultableStrategy( + implicitNamingStrategy = strategySelector.resolveDefaultableStrategy( ImplicitNamingStrategy.class, configService.getSettings().get( AvailableSettings.IMPLICIT_NAMING_STRATEGY ), new Callable<>() { @@ -773,13 +765,13 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont } ); - this.physicalNamingStrategy = strategySelector.resolveDefaultableStrategy( + physicalNamingStrategy = strategySelector.resolveDefaultableStrategy( PhysicalNamingStrategy.class, configService.getSettings().get( AvailableSettings.PHYSICAL_NAMING_STRATEGY ), PhysicalNamingStrategyStandardImpl.INSTANCE ); - this.columnOrderingStrategy = strategySelector.resolveDefaultableStrategy( + columnOrderingStrategy = strategySelector.resolveDefaultableStrategy( ColumnOrderingStrategy.class, configService.getSettings().get( AvailableSettings.COLUMN_ORDERING_STRATEGY ), new Callable<>() { @@ -794,13 +786,13 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont } ); - this.useNationalizedCharacterData = configService.getSetting( + useNationalizedCharacterData = configService.getSetting( AvailableSettings.USE_NATIONALIZED_CHARACTER_DATA, BOOLEAN, false ); - this.schemaCharset = configService.getSetting( + schemaCharset = configService.getSetting( AvailableSettings.HBM2DDL_CHARSET_NAME, String.class, null @@ -841,45 +833,33 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont } private TimeZoneStorageStrategy toTimeZoneStorageStrategy(TimeZoneSupport timeZoneSupport) { - switch ( defaultTimezoneStorage ) { - case NATIVE: + return switch (defaultTimezoneStorage) { + case NATIVE -> { if ( timeZoneSupport != TimeZoneSupport.NATIVE ) { throw new HibernateException( "The configured time zone storage type NATIVE is not supported with the configured dialect" ); } - return TimeZoneStorageStrategy.NATIVE; - case COLUMN: - return TimeZoneStorageStrategy.COLUMN; - case NORMALIZE: - return TimeZoneStorageStrategy.NORMALIZE; - case NORMALIZE_UTC: - return TimeZoneStorageStrategy.NORMALIZE_UTC; - case AUTO: - switch (timeZoneSupport) { - case NATIVE: + yield TimeZoneStorageStrategy.NATIVE; + } + case COLUMN -> TimeZoneStorageStrategy.COLUMN; + case NORMALIZE -> TimeZoneStorageStrategy.NORMALIZE; + case NORMALIZE_UTC -> TimeZoneStorageStrategy.NORMALIZE_UTC; + case AUTO -> switch (timeZoneSupport) { + case NATIVE -> // if the db has native support for timezones, we use that, not a column - return TimeZoneStorageStrategy.NATIVE; - case NORMALIZE: - case NONE: + TimeZoneStorageStrategy.NATIVE; + case NORMALIZE, NONE -> // otherwise we use a separate column - return TimeZoneStorageStrategy.COLUMN; - default: - throw new HibernateException( "Unsupported time zone support: " + timeZoneSupport); - } - case DEFAULT: - switch (timeZoneSupport) { - case NATIVE: + TimeZoneStorageStrategy.COLUMN; + }; + case DEFAULT -> switch (timeZoneSupport) { + case NATIVE -> // if the db has native support for timezones, we use that, and don't normalize - return TimeZoneStorageStrategy.NATIVE; - case NORMALIZE: - case NONE: + TimeZoneStorageStrategy.NATIVE; + case NORMALIZE, NONE -> // otherwise we normalize things to UTC - return TimeZoneStorageStrategy.NORMALIZE_UTC; - default: - throw new HibernateException( "Unsupported time zone support: " + timeZoneSupport); - } - default: - throw new HibernateException( "Unsupported time zone storage type: " + defaultTimezoneStorage ); - } + TimeZoneStorageStrategy.NORMALIZE_UTC; + }; + }; } @Override @@ -1047,12 +1027,13 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont || dialect.getPreferredSqlTypeCodeForArray() == SqlTypes.SQLXML ) ) { return WrapperArrayHandling.ALLOW; } - - return WrapperArrayHandling.LEGACY; + else { + return WrapperArrayHandling.LEGACY; + } } return setting; - }; + } private static WrapperArrayHandling resolveFallbackWrapperArrayHandling( ConfigurationService configService) { @@ -1060,7 +1041,8 @@ public class MetadataBuilderImpl implements MetadataBuilderImplementor, TypeCont // JPA compliance was enabled. Use PICK return WrapperArrayHandling.PICK; } - - return WrapperArrayHandling.DISALLOW; + else { + return WrapperArrayHandling.DISALLOW; + } } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java index 299b5f0776..f5757bd3ca 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryBuilderImpl.java @@ -404,7 +404,7 @@ public class SessionFactoryBuilderImpl implements SessionFactoryBuilderImplement return this; } - @Override + @Override @Deprecated public SessionFactoryBuilder enableJpaCascadeCompliance(boolean enabled) { this.optionsBuilder.enableJpaCascadeCompliance( enabled ); return this;