HHH-8765 corrected hbm2ddl for turkish locale

Conflicts:
	hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java
This commit is contained in:
Brett Meyer 2013-12-10 21:17:37 -05:00
parent 4207017198
commit a317dfd526
5 changed files with 33 additions and 13 deletions

View File

@ -175,7 +175,7 @@ public class DatabaseMetadata {
rs = statement.executeQuery(sql);
while ( rs.next() ) {
sequences.add( rs.getString(1).toLowerCase().trim() );
sequences.add( StringHelper.toLowerCase(rs.getString(1)).trim() );
}
}
finally {
@ -190,7 +190,7 @@ public class DatabaseMetadata {
public boolean isSequence(Object key) {
if (key instanceof String){
String[] strings = StringHelper.split(".", (String) key);
return sequences.contains( strings[strings.length-1].toLowerCase());
return sequences.contains( StringHelper.toLowerCase(strings[strings.length-1]));
}
return false;
}

View File

@ -28,6 +28,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.ForeignKey;
@ -55,11 +56,11 @@ public class ForeignKeyMetadata {
}
void addReference(ResultSet rs) throws SQLException {
references.put( rs.getString("FKCOLUMN_NAME").toLowerCase(), rs.getString("PKCOLUMN_NAME") );
references.put( StringHelper.toLowerCase(rs.getString("FKCOLUMN_NAME")), rs.getString("PKCOLUMN_NAME") );
}
private boolean hasReference(Column column, Column ref) {
String refName = (String) references.get(column.getName().toLowerCase());
String refName = (String) references.get(StringHelper.toLowerCase(column.getName()));
return ref.getName().equalsIgnoreCase(refName);
}

View File

@ -32,6 +32,7 @@ import java.util.Map;
import org.jboss.logging.Logger;
import org.hibernate.internal.CoreMessageLogger;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.mapping.ForeignKey;
/**
@ -88,11 +89,11 @@ public class TableMetadata {
}
public ColumnMetadata getColumnMetadata(String columnName) {
return (ColumnMetadata) columns.get( columnName.toLowerCase() );
return (ColumnMetadata) columns.get( StringHelper.toLowerCase(columnName) );
}
public ForeignKeyMetadata getForeignKeyMetadata(String keyName) {
return (ForeignKeyMetadata) foreignKeys.get( keyName.toLowerCase() );
return (ForeignKeyMetadata) foreignKeys.get( StringHelper.toLowerCase(keyName) );
}
public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
@ -107,7 +108,7 @@ public class TableMetadata {
}
public IndexMetadata getIndexMetadata(String indexName) {
return (IndexMetadata) indexes.get( indexName.toLowerCase() );
return (IndexMetadata) indexes.get( StringHelper.toLowerCase(indexName) );
}
private void addForeignKey(ResultSet rs) throws SQLException {
@ -120,7 +121,7 @@ public class TableMetadata {
ForeignKeyMetadata info = getForeignKeyMetadata(fk);
if (info == null) {
info = new ForeignKeyMetadata(rs);
foreignKeys.put( info.getName().toLowerCase(), info );
foreignKeys.put( StringHelper.toLowerCase(info.getName()), info );
}
info.addReference( rs );
@ -136,7 +137,7 @@ public class TableMetadata {
IndexMetadata info = getIndexMetadata(index);
if (info == null) {
info = new IndexMetadata(rs);
indexes.put( info.getName().toLowerCase(), info );
indexes.put( StringHelper.toLowerCase(info.getName()), info );
}
info.addColumn( getColumnMetadata( rs.getString("COLUMN_NAME") ) );
@ -151,7 +152,7 @@ public class TableMetadata {
if ( getColumnMetadata(column) == null ) {
ColumnMetadata info = new ColumnMetadata(rs);
columns.put( info.getName().toLowerCase(), info );
columns.put( StringHelper.toLowerCase(info.getName()), info );
}
}

View File

@ -21,15 +21,18 @@
package org.hibernate.test.locale;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Collections;
import java.util.Locale;
import org.hibernate.HibernateException;
import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory;
import org.hibernate.hql.spi.QueryTranslator;
import org.hibernate.hql.spi.QueryTranslatorFactory;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.tool.hbm2ddl.SchemaValidator;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
@ -37,14 +40,14 @@ import org.junit.Test;
/**
* @author Brett Meyer
*/
@TestForIssue(jiraKey = "HHH-8579")
public class LocaleQueryAliasTest extends BaseCoreFunctionalTestCase {
public class LocaleTest extends BaseCoreFunctionalTestCase {
private static final String asciiRegex = "^\\p{ASCII}*$";
private static Locale currentLocale;
@Test
@TestForIssue(jiraKey = "HHH-8579")
public void testAliasWithLocale() {
// Without the HHH-8579 fix, this will generate non-ascii query aliases.
String hql = "from IAmAFoo";
@ -58,6 +61,21 @@ public class LocaleQueryAliasTest extends BaseCoreFunctionalTestCase {
assertTrue( sql.matches( asciiRegex ) );
}
@Test
@TestForIssue(jiraKey = "HHH-8765")
public void testMetadataWithLocale() {
SchemaValidator sv = new SchemaValidator( configuration() );
try {
// Rather than building TableMetadata and checking for ascii values in table/column names, simply
// attempt to validate.
sv.validate();
}
catch (HibernateException e) {
fail("Failed with the Turkish locale, most likely due to the use of String#toLowerCase() within hbm2ddl. "
+ "Search for all instaces and replace with StringHelper#toLowerCase(String)! " + e.getMessage());
}
}
@BeforeClass
public static void beforeClass() {
currentLocale = Locale.getDefault();