remove more usages of some deprecated methods

This commit is contained in:
Gavin King 2022-10-29 21:58:21 +02:00
parent 6e8d609485
commit bb0541d754
39 changed files with 263 additions and 273 deletions

View File

@ -596,16 +596,16 @@ public class TeradataDialect extends Dialect {
indexNameForCreation = index.getName();
}
StringBuilder columnList = new StringBuilder();
final StringBuilder columnList = new StringBuilder();
boolean first = true;
for (Iterator<Column> column = index.getColumnIterator(); column.hasNext(); ) {
for ( Column column : index.getColumns() ) {
if ( first ) {
first = false;
}
else {
columnList.append( ", " );
}
columnList.append( column.next().getName() );
columnList.append( column.getName() );
}
return new String[] {

View File

@ -10,7 +10,6 @@ import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.StringJoiner;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
@ -106,8 +105,8 @@ class SpannerDialectTableExporter implements Exporter<Table> {
ArrayList<String> dropStrings = new ArrayList<>();
for (Iterator<Index> index = table.getIndexIterator(); index.hasNext();) {
dropStrings.add( "drop index " + index.next().getName() );
for ( Index index : table.getIndexes().values() ) {
dropStrings.add( "drop index " + index.getName() );
}
dropStrings.add( this.spannerDialect.getDropTableString( context.format( table.getQualifiedTableName() ) ) );

View File

@ -6,13 +6,14 @@
*/
package org.hibernate.dialect.unique;
import java.util.Iterator;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.UniqueKey;
import static org.hibernate.mapping.Index.buildSqlCreateIndexString;
/**
* DB2 does not allow unique constraints on nullable columns. Rather than
* forcing "not null", use unique *indexes* instead.
@ -33,11 +34,11 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate {
public String getAlterTableToAddUniqueKeyCommand(UniqueKey uniqueKey, Metadata metadata,
SqlStringGenerationContext context) {
if ( hasNullable( uniqueKey ) ) {
return org.hibernate.mapping.Index.buildSqlCreateIndexString(
return buildSqlCreateIndexString(
context,
uniqueKey.getName(),
uniqueKey.getTable(),
uniqueKey.getColumnIterator(),
uniqueKey.getColumns(),
uniqueKey.getColumnOrderMap(),
true,
metadata
@ -63,9 +64,8 @@ public class DB2UniqueDelegate extends DefaultUniqueDelegate {
}
private boolean hasNullable(UniqueKey uniqueKey) {
final Iterator<org.hibernate.mapping.Column> iter = uniqueKey.getColumnIterator();
while ( iter.hasNext() ) {
if ( iter.next().isNullable() ) {
for ( Column column : uniqueKey.getColumns() ) {
if ( column.isNullable() ) {
return true;
}
}

View File

@ -6,8 +6,6 @@
*/
package org.hibernate.dialect.unique;
import java.util.Iterator;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
@ -60,18 +58,19 @@ public class DefaultUniqueDelegate implements UniqueDelegate {
protected String uniqueConstraintSql(UniqueKey uniqueKey) {
final StringBuilder sb = new StringBuilder();
sb.append( "unique (" );
final Iterator<org.hibernate.mapping.Column> columnIterator = uniqueKey.getColumnIterator();
while ( columnIterator.hasNext() ) {
final org.hibernate.mapping.Column column = columnIterator.next();
boolean first = true;
for ( org.hibernate.mapping.Column column : uniqueKey.getColumns() ) {
if ( first ) {
first = false;
}
else {
sb.append(", ");
}
sb.append( column.getQuotedName( dialect ) );
if ( uniqueKey.getColumnOrderMap().containsKey( column ) ) {
sb.append( " " ).append( uniqueKey.getColumnOrderMap().get( column ) );
}
if ( columnIterator.hasNext() ) {
sb.append( ", " );
}
}
return sb.append( ')' ).toString();
}

View File

@ -13,18 +13,21 @@ import org.hibernate.mapping.Table;
import org.hibernate.mapping.UniqueKey;
/**
* Dialect-level delegate in charge of applying "uniqueness" to a column. Uniqueness can be defined
* in 1 of 3 ways:<ol>
* Dialect-level delegate in charge of applying "uniqueness" to a column. Uniqueness can
* be defined in 1 of 3 ways:
* <ol>
* <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}
* </li>
* <li>
* Add a unique constraint via dialect-specific syntax in table create statement. See
* {@link #getTableCreationUniqueConstraintsFragment}
* Add a unique constraint via dialect-specific syntax in table create statement.
* See {@link #getTableCreationUniqueConstraintsFragment}
* </li>
* <li>
* Add "unique" syntax to the column itself. See {@link #getColumnDefinitionUniquenessFragment}
* Add "unique" syntax to the column itself.
* See {@link #getColumnDefinitionUniquenessFragment}
* </li>
* </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.
* <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 context A context for SQL string generation
* @return The fragment (usually "unique"), empty string indicates the uniqueness will be indicated using a
* different approach
* @return The fragment (usually "unique"), empty string indicates the uniqueness will be
* indicated using a different approach
*/
String getColumnDefinitionUniquenessFragment(Column column, SqlStringGenerationContext context);
/**
* Get the fragment that can be used to apply unique constraints as part of table creation. The
* implementation should iterate over the {@link UniqueKey} instances for the given table (see
* {@link org.hibernate.mapping.Table#getUniqueKeyIterator()} and generate the whole fragment for
* all unique keys
* Get the fragment that can be used to apply unique constraints as part of table creation.
* The implementation should iterate over the {@link UniqueKey} instances for the given table
* (see {@link org.hibernate.mapping.Table#getUniqueKeys()} and generate the whole fragment
* for all unique keys.
* <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 context A context for SQL string generation
* @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}. NOTE: The leading
* comma is important!
* @return The fragment, typically in the form {@code ", unique(col1, col2), unique( col20)"}.
* NOTE: The leading comma is important!
*/
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 context A context for SQL string generation
* @return The ALTER TABLE command
@ -73,9 +77,9 @@ public interface UniqueDelegate {
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 context A context for SQL string generation
* @return The ALTER TABLE command

View File

@ -22,7 +22,8 @@ import org.hibernate.boot.model.relational.Exportable;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
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.
@ -177,7 +178,7 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
@Override
public String sqlDropString(SqlStringGenerationContext context,
String defaultCatalog, String defaultSchema) {
Dialect dialect = context.getDialect();
final Dialect dialect = context.getDialect();
if ( isGenerated( dialect ) ) {
final String tableName = getTable().getQualifiedName( context );
return String.format(
@ -195,13 +196,13 @@ public abstract class Constraint implements RelationalModel, Exportable, Seriali
@Override
public String sqlCreateString(Mapping p, SqlStringGenerationContext context, String defaultCatalog,
String defaultSchema) {
Dialect dialect = context.getDialect();
final Dialect dialect = context.getDialect();
if ( isGenerated( dialect ) ) {
// 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
// empty string. Prevent blank "alter table" statements.
String constraintString = sqlConstraintString( context, getName(), defaultCatalog, defaultSchema );
if ( !StringHelper.isEmpty( constraintString ) ) {
if ( !isEmpty( constraintString ) ) {
final String tableName = getTable().getQualifiedName( context );
return dialect.getAlterTableString( tableName ) + " " + constraintString;
}

View File

@ -124,14 +124,12 @@ public class DenormalizedTable extends Table {
@Override
public Iterator<Index> getIndexIterator() {
List<Index> indexes = new ArrayList<>();
Iterator<Index> iter = includedTable.getIndexIterator();
while ( iter.hasNext() ) {
Index parentIndex = iter.next();
final List<Index> indexes = new ArrayList<>();
for ( Index parentIndex : includedTable.getIndexes().values() ) {
Index index = new Index();
index.setName( getName() + parentIndex.getName() );
index.setTable( this );
index.addColumns( parentIndex.getColumnIterator() );
index.addColumns( parentIndex.getColumns() );
indexes.add( index );
}
return new JoinedIterator<>(

View File

@ -127,26 +127,25 @@ public class ForeignKey extends Constraint {
}
private void alignColumns(Table referencedTable) {
final int referencedPkColumnSpan = referencedTable.getPrimaryKey().getColumnSpan();
if ( referencedPkColumnSpan != getColumnSpan() ) {
final int columnSpan = getColumnSpan();
final PrimaryKey primaryKey = referencedTable.getPrimaryKey();
if ( primaryKey.getColumnSpan() != columnSpan ) {
StringBuilder sb = new StringBuilder();
sb.append( "Foreign key (" ).append( getName() ).append( ":" )
.append( getTable().getName() )
.append( " [" );
appendColumns( sb, getColumnIterator() );
appendColumns( sb, getColumns().iterator() );
sb.append( "])" )
.append( ") must have same number of columns as the referenced primary key (" )
.append( referencedTable.getName() )
.append( " [" );
appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() );
appendColumns( sb, primaryKey.getColumns().iterator() );
sb.append( "])" );
throw new MappingException( sb.toString() );
}
Iterator<Column> fkCols = getColumnIterator();
Iterator<Column> pkCols = referencedTable.getPrimaryKey().getColumnIterator();
while ( pkCols.hasNext() ) {
fkCols.next().setLength( pkCols.next().getLength() );
for (int i = 0; i<columnSpan; i++ ) {
getColumn(i).setLength( primaryKey.getColumn(i).getLength() );
}
}

View File

@ -8,7 +8,6 @@ package org.hibernate.mapping;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
@ -21,6 +20,11 @@ import org.hibernate.dialect.Dialect;
import org.hibernate.engine.spi.Mapping;
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
*
@ -41,7 +45,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
context,
getQuotedName( dialect ),
getTable(),
getColumnIterator(),
columns,
columnOrderMap,
false,
defaultCatalog,
@ -61,14 +65,14 @@ public class Index implements RelationalModel, Exportable, Serializable {
public static String buildSqlDropIndexString(
String name,
String tableName) {
return "drop index " + StringHelper.qualify( tableName, name );
return "drop index " + qualify( tableName, name );
}
public static String buildSqlCreateIndexString(
SqlStringGenerationContext context,
String name,
Table table,
Iterator<Column> columns,
java.util.List<Column> columns,
java.util.Map<Column, String> columnOrderMap,
boolean unique,
String defaultCatalog,
@ -87,7 +91,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
Dialect dialect,
String name,
String tableName,
Iterator<Column> columns,
java.util.List<Column> columns,
java.util.Map<Column, String> columnOrderMap,
boolean unique) {
StringBuilder buf = new StringBuilder( "create" )
@ -97,15 +101,18 @@ public class Index implements RelationalModel, Exportable, Serializable {
.append( " on " )
.append( tableName )
.append( " (" );
while ( columns.hasNext() ) {
Column column = columns.next();
boolean first = true;
for ( Column column : columns ) {
if ( first ) {
first = false;
}
else {
buf.append(", ");
}
buf.append( column.getQuotedName( dialect ) );
if ( columnOrderMap.containsKey( column ) ) {
buf.append( " " ).append( columnOrderMap.get( column ) );
}
if ( columns.hasNext() ) {
buf.append( ", " );
}
}
buf.append( ")" );
return buf.toString();
@ -115,7 +122,7 @@ public class Index implements RelationalModel, Exportable, Serializable {
SqlStringGenerationContext context,
String name,
Table table,
Iterator<Column> columns,
java.util.List<Column> columns,
java.util.Map<Column, String> columnOrderMap,
boolean unique,
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)
public String sqlConstraintString(Dialect dialect) {
StringBuilder buf = new StringBuilder( " index (" );
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
buf.append( ( (Column) iter.next() ).getQuotedName( dialect ) );
if ( iter.hasNext() ) {
buf.append( ", " );
boolean first = true;
for ( Column column : getColumns() ) {
if ( first ) {
first = false;
}
else {
buf.append(", ");
}
buf.append( column.getQuotedName( dialect ) );
}
return buf.append( ')' ).toString();
}
@Override
public String sqlDropString(SqlStringGenerationContext context,
String defaultCatalog, String defaultSchema) {
Dialect dialect = context.getDialect();
return "drop index " +
StringHelper.qualify(
table.getQualifiedName( context ),
getQuotedName( dialect )
);
public String sqlDropString(SqlStringGenerationContext context, String defaultCatalog, String defaultSchema) {
return "drop index " + qualify( table.getQualifiedName( context ), getQuotedName( context.getDialect() ) );
}
public Table getTable() {
@ -168,12 +172,17 @@ public class Index implements RelationalModel, Exportable, Serializable {
return columns.size();
}
@Deprecated
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() {
return Collections.unmodifiableMap( columnOrderMap );
return unmodifiableMap( columnOrderMap );
}
public void addColumn(Column column) {
@ -184,14 +193,14 @@ public class Index implements RelationalModel, Exportable, Serializable {
public void addColumn(Column column, String order) {
addColumn( column );
if ( StringHelper.isNotEmpty( order ) ) {
if ( isNotEmpty( order ) ) {
columnOrderMap.put( column, order );
}
}
public void addColumns(Iterator extraColumns) {
while ( extraColumns.hasNext() ) {
addColumn( (Column) extraColumns.next() );
public void addColumns(java.util.List<Column> extraColumns) {
for ( Column column : extraColumns ) {
addColumn( column );
}
}
@ -218,6 +227,6 @@ public class Index implements RelationalModel, Exportable, Serializable {
@Override
public String getExportIdentifier() {
return StringHelper.qualify( getTable().getExportIdentifier(), "IDX-" + getName() );
return qualify( getTable().getExportIdentifier(), "IDX-" + getName() );
}
}

View File

@ -5,7 +5,6 @@
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.mapping;
import java.util.Iterator;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
@ -60,12 +59,15 @@ public class PrimaryKey extends Constraint {
public String sqlConstraintString(Dialect dialect) {
StringBuilder buf = new StringBuilder("primary key (");
Iterator<Column> iter = getColumnIterator();
while ( iter.hasNext() ) {
buf.append( iter.next().getQuotedName(dialect) );
if ( iter.hasNext() ) {
boolean first = true;
for ( Column column : getColumns() ) {
if ( first ) {
first = false;
}
else {
buf.append(", ");
}
buf.append( column.getQuotedName( dialect ) );
}
return buf.append(')').toString();
}
@ -73,15 +75,17 @@ public class PrimaryKey extends Constraint {
@Override
public String sqlConstraintString(SqlStringGenerationContext context, String constraintName, String defaultCatalog, String defaultSchema) {
Dialect dialect = context.getDialect();
StringBuilder buf = new StringBuilder(
dialect.getAddPrimaryKeyConstraintString(constraintName)
).append('(');
Iterator iter = getColumnIterator();
while ( iter.hasNext() ) {
buf.append( ( (Column) iter.next() ).getQuotedName(dialect) );
if ( iter.hasNext() ) {
StringBuilder buf = new StringBuilder();
buf.append( dialect.getAddPrimaryKeyConstraintString( constraintName ) ).append('(');
boolean first = true;
for ( Column column : getColumns() ) {
if ( first ) {
first = false;
}
else {
buf.append(", ");
}
buf.append( column.getQuotedName( dialect ) );
}
return buf.append(')').toString();
}

View File

@ -225,7 +225,9 @@ public class Table implements RelationalModel, Serializable, ContributableDataba
* Return the column which is identified by column provided as argument.
*
* @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) {
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
// 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.
if ( uniqueKeys.isEmpty() ) {
// nothing to do
return;
}
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 ( !uniqueKeys.isEmpty() ) {
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() ) ) {
removeIt = true;
}
if ( removeIt ) {
//uniqueKeys.remove( uniqueKeyEntry.getKey() );
uniqueKeyEntries.remove();
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() ) ) {
removeIt = true;
}
if ( removeIt ) {
//uniqueKeys.remove( uniqueKeyEntry.getKey() );
uniqueKeyEntries.remove();
}
}
}
}
}

View File

@ -57,6 +57,9 @@ import org.hibernate.type.descriptor.java.JavaType;
import org.hibernate.type.descriptor.java.spi.JavaTypeRegistry;
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
*/
@ -310,18 +313,18 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
for ( Property property : bootType.getPropertyClosure() ) {
//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;
}
getterNames.add(propertyAccess.getGetter().getMethodName());
getterTypes.add(propertyAccess.getGetter().getReturnTypeClass());
getterNames.add( propertyAccess.getGetter().getMethodName() );
getterTypes.add( propertyAccess.getGetter().getReturnTypeClass() );
setterNames.add(propertyAccess.getSetter().getMethodName());
setterNames.add( propertyAccess.getSetter().getMethodName() );
}
if ( foundCustomAccessor || ! Environment.useReflectionOptimizer() ) {
@ -330,9 +333,9 @@ public class EntityRepresentationStrategyPojoStandard implements EntityRepresent
return bytecodeProvider.getReflectionOptimizer(
javaTypeToReflect,
getterNames.toArray( new String[0] ),
setterNames.toArray( new String[0] ),
getterTypes.toArray( new Class[0] )
getterNames.toArray( EMPTY_STRING_ARRAY ),
setterNames.toArray( EMPTY_STRING_ARRAY ),
getterTypes.toArray( EMPTY_CLASS_ARRAY )
);
}

View File

@ -347,9 +347,7 @@ public abstract class AbstractSchemaMigrator implements SchemaMigrator {
GenerationTarget... targets) {
final Exporter<Index> exporter = dialect.getIndexExporter();
final Iterator<Index> indexItr = table.getIndexIterator();
while ( indexItr.hasNext() ) {
final Index index = indexItr.next();
for ( Index index : table.getIndexes().values() ) {
if ( !StringHelper.isEmpty( index.getName() ) ) {
IndexInformation existingIndex = null;
if ( tableInformation != null ) {

View File

@ -10,7 +10,6 @@ import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -382,9 +381,7 @@ public class SchemaCreatorImpl implements SchemaCreator {
}
// indexes
final Iterator<Index> indexItr = table.getIndexIterator();
while ( indexItr.hasNext() ) {
final Index index = indexItr.next();
for ( Index index : table.getIndexes().values() ) {
checkExportIdentifier( index, exportIdentifiers );
applySqlStrings(
dialect.getIndexExporter().getSqlCreateStrings( index, metadata,

View File

@ -6,14 +6,13 @@
*/
package org.hibernate.tool.schema.internal;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import org.hibernate.AssertionFailure;
import org.hibernate.boot.Metadata;
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
import org.hibernate.dialect.Dialect;
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.ForeignKey;
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[] targetColumnNames = new String[numberOfColumns];
final Iterator targetItr;
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()
)
);
}
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 );
final List<Column> targetColumns = getTargetColumns( foreignKey, numberOfColumns );
final List<Column> columns = foreignKey.getColumns();
for ( int i=0; i<columns.size() && i<targetColumns.size(); i++ ) {
columnNames[i] = columns.get(i).getQuotedName( dialect );
targetColumnNames[i] = targetColumns.get(i).getQuotedName( dialect );
i++;
}
@ -119,6 +84,41 @@ public class StandardForeignKeyExporter implements Exporter<ForeignKey> {
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
public String[] getSqlDropStrings(ForeignKey foreignKey, Metadata metadata, SqlStringGenerationContext context) {
if ( !dialect.hasAlterTable() ) {
@ -134,9 +134,7 @@ public class StandardForeignKeyExporter implements Exporter<ForeignKey> {
}
final String sourceTableName = context.format( foreignKey.getTable().getQualifiedTableName() );
return new String[] {
getSqlDropStrings( sourceTableName, foreignKey, dialect )
};
return new String[] { getSqlDropStrings( sourceTableName, foreignKey, dialect ) };
}
private String getSqlDropStrings(String tableName, ForeignKey foreignKey, Dialect dialect) {

View File

@ -6,7 +6,6 @@
*/
package org.hibernate.tool.schema.internal;
import java.util.Iterator;
import java.util.Map;
import org.hibernate.boot.Metadata;
@ -60,10 +59,8 @@ public class StandardIndexExporter implements Exporter<Index> {
.append( " (" );
boolean first = true;
final Iterator<Column> columnItr = index.getColumnIterator();
final Map<Column, String> columnOrderMap = index.getColumnOrderMap();
while ( columnItr.hasNext() ) {
final Column column = columnItr.next();
for ( Column column : index.getColumns() ) {
if ( first ) {
first = false;
}
@ -87,13 +84,9 @@ public class StandardIndexExporter implements Exporter<Index> {
final String tableName = context.format( index.getTable().getQualifiedTableName() );
final String indexNameForCreation;
if ( dialect.qualifyIndexName() ) {
indexNameForCreation = StringHelper.qualify( tableName, index.getName() );
}
else {
indexNameForCreation = index.getName();
}
final String indexNameForCreation = dialect.qualifyIndexName()
? StringHelper.qualify( tableName, index.getName() )
: index.getName();
return new String[] { "drop index " + indexNameForCreation };
}

View File

@ -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
String pkColName = null;
if ( table.hasPrimaryKey() ) {
Column pkColumn = table.getPrimaryKey().getColumns().iterator().next();
pkColName = pkColumn.getQuotedName( dialect );
pkColName = table.getPrimaryKey().getColumns().get(0).getQuotedName( dialect );
}
boolean isFirst = true;
@ -166,7 +165,7 @@ public class StandardTableExporter implements Exporter<Table> {
applyComments( table, formattedTableName, sqlStrings );
applyInitCommands( table, sqlStrings, context );
applyInitCommands( table, sqlStrings, context );
return sqlStrings.toArray(StringHelper.EMPTY_STRINGS);
}

View File

@ -289,7 +289,7 @@ public class DefaultNamingCollectionElementTest {
String propertyName,
String columnName) {
final Collection collection = metadataImplementor.getCollectionBinding( collectionOwner + "." + propertyName );
final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
final Iterator columnIterator = collection.getCollectionTable().getColumns().iterator();
boolean hasDefault = false;
while ( columnIterator.hasNext() ) {
Column column = (Column) columnIterator.next();
@ -409,7 +409,7 @@ public class DefaultNamingCollectionElementTest {
assertEquals( ownerForeignKeyNameExpected, ownerCollection.getKey().getColumnIterator().next().getText() );
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();
assertSame( ownerCollection.getCollectionTable(), fk.getTable() );
if ( fk.getColumnSpan() > 1 ) {

View File

@ -47,7 +47,7 @@ public class CommentTest {
.flatMap(namespace -> namespace.getTables().stream()).filter(t -> t.getName().equals(TABLE_NAME))
.findFirst().orElse(null);
assertThat(table.getComment(), is(TABLE_COMMENT));
Iterator<Column> it = table.getColumnIterator();
Iterator<Column> it = table.getColumns().iterator();
while (it.hasNext()) {
Column col = it.next();
assertThat(col.getComment(), is("I am " + col.getName()));

View File

@ -51,7 +51,7 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
@Test
public void testTableIndex() {
PersistentClass entity = metadata().getEntityBinding( Car.class.getName() );
Iterator itr = entity.getTable().getUniqueKeyIterator();
Iterator itr = entity.getTable().getUniqueKeys().values().iterator();
assertTrue( itr.hasNext() );
UniqueKey uk = (UniqueKey) itr.next();
assertFalse( itr.hasNext() );
@ -64,13 +64,13 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
assertSame( entity.getTable(), uk.getTable() );
itr = entity.getTable().getIndexIterator();
itr = entity.getTable().getIndexes().values().iterator();
assertTrue( itr.hasNext() );
Index index = (Index)itr.next();
assertFalse( itr.hasNext() );
assertEquals( "Car_idx", index.getName() );
assertEquals( 1, index.getColumnSpan() );
column = index.getColumnIterator().next();
column = index.getColumns().iterator().next();
assertEquals( "since", column.getName() );
assertSame( entity.getTable(), index.getTable() );
}
@ -80,13 +80,13 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
PersistentClass entity = metadata().getEntityBinding( Car.class.getName() );
Join join = (Join)entity.getJoinIterator().next();
Iterator<Index> itr = join.getTable().getIndexIterator();
Iterator<Index> itr = join.getTable().getIndexes().values().iterator();
assertTrue( itr.hasNext() );
Index index = itr.next();
assertFalse( itr.hasNext() );
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
assertEquals( 2, index.getColumnSpan() );
Iterator<Column> columnIterator = index.getColumnIterator();
Iterator<Column> columnIterator = index.getColumns().iterator();
Column column = columnIterator.next();
assertEquals( "dealer_name", column.getName() );
column = columnIterator.next();
@ -102,13 +102,13 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
Set set = (Set)property.getValue();
Table collectionTable = set.getCollectionTable();
Iterator<Index> itr = collectionTable.getIndexIterator();
Iterator<Index> itr = collectionTable.getIndexes().values().iterator();
assertTrue( itr.hasNext() );
Index index = itr.next();
assertFalse( itr.hasNext() );
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
assertEquals( 1, index.getColumnSpan() );
Iterator<Column> columnIterator = index.getColumnIterator();
Iterator<Column> columnIterator = index.getColumns().iterator();
Column column = columnIterator.next();
assertEquals( "name", column.getName() );
assertSame( collectionTable, index.getTable() );
@ -122,13 +122,13 @@ public abstract class AbstractJPAIndexTest extends BaseNonConfigCoreFunctionalTe
Bag set = (Bag)property.getValue();
Table collectionTable = set.getCollectionTable();
Iterator<Index> itr = collectionTable.getIndexIterator();
Iterator<Index> itr = collectionTable.getIndexes().values().iterator();
assertTrue( itr.hasNext() );
Index index = itr.next();
assertFalse( itr.hasNext() );
assertTrue( "index name is not generated", StringHelper.isNotEmpty( index.getName() ) );
assertEquals( 1, index.getColumnSpan() );
Iterator<Column> columnIterator = index.getColumnIterator();
Iterator<Column> columnIterator = index.getColumns().iterator();
Column column = columnIterator.next();
assertEquals( "importers_id", column.getName() );
assertSame( collectionTable, index.getTable() );

View File

@ -88,7 +88,7 @@ public class IndexedCollectionTest {
private boolean isDefaultColumnPresent(SessionFactoryScope scope, String collectionOwner, String propertyName, String suffix) {
final Collection collection = scope.getMetadataImplementor().getCollectionBinding( collectionOwner + "." + propertyName );
final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
final Iterator columnIterator = collection.getCollectionTable().getColumns().iterator();
boolean hasDefault = false;
while ( columnIterator.hasNext() ) {
Column column = (Column) columnIterator.next();

View File

@ -43,7 +43,7 @@ public class EagerIndexedCollectionTest extends BaseNonConfigCoreFunctionalTestC
private boolean isDefaultColumnPresent(String collectionOwner, String propertyName, String suffix) {
final Collection collection = metadata().getCollectionBinding( collectionOwner + "." + propertyName );
final Iterator columnIterator = collection.getCollectionTable().getColumnIterator();
final Iterator columnIterator = collection.getCollectionTable().getColumns().iterator();
boolean hasDefault = false;
while ( columnIterator.hasNext() ) {
Column column = (Column) columnIterator.next();

View File

@ -202,7 +202,7 @@ public class ManyToManyImplicitNamingTest extends BaseNonConfigCoreFunctionalTes
}
boolean hasOwnerFK = 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();
assertSame( ownerCollection.getCollectionTable(), fk.getTable() );
if ( fk.getColumnSpan() > 1 ) {

View File

@ -63,13 +63,13 @@ public class LongKeyNamingStrategyTest extends BaseUnitTestCase {
.build();
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() );
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() );
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() );
}

View File

@ -8,7 +8,6 @@
// $Id$
package org.hibernate.orm.test.annotations.namingstrategy.charset;
import java.util.HashMap;
import java.util.Map;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
@ -67,14 +66,14 @@ public abstract class AbstractCharsetNamingStrategyTest extends BaseUnitTestCase
.applyImplicitNamingStrategy( new LongIdentifierNamingStrategy() )
.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() );
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() );
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() );
}

View File

@ -530,7 +530,7 @@ public class OneToManyTest extends BaseNonConfigCoreFunctionalTestCase {
public void testJoinColumnConfiguredInXml() {
PersistentClass pc = metadata().getEntityBinding( Model.class.getName() );
Table table = pc.getRootTable();
Iterator iter = table.getColumnIterator();
Iterator iter = table.getColumns().iterator();
boolean joinColumnFound = false;
while(iter.hasNext()) {
Column column = (Column) iter.next();

View File

@ -305,7 +305,7 @@ public class OneToOneTest extends BaseNonConfigCoreFunctionalTestCase {
PersistentClass pc = metadata().getEntityBinding( Son.class.getName() );
Iterator<Join> iter = pc.getJoinIterator();
Table table = iter.next().getTable();
Iterator<Column> columnIter = table.getColumnIterator();
Iterator<Column> columnIter = table.getColumns().iterator();
boolean fooFound = false;
boolean barFound = false;
while ( columnIter.hasNext() ) {

View File

@ -61,9 +61,9 @@ public class UniqueConstraintUnitTests extends BaseUnitTestCase {
}
assertTrue( "Could not find the expected tables.", tableA != null && tableB != null );
assertFalse(
tableA.getUniqueKeyIterator().next().getName().equals(
tableB.getUniqueKeyIterator().next().getName()
assertFalse(
tableA.getUniqueKeys().values().iterator().next().getName().equals(
tableB.getUniqueKeys().values().iterator().next().getName()
)
);
}

View File

@ -71,7 +71,7 @@ public class ConstraintTest extends BaseNonConfigCoreFunctionalTestCase {
int foundCount = 0;
for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) {
for ( org.hibernate.mapping.Table table : namespace.getTables() ) {
Iterator fkItr = table.getForeignKeyIterator();
Iterator fkItr = table.getForeignKeys().values().iterator();
while (fkItr.hasNext()) {
ForeignKey fk = (ForeignKey) fkItr.next();
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()) {
UniqueKey uk = (UniqueKey) ukItr.next();
assertTrue( uk.getName().length() <= MAX_NAME_LENGTH );

View File

@ -90,7 +90,7 @@ public class ForeignKeyConstraintMapsIdTest extends BaseNonConfigCoreFunctionalT
for ( Namespace namespace : metadata().getDatabase().getNamespaces() ) {
for ( Table table : namespace.getTables() ) {
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() ) {
org.hibernate.mapping.ForeignKey foreignKey = foreignKeyIterator.next();
if ( foreignKey.getColumn( 0 ).getName().equals( "PD_ID" ) ) {

View File

@ -180,7 +180,7 @@ public class ForeignKeyConstraintTest {
Set<String> columnSet = new LinkedHashSet<>( Arrays.asList( columns ) );
for ( Namespace namespace : scope.getDomainModel().getDatabase().getNamespaces() ) {
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() ) {
org.hibernate.mapping.ForeignKey fk = fkItr.next();
@ -202,7 +202,7 @@ public class ForeignKeyConstraintTest {
private void assertNoForeignKey(DomainModelScope scope, String foreignKeyName, String... columns) {
for ( Namespace namespace : scope.getDomainModel().getDatabase().getNamespaces() ) {
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() ) {
org.hibernate.mapping.ForeignKey fk = fkItr.next();
assertFalse(

View File

@ -6,9 +6,8 @@
*/
package org.hibernate.orm.test.constraint;
import java.util.Iterator;
import java.util.List;
import jakarta.persistence.CollectionTable;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.Inheritance;
@ -21,18 +20,14 @@ import jakarta.persistence.OneToMany;
import jakarta.persistence.PrimaryKeyJoinColumn;
import jakarta.persistence.Table;
import org.hibernate.mapping.Column;
import org.hibernate.mapping.ForeignKey;
import org.hibernate.mapping.JoinedSubclass;
import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.PrimaryKey;
import org.hibernate.mapping.Property;
import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Subclass;
import org.hibernate.mapping.ToOne;
import org.hibernate.metamodel.mapping.AttributeMapping;
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.ToOneAttributeMapping;
@ -102,7 +97,7 @@ public class NonRootTablePolymorphicTests {
// 2) for the sub->child fk
assertThat( subclassTable.getForeignKeys().size(), is( 2 ) );
subclassTable.getForeignKeyIterator().forEachRemaining(
subclassTable.getForeignKeys().values().iterator().forEachRemaining(
(foreignKey) -> {
assertThat( foreignKey.getTable(), sameInstance( subclassTable ) );
@ -167,7 +162,7 @@ public class NonRootTablePolymorphicTests {
assertThat( selectable.getText(), is( "parent_sub_fk" ) );
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.getTable(), sameInstance( toOne.getTable() ) );

View File

@ -76,7 +76,7 @@ public class ABCTest {
.getDatabase()
.getDefaultNamespace()
.locateTable( Identifier.toIdentifier( "TA" ) );
Iterator<Index> indexItr = table.getIndexIterator();
Iterator<Index> indexItr = table.getIndexes().values().iterator();
boolean found = false;
while ( indexItr.hasNext() ) {
final Index index = indexItr.next();

View File

@ -93,7 +93,7 @@ public class FullyQualifiedEntityNameNamingStrategyTest {
boolean ownerFKFound = 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();
if ( expectedOwnerFK.equals( fkColumnName ) ) {
ownerFKFound = true;

View File

@ -35,7 +35,7 @@ public class OneToOneSchemaTest {
Table childTable = metadata.getDatabase().getDefaultNamespace().locateTable( Identifier.toIdentifier(
"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 {
StandardServiceRegistryBuilder.destroy( ssr );

View File

@ -269,7 +269,7 @@ public class PropertyRefTest {
public void testForeignKeyCreation(SessionFactoryScope scope) {
PersistentClass classMapping = scope.getMetadataImplementor().getEntityBinding( Account.class.getName() );
Iterator foreignKeyIterator = classMapping.getTable().getForeignKeyIterator();
Iterator foreignKeyIterator = classMapping.getTable().getForeignKeys().values().iterator();
boolean found = false;
while ( foreignKeyIterator.hasNext() ) {
ForeignKey element = (ForeignKey) foreignKeyIterator.next();

View File

@ -50,8 +50,8 @@ public class QuoteGlobalTest {
@Test
@TestForIssue(jiraKey = "HHH-7890")
public void testQuotedUniqueConstraint(SessionFactoryScope scope) {
Iterator<UniqueKey> itr = scope.getMetadataImplementor().getEntityBinding( Person.class.getName() )
.getTable().getUniqueKeyIterator();
Iterator<UniqueKey> itr = scope.getMetadataImplementor().getEntityBinding(Person.class.getName())
.getTable().getUniqueKeys().values().iterator();
while ( itr.hasNext() ) {
UniqueKey uk = itr.next();
assertEquals( 1, uk.getColumns().size() );
@ -106,7 +106,7 @@ public class QuoteGlobalTest {
private void doTestHbmQuoting(Class clazz, MetadataImplementor metadataImplementor) {
Table table = metadataImplementor.getEntityBinding( clazz.getName() ).getTable();
assertTrue( table.isQuoted() );
Iterator itr = table.getColumnIterator();
Iterator itr = table.getColumns().iterator();
while ( itr.hasNext() ) {
Column column = (Column) itr.next();
assertTrue( column.isQuoted() );

View File

@ -28,7 +28,7 @@ public abstract class SchemaUtil {
Set<String> result = new HashSet<>();
for ( Table table : metadata.collectTableMappings() ) {
if (tableName.equals( table.getName() ) ) {
Iterator<Column> columns = table.getColumnIterator();
Iterator<Column> columns = table.getColumns().iterator();
while ( columns.hasNext() ) {
Column column = columns.next();
result.add( column.getName() );
@ -42,7 +42,7 @@ public abstract class SchemaUtil {
public static boolean isColumnPresent(String tableName, String columnName, Metadata metadata) {
for ( Table table : metadata.collectTableMappings() ) {
if (tableName.equals( table.getName() ) ) {
Iterator<Column> columns = (Iterator<Column>) table.getColumnIterator();
Iterator<Column> columns = (Iterator<Column>) table.getColumns().iterator();
while ( columns.hasNext() ) {
Column column = columns.next();
if ( columnName.equals( column.getName() ) ) {

View File

@ -54,16 +54,12 @@ public class ForeignKeyMetadata {
public boolean matches(ForeignKey fk) {
if ( refTable.equalsIgnoreCase( fk.getReferencedTable().getName() ) ) {
if ( fk.getColumnSpan() == references.size() ) {
List fkRefs;
if ( fk.isReferenceToPrimaryKey() ) {
fkRefs = fk.getReferencedTable().getPrimaryKey().getColumns();
}
else {
fkRefs = fk.getReferencedColumns();
}
List<Column> fkRefs = fk.isReferenceToPrimaryKey()
? fk.getReferencedTable().getPrimaryKey().getColumns()
: fk.getReferencedColumns();
for ( int i = 0; i < fk.getColumnSpan(); i++ ) {
Column column = fk.getColumn( i );
Column ref = ( Column ) fkRefs.get( i );
Column ref = fkRefs.get( i );
if ( !hasReference( column, ref ) ) {
return false;
}