Search in sources :

Example 11 with RelationshipEvent

use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.

the class RemoveRelationshipAction method removeObjRelationships.

public void removeObjRelationships(ObjEntity entity, ObjRelationship[] rels) {
    ProjectController mediator = getProjectController();
    for (ObjRelationship rel : rels) {
        entity.removeRelationship(rel.getName());
        RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, entity, MapEvent.REMOVE);
        mediator.fireObjRelationshipEvent(e);
    }
}
Also used : ObjRelationship(org.apache.cayenne.map.ObjRelationship) ProjectController(org.apache.cayenne.modeler.ProjectController) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 12 with RelationshipEvent

use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.

the class ResolveDbRelationshipDialog method save.

private void save() {
    stopEditing();
    DbJoinTableModel model = (DbJoinTableModel) table.getModel();
    boolean updatingReverse = model.getObjectList().size() > 0;
    // handle name update
    handleNameUpdate(relationship, name.getText().trim());
    model.commit();
    // maybe this is no longer valid
    if (relationship.isToDependentPK() && !relationship.isValidForDepPk()) {
        relationship.setToDependentPK(false);
    }
    // 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();
            reverseRelationship.setName(NameBuilder.builder(reverseRelationship, relationship.getTargetEntity()).baseName(reverseName.getText().trim()).name());
            reverseRelationship.setSourceEntity(relationship.getTargetEntity());
            reverseRelationship.setTargetEntityName(relationship.getSourceEntity());
            reverseRelationship.setToMany(!relationship.isToMany());
            relationship.getTargetEntity().addRelationship(reverseRelationship);
            // this is needed to update entity view...
            if (relationship.getSourceEntity() == relationship.getTargetEntity()) {
                getMediator().fireDbRelationshipEvent(new RelationshipEvent(this, reverseRelationship, reverseRelationship.getSourceEntity(), MapEvent.ADD));
            }
        } else {
            handleNameUpdate(reverseRelationship, reverseName.getText().trim());
        }
        Collection<DbJoin> 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()));
}
Also used : DbRelationship(org.apache.cayenne.map.DbRelationship) DbJoin(org.apache.cayenne.map.DbJoin) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 13 with RelationshipEvent

use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.

the class InferRelationshipsController method generateAction.

public void generateAction() {
    ProjectController mediator = application.getFrameController().getProjectController();
    InferRelationshipsUndoableEdit undoableEdit = new InferRelationshipsUndoableEdit();
    for (InferredRelationship temp : selectedEntities) {
        DbRelationship rel = new DbRelationship(uniqueRelName(temp.getSource(), temp.getName()));
        RelationshipEvent e = new RelationshipEvent(Application.getFrame(), rel, temp.getSource(), MapEvent.ADD);
        mediator.fireDbRelationshipEvent(e);
        rel.setSourceEntity(temp.getSource());
        rel.setTargetEntityName(temp.getTarget());
        DbJoin join = new DbJoin(rel, temp.getJoinSource().getName(), temp.getJoinTarget().getName());
        rel.addJoin(join);
        rel.setToMany(temp.isToMany());
        temp.getSource().addRelationship(rel);
        undoableEdit.addEdit(new CreateRelationshipUndoableEdit(temp.getSource(), new DbRelationship[] { rel }));
    }
    JOptionPane.showMessageDialog(this.getView(), getSelectedEntitiesSize() + " relationships generated");
    view.dispose();
}
Also used : DbRelationship(org.apache.cayenne.map.DbRelationship) CreateRelationshipUndoableEdit(org.apache.cayenne.modeler.undo.CreateRelationshipUndoableEdit) DbJoin(org.apache.cayenne.map.DbJoin) ProjectController(org.apache.cayenne.modeler.ProjectController) InferRelationshipsUndoableEdit(org.apache.cayenne.modeler.undo.InferRelationshipsUndoableEdit) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent)

Example 14 with RelationshipEvent

use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.

the class CreateRelationshipAction method fireDbRelationshipEvent.

/**
 * Fires events when a db rel was added
 */
static void fireDbRelationshipEvent(Object src, ProjectController mediator, DbEntity dbEntity, DbRelationship rel) {
    mediator.fireDbRelationshipEvent(new RelationshipEvent(src, rel, dbEntity, MapEvent.ADD));
    RelationshipDisplayEvent rde = new RelationshipDisplayEvent(src, rel, dbEntity, mediator.getCurrentDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode());
    mediator.fireDbRelationshipDisplayEvent(rde);
}
Also used : RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent) RelationshipDisplayEvent(org.apache.cayenne.modeler.event.RelationshipDisplayEvent)

Example 15 with RelationshipEvent

use of org.apache.cayenne.map.event.RelationshipEvent in project cayenne by apache.

the class RelationshipEventTest method testRelationship.

@Test
public void testRelationship() throws Exception {
    Object src = new Object();
    Relationship r = new DbRelationship();
    r.setName("xyz");
    RelationshipEvent e = new RelationshipEvent(src, null, null);
    e.setRelationship(r);
    assertSame(r, e.getRelationship());
}
Also used : Relationship(org.apache.cayenne.map.Relationship) DbRelationship(org.apache.cayenne.map.DbRelationship) DbRelationship(org.apache.cayenne.map.DbRelationship) RelationshipEvent(org.apache.cayenne.map.event.RelationshipEvent) Test(org.junit.Test)

Aggregations

RelationshipEvent (org.apache.cayenne.map.event.RelationshipEvent)15 DbRelationship (org.apache.cayenne.map.DbRelationship)6 ProjectController (org.apache.cayenne.modeler.ProjectController)4 ObjRelationship (org.apache.cayenne.map.ObjRelationship)3 DbEntity (org.apache.cayenne.map.DbEntity)2 DbJoin (org.apache.cayenne.map.DbJoin)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 RelationshipDisplayEvent (org.apache.cayenne.modeler.event.RelationshipDisplayEvent)2 RemoveRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.RemoveRelationshipUndoableEdit)2 ObjAttribute (org.apache.cayenne.map.ObjAttribute)1 Relationship (org.apache.cayenne.map.Relationship)1 AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)1 EntityEvent (org.apache.cayenne.map.event.EntityEvent)1 CreateRelationshipUndoableEdit (org.apache.cayenne.modeler.undo.CreateRelationshipUndoableEdit)1 InferRelationshipsUndoableEdit (org.apache.cayenne.modeler.undo.InferRelationshipsUndoableEdit)1 Test (org.junit.Test)1