Skip to content

Commit 9321a3e

Browse files
committed
eliminate copy/pasted code from TypeSafeActivator
(though we should probably move the shared method off of BinderHelper)
1 parent 2328bd9 commit 9321a3e

File tree

4 files changed

+10
-87
lines changed

4 files changed

+10
-87
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/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) {

hibernate-core/src/main/java/org/hibernate/boot/query/HbmResultSetMappingDescriptor.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,10 +563,8 @@ else if ( value instanceof Component component ) {
563563
value = component.getProperty( element ).getValue();
564564
}
565565
else if ( value instanceof ToOne toOne ) {
566-
value = collector
567-
.getEntityBinding( toOne.getReferencedEntityName() )
568-
.getProperty( element )
569-
.getValue();
566+
final var entity = collector.getEntityBinding( toOne.getReferencedEntityName() );
567+
value = entity.getProperty( element ).getValue();
570568
}
571569
else if ( value instanceof OneToMany oneToMany ) {
572570
value = oneToMany.getAssociatedClass().getProperty( element ).getValue();

hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,11 +679,9 @@ private Property getMappedSuperclassProperty(String propertyName, MappedSupercla
679679
if ( property != null ) {
680680
return property;
681681
}
682-
else if ( mappedSuperclass.getSuperPersistentClass() != null ) {
683-
return mappedSuperclass.getSuperPersistentClass().getProperty( propertyName );
684-
}
685682
else {
686-
return null;
683+
final var superclass = mappedSuperclass.getSuperPersistentClass();
684+
return superclass != null ? superclass.getProperty( propertyName ) : null;
687685
}
688686
}
689687

0 commit comments

Comments
 (0)