From 7ca12c7d80b196bc5c982d14e1c1ca47d781e99e Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Fri, 17 Apr 2015 14:35:09 -0400 Subject: [PATCH] HHH-9722 cleanup, removed StringHelper methods --- .../cfg/annotations/EntityBinder.java | 35 +++++++++---------- .../hibernate/internal/util/StringHelper.java | 18 ++-------- .../tool/hbm2ddl/ForeignKeyMetadata.java | 12 +++---- .../hibernate/tool/hbm2ddl/TableMetadata.java | 23 ++++++------ .../envers/internal/tools/StringTools.java | 3 +- 5 files changed, 39 insertions(+), 52 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java index f8fc843a5d..5a4daf850e 100644 --- a/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java @@ -23,22 +23,6 @@ */ package org.hibernate.cfg.annotations; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import javax.persistence.Access; -import javax.persistence.ConstraintMode; -import javax.persistence.Entity; -import javax.persistence.JoinColumn; -import javax.persistence.JoinTable; -import javax.persistence.NamedEntityGraph; -import javax.persistence.NamedEntityGraphs; -import javax.persistence.PrimaryKeyJoinColumn; -import javax.persistence.SecondaryTable; -import javax.persistence.SecondaryTables; - import org.hibernate.AnnotationException; import org.hibernate.AssertionFailure; import org.hibernate.EntityMode; @@ -103,9 +87,24 @@ import org.hibernate.mapping.SingleTableSubclass; import org.hibernate.mapping.Table; import org.hibernate.mapping.TableOwner; import org.hibernate.mapping.Value; - import org.jboss.logging.Logger; +import javax.persistence.Access; +import javax.persistence.ConstraintMode; +import javax.persistence.Entity; +import javax.persistence.JoinColumn; +import javax.persistence.JoinTable; +import javax.persistence.NamedEntityGraph; +import javax.persistence.NamedEntityGraphs; +import javax.persistence.PrimaryKeyJoinColumn; +import javax.persistence.SecondaryTable; +import javax.persistence.SecondaryTables; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; + import static org.hibernate.cfg.BinderHelper.toAliasEntityMap; import static org.hibernate.cfg.BinderHelper.toAliasTableMap; @@ -342,7 +341,7 @@ public class EntityBinder { if ( sqlUpdate != null ) { persistentClass.setCustomSQLUpdate( sqlUpdate.sql(), sqlUpdate.callable(), ExecuteUpdateResultCheckStyle.fromExternalName( sqlUpdate.check().toString().toLowerCase(Locale.ROOT) ) - );Locale.ROOT + ); } if ( sqlDelete != null ) { persistentClass.setCustomSQLDelete( sqlDelete.sql(), sqlDelete.callable(), 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 25afd412e8..326e37bc7d 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 @@ -24,6 +24,9 @@ */ package org.hibernate.internal.util; +import org.hibernate.dialect.Dialect; +import org.hibernate.internal.util.collections.ArrayHelper; + import java.io.Serializable; import java.util.ArrayList; import java.util.Arrays; @@ -32,9 +35,6 @@ import java.util.Iterator; import java.util.Locale; import java.util.StringTokenizer; -import org.hibernate.dialect.Dialect; -import org.hibernate.internal.util.collections.ArrayHelper; - public final class StringHelper { private static final int ALIAS_TRUNCATE_LENGTH = 10; @@ -556,8 +556,6 @@ public final class StringHelper { */ private static String generateAliasRoot(String description) { String result = truncate( unqualifyEntityName(description), ALIAS_TRUNCATE_LENGTH ) - // Important to use Locale.ENGLISH. See HHH-8579. #toLowerCase() uses the default Locale. Certain DBs - // do not like non-ascii characters in aliases, etc., so ensure consistency/portability here. .toLowerCase(Locale.ROOT) .replace( '/', '_' ) // entityNames may now include slashes for the representations .replace( '$', '_' ); //classname may be an inner class @@ -600,16 +598,6 @@ public final class StringHelper { } return result; } - - public static String toUpperCase(String str) { - return str==null ? null : str.toUpperCase(Locale.ROOT); - } - - public static String toLowerCase(String str) { - // Important to use Locale.ENGLISH. See HHH-8579. #toLowerCase() uses the default Locale. Certain DBs do not - // like non-ascii characters in aliases, etc., so ensure consistency/portability here. - return str == null ? null : str.toLowerCase(Locale.ROOT); - } public static String moveAndToBeginning(String filter) { if ( filter.trim().length()>0 ){ diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java index abf513efb7..78b2b565cf 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/ForeignKeyMetadata.java @@ -22,16 +22,16 @@ * Boston, MA 02110-1301 USA */ package org.hibernate.tool.hbm2ddl; +import org.hibernate.mapping.Column; +import org.hibernate.mapping.ForeignKey; + import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.mapping.Column; -import org.hibernate.mapping.ForeignKey; - /** * JDBC foreign key metadata * @@ -56,11 +56,11 @@ public class ForeignKeyMetadata { } void addReference(ResultSet rs) throws SQLException { - references.put( StringHelper.toLowerCase(rs.getString("FKCOLUMN_NAME")), rs.getString("PKCOLUMN_NAME") ); + references.put( rs.getString("FKCOLUMN_NAME").toLowerCase(Locale.ROOT), rs.getString("PKCOLUMN_NAME") ); } private boolean hasReference(Column column, Column ref) { - String refName = (String) references.get(StringHelper.toLowerCase(column.getName())); + String refName = (String) references.get(column.getName().toLowerCase(Locale.ROOT)); return ref.getName().equalsIgnoreCase(refName); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java index be7cd4b3c9..6b8e37efb9 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java @@ -23,19 +23,18 @@ */ package org.hibernate.tool.hbm2ddl; +import org.hibernate.internal.CoreMessageLogger; +import org.hibernate.mapping.ForeignKey; +import org.jboss.logging.Logger; + import java.sql.DatabaseMetaData; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.Iterator; +import java.util.Locale; import java.util.Map; -import org.hibernate.internal.CoreMessageLogger; -import org.hibernate.internal.util.StringHelper; -import org.hibernate.mapping.ForeignKey; - -import org.jboss.logging.Logger; - /** * JDBC table metadata * @@ -90,11 +89,11 @@ public class TableMetadata { } public ColumnMetadata getColumnMetadata(String columnName) { - return (ColumnMetadata) columns.get( StringHelper.toLowerCase(columnName) ); + return (ColumnMetadata) columns.get( columnName.toLowerCase(Locale.ROOT) ); } public ForeignKeyMetadata getForeignKeyMetadata(String keyName) { - return (ForeignKeyMetadata) foreignKeys.get( StringHelper.toLowerCase(keyName) ); + return (ForeignKeyMetadata) foreignKeys.get( keyName.toLowerCase(Locale.ROOT) ); } public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) { @@ -109,7 +108,7 @@ public class TableMetadata { } public IndexMetadata getIndexMetadata(String indexName) { - return (IndexMetadata) indexes.get( StringHelper.toLowerCase(indexName) ); + return (IndexMetadata) indexes.get( indexName.toLowerCase(Locale.ROOT) ); } private void addForeignKey(ResultSet rs) throws SQLException { @@ -122,7 +121,7 @@ public class TableMetadata { ForeignKeyMetadata info = getForeignKeyMetadata(fk); if (info == null) { info = new ForeignKeyMetadata(rs); - foreignKeys.put( StringHelper.toLowerCase(info.getName()), info ); + foreignKeys.put( info.getName().toLowerCase(Locale.ROOT), info ); } info.addReference( rs ); @@ -138,7 +137,7 @@ public class TableMetadata { IndexMetadata info = getIndexMetadata(index); if (info == null) { info = new IndexMetadata(rs); - indexes.put( StringHelper.toLowerCase(info.getName()), info ); + indexes.put( info.getName().toLowerCase(Locale.ROOT), info ); } info.addColumn( getColumnMetadata( rs.getString("COLUMN_NAME") ) ); @@ -153,7 +152,7 @@ public class TableMetadata { if ( getColumnMetadata(column) == null ) { ColumnMetadata info = new ColumnMetadata(rs); - columns.put( StringHelper.toLowerCase(info.getName()), info ); + columns.put( info.getName().toLowerCase(Locale.ROOT), info ); } } diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java index 99b09ed020..97ea076e4d 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/internal/tools/StringTools.java @@ -24,6 +24,7 @@ package org.hibernate.envers.internal.tools; import java.util.Iterator; +import java.util.Locale; /** * @author Adam Warski (adam at warski dot org) @@ -80,6 +81,6 @@ public abstract class StringTools { * @return capitalized string */ public static String capitalizeFirst(String fieldName) { - return fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1); + return fieldName.substring(0, 1).toUpperCase(Locale.ROOT) + fieldName.substring(1); } }