Search in sources :

Example 11 with EntityEvent

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

the class PKGeneratorPanel method resetStrategy.

protected void resetStrategy(DbEntity entity, boolean resetCustomSequence, boolean resetDBGenerated) {
    boolean hasChanges = false;
    if (resetCustomSequence && entity.getPrimaryKeyGenerator() != null) {
        entity.setPrimaryKeyGenerator(null);
        hasChanges = true;
    }
    if (resetDBGenerated) {
        for (DbAttribute a : entity.getPrimaryKeys()) {
            if (a.isGenerated()) {
                a.setGenerated(false);
                hasChanges = true;
            }
        }
    }
    if (hasChanges) {
        mediator.fireDbEntityEvent(new EntityEvent(this, entity));
    }
}
Also used : EntityEvent(org.apache.cayenne.map.event.EntityEvent) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 12 with EntityEvent

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

the class ObjEntitySyncAction method syncObjEntity.

protected void syncObjEntity() {
    ProjectController mediator = getProjectController();
    ObjEntity entity = mediator.getCurrentObjEntity();
    if (entity != null && entity.getDbEntity() != null) {
        EntityMergeSupport merger = new EntitySyncController(Application.getInstance().getFrameController(), entity).createMerger();
        if (merger == null) {
            return;
        }
        merger.setNameGenerator(new DbEntitySyncAction.PreserveRelationshipNameGenerator());
        if (merger.synchronizeWithDbEntity(entity)) {
            mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
            mediator.fireObjEntityDisplayEvent(new EntityDisplayEvent(this, entity, entity.getDataMap(), (DataChannelDescriptor) mediator.getProject().getRootNode()));
        }
    }
}
Also used : EntityMergeSupport(org.apache.cayenne.dbsync.merge.context.EntityMergeSupport) ObjEntity(org.apache.cayenne.map.ObjEntity) DataChannelDescriptor(org.apache.cayenne.configuration.DataChannelDescriptor) EntityDisplayEvent(org.apache.cayenne.modeler.event.EntityDisplayEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ProjectController(org.apache.cayenne.modeler.ProjectController) EntitySyncController(org.apache.cayenne.modeler.dialog.objentity.EntitySyncController)

Example 13 with EntityEvent

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

the class RemoveAction method removeDbEntity.

/**
 * Removes current DbEntity from its DataMap and fires "remove" EntityEvent.
 */
public void removeDbEntity(DataMap map, DbEntity ent) {
    ProjectController mediator = getProjectController();
    EntityEvent e = new EntityEvent(Application.getFrame(), ent, MapEvent.REMOVE);
    e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
    map.removeDbEntity(ent.getName(), true);
    mediator.fireDbEntityEvent(e);
}
Also used : EntityEvent(org.apache.cayenne.map.event.EntityEvent) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 14 with EntityEvent

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

the class RemoveAction method removeObjEntity.

/**
 * Removes current object entity from its DataMap.
 */
public void removeObjEntity(DataMap map, ObjEntity entity) {
    ProjectController mediator = getProjectController();
    EntityEvent e = new EntityEvent(Application.getFrame(), entity, MapEvent.REMOVE);
    e.setDomain((DataChannelDescriptor) mediator.getProject().getRootNode());
    map.removeObjEntity(entity.getName(), true);
    mediator.fireObjEntityEvent(e);
    // clone to be able to remove within iterator...
    for (QueryDescriptor query : new ArrayList<>(map.getQueryDescriptors())) {
        if (!QueryDescriptor.EJBQL_QUERY.equals(query.getType())) {
            Object root = query.getRoot();
            if (root == entity || (root instanceof String && root.toString().equals(entity.getName()))) {
                removeQuery(map, query);
            }
        }
    }
}
Also used : QueryDescriptor(org.apache.cayenne.map.QueryDescriptor) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ArrayList(java.util.ArrayList) ProjectController(org.apache.cayenne.modeler.ProjectController)

Example 15 with EntityEvent

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

the class CatalogUpdateController method updateCatalog.

protected void updateCatalog() {
    boolean doAll = isAllEntities();
    String defaultCatalog = dataMap.getDefaultCatalog();
    // set catalog for DbEntities
    for (DbEntity entity : dataMap.getDbEntities()) {
        if (doAll || Util.isEmptyString(entity.getCatalog())) {
            if (!Util.nullSafeEquals(defaultCatalog, entity.getCatalog())) {
                entity.setCatalog(defaultCatalog);
                // any way to batch events, a big change will flood the app
                // with entity events..?
                mediator.fireDbEntityEvent(new EntityEvent(this, entity));
            }
        }
    }
    // set catalog for procedures...
    for (Procedure procedure : dataMap.getProcedures()) {
        if (doAll || Util.isEmptyString(procedure.getCatalog())) {
            if (!Util.nullSafeEquals(defaultCatalog, procedure.getCatalog())) {
                procedure.setCatalog(defaultCatalog);
                // any way to batch events, a big change will flood the app
                // with procedure events..?
                mediator.fireProcedureEvent(new ProcedureEvent(this, procedure));
            }
        }
    }
    view.dispose();
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent) Procedure(org.apache.cayenne.map.Procedure)

Aggregations

EntityEvent (org.apache.cayenne.map.event.EntityEvent)36 DbEntity (org.apache.cayenne.map.DbEntity)14 ObjEntity (org.apache.cayenne.map.ObjEntity)13 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)7 ProjectController (org.apache.cayenne.modeler.ProjectController)6 Entity (org.apache.cayenne.map.Entity)5 Test (org.junit.Test)5 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)4 ArrayList (java.util.ArrayList)3 ProcedureEvent (org.apache.cayenne.configuration.event.ProcedureEvent)3 DbAttribute (org.apache.cayenne.map.DbAttribute)3 ObjAttribute (org.apache.cayenne.map.ObjAttribute)3 AttributeEvent (org.apache.cayenne.map.event.AttributeEvent)3 ValidationException (org.apache.cayenne.validation.ValidationException)3 ItemEvent (java.awt.event.ItemEvent)2 ItemListener (java.awt.event.ItemListener)2 QueryEvent (org.apache.cayenne.configuration.event.QueryEvent)2 EntityMergeSupport (org.apache.cayenne.dbsync.merge.context.EntityMergeSupport)2 Expression (org.apache.cayenne.exp.Expression)2 DbKeyGenerator (org.apache.cayenne.map.DbKeyGenerator)2