Revision: 6354
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6354&view=rev
Author: wis775
Date: 2011-08-10 18:59:26 +0000 (Wed, 10 Aug 2011)
Log Message:
-----------
Store result of SQL in file:
- Don't allow two simultaneously running exports to write to the same file.
Modified Paths:
--------------
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/exportData/AbstractDataExportFileWriter.java
trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties
Added Paths:
-----------
trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ExportFileContainer.java
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-10 01:01:43 UTC (rev 6353)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/AbstractExportCommand.java 2011-08-10 18:59:26 UTC (rev 6354)
@@ -71,11 +71,20 @@
ClobDescriptor.i18n.CLOB_LABEL);
String FAILED = s_stringMgr.getString("AbstractExportCommand.failed");
+
+ String ANOTHER_EXPORT_IS_ACTIVE = s_stringMgr.getString("AbstractExportCommand.anotherExportIsActive");
+ String TITLE_ANOTHER_EXPORT_IS_ACTIVE = s_stringMgr.getString("AbstractExportCommand.anotherExportIsActive.title");
}
static ILogger s_log = LoggerController.createLogger(AbstractExportCommand.class);
private ProgressAbortCallback progressController = null;
private File targetFile;
+
+ /**
+ * Container to store all files, referenced by a currently running export process.
+ */
+ private ExportFileContainer fileContainer = ExportFileContainer.getInstance();
+
private long writtenRows = -1;
/**
@@ -144,77 +153,101 @@
public void execute() throws ExportDataException
{
- TableExportCsvController ctrl = createTableExportController();
+ try{
+
+ boolean fileIsInUse = false;
+
+ TableExportCsvController ctrl;
+ do{
+ ctrl = createTableExportController();
- if(false == ctrl.isOK())
- {
- return;
- }
+ 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;
- }
- }
+ 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;
+ }
+ }
+
+ this.targetFile = ctrl.getFile();
+
+ /*
+ * Allow only one export at a time.
+ */
+ if(fileContainer.add(this.targetFile) == false){
+ fileIsInUse = true;
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.ANOTHER_EXPORT_IS_ACTIVE, i18n.TITLE_ANOTHER_EXPORT_IS_ACTIVE, JOptionPane.WARNING_MESSAGE);
+ }else {
+ fileIsInUse = false;
+ }
- this.targetFile = ctrl.getFile();
-
- this.progressController = createProgressController();
-
-
-
- try {
- writtenRows = 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(writtenRows >= 0){
- String command = ctrl.getCommand();
+ }while(fileIsInUse);
- if(null != command)
- {
- executeCommand(command);
- } else {
- // i18n[TableExportCsvCommand.writeFileSuccess=Export to file
- // "{0}" is complete.]
- String msg =
- s_stringMgr.getString("TableExportCsvCommand.writeFileSuccess", NumberFormat.getIntegerInstance().format(writtenRows),
- ctrl.getFile().getAbsolutePath());
- if (s_log.isInfoEnabled()) {
- s_log.info(msg);
- }
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
- }
- }else{
- s_log.info(i18n.FAILED);
- JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.FAILED);
+
+ this.progressController = createProgressController();
+
+
+
+ try {
+ writtenRows = 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(writtenRows >= 0){
+ 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", NumberFormat.getIntegerInstance().format(writtenRows),
+ ctrl.getFile().getAbsolutePath());
+ if (s_log.isInfoEnabled()) {
+ s_log.info(msg);
+ }
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), msg);
+ }
+ }else{
+ s_log.info(i18n.FAILED);
+ JOptionPane.showMessageDialog(GUIUtils.getMainFrame(), i18n.FAILED);
+ }
+ }finally{
+ if(this.targetFile != null){
+ this.fileContainer.remove(this.targetFile);
+ }
}
}
Added: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ExportFileContainer.java
===================================================================
--- trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ExportFileContainer.java (rev 0)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ExportFileContainer.java 2011-08-10 18:59:26 UTC (rev 6354)
@@ -0,0 +1,54 @@
+/*
+ * 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.util.HashSet;
+import java.util.Set;
+import java.io.File;
+
+/**
+ * This class stores all target files of currently running exports.
+ * @author Stefan Willinger
+ *
+ */
+public class ExportFileContainer {
+ private static ExportFileContainer instance;
+
+ private Set<File> fileSet = new HashSet<File>();
+
+ private ExportFileContainer(){
+
+ }
+
+
+ public static synchronized ExportFileContainer getInstance(){
+ if(instance == null){
+ instance = new ExportFileContainer();
+ }
+ return instance;
+ }
+
+ public synchronized boolean add(File file){
+ return fileSet.add(file);
+ }
+
+ public synchronized boolean remove(File file){
+ return fileSet.remove(file);
+ }
+}
Property changes on: trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/ExportFileContainer.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: 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/AbstractDataExportFileWriter.java 2011-08-10 01:01:43 UTC (rev 6353)
+++ trunk/sql12/fw/src/main/java/net/sourceforge/squirrel_sql/fw/gui/action/exportData/AbstractDataExportFileWriter.java 2011-08-10 18:59:26 UTC (rev 6354)
@@ -136,8 +136,6 @@
while (rows.hasNext() && isStop() == false) {
- // FIXME - remove
- Thread.sleep(500);
rowsCount++;
IExportDataRow aRow = rows.next();
if(isStatusUpdateNecessary()){
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-10 01:01:43 UTC (rev 6353)
+++ trunk/sql12/fw/src/main/resources/net/sourceforge/squirrel_sql/fw/gui/action/I18NStrings.properties 2011-08-10 18:59:26 UTC (rev 6354)
@@ -36,6 +36,8 @@
TableExportCsvCommand.missingClobDataMsg=Found Clob placeholder({0}) amongst data to be exported. Continue exporting cell data?
TableExportCsvCommand.writeFileSuccess=Export of {0} rows to file "{1}" is complete.
AbstractExportCommand.failed=Failed to export the SQL Select statement into a file.
+AbstractExportCommand.anotherExportIsActive=The chosen file can't be used, because another export is writing to the same file.
+AbstractExportCommand.anotherExportIsActive.title=File is in use.
TableExportCsvController.fileChooserTitel=Choose export file
TableExportCsvController.fileChooserButton=Choose
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|