1 56 package org.objectstyle.cayenne.modeler.dialog.datamap; 57 58 import java.util.Iterator ; 59 60 import org.objectstyle.cayenne.map.DataMap; 61 import org.objectstyle.cayenne.map.DbEntity; 62 import org.objectstyle.cayenne.map.Procedure; 63 import org.objectstyle.cayenne.map.event.EntityEvent; 64 import org.objectstyle.cayenne.map.event.ProcedureEvent; 65 import org.objectstyle.cayenne.modeler.ProjectController; 66 import org.objectstyle.cayenne.util.Util; 67 import org.scopemvc.core.Control; 68 import org.scopemvc.core.ControlException; 69 import org.scopemvc.view.swing.SPanel; 70 71 76 public class SchemaUpdateController extends DefaultsPreferencesController { 77 78 public static final String ALL_CONTROL = "cayenne.modeler.datamap.defaultprefs.schema.radio"; 79 public static final String UNINIT_CONTROL = "cayenne.modeler.datamap.defaultprefs.schemanull.radio"; 80 81 public SchemaUpdateController(ProjectController mediator, DataMap dataMap) { 82 super(mediator, dataMap); 83 } 84 85 88 public void startup() { 89 SPanel view = new DefaultsPreferencesDialog(ALL_CONTROL, UNINIT_CONTROL); 90 view.setTitle("Update DbEntities Schema"); 91 setView(view); 92 super.startup(); 93 } 94 95 protected void doHandleControl(Control control) throws ControlException { 96 if (control.matchesID(UPDATE_CONTROL)) { 97 updateSchema(); 98 } 99 else { 100 super.doHandleControl(control); 101 } 102 } 103 104 protected void updateSchema() { 105 boolean doAll = ((DefaultsPreferencesModel) getModel()).isAllEntities(); 106 String defaultSchema = dataMap.getDefaultSchema(); 107 108 Iterator dbEntities = dataMap.getDbEntities().iterator(); 110 while (dbEntities.hasNext()) { 111 DbEntity entity = (DbEntity) dbEntities.next(); 112 if (doAll || Util.isEmptyString(entity.getSchema())) { 113 if (!Util.nullSafeEquals(defaultSchema, entity.getSchema())) { 114 entity.setSchema(defaultSchema); 115 116 mediator.fireDbEntityEvent(new EntityEvent(this, entity)); 119 } 120 } 121 } 122 123 Iterator procedures = dataMap.getProcedures().iterator(); 125 while (procedures.hasNext()) { 126 Procedure procedure = (Procedure) procedures.next(); 127 if (doAll || Util.isEmptyString(procedure.getSchema())) { 128 if (!Util.nullSafeEquals(defaultSchema, procedure.getSchema())) { 129 procedure.setSchema(defaultSchema); 130 131 mediator.fireProcedureEvent(new ProcedureEvent(this, procedure)); 134 } 135 } 136 } 137 shutdown(); 138 } 139 } | Popular Tags |