diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractEntityIdGeneratorResolver.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractEntityIdGeneratorResolver.java index 77d11e05d5..d82d3b1862 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractEntityIdGeneratorResolver.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractEntityIdGeneratorResolver.java @@ -73,7 +73,7 @@ public abstract class AbstractEntityIdGeneratorResolver implements IdGeneratorRe } private void handleSequenceStrategy() { - if ( generatedValue.generator().isEmpty() ) { + if ( generatedValue.generator().isBlank() ) { handleUnnamedSequenceGenerator(); } else { @@ -86,7 +86,7 @@ public abstract class AbstractEntityIdGeneratorResolver implements IdGeneratorRe protected abstract void handleNamedSequenceGenerator(); private void handleTableStrategy() { - if ( generatedValue.generator().isEmpty() ) { + if ( generatedValue.generator().isBlank() ) { handleUnnamedTableGenerator(); } else { @@ -99,7 +99,7 @@ public abstract class AbstractEntityIdGeneratorResolver implements IdGeneratorRe protected abstract void handleNamedTableGenerator(); private void handleAutoStrategy() { - if ( generatedValue.generator().isEmpty() ) { + if ( generatedValue.generator().isBlank() ) { handleUnnamedAutoGenerator(); } else { @@ -148,7 +148,7 @@ public abstract class AbstractEntityIdGeneratorResolver implements IdGeneratorRe protected boolean handleAsLegacyGenerator() { // Handle a few legacy Hibernate generators... final String nameFromGeneratedValue = generatedValue.generator(); - if ( !nameFromGeneratedValue.isEmpty() ) { + if ( !nameFromGeneratedValue.isBlank() ) { final Class legacyNamedGenerator = mapLegacyNamedGenerator( nameFromGeneratedValue, idValue ); if ( legacyNamedGenerator != null ) { final Map configuration = buildLegacyGeneratorConfig(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java index 129b47af92..89700dbe94 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AbstractPropertyHolder.java @@ -4,7 +4,6 @@ */ package org.hibernate.boot.model.internal; -import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -24,7 +23,6 @@ import org.hibernate.boot.models.annotations.internal.ColumnJpaAnnotation; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.AnnotationTarget; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.MemberDetails; @@ -36,7 +34,6 @@ import org.jboss.logging.Logger; import jakarta.persistence.AssociationOverride; import jakarta.persistence.AttributeOverride; -import jakarta.persistence.CheckConstraint; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; import jakarta.persistence.Entity; @@ -47,7 +44,10 @@ import jakarta.persistence.MappedSuperclass; import static org.hibernate.boot.model.internal.TimeZoneStorageHelper.isOffsetTimeClass; import static org.hibernate.boot.model.internal.TimeZoneStorageHelper.useColumnForTimeZoneStorage; +import static org.hibernate.internal.util.StringHelper.isNotBlank; import static org.hibernate.internal.util.StringHelper.qualify; +import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; +import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; /** * @author Emmanuel Bernard @@ -153,10 +153,12 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { if ( isInIdClass != null ) { return isInIdClass; } - if ( parent != null ) { + else if ( parent != null ) { return parent.isInIdClass(); } - return false; + else { + return false; + } } @Override @@ -441,13 +443,15 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { return result; } - final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); + final SourceModelBuildingContext sourceModelContext = + context.getMetadataCollector().getSourceModelBuildingContext(); final Map> columnOverrideMap = new HashMap<>(); - final AttributeOverride[] overrides = element.getRepeatedAnnotationUsages( AttributeOverride.class, sourceModelContext ); - if ( CollectionHelper.isNotEmpty( overrides ) ) { + final AttributeOverride[] overrides = + element.getRepeatedAnnotationUsages( AttributeOverride.class, sourceModelContext ); + if ( isNotEmpty( overrides ) ) { for ( AttributeOverride depAttr : overrides ) { - final String qualifiedName = StringHelper.qualify( path, depAttr.name() ); + final String qualifiedName = qualify( path, depAttr.name() ); final Column column = depAttr.column(); if ( columnOverrideMap.containsKey( qualifiedName ) ) { @@ -529,7 +533,7 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { int secondPrecision; final Column annotatedColumn = element.getDirectAnnotationUsage( Column.class ); if ( annotatedColumn != null ) { - if ( StringHelper.isNotEmpty( annotatedColumn.name() ) ) { + if ( isNotBlank( annotatedColumn.name() ) ) { return annotatedColumn; } precision = annotatedColumn.precision(); @@ -564,7 +568,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { ) ); - final ColumnJpaAnnotation created = JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); + final ColumnJpaAnnotation created = + JpaAnnotations.COLUMN.createUsage( context.getMetadataCollector().getSourceModelBuildingContext() ); if ( StringHelper.isNotEmpty( implicitName.getText() ) ) { created.name( implicitName.getText() ); } @@ -587,12 +592,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { private static Map buildJoinColumnOverride(AnnotationTarget element, String path, MetadataBuildingContext context) { final Map columnOverride = new HashMap<>(); if ( element != null ) { - final AssociationOverride[] overrides = buildAssociationOverrides( element, path, context ); - for ( AssociationOverride override : overrides ) { - columnOverride.put( - qualify( path, override.name() ), - override.joinColumns() - ); + for ( AssociationOverride override : buildAssociationOverrides( element, path, context ) ) { + columnOverride.put( qualify( path, override.name() ), override.joinColumns() ); } } return columnOverride; @@ -601,12 +602,8 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { private static Map buildForeignKeyOverride(AnnotationTarget element, String path, MetadataBuildingContext context) { final Map foreignKeyOverride = new HashMap<>(); if ( element != null ) { - final AssociationOverride[] overrides = buildAssociationOverrides( element, path, context ); - for ( AssociationOverride override : overrides ) { - foreignKeyOverride.put( - qualify( path, override.name() ), - override.foreignKey() - ); + for ( AssociationOverride override : buildAssociationOverrides( element, path, context ) ) { + foreignKeyOverride.put( qualify( path, override.name() ), override.foreignKey() ); } } return foreignKeyOverride; @@ -619,14 +616,9 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { private static Map buildJoinTableOverride(AnnotationTarget element, String path, MetadataBuildingContext context) { final Map result = new HashMap<>(); if ( element != null ) { - final AssociationOverride[] overrides = buildAssociationOverrides( element, path, context ); - for ( AssociationOverride override : overrides ) { - final JoinColumn[] joinColumns = override.joinColumns(); - if ( CollectionHelper.isEmpty( joinColumns ) ) { - result.put( - qualify( path, override.name() ), - override.joinTable() - ); + for ( AssociationOverride override : buildAssociationOverrides( element, path, context ) ) { + if ( isEmpty( override.joinColumns() ) ) { + result.put( qualify( path, override.name() ), override.joinTable() ); } } } @@ -637,113 +629,4 @@ public abstract class AbstractPropertyHolder implements PropertyHolder { public void setParentProperty(String parentProperty) { throw new AssertionFailure( "Setting the parent property to a non component" ); } - - private static class ColumnImpl implements Column { - - private final String name; - private final boolean unique; - private final boolean nullable; - private final boolean insertable; - private final boolean updatable; - private final String columnDefinition; - private final String table; - private final int precision; - private final int secondPrecision; - - private ColumnImpl( - String name, - boolean unique, - boolean nullable, - boolean insertable, - boolean updatable, - String columnDefinition, - String table, - int precision, - int secondPrecision) { - this.name = name; - this.unique = unique; - this.nullable = nullable; - this.insertable = insertable; - this.updatable = updatable; - this.columnDefinition = columnDefinition; - this.table = table; - this.precision = precision; - this.secondPrecision = secondPrecision; - } - - @Override - public String name() { - return name; - } - - @Override - public boolean unique() { - return unique; - } - - @Override - public boolean nullable() { - return nullable; - } - - @Override - public boolean insertable() { - return insertable; - } - - @Override - public boolean updatable() { - return updatable; - } - - @Override - public String columnDefinition() { - return columnDefinition; - } - - @Override - public String options() { - return ""; - } - - @Override - public String table() { - return table; - } - - @Override - public int length() { - return 255; - } - - @Override - public int precision() { - return precision; - } - - @Override - public int scale() { - return 0; - } - - @Override - public int secondPrecision() { - return secondPrecision; - } - - @Override - public CheckConstraint[] check() { - return new CheckConstraint[0]; - } - - @Override - public String comment() { - return ""; - } - - @Override - public Class annotationType() { - return Column.class; - } - } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java index 44a9aafe88..a04bef3fcf 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedColumn.java @@ -28,8 +28,6 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.ArrayHelper; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.AggregateColumn; import org.hibernate.mapping.CheckConstraint; import org.hibernate.mapping.Column; @@ -46,9 +44,13 @@ import org.jboss.logging.Logger; import static org.hibernate.boot.model.internal.BinderHelper.getPath; import static org.hibernate.boot.model.internal.BinderHelper.getRelativePath; import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation; +import static org.hibernate.internal.util.StringHelper.isBlank; import static org.hibernate.internal.util.StringHelper.isEmpty; import static org.hibernate.internal.util.StringHelper.isNotEmpty; +import static org.hibernate.internal.util.StringHelper.nullIfBlank; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; +import static org.hibernate.internal.util.collections.ArrayHelper.isEmpty; +import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; /** * A mapping to a column, logically representing a @@ -664,7 +666,7 @@ public class AnnotatedColumn { } else { final jakarta.persistence.Column[] actualColumns = overrideColumns( columns, propertyHolder, inferredData ); - if ( ArrayHelper.isEmpty( actualColumns ) ) { + if ( isEmpty( actualColumns ) ) { return buildImplicitColumn( fractionalSeconds, inferredData, @@ -708,7 +710,7 @@ public class AnnotatedColumn { + " columns (every column must have exactly one '@AttributeOverride')" ); } LOG.debugf( "Column(s) overridden for property %s", inferredData.getPropertyName() ); - return ArrayHelper.isEmpty( overriddenCols ) ? null : overriddenCols; + return isEmpty( overriddenCols ) ? null : overriddenCols; } else { return columns; @@ -760,7 +762,7 @@ public class AnnotatedColumn { jakarta.persistence.Column column, Database database) { final String table = column.table(); - return table.isEmpty() + return table.isBlank() ? "" : database.getJdbcEnvironment().getIdentifierHelper().toIdentifier( table ).render(); } @@ -769,7 +771,7 @@ public class AnnotatedColumn { MetadataBuildingContext context, jakarta.persistence.Column column) { final String columnDefinition = column.columnDefinition(); - return columnDefinition.isEmpty() + return columnDefinition.isBlank() ? null : context.getObjectNameNormalizer().applyGlobalQuoting( columnDefinition ); } @@ -844,7 +846,7 @@ public class AnnotatedColumn { private static String getColumnName(Database database, jakarta.persistence.Column column) { final String name = column.name(); - return name.isEmpty() + return name.isBlank() ? null : database.getJdbcEnvironment().getIdentifierHelper().toIdentifier( name ).render(); } @@ -896,7 +898,7 @@ public class AnnotatedColumn { } void applyCheckConstraints(jakarta.persistence.CheckConstraint[] checkConstraintAnnotationUsages) { - if ( CollectionHelper.isNotEmpty( checkConstraintAnnotationUsages ) ) { + if ( isNotEmpty( checkConstraintAnnotationUsages ) ) { for ( jakarta.persistence.CheckConstraint checkConstraintAnnotationUsage : checkConstraintAnnotationUsages ) { addCheckConstraint( checkConstraintAnnotationUsage.name(), @@ -959,10 +961,10 @@ public class AnnotatedColumn { } final String targetColumnName = annotation.forColumn(); - if ( isEmpty( targetColumnName ) + if ( isBlank( targetColumnName ) || targetColumnName.equals( logicalColumnName != null ? logicalColumnName : "" ) ) { - readExpression = nullIfEmpty( annotation.read() ); - writeExpression = nullIfEmpty( annotation.write() ); + readExpression = nullIfBlank( annotation.read() ); + writeExpression = nullIfBlank( annotation.write() ); } } @@ -1016,7 +1018,7 @@ public class AnnotatedColumn { @Override public String toString() { - StringBuilder string = new StringBuilder(); + final StringBuilder string = new StringBuilder(); string.append( getClass().getSimpleName() ).append( "(" ); if ( isNotEmpty( logicalColumnName ) ) { string.append( "column='" ).append( logicalColumnName ).append( "'," ); @@ -1040,7 +1042,7 @@ public class AnnotatedColumn { } private void applyColumnComment(jakarta.persistence.Column column) { - if ( !column.comment().isEmpty() ) { + if ( !column.comment().isBlank() ) { comment = column.comment(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedDiscriminatorColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedDiscriminatorColumn.java index 26f19d8c2c..0be3f08c61 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedDiscriminatorColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedDiscriminatorColumn.java @@ -65,10 +65,10 @@ public class AnnotatedDiscriminatorColumn extends AnnotatedColumn { else if ( discriminatorColumn != null ) { discriminatorType = discriminatorColumn.discriminatorType(); column.setImplicit( false ); - if ( !discriminatorColumn.columnDefinition().isEmpty() ) { + if ( !discriminatorColumn.columnDefinition().isBlank() ) { column.setSqlType( discriminatorColumn.columnDefinition() ); } - if ( !discriminatorColumn.name().isEmpty() ) { + if ( !discriminatorColumn.name().isBlank() ) { column.setLogicalColumnName( discriminatorColumn.name() ); } column.setNullable( false ); @@ -82,7 +82,7 @@ public class AnnotatedDiscriminatorColumn extends AnnotatedColumn { column.setLogicalColumnName( columnOverride.name() ); final String columnDefinition = columnOverride.columnDefinition(); - if ( !columnDefinition.isEmpty() ) { + if ( !columnDefinition.isBlank() ) { column.setSqlType( columnDefinition ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumn.java index 196b5e6a1a..887812a1a1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumn.java @@ -176,12 +176,12 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { setImplicit( false ); final String name = joinColumn.name(); - if ( !name.isEmpty() ) { + if ( !name.isBlank() ) { setLogicalColumnName( name ); } final String columnDefinition = joinColumn.columnDefinition(); - if ( !columnDefinition.isEmpty() ) { + if ( !columnDefinition.isBlank() ) { setSqlType( getBuildingContext().getObjectNameNormalizer().applyGlobalQuoting( columnDefinition ) ); } @@ -194,7 +194,7 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { setOptions( joinColumn.options() ); final String table = joinColumn.table(); - if ( table.isEmpty() ) { + if ( table.isBlank() ) { setExplicitTableName( "" ); } else { @@ -248,11 +248,10 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { } final ObjectNameNormalizer normalizer = context.getObjectNameNormalizer(); - final String columnDef = columnDefinition.isEmpty() ? null - : normalizer.toDatabaseIdentifierText( columnDefinition ); - final String logicalColumnName = columnName.isEmpty() - ? normalizer.normalizeIdentifierQuotingAsString( defaultColumnName ) - : normalizer.normalizeIdentifierQuotingAsString( columnName ); + final String columnDef = + columnDefinition.isBlank() ? null : normalizer.toDatabaseIdentifierText( columnDefinition ); + final String logicalColumnName = + normalizer.normalizeIdentifierQuotingAsString( columnName.isBlank() ? defaultColumnName : columnName ); final AnnotatedJoinColumn column = new AnnotatedJoinColumn(); column.setSqlType( columnDef ); column.setLogicalColumnName( logicalColumnName ); @@ -321,8 +320,9 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { Column referencedColumn, PersistentClass referencedEntity, SimpleValue value) { - final String logicalReferencedColumn = getBuildingContext().getMetadataCollector() - .getLogicalColumnName( referencedEntity.getTable(), referencedColumn.getQuotedName() ); + final String logicalReferencedColumn = + getBuildingContext().getMetadataCollector() + .getLogicalColumnName( referencedEntity.getTable(), referencedColumn.getQuotedName() ); final String columnName = defaultColumnName( columnIndex, referencedEntity, logicalReferencedColumn ); //yuk side effect on an implicit column setLogicalColumnName( columnName ); @@ -407,15 +407,15 @@ public class AnnotatedJoinColumn extends AnnotatedColumn { final String referencedColumn = normalizer.normalizeIdentifierQuotingAsString( getReferencedColumn() ); final String unquotedLogColName = unquote( logicalColumnName ); final String unquotedRefColumn = unquote( referencedColumn ); - final String collectionColName = isNotEmpty( unquotedLogColName ) - ? unquotedLogColName - : getParent().getPropertyName() + '_' + unquotedRefColumn; + final String collectionColName = + isNotEmpty( unquotedLogColName ) + ? unquotedLogColName + : getParent().getPropertyName() + '_' + unquotedRefColumn; final InFlightMetadataCollector collector = getBuildingContext().getMetadataCollector(); - final String logicalCollectionColumnName = collector.getDatabase() - .getJdbcEnvironment() - .getIdentifierHelper() - .toIdentifier( collectionColName, isLogicalColumnQuoted ) - .render(); + final String logicalCollectionColumnName = + collector.getDatabase().getJdbcEnvironment().getIdentifierHelper() + .toIdentifier( collectionColName, isLogicalColumnQuoted ) + .render(); collector.addColumnNameBinding( value.getTable(), logicalCollectionColumnName, getMappingColumn() ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java index 48621739cc..120df0828a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotatedJoinColumns.java @@ -28,8 +28,6 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.MetadataBuildingOptions; import org.hibernate.boot.spi.PropertyData; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.ArrayHelper; import org.hibernate.mapping.Column; import org.hibernate.mapping.Component; import org.hibernate.mapping.Join; @@ -45,10 +43,12 @@ import jakarta.persistence.JoinColumn; import static org.hibernate.boot.model.internal.BinderHelper.findReferencedColumnOwner; import static org.hibernate.boot.model.internal.BinderHelper.getRelativePath; -import static org.hibernate.internal.util.StringHelper.isNotEmpty; +import static org.hibernate.internal.util.StringHelper.isBlank; +import static org.hibernate.internal.util.StringHelper.isNotBlank; import static org.hibernate.internal.util.StringHelper.isQuoted; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; import static org.hibernate.internal.util.StringHelper.qualify; +import static org.hibernate.internal.util.collections.ArrayHelper.isEmpty; /** * A list of {@link jakarta.persistence.JoinColumn}s that form a single join @@ -94,7 +94,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { final JoinFormula formula = columnOrFormula.formula(); final JoinColumn column = columnOrFormula.column(); final String annotationString = formula.value(); - if ( isNotEmpty( annotationString ) ) { + if ( isNotBlank( annotationString ) ) { AnnotatedJoinColumn.buildJoinFormula( formula, parent ); } else { @@ -114,8 +114,8 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { } final String referencedPropertyName = propertyRefUsage.value(); - if ( StringHelper.isEmpty( referencedPropertyName ) ) { - throw new AnnotationException( "@PropertyRef did not specify target attribute name : " + attributeMember ); + if ( isBlank( referencedPropertyName ) ) { + throw new AnnotationException( "@PropertyRef did not specify target attribute name: " + attributeMember ); } parent.referencedProperty = referencedPropertyName; } @@ -165,7 +165,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { PropertyData inferredData, String defaultColumnSuffix, MetadataBuildingContext context) { - assert mappedBy == null || !mappedBy.isEmpty(); + assert mappedBy == null || !mappedBy.isBlank(); final String propertyName = inferredData.getPropertyName(); final String path = qualify( propertyHolder.getPath(), propertyName ); final JoinColumn[] overrides = propertyHolder.getOverriddenJoinColumn( path ); @@ -177,7 +177,7 @@ public class AnnotatedJoinColumns extends AnnotatedColumns { parent.setPropertyName( getRelativePath( propertyHolder, propertyName ) ); parent.setMappedBy( mappedBy ); final MemberDetails memberDetails = inferredData.getAttributeMember(); - if ( ArrayHelper.isEmpty( actualColumns ) ) { + if ( isEmpty( actualColumns ) ) { AnnotatedJoinColumn.buildJoinColumn( null, // comment, diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java index 3fc27b90e0..e30b1a7a03 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/AnnotationBinder.java @@ -226,7 +226,7 @@ public final class AnnotationBinder { final String qualifiedName = annotatedClass.getName(); final String name = unqualify( qualifiedName ); final String rename = annotatedClass.getDirectAnnotationUsage( Imported.class ).rename(); - context.getMetadataCollector().addImport( rename.isEmpty() ? name : rename, qualifiedName ); + context.getMetadataCollector().addImport( rename.isBlank() ? name : rename, qualifiedName ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java index 20bbffbb6d..9b6f2d5ab2 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/BinderHelper.java @@ -71,9 +71,10 @@ import static jakarta.persistence.ConstraintMode.PROVIDER_DEFAULT; import static org.hibernate.boot.model.internal.AnnotatedColumn.buildColumnOrFormulaFromAnnotation; import static org.hibernate.boot.model.internal.AnyBinder.resolveImplicitDiscriminatorStrategy; import static org.hibernate.internal.util.StringHelper.isEmpty; -import static org.hibernate.internal.util.StringHelper.isNotEmpty; +import static org.hibernate.internal.util.StringHelper.isNotBlank; import static org.hibernate.internal.util.StringHelper.qualifier; import static org.hibernate.internal.util.StringHelper.qualify; +import static org.hibernate.internal.util.collections.ArrayHelper.isEmpty; import static org.hibernate.models.spi.TypeDetailsHelper.resolveRawClass; import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.EMBEDDED; import static org.hibernate.property.access.spi.BuiltInPropertyAccessStrategies.NOOP; @@ -890,9 +891,10 @@ public class BinderHelper { .getSourceModelBuildingContext() .getClassDetailsRegistry(); final PersistentClass persistentClass = propertyHolder.getPersistentClass(); - final String name = isEmpty( persistentClass.getClassName() ) - ? persistentClass.getEntityName() - : persistentClass.getClassName(); + final String name = + isEmpty( persistentClass.getClassName() ) + ? persistentClass.getEntityName() + : persistentClass.getClassName(); final ClassDetails classDetails = classDetailsRegistry.resolveClassDetails( name ); final InFlightMetadataCollector metadataCollector = buildingContext.getMetadataCollector(); if ( propertyHolder.isInIdClass() ) { @@ -912,7 +914,7 @@ public class BinderHelper { final Map ret = new HashMap<>(); for ( SqlFragmentAlias aliasAnnotation : aliases ) { final String table = aliasAnnotation.table(); - if ( isNotEmpty( table ) ) { + if ( isNotBlank( table ) ) { ret.put( aliasAnnotation.alias(), table ); } } @@ -952,7 +954,7 @@ public class BinderHelper { final CascadeType[] hibernateCascades = hibernateCascadeAnnotation == null ? null : hibernateCascadeAnnotation.value(); - if ( !ArrayHelper.isEmpty( hibernateCascades ) ) { + if ( !isEmpty( hibernateCascades ) ) { Collections.addAll( cascadeTypes, hibernateCascades ); } if ( orphanRemoval ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java index 0e692d6f5c..51f4a0c0f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ClassPropertyHolder.java @@ -127,12 +127,10 @@ public class ClassPropertyHolder extends AbstractPropertyHolder { property.forEachAnnotationUsage( Convert.class, getSourceModelContext(), (usage) -> { final AttributeConversionInfo info = new AttributeConversionInfo( usage, property ); - if ( isEmpty( info.getAttributeName() ) ) { - attributeConversionInfoMap.put( propertyName, info ); - } - else { - attributeConversionInfoMap.put( propertyName + '.' + info.getAttributeName(), info ); - } + final String path = isEmpty( info.getAttributeName() ) + ? propertyName + : propertyName + '.' + info.getAttributeName(); + attributeConversionInfoMap.put( path, info ); } ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java index 3b2af005bf..ba1ce62ab9 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionBinder.java @@ -84,9 +84,7 @@ import org.hibernate.boot.spi.SecondPass; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.ArrayHelper; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jdbc.Expectation; import org.hibernate.mapping.Any; import org.hibernate.mapping.Backref; @@ -172,11 +170,12 @@ import static org.hibernate.boot.model.internal.PropertyHolderBuilder.buildPrope import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.fromResultCheckStyle; import static org.hibernate.internal.util.ReflectHelper.getDefaultSupplier; import static org.hibernate.internal.util.StringHelper.getNonEmptyOrConjunctionIfBothNonEmpty; -import static org.hibernate.internal.util.StringHelper.isEmpty; -import static org.hibernate.internal.util.StringHelper.isNotEmpty; +import static org.hibernate.internal.util.StringHelper.isBlank; +import static org.hibernate.internal.util.StringHelper.isNotBlank; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; import static org.hibernate.internal.util.StringHelper.qualify; import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; +import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; import static org.hibernate.mapping.MappingHelper.createLocalUserCollectionTypeBean; /** @@ -459,7 +458,7 @@ public abstract class CollectionBinder { if ( property.hasDirectAnnotationUsage( OrderColumn.class ) && manyToMany != null - && StringHelper.isNotEmpty( manyToMany.mappedBy() ) ) { + && isNotBlank( manyToMany.mappedBy() ) ) { throw new AnnotationException("Collection '" + getPath( propertyHolder, inferredData ) + "' is the unowned side of a bidirectional '@ManyToMany' and may not have an '@OrderColumn'"); } @@ -740,16 +739,16 @@ public abstract class CollectionBinder { } collectionBinder.setExplicitAssociationTable( true ); - if ( CollectionHelper.isNotEmpty( jpaIndexes ) ) { + if ( isNotEmpty( jpaIndexes ) ) { associationTableBinder.setJpaIndex( jpaIndexes ); } - if ( !schema.isEmpty() ) { + if ( !schema.isBlank() ) { associationTableBinder.setSchema( schema ); } - if ( !catalog.isEmpty() ) { + if ( !catalog.isBlank() ) { associationTableBinder.setCatalog( catalog ); } - if ( !tableName.isEmpty() ) { + if ( !tableName.isBlank() ) { associationTableBinder.setName( tableName ); } associationTableBinder.setUniqueConstraints( uniqueConstraints ); @@ -910,7 +909,7 @@ public abstract class CollectionBinder { Class implementation, Map parameters, MetadataBuildingContext buildingContext) { - final boolean hasParameters = CollectionHelper.isNotEmpty( parameters ); + final boolean hasParameters = isNotEmpty( parameters ); if ( !buildingContext.getBuildingOptions().isAllowExtensionsInCdi() ) { // if deferred container access is enabled, we locally create the user-type return createLocalUserCollectionTypeBean( role, implementation, hasParameters, parameters ); @@ -1094,13 +1093,13 @@ public abstract class CollectionBinder { final SourceModelBuildingContext sourceModelContext = buildingContext.getMetadataCollector().getSourceModelBuildingContext(); final ManyToMany manyToMany = property.getAnnotationUsage( ManyToMany.class, sourceModelContext ); - if ( manyToMany != null && !manyToMany.mappedBy().isEmpty() ) { + if ( manyToMany != null && !manyToMany.mappedBy().isBlank() ) { // We don't support @OrderColumn on the non-owning side of a many-to-many association. return CollectionClassification.BAG; } final OneToMany oneToMany = property.getAnnotationUsage( OneToMany.class, sourceModelContext ); - if ( oneToMany != null && !oneToMany.mappedBy().isEmpty() ) { + if ( oneToMany != null && !oneToMany.mappedBy().isBlank() ) { // Unowned to-many mappings are always considered BAG by default return CollectionClassification.BAG; } @@ -1268,7 +1267,7 @@ public abstract class CollectionBinder { private void bindCache() { //set cache - if ( isNotEmpty( cacheConcurrencyStrategy ) ) { + if ( isNotBlank( cacheConcurrencyStrategy ) ) { collection.setCacheConcurrencyStrategy( cacheConcurrencyStrategy ); collection.setCacheRegionName( cacheRegionName ); } @@ -1780,7 +1779,7 @@ public abstract class CollectionBinder { final String hqlOrderBy = extractHqlOrderBy( jpaOrderBy ); if ( hqlOrderBy != null ) { final String orderByFragment = buildOrderByClauseFromHql( hqlOrderBy, associatedClass ); - if ( isNotEmpty( orderByFragment ) ) { + if ( isNotBlank( orderByFragment ) ) { collection.setOrderBy( orderByFragment ); } } @@ -1824,7 +1823,7 @@ public abstract class CollectionBinder { final String alias = aliasAnnotation.alias(); final String table = aliasAnnotation.table(); - if ( isNotEmpty( table ) ) { + if ( isNotBlank( table ) ) { aliasTableMap.put( alias, table ); } @@ -1870,7 +1869,7 @@ public abstract class CollectionBinder { } final String whereJoinTableClause = getWhereJoinTableClause(); - if ( isNotEmpty( whereJoinTableClause ) ) { + if ( isNotBlank( whereJoinTableClause ) ) { if ( hasAssociationTable ) { // This is a many-to-many association. // Collection#setWhere is used to set the "where" clause that applies to the collection table @@ -1926,7 +1925,7 @@ public abstract class CollectionBinder { final String alias = aliasAnnotation.alias(); final String table = aliasAnnotation.table(); - if ( isNotEmpty( table ) ) { + if ( isNotBlank( table ) ) { aliasTableMap.put( alias, table ); } @@ -1952,14 +1951,14 @@ public abstract class CollectionBinder { private String getFilterConditionForJoinTable(FilterJoinTable filterJoinTableAnnotation) { final String condition = filterJoinTableAnnotation.condition(); - return condition.isEmpty() + return condition.isBlank() ? getDefaultFilterCondition( filterJoinTableAnnotation.name(), filterJoinTableAnnotation ) : condition; } private String getFilterCondition(Filter filter) { final String condition = filter.condition(); - return condition.isEmpty() + return condition.isBlank() ? getDefaultFilterCondition( filter.name(), filter ) : condition; } @@ -1972,7 +1971,7 @@ public abstract class CollectionBinder { + "' for an undefined filter named '" + name + "'" ); } final String defaultCondition = definition.getDefaultFilterCondition(); - if ( isEmpty( defaultCondition ) ) { + if ( isBlank( defaultCondition ) ) { throw new AnnotationException( "Collection '" + qualify( propertyHolder.getPath(), propertyName ) + "' has a '@" + annotation.annotationType().getSimpleName() + "' with no 'condition' and no default condition was given by the '@FilterDef' named '" @@ -2016,7 +2015,7 @@ public abstract class CollectionBinder { if ( orderByFragment == null ) { return null; } - else if ( orderByFragment.isEmpty() ) { + else if ( orderByFragment.isBlank() ) { //order by id return buildOrderById( associatedClass, " asc" ); } @@ -2042,7 +2041,7 @@ public abstract class CollectionBinder { public static String adjustUserSuppliedValueCollectionOrderingFragment(String orderByFragment) { if ( orderByFragment != null ) { orderByFragment = orderByFragment.trim(); - if ( orderByFragment.isEmpty() || orderByFragment.equalsIgnoreCase( "asc" ) ) { + if ( orderByFragment.isBlank() || orderByFragment.equalsIgnoreCase( "asc" ) ) { // This indicates something like either: // `@OrderBy()` // `@OrderBy("asc") @@ -2124,7 +2123,7 @@ public abstract class CollectionBinder { if ( !ArrayHelper.isEmpty( joinColumnAnnotations ) ) { final JoinColumn joinColumnAnn = joinColumnAnnotations[0]; final ForeignKey joinColumnForeignKey = joinColumnAnn.foreignKey(); - if ( foreignKeyName.isEmpty() ) { + if ( foreignKeyName.isBlank() ) { foreignKeyName = joinColumnForeignKey.name(); foreignKeyDefinition = joinColumnForeignKey.foreignKeyDefinition(); foreignKeyOptions = joinColumnForeignKey.options(); @@ -2153,7 +2152,7 @@ public abstract class CollectionBinder { final OneToMany oneToManyAnn = property.getDirectAnnotationUsage( OneToMany.class ); final OnDelete onDeleteAnn = property.getDirectAnnotationUsage( OnDelete.class ); if ( oneToManyAnn != null - && !oneToManyAnn.mappedBy().isEmpty() + && !oneToManyAnn.mappedBy().isBlank() && ( onDeleteAnn == null || onDeleteAnn.action() != OnDeleteAction.CASCADE ) ) { // foreign key should be up to @ManyToOne side // @OnDelete generate "on delete cascade" foreign key @@ -2342,7 +2341,7 @@ public abstract class CollectionBinder { inheritanceStatePerClass ); collection.setElement( component ); - if ( isNotEmpty( hqlOrderBy ) ) { + if ( isNotBlank( hqlOrderBy ) ) { final String orderBy = adjustUserSuppliedValueCollectionOrderingFragment( hqlOrderBy ); if ( orderBy != null ) { collection.setOrderBy( orderBy ); @@ -2455,7 +2454,7 @@ public abstract class CollectionBinder { final JoinColumn[] inverseJoinColumns = joinTableAnn.inverseJoinColumns(); if ( !ArrayHelper.isEmpty( inverseJoinColumns ) ) { final JoinColumn joinColumnAnn = inverseJoinColumns[0]; - if ( foreignKeyName.isEmpty() ) { + if ( foreignKeyName.isBlank() ) { final ForeignKey inverseJoinColumnForeignKey = joinColumnAnn.foreignKey(); foreignKeyName = inverseJoinColumnForeignKey.name(); foreignKeyDefinition = inverseJoinColumnForeignKey.foreignKeyDefinition(); @@ -2544,7 +2543,7 @@ public abstract class CollectionBinder { collector.getLogicalTableName( owner.getTable() ), collector.getFromMappedBy( owner.getEntityName(), joinColumns.getPropertyName() ) ); - if ( isEmpty( tableBinder.getName() ) ) { + if ( isBlank( tableBinder.getName() ) ) { //default value tableBinder.setDefaultName( owner.getClassName(), @@ -2581,7 +2580,7 @@ public abstract class CollectionBinder { private static void addCheckToCollection(Table collectionTable, Check check) { final String name = check.name(); final String constraint = check.constraints(); - collectionTable.addCheck( name.isEmpty() + collectionTable.addCheck( name.isBlank() ? new CheckConstraint( constraint ) : new CheckConstraint( name, constraint ) ); } @@ -2742,7 +2741,7 @@ public abstract class CollectionBinder { private static void checkFilterConditions(Collection collection) { //for now it can't happen, but sometime soon... - if ( ( !collection.getFilters().isEmpty() || isNotEmpty( collection.getWhere() ) ) + if ( ( !collection.getFilters().isEmpty() || isNotBlank( collection.getWhere() ) ) && collection.getFetchMode() == FetchMode.JOIN && !( collection.getElement() instanceof SimpleValue ) //SimpleValue (CollectionOfElements) are always SELECT but it does not matter && collection.getElement().getFetchMode() != FetchMode.JOIN ) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java index 1aa15b8116..acee46bec0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/CollectionPropertyHolder.java @@ -109,16 +109,16 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { // elements cannot be converted so any @Convert likely meant the key, so we apply it to the key final AttributeConversionInfo info = new AttributeConversionInfo( convertAnnotation, collectionProperty ); + final String attributeName = info.getAttributeName(); if ( collection.isMap() ) { - boolean specCompliant = isNotEmpty( info.getAttributeName() ) - && ( info.getAttributeName().startsWith( "key" ) - || info.getAttributeName().startsWith( "value" ) ); + final boolean specCompliant = isNotEmpty( attributeName ) + && ( attributeName.startsWith( "key" ) || attributeName.startsWith( "value" ) ); if ( !specCompliant ) { log.nonCompliantMapConversion( collection.getRole() ); } } - if ( isEmpty( info.getAttributeName() ) ) { + if ( isEmpty( attributeName ) ) { // the @Convert did not name an attribute... if ( canElementBeConverted && canKeyBeConverted ) { if ( !isComposite ) { @@ -147,8 +147,8 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { final String elementPath; if ( canElementBeConverted && canKeyBeConverted ) { - keyPath = removePrefix( info.getAttributeName(), "key" ); - elementPath = removePrefix( info.getAttributeName(), "value" ); + keyPath = removePrefix( attributeName, "key" ); + elementPath = removePrefix( attributeName, "value" ); if ( keyPath == null && elementPath == null ) { // specified attributeName needs to have 'key.' or 'value.' prefix @@ -159,12 +159,12 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { } } else if ( canKeyBeConverted ) { - keyPath = removePrefix( info.getAttributeName(), "key", info.getAttributeName() ); + keyPath = removePrefix( attributeName, "key", attributeName ); elementPath = null; } else { keyPath = null; - elementPath = removePrefix( info.getAttributeName(), "value", info.getAttributeName() ); + elementPath = removePrefix( attributeName, "value", attributeName ); } if ( keyPath != null ) { @@ -179,7 +179,7 @@ public class CollectionPropertyHolder extends AbstractPropertyHolder { String.format( Locale.ROOT, "Could not determine how to apply @Convert(attributeName='%s') to collection [%s]", - info.getAttributeName(), + attributeName, collection.getRole() ) ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ColumnsBuilder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ColumnsBuilder.java index 66680b100b..f98e1c8b31 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ColumnsBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ColumnsBuilder.java @@ -38,6 +38,7 @@ import static org.hibernate.boot.model.internal.BinderHelper.getPath; import static org.hibernate.boot.model.internal.BinderHelper.getPropertyOverriddenByMapperOrMapsId; import static org.hibernate.boot.model.internal.DialectOverridesAnnotationHelper.getOverridableAnnotation; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; +import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; /** * Do the initial discovery of columns metadata and apply defaults. @@ -245,7 +246,7 @@ class ColumnsBuilder { HibernateAnnotations.JOIN_COLUMN_OR_FORMULA, sourceModelContext ); - if ( CollectionHelper.isNotEmpty( annotations ) ) { + if ( isNotEmpty( annotations ) ) { return annotations; } @@ -259,7 +260,7 @@ class ColumnsBuilder { JpaAnnotations.JOIN_COLUMN, sourceModelContext ); - if ( CollectionHelper.isNotEmpty( joinColumns ) ) { + if ( isNotEmpty( joinColumns ) ) { return joinColumns; } @@ -272,7 +273,7 @@ class ColumnsBuilder { JpaAnnotations.PRIMARY_KEY_JOIN_COLUMN, sourceModelContext ); - if ( CollectionHelper.isNotEmpty( primaryKeyJoinColumns ) ) { + if ( isNotEmpty( primaryKeyJoinColumns ) ) { final JoinColumn[] adapters = new JoinColumn[primaryKeyJoinColumns.length]; for ( int i = 0; i < primaryKeyJoinColumns.length; i++ ) { final PrimaryKeyJoinColumn primaryKeyJoinColumn = primaryKeyJoinColumns[i]; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DelayedParameterizedTypeBean.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DelayedParameterizedTypeBean.java index dc791b0b77..422ff95ec5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DelayedParameterizedTypeBean.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DelayedParameterizedTypeBean.java @@ -11,6 +11,8 @@ import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.resource.beans.spi.ManagedBean; import org.hibernate.usertype.ParameterizedType; +import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; + /** * ManagedBean implementation for delayed {@link ParameterizedType} * handling (parameter injection) for a UserCollectionType @@ -51,7 +53,7 @@ public class DelayedParameterizedTypeBean implements ManagedBean { String role, ManagedBean bean, Properties properties) { - if ( CollectionHelper.isNotEmpty( properties ) ) { + if ( isNotEmpty( properties ) ) { if ( ParameterizedType.class.isAssignableFrom( bean.getBeanClass() ) ) { return new DelayedParameterizedTypeBean<>( bean, properties ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DialectOverridesAnnotationHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DialectOverridesAnnotationHelper.java index 18675c99af..edfcdfbd75 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DialectOverridesAnnotationHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/DialectOverridesAnnotationHelper.java @@ -18,6 +18,8 @@ import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.models.spi.AnnotationTarget; import org.hibernate.models.spi.SourceModelBuildingContext; +import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; + /** * @author Sanne Grinovero * @author Steve Ebersole @@ -84,7 +86,7 @@ public class DialectOverridesAnnotationHelper { final Dialect dialect = context.getMetadataCollector().getDatabase().getDialect(); final Annotation[] overrides = element.getRepeatedAnnotationUsages( overrideAnnotation, sourceModelContext ); - if ( CollectionHelper.isNotEmpty( overrides ) ) { + if ( isNotEmpty( overrides ) ) { for ( int i = 0; i < overrides.length; i++ ) { //noinspection unchecked final DialectOverrider override = (DialectOverrider) overrides[i]; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java index c5dc04fa65..dd26cf9238 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EmbeddableBinder.java @@ -27,7 +27,6 @@ import org.hibernate.boot.spi.AccessType; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; @@ -70,9 +69,10 @@ import static org.hibernate.boot.model.internal.PropertyBinder.addElementsOfClas import static org.hibernate.boot.model.internal.PropertyBinder.processElementAnnotations; import static org.hibernate.boot.model.internal.PropertyHolderBuilder.buildPropertyHolder; import static org.hibernate.internal.CoreLogging.messageLogger; -import static org.hibernate.internal.util.StringHelper.isEmpty; +import static org.hibernate.internal.util.StringHelper.isBlank; import static org.hibernate.internal.util.StringHelper.qualify; import static org.hibernate.internal.util.StringHelper.unqualify; +import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; /** * A binder responsible for interpreting {@link Embeddable} classes and producing @@ -232,7 +232,7 @@ public class EmbeddableBinder { final SourceModelBuildingContext sourceModelContext = context.getMetadataCollector().getSourceModelBuildingContext(); final List metaAnnotatedAnnotations = annotatedClass.determineRawClass().getMetaAnnotated( TypeBinderType.class, sourceModelContext ); - if ( CollectionHelper.isEmpty( metaAnnotatedAnnotations ) ) { + if ( isEmpty( metaAnnotatedAnnotations ) ) { return; } @@ -712,7 +712,7 @@ public class EmbeddableBinder { ? annotatedClass.getDirectAnnotationUsage( DiscriminatorValue.class ).value() : null; final String discriminatorValue; - if ( isEmpty( explicitValue ) ) { + if ( isBlank( explicitValue ) ) { final String name = unqualify( annotatedClass.getName() ); if ( "character".equals( discriminatorType.getName() ) ) { throw new AnnotationException( String.format( diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java index e927c76ed0..b7fe306488 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/EntityBinder.java @@ -77,7 +77,6 @@ import org.hibernate.engine.spi.FilterDefinition; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.util.StringHelper; import org.hibernate.internal.util.collections.ArrayHelper; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.jdbc.Expectation; import org.hibernate.jpa.event.internal.CallbackDefinitionResolver; import org.hibernate.jpa.event.spi.CallbackType; @@ -155,10 +154,12 @@ import static org.hibernate.boot.model.naming.Identifier.toIdentifier; import static org.hibernate.engine.OptimisticLockStyle.fromLockType; import static org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle.fromResultCheckStyle; import static org.hibernate.internal.util.ReflectHelper.getDefaultSupplier; +import static org.hibernate.internal.util.StringHelper.isBlank; import static org.hibernate.internal.util.StringHelper.isEmpty; -import static org.hibernate.internal.util.StringHelper.isNotEmpty; +import static org.hibernate.internal.util.StringHelper.isNotBlank; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; import static org.hibernate.internal.util.StringHelper.unqualify; +import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; @@ -367,7 +368,7 @@ public class EntityBinder { private void addCheckToEntity(Check check) { final String name = check.name(); final String constraint = check.constraints(); - persistentClass.addCheckConstraint( name.isEmpty() + persistentClass.addCheckConstraint( name.isBlank() ? new CheckConstraint( constraint ) : new CheckConstraint( name, constraint ) ); } @@ -1300,7 +1301,7 @@ public class EntityBinder { throw new AssertionFailure( "@Entity should never be missing" ); } final String entityName = entity.name(); - name = entityName.isEmpty() ? unqualify( annotatedClass.getName() ) : entityName; + name = entityName.isBlank() ? unqualify( annotatedClass.getName() ) : entityName; } public boolean isRootEntity() { @@ -1351,7 +1352,7 @@ public class EntityBinder { + "' is annotated '@Immutable' but it is a subclass in an entity inheritance hierarchy" + " (only a root class may declare its mutability)" ); } - if ( isNotEmpty( where ) ) { + if ( isNotBlank( where ) ) { throw new AnnotationException( "Entity class '" + annotatedClass.getName() + "' specifies an '@SQLRestriction' but it is a subclass in an entity inheritance hierarchy" + " (only a root class may be specify a restriction)" ); @@ -1386,7 +1387,7 @@ public class EntityBinder { private void bindRootEntity() { final RootClass rootClass = (RootClass) persistentClass; rootClass.setMutable( isMutable() ); - if ( isNotEmpty( where ) ) { + if ( isNotBlank( where ) ) { rootClass.setWhere( where ); } if ( cacheConcurrentStrategy != null ) { @@ -1498,11 +1499,11 @@ public class EntityBinder { } final A override = dialectOverride.override(); - if ( isEmpty( tableName ) + if ( isBlank( tableName ) && isEmpty( ( (CustomSqlDetails) override ).table() ) ) { return override; } - else if ( isNotEmpty( tableName ) + else if ( isNotBlank( tableName ) && tableName.equals( ( (CustomSqlDetails) override ).table() ) ) { return override; } @@ -1516,7 +1517,7 @@ public class EntityBinder { for ( Filter filter : filters ) { final String filterName = filter.name(); String condition = filter.condition(); - if ( condition.isEmpty() ) { + if ( condition.isBlank() ) { condition = getDefaultFilterCondition( filterName ); } persistentClass.addFilter( @@ -1536,7 +1537,7 @@ public class EntityBinder { + "' has a '@Filter' for an undefined filter named '" + filterName + "'" ); } final String condition = definition.getDefaultFilterCondition(); - if ( isEmpty( condition ) ) { + if ( isBlank( condition ) ) { throw new AnnotationException( "Entity '" + name + "' has a '@Filter' with no 'condition' and no default condition was given by the '@FilterDef' named '" + filterName + "'" ); @@ -1587,7 +1588,7 @@ public class EntityBinder { final String discriminatorValue = discriminatorValueAnn != null ? discriminatorValueAnn.value() : null; - if ( isEmpty( discriminatorValue ) ) { + if ( isBlank( discriminatorValue ) ) { final Value discriminator = persistentClass.getDiscriminator(); if ( discriminator == null ) { persistentClass.setDiscriminatorValue( name ); @@ -1646,12 +1647,13 @@ public class EntityBinder { } final String region = naturalIdCacheAnn.region(); - if ( region.isEmpty() ) { + if ( region.isBlank() ) { final Cache explicitCacheAnn = annotatedClass.getAnnotationUsage( Cache.class, getSourceModelContext() ); - naturalIdCacheRegion = explicitCacheAnn != null && isNotEmpty( explicitCacheAnn.region() ) - ? explicitCacheAnn.region() + NATURAL_ID_CACHE_SUFFIX - : annotatedClass.getName() + NATURAL_ID_CACHE_SUFFIX; + naturalIdCacheRegion = + explicitCacheAnn != null && isNotBlank( explicitCacheAnn.region() ) + ? explicitCacheAnn.region() + NATURAL_ID_CACHE_SUFFIX + : annotatedClass.getName() + NATURAL_ID_CACHE_SUFFIX; } else { naturalIdCacheRegion = naturalIdCacheAnn.region(); @@ -1853,7 +1855,7 @@ public class EntityBinder { final EntityTableNamingStrategyHelper namingStrategyHelper = new EntityTableNamingStrategyHelper( persistentClass.getClassName(), entityName, name ); final Identifier logicalName = - isNotEmpty( tableName ) + isNotBlank( tableName ) ? namingStrategyHelper.handleExplicitName( tableName, context ) : namingStrategyHelper.determineImplicitName( context ); @@ -1917,7 +1919,7 @@ public class EntityBinder { final Annotation[] joinColumnSource = (Annotation[]) incoming; final AnnotatedJoinColumns annotatedJoinColumns; - if ( CollectionHelper.isEmpty( joinColumnSource ) ) { + if ( isEmpty( joinColumnSource ) ) { annotatedJoinColumns = createDefaultJoinColumn( propertyHolder ); } else { @@ -2047,7 +2049,7 @@ public class EntityBinder { private SecondaryRow findMatchingSecondaryRowAnnotation(String tableName) { final SecondaryRow row = annotatedClass.getDirectAnnotationUsage( SecondaryRow.class ); - if ( row != null && ( row.table().isEmpty() || tableName.equals( row.table() ) ) ) { + if ( row != null && ( row.table().isBlank() || tableName.equals( row.table() ) ) ) { return row; } else { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java index 93c27d9504..aa977b7dbc 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/FilterDefBinder.java @@ -34,6 +34,7 @@ import static org.hibernate.boot.model.internal.AnnotationHelper.resolveBasicTyp import static org.hibernate.boot.model.internal.AnnotationHelper.resolveJavaType; import static org.hibernate.boot.model.internal.AnnotationHelper.resolveUserType; import static org.hibernate.internal.CoreLogging.messageLogger; +import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; /** * @author Gavin King @@ -57,7 +58,7 @@ public class FilterDefBinder { final Map paramJdbcMappings; final Map>> parameterResolvers; final ParamDef[] explicitParameters = filterDef.parameters(); - if ( CollectionHelper.isEmpty( explicitParameters ) ) { + if ( isEmpty( explicitParameters ) ) { paramJdbcMappings = emptyMap(); parameterResolvers = emptyMap(); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorParameters.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorParameters.java index b7902a3075..9d4f961d28 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorParameters.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorParameters.java @@ -25,8 +25,6 @@ import org.hibernate.id.enhanced.SequenceStyleGenerator; import org.hibernate.id.enhanced.SingleNamingStrategy; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.Column; import org.hibernate.mapping.RootClass; import org.hibernate.mapping.SimpleValue; @@ -47,6 +45,8 @@ import static org.hibernate.id.OptimizableGenerator.INITIAL_PARAM; import static org.hibernate.id.PersistentIdentifierGenerator.PK; import static org.hibernate.id.PersistentIdentifierGenerator.TABLE; import static org.hibernate.id.PersistentIdentifierGenerator.TABLES; +import static org.hibernate.internal.util.StringHelper.isNotBlank; +import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; /** * Responsible for setting up the parameters which are passed to @@ -220,22 +220,22 @@ public class GeneratorParameters { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.CONFIG_PREFER_SEGMENT_PER_ENTITY, "true" ); final String catalog = tableGeneratorAnnotation.catalog(); - if ( StringHelper.isNotEmpty( catalog ) ) { + if ( isNotBlank( catalog ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.CATALOG, catalog ); } final String schema = tableGeneratorAnnotation.schema(); - if ( StringHelper.isNotEmpty( schema ) ) { + if ( isNotBlank( schema ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.SCHEMA, schema ); } final String table = tableGeneratorAnnotation.table(); - if ( StringHelper.isNotEmpty( table ) ) { + if ( isNotBlank( table ) ) { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.TABLE_PARAM, table ); } final String pkColumnName = tableGeneratorAnnotation.pkColumnName(); - if ( StringHelper.isNotEmpty( pkColumnName ) ) { + if ( isNotBlank( pkColumnName ) ) { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.SEGMENT_COLUMN_PARAM, pkColumnName @@ -243,7 +243,7 @@ public class GeneratorParameters { } final String pkColumnValue = tableGeneratorAnnotation.pkColumnValue(); - if ( StringHelper.isNotEmpty( pkColumnValue ) ) { + if ( isNotBlank( pkColumnValue ) ) { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.SEGMENT_VALUE_PARAM, pkColumnValue @@ -251,7 +251,7 @@ public class GeneratorParameters { } final String valueColumnName = tableGeneratorAnnotation.valueColumnName(); - if ( StringHelper.isNotEmpty( valueColumnName ) ) { + if ( isNotBlank( valueColumnName ) ) { definitionBuilder.addParam( org.hibernate.id.enhanced.TableGenerator.VALUE_COLUMN_PARAM, valueColumnName @@ -259,7 +259,7 @@ public class GeneratorParameters { } final String options = tableGeneratorAnnotation.options(); - if ( StringHelper.isNotEmpty( options ) ) { + if ( isNotBlank( options ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.OPTIONS, options @@ -279,7 +279,7 @@ public class GeneratorParameters { // TODO : implement unique-constraint support final UniqueConstraint[] uniqueConstraints = tableGeneratorAnnotation.uniqueConstraints(); - if ( CollectionHelper.isNotEmpty( uniqueConstraints ) ) { + if ( isNotEmpty( uniqueConstraints ) ) { LOG.ignoringTableGeneratorConstraints( tableGeneratorAnnotation.name() ); } } @@ -292,17 +292,17 @@ public class GeneratorParameters { definitionBuilder.setStrategy( SequenceStyleGenerator.class.getName() ); final String catalog = sequenceGeneratorAnnotation.catalog(); - if ( StringHelper.isNotEmpty( catalog ) ) { + if ( isNotBlank( catalog ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.CATALOG, catalog ); } final String schema = sequenceGeneratorAnnotation.schema(); - if ( StringHelper.isNotEmpty( schema ) ) { + if ( isNotBlank( schema ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.SCHEMA, schema ); } final String sequenceName = sequenceGeneratorAnnotation.sequenceName(); - if ( StringHelper.isNotEmpty( sequenceName ) ) { + if ( isNotBlank( sequenceName ) ) { definitionBuilder.addParam( SequenceStyleGenerator.SEQUENCE_PARAM, sequenceName ); } @@ -316,7 +316,7 @@ public class GeneratorParameters { ); final String options = sequenceGeneratorAnnotation.options(); - if ( StringHelper.isNotEmpty( options ) ) { + if ( isNotBlank( options ) ) { definitionBuilder.addParam( PersistentIdentifierGenerator.OPTIONS, options ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ImplicitToOneJoinTableSecondPass.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ImplicitToOneJoinTableSecondPass.java index e79cb6e8fb..e02053b9ef 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ImplicitToOneJoinTableSecondPass.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ImplicitToOneJoinTableSecondPass.java @@ -11,7 +11,6 @@ import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.boot.spi.SecondPass; -import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.Join; import org.hibernate.mapping.ManyToOne; import org.hibernate.mapping.PersistentClass; @@ -21,6 +20,7 @@ import jakarta.persistence.JoinTable; import static org.hibernate.boot.model.internal.ToOneBinder.getReferenceEntityName; import static org.hibernate.internal.util.StringHelper.isEmpty; +import static org.hibernate.internal.util.StringHelper.isNotBlank; /** * For {@link jakarta.persistence.ManyToOne} and {@link jakarta.persistence.OneToOne} @@ -88,17 +88,17 @@ public class ImplicitToOneJoinTableSecondPass implements SecondPass { tableBinder.setBuildingContext( context ); final String schema = joinTable.schema(); - if ( StringHelper.isNotEmpty( schema ) ) { + if ( isNotBlank( schema ) ) { tableBinder.setSchema( schema ); } final String catalog = joinTable.catalog(); - if ( StringHelper.isNotEmpty( catalog ) ) { + if ( isNotBlank( catalog ) ) { tableBinder.setCatalog( catalog ); } final String tableName = joinTable.name(); - if ( StringHelper.isNotEmpty( tableName ) ) { + if ( isNotBlank( tableName ) ) { tableBinder.setName( tableName ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java index a0334fe914..d737e5ae5a 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/IndexColumn.java @@ -96,7 +96,7 @@ public class IndexColumn extends AnnotatedColumn { if ( orderColumn != null ) { final String sqlType = nullIfEmpty( orderColumn.columnDefinition() ); final String explicitName = orderColumn.name(); - final String name = explicitName.isEmpty() + final String name = explicitName.isBlank() ? inferredData.getPropertyName() + "_ORDER" : explicitName; final IndexColumn column = new IndexColumn(); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java index 9bc6a9ea87..102f0193b8 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryBinder.java @@ -36,7 +36,6 @@ import org.hibernate.internal.CoreMessageLogger; import org.hibernate.internal.log.DeprecationLogger; import org.hibernate.jpa.HibernateHints; import org.hibernate.jpa.internal.util.FlushModeTypeHelper; -import org.hibernate.models.internal.util.StringHelper; import org.hibernate.models.spi.ClassDetails; import org.hibernate.models.spi.SourceModelBuildingContext; import org.hibernate.query.sql.internal.ParameterParser; @@ -60,6 +59,7 @@ import static org.hibernate.internal.util.StringHelper.nullIfEmpty; import static org.hibernate.internal.util.collections.ArrayHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.determineProperSizing; import static org.hibernate.internal.util.collections.CollectionHelper.setOf; +import static org.hibernate.models.internal.util.StringHelper.isEmpty; /** * Responsible for reading named queries defined in annotations and registering @@ -85,7 +85,7 @@ public abstract class QueryBinder { final String queryString = namedQuery.query(); final Class resultClass = namedQuery.resultClass(); - if ( queryName.isEmpty() ) { + if ( queryName.isBlank() ) { throw new AnnotationException( "Class or package level '@NamedQuery' annotation must specify a 'name'" ); } @@ -135,7 +135,7 @@ public abstract class QueryBinder { final String registrationName = namedNativeQuery.name(); final String queryString = namedNativeQuery.query(); - if ( registrationName.isEmpty() ) { + if ( registrationName.isBlank() ) { throw new AnnotationException( "Class or package level '@NamedNativeQuery' annotation must specify a 'name'" ); } @@ -223,7 +223,7 @@ public abstract class QueryBinder { final String registrationName = namedNativeQuery.name(); - if ( registrationName.isEmpty() ) { + if ( registrationName.isBlank() ) { throw new AnnotationException( "Class or package level '@NamedNativeQuery' annotation must specify a 'name'" ); } @@ -321,7 +321,7 @@ public abstract class QueryBinder { final String typeName = builder.getParameterTypes().get( paramName ); final ClassDetails classDetails; - if ( StringHelper.isEmpty( typeName ) ) { + if ( isEmpty( typeName ) ) { classDetails = ClassDetails.VOID_CLASS_DETAILS; } else { @@ -391,7 +391,7 @@ public abstract class QueryBinder { final String registrationName = namedQuery.name(); final Class resultClass = namedQuery.resultClass(); - if ( registrationName.isEmpty() ) { + if ( registrationName.isBlank() ) { throw new AnnotationException( "Class or package level '@NamedQuery' annotation must specify a 'name'" ); } @@ -452,7 +452,7 @@ public abstract class QueryBinder { MetadataBuildingContext context, boolean isDefault) { if ( namedStoredProcedureQuery != null ) { - if ( namedStoredProcedureQuery.name().isEmpty() ) { + if ( namedStoredProcedureQuery.name().isBlank() ) { throw new AnnotationException( "Class or package level '@NamedStoredProcedureQuery' annotation must specify a 'name'" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java index 6e8f4feebd..0ddfc3c513 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/QueryHintDefinition.java @@ -25,6 +25,8 @@ import jakarta.persistence.LockModeType; import jakarta.persistence.NamedQuery; import jakarta.persistence.QueryHint; +import static java.util.Collections.emptyMap; +import static org.hibernate.internal.util.collections.CollectionHelper.isEmpty; import static org.hibernate.internal.util.collections.CollectionHelper.mapOfSize; /** @@ -36,8 +38,8 @@ public class QueryHintDefinition { public QueryHintDefinition(String queryName, final QueryHint[] hints) { this.queryName = queryName; - if ( CollectionHelper.isEmpty( hints ) ) { - hintsMap = Collections.emptyMap(); + if ( isEmpty( hints ) ) { + hintsMap = emptyMap(); } else { final Map hintsMap = mapOfSize( hints.length ); diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SoftDeleteHelper.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SoftDeleteHelper.java index f7e0fcb23c..2451cde4a5 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SoftDeleteHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/SoftDeleteHelper.java @@ -11,7 +11,6 @@ import org.hibernate.boot.model.naming.PhysicalNamingStrategy; import org.hibernate.boot.model.relational.Database; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.dialect.Dialect; -import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.Column; import org.hibernate.mapping.SoftDeletable; @@ -32,6 +31,7 @@ import org.hibernate.type.descriptor.converter.spi.BasicValueConverter; import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter; import static org.hibernate.internal.util.StringHelper.coalesce; +import static org.hibernate.internal.util.StringHelper.isBlank; import static org.hibernate.query.sqm.ComparisonOperator.EQUAL; /** @@ -93,7 +93,7 @@ public class SoftDeleteHelper { softDeleteColumn.setNullable( false ); softDeleteColumn.setUnique( false ); softDeleteColumn.setOptions( softDeleteConfig.options() ); - if ( StringHelper.isEmpty( softDeleteConfig.comment() ) ) { + if ( isBlank( softDeleteConfig.comment() ) ) { softDeleteColumn.setComment( "Soft-delete indicator" ); } else { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java index 60e876c3fc..b47cc0e0a1 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/TableBinder.java @@ -22,8 +22,6 @@ import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.dialect.Dialect; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.mapping.Any; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.mapping.CheckConstraint; import org.hibernate.mapping.Collection; import org.hibernate.mapping.Column; @@ -45,10 +43,12 @@ import org.jboss.logging.Logger; import jakarta.persistence.Index; import jakarta.persistence.UniqueConstraint; +import static org.hibernate.internal.util.StringHelper.isNotBlank; import static org.hibernate.internal.util.StringHelper.isNotEmpty; import static org.hibernate.internal.util.StringHelper.isQuoted; -import static org.hibernate.internal.util.StringHelper.nullIfEmpty; +import static org.hibernate.internal.util.StringHelper.nullIfBlank; import static org.hibernate.internal.util.StringHelper.unquote; +import static org.hibernate.internal.util.collections.CollectionHelper.isNotEmpty; /** * Stateful binder responsible for producing instances of {@link Table}. @@ -492,8 +492,8 @@ public class TableBinder { final InFlightMetadataCollector metadataCollector = buildingContext.getMetadataCollector(); final Table table = addTable( - nullIfEmpty( schema ), - nullIfEmpty( catalog ), + nullIfBlank( schema ), + nullIfBlank( catalog ), logicalName, isAbstract, buildingContext, @@ -868,7 +868,7 @@ public class TableBinder { static void addTableCheck( Table table, jakarta.persistence.CheckConstraint[] checkConstraintAnnotationUsages) { - if ( CollectionHelper.isNotEmpty( checkConstraintAnnotationUsages ) ) { + if ( isNotEmpty( checkConstraintAnnotationUsages ) ) { for ( jakarta.persistence.CheckConstraint checkConstraintAnnotationUsage : checkConstraintAnnotationUsages ) { table.addCheck( new CheckConstraint( @@ -882,13 +882,13 @@ public class TableBinder { } static void addTableComment(Table table, String comment) { - if ( StringHelper.isNotEmpty( comment ) ) { + if ( isNotBlank( comment ) ) { table.setComment( comment ); } } static void addTableOptions(Table table, String options) { - if ( StringHelper.isNotEmpty( options ) ) { + if ( isNotBlank( options ) ) { table.setOptions( options ); } } diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneBinder.java index f1143d7406..caf1073bf0 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/ToOneBinder.java @@ -22,7 +22,6 @@ import org.hibernate.boot.spi.InFlightMetadataCollector; import org.hibernate.boot.spi.MetadataBuildingContext; import org.hibernate.boot.spi.PropertyData; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.StringHelper; import org.hibernate.mapping.Join; import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.SimpleValue; @@ -53,7 +52,8 @@ import static org.hibernate.boot.model.internal.BinderHelper.getPath; import static org.hibernate.boot.model.internal.BinderHelper.isDefault; import static org.hibernate.boot.model.internal.BinderHelper.noConstraint; import static org.hibernate.internal.CoreLogging.messageLogger; -import static org.hibernate.internal.util.StringHelper.isEmpty; +import static org.hibernate.internal.util.StringHelper.isBlank; +import static org.hibernate.internal.util.StringHelper.isNotBlank; import static org.hibernate.internal.util.StringHelper.nullIfEmpty; import static org.hibernate.internal.util.StringHelper.qualify; @@ -158,7 +158,7 @@ public class ToOneBinder { boolean inSecondPass, PropertyBinder propertyBinder, MetadataBuildingContext context) { - if ( joinTable != null && !isEmpty( joinTable.name() ) ) { + if ( joinTable != null && !isBlank( joinTable.name() ) ) { final Join join = propertyHolder.addJoin( joinTable, false ); // TODO: if notFoundAction!=null should we call join.disableForeignKeyCreation() ? for ( AnnotatedJoinColumn joinColumn : joinColumns.getJoinColumns() ) { @@ -173,7 +173,7 @@ public class ToOneBinder { final org.hibernate.mapping.ManyToOne value = new org.hibernate.mapping.ManyToOne( context, joinColumns.getTable() ); - if ( joinTable != null && isEmpty( joinTable.name() ) ) { + if ( joinTable != null && isBlank( joinTable.name() ) ) { context.getMetadataCollector().addSecondPass( new ImplicitToOneJoinTableSecondPass( propertyHolder, inferredData, @@ -274,7 +274,7 @@ public class ToOneBinder { if ( property.hasDirectAnnotationUsage( ManyToOne.class ) && joinColumn != null ) { final String joinColumnName = joinColumn.name(); - if ( StringHelper.isNotEmpty( joinColumnName ) + if ( isNotBlank( joinColumnName ) && joinColumnName.equals( columnName ) && !property.hasDirectAnnotationUsage( MapsId.class ) ) { hasSpecjManyToOne = true; diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/XMLContext.java b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/XMLContext.java index 8089bc3001..558c80e391 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/internal/XMLContext.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/internal/XMLContext.java @@ -29,11 +29,13 @@ import org.hibernate.boot.spi.BootstrapContext; import org.hibernate.boot.spi.ClassLoaderAccess; import org.hibernate.internal.CoreLogging; import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.StringHelper; import jakarta.persistence.AccessType; import jakarta.persistence.AttributeConverter; +import static org.hibernate.internal.util.StringHelper.isNotEmpty; +import static org.hibernate.internal.util.StringHelper.qualify; + /** * A helper for consuming orm.xml mappings. * @@ -189,10 +191,9 @@ public class XMLContext implements Serializable { } public static String buildSafeClassName(String className, String defaultPackageName) { - if ( className.indexOf( '.' ) < 0 && StringHelper.isNotEmpty( defaultPackageName ) ) { - className = StringHelper.qualify( defaultPackageName, className ); - } - return className; + return className.indexOf( '.' ) < 0 && isNotEmpty( defaultPackageName ) + ? qualify( defaultPackageName, className ) + : className; } public static String buildSafeClassName(String className, Default defaults) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/naming/Identifier.java b/hibernate-core/src/main/java/org/hibernate/boot/model/naming/Identifier.java index aca49e4afb..764034ea56 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/naming/Identifier.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/naming/Identifier.java @@ -9,6 +9,8 @@ import java.util.Locale; import org.hibernate.dialect.Dialect; import org.hibernate.internal.util.StringHelper; +import static org.hibernate.internal.util.StringHelper.isBlank; + /** * Models an identifier (name), which may or may not be quoted. * @@ -75,7 +77,7 @@ public class Identifier implements Comparable { * @return The identifier form, or {@code null} if text was {@code null} */ public static Identifier toIdentifier(String text, boolean quote, boolean quoteOnNonIdentifierChar) { - if ( StringHelper.isEmpty( text ) ) { + if ( isBlank( text ) ) { return null; } int start = 0; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java index 5d42c174a1..41aee6f2fe 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/StringHelper.java @@ -570,6 +570,10 @@ public final class StringHelper { return string == null || string.isEmpty(); } + public static boolean isNotBlank(@Nullable String string) { + return string != null && !string.isBlank(); + } + public static boolean isBlank(@Nullable String string) { return string == null || string.isBlank(); } @@ -813,6 +817,10 @@ public final class StringHelper { return isEmpty( value ) ? null : value; } + public static String nullIfBlank(@Nullable String value) { + return isBlank( value ) ? null : value; + } + public static String subStringNullIfEmpty(String value, Character startChar) { if ( isEmpty( value ) ) { return null;