Search in sources :

Example 6 with ERDAssociation

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;
}
Also used : ERDElement(org.jkiss.dbeaver.erd.model.ERDElement) ERDAssociation(org.jkiss.dbeaver.erd.model.ERDAssociation)

Example 7 with ERDAssociation

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;
}
Also used : ERDElement(org.jkiss.dbeaver.erd.model.ERDElement) ERDAssociation(org.jkiss.dbeaver.erd.model.ERDAssociation)

Example 8 with ERDAssociation

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);
    }
}
Also used : ERDAssociation(org.jkiss.dbeaver.erd.model.ERDAssociation)

Example 9 with ERDAssociation

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();
}
Also used : ERDAssociation(org.jkiss.dbeaver.erd.model.ERDAssociation)

Example 10 with ERDAssociation

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();
}
Also used : ERDAssociation(org.jkiss.dbeaver.erd.model.ERDAssociation)

Aggregations

ERDAssociation (org.jkiss.dbeaver.erd.model.ERDAssociation)16 ERDElement (org.jkiss.dbeaver.erd.model.ERDElement)4 FileOutputStream (java.io.FileOutputStream)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Bendpoint (org.eclipse.draw2d.Bendpoint)2 Dimension (org.eclipse.draw2d.geometry.Dimension)2 PointList (org.eclipse.draw2d.geometry.PointList)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 DBException (org.jkiss.dbeaver.DBException)2 ERDEntity (org.jkiss.dbeaver.erd.model.ERDEntity)2 ERDEntityAttribute (org.jkiss.dbeaver.erd.model.ERDEntityAttribute)2 AttributeListFigure (org.jkiss.dbeaver.erd.ui.figures.AttributeListFigure)2 EntityFigure (org.jkiss.dbeaver.erd.ui.figures.EntityFigure)2 AssociationPart (org.jkiss.dbeaver.erd.ui.part.AssociationPart)2 EntityPart (org.jkiss.dbeaver.erd.ui.part.EntityPart)2 DBSEntityConstraintType (org.jkiss.dbeaver.model.struct.DBSEntityConstraintType)2 XMLBuilder (org.jkiss.utils.xml.XMLBuilder)2