diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/JoinedSubclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/JoinedSubclass.java index 2a7b9d147ebd..14917846d48c 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/JoinedSubclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/JoinedSubclass.java @@ -21,8 +21,8 @@ public final class JoinedSubclass extends Subclass implements TableOwner { private Table table; private KeyValue key; - public JoinedSubclass(PersistentClass superclass, MetadataBuildingContext metadataBuildingContext) { - super( superclass, metadataBuildingContext ); + public JoinedSubclass(PersistentClass superclass, MetadataBuildingContext buildingContext) { + super( superclass, buildingContext ); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/MappedSuperclass.java b/hibernate-core/src/main/java/org/hibernate/mapping/MappedSuperclass.java index 19b15a20f35e..5bcc55f9c3cb 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/MappedSuperclass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/MappedSuperclass.java @@ -213,10 +213,9 @@ public Join getSecondaryTable(String name) { @Override public IdentifiableTypeClass getSuperType() { - if ( superPersistentClass != null ) { - return superPersistentClass; - } - return superMappedSuperclass; + return superPersistentClass != null + ? superPersistentClass + : superMappedSuperclass; } @Override @@ -231,8 +230,8 @@ public Table getImplicitTable() { @Override public void applyProperty(Property property) { - assert property.getValue().getTable() != null; - assert property.getValue().getTable().equals( getImplicitTable() ); + assert property.getValue().getTable() != null + && property.getValue().getTable().equals( getImplicitTable() ); addDeclaredProperty( property ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java b/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java index d74059fbae88..bfe537b75570 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/MappingHelper.java @@ -105,9 +105,9 @@ public static void checkPropertyColumnDuplication( Set distinctColumns, List properties, String owner) throws MappingException { - for ( var prop : properties ) { - if ( prop.isUpdatable() || prop.isInsertable() ) { - prop.getValue().checkColumnDuplication( distinctColumns, owner ); + for ( var property : properties ) { + if ( property.isUpdatable() || property.isInsertable() ) { + property.getValue().checkColumnDuplication( distinctColumns, owner ); } } } @@ -117,7 +117,7 @@ static Class classForName(String typeName, BootstrapContext bootstrapContext) } static Class classForName(Class supertype, String typeName, BootstrapContext bootstrapContext) { - final Class clazz = classForName( typeName, bootstrapContext ); + final var clazz = classForName( typeName, bootstrapContext ); if ( supertype.isAssignableFrom( clazz ) ) { //noinspection unchecked return (Class) clazz; diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/OneToMany.java b/hibernate-core/src/main/java/org/hibernate/mapping/OneToMany.java index 5edd4cd6dac9..7d0f98fdd0bd 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/OneToMany.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/OneToMany.java @@ -11,12 +11,13 @@ import org.hibernate.MappingException; import org.hibernate.annotations.NotFoundAction; import org.hibernate.boot.spi.MetadataBuildingContext; -import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.service.ServiceRegistry; import org.hibernate.type.ManyToOneType; import org.hibernate.type.Type; import org.hibernate.type.MappingContext; +import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_BOOLEAN_ARRAY; + /** * A mapping model object representing a {@linkplain jakarta.persistence.OneToMany many-to-one association}. * @@ -183,7 +184,7 @@ public boolean isSame(OneToMany other) { @Override public boolean[] getColumnInsertability() { //TODO: we could just return all false... - return ArrayHelper.EMPTY_BOOLEAN_ARRAY; + return EMPTY_BOOLEAN_ARRAY; } @Override @@ -194,7 +195,7 @@ public boolean hasAnyInsertableColumns() { @Override public boolean[] getColumnUpdateability() { //TODO: we could just return all false... - return ArrayHelper.EMPTY_BOOLEAN_ARRAY; + return EMPTY_BOOLEAN_ARRAY; } @Override @@ -215,9 +216,7 @@ public boolean isIgnoreNotFound() { } public void setIgnoreNotFound(boolean ignoreNotFound) { - this.notFoundAction = ignoreNotFound - ? NotFoundAction.IGNORE - : null; + notFoundAction = ignoreNotFound ? NotFoundAction.IGNORE : null; } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java index cc6ca2db14ed..aa77cda969c8 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java @@ -31,7 +31,6 @@ import org.hibernate.service.ServiceRegistry; import org.hibernate.sql.Alias; import org.hibernate.type.CollectionType; -import org.hibernate.type.Type; import org.hibernate.type.spi.TypeConfiguration; import static java.util.Collections.emptyList; @@ -370,7 +369,7 @@ public List getSubclassPropertyClosure() { final ArrayList> lists = new ArrayList<>(); lists.add( getPropertyClosure() ); lists.add( subclassProperties ); - for ( Join join : subclassJoins ) { + for ( var join : subclassJoins ) { lists.add( join.getProperties() ); } return new JoinedList<>( lists ); @@ -641,7 +640,7 @@ public void setOptimisticLockStyle(OptimisticLockStyle optimisticLockStyle) { public void validate(Metadata mapping) throws MappingException { for ( var prop : getProperties() ) { if ( !prop.isValid( mapping ) ) { - final Type type = prop.getType(); + final var type = prop.getType(); final int actualColumns = prop.getColumnSpan(); final int requiredColumns = type.getColumnSpan( mapping ); throw new MappingException( @@ -699,7 +698,7 @@ public List getJoinClosure() { } public void addJoin(Join join) { - if ( !joins.contains(join) ) { + if ( !joins.contains( join ) ) { joins.add( join ); } join.setPersistentClass( this ); @@ -868,8 +867,9 @@ protected void checkColumnDuplication() { if ( isDiscriminatorInsertable() && getDiscriminator() != null ) { getDiscriminator().checkColumnDuplication( cols, owner ); } - if ( getRootClass().getSoftDeleteColumn() != null ) { - getRootClass().getSoftDeleteColumn().getValue().checkColumnDuplication( cols, owner ); + final var softDeleteColumn = getRootClass().getSoftDeleteColumn(); + if ( softDeleteColumn != null ) { + softDeleteColumn.getValue().checkColumnDuplication( cols, owner ); } checkPropertyColumnDuplication( cols, getNonDuplicatedProperties(), owner ); for ( var join : getJoins() ) { @@ -923,12 +923,14 @@ else if ( value instanceof org.hibernate.mapping.Collection collection ) { } public boolean hasPartitionedSelectionMapping() { - if ( getSuperclass() != null && getSuperclass().hasPartitionedSelectionMapping() ) { + final var superclass = getSuperclass(); + if ( superclass != null + && superclass.hasPartitionedSelectionMapping() ) { return true; } for ( var property : getProperties() ) { - final var value = property.getValue(); - if ( value instanceof BasicValue basicValue && basicValue.isPartitionKey() ) { + if ( property.getValue() instanceof BasicValue basicValue + && basicValue.isPartitionKey() ) { return true; } } @@ -952,13 +954,12 @@ public boolean hasIdentifierMapper() { } public void addCallbackDefinitions(java.util.List callbackDefinitions) { - if ( callbackDefinitions == null || callbackDefinitions.isEmpty() ) { - return; - } - if ( this.callbackDefinitions == null ) { - this.callbackDefinitions = new ArrayList<>(); + if ( callbackDefinitions != null && !callbackDefinitions.isEmpty() ) { + if ( this.callbackDefinitions == null ) { + this.callbackDefinitions = new ArrayList<>(); + } + this.callbackDefinitions.addAll( callbackDefinitions ); } - this.callbackDefinitions.addAll( callbackDefinitions ); } public java.util.List getCallbackDefinitions() { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java b/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java index 837e416cd17f..9af7f7526347 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/PrimaryKey.java @@ -4,11 +4,11 @@ */ package org.hibernate.mapping; -import java.util.Arrays; import java.util.List; import org.hibernate.Internal; +import static java.util.Arrays.asList; import static org.hibernate.internal.util.StringHelper.qualify; /** @@ -55,7 +55,7 @@ public List getColumnsInOriginalOrder() { for ( int i = 0; i < columnsInOriginalOrder.length; i++ ) { columnsInOriginalOrder[originalOrder[i]] = columns.get( i ); } - return Arrays.asList( columnsInOriginalOrder ); + return asList( columnsInOriginalOrder ); } public void setOrderingUniqueKey(UniqueKey uniqueKey) { @@ -71,22 +71,23 @@ public void reorderColumns(List reorderedColumns) { final var columns = getColumns(); if ( originalOrder != null ) { assert columns.equals( reorderedColumns ); - return; } - assert columns.size() == reorderedColumns.size() - && columns.containsAll( reorderedColumns ); - originalOrder = new int[columns.size()]; - final var orderingUniqueKey = getOrderingUniqueKey(); - final var newColumns = - orderingUniqueKey != null - ? orderingUniqueKey.getColumns() - : reorderedColumns; - for ( int i = 0; i < newColumns.size(); i++ ) { - final var reorderedColumn = newColumns.get( i ); - originalOrder[i] = columns.indexOf( reorderedColumn ); + else { + assert columns.size() == reorderedColumns.size() + && columns.containsAll( reorderedColumns ); + originalOrder = new int[columns.size()]; + final var orderingUniqueKey = getOrderingUniqueKey(); + final var newColumns = + orderingUniqueKey != null + ? orderingUniqueKey.getColumns() + : reorderedColumns; + for ( int i = 0; i < newColumns.size(); i++ ) { + final var reorderedColumn = newColumns.get( i ); + originalOrder[i] = columns.indexOf( reorderedColumn ); + } + columns.clear(); + columns.addAll( newColumns ); } - columns.clear(); - columns.addAll( newColumns ); } @Internal diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java index e44a6aa6f77a..6503fa477807 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/RootClass.java @@ -295,7 +295,7 @@ private void checkTableDuplication() { if ( hasSubclasses() ) { final Set tables = new HashSet<>(); tables.add( getTable() ); - for ( Subclass subclass : getSubclasses() ) { + for ( var subclass : getSubclasses() ) { if ( !(subclass instanceof SingleTableSubclass) ) { final var table = subclass.getTable(); if ( !tables.add( table ) ) { diff --git a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java index 2f372d4fd587..fd344893354c 100644 --- a/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java +++ b/hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java @@ -485,7 +485,14 @@ public String getNullValue() { * @see org.hibernate.engine.spi.VersionValue */ public void setNullValue(String nullValue) { - nullValueSemantic = switch (nullValue) { + nullValueSemantic = decodeNullValueSemantic( nullValue ); + if ( nullValueSemantic == NullValueSemantic.VALUE ) { + this.nullValue = nullValue; + } + } + + private static NullValueSemantic decodeNullValueSemantic(String nullValue) { + return switch ( nullValue ) { // magical values (legacy of hbm.xml) case "null" -> NullValueSemantic.NULL; case "none" -> NullValueSemantic.NONE; @@ -493,9 +500,6 @@ public void setNullValue(String nullValue) { case "undefined" -> NullValueSemantic.UNDEFINED; default -> NullValueSemantic.VALUE; }; - if ( nullValueSemantic == NullValueSemantic.VALUE ) { - this.nullValue = nullValue; - } } /** @@ -615,45 +619,6 @@ protected ConverterDescriptor getAttributeConverterDescriptor() { return attributeConverterDescriptor; } - // public Type getType() throws MappingException { -// if ( type != null ) { -// return type; -// } -// -// if ( typeName == null ) { -// throw new MappingException( "No type name" ); -// } -// -// if ( typeParameters != null -// && Boolean.valueOf( typeParameters.getProperty( DynamicParameterizedType.IS_DYNAMIC ) ) -// && typeParameters.get( DynamicParameterizedType.PARAMETER_TYPE ) == null ) { -// createParameterImpl(); -// } -// -// Type result = getMetadata().getTypeConfiguration().getTypeResolver().heuristicType( typeName, typeParameters ); -// -// if ( isVersion && result instanceof BinaryType ) { -// // if this is a byte[] version/timestamp, then we need to use RowVersionType -// // instead of BinaryType (HHH-10413) -// // todo (6.0) - although for T/SQL databases we should use its -// LOG.debug( "version is BinaryType; changing to RowVersionType" ); -// result = RowVersionType.INSTANCE; -// } -// -// if ( result == null ) { -// String msg = "Could not determine type for: " + typeName; -// if ( table != null ) { -// msg += ", at table: " + table.getName(); -// } -// if ( columns != null && columns.size() > 0 ) { -// msg += ", for columns: " + columns; -// } -// throw new MappingException( msg ); -// } -// -// return result; -// } - @Override public void setTypeUsingReflection(String className, String propertyName) throws MappingException { // NOTE: this is called as the last piece in setting SimpleValue type information, @@ -669,10 +634,10 @@ public void setTypeUsingReflection(String className, String propertyName) throws "Attribute types for a dynamic entity must be explicitly specified: " + propertyName ); } typeName = getClass( className, propertyName ).getName(); - // todo : to fully support isNationalized here we need to do the process hinted at above - // essentially, much of the logic from #buildAttributeConverterTypeAdapter wrt resolving - // a (1) JdbcType, a (2) JavaType and dynamically building a BasicType - // combining them. + // TODO: To fully support isNationalized here we need to do the process hinted at above + // essentially, much of the logic from #buildAttributeConverterTypeAdapter wrt + // resolving a (1) JdbcType, a (2) JavaType and dynamically building a BasicType + // combining them. } else { // we had an AttributeConverter @@ -896,7 +861,6 @@ public boolean hasAnyUpdatableColumns() { return true; } } - return false; } @@ -944,9 +908,11 @@ public void setJpaAttributeConverterDescriptor(ConverterDescriptor descript private static final Annotation[] NO_ANNOTATIONS = new Annotation[0]; private static Annotation[] getAnnotations(MemberDetails memberDetails) { final var directAnnotationUsages = - memberDetails == null ? null + memberDetails == null + ? null : memberDetails.getDirectAnnotationUsages(); - return directAnnotationUsages == null ? NO_ANNOTATIONS + return directAnnotationUsages == null + ? NO_ANNOTATIONS : directAnnotationUsages.toArray( Annotation[]::new ); } 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 74a55651cf2c..c0c3949b7bf9 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -878,7 +878,7 @@ public EmbeddableDomainType locateEmbeddable(Class embeddableClass, Compon final var embeddableDomainTypes = embeddablesToProcess.get( embeddableClass ); if ( embeddableDomainTypes != null ) { for ( var embeddableDomainType : embeddableDomainTypes ) { - final Component cachedComponent = componentByEmbeddable.get( embeddableDomainType ); + final var cachedComponent = componentByEmbeddable.get( embeddableDomainType ); if ( cachedComponent.isSame( component ) ) { return embeddableDomainType; }