HHH-9722 cleanup, removed StringHelper methods

Conflicts:
	hibernate-core/src/main/java/org/hibernate/cfg/annotations/EntityBinder.java
	hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java
This commit is contained in:
Brett Meyer 2015-04-17 14:35:09 -04:00
parent 8db83f5221
commit d2a57d036b
6 changed files with 86 additions and 99 deletions

View File

@ -23,21 +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.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;
@ -83,9 +68,9 @@ import org.hibernate.cfg.ObjectNameNormalizer;
import org.hibernate.cfg.ObjectNameSource;
import org.hibernate.cfg.PropertyHolder;
import org.hibernate.cfg.UniqueConstraintHolder;
import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.cfg.naming.NamingStrategyDelegate;
import org.hibernate.cfg.naming.NamingStrategyDelegator;
import org.hibernate.engine.OptimisticLockStyle;
import org.hibernate.engine.spi.ExecuteUpdateResultCheckStyle;
import org.hibernate.engine.spi.FilterDefinition;
import org.hibernate.internal.CoreMessageLogger;
@ -99,9 +84,23 @@ import org.hibernate.mapping.SimpleValue;
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.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;
@ -337,7 +336,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(),
@ -386,7 +385,7 @@ public class EntityBinder {
String filterName = filter.name();
String cond = filter.condition();
if ( BinderHelper.isEmptyAnnotationValue( cond ) ) {
FilterDefinition definition = mappings.getFilterDefinition( filterName );
FilterDefinition definition = mappings.getFilterDefinition(filterName);
cond = definition == null ? null : definition.getDefaultFilterCondition();
if ( StringHelper.isEmpty( cond ) ) {
throw new AnnotationException(
@ -399,10 +398,10 @@ public class EntityBinder {
}
LOG.debugf( "Import with entity name %s", name );
try {
mappings.addImport( persistentClass.getEntityName(), name );
mappings.addImport(persistentClass.getEntityName(), name);
String entityName = persistentClass.getEntityName();
if ( !entityName.equals( name ) ) {
mappings.addImport( entityName, entityName );
mappings.addImport(entityName, entityName);
}
}
catch (MappingException me) {
@ -426,7 +425,7 @@ public class EntityBinder {
if ( annotation == null ) {
return;
}
mappings.addNamedEntityGraphDefintion( new NamedEntityGraphDefinition( annotation, name, persistentClass.getEntityName() ) );
mappings.addNamedEntityGraphDefintion(new NamedEntityGraphDefinition(annotation, name, persistentClass.getEntityName()));
}
public void bindDiscriminatorValue() {
@ -497,12 +496,12 @@ public class EntityBinder {
}
else {
if ( AnnotationBinder.isDefault(
mappings.getReflectionManager().toXClass( proxy.proxyClass() ), mappings
mappings.getReflectionManager().toXClass(proxy.proxyClass()), mappings
) ) {
proxyClass = annotatedClass;
}
else {
proxyClass = mappings.getReflectionManager().toXClass( proxy.proxyClass() );
proxyClass = mappings.getReflectionManager().toXClass(proxy.proxyClass());
}
}
}
@ -559,20 +558,20 @@ public class EntityBinder {
@Override
public String handleExplicitName(NamingStrategy strategy, String name) {
return strategy.tableName( name );
return strategy.tableName(name);
}
@Override
public String determineImplicitName(NamingStrategyDelegator strategyDelegator) {
return getNamingStrategyDelegate( strategyDelegator ).determineImplicitPrimaryTableName(
entityName,
jpaEntityName
);
return getNamingStrategyDelegate(strategyDelegator).determineImplicitPrimaryTableName(
entityName,
jpaEntityName
);
}
@Override
public String handleExplicitName(NamingStrategyDelegator strategyDelegator, String name) {
return getNamingStrategyDelegate( strategyDelegator ).toPhysicalTableName( name );
return getNamingStrategyDelegate(strategyDelegator).toPhysicalTableName( name );
}
}
@ -593,17 +592,17 @@ public class EntityBinder {
name
);
final Table table = TableBinder.buildAndFillTable(
schema,
catalog,
tableNameContext,
namingStrategyHelper,
persistentClass.isAbstract(),
uniqueConstraints,
constraints,
denormalizedSuperclassTable,
mappings,
this.subselect
);
schema,
catalog,
tableNameContext,
namingStrategyHelper,
persistentClass.isAbstract(),
uniqueConstraints,
constraints,
denormalizedSuperclassTable,
mappings,
this.subselect
);
final RowId rowId = annotatedClass.getAnnotation( RowId.class );
if ( rowId != null ) {
table.setRowId( rowId.value() );
@ -631,7 +630,7 @@ public class EntityBinder {
Join join = (Join) joins.next();
createPrimaryColumnsToSecondaryTable( uncastedColumn, propertyHolder, join );
}
mappings.addJoins( persistentClass, secondaryTables );
mappings.addJoins(persistentClass, secondaryTables);
}
private void createPrimaryColumnsToSecondaryTable(Object uncastedColumn, PropertyHolder propertyHolder, Join join) {
@ -698,7 +697,7 @@ public class EntityBinder {
for (Ejb3JoinColumn joinColumn : ejb3JoinColumns) {
joinColumn.forceNotNull();
}
bindJoinToPersistentClass( join, ejb3JoinColumns, mappings );
bindJoinToPersistentClass(join, ejb3JoinColumns, mappings);
}
private void bindJoinToPersistentClass(Join join, Ejb3JoinColumn[] ejb3JoinColumns, Mappings mappings) {
@ -713,7 +712,7 @@ public class EntityBinder {
}
private void setFKNameIfDefined(Join join) {
org.hibernate.annotations.Table matchingTable = findMatchingComplimentTableAnnotation( join );
org.hibernate.annotations.Table matchingTable = findMatchingComplimentTableAnnotation(join);
if ( matchingTable != null && !BinderHelper.isEmptyAnnotationValue( matchingTable.foreignKey().name() ) ) {
( (SimpleValue) join.getKey() ).setForeignKeyName( matchingTable.foreignKey().name() );
}
@ -794,7 +793,7 @@ public class EntityBinder {
@Override
public String handleExplicitName(NamingStrategyDelegator strategyDelegator, String name) {
return getNamingStrategyDelegate( strategyDelegator ).toPhysicalTableName( name );
return getNamingStrategyDelegate(strategyDelegator).toPhysicalTableName( name );
}
}

View File

@ -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;
@ -547,8 +547,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
@ -591,16 +589,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 ){

View File

@ -24,16 +24,6 @@
*/
package org.hibernate.tool.hbm2ddl;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.hibernate.HibernateException;
import org.hibernate.cfg.AvailableSettings;
import org.hibernate.cfg.Configuration;
@ -44,9 +34,19 @@ import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.config.ConfigurationHelper;
import org.hibernate.mapping.Table;
import org.jboss.logging.Logger;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
/**
* JDBC database metadata
* @author Christoph Sturm, Teodor Danciu
@ -116,18 +116,18 @@ public class DatabaseMetadata {
} else if ( (isQuoted && meta.storesUpperCaseQuotedIdentifiers())
|| (!isQuoted && meta.storesUpperCaseIdentifiers() )) {
rs = meta.getTables(
StringHelper.toUpperCase(catalog),
StringHelper.toUpperCase(schema),
StringHelper.toUpperCase(name),
catalog != null ? catalog.toUpperCase(Locale.ROOT) : null,
schema != null ? schema.toUpperCase(Locale.ROOT) : null,
name.toUpperCase(Locale.ROOT),
types
);
}
else if ( (isQuoted && meta.storesLowerCaseQuotedIdentifiers())
|| (!isQuoted && meta.storesLowerCaseIdentifiers() )) {
rs = meta.getTables(
StringHelper.toLowerCase( catalog ),
StringHelper.toLowerCase(schema),
StringHelper.toLowerCase(name),
rs = meta.getTables(
catalog != null ? catalog.toLowerCase(Locale.ROOT) : null,
schema != null ? schema.toLowerCase(Locale.ROOT) : null,
name.toLowerCase(Locale.ROOT),
types
);
}
@ -178,7 +178,7 @@ public class DatabaseMetadata {
rs = statement.executeQuery(sql);
while ( rs.next() ) {
sequences.add( StringHelper.toLowerCase(rs.getString(1)).trim() );
sequences.add(rs.getString(1).toLowerCase(Locale.ROOT).trim());
}
}
finally {
@ -196,7 +196,7 @@ public class DatabaseMetadata {
public boolean isSequence(Object key) {
if (key instanceof String){
String[] strings = StringHelper.split(".", (String) key);
return sequences.contains( StringHelper.toLowerCase(strings[strings.length-1]));
return sequences.contains( strings[strings.length-1].toLowerCase(Locale.ROOT));
}
return false;
}

View File

@ -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);
}

View File

@ -23,18 +23,17 @@
*/
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
*
@ -89,11 +88,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) {
@ -108,7 +107,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 {
@ -121,7 +120,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 );
@ -137,7 +136,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") ) );
@ -152,7 +151,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 );
}
}

View File

@ -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);
}
}