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);
}
}
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()));
}
}
}
Aggregations