Author: mo.jeff
Date: Fri Apr 24 14:13:08 2009
New Revision: 3007
Modified:
trunk/src/ca/sqlpower/architect/diff/CompareSQL.java
trunk/src/ca/sqlpower/architect/swingui/CompareDMPanel.java
Log:
CompareDM now refreshes any physical databases before the compare, to fix a
bug where running compareDM, executing the given script, and then
immediately running a compareDM after the script is run woudl result in the
same SQL script being generated. The problem was that the SQLDatabase cache
still had the old database structure before the script was run.
Also modified it so that the progress bar will also be running when the
refresh happens as well as when the compare is happening, since the refresh
could take some time. I've left it as indeterminate when refreshing since
I'm not sure if there's a way to get the progress of a current refresh.
Modified: trunk/src/ca/sqlpower/architect/diff/CompareSQL.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/diff/CompareSQL.java (original)
+++ trunk/src/ca/sqlpower/architect/diff/CompareSQL.java Fri Apr 24
14:13:08 2009
@@ -98,6 +98,11 @@
* A switch to indicate whether indices with be compared.
*/
private boolean compareIndex;
+
+ /**
+ * Flags whether or not the comparison has started.
+ */
+ private boolean started;
/**
* The common constructor
@@ -142,10 +147,14 @@
setProgress(0);
setJobSize(targetTableSet.size()*2 + sourceTableSet.size()*2);
setFinished(false);
+ setStarted(false);
+
}
public List<DiffChunk<SQLObject>> generateTableDiffs() throws
SQLObjectException {
- try {
+ setStarted(true);
+ setFinished(false);
+ try {
Iterator<SQLTable> sourceIter =
sourceTableSet.iterator();
Iterator<SQLTable> targetIter =
targetTableSet.iterator();
SQLTable targetTable;
@@ -682,7 +691,11 @@
}
public synchronized boolean hasStarted() {
- return true;
+ return started;
+ }
+
+ private synchronized void setStarted(boolean started) {
+ this.started = started;
}
public synchronized boolean isFinished() {
Modified: trunk/src/ca/sqlpower/architect/swingui/CompareDMPanel.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/CompareDMPanel.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/CompareDMPanel.java Fri Apr 24
14:13:08 2009
@@ -67,17 +67,16 @@
import
ca.sqlpower.architect.swingui.CompareDMSettings.SourceOrTargetSettings;
import ca.sqlpower.sql.DataSourceCollection;
import ca.sqlpower.sql.SPDataSource;
-import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLCatalog;
import ca.sqlpower.sqlobject.SQLDatabase;
import ca.sqlpower.sqlobject.SQLObject;
+import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLSchema;
import ca.sqlpower.sqlobject.SQLTable;
import ca.sqlpower.swingui.ConnectionComboBoxModel;
import ca.sqlpower.swingui.MonitorableWorker;
import ca.sqlpower.swingui.ProgressWatcher;
import ca.sqlpower.swingui.SPSUtils;
-import ca.sqlpower.swingui.SPSwingWorker;
import ca.sqlpower.validation.Status;
import ca.sqlpower.validation.ValidateResult;
import ca.sqlpower.validation.swingui.StatusComponent;
@@ -1251,17 +1250,39 @@
reenableGUIComponents();
}
- SPSwingWorker compareWorker = new
SPSwingWorker(session) {
+ MonitorableWorker compareWorker = new
MonitorableWorker(session) {
private List<DiffChunk<SQLObject>> diff;
private List<DiffChunk<SQLObject>> diff1;
+ private String message;
+ private boolean started = false;
+ private boolean finished = false;
+ Integer jobSize = null;
+
public void doStuff() throws SQLObjectException
{
+ started = true;
+ if (source.physicalRadio.isSelected()) {
+ message = "Refreshing older database";
+ logger.debug(message);
+ source.getDatabase().refresh();
+ }
+ if (target.physicalRadio.isSelected()) {
+ message = "Refreshing newer database";
+ logger.debug(message);
+ target.getDatabase().refresh();
+ }
+ jobSize = sourceComp.getJobSize() +
targetComp.getJobSize();
+ logger.debug("Generating TableDiffs for source");
diff = sourceComp.generateTableDiffs();
+ logger.debug("Generating TableDiffs for
target");
diff1 = targetComp.generateTableDiffs();
+ message = "Finished";
+ logger.debug("Finished Compare");
}
public void cleanup() {
+ finished = true;
reenableGUIComponents();
if (getDoStuffException() != null) {
Throwable exc = getDoStuffException();
@@ -1276,12 +1297,38 @@
logger.debug("cleanup finished"); //$NON-NLS-1$
}
+ public Integer getJobSize() {
+ return jobSize;
+ }
+
+ public String getMessage() {
+ if (sourceComp.hasStarted()
&& !sourceComp.isFinished()) {
+ return sourceComp.getMessage();
+ } else if (targetComp.hasStarted()
&& !targetComp.isFinished()) {
+ return targetComp.getMessage();
+ } else {
+ return message;
+ }
+ }
+
+ public int getProgress() {
+ return sourceComp.getProgress() +
targetComp.getProgress();
+ }
+
+ public boolean hasStarted() {
+ return started;
+ }
+
+ public boolean isFinished() {
+ return finished;
+ }
+
};
- new Thread(compareWorker).start();
- ProgressWatcher pw = new ProgressWatcher(progressBar, sourceComp,
statusLabel);
+ ProgressWatcher pw = new ProgressWatcher(progressBar, compareWorker,
statusLabel);
pw.setHideLabelWhenFinished(true);
pw.start();
+ new Thread(compareWorker).start();
}
private void reenableGUIComponents() {