Search in sources :

Example 26 with DbRelationship

use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.

the class FindAction method jumpToAttributeResult.

private static void jumpToAttributeResult(SearchResultEntry searchResultEntry, EditorView editor, DataChannelDescriptor domain) {
    DataMap map;
    Entity entity;
    if (searchResultEntry.getObject() instanceof Attribute) {
        map = ((Attribute) searchResultEntry.getObject()).getEntity().getDataMap();
        entity = ((Attribute) searchResultEntry.getObject()).getEntity();
    } else {
        map = ((Relationship) searchResultEntry.getObject()).getSourceEntity().getDataMap();
        entity = ((Relationship) searchResultEntry.getObject()).getSourceEntity();
    }
    buildAndSelectTreePath(map, entity, editor);
    if (searchResultEntry.getObject() instanceof Attribute) {
        AttributeDisplayEvent event = new AttributeDisplayEvent(editor.getProjectTreeView(), (Attribute) searchResultEntry.getObject(), entity, map, domain);
        event.setMainTabFocus(true);
        if (searchResultEntry.getObject() instanceof DbAttribute) {
            editor.getDbDetailView().currentDbAttributeChanged(event);
        } else {
            editor.getObjDetailView().currentObjAttributeChanged(event);
        }
    } else if (searchResultEntry.getObject() instanceof Relationship) {
        RelationshipDisplayEvent event = new RelationshipDisplayEvent(editor.getProjectTreeView(), (Relationship) searchResultEntry.getObject(), entity, map, domain);
        event.setMainTabFocus(true);
        if (searchResultEntry.getObject() instanceof DbRelationship) {
            editor.getDbDetailView().currentDbRelationshipChanged(event);
        } else {
            editor.getObjDetailView().currentObjRelationshipChanged(event);
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DetectedDbEntity(org.apache.cayenne.map.DetectedDbEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) EmbeddableAttributeDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayEvent) AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) DbAttribute(org.apache.cayenne.map.DbAttribute) ObjAttribute(org.apache.cayenne.map.ObjAttribute) Attribute(org.apache.cayenne.map.Attribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Relationship(org.apache.cayenne.map.Relationship) DbRelationship(org.apache.cayenne.map.DbRelationship) ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) DataMap(org.apache.cayenne.map.DataMap) RelationshipDisplayEvent(org.apache.cayenne.modeler.event.RelationshipDisplayEvent)

Example 27 with DbRelationship

use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.

the class RemoveRelationshipAction method removeDbRelationships.

public void removeDbRelationships(DbEntity entity, DbRelationship[] rels) {
    ProjectController mediator = getProjectController();
    for (DbRelationship rel : rels) {
        entity.removeRelationship(rel.getName());
        RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
        mediator.fireDbRelationshipEvent(e);
    }
    ProjectUtil.cleanObjMappings(mediator.getCurrentDataMap());
}
Also used : DbRelationship(org.apache.cayenne.map.DbRelationship) ProjectController(org.apache.cayenne.modeler.ProjectController) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 28 with DbRelationship

use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.

the class RemoveRelationshipAction method performAction.

@Override
public void performAction(ActionEvent e, boolean allowAsking) {
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    ProjectController mediator = getProjectController();
    ObjRelationship[] rels = getProjectController().getCurrentObjRelationships();
    if (rels != null && rels.length > 0) {
        if ((rels.length == 1 && dialog.shouldDelete("ObjRelationship", rels[0].getName())) || (rels.length > 1 && dialog.shouldDelete("selected ObjRelationships"))) {
            ObjEntity entity = mediator.getCurrentObjEntity();
            removeObjRelationships(entity, rels);
            Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, rels));
        }
    } else {
        DbRelationship[] dbRels = getProjectController().getCurrentDbRelationships();
        if (dbRels != null && dbRels.length > 0) {
            if ((dbRels.length == 1 && dialog.shouldDelete("DbRelationship", dbRels[0].getName())) || (dbRels.length > 1 && dialog.shouldDelete("selected DbRelationships"))) {
                DbEntity entity = mediator.getCurrentDbEntity();
                removeDbRelationships(entity, dbRels);
                Application.getInstance().getUndoManager().addEdit(new RemoveRelationshipUndoableEdit(entity, dbRels));
            }
        }
    }
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) RemoveRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit) ProjectController(org.apache.cayenne.modeler.ProjectController) ConfirmRemoveDialog(org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)

Example 29 with DbRelationship

use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.

the class InferRelationshipsControllerBase method createReversRelationship.

public void createReversRelationship(DbEntity eSourse, DbEntity eTarget) {
    InferredRelationship myir = new InferredRelationship();
    for (DbRelationship relationship : eSourse.getRelationships()) {
        for (DbJoin join : relationship.getJoins()) {
            if (((DbEntity) join.getSource().getEntity()).equals(eSourse) && ((DbEntity) join.getTarget().getEntity()).equals(eTarget)) {
                return;
            }
        }
    }
    myir.setSource(eSourse);
    myir.setTarget(eTarget);
    inferredRelationships.add(myir);
}
Also used : DbRelationship(org.apache.cayenne.map.DbRelationship) DbJoin(org.apache.cayenne.map.DbJoin)

Example 30 with DbRelationship

use of org.apache.cayenne.map.DbRelationship in project cayenne by apache.

the class ObjAttributeInfoDialog method setPath.

public boolean setPath(boolean isChange) {
    if (isChange()) {
        attributeSaved.setType(view.getTypeComboBox().getSelectedItem().toString());
        attributeSaved.setName(view.getAttributeName().getText());
    }
    if (!(attributeSaved instanceof EmbeddedAttribute) || isRegistredType(attributeSaved.getType())) {
        StringBuilder attributePath = new StringBuilder();
        StringBuilder pathStr = new StringBuilder();
        if (attribute.getEntity().getDbEntity() != null) {
            TreePath path = view.getPathBrowser().getSelectionPath();
            if (path.getLastPathComponent() instanceof DbAttribute) {
                Object[] pathComponents = path.getPath();
                for (int i = 0; i < pathComponents.length; i++) {
                    boolean attrOrRel = true;
                    if (pathComponents[i] instanceof DbAttribute) {
                        pathStr.append(((DbAttribute) pathComponents[i]).getName());
                        attributePath.append(((DbAttribute) pathComponents[i]).getName());
                    } else if (pathComponents[i] instanceof DbRelationship) {
                        pathStr.append(((DbRelationship) pathComponents[i]).getName());
                        attributePath.append(((DbRelationship) pathComponents[i]).getName());
                    } else {
                        attrOrRel = false;
                    }
                    if (i != pathComponents.length - 1 && attrOrRel) {
                        pathStr.append(" -> ");
                        attributePath.append(".");
                    }
                }
            }
        } else {
            view.getCurrentPathLabel().setText("");
        }
        view.getCurrentPathLabel().setText(pathStr.toString());
        if (attribute.getDbAttributePath() != null && !embeddableNames.contains(view.getTypeComboBox().getSelectedItem().toString())) {
            if (!attribute.getDbAttributePath().equals(attributePath.toString())) {
                attributeSaved.setDbAttributePath(attributePath.toString());
                if (!attribute.getDbAttributePath().equals(attributePath.toString()) && isChange) {
                    model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
                }
                return true;
            }
        } else {
            if (attributePath.length() > 0 || (attribute instanceof EmbeddedAttribute && !(attributeSaved instanceof EmbeddedAttribute))) {
                attributeSaved.setDbAttributePath(attributePath.toString());
                if (attributePath.length() == 0) {
                    model.setUpdatedValueAt(attributeSaved.getDbAttributePath(), row, 3);
                    return false;
                }
                return true;
            }
        }
    }
    return false;
}
Also used : TreePath(javax.swing.tree.TreePath) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddedAttribute(org.apache.cayenne.map.EmbeddedAttribute)

Aggregations

DbRelationship (org.apache.cayenne.map.DbRelationship)106 DbEntity (org.apache.cayenne.map.DbEntity)59 DbAttribute (org.apache.cayenne.map.DbAttribute)35 DbJoin (org.apache.cayenne.map.DbJoin)35 ObjEntity (org.apache.cayenne.map.ObjEntity)30 ObjRelationship (org.apache.cayenne.map.ObjRelationship)28 ObjAttribute (org.apache.cayenne.map.ObjAttribute)20 Test (org.junit.Test)15 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)13 ArrayList (java.util.ArrayList)11 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)10 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)9 DataMap (org.apache.cayenne.map.DataMap)9 Entity (org.apache.cayenne.map.Entity)8 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)8 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)8 HashMap (java.util.HashMap)6 ObjectId (org.apache.cayenne.ObjectId)6