use of org.jkiss.dbeaver.erd.model.ERDAssociation in project dbeaver by dbeaver.
the class AssociationReconnectTargetCommand method canExecute.
/**
* Makes sure that foreign key doesn't reconnect to itself or try to create
* a relationship which already exists
*/
@Override
public boolean canExecute() {
boolean returnVal = true;
ERDElement foreignKeyEntity = relationship.getSourceEntity();
if (foreignKeyEntity.equals(targetEntity)) {
returnVal = false;
} else {
List<ERDAssociation> relationships = targetEntity.getReferences();
for (ERDAssociation relationship : relationships) {
if (relationship.getSourceEntity().equals(sourceEntity) && relationship.getTargetEntity().equals(targetEntity)) {
returnVal = false;
break;
}
}
}
return returnVal;
}
use of org.jkiss.dbeaver.erd.model.ERDAssociation in project dbeaver by dbeaver.
the class AssociationReconnectSourceCommand method canExecute.
/**
* Makes sure that primary key doesn't reconnect to itself or try to create
* a relationship which already exists
*/
@Override
public boolean canExecute() {
boolean returnVal = true;
ERDElement primaryEntity = association.getTargetEntity();
// cannot connect to itself
if (primaryEntity.equals(sourceEntity)) {
returnVal = false;
} else {
List<ERDAssociation> relationships = sourceEntity.getAssociations();
for (ERDAssociation relationship : relationships) {
if (relationship.getTargetEntity().equals(targetEntity) && relationship.getSourceEntity().equals(sourceEntity)) {
returnVal = false;
break;
}
}
}
return returnVal;
}
use of org.jkiss.dbeaver.erd.model.ERDAssociation in project dbeaver by dbeaver.
the class EntityDeleteCommand method deleteRelationships.
private void deleteRelationships(ERDEntity t) {
this.foreignKeyRelationships.addAll(t.getAssociations());
// for all relationships where current entity is foreign key
for (ERDAssociation association : foreignKeyRelationships) {
association.getTargetEntity().removeReferenceAssociation(association, true);
t.removeAssociation(association, true);
}
// for all relationships where current entity is primary key
this.primaryKeyRelationships.addAll(t.getReferences());
for (ERDAssociation r : primaryKeyRelationships) {
r.getSourceEntity().removeAssociation(r, true);
t.removeReferenceAssociation(r, true);
}
}
use of org.jkiss.dbeaver.erd.model.ERDAssociation in project dbeaver by dbeaver.
the class EntityDeleteCommand method restoreRelationships.
private void restoreRelationships() {
for (ERDAssociation r : foreignKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
foreignKeyRelationships.clear();
for (ERDAssociation r : primaryKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
primaryKeyRelationships.clear();
}
use of org.jkiss.dbeaver.erd.model.ERDAssociation in project dbeaver by serge-rider.
the class EntityDeleteCommand method restoreRelationships.
private void restoreRelationships() {
for (ERDAssociation r : foreignKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
foreignKeyRelationships.clear();
for (ERDAssociation r : primaryKeyRelationships) {
r.getSourceEntity().addAssociation(r, true);
r.getTargetEntity().addReferenceAssociation(r, true);
}
primaryKeyRelationships.clear();
}
Aggregations