From 1c222d1b1ec9857d00c2c67d7185dd00b6568e03 Mon Sep 17 00:00:00 2001 From: Brett Meyer Date: Fri, 21 Mar 2014 16:12:09 -0400 Subject: [PATCH] HHH-6438 made Constraint#name an Identifier --- .../constraint/DB2UniqueKeyExporter.java | 4 ++-- .../constraint/InformixUniqueKeyExporter.java | 2 +- .../constraint/MySQLIndexExporter.java | 2 +- .../constraint/MySQLUniqueKeyExporter.java | 2 +- .../binder/NaturalIdUniqueKeyHelper.java | 3 ++- .../internal/binder/TableHelper.java | 4 ++-- .../spi/relational/AbstractConstraint.java | 8 +++---- .../AbstractTableSpecification.java | 9 +++++++- .../metamodel/spi/relational/Constraint.java | 2 +- .../spi/relational/DenormalizedTable.java | 10 ++++----- .../metamodel/spi/relational/ForeignKey.java | 4 ++-- .../metamodel/spi/relational/Identifier.java | 21 +++++++++++++++++-- .../metamodel/spi/relational/Index.java | 4 ++-- .../spi/relational/TableSpecification.java | 2 ++ .../metamodel/spi/relational/UniqueKey.java | 2 +- .../internal/StandardForeignKeyExporter.java | 4 ++-- .../internal/StandardIndexExporter.java | 7 +++---- .../internal/StandardUniqueKeyExporter.java | 4 ++-- .../entity/UniqueConstraintBindingTest.java | 2 +- .../spi/binding/SimpleValueBindingTests.java | 2 +- .../relational/TableManipulationTests.java | 8 +++---- .../index/jpa/AbstractJPAIndexTest.java | 10 ++++----- .../test/annotations/index/jpa/IndexTest.java | 2 +- .../test/constraint/ConstraintTest.java | 4 ++-- .../org/hibernate/test/legacy/ABCTest.java | 2 +- .../org/hibernate/test/util/SchemaUtil.java | 12 +++++++---- 26 files changed, 83 insertions(+), 53 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/constraint/DB2UniqueKeyExporter.java b/hibernate-core/src/main/java/org/hibernate/dialect/constraint/DB2UniqueKeyExporter.java index 1a5a94e475..80e58a36ea 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/constraint/DB2UniqueKeyExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/constraint/DB2UniqueKeyExporter.java @@ -50,7 +50,7 @@ public class DB2UniqueKeyExporter extends StandardUniqueKeyExporter { ( (Table) constraint.getTable() ).getTableName() ); StringBuilder sb = new StringBuilder() .append( "create unique index " ) - .append( constraint.getName() ) + .append( constraint.getName().getText( dialect ) ) .append( " on " ) .append( tableName ) .append( " (" ); @@ -73,7 +73,7 @@ public class DB2UniqueKeyExporter extends StandardUniqueKeyExporter { @Override public String[] getSqlDropStrings(Constraint constraint, JdbcEnvironment jdbcEnvironment) { if ( hasNullable( constraint ) ) { - return new String[] { "drop index " + constraint.getName() }; + return new String[] { "drop index " + constraint.getName().getText( dialect ) }; } else { return super.getSqlDropStrings( constraint, jdbcEnvironment ); diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/constraint/InformixUniqueKeyExporter.java b/hibernate-core/src/main/java/org/hibernate/dialect/constraint/InformixUniqueKeyExporter.java index f98f376924..b030bd45a0 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/constraint/InformixUniqueKeyExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/constraint/InformixUniqueKeyExporter.java @@ -67,7 +67,7 @@ public class InformixUniqueKeyExporter extends StandardUniqueKeyExporter { sb.append( ")" ) .append( " constraint " ) - .append( constraint.getName() ); + .append( constraint.getName().getText( dialect ) ); return new String[] { sb.toString() }; } } diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/constraint/MySQLIndexExporter.java b/hibernate-core/src/main/java/org/hibernate/dialect/constraint/MySQLIndexExporter.java index 77e3de6e99..6fc849e027 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/constraint/MySQLIndexExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/constraint/MySQLIndexExporter.java @@ -59,7 +59,7 @@ public class MySQLIndexExporter extends StandardIndexExporter { StringBuilder sb = new StringBuilder(); sb.append( "drop index " ); sb.append( ( dialect.qualifyIndexName() - ? StringHelper.qualify( tableName, index.getName() ) : index.getName() ) ); + ? index.getName().getQualifiedText( tableName, dialect ) : index.getName() ) ); sb.append( " on " + tableName ); return new String[] { sb.toString() }; diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/constraint/MySQLUniqueKeyExporter.java b/hibernate-core/src/main/java/org/hibernate/dialect/constraint/MySQLUniqueKeyExporter.java index f007f5bb7b..b1ba5f4f47 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/constraint/MySQLUniqueKeyExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/constraint/MySQLUniqueKeyExporter.java @@ -57,7 +57,7 @@ public class MySQLUniqueKeyExporter extends StandardUniqueKeyExporter { if ( dialect.supportsIfExistsBeforeConstraintName() ) { sb.append( "if exists " ); } - sb.append( dialect.quote( constraint.getName() ) ); + sb.append( constraint.getName().getText( dialect ) ); if ( dialect.supportsIfExistsAfterConstraintName() ) { sb.append( " if exists" ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/NaturalIdUniqueKeyHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/NaturalIdUniqueKeyHelper.java index 534cb24fea..4eb5acadd5 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/NaturalIdUniqueKeyHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/NaturalIdUniqueKeyHelper.java @@ -24,6 +24,7 @@ import java.util.HashMap; import java.util.Map; import org.hibernate.metamodel.spi.relational.Column; +import org.hibernate.metamodel.spi.relational.Identifier; import org.hibernate.metamodel.spi.relational.TableSpecification; import org.hibernate.metamodel.spi.relational.UniqueKey; @@ -60,7 +61,7 @@ public class NaturalIdUniqueKeyHelper { String keyName = "UK_" + HashedNameUtil.hashedName( table.getLogicalName().getText() + "_NaturalID" ); uniqueKey = new UniqueKey(); uniqueKey.setTable( table ); - uniqueKey.setName( keyName ); + uniqueKey.setName( Identifier.toIdentifier( keyName ) ); table.addUniqueKey( uniqueKey ); naturalIdUniqueKeys.put( table, uniqueKey ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/TableHelper.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/TableHelper.java index a5c1b9b3a4..bbdfb054f2 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/TableHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/binder/TableHelper.java @@ -222,7 +222,7 @@ public class TableHelper { final String normalizedName = normalizeDatabaseIdentifier( name, new UniqueKeyNamingStrategyHelper( table, columns ) ); - uk.setName( normalizedName ); + uk.setName( Identifier.toIdentifier( normalizedName ) ); table.addUniqueKey( uk ); } @@ -239,7 +239,7 @@ public class TableHelper { final String normalizedName = normalizeDatabaseIdentifier( name, new IndexNamingStrategyHelper( table, columns ) ); - idx.setName( normalizedName ); + idx.setName( Identifier.toIdentifier( normalizedName ) ); table.addIndex( idx ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractConstraint.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractConstraint.java index 95de0a28ac..eac97f338e 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractConstraint.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractConstraint.java @@ -44,11 +44,11 @@ import org.hibernate.internal.util.StringHelper; */ public abstract class AbstractConstraint implements Constraint { private TableSpecification table; - private String name; + private Identifier name; private final Map columnMap = new LinkedHashMap(); private final Map columnOrderMap = new HashMap(); - protected AbstractConstraint(TableSpecification table, String name) { + protected AbstractConstraint(TableSpecification table, Identifier name) { this.table = table; this.name = name; } @@ -67,7 +67,7 @@ public abstract class AbstractConstraint implements Constraint { * * @return the constraint name, or null if the name has not been set */ - public String getName() { + public Identifier getName() { return name; } @@ -80,7 +80,7 @@ public abstract class AbstractConstraint implements Constraint { * @throws IllegalArgumentException if name is null. * @throws IllegalStateException if this constraint already has a non-null name. */ - public void setName(String name) { + public void setName(Identifier name) { if ( name == null ) { throw new IllegalArgumentException( "name must be non-null." ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractTableSpecification.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractTableSpecification.java index 55aa68fcb9..85f9154e18 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractTableSpecification.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/AbstractTableSpecification.java @@ -167,6 +167,12 @@ public abstract class AbstractTableSpecification implements TableSpecification { @Override public ForeignKey createForeignKey(TableSpecification targetTable, String name, boolean createConstraint) { + Identifier identifier = Identifier.toIdentifier( name ); + return createForeignKey( targetTable, identifier, createConstraint ); + } + + @Override + public ForeignKey createForeignKey(TableSpecification targetTable, Identifier name, boolean createConstraint) { ForeignKey fk = new ForeignKey( this, targetTable, name, createConstraint ); foreignKeys.add( fk ); return fk; @@ -181,8 +187,9 @@ public abstract class AbstractTableSpecification implements TableSpecification { if ( name == null ) { throw new IllegalArgumentException( "name must be non-null." ); } + Identifier identifier = Identifier.toIdentifier( name ); for ( T constraint : constraints ) { - if ( name.equals( constraint.getName() ) ) { + if ( identifier.equals( constraint.getName() ) ) { return constraint; } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Constraint.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Constraint.java index 8b71dc693e..46a176d043 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Constraint.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Constraint.java @@ -47,7 +47,7 @@ public interface Constraint extends Exportable { * * @return the name. */ - public String getName(); + public Identifier getName(); /** * Obtain a read-only view of the columns that are part of this constraint. diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/DenormalizedTable.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/DenormalizedTable.java index 5c4f5e9668..8f26aa9f03 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/DenormalizedTable.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/DenormalizedTable.java @@ -82,16 +82,16 @@ public class DenormalizedTable extends Table { final String fkNamePostfix = Integer.toHexString( getTableName().hashCode() ); for ( ForeignKey fk : fksInSuperTable ) { - String name = fk.getName(); - if ( name == null ) { + Identifier name = fk.getName(); + if (name == null || name.getText() == null) { if(!alreadyCopiedNonNameParentFK.contains( fk )){ copyFK( fk, name ); alreadyCopiedNonNameParentFK.add( fk ); } } else { - String fkName = name + fkNamePostfix; - ForeignKey copiedFK = super.locateForeignKey( fkName ); + Identifier fkName = name.applyPostfix( fkNamePostfix ); + ForeignKey copiedFK = super.locateForeignKey( fkName.toString() ); if ( copiedFK == null ) { copyFK( fk, fkName ); } @@ -99,7 +99,7 @@ public class DenormalizedTable extends Table { } } - private void copyFK(ForeignKey fk, String fkName) { + private void copyFK(ForeignKey fk, Identifier fkName) { ForeignKey copiedFK = createForeignKey( fk.getTargetTable(), fkName, fk.createConstraint() ); copiedFK.setDeleteRule( fk.getDeleteRule() ); copiedFK.setUpdateRule( fk.getUpdateRule() ); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/ForeignKey.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/ForeignKey.java index 19c38e9f28..0a59820017 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/ForeignKey.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/ForeignKey.java @@ -55,7 +55,7 @@ public class ForeignKey extends AbstractConstraint { private boolean createConstraint; - protected ForeignKey(TableSpecification sourceTable, TableSpecification targetTable, String name, + protected ForeignKey(TableSpecification sourceTable, TableSpecification targetTable, Identifier name, boolean createConstraint) { super( sourceTable, name ); if ( targetTable == null ) { @@ -218,7 +218,7 @@ public class ForeignKey extends AbstractConstraint { @Override public String getExportIdentifier() { - return getSourceTable().getLoggableValueQualifier() + ".FK-" + getName(); + return getSourceTable().getLoggableValueQualifier() + ".FK-" + getName().getText(); } public boolean createConstraint() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Identifier.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Identifier.java index 43a69c3cf5..0dbb052ccd 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Identifier.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Identifier.java @@ -31,9 +31,10 @@ import org.hibernate.internal.util.StringHelper; * Models an identifier (name). * * @author Steve Ebersole + * @author Brett Meyer */ public class Identifier implements Comparable { - private final String text; + private String text; private final boolean isQuoted; /** @@ -71,7 +72,7 @@ public class Identifier implements Comparable { final String trimmed = text.trim(); if ( isQuoted( trimmed ) ) { final String bareName = trimmed.substring( 1, trimmed.length() - 1 ); - return new Identifier( bareName, true ); + return new Identifier( bareName, quote ); } else { return new Identifier( trimmed, quote ); @@ -159,6 +160,22 @@ public class Identifier implements Comparable { String.valueOf( openQuote ) + text + closeQuote : text; } + + public String getQualifiedText(String prefix, Dialect dialect) { + String qualified = prefix + "." + text; + return isQuoted ? dialect.openQuote() + qualified + dialect.closeQuote() : qualified; + } + + public String getUnqualifiedText(Dialect dialect) { + int loc = text.lastIndexOf("."); + String unqualified = ( loc < 0 ) ? text : text.substring( loc + 1 ); + return isQuoted ? dialect.openQuote() + unqualified + dialect.closeQuote() : unqualified; + } + + public Identifier applyPostfix(String postfix) { + String newText = text + postfix; + return Identifier.toIdentifier( newText, isQuoted ); + } @Override public String toString() { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Index.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Index.java index 2435d7ba1d..8928d53d4a 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Index.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Index.java @@ -38,7 +38,7 @@ public class Index extends AbstractConstraint { this( null, null, unique ); } - protected Index(Table table, String name, boolean unique) { + protected Index(Table table, Identifier name, boolean unique) { super( table, name ); this.unique = unique; } @@ -47,7 +47,7 @@ public class Index extends AbstractConstraint { public String getExportIdentifier() { StringBuilder sb = new StringBuilder( getTable().getLoggableValueQualifier() ); sb.append( ".IDX" ); - sb.append( '_' ).append( getName() ); + sb.append( '_' ).append( getName().getText() ); for ( Column column : getColumns() ) { sb.append( '_' ).append( column.getColumnName().getText() ); } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/TableSpecification.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/TableSpecification.java index 69da184144..8651879cc6 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/TableSpecification.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/TableSpecification.java @@ -134,6 +134,8 @@ public interface TableSpecification extends ValueContainer, Loggable { * @return The foreign key reference. */ public ForeignKey createForeignKey(TableSpecification targetTable, String name, boolean createConstraint); + + public ForeignKey createForeignKey(TableSpecification targetTable, Identifier name, boolean createConstraint); public Iterable getIndexes(); diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/UniqueKey.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/UniqueKey.java index d5b13854e4..d3ffc92e3f 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/UniqueKey.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/UniqueKey.java @@ -37,7 +37,7 @@ public class UniqueKey extends AbstractConstraint { this( null, null ); } - protected UniqueKey(Table table, String name) { + protected UniqueKey(Table table, Identifier name) { super( table, name ); } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardForeignKeyExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardForeignKeyExporter.java index 3e048b077b..f04d671098 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardForeignKeyExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardForeignKeyExporter.java @@ -72,7 +72,7 @@ public class StandardForeignKeyExporter implements Exporter { .append( sourceTableName ) .append( dialect.getAddForeignKeyConstraintString( - foreignKey.getName(), + foreignKey.getName().getText( dialect ), columnNames, targetTableName, targetColumnNames, @@ -108,7 +108,7 @@ public class StandardForeignKeyExporter implements Exporter { ( (Table) foreignKey.getSourceTable() ).getTableName() ); return new String[] { - "alter table " + sourceTableName + dialect.getDropForeignKeyString() + foreignKey.getName() + "alter table " + sourceTableName + dialect.getDropForeignKeyString() + foreignKey.getName().getText( dialect ) }; } } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardIndexExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardIndexExporter.java index 6de812c1a4..f41110a708 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardIndexExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardIndexExporter.java @@ -25,7 +25,6 @@ package org.hibernate.tool.schema.internal; import org.hibernate.dialect.Dialect; import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment; -import org.hibernate.internal.util.StringHelper; import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.Index; import org.hibernate.metamodel.spi.relational.Table; @@ -48,7 +47,8 @@ public class StandardIndexExporter implements Exporter { ); StringBuilder buf = new StringBuilder() .append( "create index " ) - .append( dialect.qualifyIndexName() ? index.getName() : StringHelper.unqualify( index.getName() ) ) + .append( dialect.qualifyIndexName() + ? index.getName().getText( dialect ) : index.getName().getUnqualifiedText( dialect ) ) .append( " on " ) .append( tableName ) .append( " (" ); @@ -77,8 +77,7 @@ public class StandardIndexExporter implements Exporter { ( (Table) index.getTable() ).getTableName() ); return new String[] { - "drop index " + ( dialect.qualifyIndexName() - ? StringHelper.qualify( tableName, index.getName() ) : index.getName() ) + "drop index " + index.getName().getQualifiedText( tableName, dialect ) }; } } diff --git a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUniqueKeyExporter.java b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUniqueKeyExporter.java index 6fd6793c9c..33f66bafa4 100644 --- a/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUniqueKeyExporter.java +++ b/hibernate-core/src/main/java/org/hibernate/tool/schema/internal/StandardUniqueKeyExporter.java @@ -58,7 +58,7 @@ public class StandardUniqueKeyExporter implements Exporter { .append( "alter table " ) .append( tableName ) .append( " add constraint " ) - .append( constraint.getName() ) + .append( constraint.getName().getText( dialect ) ) .append( " unique ( " ); final Iterator columnIterator = constraint.getColumns().iterator(); @@ -88,7 +88,7 @@ public class StandardUniqueKeyExporter implements Exporter { if ( dialect.supportsIfExistsBeforeConstraintName() ) { sb.append( "if exists " ); } - sb.append( dialect.quote( constraint.getName() ) ); + sb.append( constraint.getName().getText( dialect ) ); if ( dialect.supportsIfExistsAfterConstraintName() ) { sb.append( " if exists" ); } diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/UniqueConstraintBindingTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/UniqueConstraintBindingTest.java index b3091183fb..de9e7faab7 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/UniqueConstraintBindingTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/UniqueConstraintBindingTest.java @@ -80,7 +80,7 @@ public class UniqueConstraintBindingTest extends BaseAnnotationBindingTestCase { int i = 0; for ( UniqueKey key : uniqueKeyIterable ) { i++; - assertEquals( ukName, key.getName() ); + assertEquals( ukName, key.getName().getText() ); assertTrue( table == key.getTable() ); assertNotNull( key.getColumns() ); assertEquals( "There should be " + ukNumColumns + " columns in the unique constraint", ukNumColumns, key.getColumns().size() ); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java index 92e8caf2fe..3be5a27c6a 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/SimpleValueBindingTests.java @@ -70,7 +70,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase { idColumn.setJdbcDataType( BIGINT ); idColumn.setSize( Size.precision( 18, 0 ) ); table.getPrimaryKey().addColumn( idColumn ); - table.getPrimaryKey().setName( "my_table_pk" ); + table.getPrimaryKey().setName( Identifier.toIdentifier( "my_table_pk" ) ); Entity entity = new Entity( makeJavaType( "NoSuchClass" ), null ); HierarchyDetails hierarchyDetails = new HierarchyDetails.Builder().createHierarchyDetails(); diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/relational/TableManipulationTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/relational/TableManipulationTests.java index 678f0f674e..87594d6361 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/relational/TableManipulationTests.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/relational/TableManipulationTests.java @@ -59,8 +59,8 @@ public class TableManipulationTests extends BaseUnitTestCase { idColumn.setJdbcDataType( INTEGER ); idColumn.setSize( Size.precision( 18, 0 ) ); table.getPrimaryKey().addColumn( idColumn ); - table.getPrimaryKey().setName( "my_table_pk" ); - assertEquals( "my_table_pk", table.getPrimaryKey().getName() ); + table.getPrimaryKey().setName( Identifier.toIdentifier( "my_table_pk" ) ); + assertEquals( "my_table_pk", table.getPrimaryKey().getName().toString() ); assertEquals( "my_table.PK", table.getPrimaryKey().getExportIdentifier() ); Column col_1 = table.locateOrCreateColumn( "col_1" ); @@ -97,7 +97,7 @@ public class TableManipulationTests extends BaseUnitTestCase { bookId.setJdbcDataType( INTEGER ); bookId.setSize( Size.precision( 18, 0 ) ); book.getPrimaryKey().addColumn( bookId ); - book.getPrimaryKey().setName( "BOOK_PK" ); + book.getPrimaryKey().setName( Identifier.toIdentifier( "BOOK_PK" ) ); Table page = schema.createTable( Identifier.toIdentifier( "PAGE" ), Identifier.toIdentifier( "PAGE" ) ); @@ -105,7 +105,7 @@ public class TableManipulationTests extends BaseUnitTestCase { pageId.setJdbcDataType( INTEGER ); pageId.setSize( Size.precision( 18, 0 ) ); page.getPrimaryKey().addColumn( pageId ); - page.getPrimaryKey().setName( "PAGE_PK" ); + page.getPrimaryKey().setName( Identifier.toIdentifier( "PAGE_PK" ) ); Column pageBookId = page.locateOrCreateColumn( "BOOK_ID" ); pageId.setJdbcDataType( INTEGER ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/AbstractJPAIndexTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/AbstractJPAIndexTest.java index 47d6af0315..5a33a8d13d 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/AbstractJPAIndexTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/AbstractJPAIndexTest.java @@ -52,7 +52,7 @@ public abstract class AbstractJPAIndexTest extends BaseCoreFunctionalTestCase { org.hibernate.metamodel.spi.relational.Index index = indexes.next(); if (index.isUnique()) { found++; - assertTrue( StringHelper.isNotEmpty( index.getName() ) ); + assertTrue( StringHelper.isNotEmpty( index.getName().toString() ) ); assertEquals( 2, index.getColumnSpan() ); Column column = index.getColumns().get( 0 ); assertEquals( "brand", column.getColumnName().getText() ); @@ -61,7 +61,7 @@ public abstract class AbstractJPAIndexTest extends BaseCoreFunctionalTestCase { } else { found++; - assertEquals( "Car_idx", index.getName() ); + assertEquals( "Car_idx", index.getName().toString() ); assertEquals( 1, index.getColumnSpan() ); Column column = index.getColumns().get( 0 ); assertEquals( "since", column.getColumnName().getText() ); @@ -80,7 +80,7 @@ public abstract class AbstractJPAIndexTest extends BaseCoreFunctionalTestCase { assertTrue( indexes.hasNext() ); org.hibernate.metamodel.spi.relational.Index index = indexes.next(); assertFalse( indexes.hasNext() ); - assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) ); + assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName().toString() ) ); assertEquals( 2, index.getColumnSpan() ); org.hibernate.metamodel.spi.relational.Column column = index.getColumns().get( 0 ); assertEquals( "dealer_name", column.getColumnName().getText() ); @@ -97,7 +97,7 @@ public abstract class AbstractJPAIndexTest extends BaseCoreFunctionalTestCase { assertTrue( indexes.hasNext() ); org.hibernate.metamodel.spi.relational.Index index = indexes.next(); assertFalse( indexes.hasNext() ); - assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) ); + assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName().toString() ) ); assertEquals( 1, index.getColumnSpan() ); org.hibernate.metamodel.spi.relational.Column column = index.getColumns().get( 0 ); assertEquals( "name", column.getColumnName().getText() ); @@ -112,7 +112,7 @@ public abstract class AbstractJPAIndexTest extends BaseCoreFunctionalTestCase { assertTrue( indexes.hasNext() ); org.hibernate.metamodel.spi.relational.Index index = indexes.next(); assertFalse( indexes.hasNext() ); - assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) ); + assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName().toString() ) ); assertEquals( 1, index.getColumnSpan() ); org.hibernate.metamodel.spi.relational.Column column = index.getColumns().get( 0 ); assertEquals( "importers_id", column.getColumnName().getText() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/IndexTest.java b/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/IndexTest.java index 88d5f07382..045e025507 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/IndexTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/annotations/index/jpa/IndexTest.java @@ -57,7 +57,7 @@ public class IndexTest extends AbstractJPAIndexTest { assertTrue( indexes.hasNext() ); org.hibernate.metamodel.spi.relational.Index index = indexes.next(); assertFalse( indexes.hasNext() ); - assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) ); + assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName().toString() ) ); assertEquals( 1, index.getColumnSpan() ); org.hibernate.metamodel.spi.relational.Column column = index.getColumns().get( 0 ); assertEquals( "GEN_VALUE", column.getColumnName().getText() ); diff --git a/hibernate-core/src/test/java/org/hibernate/test/constraint/ConstraintTest.java b/hibernate-core/src/test/java/org/hibernate/test/constraint/ConstraintTest.java index 451aacdfda..e750a8f993 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/constraint/ConstraintTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/constraint/ConstraintTest.java @@ -132,10 +132,10 @@ public class ConstraintTest extends BaseCoreFunctionalTestCase { private void testConstraintLength(TableSpecification table) { for (UniqueKey uk : table.getUniqueKeys()) { - assertTrue(uk.getName().length() <= MAX_NAME_LENGTH); + assertTrue(uk.getName().toString().length() <= MAX_NAME_LENGTH); } for (ForeignKey fk : table.getForeignKeys()) { - assertTrue(fk.getName().length() <= MAX_NAME_LENGTH); + assertTrue(fk.getName().toString().length() <= MAX_NAME_LENGTH); } } diff --git a/hibernate-core/src/test/java/org/hibernate/test/legacy/ABCTest.java b/hibernate-core/src/test/java/org/hibernate/test/legacy/ABCTest.java index d3efcf063e..3d291ea94f 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/legacy/ABCTest.java +++ b/hibernate-core/src/test/java/org/hibernate/test/legacy/ABCTest.java @@ -82,7 +82,7 @@ public class ABCTest extends LegacyTestCase { for ( Schema schema : metadata().getDatabase().getSchemas() ) { for ( Table table : schema.getTables() ) { for ( Index index : table.getIndexes() ) { - if ( index.getName().equals( "indx_a_name" ) ) { + if ( index.getName().toString().equals( "indx_a_name" ) ) { found = true; break; } diff --git a/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java b/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java index 78edc4728c..352fb36659 100644 --- a/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java +++ b/hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java @@ -123,8 +123,9 @@ public class SchemaUtil { } public static boolean hasUniqueKey(TableSpecification table, String keyName) { + Identifier identifier = Identifier.toIdentifier( keyName ); for ( UniqueKey uk : table.getUniqueKeys() ) { - if ( uk.getName().equals( keyName ) ) { + if ( uk.getName().equals( identifier ) ) { return true; } } @@ -140,8 +141,9 @@ public class SchemaUtil { * @return */ public static boolean hasUniqueKey(TableSpecification table, String keyName, String... columnNames) { + Identifier identifier = Identifier.toIdentifier( keyName ); for ( UniqueKey uk : table.getUniqueKeys() ) { - if ( uk.getName().equals( keyName ) ) { + if ( uk.getName().equals( identifier ) ) { for (String columnName : columnNames) { if (!uk.hasColumn( columnName )) { return false; @@ -171,8 +173,9 @@ public class SchemaUtil { } public static boolean hasIndex(TableSpecification table, String indexName) { + Identifier identifier = Identifier.toIdentifier( indexName ); for ( Index index : table.getIndexes() ) { - if ( index.getName().equals( indexName ) ) { + if ( index.getName().equals( identifier ) ) { return true; } } @@ -188,8 +191,9 @@ public class SchemaUtil { * @return */ public static boolean hasIndex(TableSpecification table, String name, String... columnNames) { + Identifier identifier = Identifier.toIdentifier( name ); for ( Index index : table.getIndexes() ) { - if ( index.getName().equals( name ) ) { + if ( index.getName().equals( identifier ) ) { if (columnNames.length != index.getColumnSpan()) { return false; }