Search in sources :

Example 1 with EntitySyncController

use of org.apache.cayenne.modeler.dialog.objentity.EntitySyncController in project cayenne by apache.

the class DbEntitySyncAction method syncDbEntity.

protected void syncDbEntity() {
    ProjectController mediator = getProjectController();
    DbEntity dbEntity = mediator.getCurrentDbEntity();
    if (dbEntity != null) {
        Collection<ObjEntity> entities = dbEntity.getDataMap().getMappedEntities(dbEntity);
        if (entities.isEmpty()) {
            return;
        }
        EntityMergeSupport merger = new EntitySyncController(Application.getInstance().getFrameController(), dbEntity).createMerger();
        if (merger == null) {
            return;
        }
        merger.setNameGenerator(new PreserveRelationshipNameGenerator());
        DbEntitySyncUndoableEdit undoableEdit = new DbEntitySyncUndoableEdit((DataChannelDescriptor) mediator.getProject().getRootNode(), mediator.getCurrentDataMap());
        // filter out inherited entities, as we need to add attributes only to the roots
        filterInheritedEntities(entities);
        for (ObjEntity entity : entities) {
            DbEntitySyncUndoableEdit.EntitySyncUndoableListener listener = undoableEdit.new EntitySyncUndoableListener(entity);
            merger.addEntityMergeListener(listener);
            // we should not be trying to introspect the merger
            if (merger.isRemovingMeaningfulFKs()) {
                undoableEdit.addEdit(undoableEdit.new MeaningfulFKsUndoableEdit(entity, merger.getMeaningfulFKs(entity)));
            }
            if (merger.synchronizeWithDbEntity(entity)) {
                mediator.fireObjEntityEvent(new EntityEvent(this, entity, MapEvent.CHANGE));
            }
            merger.removeEntityMergeListener(listener);
        }
        application.getUndoManager().addEdit(undoableEdit);
    }
}
Also used : EntityMergeSupport(org.apache.cayenne.dbsync.merge.context.EntityMergeSupport) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent) DbEntitySyncUndoableEdit(org.apache.cayenne.modeler.undo.DbEntitySyncUndoableEdit) ProjectController(org.apache.cayenne.modeler.ProjectController) EntitySyncController(org.apache.cayenne.modeler.dialog.objentity.EntitySyncController)

Example 2 with EntitySyncController

use of org.apache.cayenne.modeler.dialog.objentity.EntitySyncController 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)

Aggregations

EntityMergeSupport (org.apache.cayenne.dbsync.merge.context.EntityMergeSupport)2 ObjEntity (org.apache.cayenne.map.ObjEntity)2 EntityEvent (org.apache.cayenne.map.event.EntityEvent)2 ProjectController (org.apache.cayenne.modeler.ProjectController)2 EntitySyncController (org.apache.cayenne.modeler.dialog.objentity.EntitySyncController)2 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)1 DbEntity (org.apache.cayenne.map.DbEntity)1 EntityDisplayEvent (org.apache.cayenne.modeler.event.EntityDisplayEvent)1 DbEntitySyncUndoableEdit (org.apache.cayenne.modeler.undo.DbEntitySyncUndoableEdit)1