Revision: 6349
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6349&view=rev
Author: wis775
Date: 2011-08-07 19:14:25 +0000 (Sun, 07 Aug 2011)
Log Message:
-----------
Store result of SQL in file: Better Exception Handling. If the export fails, the user gets an pop-up. The message panel will show the cause of the problem. e.g. an SQL Error.
Modified Paths:
--------------
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/TablePopupMenu.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/TableExportCsvCommand.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ResultSetExportData.java
trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties
trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/I18NStrings.properties
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java
Added Paths:
-----------
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ExportDataException.java
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/TablePopupMenu.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/TablePopupMenu.java 2011-08-07 17:58:24 UTC (rev 6348)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/TablePopupMenu.java 2011-08-07 19:14:25 UTC (rev 6349)
@@ -27,6 +27,7 @@
import javax.swing.*;
import net.sourceforge.squirrel_sql.fw.gui.action.*;
+import net.sourceforge.squirrel_sql.fw.gui.action.exportData.ExportDataException;
import net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.CopyWikiTableActionFactory;
import net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.ICopyWikiTableActionFactory;
import net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.ITableActionCallback;
@@ -434,7 +435,12 @@
{
if (_table != null)
{
- new TableExportCsvCommand(_table).execute();
+ try {
+ new TableExportCsvCommand(_table).execute();
+ } catch (ExportDataException e) {
+ // should never happen. Just convert it to a Runtime Exception.
+ throw new RuntimeException(e);
+ }
}
}
}
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java 2011-08-07 17:58:24 UTC (rev 6348)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java 2011-08-07 19:14:25 UTC (rev 6349)
@@ -23,11 +23,12 @@
import javax.swing.JOptionPane;
+import net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.ClobDescriptor;
import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
-import net.sourceforge.squirrel_sql.fw.gui.action.TableExportCsvCommand.i18n;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.DataExportCSVWriter;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.DataExportExcelWriter;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.DataExportXMLWriter;
+import net.sourceforge.squirrel_sql.fw.gui.action.exportData.ExportDataException;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.IExportData;
import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback;
import net.sourceforge.squirrel_sql.fw.util.StringManager;
@@ -61,10 +62,16 @@
static final StringManager s_stringMgr = StringManagerFactory
.getStringManager(AbstractExportCommand.class);
+ static interface i18n {
+ //i18n[TableExportCsvCommand.missingClobDataMsg=Found Clob placeholder
+ //({0}) amongst data to be exported. Continue exporting cell data?]
+ String missingClobDataMsg =
+ s_stringMgr.getString("TableExportCsvCommand.missingClobDataMsg",
+ ClobDescriptor.i18n.CLOB_LABEL);
+
+ String FAILED = s_stringMgr.getString("AbstractExportCommand.failed");
+ }
-
-
-
static ILogger s_log = LoggerController.createLogger(AbstractExportCommand.class);
private ProgressAbortCallback progressController = null;
@@ -134,7 +141,7 @@
}
}
- public void execute()
+ public void execute() throws ExportDataException
{
TableExportCsvController ctrl = createTableExportController();
@@ -172,10 +179,18 @@
}
}
- boolean writeFileSuccess = writeFile(ctrl, createExportData(ctrl));
+ boolean writeFileSuccess = false;
- if(writeFileSuccess)
- {
+ try {
+ writeFileSuccess = writeFile(ctrl, createExportData(ctrl));
+ } catch (ExportDataException e) {
+ // Show an error and re-throw the exception.
+ s_log.error(i18n.FAILED);
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.FAILED);
+ throw e;
+ }
+
+ if(writeFileSuccess){
String command = ctrl.getCommand();
if(null != command)
@@ -192,6 +207,9 @@
}
JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
}
+ }else{
+ s_log.info(i18n.FAILED);
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.FAILED);
}
}
@@ -209,10 +227,12 @@
protected abstract boolean checkMissingData(String separatorChar);
/**
- * @param ctrl
- * @return
+ * Creates the export data from the original source.
+ * @param ctrl the controller to use.
+ * @return the data for the export.
+ * @throws ExportDataException if any problem occurs while creating the data.
*/
- protected abstract IExportData createExportData(TableExportCsvController ctrl);
+ protected abstract IExportData createExportData(TableExportCsvController ctrl) throws ExportDataException;
/**
* @return the progressController
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java 2011-08-07 17:58:24 UTC (rev 6348)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java 2011-08-07 19:14:25 UTC (rev 6349)
@@ -23,6 +23,7 @@
import java.sql.Statement;
import net.sourceforge.squirrel_sql.fw.dialects.DialectType;
+import net.sourceforge.squirrel_sql.fw.gui.action.exportData.ExportDataException;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.IExportData;
import net.sourceforge.squirrel_sql.fw.gui.action.exportData.ResultSetExportData;
import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback;
@@ -33,16 +34,23 @@
/**
* Command for exporting a result set to a file.
+ *
* @author Stefan Willinger
- *
+ *
*/
public class ResultSetExportCommand extends AbstractExportCommand {
- static final StringManager s_stringMgr =
- StringManagerFactory.getStringManager(ResultSetExportCommand.class);
+ static final StringManager s_stringMgr = StringManagerFactory
+ .getStringManager(ResultSetExportCommand.class);
- static ILogger s_log = LoggerController.createLogger(ResultSetExportCommand.class);
+ static ILogger log = LoggerController.createLogger(ResultSetExportCommand.class);
+ static interface i18n {
+ // i18n[ResultSetExportCommand.errorExecuteStatement="Could not create the data for exporting."]
+ String ERROR_EXECUTE_STATEMENT = s_stringMgr
+ .getString("ResultSetExportCommand.errorExecuteStatement");
+ }
+
private ResultSet resultSet;
private DialectType dialect;
@@ -51,50 +59,38 @@
private Statement stmt;
- static interface i18n {
-
- }
-
- public ResultSetExportCommand(Statement stmt, String sql, DialectType dialect, ProgressAbortCallback progressController)
- {
- super(progressController);
- this.sql = sql;
- this.stmt = stmt;
- this.dialect = dialect;
- }
+ public ResultSetExportCommand(Statement stmt, String sql, DialectType dialect,
+ ProgressAbortCallback progressController) {
+ super(progressController);
+ this.sql = sql;
+ this.stmt = stmt;
+ this.dialect = dialect;
+ }
-
-
-
- /**
- *
+ /**
+ *
* @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#checkMissingData(java.lang.String)
*/
- @Override
+ @Override
protected boolean checkMissingData(String sepChar) {
- return false;
+ return false;
}
-
-
-
- /**
- * @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#createExportData()
- */
- @Override
- protected IExportData createExportData(TableExportCsvController ctrl) {
- try {
- super.progress("Running the query");
- this.resultSet = stmt.executeQuery(sql);
- return new ResultSetExportData(this.resultSet, dialect);
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#createExportData()
+ */
+ @Override
+ protected IExportData createExportData(TableExportCsvController ctrl) throws ExportDataException{
+ try {
+ super.progress("Running the query");
+ this.resultSet = stmt.executeQuery(sql);
+ return new ResultSetExportData(this.resultSet, dialect);
} catch (SQLException e) {
- throw new RuntimeException("Could not create the data for exporting.", e);
+ log.error(i18n.ERROR_EXECUTE_STATEMENT, e);
+ throw new ExportDataException(i18n.ERROR_EXECUTE_STATEMENT, e);
}
- }
+ }
-
-
-
/**
* @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#createTableExportController()
*/
@@ -102,7 +98,5 @@
protected TableExportCsvController createTableExportController() {
return new ResultSetExportCsvController();
}
-
-
}
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/TableExportCsvCommand.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/TableExportCsvCommand.java 2011-08-07 17:58:24 UTC (rev 6348)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/TableExportCsvCommand.java 2011-08-07 19:14:25 UTC (rev 6349)
@@ -23,31 +23,17 @@
*/
public class TableExportCsvCommand extends AbstractExportCommand
{
- static final StringManager s_stringMgr =
- StringManagerFactory.getStringManager(TableExportCsvCommand.class);
static ILogger s_log = LoggerController.createLogger(TableExportCsvCommand.class);
-
JTable _table;
-
- static interface i18n {
- //i18n[TableExportCsvCommand.missingClobDataMsg=Found Clob placeholder
- //({0}) amongst data to be exported. Continue exporting cell data?]
- String missingClobDataMsg =
- s_stringMgr.getString("TableExportCsvCommand.missingClobDataMsg",
- ClobDescriptor.i18n.CLOB_LABEL);
- }
-
+
public TableExportCsvCommand(JTable table)
{
super();
_table = table;
}
-
-
-
/**
*
* @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#checkMissingData(java.lang.String)
@@ -80,8 +66,6 @@
}
-
-
/**
* @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#createExportData()
*/
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ExportDataException.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ExportDataException.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ExportDataException.java 2011-08-07 19:14:25 UTC (rev 6349)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2011 Stefan Willinger
+ * wi...@us...
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+package net.sourceforge.squirrel_sql.fw.gui.action.exportData;
+
+/**
+ * Exception to indicate a serious problem while dealing with {@link IExportData}.
+ * If this exception occurs, there is no way to continue the export progress.
+ * @author Stefan Willinger
+ *
+ */
+public class ExportDataException extends Exception {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Constructor, if the error depends on a other Exception (e.g. a SQLException)
+ * @param message The message
+ * @param cause The cause of the problem.
+ */
+ public ExportDataException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Constructor, if the error does not depend on a other Exception.
+ * @param message The occurred error.
+ */
+ public ExportDataException(String message) {
+ super(message);
+ }
+
+}
Property changes on: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ExportDataException.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ResultSetExportData.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ResultSetExportData.java 2011-08-07 17:58:24 UTC (rev 6348)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ResultSetExportData.java 2011-08-07 19:14:25 UTC (rev 6349)
@@ -28,6 +28,10 @@
import net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.CellComponentFactory;
import net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.DataTypeGeneral;
import net.sourceforge.squirrel_sql.fw.dialects.DialectType;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
/**
* The implementation of {@link IExportData} for exporting data of a {@link ResultSet}
@@ -39,6 +43,22 @@
*/
public class ResultSetExportData implements IExportData {
+ /** Logger for this class. */
+ private final static ILogger log =
+ LoggerController.createLogger(ResultSetExportData.class);
+
+ /** Internationalized strings for this class */
+ private static final StringManager s_stringMgr =
+ StringManagerFactory.getStringManager(ResultSetExportData.class);
+
+ static interface i18n
+ {
+ // i18n[ResultSetExportData.defaultLoadingPrefix="Error while reading the result set."]
+ String ERROR_READING_RESULTSET = s_stringMgr.getString("ResultSetExportData.errorReadingResultSet");
+
+ }
+
+
/**
* The result set to work on.
*/
@@ -69,7 +89,7 @@
int columnCount = this.resultSet.getMetaData().getColumnCount();
for (int i = 1; i <= columnCount; i++) {
- colDispDef.add(new ColumnDisplayDefinition(resultSet, i, dialect));
+ colDispDef.add(new ColumnDisplayDefinition(resultSet, i, this.dialect));
}
}
@@ -131,7 +151,8 @@
rowIndex++;
return data;
} catch (SQLException e) {
- throw new RuntimeException("Error while reading the result set.");
+ log.error(i18n.ERROR_READING_RESULTSET, e);
+ throw new RuntimeException(i18n.ERROR_READING_RESULTSET, e);
}
}
@@ -145,7 +166,8 @@
boolean next = resultSet.next();
return next;
} catch (SQLException e) {
- throw new RuntimeException("Error while reading the result set.");
+ log.error(i18n.ERROR_READING_RESULTSET, e);
+ throw new RuntimeException(i18n.ERROR_READING_RESULTSET, e);
}
}
};
Modified: trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties
===================================================================
--- trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties 2011-08-07 17:58:24 UTC (rev 6348)
+++ trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties 2011-08-07 19:14:25 UTC (rev 6349)
@@ -35,6 +35,7 @@
TableExportCsvCommand.failedToExecuteCommand=Failed to execute\n{0}\nError message\n{1}\nSee last log entry for details.
TableExportCsvCommand.missingClobDataMsg=Found Clob placeholder({0}) amongst data to be exported. Continue exporting cell data?
TableExportCsvCommand.writeFileSuccess=Export to file "{0}" is complete.
+AbstractExportCommand.failed=Failed to export the SQL Select statement into a file.
TableExportCsvController.fileChooserTitel=Choose export file
TableExportCsvController.fileChooserButton=Choose
@@ -50,3 +51,5 @@
TableExportCsvDlg.formatXML=Export XML file
TableExportCsvDlg.useGlobalPrefsFormatingExcel=Use formatting as configured in Global Prefs (recommended for MS Excel)
+
+ResultSetExportCommand.errorExecuteStatement=Could not create the data for exporting.
Modified: trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/I18NStrings.properties
===================================================================
--- trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/I18NStrings.properties 2011-08-07 17:58:24 UTC (rev 6348)
+++ trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/exportData/I18NStrings.properties 2011-08-07 19:14:25 UTC (rev 6349)
@@ -3,3 +3,5 @@
AbstractDataExportFileWriter.finishedLoading=Finished with {0} rows.
AbstractDataExportFileWriter.closingTheFile=Closing the file.
AbstractDataExportFileWriter.done=Done.
+
+ResultSetExportData.errorReadingResultSet=Error while reading the result set.
\ No newline at end of file
Modified: trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java
===================================================================
--- trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java 2011-08-07 17:58:24 UTC (rev 6348)
+++ trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java 2011-08-07 19:14:25 UTC (rev 6349)
@@ -32,6 +32,7 @@
import net.sourceforge.squirrel_sql.fw.dialects.DialectType;
import net.sourceforge.squirrel_sql.fw.gui.action.ResultSetExportCommand;
import net.sourceforge.squirrel_sql.fw.gui.action.TableExportCsvDlg;
+import net.sourceforge.squirrel_sql.fw.gui.action.exportData.ExportDataException;
import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback;
import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
@@ -127,9 +128,11 @@
unmanagedConnection.close();
}
}
- } catch (Exception e) {
- getSession().showErrorMessage(e);
- e.printStackTrace();
+ }catch (Exception e) {
+ if(e.getCause() != null){
+ getSession().showErrorMessage(e.getCause());
+ }
+ getSession().showErrorMessage(e.getMessage());
} finally {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|