diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Constraint.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Constraint.java
index 6f13abc170..8b71dc693e 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Constraint.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/Constraint.java
@@ -23,6 +23,8 @@
*/
package org.hibernate.metamodel.spi.relational;
+import java.util.List;
+
/**
* Basic contract for the types of constraints we fully support as metadata constructs:
* - primary key
@@ -48,9 +50,9 @@ public interface Constraint extends Exportable {
public String getName();
/**
- * Obtain the columns that are part of this constraint.
+ * Obtain a read-only view of the columns that are part of this constraint.
*
- * @return The constrained columns.
+ * @return A read-only view of the constrained columns.
*/
- public Iterable getColumns();
+ public List getColumns();
}
diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/ForeignKey.java b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/ForeignKey.java
index beb165a8ef..e6e4719367 100644
--- a/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/ForeignKey.java
+++ b/hibernate-core/src/main/java/org/hibernate/metamodel/spi/relational/ForeignKey.java
@@ -72,11 +72,11 @@ public class ForeignKey extends AbstractConstraint implements Constraint, Export
return targetTable;
}
- public Iterable getSourceColumns() {
+ public List getSourceColumns() {
return getColumns();
}
- public Iterable getTargetColumns() {
+ public List getTargetColumns() {
return targetColumns == null
? getTargetTable().getPrimaryKey().getColumns()
: Collections.unmodifiableList( targetColumns );
diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/UniqueConstraintBindingTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/UniqueConstraintBindingTest.java
index 5e92fb4047..3605b20d97 100644
--- a/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/UniqueConstraintBindingTest.java
+++ b/hibernate-core/src/test/java/org/hibernate/metamodel/internal/source/annotations/entity/UniqueConstraintBindingTest.java
@@ -59,11 +59,8 @@ public class UniqueConstraintBindingTest extends BaseAnnotationBindingTestCase {
assertEquals( "u1", key.getName() );
assertTrue( table == key.getTable() );
assertNotNull( key.getColumns() );
- int j = 0;
- for ( Column column : key.getColumns() ) {
- j++;
- }
- assertEquals( "There should be two columns in the unique constraint", 2, j );
+ assertEquals( "There should be two columns in the unique constraint", 2, key.getColumns().size() );
+ assertEquals( "There should be two columns in the unique constraint", 2, key.getColumnSpan() );
}
assertEquals( "There should only be one unique constraint", 1, i );
}
diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java
index a9ec2741c8..9ff209c62b 100644
--- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java
+++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/AbstractBasicBindingTests.java
@@ -153,10 +153,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
assertEquals( 1, SingularAttributeBinding.class.cast( referencedAttributeBinding ).getRelationalValueBindings().size() );
final Value referencedValue =
SingularAttributeBinding.class.cast( referencedAttributeBinding )
- .getRelationalValueBindings()
- .iterator()
- .next()
- .getValue();
+ .getRelationalValueBindings().get( 0 ).getValue();
assertTrue( Column.class.isInstance( referencedValue ) );
final JdbcDataType referencedJdbcDataType = Column.class.cast( referencedValue ).getJdbcDataType();
@@ -200,7 +197,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
// relational
List relationalValueBindings = manyToOneAttributeBinding.getRelationalValueBindings();
Assert.assertEquals( 1, relationalValueBindings.size() );
- RelationalValueBinding relationalValueBinding = relationalValueBindings.iterator().next();
+ RelationalValueBinding relationalValueBinding = relationalValueBindings.get( 0 );
assertFalse( relationalValueBinding.isDerived() );
assertTrue( relationalValueBinding.isIncludeInInsert() );
assertTrue( relationalValueBinding.isIncludeInUpdate() );
@@ -221,13 +218,11 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
if ( sourceColumn == column ) {
assertFalse( "source column not found in more than one foreign key", sourceColumnFound );
sourceColumnFound = true;
- Iterator targetColumnIterator = fk.getTargetColumns().iterator();
- assertTrue( targetColumnIterator.hasNext() );
- assertSame(
- referencedAttributeBinding.getRelationalValueBindings().iterator().next().getValue(),
- targetColumnIterator.next()
+ assertEquals( 1, fk.getTargetColumns().size() );
+ assertSame(
+ referencedAttributeBinding.getRelationalValueBindings().get( 0 ).getValue(),
+ fk.getTargetColumns().get( 0 )
);
- assertFalse( targetColumnIterator.hasNext() );
}
}
}
diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/BasicCollectionBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/BasicCollectionBindingTests.java
index 39315e3bb1..6183068d9d 100644
--- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/BasicCollectionBindingTests.java
+++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/BasicCollectionBindingTests.java
@@ -24,7 +24,6 @@
package org.hibernate.metamodel.spi.binding;
import java.util.Collection;
-import java.util.Iterator;
import java.util.Set;
import org.junit.After;
@@ -36,7 +35,6 @@ import org.hibernate.metamodel.MetadataSourceProcessingOrder;
import org.hibernate.metamodel.MetadataSources;
import org.hibernate.metamodel.internal.MetadataImpl;
import org.hibernate.metamodel.spi.domain.PluralAttributeNature;
-import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.ForeignKey;
import org.hibernate.metamodel.spi.relational.Identifier;
import org.hibernate.metamodel.spi.relational.TableSpecification;
@@ -182,24 +180,13 @@ public class BasicCollectionBindingTests extends BaseUnitTestCase {
assertEquals( 1, fk.getColumnSpan() );
assertEquals( 1, expectedKeyTargetAttributeBinding.getRelationalValueBindings().size() );
Value expectedFKTargetValue = expectedKeyTargetAttributeBinding.getRelationalValueBindings().get( 0 ).getValue();
- Iterator fkColumnIterator = fk.getColumns().iterator();
- Iterator fkSourceColumnIterator = fk.getSourceColumns().iterator();
- Iterator fkTargetColumnIterator = fk.getTargetColumns().iterator();
- assertNotNull( fkColumnIterator );
- assertNotNull( fkSourceColumnIterator );
- assertNotNull( fkTargetColumnIterator );
- assertTrue( fkColumnIterator.hasNext() );
- assertTrue( fkSourceColumnIterator.hasNext() );
- assertTrue( fkTargetColumnIterator.hasNext() );
- Column fkSourceColumn = fkSourceColumnIterator.next();
- assertSame( fkSourceColumn, fkColumnIterator.next() );
- assertEquals( expectedKeySourceColumnName, fkSourceColumn.getColumnName() );
- assertSame( expectedFKTargetValue, fkTargetColumnIterator.next() );
- assertFalse( fkColumnIterator.hasNext() );
- assertFalse( fkSourceColumnIterator.hasNext() );
- assertFalse( fkTargetColumnIterator.hasNext() );
+ assertEquals( fk.getColumns(), fk.getSourceColumns() );
+ assertEquals( 1, fk.getSourceColumns().size() );
+ assertEquals( 1, fk.getTargetColumns().size() );
+ assertEquals( expectedKeySourceColumnName, fk.getSourceColumns().get( 0 ).getColumnName() );
+ assertSame( expectedFKTargetValue, fk.getTargetColumns().get( 0 ) );
assertSame( collectionOwnerBinding.getPrimaryTable(), fk.getTargetTable() );
- assertEquals( expectedFKTargetValue.getJdbcDataType(), fkSourceColumn.getJdbcDataType() );
+ assertEquals( expectedFKTargetValue.getJdbcDataType(), fk.getSourceColumns().get( 0 ).getJdbcDataType() );
assertSame( ForeignKey.ReferentialAction.NO_ACTION, fk.getDeleteRule() );
assertSame( ForeignKey.ReferentialAction.NO_ACTION, fk.getUpdateRule() );
@@ -235,19 +222,12 @@ public class BasicCollectionBindingTests extends BaseUnitTestCase {
}
else {
assertEquals( 2, collectionTable.getPrimaryKey().getColumnSpan() );
- assertSame( fkSourceColumn, collectionTable.getPrimaryKey().getColumns().get( 0 ) );
+ assertSame( fk.getSourceColumns().get( 0 ), collectionTable.getPrimaryKey().getColumns().get( 0 ) );
assertSame( elementRelationalValueBinding.getValue(), collectionTable.getPrimaryKey().getColumns().get( 1 ) );
}
}
}
- protected void assertSameElements(Iterable iterable, Iterable iterable2) {
- Iterator itr2 = iterable2.iterator();
- for ( Object it : iterable ) {
- assertSame( it, itr2.next() );
- }
- }
-
private void checkEquals(HibernateTypeDescriptor expected, HibernateTypeDescriptor actual) {
assertEquals( expected.getExplicitTypeName(), actual.getExplicitTypeName() );
assertEquals( expected.getJavaTypeName(), actual.getJavaTypeName() );
diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalOneToManyBindingTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalOneToManyBindingTests.java
index 3f2f065b86..a7f8550f3e 100644
--- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalOneToManyBindingTests.java
+++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/binding/UnidirectionalOneToManyBindingTests.java
@@ -24,7 +24,6 @@
package org.hibernate.metamodel.spi.binding;
import java.util.Collection;
-import java.util.Iterator;
import java.util.Set;
import org.junit.After;
@@ -187,26 +186,21 @@ public class UnidirectionalOneToManyBindingTests extends BaseUnitTestCase {
assertSame( expectedElementEntityBinding.getPrimaryTable(), fk.getSourceTable() );
assertEquals( 1, fk.getColumnSpan() );
- Iterator fkColumnIterator = fk.getColumns().iterator();
- Iterator fkSourceColumnIterator = fk.getSourceColumns().iterator();
- assertNotNull( fkColumnIterator );
- assertNotNull( fkSourceColumnIterator );
- assertTrue( fkColumnIterator.hasNext() );
- assertTrue( fkSourceColumnIterator.hasNext() );
- assertSame( keySourceColumn, fkColumnIterator.next() );
- assertSame( keySourceColumn, fkSourceColumnIterator.next() );
- assertFalse( fkColumnIterator.hasNext() );
- assertFalse( fkSourceColumnIterator.hasNext() );
+ assertEquals( fk.getColumns(), fk.getSourceColumns() );
+ assertEquals( 1, fk.getSourceColumns().size() );
+ assertEquals( 1, fk.getTargetColumns().size() );
+ assertSame( keySourceColumn, fk.getColumns().get( 0 ) );
+ assertSame( keySourceColumn, fk.getSourceColumns().get( 0 ) );
assertSame( collectionOwnerBinding.getPrimaryTable(), fk.getTargetTable() );
assertEquals( 1, expectedKeyTargetAttributeBinding.getRelationalValueBindings().size() );
assertSame(
expectedKeyTargetAttributeBinding.getRelationalValueBindings().get( 0 ).getValue(),
- fk.getTargetColumns().iterator().next()
+ fk.getTargetColumns().get( 0 )
);
assertEquals(
expectedKeyTargetAttributeBinding.getRelationalValueBindings().get( 0 ).getValue().getJdbcDataType(),
- fk.getColumns().iterator().next().getJdbcDataType()
+ fk.getColumns().get( 0 ).getJdbcDataType()
);
checkEquals(
diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/relational/TableManipulationTests.java b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/relational/TableManipulationTests.java
index d744a64125..19a47267c6 100644
--- a/hibernate-core/src/test/java/org/hibernate/metamodel/spi/relational/TableManipulationTests.java
+++ b/hibernate-core/src/test/java/org/hibernate/metamodel/spi/relational/TableManipulationTests.java
@@ -131,6 +131,14 @@ public class TableManipulationTests extends BaseUnitTestCase {
assertEquals( page, pageBookFk.getSourceTable() );
assertEquals( book, pageBookFk.getTargetTable() );
+
+ assertEquals( 1, pageBookFk.getColumnSpan() );
+ assertEquals( 1, pageBookFk.getColumns().size() );
+ assertEquals( 1, pageBookFk.getSourceColumns().size() );
+ assertEquals( 1, pageBookFk.getTargetColumns().size() );
+ assertSame( pageBookId, pageBookFk.getColumns().get( 0 ) );
+ assertSame( pageBookId, pageBookFk.getSourceColumns().get( 0 ) );
+ assertSame( bookId, pageBookFk.getTargetColumns().get( 0 ) );
}
@Test