Search in sources :

Example 21 with ObjRelationship

use of org.apache.cayenne.map.ObjRelationship 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 22 with ObjRelationship

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

the class WarningDialogByDbTargetChange method showWarningDialog.

/*
      Check the situation, when targetEntity in DbRelationship was changed.
      After we have two cases:
          - the user agrees to accept changes (all ObjRelationships and ObjAttributes),
            that are related to current targetEntity and set new targetEntity.
          - the user doesn't agree and wanna return back.
    */
public static boolean showWarningDialog(ProjectController mediator, DbRelationship relationship) {
    Collection<ObjRelationship> objRelationshipsForDbRelationship = ProjectUtil.findObjRelationshipsForDbRelationship(mediator, relationship);
    Collection<ObjAttribute> fObjAttributesForDbRelationship = ProjectUtil.findObjAttributesForDbRelationship(mediator, relationship);
    if (fObjAttributesForDbRelationship.isEmpty() && objRelationshipsForDbRelationship.isEmpty()) {
        return true;
    }
    JPanel dialogPanel = new JPanel();
    dialogPanel.setLayout(new BorderLayout());
    JLabel textLabel = new JLabel(String.format("<html><p>Following ObjAttributes and ObjRelationships " + "<br>will be affected by change of DbRelationship <br> '%s'" + " target and must be fixed manually. " + "<br>Are you sure you want to proceed?</p><br></html>", relationship.getName()));
    dialogPanel.add(textLabel, BorderLayout.NORTH);
    DefaultListModel<String> model = new DefaultListModel<>();
    JList<String> objects = new JList<>(model);
    JScrollPane scrollPane = new JScrollPane(objects);
    if (!objRelationshipsForDbRelationship.isEmpty()) {
        model.addElement("Relationships: ");
        for (ObjRelationship objRelationship : objRelationshipsForDbRelationship) {
            model.addElement(objRelationship.getSourceEntity().getName() + "." + objRelationship.getName());
        }
    }
    if (!fObjAttributesForDbRelationship.isEmpty()) {
        model.addElement("Attributes: ");
        for (ObjAttribute objAttribute : fObjAttributesForDbRelationship) {
            model.addElement(objAttribute.getEntity().getName() + "." + objAttribute.getName());
        }
    }
    dialogPanel.add(scrollPane, BorderLayout.SOUTH);
    int result = JOptionPane.showConfirmDialog(Application.getFrame(), dialogPanel, "Warning", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    return (result == JOptionPane.OK_OPTION);
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) ObjAttribute(org.apache.cayenne.map.ObjAttribute)

Example 23 with ObjRelationship

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

the class ObjRelationshipInfo method valueChanged.

/**
 * Sets list of DB Relationships current ObjRelationship is mapped to
 */
public void valueChanged(TreeSelectionEvent e) {
    TreePath selectedPath = e.getPath();
    // at least two elements to constitute a valid ordering path
    if (selectedPath == null || selectedPath.getPathCount() < 2) {
        return;
    }
    Relationship rel = (Relationship) selectedPath.getLastPathComponent();
    DbEntity target = (DbEntity) rel.getTargetEntity();
    /**
     * Initialize root with one of mapped ObjEntities.
     */
    Collection<ObjEntity> objEntities = target.getDataMap().getMappedEntities(target);
    List<DbRelationship> relPath = new Vector<DbRelationship>(selectedPath.getPathCount() - 1);
    for (int i = 1; i < selectedPath.getPathCount(); i++) {
        relPath.add((DbRelationship) selectedPath.getPathComponent(i));
    }
    setDbRelationships(relPath);
    updateCollectionChoosers();
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) TreePath(javax.swing.tree.TreePath) DbEntity(org.apache.cayenne.map.DbEntity) Relationship(org.apache.cayenne.map.Relationship) DbRelationship(org.apache.cayenne.map.DbRelationship) ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbRelationship(org.apache.cayenne.map.DbRelationship) Vector(java.util.Vector)

Example 24 with ObjRelationship

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

the class DeleteRulesIT method changeDeleteRule.

private int changeDeleteRule(int deleteRule) {
    ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
    ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B.getName());
    int oldRule = relationship.getDeleteRule();
    relationship.setDeleteRule(deleteRule);
    return oldRule;
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship)

Example 25 with ObjRelationship

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

the class DeleteRulesIT method restoreReverse.

private void restoreReverse(ObjRelationship reverse) {
    ObjEntity entity = context.getEntityResolver().getObjEntity(DeleteRuleFlatA.class);
    ObjRelationship relationship = entity.getRelationship(DeleteRuleFlatA.FLAT_B.getName());
    relationship.getTargetEntity().addRelationship(reverse);
    context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatA");
    context.getEntityResolver().getClassDescriptorMap().removeDescriptor("DeleteRuleFlatB");
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjRelationship(org.apache.cayenne.map.ObjRelationship)

Aggregations

ObjRelationship (org.apache.cayenne.map.ObjRelationship)84 ObjEntity (org.apache.cayenne.map.ObjEntity)48 ObjAttribute (org.apache.cayenne.map.ObjAttribute)27 DbRelationship (org.apache.cayenne.map.DbRelationship)26 Test (org.junit.Test)24 DbEntity (org.apache.cayenne.map.DbEntity)18 DbAttribute (org.apache.cayenne.map.DbAttribute)15 DbJoin (org.apache.cayenne.map.DbJoin)14 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)12 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)12 ObjectId (org.apache.cayenne.ObjectId)10 ToManyProperty (org.apache.cayenne.reflect.ToManyProperty)9 ToOneProperty (org.apache.cayenne.reflect.ToOneProperty)9 ArrayList (java.util.ArrayList)8 AttributeProperty (org.apache.cayenne.reflect.AttributeProperty)8 PropertyVisitor (org.apache.cayenne.reflect.PropertyVisitor)8 List (java.util.List)7 EJBQLException (org.apache.cayenne.ejbql.EJBQLException)7 DataMap (org.apache.cayenne.map.DataMap)7 HashMap (java.util.HashMap)6