HHH-6356 Add PluralAttributeBinding.isInsertable() and isUpdatable()

This commit is contained in:
brmeyer 2012-11-06 16:38:00 -05:00
parent af66aec4a1
commit 4a92016f0c
3 changed files with 22 additions and 12 deletions

View File

@ -161,6 +161,7 @@ import static org.hibernate.metamodel.spi.source.ForeignKeyContributingSource.Jo
* @author Steve Ebersole
* @author Hardy Ferentschik
* @author Gail Badner
* @author Brett Meyer
*/
public class Binder {
private static final CoreMessageLogger log = Logger.getMessageLogger(
@ -496,6 +497,7 @@ public class Binder {
bindValues( attributeBindingContainer, keySource, attributeBinding.getAttribute(), collectionTable );
// Determine if the foreign key (source) column is updatable and also extract the columns out
// of the RelationalValueBindings.
boolean isInsertable = false;
boolean isUpdatable = false;
List<Column> sourceColumns = new ArrayList<Column>( sourceColumnBindings.size() );
for ( RelationalValueBinding relationalValueBinding : sourceColumnBindings ) {
@ -505,10 +507,12 @@ public class Binder {
throw new NotYetImplementedException(
"Derived values are not supported when creating a foreign key that targets columns." );
}
isInsertable = isInsertable || relationalValueBinding.isIncludeInInsert();
isUpdatable = isUpdatable || relationalValueBinding.isIncludeInUpdate();
sourceColumns.add( (Column) value );
}
keyBinding.setIncludedInUpdate( isUpdatable );
keyBinding.setInsertable( isInsertable );
keyBinding.setUpdatable( isUpdatable );
List<Column> targetColumns =
determineForeignKeyTargetColumns(
@ -1309,7 +1313,7 @@ public class Binder {
keyBinding.setForeignKey( fk );
}
}
keyBinding.setIncludedInUpdate( isUpdatable );
keyBinding.setUpdatable( isUpdatable );
}
else {
bindCollectionTableForeignKey( attributeBinding, attributeSource.getKeySource(), collectionTable );

View File

@ -38,7 +38,8 @@ public class PluralAttributeKeyBinding {
private final SingularAttributeBinding referencedAttributeBinding;
private ForeignKey foreignKey;
private boolean inverse;
private boolean isIncludedInUpdate;
private boolean insertable;
private boolean updatable;
// this knowledge can be implicitly resolved based on the typing information on the referenced owner attribute
private HibernateTypeDescriptor hibernateTypeDescriptor = new HibernateTypeDescriptor();
@ -130,14 +131,22 @@ public class PluralAttributeKeyBinding {
return false;
}
public void setIncludedInUpdate(boolean isIncludedInUpdate){
public void setInsertable( boolean insertable ){
this.insertable = insertable;
}
public boolean isInsertable() {
return insertable;
}
public void setUpdatable( boolean updatable ){
// The key is updatable if the foreign key *source* columns are updatable;
// We don't have the RelationalValueBindings for the FK source columns stored in ForeignKey
// so it needs to be set explicitly.
this.isIncludedInUpdate = isIncludedInUpdate;
this.updatable = updatable;
}
public boolean isUpdatable() {
return isIncludedInUpdate;
return updatable;
}
}

View File

@ -354,15 +354,12 @@ public class PropertyFactory {
null,
type,
lazyAvailable && pluralAttributeBinding.isLazy(),
// TODO: fix this when HHH-6356 is fixed; for now assume AbstractPluralAttributeBinding is updatable and insertable
true, // pluralAttributeBinding.isInsertable(),
true, //pluralAttributeBinding.isUpdatable(),
pluralAttributeBinding.getPluralAttributeKeyBinding().isInsertable(),
pluralAttributeBinding.getPluralAttributeKeyBinding().isUpdatable(),
false,
false,
true, // plural attributes are nullable
// TODO: fix this when HHH-6356 is fixed; for now assume AbstractPluralAttributeBinding is updatable and insertable
//alwaysDirtyCheck || pluralAttributeBinding.isUpdatable(),
true,
alwaysDirtyCheck || pluralAttributeBinding.getPluralAttributeKeyBinding().isUpdatable(),
pluralAttributeBinding.isIncludedInOptimisticLocking(),
cascadeStyle,
fetchMode