HHH-7383 : Change Constraint interface and implementations to return unmodifiable collections instead of Iterable
This commit is contained in:
parent
55abc2e357
commit
22365060d5
|
@ -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:<ul>
|
||||
* <li>primary key</li>
|
||||
|
@ -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<Column> getColumns();
|
||||
public List<Column> getColumns();
|
||||
}
|
||||
|
|
|
@ -72,11 +72,11 @@ public class ForeignKey extends AbstractConstraint implements Constraint, Export
|
|||
return targetTable;
|
||||
}
|
||||
|
||||
public Iterable<Column> getSourceColumns() {
|
||||
public List<Column> getSourceColumns() {
|
||||
return getColumns();
|
||||
}
|
||||
|
||||
public Iterable<Column> getTargetColumns() {
|
||||
public List<Column> getTargetColumns() {
|
||||
return targetColumns == null
|
||||
? getTargetTable().getPrimaryKey().getColumns()
|
||||
: Collections.unmodifiableList( targetColumns );
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
@ -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<RelationalValueBinding> 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<Column> 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() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Column> fkColumnIterator = fk.getColumns().iterator();
|
||||
Iterator<Column> fkSourceColumnIterator = fk.getSourceColumns().iterator();
|
||||
Iterator<Column> 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() );
|
||||
|
|
|
@ -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<Column> fkColumnIterator = fk.getColumns().iterator();
|
||||
Iterator<Column> 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(
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue