remove more usages of some deprecated methods
This commit is contained in:
parent
6e8d609485
commit
bb0541d754
|
@ -596,16 +596,16 @@ public class TeradataDialect extends Dialect {
|
||||||
indexNameForCreation = index.getName();
|
indexNameForCreation = index.getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder columnList = new StringBuilder();
|
final StringBuilder columnList = new StringBuilder();
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Iterator<Column> column = index.getColumnIterator(); column.hasNext(); ) {
|
for ( Column column : index.getColumns() ) {
|
||||||
if ( first ) {
|
if ( first ) {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
columnList.append( ", " );
|
columnList.append( ", " );
|
||||||
}
|
}
|
||||||
columnList.append( column.next().getName() );
|
columnList.append( column.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
return new String[] {
|
return new String[] {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.StringJoiner;
|
import java.util.StringJoiner;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.StreamSupport;
|
import java.util.stream.StreamSupport;
|
||||||
|
@ -106,8 +105,8 @@ class SpannerDialectTableExporter implements Exporter<Table> {
|
||||||
|
|
||||||
ArrayList<String> dropStrings = new ArrayList<>();
|
ArrayList<String> dropStrings = new ArrayList<>();
|
||||||
|
|
||||||
for (Iterator<Index> index = table.getIndexIterator(); index.hasNext();) {
|
for ( Index index : table.getIndexes().values() ) {
|
||||||
dropStrings.add( "drop index " + index.next().getName() );
|
dropStrings.add( "drop index " + index.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
dropStrings.add( this.spannerDialect.getDropTableString( context.format( table.getQualifiedTableName() ) ) );
|
dropStrings.add( this.spannerDialect.getDropTableString( context.format( table.getQualifiedTableName() ) ) );
|
||||||
|
|
|
@ -6,13 +6,14 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.dialect.unique;
|
package org.hibernate.dialect.unique;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.UniqueKey;
|
import org.hibernate.mapping.UniqueKey;
|
||||||
|
|
||||||
|
import static org.hibernate.mapping.Index.buildSqlCreateIndexString;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* DB2 does not allow unique constraints on nullable columns. Rather than
|
* DB2 does not allow unique constraints on nullable columns. Rather than
|
||||||
* forcing "not null", use unique *indexes* instead.
|
* forcing "not null", use unique *indexes* instead.
|
||||||
|
@ -33,11 +34,11 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate {
|
||||||
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
|
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
|
||||||
SqlStringGenerationContext context) {
|
SqlStringGenerationContext context) {
|
||||||
if ( hasNullable( uniqueKey ) ) {
|
if ( hasNullable( uniqueKey ) ) {
|
||||||
return org.hibernate.mapping.Index.buildSqlCreateIndexString(
|
return buildSqlCreateIndexString(
|
||||||
context,
|
context,
|
||||||
uniqueKey.getName(),
|
uniqueKey.getName(),
|
||||||
uniqueKey.getTable(),
|
uniqueKey.getTable(),
|
||||||
uniqueKey.getColumnIterator(),
|
uniqueKey.getColumns(),
|
||||||
uniqueKey.getColumnOrderMap(),
|
uniqueKey.getColumnOrderMap(),
|
||||||
true,
|
true,
|
||||||
metadata
|
metadata
|
||||||
|
@ -63,9 +64,8 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasNullable(UniqueKey uniqueKey) {
|
private boolean hasNullable(UniqueKey uniqueKey) {
|
||||||
final Iterator<org.hibernate.mapping.Column> iter = uniqueKey.getColumnIterator();
|
for ( Column column : uniqueKey.getColumns() ) {
|
||||||
while ( iter.hasNext() ) {
|
if ( column.isNullable() ) {
|
||||||
if ( iter.next().isNullable() ) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.dialect.unique;
|
package org.hibernate.dialect.unique;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
@ -60,18 +58,19 @@ public class DefaultUniqueDelegate implements UniqueDelegate {
|
||||||
protected String uniqueConstraintSql(UniqueKey uniqueKey) {
|
protected String uniqueConstraintSql(UniqueKey uniqueKey) {
|
||||||
final StringBuilder sb = new StringBuilder();
|
final StringBuilder sb = new StringBuilder();
|
||||||
sb.append( "unique (" );
|
sb.append( "unique (" );
|
||||||
final Iterator<org.hibernate.mapping.Column> columnIterator = uniqueKey.getColumnIterator();
|
boolean first = true;
|
||||||
while ( columnIterator.hasNext() ) {
|
for ( org.hibernate.mapping.Column column : uniqueKey.getColumns() ) {
|
||||||
final org.hibernate.mapping.Column column = columnIterator.next();
|
if ( first ) {
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sb.append(", ");
|
||||||
|
}
|
||||||
sb.append( column.getQuotedName( dialect ) );
|
sb.append( column.getQuotedName( dialect ) );
|
||||||
if ( uniqueKey.getColumnOrderMap().containsKey( column ) ) {
|
if ( uniqueKey.getColumnOrderMap().containsKey( column ) ) {
|
||||||
sb.append( " " ).append( uniqueKey.getColumnOrderMap().get( column ) );
|
sb.append( " " ).append( uniqueKey.getColumnOrderMap().get( column ) );
|
||||||
}
|
}
|
||||||
if ( columnIterator.hasNext() ) {
|
|
||||||
sb.append( ", " );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return sb.append( ')' ).toString();
|
return sb.append( ')' ).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,18 +13,21 @@ import org.hibernate.mapping.Table;
|
||||||
import org.hibernate.mapping.UniqueKey;
|
import org.hibernate.mapping.UniqueKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Dialect-level delegate in charge of applying "uniqueness" to a column. Uniqueness can be defined
|
* Dialect-level delegate in charge of applying "uniqueness" to a column. Uniqueness can
|
||||||
* in 1 of 3 ways:<ol>
|
* be defined in 1 of 3 ways:
|
||||||
|
* <ol>
|
||||||
* <li>
|
* <li>
|
||||||
* Add a unique constraint via separate alter table statements. See {@link #getAlterTableToAddUniqueKeyCommand}.
|
* Add a unique constraint via separate alter table statements.
|
||||||
|
* See {@link #getAlterTableToAddUniqueKeyCommand}.
|
||||||
* Also, see {@link #getAlterTableToDropUniqueKeyCommand}
|
* Also, see {@link #getAlterTableToDropUniqueKeyCommand}
|
||||||
* </li>
|
* </li>
|
||||||
* <li>
|
* <li>
|
||||||
* Add a unique constraint via dialect-specific syntax in table create statement. See
|
* Add a unique constraint via dialect-specific syntax in table create statement.
|
||||||
* {@link #getTableCreationUniqueConstraintsFragment}
|
* See {@link #getTableCreationUniqueConstraintsFragment}
|
||||||
* </li>
|
* </li>
|
||||||
* <li>
|
* <li>
|
||||||
* Add "unique" syntax to the column itself. See {@link #getColumnDefinitionUniquenessFragment}
|
* Add "unique" syntax to the column itself.
|
||||||
|
* See {@link #getColumnDefinitionUniquenessFragment}
|
||||||
* </li>
|
* </li>
|
||||||
* </ol>
|
* </ol>
|
||||||
*
|
*
|
||||||
|
@ -38,34 +41,35 @@ public interface UniqueDelegate {
|
||||||
/**
|
/**
|
||||||
* Get the fragment that can be used to make a column unique as part of its column definition.
|
* Get the fragment that can be used to make a column unique as part of its column definition.
|
||||||
* <p/>
|
* <p/>
|
||||||
* This is intended for dialects which do not support unique constraints
|
* This is intended for {@code Dialect}s which do not support unique constraints.
|
||||||
*
|
*
|
||||||
* @param column The column to which to apply the unique
|
* @param column The column to which to apply the unique
|
||||||
* @param context A context for SQL string generation
|
* @param context A context for SQL string generation
|
||||||
* @return The fragment (usually "unique"), empty string indicates the uniqueness will be indicated using a
|
* @return The fragment (usually "unique"), empty string indicates the uniqueness will be
|
||||||
* different approach
|
* indicated using a different approach
|
||||||
*/
|
*/
|
||||||
String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context);
|
String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the fragment that can be used to apply unique constraints as part of table creation. The
|
* Get the fragment that can be used to apply unique constraints as part of table creation.
|
||||||
* implementation should iterate over the {@link UniqueKey} instances for the given table (see
|
* The implementation should iterate over the {@link UniqueKey} instances for the given table
|
||||||
* {@link org.hibernate.mapping.Table#getUniqueKeyIterator()} and generate the whole fragment for
|
* (see {@link org.hibernate.mapping.Table#getUniqueKeys()} and generate the whole fragment
|
||||||
* all unique keys
|
* for all unique keys.
|
||||||
* <p/>
|
* <p/>
|
||||||
* Intended for Dialects which support unique constraint definitions, but just not in separate ALTER statements.
|
* Intended for {@code Dialect}s which support unique constraint definitions, but just not in
|
||||||
|
* separate ALTER statements.
|
||||||
*
|
*
|
||||||
* @param table The table for which to generate the unique constraints fragment
|
* @param table The table for which to generate the unique constraints fragment
|
||||||
* @param context A context for SQL string generation
|
* @param context A context for SQL string generation
|
||||||
* @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}. NOTE: The leading
|
* @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}.
|
||||||
* comma is important!
|
* NOTE: The leading comma is important!
|
||||||
*/
|
*/
|
||||||
String getTableCreationUniqueConstraintsFragment(Table table, SqlStringGenerationContext context);
|
String getTableCreationUniqueConstraintsFragment(Table table, SqlStringGenerationContext context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the SQL ALTER TABLE command to be used to create the given UniqueKey.
|
* Get the SQL ALTER TABLE command to be used to create the given {@link UniqueKey}.
|
||||||
*
|
*
|
||||||
* @param uniqueKey The UniqueKey instance. Contains all information about the columns
|
* @param uniqueKey The {@link UniqueKey} instance. Contains all information about the columns
|
||||||
* @param metadata Access to the bootstrap mapping information
|
* @param metadata Access to the bootstrap mapping information
|
||||||
* @param context A context for SQL string generation
|
* @param context A context for SQL string generation
|
||||||
* @return The ALTER TABLE command
|
* @return The ALTER TABLE command
|
||||||
|
@ -73,9 +77,9 @@ public interface UniqueDelegate {
|
||||||
String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context);
|
String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata, SqlStringGenerationContext context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the SQL ALTER TABLE command to be used to drop the given UniqueKey.
|
* Get the SQL ALTER TABLE command to be used to drop the given {@link UniqueKey}.
|
||||||
*
|
*
|
||||||
* @param uniqueKey The UniqueKey instance. Contains all information about the columns
|
* @param uniqueKey The {@link UniqueKey} instance. Contains all information about the columns
|
||||||
* @param metadata Access to the bootstrap mapping information
|
* @param metadata Access to the bootstrap mapping information
|
||||||
* @param context A context for SQL string generation
|
* @param context A context for SQL string generation
|
||||||
* @return The ALTER TABLE command
|
* @return The ALTER TABLE command
|
||||||
|
|
|
@ -22,7 +22,8 @@ import org.hibernate.boot.model.relational.Exportable;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
|
||||||
|
import static org.hibernate.internal.util.StringHelper.isEmpty;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A constraint on a relational database table.
|
* A constraint on a relational database table.
|
||||||
|
@ -177,7 +178,7 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
|
||||||
@Override
|
@Override
|
||||||
public String sqlDropString(SqlStringGenerationContext context,
|
public String sqlDropString(SqlStringGenerationContext context,
|
||||||
String defaultCatalog, String defaultSchema) {
|
String defaultCatalog, String defaultSchema) {
|
||||||
Dialect dialect = context.getDialect();
|
final Dialect dialect = context.getDialect();
|
||||||
if ( isGenerated( dialect ) ) {
|
if ( isGenerated( dialect ) ) {
|
||||||
final String tableName = getTable().getQualifiedName( context );
|
final String tableName = getTable().getQualifiedName( context );
|
||||||
return String.format(
|
return String.format(
|
||||||
|
@ -195,13 +196,13 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
|
||||||
@Override
|
@Override
|
||||||
public String sqlCreateString(Mapping p, SqlStringGenerationContext context, String defaultCatalog,
|
public String sqlCreateString(Mapping p, SqlStringGenerationContext context, String defaultCatalog,
|
||||||
String defaultSchema) {
|
String defaultSchema) {
|
||||||
Dialect dialect = context.getDialect();
|
final Dialect dialect = context.getDialect();
|
||||||
if ( isGenerated( dialect ) ) {
|
if ( isGenerated( dialect ) ) {
|
||||||
// Certain dialects (ex: HANA) don't support FKs as expected, but other constraints can still be created.
|
// Certain dialects (ex: HANA) don't support FKs as expected, but other constraints can still be created.
|
||||||
// If that's the case, hasAlterTable() will be true, but getAddForeignKeyConstraintString will return
|
// If that's the case, hasAlterTable() will be true, but getAddForeignKeyConstraintString will return
|
||||||
// empty string. Prevent blank "alter table" statements.
|
// empty string. Prevent blank "alter table" statements.
|
||||||
String constraintString = sqlConstraintString( context, getName(), defaultCatalog, defaultSchema );
|
String constraintString = sqlConstraintString( context, getName(), defaultCatalog, defaultSchema );
|
||||||
if ( !StringHelper.isEmpty( constraintString ) ) {
|
if ( !isEmpty( constraintString ) ) {
|
||||||
final String tableName = getTable().getQualifiedName( context );
|
final String tableName = getTable().getQualifiedName( context );
|
||||||
return dialect.getAlterTableString( tableName ) + " " + constraintString;
|
return dialect.getAlterTableString( tableName ) + " " + constraintString;
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,14 +124,12 @@ public class DenormalizedTable extends Table {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Index> getIndexIterator() {
|
public Iterator<Index> getIndexIterator() {
|
||||||
List<Index> indexes = new ArrayList<>();
|
final List<Index> indexes = new ArrayList<>();
|
||||||
Iterator<Index> iter = includedTable.getIndexIterator();
|
for ( Index parentIndex : includedTable.getIndexes().values() ) {
|
||||||
while ( iter.hasNext() ) {
|
|
||||||
Index parentIndex = iter.next();
|
|
||||||
Index index = new Index();
|
Index index = new Index();
|
||||||
index.setName( getName() + parentIndex.getName() );
|
index.setName( getName() + parentIndex.getName() );
|
||||||
index.setTable( this );
|
index.setTable( this );
|
||||||
index.addColumns( parentIndex.getColumnIterator() );
|
index.addColumns( parentIndex.getColumns() );
|
||||||
indexes.add( index );
|
indexes.add( index );
|
||||||
}
|
}
|
||||||
return new JoinedIterator<>(
|
return new JoinedIterator<>(
|
||||||
|
|
|
@ -127,26 +127,25 @@ public class ForeignKey extends Constraint {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void alignColumns(Table referencedTable) {
|
private void alignColumns(Table referencedTable) {
|
||||||
final int referencedPkColumnSpan = referencedTable.getPrimaryKey().getColumnSpan();
|
final int columnSpan = getColumnSpan();
|
||||||
if ( referencedPkColumnSpan != getColumnSpan() ) {
|
final PrimaryKey primaryKey = referencedTable.getPrimaryKey();
|
||||||
|
if ( primaryKey.getColumnSpan() != columnSpan ) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
sb.append( "Foreign key (" ).append( getName() ).append( ":" )
|
sb.append( "Foreign key (" ).append( getName() ).append( ":" )
|
||||||
.append( getTable().getName() )
|
.append( getTable().getName() )
|
||||||
.append( " [" );
|
.append( " [" );
|
||||||
appendColumns( sb, getColumnIterator() );
|
appendColumns( sb, getColumns().iterator() );
|
||||||
sb.append( "])" )
|
sb.append( "])" )
|
||||||
.append( ") must have same number of columns as the referenced primary key (" )
|
.append( ") must have same number of columns as the referenced primary key (" )
|
||||||
.append( referencedTable.getName() )
|
.append( referencedTable.getName() )
|
||||||
.append( " [" );
|
.append( " [" );
|
||||||
appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() );
|
appendColumns( sb, primaryKey.getColumns().iterator() );
|
||||||
sb.append( "])" );
|
sb.append( "])" );
|
||||||
throw new MappingException( sb.toString() );
|
throw new MappingException( sb.toString() );
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator<Column> fkCols = getColumnIterator();
|
for (int i = 0; i<columnSpan; i++ ) {
|
||||||
Iterator<Column> pkCols = referencedTable.getPrimaryKey().getColumnIterator();
|
getColumn(i).setLength( primaryKey.getColumn(i).getLength() );
|
||||||
while ( pkCols.hasNext() ) {
|
|
||||||
fkCols.next().setLength( pkCols.next().getLength() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ package org.hibernate.mapping;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
@ -21,6 +20,11 @@ import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.spi.Mapping;
|
import org.hibernate.engine.spi.Mapping;
|
||||||
import org.hibernate.internal.util.StringHelper;
|
import org.hibernate.internal.util.StringHelper;
|
||||||
|
|
||||||
|
import static java.util.Collections.unmodifiableList;
|
||||||
|
import static java.util.Collections.unmodifiableMap;
|
||||||
|
import static org.hibernate.internal.util.StringHelper.isNotEmpty;
|
||||||
|
import static org.hibernate.internal.util.StringHelper.qualify;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A relational table index
|
* A relational table index
|
||||||
*
|
*
|
||||||
|
@ -41,7 +45,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
context,
|
context,
|
||||||
getQuotedName( dialect ),
|
getQuotedName( dialect ),
|
||||||
getTable(),
|
getTable(),
|
||||||
getColumnIterator(),
|
columns,
|
||||||
columnOrderMap,
|
columnOrderMap,
|
||||||
false,
|
false,
|
||||||
defaultCatalog,
|
defaultCatalog,
|
||||||
|
@ -61,14 +65,14 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
public static String buildSqlDropIndexString(
|
public static String buildSqlDropIndexString(
|
||||||
String name,
|
String name,
|
||||||
String tableName) {
|
String tableName) {
|
||||||
return "drop index " + StringHelper.qualify( tableName, name );
|
return "drop index " + qualify( tableName, name );
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String buildSqlCreateIndexString(
|
public static String buildSqlCreateIndexString(
|
||||||
SqlStringGenerationContext context,
|
SqlStringGenerationContext context,
|
||||||
String name,
|
String name,
|
||||||
Table table,
|
Table table,
|
||||||
Iterator<Column> columns,
|
java.util.List<Column> columns,
|
||||||
java.util.Map<Column, String> columnOrderMap,
|
java.util.Map<Column, String> columnOrderMap,
|
||||||
boolean unique,
|
boolean unique,
|
||||||
String defaultCatalog,
|
String defaultCatalog,
|
||||||
|
@ -87,7 +91,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
Dialect dialect,
|
Dialect dialect,
|
||||||
String name,
|
String name,
|
||||||
String tableName,
|
String tableName,
|
||||||
Iterator<Column> columns,
|
java.util.List<Column> columns,
|
||||||
java.util.Map<Column, String> columnOrderMap,
|
java.util.Map<Column, String> columnOrderMap,
|
||||||
boolean unique) {
|
boolean unique) {
|
||||||
StringBuilder buf = new StringBuilder( "create" )
|
StringBuilder buf = new StringBuilder( "create" )
|
||||||
|
@ -97,15 +101,18 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
.append( " on " )
|
.append( " on " )
|
||||||
.append( tableName )
|
.append( tableName )
|
||||||
.append( " (" );
|
.append( " (" );
|
||||||
while ( columns.hasNext() ) {
|
boolean first = true;
|
||||||
Column column = columns.next();
|
for ( Column column : columns ) {
|
||||||
|
if ( first ) {
|
||||||
|
first = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
buf.append(", ");
|
||||||
|
}
|
||||||
buf.append( column.getQuotedName( dialect ) );
|
buf.append( column.getQuotedName( dialect ) );
|
||||||
if ( columnOrderMap.containsKey( column ) ) {
|
if ( columnOrderMap.containsKey( column ) ) {
|
||||||
buf.append( " " ).append( columnOrderMap.get( column ) );
|
buf.append( " " ).append( columnOrderMap.get( column ) );
|
||||||
}
|
}
|
||||||
if ( columns.hasNext() ) {
|
|
||||||
buf.append( ", " );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
buf.append( ")" );
|
buf.append( ")" );
|
||||||
return buf.toString();
|
return buf.toString();
|
||||||
|
@ -115,7 +122,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
SqlStringGenerationContext context,
|
SqlStringGenerationContext context,
|
||||||
String name,
|
String name,
|
||||||
Table table,
|
Table table,
|
||||||
Iterator<Column> columns,
|
java.util.List<Column> columns,
|
||||||
java.util.Map<Column, String> columnOrderMap,
|
java.util.Map<Column, String> columnOrderMap,
|
||||||
boolean unique,
|
boolean unique,
|
||||||
Metadata metadata) {
|
Metadata metadata) {
|
||||||
|
@ -135,25 +142,22 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
// Used only in Table for sqlCreateString (but commented out at the moment)
|
// Used only in Table for sqlCreateString (but commented out at the moment)
|
||||||
public String sqlConstraintString(Dialect dialect) {
|
public String sqlConstraintString(Dialect dialect) {
|
||||||
StringBuilder buf = new StringBuilder( " index (" );
|
StringBuilder buf = new StringBuilder( " index (" );
|
||||||
Iterator iter = getColumnIterator();
|
boolean first = true;
|
||||||
while ( iter.hasNext() ) {
|
for ( Column column : getColumns() ) {
|
||||||
buf.append( ( (Column) iter.next() ).getQuotedName( dialect ) );
|
if ( first ) {
|
||||||
if ( iter.hasNext() ) {
|
first = false;
|
||||||
buf.append( ", " );
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
buf.append(", ");
|
||||||
|
}
|
||||||
|
buf.append( column.getQuotedName( dialect ) );
|
||||||
}
|
}
|
||||||
return buf.append( ')' ).toString();
|
return buf.append( ')' ).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String sqlDropString(SqlStringGenerationContext context,
|
public String sqlDropString(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) {
|
||||||
String defaultCatalog, String defaultSchema) {
|
return "drop index " + qualify( table.getQualifiedName( context ), getQuotedName( context.getDialect() ) );
|
||||||
Dialect dialect = context.getDialect();
|
|
||||||
return "drop index " +
|
|
||||||
StringHelper.qualify(
|
|
||||||
table.getQualifiedName( context ),
|
|
||||||
getQuotedName( dialect )
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Table getTable() {
|
public Table getTable() {
|
||||||
|
@ -168,12 +172,17 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
return columns.size();
|
return columns.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public Iterator<Column> getColumnIterator() {
|
public Iterator<Column> getColumnIterator() {
|
||||||
return columns.iterator();
|
return getColumns().iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public java.util.List<Column> getColumns() {
|
||||||
|
return unmodifiableList( columns );
|
||||||
}
|
}
|
||||||
|
|
||||||
public java.util.Map<Column, String> getColumnOrderMap() {
|
public java.util.Map<Column, String> getColumnOrderMap() {
|
||||||
return Collections.unmodifiableMap( columnOrderMap );
|
return unmodifiableMap( columnOrderMap );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addColumn(Column column) {
|
public void addColumn(Column column) {
|
||||||
|
@ -184,14 +193,14 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
|
|
||||||
public void addColumn(Column column, String order) {
|
public void addColumn(Column column, String order) {
|
||||||
addColumn( column );
|
addColumn( column );
|
||||||
if ( StringHelper.isNotEmpty( order ) ) {
|
if ( isNotEmpty( order ) ) {
|
||||||
columnOrderMap.put( column, order );
|
columnOrderMap.put( column, order );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addColumns(Iterator extraColumns) {
|
public void addColumns(java.util.List<Column> extraColumns) {
|
||||||
while ( extraColumns.hasNext() ) {
|
for ( Column column : extraColumns ) {
|
||||||
addColumn( (Column) extraColumns.next() );
|
addColumn( column );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,6 +227,6 @@ public class Index implements RelationalModel, Exportable, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getExportIdentifier() {
|
public String getExportIdentifier() {
|
||||||
return StringHelper.qualify( getTable().getExportIdentifier(), "IDX-" + getName() );
|
return qualify( getTable().getExportIdentifier(), "IDX-" + getName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
|
||||||
*/
|
*/
|
||||||
package org.hibernate.mapping;
|
package org.hibernate.mapping;
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
|
@ -60,12 +59,15 @@ public class PrimaryKey extends Constraint {
|
||||||
|
|
||||||
public String sqlConstraintString(Dialect dialect) {
|
public String sqlConstraintString(Dialect dialect) {
|
||||||
StringBuilder buf = new StringBuilder("primary key (");
|
StringBuilder buf = new StringBuilder("primary key (");
|
||||||
Iterator<Column> iter = getColumnIterator();
|
boolean first = true;
|
||||||
while ( iter.hasNext() ) {
|
for ( Column column : getColumns() ) {
|
||||||
buf.append( iter.next().getQuotedName(dialect) );
|
if ( first ) {
|
||||||
if ( iter.hasNext() ) {
|
first = false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
}
|
}
|
||||||
|
buf.append( column.getQuotedName( dialect ) );
|
||||||
}
|
}
|
||||||
return buf.append(')').toString();
|
return buf.append(')').toString();
|
||||||
}
|
}
|
||||||
|
@ -73,15 +75,17 @@ public class PrimaryKey extends Constraint {
|
||||||
@Override
|
@Override
|
||||||
public String sqlConstraintString(SqlStringGenerationContext context, String constraintName, String defaultCatalog, String defaultSchema) {
|
public String sqlConstraintString(SqlStringGenerationContext context, String constraintName, String defaultCatalog, String defaultSchema) {
|
||||||
Dialect dialect = context.getDialect();
|
Dialect dialect = context.getDialect();
|
||||||
StringBuilder buf = new StringBuilder(
|
StringBuilder buf = new StringBuilder();
|
||||||
dialect.getAddPrimaryKeyConstraintString(constraintName)
|
buf.append( dialect.getAddPrimaryKeyConstraintString( constraintName ) ).append('(');
|
||||||
).append('(');
|
boolean first = true;
|
||||||
Iterator iter = getColumnIterator();
|
for ( Column column : getColumns() ) {
|
||||||
while ( iter.hasNext() ) {
|
if ( first ) {
|
||||||
buf.append( ( (Column) iter.next() ).getQuotedName(dialect) );
|
first = false;
|
||||||
if ( iter.hasNext() ) {
|
}
|
||||||
|
else {
|
||||||
buf.append(", ");
|
buf.append(", ");
|
||||||
}
|
}
|
||||||
|
buf.append( column.getQuotedName( dialect ) );
|
||||||
}
|
}
|
||||||
return buf.append(')').toString();
|
return buf.append(')').toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,9 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
|
||||||
* Return the column which is identified by column provided as argument.
|
* Return the column which is identified by column provided as argument.
|
||||||
*
|
*
|
||||||
* @param column column with at least a name.
|
* @param column column with at least a name.
|
||||||
* @return the underlying column or null if not inside this table. Note: the instance *can* be different than the input parameter, but the name will be the same.
|
* @return the underlying column or null if not inside this table.
|
||||||
|
* Note: the instance *can* be different than the input parameter,
|
||||||
|
* but the name will be the same.
|
||||||
*/
|
*/
|
||||||
public Column getColumn(Column column) {
|
public Column getColumn(Column column) {
|
||||||
if ( column == null ) {
|
if ( column == null ) {
|
||||||
|
@ -337,49 +339,46 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
|
||||||
// unique key is unnecessary because a primary key is already unique by definition. We handle
|
// unique key is unnecessary because a primary key is already unique by definition. We handle
|
||||||
// this case specifically because some databases fail if you try to apply a unique key to
|
// this case specifically because some databases fail if you try to apply a unique key to
|
||||||
// the primary key columns which causes schema export to fail in these cases.
|
// the primary key columns which causes schema export to fail in these cases.
|
||||||
if ( uniqueKeys.isEmpty() ) {
|
if ( !uniqueKeys.isEmpty() ) {
|
||||||
// nothing to do
|
if ( uniqueKeys.size() == 1 ) {
|
||||||
return;
|
// we have to worry about condition 2 above, but not condition 1
|
||||||
}
|
final Map.Entry<String,UniqueKey> uniqueKeyEntry = uniqueKeys.entrySet().iterator().next();
|
||||||
else if ( uniqueKeys.size() == 1 ) {
|
|
||||||
// we have to worry about condition 2 above, but not condition 1
|
|
||||||
final Map.Entry<String,UniqueKey> uniqueKeyEntry = uniqueKeys.entrySet().iterator().next();
|
|
||||||
if ( isSameAsPrimaryKeyColumns( uniqueKeyEntry.getValue() ) ) {
|
|
||||||
uniqueKeys.remove( uniqueKeyEntry.getKey() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
// we have to check both conditions 1 and 2
|
|
||||||
final Iterator<Map.Entry<String,UniqueKey>> uniqueKeyEntries = uniqueKeys.entrySet().iterator();
|
|
||||||
while ( uniqueKeyEntries.hasNext() ) {
|
|
||||||
final Map.Entry<String,UniqueKey> uniqueKeyEntry = uniqueKeyEntries.next();
|
|
||||||
final UniqueKey uniqueKey = uniqueKeyEntry.getValue();
|
|
||||||
boolean removeIt = false;
|
|
||||||
|
|
||||||
// condition 1 : check against other unique keys
|
|
||||||
for ( UniqueKey otherUniqueKey : uniqueKeys.values() ) {
|
|
||||||
// make sure its not the same unique key
|
|
||||||
if ( uniqueKeyEntry.getValue() == otherUniqueKey ) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( otherUniqueKey.getColumns().containsAll( uniqueKey.getColumns() )
|
|
||||||
&& uniqueKey.getColumns().containsAll( otherUniqueKey.getColumns() ) ) {
|
|
||||||
removeIt = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// condition 2 : check against pk
|
|
||||||
if ( isSameAsPrimaryKeyColumns( uniqueKeyEntry.getValue() ) ) {
|
if ( isSameAsPrimaryKeyColumns( uniqueKeyEntry.getValue() ) ) {
|
||||||
removeIt = true;
|
uniqueKeys.remove( uniqueKeyEntry.getKey() );
|
||||||
}
|
|
||||||
|
|
||||||
if ( removeIt ) {
|
|
||||||
//uniqueKeys.remove( uniqueKeyEntry.getKey() );
|
|
||||||
uniqueKeyEntries.remove();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// we have to check both conditions 1 and 2
|
||||||
|
final Iterator<Map.Entry<String,UniqueKey>> uniqueKeyEntries = uniqueKeys.entrySet().iterator();
|
||||||
|
while ( uniqueKeyEntries.hasNext() ) {
|
||||||
|
final Map.Entry<String,UniqueKey> uniqueKeyEntry = uniqueKeyEntries.next();
|
||||||
|
final UniqueKey uniqueKey = uniqueKeyEntry.getValue();
|
||||||
|
boolean removeIt = false;
|
||||||
|
|
||||||
|
// condition 1 : check against other unique keys
|
||||||
|
for ( UniqueKey otherUniqueKey : uniqueKeys.values() ) {
|
||||||
|
// make sure its not the same unique key
|
||||||
|
if ( uniqueKeyEntry.getValue() == otherUniqueKey ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( otherUniqueKey.getColumns().containsAll( uniqueKey.getColumns() )
|
||||||
|
&& uniqueKey.getColumns().containsAll( otherUniqueKey.getColumns() ) ) {
|
||||||
|
removeIt = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// condition 2 : check against pk
|
||||||
|
if ( isSameAsPrimaryKeyColumns( uniqueKeyEntry.getValue() ) ) {
|
||||||
|
removeIt = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( removeIt ) {
|
||||||
|
//uniqueKeys.remove( uniqueKeyEntry.getKey() );
|
||||||
|
uniqueKeyEntries.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,9 @@ import org.hibernate.type.descriptor.java.JavaType;
|
||||||
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
|
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
|
||||||
import org.hibernate.type.spi.CompositeTypeImplementor;
|
import org.hibernate.type.spi.CompositeTypeImplementor;
|
||||||
|
|
||||||
|
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_CLASS_ARRAY;
|
||||||
|
import static org.hibernate.internal.util.collections.ArrayHelper.EMPTY_STRING_ARRAY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Steve Ebersole
|
* @author Steve Ebersole
|
||||||
*/
|
*/
|
||||||
|
@ -310,18 +313,18 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
|
||||||
|
|
||||||
for ( Property property : bootType.getPropertyClosure() ) {
|
for ( Property property : bootType.getPropertyClosure() ) {
|
||||||
//TODO: redesign how PropertyAccessors are acquired...
|
//TODO: redesign how PropertyAccessors are acquired...
|
||||||
final PropertyAccess propertyAccess = makePropertyAccess(property);
|
final PropertyAccess propertyAccess = makePropertyAccess( property );
|
||||||
|
|
||||||
propertyAccessMap.put(property.getName(), propertyAccess);
|
propertyAccessMap.put( property.getName(), propertyAccess );
|
||||||
|
|
||||||
if (!(propertyAccess instanceof PropertyAccessBasicImpl)) {
|
if ( !(propertyAccess instanceof PropertyAccessBasicImpl) ) {
|
||||||
foundCustomAccessor = true;
|
foundCustomAccessor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getterNames.add(propertyAccess.getGetter().getMethodName());
|
getterNames.add( propertyAccess.getGetter().getMethodName() );
|
||||||
getterTypes.add(propertyAccess.getGetter().getReturnTypeClass());
|
getterTypes.add( propertyAccess.getGetter().getReturnTypeClass() );
|
||||||
|
|
||||||
setterNames.add(propertyAccess.getSetter().getMethodName());
|
setterNames.add( propertyAccess.getSetter().getMethodName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( foundCustomAccessor || ! Environment.useReflectionOptimizer() ) {
|
if ( foundCustomAccessor || ! Environment.useReflectionOptimizer() ) {
|
||||||
|
@ -330,9 +333,9 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
|
||||||
|
|
||||||
return bytecodeProvider.getReflectionOptimizer(
|
return bytecodeProvider.getReflectionOptimizer(
|
||||||
javaTypeToReflect,
|
javaTypeToReflect,
|
||||||
getterNames.toArray( new String[0] ),
|
getterNames.toArray( EMPTY_STRING_ARRAY ),
|
||||||
setterNames.toArray( new String[0] ),
|
setterNames.toArray( EMPTY_STRING_ARRAY ),
|
||||||
getterTypes.toArray( new Class[0] )
|
getterTypes.toArray( EMPTY_CLASS_ARRAY )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -347,9 +347,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
|
||||||
GenerationTarget... targets) {
|
GenerationTarget... targets) {
|
||||||
final Exporter<Index> exporter = dialect.getIndexExporter();
|
final Exporter<Index> exporter = dialect.getIndexExporter();
|
||||||
|
|
||||||
final Iterator<Index> indexItr = table.getIndexIterator();
|
for ( Index index : table.getIndexes().values() ) {
|
||||||
while ( indexItr.hasNext() ) {
|
|
||||||
final Index index = indexItr.next();
|
|
||||||
if ( !StringHelper.isEmpty( index.getName() ) ) {
|
if ( !StringHelper.isEmpty( index.getName() ) ) {
|
||||||
IndexInformation existingIndex = null;
|
IndexInformation existingIndex = null;
|
||||||
if ( tableInformation != null ) {
|
if ( tableInformation != null ) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ import java.net.URL;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -382,9 +381,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// indexes
|
// indexes
|
||||||
final Iterator<Index> indexItr = table.getIndexIterator();
|
for ( Index index : table.getIndexes().values() ) {
|
||||||
while ( indexItr.hasNext() ) {
|
|
||||||
final Index index = indexItr.next();
|
|
||||||
checkExportIdentifier( index, exportIdentifiers );
|
checkExportIdentifier( index, exportIdentifiers );
|
||||||
applySqlStrings(
|
applySqlStrings(
|
||||||
dialect.getIndexExporter().getSqlCreateStrings( index, metadata,
|
dialect.getIndexExporter().getSqlCreateStrings( index, metadata,
|
||||||
|
|
|
@ -6,14 +6,13 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.tool.schema.internal;
|
package org.hibernate.tool.schema.internal;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.hibernate.AssertionFailure;
|
import org.hibernate.AssertionFailure;
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
|
||||||
import org.hibernate.dialect.Dialect;
|
import org.hibernate.dialect.Dialect;
|
||||||
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
|
|
||||||
import org.hibernate.mapping.Column;
|
import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.ForeignKey;
|
import org.hibernate.mapping.ForeignKey;
|
||||||
import org.hibernate.tool.schema.spi.Exporter;
|
import org.hibernate.tool.schema.spi.Exporter;
|
||||||
|
@ -49,45 +48,11 @@ public class StandardForeignKeyExporter implements Exporter<ForeignKey> {
|
||||||
final String[] columnNames = new String[numberOfColumns];
|
final String[] columnNames = new String[numberOfColumns];
|
||||||
final String[] targetColumnNames = new String[numberOfColumns];
|
final String[] targetColumnNames = new String[numberOfColumns];
|
||||||
|
|
||||||
final Iterator targetItr;
|
final List<Column> targetColumns = getTargetColumns( foreignKey, numberOfColumns );
|
||||||
if ( foreignKey.isReferenceToPrimaryKey() ) {
|
final List<Column> columns = foreignKey.getColumns();
|
||||||
if ( numberOfColumns != foreignKey.getReferencedTable().getPrimaryKey().getColumnSpan() ) {
|
for ( int i=0; i<columns.size() && i<targetColumns.size(); i++ ) {
|
||||||
throw new AssertionFailure(
|
columnNames[i] = columns.get(i).getQuotedName( dialect );
|
||||||
String.format(
|
targetColumnNames[i] = targetColumns.get(i).getQuotedName( dialect );
|
||||||
Locale.ENGLISH,
|
|
||||||
COLUMN_MISMATCH_MSG,
|
|
||||||
numberOfColumns,
|
|
||||||
foreignKey.getReferencedTable().getPrimaryKey().getColumnSpan(),
|
|
||||||
foreignKey.getName(),
|
|
||||||
foreignKey.getTable().getName(),
|
|
||||||
foreignKey.getReferencedTable().getName()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
targetItr = foreignKey.getReferencedTable().getPrimaryKey().getColumnIterator();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ( numberOfColumns != foreignKey.getReferencedColumns().size() ) {
|
|
||||||
throw new AssertionFailure(
|
|
||||||
String.format(
|
|
||||||
Locale.ENGLISH,
|
|
||||||
COLUMN_MISMATCH_MSG,
|
|
||||||
numberOfColumns,
|
|
||||||
foreignKey.getReferencedColumns().size(),
|
|
||||||
foreignKey.getName(),
|
|
||||||
foreignKey.getTable().getName(),
|
|
||||||
foreignKey.getReferencedTable().getName()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
targetItr = foreignKey.getReferencedColumns().iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
final Iterator itr = foreignKey.getColumnIterator();
|
|
||||||
while ( itr.hasNext() ) {
|
|
||||||
columnNames[i] = ( (Column) itr.next() ).getQuotedName( dialect );
|
|
||||||
targetColumnNames[i] = ( (Column) targetItr.next() ).getQuotedName( dialect );
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,6 +84,41 @@ public class StandardForeignKeyExporter implements Exporter<ForeignKey> {
|
||||||
return new String[] { buffer.toString() };
|
return new String[] { buffer.toString() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<Column> getTargetColumns(ForeignKey foreignKey, int numberOfColumns) {
|
||||||
|
if ( foreignKey.isReferenceToPrimaryKey() ) {
|
||||||
|
if ( numberOfColumns != foreignKey.getReferencedTable().getPrimaryKey().getColumnSpan() ) {
|
||||||
|
throw new AssertionFailure(
|
||||||
|
String.format(
|
||||||
|
Locale.ENGLISH,
|
||||||
|
COLUMN_MISMATCH_MSG,
|
||||||
|
numberOfColumns,
|
||||||
|
foreignKey.getReferencedTable().getPrimaryKey().getColumnSpan(),
|
||||||
|
foreignKey.getName(),
|
||||||
|
foreignKey.getTable().getName(),
|
||||||
|
foreignKey.getReferencedTable().getName()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return foreignKey.getReferencedTable().getPrimaryKey().getColumns();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if ( numberOfColumns != foreignKey.getReferencedColumns().size() ) {
|
||||||
|
throw new AssertionFailure(
|
||||||
|
String.format(
|
||||||
|
Locale.ENGLISH,
|
||||||
|
COLUMN_MISMATCH_MSG,
|
||||||
|
numberOfColumns,
|
||||||
|
foreignKey.getReferencedColumns().size(),
|
||||||
|
foreignKey.getName(),
|
||||||
|
foreignKey.getTable().getName(),
|
||||||
|
foreignKey.getReferencedTable().getName()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return foreignKey.getReferencedColumns();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String[] getSqlDropStrings(ForeignKey foreignKey, Metadata metadata, SqlStringGenerationContext context) {
|
public String[] getSqlDropStrings(ForeignKey foreignKey, Metadata metadata, SqlStringGenerationContext context) {
|
||||||
if ( !dialect.hasAlterTable() ) {
|
if ( !dialect.hasAlterTable() ) {
|
||||||
|
@ -134,9 +134,7 @@ public class StandardForeignKeyExporter implements Exporter<ForeignKey> {
|
||||||
}
|
}
|
||||||
|
|
||||||
final String sourceTableName = context.format( foreignKey.getTable().getQualifiedTableName() );
|
final String sourceTableName = context.format( foreignKey.getTable().getQualifiedTableName() );
|
||||||
return new String[] {
|
return new String[] { getSqlDropStrings( sourceTableName, foreignKey, dialect ) };
|
||||||
getSqlDropStrings( sourceTableName, foreignKey, dialect )
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSqlDropStrings(String tableName, ForeignKey foreignKey, Dialect dialect) {
|
private String getSqlDropStrings(String tableName, ForeignKey foreignKey, Dialect dialect) {
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.tool.schema.internal;
|
package org.hibernate.tool.schema.internal;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.hibernate.boot.Metadata;
|
import org.hibernate.boot.Metadata;
|
||||||
|
@ -60,10 +59,8 @@ public class StandardIndexExporter implements Exporter<Index> {
|
||||||
.append( " (" );
|
.append( " (" );
|
||||||
|
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
final Iterator<Column> columnItr = index.getColumnIterator();
|
|
||||||
final Map<Column, String> columnOrderMap = index.getColumnOrderMap();
|
final Map<Column, String> columnOrderMap = index.getColumnOrderMap();
|
||||||
while ( columnItr.hasNext() ) {
|
for ( Column column : index.getColumns() ) {
|
||||||
final Column column = columnItr.next();
|
|
||||||
if ( first ) {
|
if ( first ) {
|
||||||
first = false;
|
first = false;
|
||||||
}
|
}
|
||||||
|
@ -87,13 +84,9 @@ public class StandardIndexExporter implements Exporter<Index> {
|
||||||
|
|
||||||
final String tableName = context.format( index.getTable().getQualifiedTableName() );
|
final String tableName = context.format( index.getTable().getQualifiedTableName() );
|
||||||
|
|
||||||
final String indexNameForCreation;
|
final String indexNameForCreation = dialect.qualifyIndexName()
|
||||||
if ( dialect.qualifyIndexName() ) {
|
? StringHelper.qualify( tableName, index.getName() )
|
||||||
indexNameForCreation = StringHelper.qualify( tableName, index.getName() );
|
: index.getName();
|
||||||
}
|
|
||||||
else {
|
|
||||||
indexNameForCreation = index.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new String[] { "drop index " + indexNameForCreation };
|
return new String[] { "drop index " + indexNameForCreation };
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,8 +68,7 @@ public class StandardTableExporter implements Exporter<Table> {
|
||||||
// Try to find out the name of the primary key in case the dialect needs it to create an identity
|
// Try to find out the name of the primary key in case the dialect needs it to create an identity
|
||||||
String pkColName = null;
|
String pkColName = null;
|
||||||
if ( table.hasPrimaryKey() ) {
|
if ( table.hasPrimaryKey() ) {
|
||||||
Column pkColumn = table.getPrimaryKey().getColumns().iterator().next();
|
pkColName = table.getPrimaryKey().getColumns().get(0).getQuotedName( dialect );
|
||||||
pkColName = pkColumn.getQuotedName( dialect );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isFirst = true;
|
boolean isFirst = true;
|
||||||
|
@ -166,7 +165,7 @@ public class StandardTableExporter implements Exporter<Table> {
|
||||||
|
|
||||||
applyComments( table, formattedTableName, sqlStrings );
|
applyComments( table, formattedTableName, sqlStrings );
|
||||||
|
|
||||||
applyInitCommands( table, sqlStrings, context );
|
applyInitCommands( table, sqlStrings, context );
|
||||||
|
|
||||||
return sqlStrings.toArray(StringHelper.EMPTY_STRINGS);
|
return sqlStrings.toArray(StringHelper.EMPTY_STRINGS);
|
||||||
}
|
}
|
||||||
|
|
|
@ -289,7 +289,7 @@ public class DefaultNamingCollectionElementTest {
|
||||||
String propertyName,
|
String propertyName,
|
||||||
String columnName) {
|
String columnName) {
|
||||||
final Collection collection = metadataImplementor.getCollectionBinding( collectionOwner + "." + propertyName );
|
final Collection collection = metadataImplementor.getCollectionBinding( collectionOwner + "." + propertyName );
|
||||||
final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
|
final Iterator columnIterator = collection.getCollectionTable().getColumns().iterator();
|
||||||
boolean hasDefault = false;
|
boolean hasDefault = false;
|
||||||
while ( columnIterator.hasNext() ) {
|
while ( columnIterator.hasNext() ) {
|
||||||
Column column = (Column) columnIterator.next();
|
Column column = (Column) columnIterator.next();
|
||||||
|
@ -409,7 +409,7 @@ public class DefaultNamingCollectionElementTest {
|
||||||
assertEquals( ownerForeignKeyNameExpected, ownerCollection.getKey().getColumnIterator().next().getText() );
|
assertEquals( ownerForeignKeyNameExpected, ownerCollection.getKey().getColumnIterator().next().getText() );
|
||||||
|
|
||||||
boolean hasOwnerFK = false;
|
boolean hasOwnerFK = false;
|
||||||
for ( Iterator it = ownerCollection.getCollectionTable().getForeignKeyIterator(); it.hasNext(); ) {
|
for (Iterator it = ownerCollection.getCollectionTable().getForeignKeys().values().iterator(); it.hasNext(); ) {
|
||||||
final ForeignKey fk = (ForeignKey) it.next();
|
final ForeignKey fk = (ForeignKey) it.next();
|
||||||
assertSame( ownerCollection.getCollectionTable(), fk.getTable() );
|
assertSame( ownerCollection.getCollectionTable(), fk.getTable() );
|
||||||
if ( fk.getColumnSpan() > 1 ) {
|
if ( fk.getColumnSpan() > 1 ) {
|
||||||
|
|
|
@ -47,7 +47,7 @@ public class CommentTest {
|
||||||
.flatMap(namespace -> namespace.getTables().stream()).filter(t -> t.getName().equals(TABLE_NAME))
|
.flatMap(namespace -> namespace.getTables().stream()).filter(t -> t.getName().equals(TABLE_NAME))
|
||||||
.findFirst().orElse(null);
|
.findFirst().orElse(null);
|
||||||
assertThat(table.getComment(), is(TABLE_COMMENT));
|
assertThat(table.getComment(), is(TABLE_COMMENT));
|
||||||
Iterator<Column> it = table.getColumnIterator();
|
Iterator<Column> it = table.getColumns().iterator();
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Column col = it.next();
|
Column col = it.next();
|
||||||
assertThat(col.getComment(), is("I am " + col.getName()));
|
assertThat(col.getComment(), is("I am " + col.getName()));
|
||||||
|
|
|
@ -51,7 +51,7 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
|
||||||
@Test
|
@Test
|
||||||
public void testTableIndex() {
|
public void testTableIndex() {
|
||||||
PersistentClass entity = metadata().getEntityBinding( Car.class.getName() );
|
PersistentClass entity = metadata().getEntityBinding( Car.class.getName() );
|
||||||
Iterator itr = entity.getTable().getUniqueKeyIterator();
|
Iterator itr = entity.getTable().getUniqueKeys().values().iterator();
|
||||||
assertTrue( itr.hasNext() );
|
assertTrue( itr.hasNext() );
|
||||||
UniqueKey uk = (UniqueKey) itr.next();
|
UniqueKey uk = (UniqueKey) itr.next();
|
||||||
assertFalse( itr.hasNext() );
|
assertFalse( itr.hasNext() );
|
||||||
|
@ -64,13 +64,13 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
|
||||||
assertSame( entity.getTable(), uk.getTable() );
|
assertSame( entity.getTable(), uk.getTable() );
|
||||||
|
|
||||||
|
|
||||||
itr = entity.getTable().getIndexIterator();
|
itr = entity.getTable().getIndexes().values().iterator();
|
||||||
assertTrue( itr.hasNext() );
|
assertTrue( itr.hasNext() );
|
||||||
Index index = (Index)itr.next();
|
Index index = (Index)itr.next();
|
||||||
assertFalse( itr.hasNext() );
|
assertFalse( itr.hasNext() );
|
||||||
assertEquals( "Car_idx", index.getName() );
|
assertEquals( "Car_idx", index.getName() );
|
||||||
assertEquals( 1, index.getColumnSpan() );
|
assertEquals( 1, index.getColumnSpan() );
|
||||||
column = index.getColumnIterator().next();
|
column = index.getColumns().iterator().next();
|
||||||
assertEquals( "since", column.getName() );
|
assertEquals( "since", column.getName() );
|
||||||
assertSame( entity.getTable(), index.getTable() );
|
assertSame( entity.getTable(), index.getTable() );
|
||||||
}
|
}
|
||||||
|
@ -80,13 +80,13 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
|
||||||
PersistentClass entity = metadata().getEntityBinding( Car.class.getName() );
|
PersistentClass entity = metadata().getEntityBinding( Car.class.getName() );
|
||||||
|
|
||||||
Join join = (Join)entity.getJoinIterator().next();
|
Join join = (Join)entity.getJoinIterator().next();
|
||||||
Iterator<Index> itr = join.getTable().getIndexIterator();
|
Iterator<Index> itr = join.getTable().getIndexes().values().iterator();
|
||||||
assertTrue( itr.hasNext() );
|
assertTrue( itr.hasNext() );
|
||||||
Index index = itr.next();
|
Index index = itr.next();
|
||||||
assertFalse( itr.hasNext() );
|
assertFalse( itr.hasNext() );
|
||||||
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
|
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
|
||||||
assertEquals( 2, index.getColumnSpan() );
|
assertEquals( 2, index.getColumnSpan() );
|
||||||
Iterator<Column> columnIterator = index.getColumnIterator();
|
Iterator<Column> columnIterator = index.getColumns().iterator();
|
||||||
Column column = columnIterator.next();
|
Column column = columnIterator.next();
|
||||||
assertEquals( "dealer_name", column.getName() );
|
assertEquals( "dealer_name", column.getName() );
|
||||||
column = columnIterator.next();
|
column = columnIterator.next();
|
||||||
|
@ -102,13 +102,13 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
|
||||||
Set set = (Set)property.getValue();
|
Set set = (Set)property.getValue();
|
||||||
Table collectionTable = set.getCollectionTable();
|
Table collectionTable = set.getCollectionTable();
|
||||||
|
|
||||||
Iterator<Index> itr = collectionTable.getIndexIterator();
|
Iterator<Index> itr = collectionTable.getIndexes().values().iterator();
|
||||||
assertTrue( itr.hasNext() );
|
assertTrue( itr.hasNext() );
|
||||||
Index index = itr.next();
|
Index index = itr.next();
|
||||||
assertFalse( itr.hasNext() );
|
assertFalse( itr.hasNext() );
|
||||||
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
|
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
|
||||||
assertEquals( 1, index.getColumnSpan() );
|
assertEquals( 1, index.getColumnSpan() );
|
||||||
Iterator<Column> columnIterator = index.getColumnIterator();
|
Iterator<Column> columnIterator = index.getColumns().iterator();
|
||||||
Column column = columnIterator.next();
|
Column column = columnIterator.next();
|
||||||
assertEquals( "name", column.getName() );
|
assertEquals( "name", column.getName() );
|
||||||
assertSame( collectionTable, index.getTable() );
|
assertSame( collectionTable, index.getTable() );
|
||||||
|
@ -122,13 +122,13 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
|
||||||
Bag set = (Bag)property.getValue();
|
Bag set = (Bag)property.getValue();
|
||||||
Table collectionTable = set.getCollectionTable();
|
Table collectionTable = set.getCollectionTable();
|
||||||
|
|
||||||
Iterator<Index> itr = collectionTable.getIndexIterator();
|
Iterator<Index> itr = collectionTable.getIndexes().values().iterator();
|
||||||
assertTrue( itr.hasNext() );
|
assertTrue( itr.hasNext() );
|
||||||
Index index = itr.next();
|
Index index = itr.next();
|
||||||
assertFalse( itr.hasNext() );
|
assertFalse( itr.hasNext() );
|
||||||
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
|
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
|
||||||
assertEquals( 1, index.getColumnSpan() );
|
assertEquals( 1, index.getColumnSpan() );
|
||||||
Iterator<Column> columnIterator = index.getColumnIterator();
|
Iterator<Column> columnIterator = index.getColumns().iterator();
|
||||||
Column column = columnIterator.next();
|
Column column = columnIterator.next();
|
||||||
assertEquals( "importers_id", column.getName() );
|
assertEquals( "importers_id", column.getName() );
|
||||||
assertSame( collectionTable, index.getTable() );
|
assertSame( collectionTable, index.getTable() );
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class IndexedCollectionTest {
|
||||||
|
|
||||||
private boolean isDefaultColumnPresent(SessionFactoryScope scope, String collectionOwner, String propertyName, String suffix) {
|
private boolean isDefaultColumnPresent(SessionFactoryScope scope, String collectionOwner, String propertyName, String suffix) {
|
||||||
final Collection collection = scope.getMetadataImplementor().getCollectionBinding( collectionOwner + "." + propertyName );
|
final Collection collection = scope.getMetadataImplementor().getCollectionBinding( collectionOwner + "." + propertyName );
|
||||||
final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
|
final Iterator columnIterator = collection.getCollectionTable().getColumns().iterator();
|
||||||
boolean hasDefault = false;
|
boolean hasDefault = false;
|
||||||
while ( columnIterator.hasNext() ) {
|
while ( columnIterator.hasNext() ) {
|
||||||
Column column = (Column) columnIterator.next();
|
Column column = (Column) columnIterator.next();
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class EagerIndexedCollectionTest extends BaseNonConfigCoreFunctionalTestC
|
||||||
|
|
||||||
private boolean isDefaultColumnPresent(String collectionOwner, String propertyName, String suffix) {
|
private boolean isDefaultColumnPresent(String collectionOwner, String propertyName, String suffix) {
|
||||||
final Collection collection = metadata().getCollectionBinding( collectionOwner + "." + propertyName );
|
final Collection collection = metadata().getCollectionBinding( collectionOwner + "." + propertyName );
|
||||||
final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
|
final Iterator columnIterator = collection.getCollectionTable().getColumns().iterator();
|
||||||
boolean hasDefault = false;
|
boolean hasDefault = false;
|
||||||
while ( columnIterator.hasNext() ) {
|
while ( columnIterator.hasNext() ) {
|
||||||
Column column = (Column) columnIterator.next();
|
Column column = (Column) columnIterator.next();
|
||||||
|
|
|
@ -202,7 +202,7 @@ public class ManyToManyImplicitNamingTest extends BaseNonConfigCoreFunctionalTes
|
||||||
}
|
}
|
||||||
boolean hasOwnerFK = false;
|
boolean hasOwnerFK = false;
|
||||||
boolean hasInverseFK = false;
|
boolean hasInverseFK = false;
|
||||||
for ( Iterator it=ownerCollection.getCollectionTable().getForeignKeyIterator(); it.hasNext(); ) {
|
for (Iterator it = ownerCollection.getCollectionTable().getForeignKeys().values().iterator(); it.hasNext(); ) {
|
||||||
final ForeignKey fk = (ForeignKey) it.next();
|
final ForeignKey fk = (ForeignKey) it.next();
|
||||||
assertSame( ownerCollection.getCollectionTable(), fk.getTable() );
|
assertSame( ownerCollection.getCollectionTable(), fk.getTable() );
|
||||||
if ( fk.getColumnSpan() > 1 ) {
|
if ( fk.getColumnSpan() > 1 ) {
|
||||||
|
|
|
@ -63,13 +63,13 @@ public class LongKeyNamingStrategyTest extends BaseUnitTestCase {
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
org.hibernate.mapping.ForeignKey foreignKey =
|
org.hibernate.mapping.ForeignKey foreignKey =
|
||||||
(org.hibernate.mapping.ForeignKey) metadata.getEntityBinding( Address.class.getName()).getTable().getForeignKeyIterator().next();
|
(org.hibernate.mapping.ForeignKey) metadata.getEntityBinding(Address.class.getName()).getTable().getForeignKeys().values().iterator().next();
|
||||||
assertEquals( "FK_way_longer_than_the_30_char", foreignKey.getName() );
|
assertEquals( "FK_way_longer_than_the_30_char", foreignKey.getName() );
|
||||||
|
|
||||||
UniqueKey uniqueKey = metadata.getEntityBinding( Address.class.getName()).getTable().getUniqueKeyIterator().next();
|
UniqueKey uniqueKey = metadata.getEntityBinding(Address.class.getName()).getTable().getUniqueKeys().values().iterator().next();
|
||||||
assertEquals( "UK_way_longer_than_the_30_char", uniqueKey.getName() );
|
assertEquals( "UK_way_longer_than_the_30_char", uniqueKey.getName() );
|
||||||
|
|
||||||
org.hibernate.mapping.Index index = metadata.getEntityBinding( Address.class.getName()).getTable().getIndexIterator().next();
|
org.hibernate.mapping.Index index = metadata.getEntityBinding(Address.class.getName()).getTable().getIndexes().values().iterator().next();
|
||||||
assertEquals( "IDX_way_longer_than_the_30_cha", index.getName() );
|
assertEquals( "IDX_way_longer_than_the_30_cha", index.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
// $Id$
|
// $Id$
|
||||||
package org.hibernate.orm.test.annotations.namingstrategy.charset;
|
package org.hibernate.orm.test.annotations.namingstrategy.charset;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
|
@ -67,14 +66,14 @@ public abstract class AbstractCharsetNamingStrategyTest extends BaseUnitTestCase
|
||||||
.applyImplicitNamingStrategy( new LongIdentifierNamingStrategy() )
|
.applyImplicitNamingStrategy( new LongIdentifierNamingStrategy() )
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
UniqueKey uniqueKey = metadata.getEntityBinding( Address.class.getName()).getTable().getUniqueKeyIterator().next();
|
UniqueKey uniqueKey = metadata.getEntityBinding(Address.class.getName()).getTable().getUniqueKeys().values().iterator().next();
|
||||||
assertEquals( expectedUniqueKeyName(), uniqueKey.getName() );
|
assertEquals( expectedUniqueKeyName(), uniqueKey.getName() );
|
||||||
|
|
||||||
org.hibernate.mapping.ForeignKey foreignKey =
|
org.hibernate.mapping.ForeignKey foreignKey =
|
||||||
(org.hibernate.mapping.ForeignKey) metadata.getEntityBinding( Address.class.getName()).getTable().getForeignKeyIterator().next();
|
(org.hibernate.mapping.ForeignKey) metadata.getEntityBinding(Address.class.getName()).getTable().getForeignKeys().values().iterator().next();
|
||||||
assertEquals( expectedForeignKeyName(), foreignKey.getName() );
|
assertEquals( expectedForeignKeyName(), foreignKey.getName() );
|
||||||
|
|
||||||
org.hibernate.mapping.Index index = metadata.getEntityBinding( Address.class.getName()).getTable().getIndexIterator().next();
|
org.hibernate.mapping.Index index = metadata.getEntityBinding(Address.class.getName()).getTable().getIndexes().values().iterator().next();
|
||||||
assertEquals( expectedIndexName(), index.getName() );
|
assertEquals( expectedIndexName(), index.getName() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -530,7 +530,7 @@ public class OneToManyTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
public void testJoinColumnConfiguredInXml() {
|
public void testJoinColumnConfiguredInXml() {
|
||||||
PersistentClass pc = metadata().getEntityBinding( Model.class.getName() );
|
PersistentClass pc = metadata().getEntityBinding( Model.class.getName() );
|
||||||
Table table = pc.getRootTable();
|
Table table = pc.getRootTable();
|
||||||
Iterator iter = table.getColumnIterator();
|
Iterator iter = table.getColumns().iterator();
|
||||||
boolean joinColumnFound = false;
|
boolean joinColumnFound = false;
|
||||||
while(iter.hasNext()) {
|
while(iter.hasNext()) {
|
||||||
Column column = (Column) iter.next();
|
Column column = (Column) iter.next();
|
||||||
|
|
|
@ -305,7 +305,7 @@ public class OneToOneTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
PersistentClass pc = metadata().getEntityBinding( Son.class.getName() );
|
PersistentClass pc = metadata().getEntityBinding( Son.class.getName() );
|
||||||
Iterator<Join> iter = pc.getJoinIterator();
|
Iterator<Join> iter = pc.getJoinIterator();
|
||||||
Table table = iter.next().getTable();
|
Table table = iter.next().getTable();
|
||||||
Iterator<Column> columnIter = table.getColumnIterator();
|
Iterator<Column> columnIter = table.getColumns().iterator();
|
||||||
boolean fooFound = false;
|
boolean fooFound = false;
|
||||||
boolean barFound = false;
|
boolean barFound = false;
|
||||||
while ( columnIter.hasNext() ) {
|
while ( columnIter.hasNext() ) {
|
||||||
|
|
|
@ -61,9 +61,9 @@ public class UniqueConstraintUnitTests extends BaseUnitTestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
assertTrue( "Could not find the expected tables.", tableA != null && tableB != null );
|
assertTrue( "Could not find the expected tables.", tableA != null && tableB != null );
|
||||||
assertFalse(
|
assertFalse(
|
||||||
tableA.getUniqueKeyIterator().next().getName().equals(
|
tableA.getUniqueKeys().values().iterator().next().getName().equals(
|
||||||
tableB.getUniqueKeyIterator().next().getName()
|
tableB.getUniqueKeys().values().iterator().next().getName()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,7 @@ public class ConstraintTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
int foundCount = 0;
|
int foundCount = 0;
|
||||||
for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) {
|
for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) {
|
||||||
for ( org.hibernate.mapping.Table table : namespace.getTables() ) {
|
for ( org.hibernate.mapping.Table table : namespace.getTables() ) {
|
||||||
Iterator fkItr = table.getForeignKeyIterator();
|
Iterator fkItr = table.getForeignKeys().values().iterator();
|
||||||
while (fkItr.hasNext()) {
|
while (fkItr.hasNext()) {
|
||||||
ForeignKey fk = (ForeignKey) fkItr.next();
|
ForeignKey fk = (ForeignKey) fkItr.next();
|
||||||
assertTrue( fk.getName().length() <= MAX_NAME_LENGTH );
|
assertTrue( fk.getName().length() <= MAX_NAME_LENGTH );
|
||||||
|
@ -89,7 +89,7 @@ public class ConstraintTest extends BaseNonConfigCoreFunctionalTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator ukItr = table.getUniqueKeyIterator();
|
Iterator ukItr = table.getUniqueKeys().values().iterator();
|
||||||
while (ukItr.hasNext()) {
|
while (ukItr.hasNext()) {
|
||||||
UniqueKey uk = (UniqueKey) ukItr.next();
|
UniqueKey uk = (UniqueKey) ukItr.next();
|
||||||
assertTrue( uk.getName().length() <= MAX_NAME_LENGTH );
|
assertTrue( uk.getName().length() <= MAX_NAME_LENGTH );
|
||||||
|
|
|
@ -90,7 +90,7 @@ public class ForeignKeyConstraintMapsIdTest extends BaseNonConfigCoreFunctionalT
|
||||||
for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) {
|
for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) {
|
||||||
for ( Table table : namespace.getTables() ) {
|
for ( Table table : namespace.getTables() ) {
|
||||||
if ( table.getName().equals( "Post" ) ) {
|
if ( table.getName().equals( "Post" ) ) {
|
||||||
Iterator<org.hibernate.mapping.ForeignKey> foreignKeyIterator = table.getForeignKeyIterator();
|
Iterator<org.hibernate.mapping.ForeignKey> foreignKeyIterator = table.getForeignKeys().values().iterator();
|
||||||
while ( foreignKeyIterator.hasNext() ) {
|
while ( foreignKeyIterator.hasNext() ) {
|
||||||
org.hibernate.mapping.ForeignKey foreignKey = foreignKeyIterator.next();
|
org.hibernate.mapping.ForeignKey foreignKey = foreignKeyIterator.next();
|
||||||
if ( foreignKey.getColumn( 0 ).getName().equals( "PD_ID" ) ) {
|
if ( foreignKey.getColumn( 0 ).getName().equals( "PD_ID" ) ) {
|
||||||
|
|
|
@ -180,7 +180,7 @@ public class ForeignKeyConstraintTest {
|
||||||
Set<String> columnSet = new LinkedHashSet<>( Arrays.asList( columns ) );
|
Set<String> columnSet = new LinkedHashSet<>( Arrays.asList( columns ) );
|
||||||
for ( Namespace namespace : scope.getDomainModel().getDatabase().getNamespaces() ) {
|
for ( Namespace namespace : scope.getDomainModel().getDatabase().getNamespaces() ) {
|
||||||
for ( org.hibernate.mapping.Table table : namespace.getTables() ) {
|
for ( org.hibernate.mapping.Table table : namespace.getTables() ) {
|
||||||
Iterator<org.hibernate.mapping.ForeignKey> fkItr = table.getForeignKeyIterator();
|
Iterator<org.hibernate.mapping.ForeignKey> fkItr = table.getForeignKeys().values().iterator();
|
||||||
while ( fkItr.hasNext() ) {
|
while ( fkItr.hasNext() ) {
|
||||||
org.hibernate.mapping.ForeignKey fk = fkItr.next();
|
org.hibernate.mapping.ForeignKey fk = fkItr.next();
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ public class ForeignKeyConstraintTest {
|
||||||
private void assertNoForeignKey(DomainModelScope scope, String foreignKeyName, String... columns) {
|
private void assertNoForeignKey(DomainModelScope scope, String foreignKeyName, String... columns) {
|
||||||
for ( Namespace namespace : scope.getDomainModel().getDatabase().getNamespaces() ) {
|
for ( Namespace namespace : scope.getDomainModel().getDatabase().getNamespaces() ) {
|
||||||
for ( org.hibernate.mapping.Table table : namespace.getTables() ) {
|
for ( org.hibernate.mapping.Table table : namespace.getTables() ) {
|
||||||
Iterator<org.hibernate.mapping.ForeignKey> fkItr = table.getForeignKeyIterator();
|
Iterator<org.hibernate.mapping.ForeignKey> fkItr = table.getForeignKeys().values().iterator();
|
||||||
while ( fkItr.hasNext() ) {
|
while ( fkItr.hasNext() ) {
|
||||||
org.hibernate.mapping.ForeignKey fk = fkItr.next();
|
org.hibernate.mapping.ForeignKey fk = fkItr.next();
|
||||||
assertFalse(
|
assertFalse(
|
||||||
|
|
|
@ -6,9 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.orm.test.constraint;
|
package org.hibernate.orm.test.constraint;
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import jakarta.persistence.CollectionTable;
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
import jakarta.persistence.Inheritance;
|
import jakarta.persistence.Inheritance;
|
||||||
|
@ -21,18 +20,14 @@ import jakarta.persistence.OneToMany;
|
||||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||||
import jakarta.persistence.Table;
|
import jakarta.persistence.Table;
|
||||||
|
|
||||||
import org.hibernate.mapping.Column;
|
|
||||||
import org.hibernate.mapping.ForeignKey;
|
import org.hibernate.mapping.ForeignKey;
|
||||||
import org.hibernate.mapping.JoinedSubclass;
|
import org.hibernate.mapping.JoinedSubclass;
|
||||||
import org.hibernate.mapping.PersistentClass;
|
|
||||||
import org.hibernate.mapping.PrimaryKey;
|
import org.hibernate.mapping.PrimaryKey;
|
||||||
import org.hibernate.mapping.Property;
|
import org.hibernate.mapping.Property;
|
||||||
import org.hibernate.mapping.Selectable;
|
import org.hibernate.mapping.Selectable;
|
||||||
import org.hibernate.mapping.Subclass;
|
import org.hibernate.mapping.Subclass;
|
||||||
import org.hibernate.mapping.ToOne;
|
import org.hibernate.mapping.ToOne;
|
||||||
import org.hibernate.metamodel.mapping.AttributeMapping;
|
|
||||||
import org.hibernate.metamodel.mapping.EntityMappingType;
|
import org.hibernate.metamodel.mapping.EntityMappingType;
|
||||||
import org.hibernate.metamodel.mapping.ForeignKeyDescriptor;
|
|
||||||
import org.hibernate.metamodel.mapping.internal.SimpleForeignKeyDescriptor;
|
import org.hibernate.metamodel.mapping.internal.SimpleForeignKeyDescriptor;
|
||||||
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
|
||||||
|
|
||||||
|
@ -102,7 +97,7 @@ public class NonRootTablePolymorphicTests {
|
||||||
// 2) for the sub->child fk
|
// 2) for the sub->child fk
|
||||||
|
|
||||||
assertThat( subclassTable.getForeignKeys().size(), is( 2 ) );
|
assertThat( subclassTable.getForeignKeys().size(), is( 2 ) );
|
||||||
subclassTable.getForeignKeyIterator().forEachRemaining(
|
subclassTable.getForeignKeys().values().iterator().forEachRemaining(
|
||||||
(foreignKey) -> {
|
(foreignKey) -> {
|
||||||
assertThat( foreignKey.getTable(), sameInstance( subclassTable ) );
|
assertThat( foreignKey.getTable(), sameInstance( subclassTable ) );
|
||||||
|
|
||||||
|
@ -167,7 +162,7 @@ public class NonRootTablePolymorphicTests {
|
||||||
assertThat( selectable.getText(), is( "parent_sub_fk" ) );
|
assertThat( selectable.getText(), is( "parent_sub_fk" ) );
|
||||||
|
|
||||||
assertThat( subParent.getTable().getForeignKeys().size(), is( 1 ) );
|
assertThat( subParent.getTable().getForeignKeys().size(), is( 1 ) );
|
||||||
final ForeignKey foreignKey = subParent.getTable().getForeignKeyIterator().next();
|
final ForeignKey foreignKey = subParent.getTable().getForeignKeys().values().iterator().next();
|
||||||
|
|
||||||
assertThat( foreignKey.getReferencedTable().getName(), is( "sub" ) );
|
assertThat( foreignKey.getReferencedTable().getName(), is( "sub" ) );
|
||||||
assertThat( foreignKey.getTable(), sameInstance( toOne.getTable() ) );
|
assertThat( foreignKey.getTable(), sameInstance( toOne.getTable() ) );
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class ABCTest {
|
||||||
.getDatabase()
|
.getDatabase()
|
||||||
.getDefaultNamespace()
|
.getDefaultNamespace()
|
||||||
.locateTable( Identifier.toIdentifier( "TA" ) );
|
.locateTable( Identifier.toIdentifier( "TA" ) );
|
||||||
Iterator<Index> indexItr = table.getIndexIterator();
|
Iterator<Index> indexItr = table.getIndexes().values().iterator();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
while ( indexItr.hasNext() ) {
|
while ( indexItr.hasNext() ) {
|
||||||
final Index index = indexItr.next();
|
final Index index = indexItr.next();
|
||||||
|
|
|
@ -93,7 +93,7 @@ public class FullyQualifiedEntityNameNamingStrategyTest {
|
||||||
|
|
||||||
boolean ownerFKFound = false;
|
boolean ownerFKFound = false;
|
||||||
boolean inverseFKFound = false;
|
boolean inverseFKFound = false;
|
||||||
for ( Iterator it = ownerCollectionMapping.getCollectionTable().getForeignKeyIterator(); it.hasNext(); ) {
|
for (Iterator it = ownerCollectionMapping.getCollectionTable().getForeignKeys().values().iterator(); it.hasNext(); ) {
|
||||||
final String fkColumnName = ( (ForeignKey) it.next() ).getColumn( 0 ).getName();
|
final String fkColumnName = ( (ForeignKey) it.next() ).getColumn( 0 ).getName();
|
||||||
if ( expectedOwnerFK.equals( fkColumnName ) ) {
|
if ( expectedOwnerFK.equals( fkColumnName ) ) {
|
||||||
ownerFKFound = true;
|
ownerFKFound = true;
|
||||||
|
|
|
@ -35,7 +35,7 @@ public class OneToOneSchemaTest {
|
||||||
|
|
||||||
Table childTable = metadata.getDatabase().getDefaultNamespace().locateTable( Identifier.toIdentifier(
|
Table childTable = metadata.getDatabase().getDefaultNamespace().locateTable( Identifier.toIdentifier(
|
||||||
"CHILD" ) );
|
"CHILD" ) );
|
||||||
assertFalse( childTable.getUniqueKeyIterator().hasNext(), "UniqueKey was generated when it should not" );
|
assertFalse( childTable.getUniqueKeys().values().iterator().hasNext(), "UniqueKey was generated when it should not" );
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
StandardServiceRegistryBuilder.destroy( ssr );
|
StandardServiceRegistryBuilder.destroy( ssr );
|
||||||
|
|
|
@ -269,7 +269,7 @@ public class PropertyRefTest {
|
||||||
public void testForeignKeyCreation(SessionFactoryScope scope) {
|
public void testForeignKeyCreation(SessionFactoryScope scope) {
|
||||||
PersistentClass classMapping = scope.getMetadataImplementor().getEntityBinding( Account.class.getName() );
|
PersistentClass classMapping = scope.getMetadataImplementor().getEntityBinding( Account.class.getName() );
|
||||||
|
|
||||||
Iterator foreignKeyIterator = classMapping.getTable().getForeignKeyIterator();
|
Iterator foreignKeyIterator = classMapping.getTable().getForeignKeys().values().iterator();
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
while ( foreignKeyIterator.hasNext() ) {
|
while ( foreignKeyIterator.hasNext() ) {
|
||||||
ForeignKey element = (ForeignKey) foreignKeyIterator.next();
|
ForeignKey element = (ForeignKey) foreignKeyIterator.next();
|
||||||
|
|
|
@ -50,8 +50,8 @@ public class QuoteGlobalTest {
|
||||||
@Test
|
@Test
|
||||||
@TestForIssue(jiraKey = "HHH-7890")
|
@TestForIssue(jiraKey = "HHH-7890")
|
||||||
public void testQuotedUniqueConstraint(SessionFactoryScope scope) {
|
public void testQuotedUniqueConstraint(SessionFactoryScope scope) {
|
||||||
Iterator<UniqueKey> itr = scope.getMetadataImplementor().getEntityBinding( Person.class.getName() )
|
Iterator<UniqueKey> itr = scope.getMetadataImplementor().getEntityBinding(Person.class.getName())
|
||||||
.getTable().getUniqueKeyIterator();
|
.getTable().getUniqueKeys().values().iterator();
|
||||||
while ( itr.hasNext() ) {
|
while ( itr.hasNext() ) {
|
||||||
UniqueKey uk = itr.next();
|
UniqueKey uk = itr.next();
|
||||||
assertEquals( 1, uk.getColumns().size() );
|
assertEquals( 1, uk.getColumns().size() );
|
||||||
|
@ -106,7 +106,7 @@ public class QuoteGlobalTest {
|
||||||
private void doTestHbmQuoting(Class clazz, MetadataImplementor metadataImplementor) {
|
private void doTestHbmQuoting(Class clazz, MetadataImplementor metadataImplementor) {
|
||||||
Table table = metadataImplementor.getEntityBinding( clazz.getName() ).getTable();
|
Table table = metadataImplementor.getEntityBinding( clazz.getName() ).getTable();
|
||||||
assertTrue( table.isQuoted() );
|
assertTrue( table.isQuoted() );
|
||||||
Iterator itr = table.getColumnIterator();
|
Iterator itr = table.getColumns().iterator();
|
||||||
while ( itr.hasNext() ) {
|
while ( itr.hasNext() ) {
|
||||||
Column column = (Column) itr.next();
|
Column column = (Column) itr.next();
|
||||||
assertTrue( column.isQuoted() );
|
assertTrue( column.isQuoted() );
|
||||||
|
|
|
@ -28,7 +28,7 @@ public abstract class SchemaUtil {
|
||||||
Set<String> result = new HashSet<>();
|
Set<String> result = new HashSet<>();
|
||||||
for ( Table table : metadata.collectTableMappings() ) {
|
for ( Table table : metadata.collectTableMappings() ) {
|
||||||
if (tableName.equals( table.getName() ) ) {
|
if (tableName.equals( table.getName() ) ) {
|
||||||
Iterator<Column> columns = table.getColumnIterator();
|
Iterator<Column> columns = table.getColumns().iterator();
|
||||||
while ( columns.hasNext() ) {
|
while ( columns.hasNext() ) {
|
||||||
Column column = columns.next();
|
Column column = columns.next();
|
||||||
result.add( column.getName() );
|
result.add( column.getName() );
|
||||||
|
@ -42,7 +42,7 @@ public abstract class SchemaUtil {
|
||||||
public static boolean isColumnPresent(String tableName, String columnName, Metadata metadata) {
|
public static boolean isColumnPresent(String tableName, String columnName, Metadata metadata) {
|
||||||
for ( Table table : metadata.collectTableMappings() ) {
|
for ( Table table : metadata.collectTableMappings() ) {
|
||||||
if (tableName.equals( table.getName() ) ) {
|
if (tableName.equals( table.getName() ) ) {
|
||||||
Iterator<Column> columns = (Iterator<Column>) table.getColumnIterator();
|
Iterator<Column> columns = (Iterator<Column>) table.getColumns().iterator();
|
||||||
while ( columns.hasNext() ) {
|
while ( columns.hasNext() ) {
|
||||||
Column column = columns.next();
|
Column column = columns.next();
|
||||||
if ( columnName.equals( column.getName() ) ) {
|
if ( columnName.equals( column.getName() ) ) {
|
||||||
|
|
|
@ -54,16 +54,12 @@ public class ForeignKeyMetadata {
|
||||||
public boolean matches(ForeignKey fk) {
|
public boolean matches(ForeignKey fk) {
|
||||||
if ( refTable.equalsIgnoreCase( fk.getReferencedTable().getName() ) ) {
|
if ( refTable.equalsIgnoreCase( fk.getReferencedTable().getName() ) ) {
|
||||||
if ( fk.getColumnSpan() == references.size() ) {
|
if ( fk.getColumnSpan() == references.size() ) {
|
||||||
List fkRefs;
|
List<Column> fkRefs = fk.isReferenceToPrimaryKey()
|
||||||
if ( fk.isReferenceToPrimaryKey() ) {
|
? fk.getReferencedTable().getPrimaryKey().getColumns()
|
||||||
fkRefs = fk.getReferencedTable().getPrimaryKey().getColumns();
|
: fk.getReferencedColumns();
|
||||||
}
|
|
||||||
else {
|
|
||||||
fkRefs = fk.getReferencedColumns();
|
|
||||||
}
|
|
||||||
for ( int i = 0; i < fk.getColumnSpan(); i++ ) {
|
for ( int i = 0; i < fk.getColumnSpan(); i++ ) {
|
||||||
Column column = fk.getColumn( i );
|
Column column = fk.getColumn( i );
|
||||||
Column ref = ( Column ) fkRefs.get( i );
|
Column ref = fkRefs.get( i );
|
||||||
if ( !hasReference( column, ref ) ) {
|
if ( !hasReference( column, ref ) ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue