Revision: 6339
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6339&view=rev
Author: wis775
Date: 2011-08-04 21:26:15 +0000 (Thu, 04 Aug 2011)
Log Message:
-----------
SQL Scripts Plugin: Added "Store result of SQL into file". This new function allows the user to store the result of the selected SQL directly into a file,
instead of showing a result table. This is avaiable in the tools pop-up (sql2file) and the menu (Session ==> Scripts ==> Store result of SQL in file).
There are really few new features. The main work was refactoring of TableExportCSVCommand to convert the access to the data structure into a more generic way, so that the source of the data are less important. Now, the source of the data could be a ResultSet or a JTable.
Modified Paths:
--------------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/ISession.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/Session.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/mainpanel/ISQLExecuter.java
trunk/sql12/doc/src/main/resources/changes.txt
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/TableExportCsvController.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/util/ISessionProperties.java
trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties
trunk/sql12/fw/src/test/java/net/sourceforge/squirrel_sql/fw/gui/action/TableExportCsvCommandTest.java
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/SQLScriptPlugin.java
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/AbortController.java
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateDataScriptCommand.java
trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/sqlscript.properties
trunk/sql12/plugins/sqlscript/src/main/resources/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/I18NStrings.properties
Added Paths:
-----------
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/IAbortEventHandler.java
trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.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/ResultSetExportCsvController.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/AbstractDataExportFileWriter.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/DataExportCSVWriter.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/DataExportExcelWriter.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/DataExportXMLWriter.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ExportDataColumn.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/ExportDataRow.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/IDataExportWriter.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/IExportData.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/IExportDataCell.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/IExportDataRow.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/JTableExportData.java
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/sql/IAbortController.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ISQLExecutionCallback.java
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/sql/ProgressAbortCallback.java
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/AbstractDataScriptCommand.java
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLAction.java
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/CreateFileOfCurrentSQLCommand.java
Removed Paths:
-------------
trunk/sql12/plugins/sqlscript/src/main/java/net/sourceforge/squirrel_sql/plugins/sqlscript/table_script/IAbortController.java
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/IAbortEventHandler.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/IAbortEventHandler.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/IAbortEventHandler.java 2011-08-04 21:26:15 UTC (rev 6339)
@@ -0,0 +1,32 @@
+/*
+ * 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.client.gui;
+
+/**
+ * Interface, to handle a cancel event of a {@link ProgressAbortDialog}
+ * @author Stefan Willinger
+ *
+ */
+public interface IAbortEventHandler {
+
+ /**
+ * Called, if a cancel of the operation was requested
+ */
+ void cancel();
+}
Property changes on: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/IAbortEventHandler.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java (rev 0)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java 2011-08-04 21:26:15 UTC (rev 6339)
@@ -0,0 +1,430 @@
+/*
+ * 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.client.gui;
+
+import java.awt.Dialog;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
+import java.awt.Insets;
+import java.awt.Window;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.text.DateFormat;
+import java.util.Date;
+
+import javax.swing.BorderFactory;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JProgressBar;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+
+import net.sourceforge.squirrel_sql.fw.gui.GUIUtils;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.StringUtilities;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+
+/**
+ * A monitor, which provide certain information to the user about a long running operation.
+ * The user get information about the progress of a long running operation. In addition to the progress bar, each step is reported in a
+ * "history area".
+ * This monitor provides the opportunity to cancel the operation.
+ * Sometimes it is not known, how many tasks must be completed, until the whole operation is finished. For this case, the monitor can be run in "indeterminate" mode.
+ * Depending on indeterminate or not, we can or cann't claim that the overall progress is finished.
+ * @see JProgressBar#isIndeterminate()
+ * @author Stefan Willinger
+ *
+ */
+public class ProgressAbortDialog extends JDialog implements ProgressAbortCallback{
+ /**
+ * serialVersionUID
+ */
+ private static final long serialVersionUID = 1L;
+
+ /** Logger for this class. */
+ public final static ILogger s_log = LoggerController.createLogger(ProgressCallBackDialog.class);
+
+ /** Internationalized strings for this class */
+ private static final StringManager s_stringMgr =
+ StringManagerFactory.getStringManager(ProgressCallBackDialog.class);
+
+ static interface i18n
+ {
+ // i18n[ProgressCallBackDialog.defaultLoadingPrefix=Loading:]
+ String DEFAULT_LOADING_PREFIX = s_stringMgr.getString("ProgressCallBackDialog.defaultLoadingPrefix");
+
+ // i18n[ProgressCallBackDialog.initialLoadingPrefix=Loading...]
+ String INITIAL_LOADING_PREFIX = s_stringMgr.getString("ProgressCallBackDialog.initialLoadingPrefix");
+ }
+
+ /**
+ * Dateformat for the hisotry area.
+ */
+ private DateFormat dateFormat = DateFormat.getTimeInstance();
+
+
+ /**
+ * The number of task, until the opeartion is completed.
+ */
+ private int itemCount = 0;
+
+ /**
+ * The progressbar itself
+ */
+ private JProgressBar progressBar = null;
+
+ /**
+ * The place to show the current task
+ */
+ private JLabel statusLabel = null;
+
+ private String _loadingPrefix = i18n.DEFAULT_LOADING_PREFIX;
+
+ /**
+ * True, if we dont know, how many tasks are neccesary to complete the operation
+ * @see JProgressBar#setIndeterminate(boolean)
+ */
+ private boolean indeterminate;
+
+ /**
+ * A callback handler, if the user decided to abort the operation.
+ */
+ private IAbortEventHandler abortHandler;
+
+ private JButton cancelButton;
+
+ /**
+ * Area to display the already completed tasks of this operation.
+ */
+ private JTextArea historyArea;
+
+ /**
+ * Description of the long running operation.
+ */
+ private JLabel taskDescriptionLabel;
+
+ /**
+ * Flag, if the operation should be canceled
+ */
+ private boolean canceled;
+
+ /**
+ * Constructor which accepts a Dialog owner
+ *
+ * @param owner
+ * the owner Dialog from which the dialog is displayed or null if this dialog has no owner
+ * @param title
+ * the String to display in the dialog's title bar
+ * @param totalItems
+ * the total number of items at which point progress will indicate complete
+ * @param indeterminate true, if the {@link JProgressBar} should be used in the indeterminate mode.
+ * @param abortHandler If the underlying tasks maybe aborted, then a abort Handler is needed. Otherwise null.
+ * @see JProgressBar#setIndeterminate(boolean)
+ */
+ public ProgressAbortDialog(Dialog owner, String title, String description, int totalItems, boolean indeterminate, IAbortEventHandler abortHandler)
+ {
+ super(owner, title);
+ init(description, totalItems, indeterminate, abortHandler);
+ }
+
+ /**
+ * Constructor which accepts a Frame owner
+ *
+ * @param owner
+ * the owner Frame from which the dialog is displayed or null if this dialog has no owner
+ * @param title
+ * the String to display in the dialog's title bar
+ * @param totalItems
+ * the total number of items at which point progress will indicate complete
+ * @param indeterminate true, if the {@link JProgressBar} should be used in the indeterminate mode.
+ * @param abortHandler If the underlying tasks maybe aborted, then a abort Handler is needed. Otherwise null.
+ * @see JProgressBar#setIndeterminate(boolean)
+ */
+ public ProgressAbortDialog(Frame owner, String title, String description, int totalItems, boolean indeterminate, IAbortEventHandler abortHandler)
+ {
+ super(owner, title);
+ setLocationRelativeTo(owner);
+ init(description, totalItems, indeterminate, abortHandler);
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#setTotalItems(int)
+ */
+ @Override
+ public void setTotalItems(int totalItems)
+ {
+ itemCount = totalItems;
+ progressBar.setMaximum(totalItems);
+ }
+
+ /**
+ * Sets the text that is displayed before each thing being loaded. By default this is the string
+ * "Loading:".
+ *
+ * @param loadingPrefix
+ */
+ @Override
+ public void setLoadingPrefix(String loadingPrefix)
+ {
+ if (loadingPrefix != null)
+ {
+ _loadingPrefix = loadingPrefix;
+ }
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#currentlyLoading(java.lang.String)
+ */
+ @Override
+ public void currentlyLoading(final String simpleName)
+ {
+ final StringBuilder statusText = new StringBuilder();
+ statusText.append(_loadingPrefix);
+ statusText.append(" ");
+ statusText.append(simpleName);
+
+ appendToHistory(statusText.toString());
+
+ try
+ {
+ GUIUtils.processOnSwingEventThread(new Runnable()
+ {
+ public void run()
+ {
+ statusLabel.setText(statusText.toString());
+ progressBar.setValue(progressBar.getValue() + 1);
+
+ if (finishedLoading())
+ {
+ ProgressAbortDialog.this.setVisible(false);
+ return;
+ }
+ }
+ });
+ }
+ catch (Exception e)
+ {
+ s_log.error("Unexpected exception: " + e.getMessage(), e);
+ }
+ }
+
+ /**
+ * @param string
+ */
+ private void appendToHistory(String string) {
+ if(this.historyArea != null){
+ StringBuilder sb = new StringBuilder();
+ sb.append(dateFormat.format(new Date()));
+ sb.append(": ");
+ sb.append(string);
+ sb.append(StringUtilities.getEolStr());
+ this.historyArea.append(sb.toString());
+ this.historyArea.setCaretPosition(historyArea.getDocument().getLength());
+ }
+ }
+
+ /**
+ * Checks, if the overall progress is finished.
+ * If this monitor runs in indeterminate mode, we didn't know, if the progress is finished.
+ * Otherwise, the finish state is interpreted, if we have reached the necessary task count.
+ * @see net.sourceforge.squirrel_sql.fw.sql.ProgressCallBack#finishedLoading()
+ */
+ @Override
+ public boolean finishedLoading()
+ {
+ if(this.indeterminate){
+ return false;
+ }
+ return progressBar.getValue() == itemCount;
+ }
+
+ /**
+ * Dispose this monitor.
+ * @see java.awt.Window#dispose()
+ */
+ @Override
+ public void dispose()
+ {
+ GUIUtils.processOnSwingEventThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ callDisposeFromSuperClass();
+ }
+ });
+ }
+
+ /**
+ * Since {@link #dispose()} uses an {@link Runnable}, we needs an
+ * delegate to call the overridden dispose method.
+ */
+ private void callDisposeFromSuperClass(){
+ super.dispose();
+ }
+
+ /**
+ * @see java.awt.Dialog#setVisible(boolean)
+ */
+ @Override
+ public void setVisible(final boolean b)
+ {
+ GUIUtils.processOnSwingEventThread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ callSetVisibleFromSuperClass(b);
+ }
+ });
+ }
+
+ /**
+ * Since {@link #setVisible(boolean)} uses an {@link Runnable}, we needs an
+ * delegate to call the overridden setVisible method.
+ */
+ private void callSetVisibleFromSuperClass(final boolean b){
+ super.setVisible(b);
+ }
+
+
+ private void init(String description, int totalItems, boolean intermediate, IAbortEventHandler abortHandler)
+ {
+ itemCount = totalItems;
+ this.indeterminate = intermediate;
+ this.abortHandler = abortHandler;
+ final Window owner = super.getOwner();
+ final ProgressAbortDialog dialog = this;
+ createGUI(description);
+ setLocationRelativeTo(owner);
+ dialog.setVisible(true);
+ }
+
+ private void createGUI(String description)
+ {
+ JPanel dialogPanel = new JPanel(new GridBagLayout());
+ dialogPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
+ GridBagConstraints c;
+
+ c = new GridBagConstraints();
+ c.gridx = 0;
+ c.gridy = 0;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.anchor = GridBagConstraints.WEST;
+ c.insets = new Insets(4, 0, 4, 0);
+ taskDescriptionLabel = new JLabel(description);
+ dialogPanel.add(taskDescriptionLabel, c);
+
+ c.gridy++;
+ c.insets = new Insets(4, 10, 4, 10);
+ statusLabel = new JLabel(i18n.INITIAL_LOADING_PREFIX);
+ dialogPanel.add(statusLabel, c);
+
+ c.gridy++;
+ c.weightx = 1.0;
+ progressBar = new JProgressBar(0, itemCount);
+ progressBar.setIndeterminate(indeterminate);
+ dialogPanel.add(progressBar, c);
+
+ c.gridy++;
+ c.fill = GridBagConstraints.BOTH;
+ c.weightx=1.0;
+ c.weighty=1.0;
+ historyArea = new JTextArea();
+ historyArea.setEditable(false);
+ JScrollPane jScrollPane = new JScrollPane(historyArea);
+ dialogPanel.add(jScrollPane, c);
+
+
+ if(abortHandler != null){
+ cancelButton = new JButton("Cancel");
+ cancelButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ appendToHistory("Canceling the operation");
+ canceled = true;
+ cancelButton.setEnabled(false);
+ abortHandler.cancel();
+
+ }
+ });
+
+ c.gridy++;
+ c.anchor = GridBagConstraints.WEST;
+ c.fill = GridBagConstraints.HORIZONTAL;
+ c.weightx=0.0;
+ c.weighty=0.0;
+ dialogPanel.add(cancelButton, c);
+ }
+
+ super.getContentPane().add(dialogPanel);
+ super.pack();
+ super.setSize(new Dimension(400, 400));
+ super.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
+ }
+
+ /**
+ * Just for playing...
+ */
+ public static void main(String[] args) throws Exception {
+ IAbortEventHandler handler = new IAbortEventHandler() {
+
+ @Override
+ public void cancel() {
+ System.out.println("echo");
+ }
+ };
+
+ ProgressCallBack dialog = new ProgressAbortDialog((Frame)null, "myTitle", "myDescription", 0, true, handler);
+ Thread.sleep(3000);
+ dialog.currentlyLoading("Running query");
+ Thread.sleep(3000);
+ dialog.currentlyLoading("1 Row(s) exported");
+ Thread.sleep(3000);
+ dialog.currentlyLoading("100 Row(s) exported");
+ Thread.sleep(3000);
+ dialog.currentlyLoading("1000 Row(s) exported");
+ dialog.currentlyLoading("Finished");
+
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.IAbortController#isStop()
+ */
+ @Override
+ public boolean isStop() {
+ return this.canceled;
+ }
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.sql.IAbortController#isVisble()
+ */
+ @Override
+ public boolean isVisble() {
+ return super.isVisible();
+ }
+}
Property changes on: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/gui/ProgressAbortDialog.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/ISession.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/ISession.java 2011-08-03 23:24:32 UTC (rev 6338)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/ISession.java 2011-08-04 21:26:15 UTC (rev 6339)
@@ -20,6 +20,11 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+import java.sql.SQLException;
+
+import javax.swing.Action;
+import javax.swing.JComponent;
+
import net.sourceforge.squirrel_sql.client.IApplication;
import net.sourceforge.squirrel_sql.client.gui.db.ISQLAliasExt;
import net.sourceforge.squirrel_sql.client.gui.desktopcontainer.ISessionWidget;
@@ -36,12 +41,10 @@
import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
import net.sourceforge.squirrel_sql.fw.sql.ISQLDriver;
+import net.sourceforge.squirrel_sql.fw.sql.SQLConnection;
import net.sourceforge.squirrel_sql.fw.util.ExceptionFormatter;
import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
-import javax.swing.*;
-import java.sql.SQLException;
-
/**
* The current session.
*/
@@ -378,5 +381,13 @@
void showErrorMessage(String msg);
void showWarningMessage(String msg);
-
+
+ /**
+ * Create a new connection, which is not associated with the current session.
+ * The new {@link SQLConnection} will is based on the same alias, user name and password of the current session. But it will be not associated with the session.
+ * Please note, that a commit and roll back on the current session will not affect the new created connection.
+ * The caller have to manage the connection by himself. Especially commit, roll back, close and so on.
+ * @return A new connection for the alias of the current session.
+ */
+ public SQLConnection createUnmanagedConnection();
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/Session.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/Session.java 2011-08-03 23:24:32 UTC (rev 6338)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/Session.java 2011-08-04 21:26:15 UTC (rev 6339)
@@ -68,6 +68,7 @@
import net.sourceforge.squirrel_sql.fw.sql.SQLConnectionState;
import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
import net.sourceforge.squirrel_sql.fw.sql.TokenizerSessPropsInteractions;
+import net.sourceforge.squirrel_sql.fw.util.BaseException;
import net.sourceforge.squirrel_sql.fw.util.DefaultExceptionFormatter;
import net.sourceforge.squirrel_sql.fw.util.ExceptionFormatter;
import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
@@ -1192,4 +1193,22 @@
_msgHandler.showWarningMessage(msg);
}
+ /**
+ * @see net.sourceforge.squirrel_sql.client.session.ISession#createUnmanagedConnection()
+ */
+ public SQLConnection createUnmanagedConnection() {
+ SQLConnectionState connState = new SQLConnectionState();
+
+ OpenConnectionCommand cmd = new OpenConnectionCommand(_app, _alias,
+ _user, _password, connState.getConnectionProperties());
+ try {
+ cmd.execute();
+ } catch (BaseException e) {
+ showErrorMessage(e);
+ return null;
+ }
+
+ return cmd.getSQLConnection();
+ }
+
}
Modified: trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/mainpanel/ISQLExecuter.java
===================================================================
--- trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/mainpanel/ISQLExecuter.java 2011-08-03 23:24:32 UTC (rev 6338)
+++ trunk/sql12/app/src/main/java/net/sourceforge/squirrel_sql/client/session/mainpanel/ISQLExecuter.java 2011-08-04 21:26:15 UTC (rev 6339)
@@ -28,6 +28,7 @@
* This is the interface that can store executors for SQL.
*
*/
+@Deprecated
public interface ISQLExecuter
{
/** Returns the title of this executor.*/
Modified: trunk/sql12/doc/src/main/resources/changes.txt
===================================================================
--- trunk/sql12/doc/src/main/resources/changes.txt 2011-08-03 23:24:32 UTC (rev 6338)
+++ trunk/sql12/doc/src/main/resources/changes.txt 2011-08-04 21:26:15 UTC (rev 6339)
@@ -7,6 +7,11 @@
Enhancements:
+
+SQL Scripts Plugin: Added "Store result of SQL into file". This new function allows the user to store the result of the selected SQL directly into a file,
+ instead of showing a result table. This is avaiable in the tools pop-up (sql2file) and the menu (Session ==> Scripts ==> Store result of SQL in file).
+
+
DBCopy Plugin: (Feature request #3291501) This plugin now has a command-line interface (via DBCopyCLI). See
DBCopy plugin documentation for usage details.
@@ -93,6 +98,8 @@
Bug-fixes:
+The column numbers of the header columns are now correct, when exporting the result table as XML.
+
When displaying the content of a table, the dialog "Please wait while the query is executed" may not dispose.
This may occurs only for tables of a "In Memory Database" with only a few rows of data.
Added: 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 (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java 2011-08-04 21:26:15 UTC (rev 6339)
@@ -0,0 +1,243 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.io.IOException;
+
+import javax.swing.JOptionPane;
+
+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.IExportData;
+import net.sourceforge.squirrel_sql.fw.sql.ProgressAbortCallback;
+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;
+
+/**
+ * Abstract command for exporting Data.
+ * This command exports the specified {@link IExportData}. The main configuration of the export could be managed with the {@link TableExportCsvController}.
+ * A {@link ProgressAbortCallback} can monitor the progress, but there must not be a such monitor.
+ * There are several target formats supported:
+ * <li>CSV</li>
+ * <li>XML</li>
+ * <li>XLS</li>
+ * But be aware, exporting to the excel format may use huge heap space, because the data structure must be build in memory.
+ * <p>
+ * The basic idea is, that Squirrel is able to export each table organized data structure by the same way.
+ * Independent, if the source of the data is a JTable, a result set or whatever. Its only important, that the data is tabulated. This is ensured by the
+ * interface {@link IExportData}. There are existing some DataExportWriters for various target formats.
+ *
+ * <b>Note:</b> This class is the result of a refactoring task. The code was taken from TableExportCsvCommand.
+ * @see DataExportCSVWriter
+ * @see DataExportXMLWriter
+ * @see DataExportExcelWriter
+ *
+ * @author Stefan Willinger
+ *
+ */
+public abstract class AbstractExportCommand {
+ static final StringManager s_stringMgr = StringManagerFactory
+ .getStringManager(AbstractExportCommand.class);
+ static ILogger s_log = LoggerController.createLogger(AbstractExportCommand.class);
+ private boolean cancel;
+ private ProgressAbortCallback progressController = null;
+
+ /**
+ * @param progressController
+ */
+ public AbstractExportCommand() {
+
+ }
+
+ /**
+ * @param progressController
+ */
+ public AbstractExportCommand(ProgressAbortCallback progressController) {
+ this.progressController =progressController;
+ }
+
+
+ protected boolean writeFile(TableExportCsvController ctrl, IExportData data) {
+ File file = null;
+ try {
+
+ file = ctrl.getFile();
+ if (null != file.getParentFile()) {
+ file.getParentFile().mkdirs();
+ }
+
+ boolean includeHeaders = ctrl.includeHeaders();
+
+ if (TableExportCsvController.EXPORT_FORMAT_CSV == ctrl.getExportFormat()) {
+ return new DataExportCSVWriter(file, ctrl, includeHeaders, progressController).write(data);
+ } else if (TableExportCsvController.EXPORT_FORMAT_XLS == ctrl.getExportFormat()) {
+ return new DataExportExcelWriter(file, ctrl, includeHeaders, progressController).write(data);
+ } else if (TableExportCsvController.EXPORT_FORMAT_XML == ctrl.getExportFormat()) {
+ return new DataExportXMLWriter(file, ctrl, includeHeaders, progressController).write(data);
+ } else {
+ throw new IllegalStateException("Unknown export format " + ctrl.getExportFormat());
+ }
+
+ } catch (Exception e) {
+
+ Object[] params = new Object[] { file, e.getMessage() };
+ // i18n[TableExportCsvCommand.failedToWriteFile=Failed to write
+ // file\n{0}\nError message\n{1}\nSee last log entry for details.]
+ String msg = s_stringMgr.getString("TableExportCsvCommand.failedToWriteFile", params);
+ s_log.error(msg, e);
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
+ return false;
+ }
+
+ }
+
+
+ private void executeCommand(String command)
+ {
+ try
+ {
+ Runtime.getRuntime().exec(command);
+ }
+ catch (IOException e)
+ {
+ Object[] params = new Object[]{command, e.getMessage()};
+ // i18n[TableExportCsvCommand.failedToExecuteCommand=Failed to execute\n{0}\nError message\n{1}\nSee last log entry for details.]
+ String msg = s_stringMgr.getString("TableExportCsvCommand.failedToExecuteCommand", params);
+ s_log.error(msg, e);
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
+ }
+ }
+
+ public void execute()
+ {
+ TableExportCsvController ctrl = createTableExportController();
+
+ if(false == ctrl.isOK())
+ {
+ return;
+ }
+
+ if (checkMissingData(ctrl.getSeparatorChar())) {
+ int choice = JOptionPane.showConfirmDialog(GUIUtils.getMainFrame(),
+ i18n.missingClobDataMsg);
+ if (choice == JOptionPane.YES_OPTION) {
+ // Need to somehow call
+ // SQLResultExecuterPanel.reRunSelectedResultTab(true);
+ //
+ // Something like :
+ // SQLResultExecuterPanel panel = getPanel();
+ // panel.reRunSelectedResultTab(true);
+ //
+ // However, that doesn't apply when the user is exporting from the
+ // table contents table. There needs to be a more generic way to
+ // do this for all tables containing data that is to be exported
+ // where some of the fields contain placeholders.
+ // For now, we just inform the user and let them either continue
+ // or abort and change the configuration manually,
+ // re-run the query / reload the table data and re-export.
+ }
+ if (choice == JOptionPane.NO_OPTION) {
+ // abort the export
+ return;
+ }
+ if (choice == JOptionPane.CANCEL_OPTION) {
+ // abort the export
+ return;
+ }
+ }
+
+ boolean writeFileSuccess = writeFile(ctrl, createExportData(ctrl));
+ progress("Done");
+ if(writeFileSuccess)
+ {
+ String command = ctrl.getCommand();
+
+ if(null != command)
+ {
+ executeCommand(command);
+ } else {
+ // i18n[TableExportCsvCommand.writeFileSuccess=Export to file
+ // "{0}" is complete.]
+ String msg =
+ s_stringMgr.getString("TableExportCsvCommand.writeFileSuccess",
+ ctrl.getFile().getAbsolutePath());
+ if (s_log.isInfoEnabled()) {
+ s_log.info(msg);
+ }
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
+ }
+ }
+ }
+
+ /**
+ * @return
+ */
+ protected TableExportCsvController createTableExportController() {
+ return new TableExportCsvController();
+ }
+
+ /**
+ * @param separatorChar
+ * @return
+ */
+ protected abstract boolean checkMissingData(String separatorChar);
+
+ /**
+ * @param ctrl
+ * @return
+ */
+ protected abstract IExportData createExportData(TableExportCsvController ctrl);
+
+
+ public void cancel(){
+ this.cancel=true;
+ }
+
+ /**
+ * @return the progressController
+ */
+ public ProgressAbortCallback getProgressController() {
+ return progressController;
+ }
+
+ /**
+ * @param progressController the progressController to set
+ */
+ public void setProgressController(ProgressAbortCallback progressController) {
+ this.progressController = progressController;
+ }
+
+ /**
+ * @param string
+ */
+ protected void progress(String task) {
+ if(progressController != null){
+ progressController.currentlyLoading(task);
+ }
+ }
+
+
+
+}
Property changes on: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: 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 (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java 2011-08-04 21:26:15 UTC (rev 6339)
@@ -0,0 +1,108 @@
+/*
+ * 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;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import net.sourceforge.squirrel_sql.fw.dialects.DialectType;
+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;
+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;
+
+/**
+ * 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 ILogger s_log = LoggerController.createLogger(ResultSetExportCommand.class);
+
+
+ private ResultSet resultSet;
+
+ private DialectType dialect;
+
+ private String sql;
+
+ 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;
+ }
+
+
+
+
+ /**
+ *
+ * @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#checkMissingData(java.lang.String)
+ */
+ @Override
+ protected boolean checkMissingData(String sepChar) {
+ 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);
+ } catch (SQLException e) {
+ throw new RuntimeException("Could not create the data for exporting.", e);
+ }
+ }
+
+
+
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#createTableExportController()
+ */
+ @Override
+ protected TableExportCsvController createTableExportController() {
+ return new ResultSetExportCsvController();
+ }
+
+
+
+}
Property changes on: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCommand.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCsvController.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCsvController.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCsvController.java 2011-08-04 21:26:15 UTC (rev 6339)
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+
+/**
+ * A specialization of {@link TableExportCsvController}, that tells the user, that exporting to Excel is dangerous, if the SQL returns a huge data set.
+ * @author Stefan Willinger
+ *
+ */
+public class ResultSetExportCsvController extends TableExportCsvController {
+
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.gui.action.TableExportCsvController#shouldWarnIfExcel()
+ */
+ @Override
+ protected boolean shouldWarnIfExcel() {
+ return true;
+ }
+
+}
Property changes on: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ResultSetExportCsvController.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
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-03 23:24:32 UTC (rev 6338)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/TableExportCsvCommand.java 2011-08-04 21:26:15 UTC (rev 6339)
@@ -1,54 +1,36 @@
package net.sourceforge.squirrel_sql.fw.gui.action;
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.PrintStream;
import java.sql.Types;
-import java.util.Calendar;
-import javax.swing.JOptionPane;
import javax.swing.JTable;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import jxl.Workbook;
-import jxl.write.WritableCell;
-import jxl.write.WritableSheet;
-import jxl.write.WritableWorkbook;
-import jxl.write.WriteException;
-import net.sourceforge.squirrel_sql.fw.datasetviewer.ColumnDisplayDefinition;
import net.sourceforge.squirrel_sql.fw.datasetviewer.ExtTableColumn;
-import net.sourceforge.squirrel_sql.fw.datasetviewer.cellcomponent.CellComponentFactory;
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.exportData.DataExportCSVWriter;
+import net.sourceforge.squirrel_sql.fw.gui.action.exportData.IExportData;
+import net.sourceforge.squirrel_sql.fw.gui.action.exportData.JTableExportData;
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;
-public class TableExportCsvCommand
+/**
+ * Command for exporting a {@link JTable} into a file.
+ * <p><b>Note:</b> The structure of this class has be really changed.
+ * The content of this class was split up into the package <pre>net.sourceforge.squirrel_sql.fw.gui.action.export</pre>
+ * @author Stefan Willinger
+ * @see net.sourceforge.squirrel_sql.fw.gui.action.export
+ */
+public class TableExportCsvCommand extends AbstractExportCommand
{
- private static final StringManager s_stringMgr =
+ static final StringManager s_stringMgr =
StringManagerFactory.getStringManager(TableExportCsvCommand.class);
- private static ILogger s_log = LoggerController.createLogger(TableExportCsvCommand.class);
+ static ILogger s_log = LoggerController.createLogger(TableExportCsvCommand.class);
- private JTable _table;
+ JTable _table;
+
static interface i18n {
//i18n[TableExportCsvCommand.missingClobDataMsg=Found Clob placeholder
//({0}) amongst data to be exported. Continue exporting cell data?]
@@ -59,71 +41,19 @@
public TableExportCsvCommand(JTable table)
{
+ super();
_table = table;
}
- public void execute()
- {
- TableExportCsvController ctrl = new TableExportCsvController();
+
+
- if(false == ctrl.isOK())
- {
- return;
- }
-
- if (checkMissingData(ctrl.getSeparatorChar())) {
- int choice = JOptionPane.showConfirmDialog(GUIUtils.getMainFrame(),
- i18n.missingClobDataMsg);
- if (choice == JOptionPane.YES_OPTION) {
- // Need to somehow call
- // SQLResultExecuterPanel.reRunSelectedResultTab(true);
- //
- // Something like :
- // SQLResultExecuterPanel panel = getPanel();
- // panel.reRunSelectedResultTab(true);
- //
- // However, that doesn't apply when the user is exporting from the
- // table contents table. There needs to be a more generic way to
- // do this for all tables containing data that is to be exported
- // where some of the fields contain placeholders.
- // For now, we just inform the user and let them either continue
- // or abort and change the configuration manually,
- // re-run the query / reload the table data and re-export.
- }
- if (choice == JOptionPane.NO_OPTION) {
- // abort the export
- return;
- }
- if (choice == JOptionPane.CANCEL_OPTION) {
- // abort the export
- return;
- }
- }
-
- boolean writeFileSuccess = writeFile(ctrl);
-
- if(writeFileSuccess)
- {
- String command = ctrl.getCommand();
-
- if(null != command)
- {
- executeCommand(command);
- } else {
- // i18n[TableExportCsvCommand.writeFileSuccess=Export to file
- // "{0}" is complete.]
- String msg =
- s_stringMgr.getString("TableExportCsvCommand.writeFileSuccess",
- ctrl.getFile().getAbsolutePath());
- if (s_log.isInfoEnabled()) {
- s_log.info(msg);
- }
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- }
- }
- }
-
- private boolean checkMissingData(String sepChar) {
+ /**
+ *
+ * @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#checkMissingData(java.lang.String)
+ */
+ @Override
+protected boolean checkMissingData(String sepChar) {
// TODO: if the use checks "export entire table" and doesn't select all,
// then the selected indices are not set, and this check doesn't properly
// detect missing data. If export entire table is selected, we need to
@@ -138,7 +68,8 @@
if (sqlType == Types.CLOB) {
for (int rowIdx = firstSelectedRowIdx; rowIdx < lastSelectedRowIdx; rowIdx++) {
Object cellObj = _table.getValueAt(rowIdx, colIdx);
- String data = getDataCSV(sepChar, cellObj);
+ // TODO stefan why did we need the csv data?
+ String data = DataExportCSVWriter.getDataCSV(sepChar, cellObj.toString());
if (data != null && ClobDescriptor.i18n.CLOB_LABEL.equals(data)) {
return true;
}
@@ -147,476 +78,19 @@
}
return false;
}
-
- private void executeCommand(String command)
- {
- try
- {
- Runtime.getRuntime().exec(command);
- }
- catch (IOException e)
- {
- Object[] params = new Object[]{command, e.getMessage()};
- // i18n[TableExportCsvCommand.failedToExecuteCommand=Failed to execute\n{0}\nError message\n{1}\nSee last log entry for details.]
- String msg = s_stringMgr.getString("TableExportCsvCommand.failedToExecuteCommand", params);
- s_log.error(msg, e);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- }
- }
- private boolean writeFile(TableExportCsvController ctrl)
- {
- File file = null;
- try
- {
- file = ctrl.getFile();
- if(null != file.getParentFile())
- {
- file.getParentFile().mkdirs();
- }
- boolean includeHeaders = ctrl.includeHeaders();
- boolean complete = ctrl.exportComplete();
-
-
- int nbrSelRows = _table.getSelectedRowCount();
- if(0 == nbrSelRows || complete)
- {
- nbrSelRows = _table.getRowCount();
- }
-
- int nbrSelCols = _table.getSelectedColumnCount();
- if(0 == nbrSelCols || complete)
- {
- nbrSelCols = _table.getColumnCount();
- }
-
- int[] selRows = _table.getSelectedRows();
- if(0 == selRows.length || complete)
- {
- selRows = new int[nbrSelRows];
- for (int i = 0; i < selRows.length; i++)
- {
- selRows[i] = i;
- }
- }
-
- int[] selCols = _table.getSelectedColumns();
- if(0 == selCols.length || complete)
- {
- selCols = new int[nbrSelCols];
- for (int i = 0; i < selCols.length; i++)
- {
- selCols[i] = i;
- }
- }
-
- if(TableExportCsvController.EXPORT_FORMAT_CSV == ctrl.getExportFormat())
- {
- return writeCSV(file, ctrl, includeHeaders, nbrSelCols, selCols, nbrSelRows, selRows);
- }
- else if(TableExportCsvController.EXPORT_FORMAT_XLS == ctrl.getExportFormat())
- {
- return writeXLS(file, includeHeaders, nbrSelCols, selCols, nbrSelRows, ctrl, selRows);
- }
- else if(TableExportCsvController.EXPORT_FORMAT_XML == ctrl.getExportFormat())
- {
- return writeXML(file, includeHeaders, nbrSelCols, selCols, nbrSelRows, ctrl, selRows);
- }
- else
- {
- throw new IllegalStateException("Unknown export format " + ctrl.getExportFormat());
- }
-
-
- }
- catch (IOException e)
- {
-
- Object[] params = new Object[]{file, e.getMessage()};
- // i18n[TableExportCsvCommand.failedToWriteFile=Failed to write file\n{0}\nError message\n{1}\nSee last log entry for details.]
- String msg = s_stringMgr.getString("TableExportCsvCommand.failedToWriteFile", params);
- s_log.error(msg, e);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- return false;
- }
- catch (jxl.write.WriteException e)
- {
-
- Object[] params = new Object[]{file, e.getMessage()};
- // i18n[TableExportCsvCommand.failedToWriteFile=Failed to write file\n{0}\nError message\n{1}\nSee last log entry for details.]
- String msg = s_stringMgr.getString("TableExportCsvCommand.failedToWriteFile", params);
- s_log.error(msg, e);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- return false;
- } catch (ParserConfigurationException e) {
- Object[] params = new Object[]{file, e.getMessage()};
- // i18n[TableExportCsvCommand.failedToWriteFile=Failed to write file\n{0}\nError message\n{1}\nSee last log entry for details.]
- String msg = s_stringMgr.getString("TableExportCsvCommand.failedToWriteFile", params);
- s_log.error(msg, e);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- return false;
- } catch (TransformerException e) {
- Object[] params = new Object[]{file, e.getMessage()};
- // i18n[TableExportCsvCommand.failedToWriteFile=Failed to write file\n{0}\nError message\n{1}\nSee last log entry for details.]
- String msg = s_stringMgr.getString("TableExportCsvCommand.failedToWriteFile", params);
- s_log.error(msg, e);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- return false;
- }
-
+ /**
+ * @see net.sourceforge.squirrel_sql.fw.gui.action.AbstractExportCommand#createExportData()
+ */
+ @Override
+ protected IExportData createExportData(TableExportCsvController ctrl) {
+ return new JTableExportData(_table, ctrl.exportComplete());
}
- private boolean writeXLS(File file, boolean includeHeaders, int nbrSelCols, int[] selCols, int nbrSelRows, TableExportCsvController ctrl, int[] selRows)
- throws IOException, WriteException
- {
- WritableWorkbook workbook = Workbook.createWorkbook(file);
- WritableSheet sheet = workbook.createSheet("Squirrel SQL Export", 0);
- int curRow= 0;
- if (includeHeaders)
- {
- for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx)
- {
- String columnName = _table.getColumnName(selCols[colIdx]);
- jxl.write.Label label = new jxl.write.Label(colIdx, curRow, columnName);
- sheet.addCell(label);
- }
- curRow++;
- }
-
-
- for (int rowIdx = 0; rowIdx < nbrSelRows; ++rowIdx)
- {
- for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx)
- {
- WritableCell xlsCell;
- if(ctrl.useGloablPrefsFormatting() && _table.getColumnModel().getColumn(colIdx) instanceof ExtTableColumn)
- {
- ExtTableColumn col = (ExtTableColumn) _table.getColumnModel().getColumn(colIdx);
- xlsCell = getXlsCell(col, colIdx, curRow, _table.getValueAt(selRows[rowIdx], selCols[colIdx]));
- }
- else
- {
- xlsCell = getXlsCell(null, colIdx, curRow, _table.getValueAt(selRows[rowIdx], selCols[colIdx]));
- }
- sheet.addCell(xlsCell);
-
- }
- curRow++;
- }
-
- // All sheets and cells added. Now write out the workbook
- workbook.write();
- workbook.close();
-
- return true;
- }
-
- /**
- * Writes the selected table data to XML file.
- *
- * <p>
- * Uses DOM for output
- * </p>
- *
- * @param file
- * File to output to
- * @param includeHeaders
- * Set to true if header info (column names) should be included
- * @param nbrSelCols
- * Number of selected columns
- * @param selCols
- * Selected columns
- * @param nbrSelRows
- * Number of selected rows
- * @param ctrl
- * Export controller
- * @param selRows
- * Selected rows
- * @return If everything went well returns true
- * @throws ParserConfigurationException
- * If the XML DocumentBuilder cannnot be created
- * @throws FileNotFoundException
- * When failing to create the file
- * @throws TransformerException
- * When failing to output the XML structure to the file
- */
- private boolean writeXML(File file, boolean includeHeaders, int nbrSelCols,
- int[] selCols, int nbrSelRows, TableExportCsvController ctrl,
- int[] selRows) throws ParserConfigurationException,
- FileNotFoundException, TransformerException {
-
- // Using a factory to get DocumentBuilder for creating XML's
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
-
- // Here instead of parsing an existing document we want to
- // create a new one.
- Document testDoc = builder.newDocument();
-
- // 'table' is the main tag in the XML.
- Element root = testDoc.createElement("table");
- testDoc.appendChild(root);
-
- // 'columns' tag will contain informations about columns
- Element columns = testDoc.createElement("columns");
- root.appendChild(columns);
- int curRow = 0;
- if (includeHeaders) {
- for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) {
- String columnName = _table.getColumnName(selCols[colIdx]);
-
- Element columnEl = testDoc.createElement("column");
- columnEl.setAttribute("number", String.valueOf(colIdx));
- columns.appendChild(columnEl);
-
- Element columnNameEl = testDoc.createElement("name");
- columnNameEl.setTextContent(columnName);
- columnEl.appendChild(columnNameEl);
- }
- curRow++;
- }
-
- // 'rows' tag contains the data extracted from the table
- Element rows = testDoc.createElement("rows");
- root.appendChild(rows);
-
- for (int rowIdx = 0; rowIdx < nbrSelRows; ++rowIdx) {
- Element row = testDoc.createElement("row");
- row.setAttribute("rowNumber", String.valueOf(rowIdx));
- rows.appendChild(row);
- for (int colIdx = 0; colIdx < nbrSelCols; ++colIdx) {
-
- Element value = testDoc.createElement("value");
- Object cellValue = _table.getValueAt(selRows[rowIdx], selCols[colIdx]);
- String strCellValue = "";
- if(null != cellValue)
- {
- strCellValue = cellValue.toString();
- }
-
- value.setAttribute("columnNumber", String.valueOf(colIdx));
- value.setTextContent(strCellValue);
- row.appendChild(value);
-
- }
- curRow++;
- }
-
- // The XML document we created above is still in memory
- // so we have to output it to a real file.
- // In order to do it we first have to create
- // an instance of DOMSource
- DOMSource source = new DOMSource(testDoc);
-
- // PrintStream will be responsible for writing
- // the text data to the file
- PrintStream ps = new PrintStream(file);
- StreamResult result = new StreamResult(ps);
-
- // Once again we are using a factory of some sort,
- // this time for getting a Transformer instance,
- // which we use to output the XML
- TransformerFactory transformerFactory = TransformerFactory
- .newInstance();
- Transformer transformer = transformerFactory.newTransformer();
-
- // Indenting the XML
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
-
- // The actual output to a file goes here
- transformer.transform(source, result);
-
- return true;
- }
-
- private WritableCell getXlsCell(ExtTableColumn col, int colIdx, int curRow, Object cellObj)
- {
- if(null == cellObj)
- {
- return new jxl.write.Label(colIdx, curRow, getDataXLSAsString(cellObj));
- }
-
- if(null == col)
- {
- return new jxl.write.Label(colIdx, curRow, getDataXLSAsString(cellObj));
- }
-
-
- WritableCell ret;
- ColumnDisplayDefinition colDef = col.getColumnDisplayDefinition();
- int colType = colDef.getSqlType();
- switch (colType)
- {
- case Types.BIT:
- case Types.BOOLEAN:
- ret = new jxl.write.Boolean(colIdx, curRow, (Boolean) cellObj);
- break;
- case Types.INTEGER:
- ret = new jxl.write.Number(colIdx, curRow, ((Number) cellObj).doubleValue());
- break;
- case Types.SMALLINT:
- case Types.TINYINT:
- ret = new jxl.write.Number(colIdx, curRow, ((Number) cellObj).doubleValue() ) ;
- break;
- case Types.DECIMAL:
- ret = new jxl.write.Number(colIdx, curRow, ((Number) cellObj).doubleValue());
- break;
- case Types.NUMERIC:
- ret = new jxl.write.Number(colIdx, curRow, ((Number) cellObj).doubleValue());
- break;
- case Types.FLOAT:
- ret = new jxl.write.Number(colIdx, curRow, ((Number) cellObj).doubleValue());
- break;
- case Types.DOUBLE:
- ret = new jxl.write.Number(colIdx, curRow, ((Number) cellObj).doubleValue());
- break;
- case Types.REAL:
- ret = new jxl.write.Number(colIdx, curRow, ((Number) cellObj).doubleValue()...
[truncated message content] |