Author: thomasobrien95
Date: Tue May 5 13:23:48 2009
New Revision: 3039
Modified:
trunk/src/ca/sqlpower/architect/swingui/CompareDMPanel.java
trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
trunk/src/ca/sqlpower/architect/swingui/SQLScriptDialog.java
trunk/src/ca/sqlpower/architect/swingui/action/ExportDDLAction.java
trunk/src/ca/sqlpower/architect/swingui/action/RefreshAction.java
Log:
Updated the SPSwingWorker implementations to use the thread safe
methods or override the impl versions where required.
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 Tue May 5
13:23:48 2009
@@ -367,7 +367,6 @@
try {
ProgressWatcher.watchProgress(progressBar, this);
- started = true;
db.populate();
} catch (SQLObjectException e) {
@@ -453,9 +452,7 @@
ProgressWatcher.watchProgress(progressBar, this);
// this populates the
schema parent (populate is not
// visible here)
- started = true;
finalSchemaParent.getChildren();
- finished = true;
}
/**
@@ -514,8 +511,8 @@
catalogSelect = null;
}
- // Overriding isFinished to be based on the state of db.
- public boolean isFinished() {
+ @Override
+ protected boolean isFinishedImpl() {
if (db != null) {
return db.isPopulated();
}
@@ -577,11 +574,9 @@
public void doStuff() throws SQLObjectException {
logger.debug("SCHEMA POPULATOR IS STARTED...");
//$NON-NLS-1$
ProgressWatcher.watchProgress(progressBar,
this);
- started = true;
SQLCatalog catToPopulate = (SQLCatalog)
catalogDropdown
.getSelectedItem();
catToPopulate.populate(); // this might take a
while
- finished = true;
}
/**
@@ -634,38 +629,13 @@
// TODO Document this class!!!!
private abstract class PopulateProgressMonitorableWorker extends
SPSwingWorker {
- boolean started = false;
- boolean finished = false;
-
public PopulateProgressMonitorableWorker(ArchitectSwingSession
session) {
super(session);
+ setJobSize(null);
+ setProgress(0);
+
setMessage(Messages.getString("CompareDMPanel.connectingToDatabase"));
//$NON-NLS-1$
}
- /**
- * Returns null, which will keep the monitor in indeterminate
mode.
- */
- public Integer getJobSize() {
- return null;
- }
-
- /**
- * Cannot measure progress of connecting to the database, so
always return 0
- */
- public int getProgress() {
- return 0;
- }
-
- public boolean isFinished() {
- return finished;
- }
-
- public String getMessage() {
- return
Messages.getString("CompareDMPanel.connectingToDatabase"); //$NON-NLS-1$
- }
-
- public boolean hasStarted() {
- return started;
- }
}
public synchronized JDialog getNewConnectionDialog() {
@@ -1256,12 +1226,8 @@
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);
@@ -1272,7 +1238,7 @@
logger.debug(message);
target.getDatabase().refresh();
}
- jobSize = sourceComp.getJobSize() +
targetComp.getJobSize();
+ setJobSize(sourceComp.getJobSize() +
targetComp.getJobSize());
logger.debug("Generating TableDiffs for source");
diff = sourceComp.generateTableDiffs();
logger.debug("Generating TableDiffs for
target");
@@ -1282,7 +1248,6 @@
}
public void cleanup() {
- finished = true;
reenableGUIComponents();
if (getDoStuffException() != null) {
Throwable exc = getDoStuffException();
@@ -1297,11 +1262,8 @@
logger.debug("cleanup finished"); //$NON-NLS-1$
}
- public Integer getJobSize() {
- return jobSize;
- }
-
- public String getMessage() {
+ @Override
+ protected String getMessageImpl() {
if (sourceComp.hasStarted()
&& !sourceComp.isFinished()) {
return sourceComp.getMessage();
} else if (targetComp.hasStarted()
&& !targetComp.isFinished()) {
@@ -1311,16 +1273,9 @@
}
}
- public int getProgress() {
+ @Override
+ protected int getProgressImpl() {
return sourceComp.getProgress() +
targetComp.getProgress();
- }
-
- public boolean hasStarted() {
- return started;
- }
-
- public boolean isFinished() {
- return finished;
}
};
Modified: trunk/src/ca/sqlpower/architect/swingui/PlayPen.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/PlayPen.java (original)
+++ trunk/src/ca/sqlpower/architect/swingui/PlayPen.java Tue May 5
13:23:48 2009
@@ -1439,11 +1439,6 @@
private List<SQLObject> sqlObjects;
private Point preferredLocation;
- private boolean hasStarted = false;
- private boolean finished = false;
- private String message = null;
- private int progress = 0;
- private Integer jobSize = null;
private String errorMessage = null;
private ProgressMonitor pm;
@@ -1458,27 +1453,10 @@
this.sqlObjects = sqlObjects;
this.preferredLocation = preferredLocation;
this.transferStyle = transferStyle;
- finished = false;
ProgressWatcher.watchProgress(pm, this);
this.pm = pm;
}
- public int getProgress() {
- return progress;
- }
-
- public Integer getJobSize() {
- return jobSize;
- }
-
- public boolean isFinished() {
- return finished;
- }
-
- public String getMessage() {
- return message;
- }
-
/**
* Combines the MonitorableWorker's canceled flag with the
* ProgressMonitor's.
@@ -1495,7 +1473,6 @@
logger.info("AddObjectsTask starting on
thread "+Thread.currentThread().getName()); //$NON-NLS-1$
session.getArchitectFrame().getContentPane().setCursor(new
Cursor(Cursor.WAIT_CURSOR));
try {
- hasStarted = true;
int tableCount = 0;
Iterator<SQLObject> soIt =
sqlObjects.iterator();
@@ -1504,7 +1481,7 @@
SQLObject so = soIt.next();
tableCount += SQLObjectUtils.countTablesSnapshot(so);
}
- jobSize = new Integer(tableCount);
+ setJobSize(new Integer(tableCount));
ensurePopulated(sqlObjects);
@@ -1528,7 +1505,7 @@
for (SQLObject so : soList) {
if (isCancelled()) break;
try {
- if (so instanceof SQLTable) progress++;
+ if (so instanceof SQLTable)
setProgress(getProgress() + 1);
ensurePopulated(so.getChildren());
} catch (SQLObjectException e) {
errorMessage = "Couldn't get children of " + so;
//$NON-NLS-1$
@@ -1571,19 +1548,19 @@
if (someData instanceof SQLTable) {
TablePane tp = importTableCopy((SQLTable) someData,
preferredLocation, duplicateProperties);
- message =
ArchitectUtils.truncateString(((SQLTable)someData).getName());
+
setMessage(ArchitectUtils.truncateString(((SQLTable)someData).getName()));
preferredLocation.x += tp.getPreferredSize().width
+ 5;
- progress++;
+ increaseProgress();
} else if (someData instanceof
SQLSchema) {
SQLSchema sourceSchema =
(SQLSchema) someData;
Iterator it =
sourceSchema.getChildren().iterator();
while (it.hasNext() &&
!isCancelled()) {
Object nextTable = it.next();
SQLTable sourceTable =
(SQLTable) nextTable;
- message =
ArchitectUtils.truncateString(sourceTable.getName());
+
setMessage(ArchitectUtils.truncateString(sourceTable.getName()));
TablePane tp = importTableCopy(sourceTable, preferredLocation,
duplicateProperties);
preferredLocation.x +=
tp.getPreferredSize().width + 5;
- progress++;
+ increaseProgress();
}
} else if (someData instanceof
SQLCatalog) {
SQLCatalog sourceCatalog =
(SQLCatalog) someData;
@@ -1595,20 +1572,20 @@
while (it.hasNext()
&& !isCancelled()) {
Object
nextTable = it.next();
SQLTable sourceTable = (SQLTable)
nextTable;
- message
= ArchitectUtils.truncateString(sourceTable.getName());
+
setMessage(ArchitectUtils.truncateString(sourceTable.getName()));
TablePane tp = importTableCopy(sourceTable, preferredLocation,
duplicateProperties);
preferredLocation.x += tp.getPreferredSize().width + 5;
-
progress++;
+
increaseProgress();
}
}
} else {
while (cit.hasNext() &&
!isCancelled()) {
Object nextTable = cit.next();
SQLTable
sourceTable = (SQLTable) nextTable;
- message =
ArchitectUtils.truncateString(sourceTable.getName());
+
setMessage(ArchitectUtils.truncateString(sourceTable.getName()));
TablePane tp = importTableCopy(sourceTable, preferredLocation,
duplicateProperties);
preferredLocation.x += tp.getPreferredSize().width + 5;
- progress++;
+
increaseProgress();
}
}
} else {
@@ -1619,14 +1596,12 @@
ASUtils.showExceptionDialog(session,
"Unexpected Exception During Import", e); //$NON-NLS-1$
} finally {
- finished = true;
session.getArchitectFrame().getContentPane().setCursor(new
Cursor(Cursor.DEFAULT_CURSOR));
- hasStarted = false;
session.getPlayPen().endCompoundEdit("Ending multi-select");
//$NON-NLS-1$
}
// deals with bug 1333, when the user tries to add inaccessible objects
to the PlayPen
- if (jobSize == 0) {
+ if (getJobSize() == 0) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JOptionPane.showMessageDialog(session.getArchitectFrame(),
@@ -1637,9 +1612,6 @@
}
}
- public boolean hasStarted () {
- return hasStarted;
- }
}
// -------------------- SQLOBJECT EVENT SUPPORT ---------------------
Modified: trunk/src/ca/sqlpower/architect/swingui/SQLScriptDialog.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/SQLScriptDialog.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/SQLScriptDialog.java Tue May 5
13:23:48 2009
@@ -322,13 +322,16 @@
private class ExecuteSQLScriptWorker extends SPSwingWorker {
- private int stmtsTried = 0;
private int stmtsCompleted = 0;
- private boolean finished = false;
- private boolean hasStarted = false;
public ExecuteSQLScriptWorker(ArchitectSwingSession session) {
super(session);
+ setMessage(null);
+ if (statements != null) {
+ setJobSize(new Integer(statements.size()));
+ } else {
+ setJobSize(null);
+ }
}
/**
@@ -336,14 +339,12 @@
*/
public void doStuff() {
- finished = false;
setCancelled(false);
- hasStarted = true;
- if (isCancelled() || finished) return;
+ if (isCancelled() || isFinished()) return;
SQLDatabase target = new SQLDatabase(targetDataSource);
statusLabel.setText(Messages.getString("SQLScriptDialog.creatingObjectsInTargetDb")
+ target.getDataSource() ); //$NON-NLS-1$
- stmtsTried = 0;
+ setProgress(0);
stmtsCompleted = 0;
logger.debug("the Target Database is: " + target.getDataSource());
//$NON-NLS-1$
@@ -354,11 +355,11 @@
try {
con = target.getConnection();
} catch (SQLObjectException ex) {
- finished = true;
+ setFinished(true);
throw new RuntimeException(
Messages.getString("SQLScriptDialog.couldNotConnectToTargetDb",
ex.getMessage()), ex); //$NON-NLS-1$
} catch (Exception ex) {
- finished = true;
+ setFinished(true);
logger.error("Unexpected exception in DDL generation", ex);
//$NON-NLS-1$
throw new
RuntimeException(Messages.getString("SQLScriptDialog.specifyATargetDb"));
//$NON-NLS-1$
}
@@ -367,7 +368,7 @@
logger.debug("the connection thinks it is: " +
con.getMetaData().getURL()); //$NON-NLS-1$
stmt = con.createStatement();
} catch (SQLException ex) {
- finished = true;
+ setFinished(true);
throw new
RuntimeException(Messages.getString("SQLScriptDialog.couldNotGenerateDDL",
ex.getMessage())); //$NON-NLS-1$
}
@@ -376,10 +377,10 @@
logger.info("Database Target: " + target.getDataSource());
//$NON-NLS-1$
logger.info("Playpen Dump: " +
target.getDataSource()); //$NON-NLS-1$
Iterator<DDLStatement> it =
statements.iterator();
- while (it.hasNext() && !finished &&
!isCancelled()) {
+ while (it.hasNext() && !isFinished() &&
!isCancelled()) {
DDLStatement ddlStmt = it.next();
try {
- stmtsTried++;
+ increaseProgress();
logger.info("executing: " +
ddlStmt.getSQLText()); //$NON-NLS-1$
stmt.executeUpdate(ddlStmt.getSQLText());
stmtsCompleted++;
@@ -414,7 +415,7 @@
}
if (isCancelled()) {
- finished = true;
+ setFinished(true);
// don't return, we might as well display how many statements ended
up being processed...
}
}
@@ -428,8 +429,8 @@
exc);
} finally {
final String resultsMessage =
- (stmtsCompleted == 0 ?
Messages.getString("SQLScriptDialog.didNotExecute",
String.valueOf(stmtsTried)) : //$NON-NLS-1$
- Messages.getString("SQLScriptDialog.successfullyExecuted",
String.valueOf(stmtsCompleted), String.valueOf(stmtsTried))); //$NON-NLS-1$
+ (stmtsCompleted == 0 ?
Messages.getString("SQLScriptDialog.didNotExecute",
String.valueOf(getProgress())) : //$NON-NLS-1$
+ Messages.getString("SQLScriptDialog.successfullyExecuted",
String.valueOf(stmtsCompleted), String.valueOf(getProgress())));
//$NON-NLS-1$
logger.info(resultsMessage);
JOptionPane.showMessageDialog(SQLScriptDialog.this, resultsMessage);
// flush and close the LogWriter
@@ -445,8 +446,6 @@
}
}
- finished = true;
-
}
/**
@@ -462,38 +461,10 @@
// ============= Monitorable Interface =============
- public Integer getJobSize() {
- if (statements != null) {
- return new Integer(statements.size());
- } else {
- return null;
- }
- }
-
- public int getProgress() {
- return stmtsTried;
- }
-
- public boolean isFinished() {
- return finished;
- }
-
- public String getMessage() {
- return null;
- }
-
public void cancelJob() {
this.setCancelled(true);
- finished = true;
+ setFinished(true);
}
-
- public boolean hasStarted() {
- return hasStarted;
- }
-
- public void setHasStarted(boolean hasStarted) {
- this.hasStarted = hasStarted;
- }
}
}
Modified:
trunk/src/ca/sqlpower/architect/swingui/action/ExportDDLAction.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/action/ExportDDLAction.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/action/ExportDDLAction.java Tue
May 5 13:23:48 2009
@@ -355,24 +355,28 @@
}
-
- public Integer getJobSize() {
+ @Override
+ protected Integer getJobSizeImpl() {
return cr.getJobSize();
}
- public String getMessage() {
+ @Override
+ protected String getMessageImpl() {
return cr.getMessage();
}
- public int getProgress() {
+ @Override
+ protected int getProgressImpl() {
return cr.getProgress();
}
- public boolean hasStarted() {
+ @Override
+ protected boolean hasStartedImpl() {
return cr.hasStarted();
}
- public boolean isFinished() {
+ @Override
+ protected boolean isFinishedImpl() {
return cr.isFinished();
}
@@ -437,23 +441,28 @@
}
}
- public Integer getJobSize() {
+ @Override
+ protected Integer getJobSizeImpl() {
return cr.getJobSize();
}
- public String getMessage() {
+ @Override
+ protected String getMessageImpl() {
return cr.getMessage();
}
- public int getProgress() {
+ @Override
+ protected int getProgressImpl() {
return cr.getProgress();
}
- public boolean hasStarted() {
+ @Override
+ protected boolean hasStartedImpl() {
return cr.hasStarted();
}
- public boolean isFinished() {
+ @Override
+ protected boolean isFinishedImpl() {
return cr.isFinished();
}
Modified: trunk/src/ca/sqlpower/architect/swingui/action/RefreshAction.java
==============================================================================
--- trunk/src/ca/sqlpower/architect/swingui/action/RefreshAction.java
(original)
+++ trunk/src/ca/sqlpower/architect/swingui/action/RefreshAction.java Tue
May 5 13:23:48 2009
@@ -59,52 +59,31 @@
private final Set<SQLDatabase> databasesToRefresh = new
HashSet<SQLDatabase>();
private final Component parent;
- private int progress;
- private boolean hasStarted;
- private boolean isFinished;
private SQLDatabase dbBeingRefreshed;
public RefreshMonitorableWorker(SwingWorkerRegistry registry,
Component parent, Set<SQLDatabase> dbs) {
super(registry);
this.parent = parent;
this.databasesToRefresh.addAll(dbs);
- hasStarted = false;
- isFinished = false;
+ setJobSize(null);
}
- public boolean isFinished() {
- return isFinished;
- }
-
- public boolean hasStarted() {
- return hasStarted;
- }
-
- public int getProgress() {
- return progress;
- }
-
- public String getMessage() {
+ @Override
+ protected String getMessageImpl() {
if (dbBeingRefreshed == null) {
return "Refreshing selected databases.";
}
return "Refreshing database " + dbBeingRefreshed.getName();
}
- public Integer getJobSize() {
- return null;
- }
-
@Override
public void doStuff() throws Exception {
- hasStarted = true;
- isFinished = false;
- progress = 0;
+ setProgress(0);
try {
for (SQLDatabase db : databasesToRefresh) {
dbBeingRefreshed = db;
db.refresh();
- progress++;
+ increaseProgress();
}
} catch (SQLObjectException ex) {
setDoStuffException(ex);
@@ -115,7 +94,6 @@
@Override
public void cleanup() throws Exception {
- isFinished = true;
if (getDoStuffException() != null) {
ASUtils.showExceptionDialogNoReport(parent, "Refresh
failed", getDoStuffException());
}