relationship.setName(sourceEntityName);
undo.addNameUndo(relationship, oldName, sourceEntityName);
getMediator().fireDbRelationshipEvent(
new RelationshipEvent(this, relationship, relationship
.getSourceEntity(), oldName));
}
model.commit();
// check "to dep pk" setting,
// maybe this is no longer valid
if (relationship.isToDependentPK() && !relationship.isValidForDepPk()) {
relationship.setToDependentPK(false);
}
// If new reverse DbRelationship was created, add it to the target
// Don't create reverse with no joins - makes no sense...
if (updatingReverse) {
// If didn't find anything, create reverseDbRel
if (reverseRelationship == null) {
reverseRelationship = new DbRelationship(targetEntityName);
reverseRelationship.setSourceEntity(relationship.getTargetEntity());
reverseRelationship.setTargetEntity(relationship.getSourceEntity());
reverseRelationship.setToMany(!relationship.isToMany());
relationship.getTargetEntity().addRelationship(reverseRelationship);
// fire only if the relationship is to the same entity...
// this is needed to update entity view...
if (relationship.getSourceEntity() == relationship.getTargetEntity()) {
getMediator().fireDbRelationshipEvent(
new RelationshipEvent(
this,
reverseRelationship,
reverseRelationship.getSourceEntity(),
MapEvent.ADD));
}
}
else if (!Util
.nullSafeEquals(targetEntityName, reverseRelationship.getName())) {
String oldName = reverseRelationship.getName();
reverseRelationship.setName(targetEntityName);
undo.addNameUndo(reverseRelationship, oldName, targetEntityName);
getMediator().fireDbRelationshipEvent(
new RelationshipEvent(
this,
reverseRelationship,
reverseRelationship.getSourceEntity(),
oldName));
}
Collection reverseJoins = getReverseJoins();
reverseRelationship.setJoins(reverseJoins);
// check if joins map to a primary key of this entity
if (!relationship.isToDependentPK() && reverseRelationship.isValidForDepPk()) {
reverseRelationship.setToDependentPK(true);
}
}
Application.getInstance().getUndoManager().addEdit(undo);
getMediator()
.fireDbRelationshipEvent(
new RelationshipEvent(this, relationship, relationship
.getSourceEntity()));
}