Skip to content

Commit 5d6e123

Browse files
author
Mike Mannion
committed
Merge branch 'main' into HHH-19704-listagg-on-overflow
2 parents 39b8da6 + b8a6fc2 commit 5d6e123

File tree

17 files changed

+411
-513
lines changed

17 files changed

+411
-513
lines changed

hibernate-core/src/main/java/org/hibernate/boot/beanvalidation/TypeSafeActivator.java

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import java.util.Locale;
1515
import java.util.Map;
1616
import java.util.Set;
17-
import java.util.StringTokenizer;
1817

1918
import jakarta.validation.NoProviderFoundException;
2019
import jakarta.validation.constraints.Digits;
@@ -25,7 +24,6 @@
2524
import jakarta.validation.constraints.NotNull;
2625
import jakarta.validation.constraints.Size;
2726
import org.hibernate.AssertionFailure;
28-
import org.hibernate.MappingException;
2927
import org.hibernate.boot.internal.ClassLoaderAccessImpl;
3028
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
3129
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
@@ -60,10 +58,10 @@
6058
import static java.util.Collections.disjoint;
6159
import static org.hibernate.boot.beanvalidation.BeanValidationIntegrator.APPLY_CONSTRAINTS;
6260
import static org.hibernate.boot.beanvalidation.GroupsPerOperation.buildGroupsForOperation;
61+
import static org.hibernate.boot.model.internal.BinderHelper.findPropertyByName;
6362
import static org.hibernate.cfg.ValidationSettings.CHECK_NULLABILITY;
6463
import static org.hibernate.cfg.ValidationSettings.JAKARTA_VALIDATION_FACTORY;
6564
import static org.hibernate.cfg.ValidationSettings.JPA_VALIDATION_FACTORY;
66-
import static org.hibernate.internal.util.StringHelper.isEmpty;
6765
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
6866

6967
/**
@@ -496,72 +494,6 @@ private static boolean isValidatorLengthAnnotation(ConstraintDescriptor<?> descr
496494
.equals( descriptor.getAnnotation().annotationType().getName() );
497495
}
498496

499-
/**
500-
* Locate the property by path in a recursive way, including IdentifierProperty in the loop if propertyName is
501-
* {@code null}. If propertyName is {@code null} or empty, the IdentifierProperty is returned
502-
*/
503-
private static Property findPropertyByName(PersistentClass associatedClass, String propertyName) {
504-
Property property = null;
505-
final Property idProperty = associatedClass.getIdentifierProperty();
506-
final String idName = idProperty != null ? idProperty.getName() : null;
507-
try {
508-
if ( isEmpty( propertyName ) || propertyName.equals( idName ) ) {
509-
//default to id
510-
property = idProperty;
511-
}
512-
else {
513-
if ( propertyName.indexOf( idName + "." ) == 0 ) {
514-
property = idProperty;
515-
propertyName = propertyName.substring( idName.length() + 1 );
516-
}
517-
final StringTokenizer tokens = new StringTokenizer( propertyName, ".", false );
518-
while ( tokens.hasMoreTokens() ) {
519-
final String element = tokens.nextToken();
520-
if ( property == null ) {
521-
property = associatedClass.getProperty( element );
522-
}
523-
else {
524-
if ( property.isComposite() ) {
525-
property = ( (Component) property.getValue() ).getProperty( element );
526-
}
527-
else {
528-
return null;
529-
}
530-
}
531-
}
532-
}
533-
}
534-
catch ( MappingException e ) {
535-
try {
536-
//if we do not find it, try to check the identifier mapper
537-
if ( associatedClass.getIdentifierMapper() == null ) {
538-
return null;
539-
}
540-
else {
541-
final StringTokenizer tokens = new StringTokenizer( propertyName, ".", false );
542-
while ( tokens.hasMoreTokens() ) {
543-
final String element = tokens.nextToken();
544-
if ( property == null ) {
545-
property = associatedClass.getIdentifierMapper().getProperty( element );
546-
}
547-
else {
548-
if ( property.isComposite() ) {
549-
property = ( (Component) property.getValue() ).getProperty( element );
550-
}
551-
else {
552-
return null;
553-
}
554-
}
555-
}
556-
}
557-
}
558-
catch ( MappingException ee ) {
559-
return null;
560-
}
561-
}
562-
return property;
563-
}
564-
565497
private static ValidatorFactory getValidatorFactory(ActivationContext context) {
566498
// IMPL NOTE: We can either be provided a ValidatorFactory or make one. We can be provided
567499
// a ValidatorFactory in 2 different ways. So here we "get" a ValidatorFactory

hibernate-core/src/main/java/org/hibernate/boot/internal/SessionFactoryOptionsBuilder.java

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ public SessionFactoryOptionsBuilder(StandardServiceRegistry serviceRegistry, Boo
266266

267267
// we cannot use context.getConfigurationService() here because it might be missing some settings
268268
// (the StandardServiceRegistry passed in here does not need to be the bootstrap service registry)
269-
final ConfigurationService configurationService = serviceRegistry.requireService( ConfigurationService.class );
269+
final var configurationService = serviceRegistry.requireService( ConfigurationService.class );
270270

271-
final StrategySelector strategySelector = serviceRegistry.requireService( StrategySelector.class );
272-
final JdbcServices jdbcServices = serviceRegistry.requireService( JdbcServices.class );
271+
final var strategySelector = serviceRegistry.requireService( StrategySelector.class );
272+
final var jdbcServices = serviceRegistry.requireService( JdbcServices.class );
273273

274-
final Dialect dialect = jdbcServices.getJdbcEnvironment().getDialect();
274+
final var dialect = jdbcServices.getJdbcEnvironment().getDialect();
275275

276276
final Map<String,Object> settings = new HashMap<>();
277277
settings.putAll( map( dialect.getDefaultProperties() ) );
@@ -601,6 +601,12 @@ private static boolean disallowBatchUpdates(Dialect dialect, ExtractedDatabaseMe
601601
return dialectAnswer != null ? !dialectAnswer : !meta.supportsBatchUpdates();
602602
}
603603

604+
private static boolean hasStrategyConstructorSignature(Class<?>[] parameterTypes) {
605+
return parameterTypes.length == 2
606+
&& parameterTypes[0] == EntityMappingType.class
607+
&& parameterTypes[1] == RuntimeModelCreationContext.class;
608+
}
609+
604610
@SuppressWarnings("unchecked")
605611
private SqmMultiTableMutationStrategy resolveSqmMutationStrategy(
606612
String strategyName,
@@ -631,7 +637,7 @@ private SqmMultiTableMutationStrategy resolveSqmMutationStrategy(
631637
else if ( parameterTypes.length == 0 ) {
632638
emptyConstructor = constructor;
633639
}
634-
else if ( parameterTypes.length == 2 && parameterTypes[0] == EntityMappingType.class && parameterTypes[1] == RuntimeModelCreationContext.class ) {
640+
else if ( hasStrategyConstructorSignature( parameterTypes ) ) {
635641
entityBasedConstructor = (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
636642
}
637643
}
@@ -649,13 +655,12 @@ else if ( emptyConstructor != null ) {
649655
}
650656
catch (Exception e) {
651657
throw new StrategySelectionException(
652-
"Could not instantiate named strategy class [" +
653-
strategyClass.getName() + "]",
658+
"Could not instantiate named strategy class [" + strategyClass.getName() + "]",
654659
e
655660
);
656661
}
657-
throw new IllegalArgumentException(
658-
"Cannot instantiate the class [" + strategyClass.getName() + "] because it does not have a constructor that accepts a dialect or an empty constructor" );
662+
throw new IllegalArgumentException( "Cannot instantiate the class [" + strategyClass.getName()
663+
+ "] because it does not have a constructor that accepts a dialect or an empty constructor" );
659664
}
660665
else {
661666
return null;
@@ -668,19 +673,16 @@ else if ( emptyConstructor != null ) {
668673
private Constructor<SqmMultiTableMutationStrategy> resolveSqmMutationStrategyConstructor(
669674
String strategyName,
670675
StrategySelector strategySelector) {
671-
if ( strategyName == null ) {
672-
return null;
673-
}
674-
675-
Class<? extends SqmMultiTableMutationStrategy> strategyClass =
676-
strategySelector.selectStrategyImplementor( SqmMultiTableMutationStrategy.class, strategyName );
677-
for ( Constructor<?> declaredConstructor : strategyClass.getDeclaredConstructors() ) {
678-
final Class<?>[] parameterTypes = declaredConstructor.getParameterTypes();
679-
if ( parameterTypes.length == 2 && parameterTypes[0] == EntityMappingType.class && parameterTypes[1] == RuntimeModelCreationContext.class ) {
680-
return (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
676+
if ( strategyName != null ) {
677+
final var strategyClass =
678+
strategySelector.selectStrategyImplementor( SqmMultiTableMutationStrategy.class, strategyName );
679+
for ( var declaredConstructor : strategyClass.getDeclaredConstructors() ) {
680+
final var parameterTypes = declaredConstructor.getParameterTypes();
681+
if ( hasStrategyConstructorSignature( parameterTypes ) ) {
682+
return (Constructor<SqmMultiTableMutationStrategy>) declaredConstructor;
683+
}
681684
}
682685
}
683-
684686
return null;
685687
}
686688

@@ -714,7 +716,7 @@ private SqmMultiTableInsertStrategy resolveSqmInsertStrategy(
714716
else if ( parameterTypes.length == 0 ) {
715717
emptyConstructor = constructor;
716718
}
717-
else if ( parameterTypes.length == 2 && parameterTypes[0] == EntityMappingType.class && parameterTypes[1] == RuntimeModelCreationContext.class ) {
719+
else if ( hasStrategyConstructorSignature( parameterTypes ) ) {
718720
entityBasedConstructor = (Constructor<SqmMultiTableInsertStrategy>) declaredConstructor;
719721
}
720722
}
@@ -751,19 +753,16 @@ else if ( emptyConstructor != null ) {
751753
private Constructor<SqmMultiTableInsertStrategy> resolveSqmInsertStrategyConstructor(
752754
String strategyName,
753755
StrategySelector strategySelector) {
754-
if ( strategyName == null ) {
755-
return null;
756-
}
757-
758-
Class<? extends SqmMultiTableInsertStrategy> strategyClass =
759-
strategySelector.selectStrategyImplementor( SqmMultiTableInsertStrategy.class, strategyName );
760-
for ( Constructor<?> declaredConstructor : strategyClass.getDeclaredConstructors() ) {
761-
final Class<?>[] parameterTypes = declaredConstructor.getParameterTypes();
762-
if ( parameterTypes.length == 2 && parameterTypes[0] == EntityMappingType.class && parameterTypes[1] == RuntimeModelCreationContext.class ) {
763-
return (Constructor<SqmMultiTableInsertStrategy>) declaredConstructor;
756+
if ( strategyName != null ) {
757+
final var strategyClass =
758+
strategySelector.selectStrategyImplementor( SqmMultiTableInsertStrategy.class, strategyName );
759+
for ( var declaredConstructor : strategyClass.getDeclaredConstructors() ) {
760+
final var parameterTypes = declaredConstructor.getParameterTypes();
761+
if ( hasStrategyConstructorSignature( parameterTypes ) ) {
762+
return (Constructor<SqmMultiTableInsertStrategy>) declaredConstructor;
763+
}
764764
}
765765
}
766-
767766
return null;
768767
}
769768

@@ -844,7 +843,7 @@ private static Supplier<? extends Interceptor> interceptorSupplier(Class<? exten
844843
private PhysicalConnectionHandlingMode interpretConnectionHandlingMode(
845844
Map<String,Object> configurationSettings,
846845
StandardServiceRegistry serviceRegistry) {
847-
final PhysicalConnectionHandlingMode specifiedHandlingMode =
846+
final var specifiedHandlingMode =
848847
PhysicalConnectionHandlingMode.interpret( configurationSettings.get( CONNECTION_HANDLING ) );
849848
return specifiedHandlingMode != null
850849
? specifiedHandlingMode
@@ -995,7 +994,8 @@ public SqmMultiTableMutationStrategy resolveCustomSqmMultiTableMutationStrategy(
995994
}
996995
catch (Exception e) {
997996
throw new StrategySelectionException(
998-
String.format( "Could not instantiate named strategy class [%s]", sqmMultiTableMutationStrategyConstructor.getDeclaringClass().getName() ),
997+
String.format( "Could not instantiate named strategy class [%s]",
998+
sqmMultiTableMutationStrategyConstructor.getDeclaringClass().getName() ),
999999
e
10001000
);
10011001
}
@@ -1011,7 +1011,8 @@ public SqmMultiTableInsertStrategy resolveCustomSqmMultiTableInsertStrategy(Enti
10111011
}
10121012
catch (Exception e) {
10131013
throw new StrategySelectionException(
1014-
String.format( "Could not instantiate named strategy class [%s]", sqmMultiTableInsertStrategyConstructor.getDeclaringClass().getName() ),
1014+
String.format( "Could not instantiate named strategy class [%s]",
1015+
sqmMultiTableInsertStrategyConstructor.getDeclaringClass().getName() ),
10151016
e
10161017
);
10171018
}

hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,9 @@ Property resolveMapsId() {
233233
final PersistentClass persistentClass = getPropertyHolder().getPersistentClass();
234234
final KeyValue identifier = persistentClass.getIdentifier();
235235
try {
236-
if ( identifier instanceof Component embeddedIdType ) {
237-
// an @EmbeddedId
238-
return embeddedIdType.getProperty( getMapsId() );
239-
}
240-
else {
241-
// a simple id or an @IdClass
242-
return persistentClass.getProperty( getMapsId() );
243-
}
236+
return identifier instanceof Component embeddedIdType
237+
? embeddedIdType.getProperty( getMapsId() ) // an @EmbeddedId
238+
: persistentClass.getProperty( getMapsId() ); // a simple id or an @IdClass
244239
}
245240
catch (MappingException me) {
246241
throw new AnnotationException( "Identifier field '" + getMapsId()
@@ -255,10 +250,10 @@ public List<AnnotatedJoinColumn> getJoinColumns() {
255250

256251
@Override
257252
public void addColumn(AnnotatedColumn child) {
258-
if ( !( child instanceof AnnotatedJoinColumn ) ) {
253+
if ( !( child instanceof AnnotatedJoinColumn joinColumn ) ) {
259254
throw new AssertionFailure( "wrong sort of column" );
260255
}
261-
addColumn( (AnnotatedJoinColumn) child );
256+
addColumn( joinColumn );
262257
}
263258

264259
public void addColumn(AnnotatedJoinColumn child) {

0 commit comments

Comments
 (0)