HHH-7830 : union-subclass support

This commit is contained in:
Gail Badner 2013-02-07 09:33:15 -08:00
parent 1634d56c36
commit ba0f96639e
27 changed files with 241 additions and 159 deletions

View File

@ -640,7 +640,7 @@ public class Binder {
entityBinding.getPrimaryTable().getLogicalName().getText() entityBinding.getPrimaryTable().getLogicalName().getText()
) )
); );
joinRelationalValueBindings.add( new RelationalValueBinding( joinColumn, true, false ) ); joinRelationalValueBindings.add( new RelationalValueBinding( entityBinding.getPrimaryTable(), joinColumn, true, false ) );
} }
} }
else { else {
@ -667,7 +667,7 @@ public class Binder {
column.setSqlType( joinColumnSource.getSqlType() ); column.setSqlType( joinColumnSource.getSqlType() );
} }
} }
joinRelationalValueBindings.add( new RelationalValueBinding( column, true, false ) ); joinRelationalValueBindings.add( new RelationalValueBinding( table, column, true, false ) );
} }
} }
typeHelper.bindJdbcDataType( typeHelper.bindJdbcDataType(
@ -680,10 +680,13 @@ public class Binder {
); );
// TODO: make the foreign key column the primary key??? // TODO: make the foreign key column the primary key???
final List<Column> targetColumns = determineForeignKeyTargetColumns( entityBinding, secondaryTableSource );
final ForeignKey foreignKey = locateOrCreateForeignKey( final ForeignKey foreignKey = locateOrCreateForeignKey(
quotedIdentifier( secondaryTableSource.getExplicitForeignKeyName() ), quotedIdentifier( secondaryTableSource.getExplicitForeignKeyName() ),
table,
joinRelationalValueBindings, joinRelationalValueBindings,
determineForeignKeyTargetColumns( entityBinding, secondaryTableSource ) determineForeignKeyTargetTable( entityBinding, targetColumns ),
targetColumns
); );
SecondaryTable secondaryTable = new SecondaryTable( table, foreignKey ); SecondaryTable secondaryTable = new SecondaryTable( table, foreignKey );
secondaryTable.setFetchStyle( secondaryTableSource.getFetchStyle() ); secondaryTable.setFetchStyle( secondaryTableSource.getFetchStyle() );
@ -696,11 +699,15 @@ public class Binder {
public ForeignKey locateOrCreateForeignKey( public ForeignKey locateOrCreateForeignKey(
final String foreignKeyName, final String foreignKeyName,
final TableSpecification sourceTable,
final List<RelationalValueBinding> sourceRelationalValueBindings, final List<RelationalValueBinding> sourceRelationalValueBindings,
final TableSpecification targetTable,
final List<Column> targetColumns) { final List<Column> targetColumns) {
return foreignKeyHelper.locateOrCreateForeignKey( return foreignKeyHelper.locateOrCreateForeignKey(
foreignKeyName, foreignKeyName,
sourceTable,
extractColumnsFromRelationalValueBindings( sourceRelationalValueBindings ), extractColumnsFromRelationalValueBindings( sourceRelationalValueBindings ),
targetTable,
targetColumns targetColumns
); );
} }
@ -1189,14 +1196,17 @@ public class Binder {
attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(), attributeBinding.getHibernateTypeDescriptor().getResolvedTypeMapping(),
attributeBinding.getRelationalValueBindings() attributeBinding.getRelationalValueBindings()
); );
final List<Column> targetColumns = determineForeignKeyTargetColumns(
attributeBinding.getReferencedEntityBinding(),
attributeSource
);
if ( !attributeBinding.hasDerivedValue() ) { if ( !attributeBinding.hasDerivedValue() ) {
locateOrCreateForeignKey( locateOrCreateForeignKey(
quotedIdentifier( attributeSource.getExplicitForeignKeyName() ), quotedIdentifier( attributeSource.getExplicitForeignKeyName() ),
attributeBinding.getRelationalValueBindings().get( 0 ).getTable(),
attributeBinding.getRelationalValueBindings(), attributeBinding.getRelationalValueBindings(),
determineForeignKeyTargetColumns( determineForeignKeyTargetTable( attributeBinding.getReferencedEntityBinding(), targetColumns ),
attributeBinding.getReferencedEntityBinding(), targetColumns
attributeSource
)
); );
} }
return attributeBinding; return attributeBinding;
@ -1310,13 +1320,16 @@ public class Binder {
.getAttributeBinding() .getAttributeBinding()
.getRelationalValueBindings(); .getRelationalValueBindings();
final List<Column> targetColumns = determineForeignKeyTargetColumns(
attributeBinding.getReferencedEntityBinding(),
attributeSource
);
locateOrCreateForeignKey( locateOrCreateForeignKey(
quotedIdentifier( attributeSource.getExplicitForeignKeyName() ), quotedIdentifier( attributeSource.getExplicitForeignKeyName() ),
foreignKeyRelationalValueBindings.get( 0 ).getTable(),
foreignKeyRelationalValueBindings, foreignKeyRelationalValueBindings,
determineForeignKeyTargetColumns( determineForeignKeyTargetTable( attributeBinding.getReferencedEntityBinding(), targetColumns ),
attributeBinding.getReferencedEntityBinding(), targetColumns
attributeSource
)
); );
} }
return attributeBinding; return attributeBinding;
@ -1810,22 +1823,6 @@ public class Binder {
indexedPluralAttribute.setIndexType( aggregate ); indexedPluralAttribute.setIndexType( aggregate );
} }
private SingularAttributeBinding determineReferencedAttributeBinding(
final ForeignKeyContributingSource foreignKeyContributingSource,
final EntityBinding referencedEntityBinding) {
final JoinColumnResolutionDelegate resolutionDelegate =
foreignKeyContributingSource.getForeignKeyTargetColumnResolutionDelegate();
final JoinColumnResolutionContext resolutionContext = resolutionDelegate == null ? null : new JoinColumnResolutionContextImpl(
referencedEntityBinding
);
return determineReferencedAttributeBinding(
resolutionDelegate,
resolutionContext,
referencedEntityBinding
);
}
private void bindOneToManyCollectionElement( private void bindOneToManyCollectionElement(
final OneToManyPluralAttributeElementBinding elementBinding, final OneToManyPluralAttributeElementBinding elementBinding,
final OneToManyPluralAttributeElementSource elementSource, final OneToManyPluralAttributeElementSource elementSource,
@ -1882,22 +1879,24 @@ public class Binder {
); );
} }
final TableSpecification collectionTable = elementBinding.getPluralAttributeBinding().getPluralAttributeKeyBinding().getCollectionTable();
elementBinding.setRelationalValueBindings( elementBinding.setRelationalValueBindings(
bindValues( bindValues(
elementBinding.getPluralAttributeBinding().getContainer(), elementBinding.getPluralAttributeBinding().getContainer(),
elementSource, elementSource,
elementBinding.getPluralAttributeBinding().getAttribute(), elementBinding.getPluralAttributeBinding().getAttribute(),
elementBinding.getPluralAttributeBinding().getPluralAttributeKeyBinding().getCollectionTable(), collectionTable,
namingStrategies, namingStrategies,
true true
) )
); );
if ( !elementBinding.getPluralAttributeBinding().getPluralAttributeKeyBinding().isInverse() && if ( !elementBinding.getPluralAttributeBinding().getPluralAttributeKeyBinding().isInverse() &&
!elementBinding.hasDerivedValue() ) { !elementBinding.hasDerivedValue() ) {
locateOrCreateForeignKey( locateOrCreateForeignKey(
quotedIdentifier( elementSource.getExplicitForeignKeyName() ), quotedIdentifier( elementSource.getExplicitForeignKeyName() ),
collectionTable,
elementBinding.getRelationalValueBindings(), elementBinding.getRelationalValueBindings(),
determineForeignKeyTargetTable( referencedEntityBinding, targetColumns ),
targetColumns targetColumns
); );
} }
@ -2257,9 +2256,13 @@ public class Binder {
} }
private SingularAttributeBinding determineReferencedAttributeBinding( private SingularAttributeBinding determineReferencedAttributeBinding(
final JoinColumnResolutionDelegate resolutionDelegate, final ForeignKeyContributingSource foreignKeyContributingSource,
final JoinColumnResolutionContext resolutionContext,
final EntityBinding referencedEntityBinding) { final EntityBinding referencedEntityBinding) {
final JoinColumnResolutionDelegate resolutionDelegate =
foreignKeyContributingSource.getForeignKeyTargetColumnResolutionDelegate();
final JoinColumnResolutionContext resolutionContext = resolutionDelegate == null ? null : new JoinColumnResolutionContextImpl(
referencedEntityBinding
);
if ( resolutionDelegate == null ) { if ( resolutionDelegate == null ) {
return referencedEntityBinding.getHierarchyDetails().getEntityIdentifier().getAttributeBinding(); return referencedEntityBinding.getHierarchyDetails().getEntityIdentifier().getAttributeBinding();
} }
@ -2300,7 +2303,6 @@ public class Binder {
return (SingularAttributeBinding) referencedAttributeBinding; return (SingularAttributeBinding) referencedAttributeBinding;
} }
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ relational binding relates methods //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ relational binding relates methods
private void bindBasicPluralElementRelationalValues( private void bindBasicPluralElementRelationalValues(
final RelationalValueSourceContainer relationalValueSourceContainer, final RelationalValueSourceContainer relationalValueSourceContainer,
@ -2398,7 +2400,9 @@ public class Binder {
keyBinding.setRelationalValueBindings( sourceRelationalBindings ); keyBinding.setRelationalValueBindings( sourceRelationalBindings );
ForeignKey foreignKey = locateOrCreateForeignKey( ForeignKey foreignKey = locateOrCreateForeignKey(
quotedIdentifier( keySource.getExplicitForeignKeyName() ), quotedIdentifier( keySource.getExplicitForeignKeyName() ),
collectionTable,
sourceRelationalBindings, sourceRelationalBindings,
determineForeignKeyTargetTable( attributeBinding.getContainer().seekEntityBinding(), targetColumns ),
targetColumns targetColumns
); );
foreignKey.setDeleteRule( keySource.getOnDeleteAction() ); foreignKey.setDeleteRule( keySource.getOnDeleteAction() );
@ -2533,7 +2537,9 @@ public class Binder {
ForeignKey foreignKey = foreignKeyHelper.locateOrCreateForeignKey( ForeignKey foreignKey = foreignKeyHelper.locateOrCreateForeignKey(
quotedIdentifier( subclassEntitySource.getExplicitForeignKeyName() ), quotedIdentifier( subclassEntitySource.getExplicitForeignKeyName() ),
entityBinding.getPrimaryTable(),
sourceColumns, sourceColumns,
determineForeignKeyTargetTable( superEntityBinding, targetColumns ),
targetColumns targetColumns
); );
@ -2629,6 +2635,7 @@ public class Binder {
} }
valueBindings.add( valueBindings.add(
new RelationalValueBinding( new RelationalValueBinding(
defaultTable,
column, column,
valueSourceContainer.areValuesIncludedInInsertByDefault(), valueSourceContainer.areValuesIncludedInInsertByDefault(),
valueSourceContainer.areValuesIncludedInUpdateByDefault() && !isImmutableNaturalId valueSourceContainer.areValuesIncludedInUpdateByDefault() && !isImmutableNaturalId
@ -2670,6 +2677,7 @@ public class Binder {
); );
valueBindings.add( valueBindings.add(
new RelationalValueBinding( new RelationalValueBinding(
table,
column, column,
isIncludedInInsert, isIncludedInInsert,
!isImmutableNaturalId && isIncludedInUpdate !isImmutableNaturalId && isIncludedInUpdate
@ -2679,7 +2687,7 @@ public class Binder {
else { else {
final DerivedValue derivedValue = final DerivedValue derivedValue =
table.locateOrCreateDerivedValue( ( (DerivedValueSource) valueSource ).getExpression() ); table.locateOrCreateDerivedValue( ( (DerivedValueSource) valueSource ).getExpression() );
valueBindings.add( new RelationalValueBinding( derivedValue ) ); valueBindings.add( new RelationalValueBinding( table, derivedValue ) );
} }
} }
} }
@ -2909,6 +2917,43 @@ public class Binder {
} }
} }
private TableSpecification determineForeignKeyTargetTable(final EntityBinding entityBinding,
final List<Column> targetColumns) {
TableSpecification table = null;
TableSpecification actualTable = null;
boolean first = true;
for ( Column column : targetColumns) {
if ( first ) {
table = column.getTable();
if ( entityBinding.hasTable( table.getLogicalName().getText() ) ) {
actualTable = table;
}
else {
if ( entityBinding.getHierarchyDetails().getInheritanceType() == InheritanceType.TABLE_PER_CLASS &&
column == entityBinding.getPrimaryTable().locateColumn( column.getColumnName().getText() ) ) {
actualTable = entityBinding.getPrimaryTable();
}
else {
throw bindingContext().makeMappingException( "improve this message!!!" );
}
}
first = false;
}
else {
if ( !table.equals( column.getTable() ) ) {
throw bindingContext().makeMappingException(
String.format(
"Join columns come from more than one table: %s, %s ",
table,
column.getTable()
)
);
}
}
}
return actualTable;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ simple instance helper methods //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ simple instance helper methods
private void mapSourcesByName(final EntitySource rootEntitySource) { private void mapSourcesByName(final EntitySource rootEntitySource) {
String entityName = rootEntitySource.getEntityName(); String entityName = rootEntitySource.getEntityName();

View File

@ -50,14 +50,16 @@ public class ForeignKeyHelper {
public ForeignKey locateOrCreateForeignKey( public ForeignKey locateOrCreateForeignKey(
final String foreignKeyName, final String foreignKeyName,
final TableSpecification sourceTable,
final List<Column> sourceColumns, final List<Column> sourceColumns,
final TableSpecification targetTable,
final List<Column> targetColumns) { final List<Column> targetColumns) {
ForeignKey foreignKey = null; ForeignKey foreignKey = null;
if ( foreignKeyName != null ) { if ( foreignKeyName != null ) {
foreignKey = locateAndBindForeignKeyByName( foreignKeyName, sourceColumns, targetColumns ); foreignKey = locateAndBindForeignKeyByName( foreignKeyName, sourceTable, sourceColumns, targetTable, targetColumns );
} }
if ( foreignKey == null ) { if ( foreignKey == null ) {
foreignKey = locateForeignKeyByColumnMapping( sourceColumns, targetColumns ); foreignKey = locateForeignKeyByColumnMapping( sourceTable, sourceColumns, targetTable, targetColumns );
if ( foreignKey != null && foreignKeyName != null ) { if ( foreignKey != null && foreignKeyName != null ) {
if ( foreignKey.getName() == null ) { if ( foreignKey.getName() == null ) {
// the foreign key name has not be initialized; set it to foreignKeyName // the foreign key name has not be initialized; set it to foreignKeyName
@ -78,19 +80,17 @@ public class ForeignKeyHelper {
} }
if ( foreignKey == null ) { if ( foreignKey == null ) {
// no foreign key found; create one // no foreign key found; create one
final TableSpecification sourceTable = sourceColumns.get( 0 ).getTable();
final TableSpecification targetTable = targetColumns.get( 0 ).getTable();
foreignKey = sourceTable.createForeignKey( targetTable, foreignKeyName ); foreignKey = sourceTable.createForeignKey( targetTable, foreignKeyName );
bindForeignKeyColumns( foreignKey, sourceColumns, targetColumns ); bindForeignKeyColumns( foreignKey, sourceTable, sourceColumns, targetTable, targetColumns );
} }
return foreignKey; return foreignKey;
} }
private static ForeignKey locateForeignKeyByColumnMapping( private static ForeignKey locateForeignKeyByColumnMapping(
final TableSpecification sourceTable,
final List<Column> sourceColumns, final List<Column> sourceColumns,
final TableSpecification targetTable,
final List<Column> targetColumns) { final List<Column> targetColumns) {
final TableSpecification sourceTable = sourceColumns.get( 0 ).getTable();
final TableSpecification targetTable = targetColumns.get( 0 ).getTable();
// check for an existing foreign key with the same source/target columns // check for an existing foreign key with the same source/target columns
ForeignKey foreignKey = null; ForeignKey foreignKey = null;
Iterable<ForeignKey> possibleForeignKeys = sourceTable.locateForeignKey( targetTable ); Iterable<ForeignKey> possibleForeignKeys = sourceTable.locateForeignKey( targetTable );
@ -109,15 +109,17 @@ public class ForeignKeyHelper {
private void bindForeignKeyColumns( private void bindForeignKeyColumns(
final ForeignKey foreignKey, final ForeignKey foreignKey,
final TableSpecification sourceTable,
final List<Column> sourceColumns, final List<Column> sourceColumns,
final TableSpecification targetTable,
final List<Column> targetColumns) { final List<Column> targetColumns) {
if ( sourceColumns.size() != targetColumns.size() ) { if ( sourceColumns.size() != targetColumns.size() ) {
throw binder.bindingContext().makeMappingException( throw binder.bindingContext().makeMappingException(
String.format( String.format(
"Non-matching number columns in foreign key source columns [%s : %s] and target columns [%s : %s]", "Non-matching number columns in foreign key source columns [%s : %s] and target columns [%s : %s]",
sourceColumns.get( 0 ).getTable().getLogicalName().getText(), sourceTable.getLogicalName().getText(),
sourceColumns.size(), sourceColumns.size(),
targetColumns.get( 0 ).getTable().getLogicalName().getText(), targetTable.getLogicalName().getText(),
targetColumns.size() targetColumns.size()
) )
); );
@ -129,13 +131,13 @@ public class ForeignKeyHelper {
private ForeignKey locateAndBindForeignKeyByName( private ForeignKey locateAndBindForeignKeyByName(
final String foreignKeyName, final String foreignKeyName,
final TableSpecification sourceTable,
final List<Column> sourceColumns, final List<Column> sourceColumns,
final TableSpecification targetTable,
final List<Column> targetColumns) { final List<Column> targetColumns) {
if ( foreignKeyName == null ) { if ( foreignKeyName == null ) {
throw new AssertionFailure( "foreignKeyName must be non-null." ); throw new AssertionFailure( "foreignKeyName must be non-null." );
} }
final TableSpecification sourceTable = sourceColumns.get( 0 ).getTable();
final TableSpecification targetTable = targetColumns.get( 0 ).getTable();
ForeignKey foreignKey = sourceTable.locateForeignKey( foreignKeyName ); ForeignKey foreignKey = sourceTable.locateForeignKey( foreignKeyName );
if ( foreignKey != null ) { if ( foreignKey != null ) {
if ( !targetTable.equals( foreignKey.getTargetTable() ) ) { if ( !targetTable.equals( foreignKey.getTargetTable() ) ) {
@ -151,7 +153,7 @@ public class ForeignKeyHelper {
// check if source and target columns have been bound already // check if source and target columns have been bound already
if ( foreignKey.getColumnSpan() == 0 ) { if ( foreignKey.getColumnSpan() == 0 ) {
// foreign key was found, but no columns bound to it yet // foreign key was found, but no columns bound to it yet
bindForeignKeyColumns( foreignKey, sourceColumns, targetColumns ); bindForeignKeyColumns( foreignKey, sourceTable, sourceColumns, targetTable, targetColumns );
} }
else { else {
// The located foreign key already has columns bound; // The located foreign key already has columns bound;

View File

@ -33,8 +33,10 @@ import org.hibernate.metamodel.internal.Binder;
import org.hibernate.metamodel.spi.binding.AttributeBinding; import org.hibernate.metamodel.spi.binding.AttributeBinding;
import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding; import org.hibernate.metamodel.spi.binding.CompositeAttributeBinding;
import org.hibernate.metamodel.spi.binding.SingularAttributeBinding; import org.hibernate.metamodel.spi.binding.SingularAttributeBinding;
import org.hibernate.metamodel.spi.relational.TableSpecification;
import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.relational.Value;
import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource; import org.hibernate.metamodel.spi.source.ExplicitHibernateTypeSource;
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
import org.hibernate.metamodel.spi.source.MappingException; import org.hibernate.metamodel.spi.source.MappingException;
import org.hibernate.metamodel.spi.source.ToOneAttributeSource; import org.hibernate.metamodel.spi.source.ToOneAttributeSource;
import org.hibernate.type.ForeignKeyDirection; import org.hibernate.type.ForeignKeyDirection;

View File

@ -28,8 +28,10 @@ import java.util.List;
import org.hibernate.jaxb.spi.hbm.JaxbColumnElement; import org.hibernate.jaxb.spi.hbm.JaxbColumnElement;
import org.hibernate.jaxb.spi.hbm.JaxbKeyElement; import org.hibernate.jaxb.spi.hbm.JaxbKeyElement;
import org.hibernate.metamodel.spi.relational.ForeignKey; import org.hibernate.metamodel.spi.relational.ForeignKey;
import org.hibernate.metamodel.spi.relational.TableSpecification;
import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.relational.Value;
import org.hibernate.metamodel.spi.source.AttributeSourceContainer; import org.hibernate.metamodel.spi.source.AttributeSourceContainer;
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
import org.hibernate.metamodel.spi.source.PluralAttributeKeySource; import org.hibernate.metamodel.spi.source.PluralAttributeKeySource;
import org.hibernate.metamodel.spi.source.RelationalValueSource; import org.hibernate.metamodel.spi.source.RelationalValueSource;

View File

@ -31,8 +31,10 @@ import org.hibernate.jaxb.spi.hbm.JaxbColumnElement;
import org.hibernate.jaxb.spi.hbm.JaxbFetchStyleAttribute; import org.hibernate.jaxb.spi.hbm.JaxbFetchStyleAttribute;
import org.hibernate.jaxb.spi.hbm.JaxbJoinElement; import org.hibernate.jaxb.spi.hbm.JaxbJoinElement;
import org.hibernate.jaxb.spi.hbm.JaxbOnDeleteAttribute; import org.hibernate.jaxb.spi.hbm.JaxbOnDeleteAttribute;
import org.hibernate.metamodel.spi.relational.TableSpecification;
import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.relational.Value;
import org.hibernate.metamodel.spi.source.ColumnSource; import org.hibernate.metamodel.spi.source.ColumnSource;
import org.hibernate.metamodel.spi.source.ForeignKeyContributingSource;
import org.hibernate.metamodel.spi.source.InLineViewSource; import org.hibernate.metamodel.spi.source.InLineViewSource;
import org.hibernate.metamodel.spi.source.RelationalValueSource; import org.hibernate.metamodel.spi.source.RelationalValueSource;
import org.hibernate.metamodel.spi.source.SecondaryTableSource; import org.hibernate.metamodel.spi.source.SecondaryTableSource;

View File

@ -70,9 +70,9 @@ public class BackRefAttributeBinding extends BasicAttributeBinding {
} }
else { else {
relationalValueBindings = new ArrayList<RelationalValueBinding>( ); relationalValueBindings = new ArrayList<RelationalValueBinding>( );
for ( RelationalValueBinding keyRelationalValueBindings : pluralAttributeBinding.getPluralAttributeKeyBinding().getRelationalValueBindings() ) { for ( RelationalValueBinding keyRelationalValueBinding : pluralAttributeBinding.getPluralAttributeKeyBinding().getRelationalValueBindings() ) {
Column keyColumn = (Column) keyRelationalValueBindings.getValue(); Column keyColumn = (Column) keyRelationalValueBinding.getValue();
relationalValueBindings.add( new RelationalValueBinding( keyColumn, true, false ) ); relationalValueBindings.add( new RelationalValueBinding( keyRelationalValueBinding.getTable(), keyColumn, true, false ) );
} }
} }
return relationalValueBindings; return relationalValueBindings;

View File

@ -184,6 +184,11 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements
this.primaryTable = primaryTable; this.primaryTable = primaryTable;
} }
public boolean hasTable(String tableName) {
return tableName.equals( getPrimaryTableName() ) ||
secondaryTables.containsKey( Identifier.toIdentifier( tableName ) );
}
public TableSpecification locateTable(String tableName) { public TableSpecification locateTable(String tableName) {
if ( tableName == null || tableName.equals( getPrimaryTableName() ) ) { if ( tableName == null || tableName.equals( getPrimaryTableName() ) ) {
return primaryTable; return primaryTable;
@ -809,8 +814,7 @@ public class EntityBinding extends AbstractAttributeBindingContainer implements
return 0; return 0;
} }
int result=1; int result=1;
Value value = attributeBinding.getRelationalValueBindings().get( 0 ).getValue(); TableSpecification table = attributeBinding.getRelationalValueBindings().get( 0 ).getTable();
TableSpecification table = value.getTable();
for ( SecondaryTable secondaryTable : getEntitiesSecondaryTableClosure() ) { for ( SecondaryTable secondaryTable : getEntitiesSecondaryTableClosure() ) {
if ( secondaryTable.getSecondaryTableReference() == table ) { if ( secondaryTable.getSecondaryTableReference() == table ) {
return result; return result;

View File

@ -274,7 +274,7 @@ public class EntityIdentifier {
// the first one to get the TableSpecification. // the first one to get the TableSpecification.
final RelationalValueBinding relationalValueBinding = relationalValueBindings.get( 0 ); final RelationalValueBinding relationalValueBinding = relationalValueBindings.get( 0 );
final TableSpecification table = relationalValueBinding.getValue().getTable(); final TableSpecification table = relationalValueBinding.getTable();
if ( !Column.class.isInstance( relationalValueBinding.getValue() ) ) { if ( !Column.class.isInstance( relationalValueBinding.getValue() ) ) {
throw new MappingException( throw new MappingException(
"Cannot create an IdentifierGenerator because the value is not a column: " + "Cannot create an IdentifierGenerator because the value is not a column: " +

View File

@ -71,7 +71,7 @@ public class PluralAttributeKeyBinding {
public TableSpecification getCollectionTable() { public TableSpecification getCollectionTable() {
// TODO: get table directly from relationalValueBindingContainer // TODO: get table directly from relationalValueBindingContainer
return relationalValueBindingContainer.relationalValueBindings().get( 0 ).getValue().getTable(); return relationalValueBindingContainer.relationalValueBindings().get( 0 ).getTable();
} }
/** /**

View File

@ -25,6 +25,7 @@ package org.hibernate.metamodel.spi.binding;
import org.hibernate.metamodel.spi.relational.Column; import org.hibernate.metamodel.spi.relational.Column;
import org.hibernate.metamodel.spi.relational.DerivedValue; import org.hibernate.metamodel.spi.relational.DerivedValue;
import org.hibernate.metamodel.spi.relational.TableSpecification;
import org.hibernate.metamodel.spi.relational.Value; import org.hibernate.metamodel.spi.relational.Value;
/** /**
@ -37,25 +38,32 @@ import org.hibernate.metamodel.spi.relational.Value;
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class RelationalValueBinding { public class RelationalValueBinding {
private final TableSpecification table;
private final Value value; private final Value value;
private final boolean includeInInsert; private final boolean includeInInsert;
private final boolean includeInUpdate; private final boolean includeInUpdate;
private final boolean isDerived; private final boolean isDerived;
public RelationalValueBinding(final DerivedValue value) { public RelationalValueBinding(final TableSpecification table, final DerivedValue value) {
this.table = table;
this.value = value; this.value = value;
this.includeInInsert = false; this.includeInInsert = false;
this.includeInUpdate = false; this.includeInUpdate = false;
this.isDerived = true; this.isDerived = true;
} }
public RelationalValueBinding(final Column value, final boolean includeInInsert, final boolean includeInUpdate) { public RelationalValueBinding(final TableSpecification table, final Column value, final boolean includeInInsert, final boolean includeInUpdate) {
this.table = table;
this.value = value; this.value = value;
this.includeInInsert = includeInInsert; this.includeInInsert = includeInInsert;
this.includeInUpdate = includeInUpdate; this.includeInUpdate = includeInUpdate;
this.isDerived = false; this.isDerived = false;
} }
public TableSpecification getTable() {
return table;
}
/** /**
* Retrieve the relational value bound here. * Retrieve the relational value bound here.
* *

View File

@ -81,10 +81,6 @@ public abstract class AbstractTableSpecification implements TableSpecification {
@Override @Override
public boolean hasValue(Value value) { public boolean hasValue(Value value) {
//shortcut
if ( this != value.getTable() ) {
return false;
}
return valueMap.containsValue( value ); return valueMap.containsValue( value );
} }

View File

@ -39,6 +39,7 @@ public class DenormalizedTable extends Table {
public DenormalizedTable(Schema database, Identifier logicalName, Identifier physicalName, Table includedTable) { public DenormalizedTable(Schema database, Identifier logicalName, Identifier physicalName, Table includedTable) {
super( database, logicalName, physicalName ); super( database, logicalName, physicalName );
this.includedTable = includedTable; this.includedTable = includedTable;
this.includedTable.setHasDenormalizedTables( true );
} }
@Override @Override

View File

@ -127,15 +127,15 @@ public class ForeignKey extends AbstractConstraint {
} }
private void checkTargetTable(Column targetColumn) { private void checkTargetTable(Column targetColumn) {
if ( targetColumn.getTable() != getTargetTable() ) { // if ( targetColumn.getTable() != getTargetTable() ) {
throw new AssertionFailure( // throw new AssertionFailure(
String.format( // String.format(
"Unable to add column to constraint; tables [%s, %s] did not match", // "Unable to add column to constraint; tables [%s, %s] did not match",
targetColumn.getTable().toLoggableString(), // targetColumn.getTable().toLoggableString(),
getTargetTable().toLoggableString() // getTargetTable().toLoggableString()
) // )
); // );
} // }
} }
@Override @Override

View File

@ -48,6 +48,7 @@ public class Table extends AbstractTableSpecification implements Exportable {
private ObjectName qualifiedName; private ObjectName qualifiedName;
private String exportIdentifier; private String exportIdentifier;
private boolean isPhysicalTable = true; private boolean isPhysicalTable = true;
private boolean hasDenormalizedTables = false;
private final Set<Index> indexes = new LinkedHashSet<Index>(); private final Set<Index> indexes = new LinkedHashSet<Index>();
private final Set<UniqueKey> uniqueKeys = new LinkedHashSet<UniqueKey>(); private final Set<UniqueKey> uniqueKeys = new LinkedHashSet<UniqueKey>();
@ -108,6 +109,14 @@ public class Table extends AbstractTableSpecification implements Exportable {
isPhysicalTable = physicalTable; isPhysicalTable = physicalTable;
} }
public boolean hasDenormalizedTables() {
return hasDenormalizedTables;
}
protected void setHasDenormalizedTables(boolean hasDenormalizedTables) {
this.hasDenormalizedTables = hasDenormalizedTables;
}
/** /**
* Gets the qualified table name. * Gets the qualified table name.
* *

View File

@ -982,7 +982,7 @@ public abstract class AbstractEntityPersister
for ( RelationalValueBinding valueBinding : singularAttributeBinding.getRelationalValueBindings() ) { for ( RelationalValueBinding valueBinding : singularAttributeBinding.getRelationalValueBindings() ) {
colAliases[k] = valueBinding.getValue().getAlias( colAliases[k] = valueBinding.getValue().getAlias(
factory.getDialect(), factory.getDialect(),
valueBinding.getValue().getTable() valueBinding.getTable()
); );
if ( valueBinding.isDerived() ) { if ( valueBinding.isDerived() ) {
foundFormula = true; foundFormula = true;
@ -1106,7 +1106,7 @@ public abstract class AbstractEntityPersister
aliases.add( aliases.add(
col.getAlias( col.getAlias(
factory.getDialect(), factory.getDialect(),
col.getTable() valueBinding.getTable()
) )
); );
columnsLazy.add( lazy ); columnsLazy.add( lazy );
@ -2319,7 +2319,7 @@ public abstract class AbstractEntityPersister
for ( RelationalValueBinding relationalValueBinding : singularProp.getRelationalValueBindings() ) { for ( RelationalValueBinding relationalValueBinding : singularProp.getRelationalValueBindings() ) {
aliases[l] = relationalValueBinding.getValue().getAlias( aliases[l] = relationalValueBinding.getValue().getAlias(
getFactory().getDialect(), getFactory().getDialect(),
relationalValueBinding.getValue().getTable() relationalValueBinding.getTable()
); );
if ( relationalValueBinding.isDerived() ) { if ( relationalValueBinding.isDerived() ) {
cols[l] = ( (DerivedValue) relationalValueBinding.getValue() ).getExpression(); // TODO: skip formulas? cols[l] = ( (DerivedValue) relationalValueBinding.getValue() ).getExpression(); // TODO: skip formulas?

View File

@ -115,10 +115,18 @@ public class SchemaCreatorImpl implements SchemaCreator {
for ( Table table : schema.getTables() ) { for ( Table table : schema.getTables() ) {
for ( ForeignKey foreignKey : table.getForeignKeys() ) { for ( ForeignKey foreignKey : table.getForeignKeys() ) {
// only add the foreign key if its target is a physical table // only add the foreign key if its source and target are both physical tables
if ( Table.class.isInstance( foreignKey.getTargetTable() ) ) { // and if the target table does not have any denormalized tables.
checkExportIdentifier( foreignKey, exportIdentifiers ); if ( Table.class.isInstance( foreignKey.getTable() ) &&
applySqlStrings( targets, dialect.getForeignKeyExporter().getSqlCreateStrings( foreignKey, jdbcEnvironment ) ); Table.class.isInstance( foreignKey.getTargetTable() ) ) {
Table sourceTable = Table.class.cast( foreignKey.getTable() );
Table targetTable = Table.class.cast( foreignKey.getTargetTable() );
if ( sourceTable.isPhysicalTable() &&
targetTable.isPhysicalTable() &&
!targetTable.hasDenormalizedTables() ) {
checkExportIdentifier( foreignKey, exportIdentifiers );
applySqlStrings( targets, dialect.getForeignKeyExporter().getSqlCreateStrings( foreignKey, jdbcEnvironment ) );
}
} }
} }
} }

View File

@ -87,13 +87,21 @@ public class SchemaDropperImpl implements SchemaDropper {
// we need to drop constraints prior to dropping table // we need to drop constraints prior to dropping table
for ( ForeignKey foreignKey : table.getForeignKeys() ) { for ( ForeignKey foreignKey : table.getForeignKeys() ) {
// only add the foreign key if its target is a physical table // only add the foreign key if its source and target are both physical tables
if ( Table.class.isInstance( foreignKey.getTargetTable() ) ) { // and if the target table does not have any denormalized tables.
checkExportIdentifier( foreignKey, exportIdentifiers ); if ( Table.class.isInstance( foreignKey.getTable() ) &&
applySqlStrings( Table.class.isInstance( foreignKey.getTargetTable() ) ) {
targets, Table sourceTable = Table.class.cast( foreignKey.getTable() );
dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, jdbcEnvironment ) Table targetTable = Table.class.cast( foreignKey.getTargetTable() );
); if ( sourceTable.isPhysicalTable() &&
targetTable.isPhysicalTable() &&
!targetTable.hasDenormalizedTables() ) {
checkExportIdentifier( foreignKey, exportIdentifiers );
applySqlStrings(
targets,
dialect.getForeignKeyExporter().getSqlDropStrings( foreignKey, jdbcEnvironment )
);
}
} }
} }

View File

@ -88,12 +88,12 @@ public class SchemaValidatorImpl implements SchemaValidator {
); );
} }
validateColumnType( column, columnInformation ); validateColumnType( table, column, columnInformation );
} }
} }
} }
protected void validateColumnType(Column column, ColumnInformation columnInformation) { protected void validateColumnType(Table table, Column column, ColumnInformation columnInformation) {
// this is the old Hibernate check... // this is the old Hibernate check...
final boolean typesMatch = column.getJdbcDataType().getTypeCode() == columnInformation.getTypeCode() final boolean typesMatch = column.getJdbcDataType().getTypeCode() == columnInformation.getTypeCode()
|| column.getSqlType().toLowerCase().startsWith( columnInformation.getTypeName().toLowerCase() ); || column.getSqlType().toLowerCase().startsWith( columnInformation.getTypeName().toLowerCase() );
@ -102,7 +102,7 @@ public class SchemaValidatorImpl implements SchemaValidator {
String.format( String.format(
"Schema-validation: wrong column type encountered in column [%s] in table [%s]; found [%s], but expecting [%s]", "Schema-validation: wrong column type encountered in column [%s] in table [%s]; found [%s], but expecting [%s]",
column.getColumnName().getText(), column.getColumnName().getText(),
((Table) column.getTable()).getTableName().toText(), table.getTableName().toText(),
columnInformation.getTypeName().toLowerCase(), columnInformation.getTypeName().toLowerCase(),
column.getSqlType().toLowerCase() column.getSqlType().toLowerCase()
) )

View File

@ -88,7 +88,7 @@ public class SecondaryTableTest extends BaseAnnotationBindingTestCase {
assertEquals( 1, nameAttrBinding.getRelationalValueBindings().size() ); assertEquals( 1, nameAttrBinding.getRelationalValueBindings().size() );
RelationalValueBinding valueBinding = nameAttrBinding.getRelationalValueBindings().get( 0 ); RelationalValueBinding valueBinding = nameAttrBinding.getRelationalValueBindings().get( 0 );
assertFalse( valueBinding.isDerived() ); assertFalse( valueBinding.isDerived() );
assertSame( table, valueBinding.getValue().getTable() ); assertSame( table, valueBinding.getTable() );
assertSame( column, valueBinding.getValue() ); assertSame( column, valueBinding.getValue() );
} }

View File

@ -216,7 +216,7 @@ public abstract class AbstractBasicBindingTests extends BaseUnitTestCase {
// locate the foreignKey // locate the foreignKey
boolean sourceColumnFound = false; boolean sourceColumnFound = false;
for ( ForeignKey fk : column.getTable().getForeignKeys() ) { for ( ForeignKey fk : relationalValueBinding.getTable().getForeignKeys() ) {
for ( Column sourceColumn : fk.getSourceColumns() ) { for ( Column sourceColumn : fk.getSourceColumns() ) {
if ( sourceColumn == column ) { if ( sourceColumn == column ) {
assertFalse( "source column not found in more than one foreign key", sourceColumnFound ); assertFalse( "source column not found in more than one foreign key", sourceColumnFound );

View File

@ -74,6 +74,7 @@ public class SimpleValueBindingTests extends BaseUnitTestCase {
List<RelationalValueBinding> valueBindings = new ArrayList<RelationalValueBinding>(); List<RelationalValueBinding> valueBindings = new ArrayList<RelationalValueBinding>();
valueBindings.add( valueBindings.add(
new RelationalValueBinding( new RelationalValueBinding(
table,
idColumn, idColumn,
true, true,
true true

View File

@ -179,7 +179,7 @@ public abstract class AbstractBasicCollectionBindingTests extends BaseUnitTestCa
List<RelationalValueBinding> keyRelationalValueBindings = keyBinding.getRelationalValueBindings(); List<RelationalValueBinding> keyRelationalValueBindings = keyBinding.getRelationalValueBindings();
assertNotNull( keyRelationalValueBindings ); assertNotNull( keyRelationalValueBindings );
for( RelationalValueBinding keyRelationalValueBinding : keyRelationalValueBindings ) { for( RelationalValueBinding keyRelationalValueBinding : keyRelationalValueBindings ) {
assertSame( collectionTable, keyRelationalValueBinding.getValue().getTable() ); assertSame( collectionTable, keyRelationalValueBinding.getTable() );
} }
assertEquals( 1, keyRelationalValueBindings.size() ); assertEquals( 1, keyRelationalValueBindings.size() );
assertEquals( 1, expectedKeyTargetAttributeBinding.getRelationalValueBindings().size() ); assertEquals( 1, expectedKeyTargetAttributeBinding.getRelationalValueBindings().size() );

View File

@ -72,42 +72,42 @@ public class GeneratedNamesForDifferentConstraintTypes {
// Add primary key columns to PK constraints and add generated name // Add primary key columns to PK constraints and add generated name
assertTrue( generatedNames.add( addColumnToPrimaryKey( pkColTab1 ).generateName() ) ); assertTrue( generatedNames.add( addColumnToPrimaryKey( tab1, pkColTab1 ).generateName() ) );
assertTrue( generatedNames.add( addColumnToPrimaryKey( pkColTab2 ).generateName() ) ); assertTrue( generatedNames.add( addColumnToPrimaryKey( tab2, pkColTab2 ).generateName() ) );
assertTrue( generatedNames.add( addColumnToPrimaryKey( pkColTab1Ref ).generateName() ) ); assertTrue( generatedNames.add( addColumnToPrimaryKey( refTab1, pkColTab1Ref ).generateName() ) );
assertTrue( generatedNames.add( addColumnToPrimaryKey( pkColTab2Ref ).generateName() ) ); assertTrue( generatedNames.add( addColumnToPrimaryKey( refTab2, pkColTab2Ref ).generateName() ) );
// add constraints to tab1 // add constraints to tab1
// add other types of constraints to the PK column for tab1 // add other types of constraints to the PK column for tab1
assertTrue( generatedNames.add( createUniqueKey( pkColTab1 ).generateName() ) ); assertTrue( generatedNames.add( createUniqueKey( tab1, pkColTab1 ).generateName() ) );
assertTrue( generatedNames.add( createIndex( pkColTab1 ).generateName() ) ); assertTrue( generatedNames.add( createIndex( tab1, pkColTab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( pkColTab1, tab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, pkColTab1, tab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( pkColTab1, tab1, col1Tab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, pkColTab1, tab1, col1Tab1 ).generateName() ) );
// add constraints to 1st non-PK column for tab1 (col1Tab1) // add constraints to 1st non-PK column for tab1 (col1Tab1)
assertTrue( generatedNames.add( createUniqueKey( col1Tab1 ).generateName() ) ); assertTrue( generatedNames.add( createUniqueKey( tab1, col1Tab1 ).generateName() ) );
assertTrue( generatedNames.add( createIndex( col1Tab1 ).generateName() ) ); assertTrue( generatedNames.add( createIndex( tab1, col1Tab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab1, tab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col1Tab1, tab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab1, tab1, col2Tab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col1Tab1, tab1, col2Tab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab1, refTab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col1Tab1, refTab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab1, refTab1, col1Tab1Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col1Tab1, refTab1, col1Tab1Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab1, refTab1, col2Tab1Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col1Tab1, refTab1, col2Tab1Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab1, refTab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col1Tab1, refTab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab1, refTab2, col1Tab2Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col1Tab1, refTab2, col1Tab2Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab1, refTab2, col2Tab2Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col1Tab1, refTab2, col2Tab2Ref ).generateName() ) );
// add constraints to 2nd non-PK column for tab1 (col2Tab1) // add constraints to 2nd non-PK column for tab1 (col2Tab1)
assertTrue( generatedNames.add( createUniqueKey( col2Tab1 ).generateName() ) ); assertTrue( generatedNames.add( createUniqueKey( tab1, col2Tab1 ).generateName() ) );
assertTrue( generatedNames.add( createIndex( col2Tab1 ).generateName() ) ); assertTrue( generatedNames.add( createIndex( tab1, col2Tab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab1, tab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col2Tab1, tab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab1, tab1, col1Tab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col2Tab1, tab1, col1Tab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab1, refTab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col2Tab1, refTab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab1, refTab1, col1Tab1Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col2Tab1, refTab1, col1Tab1Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab1, refTab1, col2Tab1Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col2Tab1, refTab1, col2Tab1Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab1, refTab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col2Tab1, refTab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab1, refTab2, col1Tab2Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col2Tab1, refTab2, col1Tab2Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab1, refTab2, col2Tab2Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab1, col2Tab1, refTab2, col2Tab2Ref ).generateName() ) );
// add multi-column constraints to tab1 // add multi-column constraints to tab1
List<Column> colsTab1 = new ArrayList<Column>( ); List<Column> colsTab1 = new ArrayList<Column>( );
@ -139,34 +139,34 @@ public class GeneratedNamesForDifferentConstraintTypes {
// add constraints to tab2 // add constraints to tab2
// add other types of constraints to the PK column for tab2 // add other types of constraints to the PK column for tab2
assertTrue( generatedNames.add( createUniqueKey( pkColTab2 ).generateName() ) ); assertTrue( generatedNames.add( createUniqueKey( tab2, pkColTab2 ).generateName() ) );
assertTrue( generatedNames.add( createIndex( pkColTab2 ).generateName() ) ); assertTrue( generatedNames.add( createIndex( tab2, pkColTab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( pkColTab2, tab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, pkColTab2, tab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( pkColTab2, tab2, col1Tab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, pkColTab2, tab2, col1Tab2 ).generateName() ) );
// add constraints to 1st non-PK column for tab2 (col1Tab2) // add constraints to 1st non-PK column for tab2 (col1Tab2)
assertTrue( generatedNames.add( createUniqueKey( col1Tab2 ).generateName() ) ); assertTrue( generatedNames.add( createUniqueKey( tab2, col1Tab2 ).generateName() ) );
assertTrue( generatedNames.add( createIndex( col1Tab2 ).generateName() ) ); assertTrue( generatedNames.add( createIndex( tab2, col1Tab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab2, tab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col1Tab2, tab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab2, tab2, col2Tab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col1Tab2, tab2, col2Tab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab2, refTab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col1Tab2, refTab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab2, refTab1, col1Tab1Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col1Tab2, refTab1, col1Tab1Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab2, refTab1, col2Tab1Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col1Tab2, refTab1, col2Tab1Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab2, refTab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col1Tab2, refTab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab2, refTab2, col1Tab2Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col1Tab2, refTab2, col1Tab2Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col1Tab2, refTab2, col2Tab2Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col1Tab2, refTab2, col2Tab2Ref ).generateName() ) );
// add constraints to 2nd non-PK column (col2Tab1) for tab1 // add constraints to 2nd non-PK column (col2Tab1) for tab1
assertTrue( generatedNames.add( createUniqueKey( col2Tab2 ).generateName() ) ); assertTrue( generatedNames.add( createUniqueKey( tab2, col2Tab2 ).generateName() ) );
assertTrue( generatedNames.add( createIndex( col2Tab2 ).generateName() ) ); assertTrue( generatedNames.add( createIndex( tab2, col2Tab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab2, tab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col2Tab2, tab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab2, tab2, col1Tab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col2Tab2, tab2, col1Tab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab2, refTab1 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col2Tab2, refTab1 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab2, refTab1, col1Tab1Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col2Tab2, refTab1, col1Tab1Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab2, refTab1, col2Tab1Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col2Tab2, refTab1, col2Tab1Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab2, refTab2 ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col2Tab2, refTab2 ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab2, refTab2, col1Tab2Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col2Tab2, refTab2, col1Tab2Ref ).generateName() ) );
assertTrue( generatedNames.add( createForeignKey( col2Tab2, refTab2, col2Tab2Ref ).generateName() ) ); assertTrue( generatedNames.add( createForeignKey( tab2, col2Tab2, refTab2, col2Tab2Ref ).generateName() ) );
} }
@Test @Test
@ -179,8 +179,9 @@ public class GeneratedNamesForDifferentConstraintTypes {
Column referencedPKColumn = referencedTable.locateColumn( COLUMN_NAMES[0] ); Column referencedPKColumn = referencedTable.locateColumn( COLUMN_NAMES[0] );
referencedTable.getPrimaryKey().addColumn( referencedPKColumn ); referencedTable.getPrimaryKey().addColumn( referencedPKColumn );
ForeignKey fkImplicitFKMapping = createForeignKey( fkColumn, referencedTable ); ForeignKey fkImplicitFKMapping = createForeignKey( table, fkColumn, referencedTable );
ForeignKey fkExplicitFKMappingToPK = createForeignKey( ForeignKey fkExplicitFKMappingToPK = createForeignKey(
table,
fkColumn, fkColumn,
referencedTable, referencedTable,
referencedPKColumn referencedPKColumn
@ -188,20 +189,20 @@ public class GeneratedNamesForDifferentConstraintTypes {
assertEquals( fkImplicitFKMapping.generateName(), fkExplicitFKMappingToPK.generateName() ); assertEquals( fkImplicitFKMapping.generateName(), fkExplicitFKMappingToPK.generateName() );
} }
private PrimaryKey addColumnToPrimaryKey(Column column) { private PrimaryKey addColumnToPrimaryKey(TableSpecification tableSpecification, Column column) {
PrimaryKey primaryKey = column.getTable().getPrimaryKey(); PrimaryKey primaryKey = tableSpecification.getPrimaryKey();
primaryKey.addColumn( column ); primaryKey.addColumn( column );
return primaryKey; return primaryKey;
} }
private ForeignKey createForeignKey(Column column, TableSpecification referencedTable ) { private ForeignKey createForeignKey(TableSpecification sourceTable, Column column, TableSpecification referencedTable ) {
ForeignKey foreignKey = column.getTable().createForeignKey( referencedTable, null ); ForeignKey foreignKey = sourceTable.createForeignKey( referencedTable, null );
foreignKey.addColumn( column ); foreignKey.addColumn( column );
return foreignKey; return foreignKey;
} }
private ForeignKey createForeignKey(Column column, TableSpecification referencedTable, Column referencedColumn ) { private ForeignKey createForeignKey(TableSpecification sourceTable, Column column, TableSpecification referencedTable, Column referencedColumn ) {
ForeignKey foreignKey = column.getTable().createForeignKey( referencedTable, null ); ForeignKey foreignKey = sourceTable.createForeignKey( referencedTable, null );
foreignKey.addColumnMapping( column, referencedColumn ); foreignKey.addColumnMapping( column, referencedColumn );
return foreignKey; return foreignKey;
} }
@ -218,8 +219,8 @@ public class GeneratedNamesForDifferentConstraintTypes {
return foreignKey; return foreignKey;
} }
private UniqueKey createUniqueKey(Column column) { private UniqueKey createUniqueKey(TableSpecification table, Column column) {
UniqueKey uniqueKey = column.getTable().getOrCreateUniqueKey( null ); UniqueKey uniqueKey = table.getOrCreateUniqueKey( null );
uniqueKey.addColumn( column ); uniqueKey.addColumn( column );
return uniqueKey; return uniqueKey;
} }
@ -232,8 +233,8 @@ public class GeneratedNamesForDifferentConstraintTypes {
return uniqueKey; return uniqueKey;
} }
private Index createIndex(Column column) { private Index createIndex(TableSpecification table, Column column) {
Index index = column.getTable().getOrCreateIndex( null ); Index index = table.getOrCreateIndex( null );
index.addColumn( column ); index.addColumn( column );
return index; return index;
} }

View File

@ -105,9 +105,7 @@ public class NamingStrategyTest extends BaseCoreFunctionalTestCase {
assertEquals( 1, singularAttributeBinding.getRelationalValueBindings().size() ); assertEquals( 1, singularAttributeBinding.getRelationalValueBindings().size() );
RelationalValueBinding valueBinding = singularAttributeBinding.getRelationalValueBindings().get( 0 ); RelationalValueBinding valueBinding = singularAttributeBinding.getRelationalValueBindings().get( 0 );
assertFalse( valueBinding.isDerived() ); assertFalse( valueBinding.isDerived() );
org.hibernate.metamodel.spi.relational.Column column = (org.hibernate.metamodel.spi.relational.Column) valueBinding Table table = (Table)valueBinding.getTable();
.getValue();
Table table = (Table)column.getTable();
assertEquals( "TAB_ITEMS_SEC", table.getPhysicalName().getText() ); assertEquals( "TAB_ITEMS_SEC", table.getPhysicalName().getText() );
@ -115,9 +113,7 @@ public class NamingStrategyTest extends BaseCoreFunctionalTestCase {
assertEquals( 1, singularAttributeBinding.getRelationalValueBindings().size() ); assertEquals( 1, singularAttributeBinding.getRelationalValueBindings().size() );
valueBinding = singularAttributeBinding.getRelationalValueBindings().get( 0 ); valueBinding = singularAttributeBinding.getRelationalValueBindings().get( 0 );
assertFalse( valueBinding.isDerived() ); assertFalse( valueBinding.isDerived() );
column = (org.hibernate.metamodel.spi.relational.Column) valueBinding table = (Table)valueBinding.getTable();
.getValue();
table = (Table)column.getTable();
assertEquals( "TAB_ITEMS", table.getPhysicalName().getText()); assertEquals( "TAB_ITEMS", table.getPhysicalName().getText());
} }

View File

@ -38,7 +38,6 @@ import static org.junit.Assert.assertTrue;
/** /**
* @author Gavin King * @author Gavin King
*/ */
@FailureExpectedWithNewMetamodel
public class UnionSubclassPropertyRefTest extends BaseCoreFunctionalTestCase { public class UnionSubclassPropertyRefTest extends BaseCoreFunctionalTestCase {
@Override @Override
public String[] getMappings() { public String[] getMappings() {

View File

@ -39,7 +39,6 @@ import static org.junit.Assert.assertNotNull;
* @author Strong Liu <stliu@redhat.com> * @author Strong Liu <stliu@redhat.com>
*/ */
@TestForIssue( jiraKey = "HHH-4825" ) @TestForIssue( jiraKey = "HHH-4825" )
@FailureExpectedWithNewMetamodel
public class SellCarTest extends BaseCoreFunctionalTestCase { public class SellCarTest extends BaseCoreFunctionalTestCase {
@Override @Override
public String[] getMappings() { public String[] getMappings() {

View File

@ -53,7 +53,6 @@ public class UnionSubclassTest extends BaseCoreFunctionalTestCase {
} }
@Test @Test
@FailureExpectedWithNewMetamodel
public void testUnionSubclass() { public void testUnionSubclass() {
Session s = openSession(); Session s = openSession();
Transaction t = s.beginTransaction(); Transaction t = s.beginTransaction();