HHH-14190 Rename isEmptyOrWhitespace() to isBlank()
and use it in more places
This commit is contained in:
parent
beabfecb3e
commit
9c6805fdd3
|
@ -43,7 +43,7 @@ public class FilterSourceImpl
|
||||||
for ( Serializable content : filterElement.getContent() ) {
|
for ( Serializable content : filterElement.getContent() ) {
|
||||||
if ( String.class.isInstance( content ) ) {
|
if ( String.class.isInstance( content ) ) {
|
||||||
final String str = content.toString();
|
final String str = content.toString();
|
||||||
if ( !StringHelper.isEmptyOrWhiteSpace( str ) ) {
|
if ( !StringHelper.isBlank( str ) ) {
|
||||||
conditionContent = str.trim();
|
conditionContent = str.trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -349,7 +349,7 @@ public class Example implements Criterion {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String conditionFragment = condition.toSqlString( criteria, cq );
|
final String conditionFragment = condition.toSqlString( criteria, cq );
|
||||||
if ( conditionFragment.trim().length() > 0 ) {
|
if ( !StringHelper.isBlank( conditionFragment ) ) {
|
||||||
if ( buf.length() > 1 ) {
|
if ( buf.length() > 1 ) {
|
||||||
buf.append( " and " );
|
buf.append( " and " );
|
||||||
}
|
}
|
||||||
|
|
|
@ -484,7 +484,7 @@ public class JoinSequence {
|
||||||
* @return {@link this}, for method chaining
|
* @return {@link this}, for method chaining
|
||||||
*/
|
*/
|
||||||
public JoinSequence addCondition(String condition) {
|
public JoinSequence addCondition(String condition) {
|
||||||
if ( condition.trim().length() != 0 ) {
|
if ( !StringHelper.isBlank( condition ) ) {
|
||||||
if ( !condition.startsWith( " and " ) ) {
|
if ( !condition.startsWith( " and " ) ) {
|
||||||
conditions.append( " and " );
|
conditions.append( " and " );
|
||||||
}
|
}
|
||||||
|
|
|
@ -472,10 +472,19 @@ public final class StringHelper {
|
||||||
return string == null || string.isEmpty();
|
return string == null || string.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isEmptyOrWhiteSpace(String string) {
|
public static boolean isBlank(String string) {
|
||||||
return isEmpty( string ) || isEmpty( string.trim() );
|
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) {
|
public static String qualify(String prefix, String name) {
|
||||||
if ( name == null || prefix == null ) {
|
if ( name == null || prefix == null ) {
|
||||||
throw new NullPointerException( "prefix or name were null attempting to build qualified name" );
|
throw new NullPointerException( "prefix or name were null attempting to build qualified name" );
|
||||||
|
|
|
@ -1112,7 +1112,7 @@ public class JoinWalker {
|
||||||
collectionSuffix,
|
collectionSuffix,
|
||||||
join.getJoinType() == JoinType.LEFT_OUTER_JOIN
|
join.getJoinType() == JoinType.LEFT_OUTER_JOIN
|
||||||
);
|
);
|
||||||
if ( selectFragment.trim().length() > 0 ) {
|
if ( !StringHelper.isBlank( selectFragment ) ) {
|
||||||
buf.append( ", " ).append( selectFragment );
|
buf.append( ", " ).append( selectFragment );
|
||||||
}
|
}
|
||||||
if ( joinable.consumesEntityAlias() ) {
|
if ( joinable.consumesEntityAlias() ) {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.util.Map;
|
||||||
import org.hibernate.MappingException;
|
import org.hibernate.MappingException;
|
||||||
import org.hibernate.engine.internal.JoinHelper;
|
import org.hibernate.engine.internal.JoinHelper;
|
||||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.persister.collection.QueryableCollection;
|
import org.hibernate.persister.collection.QueryableCollection;
|
||||||
import org.hibernate.persister.entity.Joinable;
|
import org.hibernate.persister.entity.Joinable;
|
||||||
import org.hibernate.sql.JoinFragment;
|
import org.hibernate.sql.JoinFragment;
|
||||||
|
@ -77,7 +78,7 @@ public final class OuterJoinableAssociation {
|
||||||
this.joinable = joinableType.getAssociatedJoinable( factory );
|
this.joinable = joinableType.getAssociatedJoinable( factory );
|
||||||
this.rhsColumns = JoinHelper.getRHSColumnNames( joinableType, factory );
|
this.rhsColumns = JoinHelper.getRHSColumnNames( joinableType, factory );
|
||||||
this.on = joinableType.getOnCondition( rhsAlias, factory, enabledFilters )
|
this.on = joinableType.getOnCondition( rhsAlias, factory, enabledFilters )
|
||||||
+ ( withClause == null || withClause.trim().length() == 0 ? "" : " and ( " + withClause + " )" );
|
+ ( StringHelper.isBlank( withClause ) ? "" : " and ( " + withClause + " )" );
|
||||||
this.hasRestriction = hasRestriction;
|
this.hasRestriction = hasRestriction;
|
||||||
this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application
|
this.enabledFilters = enabledFilters; // needed later for many-to-many/filter application
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ public class InformationExtractorJdbcDatabaseMetaDataImpl implements Information
|
||||||
""
|
""
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if ( ! StringHelper.isEmptyOrWhiteSpace( extraPhysycalTableTypesConfig ) ) {
|
if ( ! StringHelper.isBlank( extraPhysycalTableTypesConfig ) ) {
|
||||||
this.extraPhysicalTableTypes = StringHelper.splitTrimmingTokens(
|
this.extraPhysicalTableTypes = StringHelper.splitTrimmingTokens(
|
||||||
",;",
|
",;",
|
||||||
extraPhysycalTableTypesConfig,
|
extraPhysycalTableTypesConfig,
|
||||||
|
|
|
@ -27,6 +27,7 @@ import javax.persistence.Version;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
|
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -142,7 +143,7 @@ public class EmbeddableWithManyToMany_HHH_11302_Test
|
||||||
result += "id: " + id;
|
result += "id: " + id;
|
||||||
}
|
}
|
||||||
result += ", version: " + version;
|
result += ", version: " + version;
|
||||||
if ( type != null && !type.trim().isEmpty() ) {
|
if ( !StringHelper.isBlank( type ) ) {
|
||||||
result += ", type: " + type;
|
result += ", type: " + type;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -27,6 +27,7 @@ import javax.persistence.Version;
|
||||||
|
|
||||||
import org.hibernate.AnnotationException;
|
import org.hibernate.AnnotationException;
|
||||||
|
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -142,7 +143,7 @@ public class EmbeddableWithOneToMany_HHH_11302_Test
|
||||||
result += "id: " + id;
|
result += "id: " + id;
|
||||||
}
|
}
|
||||||
result += ", version: " + version;
|
result += ", version: " + version;
|
||||||
if ( type != null && !type.trim().isEmpty() ) {
|
if ( !StringHelper.isBlank( type ) ) {
|
||||||
result += ", type: " + type;
|
result += ", type: " + type;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package org.hibernate.test.annotations.embeddables.collection.xml;
|
package org.hibernate.test.annotations.embeddables.collection.xml;
|
||||||
|
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -71,7 +73,7 @@ public class ContactType implements Serializable {
|
||||||
result += "id: " + id;
|
result += "id: " + id;
|
||||||
}
|
}
|
||||||
result += ", version: " + version;
|
result += ", version: " + version;
|
||||||
if ( type != null && !type.trim().isEmpty() ) {
|
if ( !StringHelper.isBlank( type ) ) {
|
||||||
result += ", type: " + type;
|
result += ", type: " + type;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -11,6 +11,7 @@ import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Types;
|
import java.sql.Types;
|
||||||
|
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.type.descriptor.ValueBinder;
|
import org.hibernate.type.descriptor.ValueBinder;
|
||||||
import org.hibernate.type.descriptor.ValueExtractor;
|
import org.hibernate.type.descriptor.ValueExtractor;
|
||||||
import org.hibernate.type.descriptor.WrapperOptions;
|
import org.hibernate.type.descriptor.WrapperOptions;
|
||||||
|
@ -55,7 +56,7 @@ public class MyCustomSqlTypeDescriptor implements SqlTypeDescriptor {
|
||||||
@Override
|
@Override
|
||||||
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
|
protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
|
||||||
final String valueStr = javaTypeDescriptor.unwrap( value, String.class, options );
|
final String valueStr = javaTypeDescriptor.unwrap( value, String.class, options );
|
||||||
if ( valueStr == null || valueStr.trim().isEmpty() ) {
|
if ( StringHelper.isBlank( valueStr ) ) {
|
||||||
st.setNull( index, getSqlType() );
|
st.setNull( index, getSqlType() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -66,7 +67,7 @@ public class MyCustomSqlTypeDescriptor implements SqlTypeDescriptor {
|
||||||
@Override
|
@Override
|
||||||
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
|
protected void doBind(CallableStatement st, X value, String name, WrapperOptions options) throws SQLException {
|
||||||
final String valueStr = javaTypeDescriptor.unwrap( value, String.class, options );
|
final String valueStr = javaTypeDescriptor.unwrap( value, String.class, options );
|
||||||
if ( valueStr == null || valueStr.trim().isEmpty() ) {
|
if ( StringHelper.isBlank( valueStr ) ) {
|
||||||
st.setNull( name, getSqlType() );
|
st.setNull( name, getSqlType() );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -13,9 +13,7 @@ import java.util.Map;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.hibernate.Criteria;
|
import org.hibernate.Criteria;
|
||||||
import org.hibernate.FetchMode;
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
import org.hibernate.criterion.CriteriaSpecification;
|
|
||||||
import org.hibernate.criterion.Restrictions;
|
import org.hibernate.criterion.Restrictions;
|
||||||
import org.hibernate.sql.JoinFragment;
|
import org.hibernate.sql.JoinFragment;
|
||||||
import org.hibernate.sql.JoinType;
|
import org.hibernate.sql.JoinType;
|
||||||
|
@ -622,7 +620,4 @@ public class OuterJoinCriteriaTest extends BaseCoreFunctionalTestCase {
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isBlank(String s) {
|
|
||||||
return s == null || s.trim().length() == 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue