diff --git a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/FilterSourceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/FilterSourceImpl.java index ecdbe1d3f5..0ce509069d 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/FilterSourceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/hbm/FilterSourceImpl.java @@ -43,7 +43,7 @@ public class FilterSourceImpl for ( Serializable content : filterElement.getContent() ) { if ( String.class.isInstance( content ) ) { final String str = content.toString(); - if ( !StringHelper.isEmptyOrWhiteSpace( str ) ) { + if ( !StringHelper.isBlank( str ) ) { conditionContent = str.trim(); } } diff --git a/hibernate-core/src/main/java/org/hibernate/criterion/Example.java b/hibernate-core/src/main/java/org/hibernate/criterion/Example.java index 535e529d35..fda3317373 100644 --- a/hibernate-core/src/main/java/org/hibernate/criterion/Example.java +++ b/hibernate-core/src/main/java/org/hibernate/criterion/Example.java @@ -349,7 +349,7 @@ public class Example implements Criterion { } final String conditionFragment = condition.toSqlString( criteria, cq ); - if ( conditionFragment.trim().length() > 0 ) { + if ( !StringHelper.isBlank( conditionFragment ) ) { if ( buf.length() > 1 ) { buf.append( " and " ); } diff --git a/hibernate-core/src/main/java/org/hibernate/engine/internal/JoinSequence.java b/hibernate-core/src/main/java/org/hibernate/engine/internal/JoinSequence.java index af300a5ed3..f9ca7acfb6 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/internal/JoinSequence.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/internal/JoinSequence.java @@ -484,7 +484,7 @@ public class JoinSequence { * @return {@link this}, for method chaining */ public JoinSequence addCondition(String condition) { - if ( condition.trim().length() != 0 ) { + if ( !StringHelper.isBlank( condition ) ) { if ( !condition.startsWith( " and " ) ) { conditions.append( " and " ); } 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 87813e414a..f04a36d301 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 @@ -472,10 +472,19 @@ public final class StringHelper { return string == null || string.isEmpty(); } - public static boolean isEmptyOrWhiteSpace(String string) { + public static boolean isBlank(String string) { return isEmpty( string ) || isEmpty( string.trim() ); } + /** + * @deprecated use {@link #isBlank(String)} + * @return + */ + @Deprecated + public static boolean isEmptyOrWhitespace(String string) { + return isBlank(string); + } + public static String qualify(String prefix, String name) { if ( name == null || prefix == null ) { throw new NullPointerException( "prefix or name were null attempting to build qualified name" ); diff --git a/hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java b/hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java index 9ce89b60de..2ab2859b4f 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/JoinWalker.java @@ -1112,7 +1112,7 @@ public class JoinWalker { collectionSuffix, join.getJoinType() == JoinType.LEFT_OUTER_JOIN ); - if ( selectFragment.trim().length() > 0 ) { + if ( !StringHelper.isBlank( selectFragment ) ) { buf.append( ", " ).append( selectFragment ); } if ( joinable.consumesEntityAlias() ) { diff --git a/hibernate-core/src/main/java/org/hibernate/loader/OuterJoinableAssociation.java b/hibernate-core/src/main/java/org/hibernate/loader/OuterJoinableAssociation.java index a0b5a8fed6..deb666dc26 100644 --- a/hibernate-core/src/main/java/org/hibernate/loader/OuterJoinableAssociation.java +++ b/hibernate-core/src/main/java/org/hibernate/loader/OuterJoinableAssociation.java @@ -13,6 +13,7 @@ import java.util.Map; import org.hibernate.MappingException; import org.hibernate.engine.internal.JoinHelper; import org.hibernate.engine.spi.SessionFactoryImplementor; +import org.hibernate.internal.util.StringHelper; import org.hibernate.persister.collection.QueryableCollection; import org.hibernate.persister.entity.Joinable; import org.hibernate.sql.JoinFragment; @@ -77,7 +78,7 @@ public final class OuterJoinableAssociation { this.joinable = joinableType.getAssociatedJoinable( factory ); this.rhsColumns = JoinHelper.getRHSColumnNames( joinableType, factory ); this.on = joinableType.getOnCondition( rhsAlias, factory, enabledFilters ) - + ( withClause == null || withClause.trim().length() == 0 ? "" : " and ( " + withClause + " )" ); + + ( StringHelper.isBlank( withClause ) ? "" : " and ( " + withClause + " )" ); this.hasRestriction = hasRestriction; this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java index 7a04dfee5a..7f80d02311 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/extract/internal/InformationExtractorJdbcDatabaseMetaDataImpl.java @@ -72,7 +72,7 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information "" ) ); - if ( ! StringHelper.isEmptyOrWhiteSpace( extraPhysycalTableTypesConfig ) ) { + if ( ! StringHelper.isBlank( extraPhysycalTableTypesConfig ) ) { this.extraPhysicalTableTypes = StringHelper.splitTrimmingTokens( ",;", extraPhysycalTableTypesConfig, diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/EmbeddableWithManyToMany_HHH_11302_Test.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/EmbeddableWithManyToMany_HHH_11302_Test.java index 7840a7912d..6b1ecb2b70 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/EmbeddableWithManyToMany_HHH_11302_Test.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/EmbeddableWithManyToMany_HHH_11302_Test.java @@ -27,6 +27,7 @@ import javax.persistence.Version; import org.hibernate.AnnotationException; +import org.hibernate.internal.util.StringHelper; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -142,7 +143,7 @@ public class EmbeddableWithManyToMany_HHH_11302_Test result += "id: " + id; } result += ", version: " + version; - if ( type != null && !type.trim().isEmpty() ) { + if ( !StringHelper.isBlank( type ) ) { result += ", type: " + type; } return result; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/EmbeddableWithOneToMany_HHH_11302_Test.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/EmbeddableWithOneToMany_HHH_11302_Test.java index 893d6c1e04..0ec874fca4 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/EmbeddableWithOneToMany_HHH_11302_Test.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/EmbeddableWithOneToMany_HHH_11302_Test.java @@ -27,6 +27,7 @@ import javax.persistence.Version; import org.hibernate.AnnotationException; +import org.hibernate.internal.util.StringHelper; import org.hibernate.testing.TestForIssue; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.junit.Test; @@ -142,7 +143,7 @@ public class EmbeddableWithOneToMany_HHH_11302_Test result += "id: " + id; } result += ", version: " + version; - if ( type != null && !type.trim().isEmpty() ) { + if ( !StringHelper.isBlank( type ) ) { result += ", type: " + type; } return result; diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/ContactType.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/ContactType.java index 9344c197d5..8004defe4c 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/ContactType.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/embeddables/collection/xml/ContactType.java @@ -1,5 +1,7 @@ package org.hibernate.test.annotations.embeddables.collection.xml; +import org.hibernate.internal.util.StringHelper; + import java.io.Serializable; /** @@ -71,7 +73,7 @@ public class ContactType implements Serializable { result += "id: " + id; } result += ", version: " + version; - if ( type != null && !type.trim().isEmpty() ) { + if ( !StringHelper.isBlank( type ) ) { result += ", type: " + type; } return result; diff --git a/hibernate-core/src/test/java/org/hibernate/test/converter/custom/MyCustomSqlTypeDescriptor.java b/hibernate-core/src/test/java/org/hibernate/test/converter/custom/MyCustomSqlTypeDescriptor.java index a9f336232d..2773bd9561 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/converter/custom/MyCustomSqlTypeDescriptor.java +++ b/hibernate-core/src/test/java/org/hibernate/test/converter/custom/MyCustomSqlTypeDescriptor.java @@ -11,6 +11,7 @@ import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Types; +import org.hibernate.internal.util.StringHelper; import org.hibernate.type.descriptor.ValueBinder; import org.hibernate.type.descriptor.ValueExtractor; import org.hibernate.type.descriptor.WrapperOptions; @@ -55,7 +56,7 @@ public class MyCustomSqlTypeDescriptor implements SqlTypeDescriptor { @Override protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException { final String valueStr = javaTypeDescriptor.unwrap( value, String.class, options ); - if ( valueStr == null || valueStr.trim().isEmpty() ) { + if ( StringHelper.isBlank( valueStr ) ) { st.setNull( index, getSqlType() ); } else { @@ -66,7 +67,7 @@ public class MyCustomSqlTypeDescriptor implements SqlTypeDescriptor { @Override protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException { final String valueStr = javaTypeDescriptor.unwrap( value, String.class, options ); - if ( valueStr == null || valueStr.trim().isEmpty() ) { + if ( StringHelper.isBlank( valueStr ) ) { st.setNull( name, getSqlType() ); } else { diff --git a/hibernate-core/src/test/java/org/hibernate/test/criteria/OuterJoinCriteriaTest.java b/hibernate-core/src/test/java/org/hibernate/test/criteria/OuterJoinCriteriaTest.java index a4e2f65ccb..3143e175d7 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/criteria/OuterJoinCriteriaTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/criteria/OuterJoinCriteriaTest.java @@ -13,9 +13,7 @@ import java.util.Map; import org.junit.Test; import org.hibernate.Criteria; -import org.hibernate.FetchMode; import org.hibernate.Session; -import org.hibernate.criterion.CriteriaSpecification; import org.hibernate.criterion.Restrictions; import org.hibernate.sql.JoinFragment; import org.hibernate.sql.JoinType; @@ -622,7 +620,4 @@ public class OuterJoinCriteriaTest extends BaseCoreFunctionalTestCase { s.close(); } - private static boolean isBlank(String s) { - return s == null || s.trim().length() == 0; - } }