HHH-8765 corrected hbm2ddl for turkish locale
Conflicts: hibernate-core/src/main/java/org/hibernate/tool/hbm2ddl/TableMetadata.java
This commit is contained in:
parent
4207017198
commit
a317dfd526
|
@ -603,7 +603,7 @@ public final class StringHelper {
|
||||||
public static String toLowerCase(String str) {
|
public static String toLowerCase(String str) {
|
||||||
// Important to use Locale.ENGLISH. See HHH-8579. #toLowerCase() uses the default Locale. Certain DBs do not
|
// 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.
|
// like non-ascii characters in aliases, etc., so ensure consistency/portability here.
|
||||||
return str==null ? null : str.toLowerCase(Locale.ENGLISH);
|
return str == null ? null : str.toLowerCase(Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String moveAndToBeginning(String filter) {
|
public static String moveAndToBeginning(String filter) {
|
||||||
|
|
|
@ -175,7 +175,7 @@ public class DatabaseMetadata {
|
||||||
rs = statement.executeQuery(sql);
|
rs = statement.executeQuery(sql);
|
||||||
|
|
||||||
while ( rs.next() ) {
|
while ( rs.next() ) {
|
||||||
sequences.add( rs.getString(1).toLowerCase().trim() );
|
sequences.add( StringHelper.toLowerCase(rs.getString(1)).trim() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
|
@ -190,7 +190,7 @@ public class DatabaseMetadata {
|
||||||
public boolean isSequence(Object key) {
|
public boolean isSequence(Object key) {
|
||||||
if (key instanceof String){
|
if (key instanceof String){
|
||||||
String[] strings = StringHelper.split(".", (String) key);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.ForeignKey;
|
import org.hibernate.mapping.ForeignKey;
|
||||||
|
|
||||||
|
@ -55,11 +56,11 @@ public class ForeignKeyMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
void addReference(ResultSet rs) throws SQLException {
|
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) {
|
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);
|
return ref.getName().equalsIgnoreCase(refName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,7 @@ import java.util.Map;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import org.hibernate.internal.CoreMessageLogger;
|
import org.hibernate.internal.CoreMessageLogger;
|
||||||
|
import org.hibernate.internal.util.StringHelper;
|
||||||
import org.hibernate.mapping.ForeignKey;
|
import org.hibernate.mapping.ForeignKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,11 +89,11 @@ public class TableMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnMetadata getColumnMetadata(String columnName) {
|
public ColumnMetadata getColumnMetadata(String columnName) {
|
||||||
return (ColumnMetadata) columns.get( columnName.toLowerCase() );
|
return (ColumnMetadata) columns.get( StringHelper.toLowerCase(columnName) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForeignKeyMetadata getForeignKeyMetadata(String keyName) {
|
public ForeignKeyMetadata getForeignKeyMetadata(String keyName) {
|
||||||
return (ForeignKeyMetadata) foreignKeys.get( keyName.toLowerCase() );
|
return (ForeignKeyMetadata) foreignKeys.get( StringHelper.toLowerCase(keyName) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
|
public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
|
||||||
|
@ -107,7 +108,7 @@ public class TableMetadata {
|
||||||
}
|
}
|
||||||
|
|
||||||
public IndexMetadata getIndexMetadata(String indexName) {
|
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 {
|
private void addForeignKey(ResultSet rs) throws SQLException {
|
||||||
|
@ -120,7 +121,7 @@ public class TableMetadata {
|
||||||
ForeignKeyMetadata info = getForeignKeyMetadata(fk);
|
ForeignKeyMetadata info = getForeignKeyMetadata(fk);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
info = new ForeignKeyMetadata(rs);
|
info = new ForeignKeyMetadata(rs);
|
||||||
foreignKeys.put( info.getName().toLowerCase(), info );
|
foreignKeys.put( StringHelper.toLowerCase(info.getName()), info );
|
||||||
}
|
}
|
||||||
|
|
||||||
info.addReference( rs );
|
info.addReference( rs );
|
||||||
|
@ -136,7 +137,7 @@ public class TableMetadata {
|
||||||
IndexMetadata info = getIndexMetadata(index);
|
IndexMetadata info = getIndexMetadata(index);
|
||||||
if (info == null) {
|
if (info == null) {
|
||||||
info = new IndexMetadata(rs);
|
info = new IndexMetadata(rs);
|
||||||
indexes.put( info.getName().toLowerCase(), info );
|
indexes.put( StringHelper.toLowerCase(info.getName()), info );
|
||||||
}
|
}
|
||||||
|
|
||||||
info.addColumn( getColumnMetadata( rs.getString("COLUMN_NAME") ) );
|
info.addColumn( getColumnMetadata( rs.getString("COLUMN_NAME") ) );
|
||||||
|
@ -151,7 +152,7 @@ public class TableMetadata {
|
||||||
|
|
||||||
if ( getColumnMetadata(column) == null ) {
|
if ( getColumnMetadata(column) == null ) {
|
||||||
ColumnMetadata info = new ColumnMetadata(rs);
|
ColumnMetadata info = new ColumnMetadata(rs);
|
||||||
columns.put( info.getName().toLowerCase(), info );
|
columns.put( StringHelper.toLowerCase(info.getName()), info );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,15 +21,18 @@
|
||||||
package org.hibernate.test.locale;
|
package org.hibernate.test.locale;
|
||||||
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory;
|
import org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory;
|
||||||
import org.hibernate.hql.spi.QueryTranslator;
|
import org.hibernate.hql.spi.QueryTranslator;
|
||||||
import org.hibernate.hql.spi.QueryTranslatorFactory;
|
import org.hibernate.hql.spi.QueryTranslatorFactory;
|
||||||
import org.hibernate.testing.TestForIssue;
|
import org.hibernate.testing.TestForIssue;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
import org.hibernate.tool.hbm2ddl.SchemaValidator;
|
||||||
import org.junit.AfterClass;
|
import org.junit.AfterClass;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -37,14 +40,14 @@ import org.junit.Test;
|
||||||
/**
|
/**
|
||||||
* @author Brett Meyer
|
* @author Brett Meyer
|
||||||
*/
|
*/
|
||||||
@TestForIssue(jiraKey = "HHH-8579")
|
public class LocaleTest extends BaseCoreFunctionalTestCase {
|
||||||
public class LocaleQueryAliasTest extends BaseCoreFunctionalTestCase {
|
|
||||||
|
|
||||||
private static final String asciiRegex = "^\\p{ASCII}*$";
|
private static final String asciiRegex = "^\\p{ASCII}*$";
|
||||||
|
|
||||||
private static Locale currentLocale;
|
private static Locale currentLocale;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@TestForIssue(jiraKey = "HHH-8579")
|
||||||
public void testAliasWithLocale() {
|
public void testAliasWithLocale() {
|
||||||
// Without the HHH-8579 fix, this will generate non-ascii query aliases.
|
// Without the HHH-8579 fix, this will generate non-ascii query aliases.
|
||||||
String hql = "from IAmAFoo";
|
String hql = "from IAmAFoo";
|
||||||
|
@ -58,6 +61,21 @@ public class LocaleQueryAliasTest extends BaseCoreFunctionalTestCase {
|
||||||
assertTrue( sql.matches( asciiRegex ) );
|
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
|
@BeforeClass
|
||||||
public static void beforeClass() {
|
public static void beforeClass() {
|
||||||
currentLocale = Locale.getDefault();
|
currentLocale = Locale.getDefault();
|
Loading…
Reference in New Issue