Revision: 6513
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6513&view=rev
Author: manningr
Date: 2011-11-19 04:54:47 +0000 (Sat, 19 Nov 2011)
Log Message:
-----------
Relocated CLI-related classes to the dbcopy-cli project.
Modified Paths:
--------------
trunk/sql12/cli/dbcopy/pom.xml
trunk/sql12/plugins/dbcopy/src/main/resources/doc/command-line.html
trunk/sql12/plugins/dbcopy/src/main/resources/doc/readme.html
trunk/sql12/squirrelsql-integration-environment/pom.xml
Added Paths:
-----------
trunk/sql12/cli/dbcopy/src/
trunk/sql12/cli/dbcopy/src/main/
trunk/sql12/cli/dbcopy/src/main/java/
trunk/sql12/cli/dbcopy/src/main/java/net/
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyRunner.java
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java
trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionUtil.java
trunk/sql12/cli/dbcopy/src/test/
trunk/sql12/cli/dbcopy/src/test/java/
trunk/sql12/cli/dbcopy/src/test/java/net/
trunk/sql12/cli/dbcopy/src/test/java/net/sourceforge/
trunk/sql12/cli/dbcopy/src/test/java/net/sourceforge/squirrel_sql/
trunk/sql12/cli/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/
trunk/sql12/cli/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/
trunk/sql12/cli/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/
trunk/sql12/cli/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessorTest.java
Removed Paths:
-------------
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyRunner.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionUtil.java
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessorTest.java
Modified: trunk/sql12/cli/dbcopy/pom.xml
===================================================================
--- trunk/sql12/cli/dbcopy/pom.xml 2011-11-17 01:36:28 UTC (rev 6512)
+++ trunk/sql12/cli/dbcopy/pom.xml 2011-11-19 04:54:47 UTC (rev 6513)
@@ -98,9 +98,23 @@
</build>
<dependencies>
<dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>fw</artifactId>
+ <version>3.3.0-rc1</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>squirrel-sql</artifactId>
+ <version>3.3.0-rc1</version>
+ </dependency>
+ <dependency>
<groupId>net.sf.squirrel-sql.plugins</groupId>
<artifactId>dbcopy</artifactId>
<version>3.3.0-rc2</version>
</dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
</dependencies>
</project>
Copied: trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java (from rev 6475, trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java)
===================================================================
--- trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java (rev 0)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -0,0 +1,280 @@
+/*
+ * Copyright (C) 2011 Rob Manning
+ * man...@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.plugins.dbcopy.cli;
+
+import javax.swing.Action;
+import javax.swing.JComponent;
+import javax.swing.JMenu;
+
+import net.sourceforge.squirrel_sql.client.ApplicationListener;
+import net.sourceforge.squirrel_sql.client.FontInfoStore;
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.action.ActionCollection;
+import net.sourceforge.squirrel_sql.client.gui.WindowManager;
+import net.sourceforge.squirrel_sql.client.gui.db.DataCache;
+import net.sourceforge.squirrel_sql.client.gui.desktopcontainer.DesktopStyle;
+import net.sourceforge.squirrel_sql.client.gui.mainframe.MainFrame;
+import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
+import net.sourceforge.squirrel_sql.client.plugin.IPluginManager;
+import net.sourceforge.squirrel_sql.client.preferences.PreferenceType;
+import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
+import net.sourceforge.squirrel_sql.client.resources.SquirrelResources;
+import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanelFactory;
+import net.sourceforge.squirrel_sql.client.session.SessionManager;
+import net.sourceforge.squirrel_sql.client.session.mainpanel.SQLHistory;
+import net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.IWikiTableConfigurationFactory;
+import net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager;
+import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
+import net.sourceforge.squirrel_sql.fw.util.TaskThreadPool;
+
+public class ApplicationStub implements IApplication
+{
+
+ private SessionManager sessionManager = null;
+
+ private SquirrelPreferences squirrelPreferences = new SquirrelPreferences();
+
+ private TaskThreadPool threadPool = new TaskThreadPool();
+
+ public ApplicationStub()
+ {
+ sessionManager = new SessionManager(this);
+ }
+
+ @Override
+ public void addApplicationListener(ApplicationListener l)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void addToMenu(int menuId, JMenu menu)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void addToMenu(int menuId, Action action)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void addToStatusBar(JComponent comp)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public ActionCollection getActionCollection()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DataCache getDataCache()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public DesktopStyle getDesktopStyle()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IPlugin getDummyAppPlugin()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public FontInfoStore getFontInfoStore()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public MainFrame getMainFrame()
+ {
+ return null;
+ }
+
+ @Override
+ public IMessageHandler getMessageHandler()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public IPluginManager getPluginManager()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SquirrelResources getResources()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SQLDriverManager getSQLDriverManager()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public ISQLEntryPanelFactory getSQLEntryPanelFactory()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SQLHistory getSQLHistory()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public SessionManager getSessionManager()
+ {
+ return sessionManager;
+ }
+
+ @Override
+ public SquirrelPreferences getSquirrelPreferences()
+ {
+ return squirrelPreferences;
+ }
+
+ @Override
+ public TaskThreadPool getThreadPool()
+ {
+ return threadPool;
+ }
+
+ @Override
+ public IWikiTableConfigurationFactory getWikiTableConfigFactory()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public WindowManager getWindowManager()
+ {
+
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void openURL(String url)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void removeApplicationListener(ApplicationListener l)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void removeFromStatusBar(JComponent comp)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void saveApplicationState()
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void savePreferences(PreferenceType preferenceType)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void setSQLEntryPanelFactory(ISQLEntryPanelFactory factory)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void showErrorDialog(String msg)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void showErrorDialog(Throwable th)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public void showErrorDialog(String msg, Throwable th)
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+ @Override
+ public boolean shutdown(boolean updateLaunchScript)
+ {
+ return false;
+ }
+
+ @Override
+ public void startup()
+ {
+ throw new UnsupportedOperationException();
+
+ }
+
+}
Copied: trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java (from rev 6475, trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java)
===================================================================
--- trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java (rev 0)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2011 Rob Manning
+ * man...@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.plugins.dbcopy.cli;
+
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.AnalysisEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.CopyEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.CopyTableListener;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.ErrorEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.RecordEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.StatementEvent;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.event.TableEvent;
+
+public class CLCopyListener implements CopyTableListener
+{
+
+ private boolean copyFinished = false;
+
+ private ErrorEvent errorEvent = null;
+
+ public boolean isCopyFinished()
+ {
+ return copyFinished;
+ }
+
+ public void checkErrors() throws Exception {
+ if (errorEvent != null) {
+ throw errorEvent.getException();
+ }
+ }
+
+ @Override
+ public void analyzingTable(TableEvent e)
+ {
+ }
+
+ @Override
+ public void copyFinished(int seconds)
+ {
+ copyFinished = true;
+ }
+
+ @Override
+ public void copyStarted(CopyEvent e)
+ {
+ }
+
+ @Override
+ public void handleError(ErrorEvent e)
+ {
+ System.err.println("Encountered the following exception: " + e.getException().getMessage());
+ e.getException().printStackTrace();
+ errorEvent = e;
+ copyFinished = true;
+ }
+
+ @Override
+ public void recordCopied(RecordEvent e)
+ {
+ System.out.println("Copied " + e.toString());
+ }
+
+ @Override
+ public void statementExecuted(StatementEvent e)
+ {
+ System.out.println("Executed " + e.toString());
+ }
+
+ @Override
+ public void tableAnalysisStarted(AnalysisEvent e)
+ {
+ }
+
+ @Override
+ public void tableCopyFinished(TableEvent e)
+ {
+ System.out.println("Finished table copy for table: "+e.getTableName()+" (table #"+e.getTableNumber()+" of "+e.getTableCount()+")");
+ }
+
+ @Override
+ public void tableCopyStarted(TableEvent e)
+ {
+ System.out.println("Starting table copy for table: "+e.getTableName());
+ }
+
+}
Copied: trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java (from rev 6475, trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java)
===================================================================
--- trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java (rev 0)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2011 Rob Manning
+ * man...@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.plugins.dbcopy.cli;
+
+import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.UICallbacks;
+
+public class CLCopyUICallback implements UICallbacks
+{
+
+ @Override
+ public boolean appendRecordsToExisting(String tableName) throws UserCancelledOperationException
+ {
+ return false;
+ }
+
+ @Override
+ public boolean deleteTableData(String tableName) throws UserCancelledOperationException
+ {
+ return true;
+ }
+
+}
Copied: trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java (from rev 6475, trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java)
===================================================================
--- trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java (rev 0)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2011 Rob Manning
+ * man...@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.plugins.dbcopy.cli;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.cli.CommandLine;
+import org.apache.commons.cli.CommandLineParser;
+import org.apache.commons.cli.GnuParser;
+import org.apache.commons.cli.HelpFormatter;
+import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
+import org.apache.commons.cli.OptionGroup;
+import org.apache.commons.cli.Options;
+import org.apache.commons.cli.ParseException;
+
+/**
+ * Class that processes arguments that are specific to the DBCopy command-line.
+ */
+public class CommandLineArgumentProcessor
+{
+ public static final String SOURCE_CATALOG = "source-catalog";
+
+ public static final String SOURCE_SCHEMA = "source-schema";
+
+ public static final String DEST_CATALOG = "dest-catalog";
+
+ public static final String DEST_SCHEMA = "dest-schema";
+
+ public static final String TABLE_PATTERN = "table-pattern";
+
+ public static final String TABLE_LIST = "table-list";
+
+ public static final String DEST_SESSION = "dest-alias";
+
+ public static final String SOURCE_SESSION = "source-alias";
+
+ private Options options = new Options();
+
+ private CommandLine cmd = null;
+
+ public CommandLineArgumentProcessor(String[] args) throws ParseException
+ {
+ createOptions();
+ CommandLineParser parser = new GnuParser();
+ try {
+ cmd = parser.parse(options, args);
+ } catch (ParseException e) {
+ HelpFormatter formatter = new HelpFormatter();
+ System.out.println(e.getMessage());
+ System.out.println();
+ formatter.printHelp("DBCopyCLI", options, true);
+ throw e;
+ }
+ }
+
+ @SuppressWarnings("static-access")
+ private void createOptions()
+ {
+ Option sourceOption =
+ OptionBuilder.hasArg().isRequired().withLongOpt(SOURCE_SESSION).withDescription(
+ "The name of the source alias to copy tables from").create();
+ options.addOption(sourceOption);
+
+ Option destOption =
+ OptionBuilder.hasArg().isRequired().withLongOpt(DEST_SESSION).withDescription(
+ "The name of the destination alias to copy tables to").create();
+ options.addOption(destOption);
+
+ Option sourceSchemaOption =
+ OptionBuilder.hasArg().withLongOpt(SOURCE_SCHEMA).withDescription(
+ "The source schema to copy tables from").create();
+
+ Option sourceCatalogOption =
+ OptionBuilder.hasArg().withLongOpt(SOURCE_CATALOG).withDescription(
+ "The source catalog to copy tables from").create();
+
+ OptionGroup sourceSchemaGroup = new OptionGroup();
+ sourceSchemaGroup.setRequired(true);
+ sourceSchemaGroup.addOption(sourceSchemaOption);
+ sourceSchemaGroup.addOption(sourceCatalogOption);
+
+ options.addOptionGroup(sourceSchemaGroup);
+
+ Option listOption =
+ OptionBuilder.hasArg().withLongOpt(TABLE_LIST).withDescription(
+ "A comma-delimited list of tables to copy").create();
+ Option patternOption =
+ OptionBuilder.hasArg().withLongOpt(TABLE_PATTERN).withDescription(
+ "A regexp pattern to match source table names").create();
+
+ OptionGroup tableGroup = new OptionGroup();
+ tableGroup.setRequired(true);
+ tableGroup.addOption(listOption);
+ tableGroup.addOption(patternOption);
+
+ options.addOptionGroup(tableGroup);
+
+ Option destSchemaOption =
+ OptionBuilder.hasArg().withLongOpt(DEST_SCHEMA).withDescription(
+ "The destination schema to copy tables into").create();
+
+ Option destCatalogOption =
+ OptionBuilder.hasArg().withLongOpt(DEST_CATALOG).withDescription(
+ "The destination catalog to copy tables into").create();
+
+ OptionGroup destSchemaGroup = new OptionGroup();
+ destSchemaGroup.setRequired(true);
+ destSchemaGroup.addOption(destSchemaOption);
+ destSchemaGroup.addOption(destCatalogOption);
+
+ options.addOptionGroup(destSchemaGroup);
+
+
+ }
+
+ public String getSourceAliasName() {
+ return cmd.getOptionValue(SOURCE_SESSION);
+ }
+
+ public String getDestAliasName() {
+ return cmd.getOptionValue(DEST_SESSION);
+ }
+
+ public String getDestSchemaName() {
+ return cmd.getOptionValue(DEST_SCHEMA);
+ }
+
+ public String getDestCatalogName() {
+ return cmd.getOptionValue(DEST_CATALOG);
+ }
+
+ public String getSourceCatalogName() {
+ return cmd.getOptionValue(SOURCE_CATALOG);
+ }
+
+ public String getSourceSchemaName() {
+ return cmd.getOptionValue(SOURCE_SCHEMA);
+ }
+
+ public List<String> getTableList() {
+ List<String> result = new ArrayList<String>();
+ if (cmd.hasOption(TABLE_LIST)) {
+ String tableListStr = cmd.getOptionValue(TABLE_LIST);
+ if (tableListStr.contains(",")) {
+ String[] parts = tableListStr.split(",");
+ for (String part : parts) {
+ result.add(part);
+ }
+ } else {
+ result.add(tableListStr);
+ }
+ }
+ // TODO: add support for regular expression.
+ return result;
+ }
+}
Copied: trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java (from rev 6475, trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java)
===================================================================
--- trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java (rev 0)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (C) 2011 Rob Manning
+ * man...@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.plugins.dbcopy.cli;
+
+import org.apache.commons.cli.MissingOptionException;
+
+
+public class DBCopyCLI
+{
+
+ private static SessionUtil sessionUtil = new SessionUtil();
+
+ private static DBCopyRunner runner = new DBCopyRunner();
+
+ /**
+ * @param args
+ */
+ public static void main(String[] args) throws Exception
+ {
+ try
+ {
+ CommandLineArgumentProcessor argProcessor = new CommandLineArgumentProcessor(args);
+ runner.setSourceSchemaName(argProcessor.getSourceSchemaName());
+ runner.setSourceCatalogName(argProcessor.getSourceCatalogName());
+ runner.setDestSchemaName(argProcessor.getDestSchemaName());
+ runner.setDestCatalogName(argProcessor.getDestCatalogName());
+ runner.setSourceSession(sessionUtil.getSessionForAlias(argProcessor.getSourceAliasName()));
+ runner.setDestSession(sessionUtil.getSessionForAlias(argProcessor.getDestAliasName()));
+ runner.run();
+ }
+ catch (MissingOptionException e)
+ {
+ // We handle printing the usage in the argProcessor, so no need to log it here.
+ }
+ }
+
+}
Copied: trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyRunner.java (from rev 6475, trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyRunner.java)
===================================================================
--- trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyRunner.java (rev 0)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyRunner.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -0,0 +1,147 @@
+/*
+ * Copyright (C) 2011 Rob Manning
+ * man...@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.plugins.dbcopy.cli;
+
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.lang.StringUtils;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
+import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.DatabaseObjectType;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
+import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.CopyExecutor;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.DBCopyPlugin;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.util.DBUtil;
+
+public class DBCopyRunner
+{
+ private SessionInfoProvider sessionInfoProvider = new SessionInfoProviderImpl();
+
+ private ArrayList<ITableInfo> tables = new ArrayList<ITableInfo>();
+
+ private CLCopyListener listener = new CLCopyListener();
+
+ private String sourceSchemaName = null;
+
+ private String sourceCatalogName = null;
+
+ private String destSchemaName = null;
+
+ private String destCatalogName = null;
+
+ public void run() throws Exception
+ {
+ String simpleName = StringUtils.isEmpty(destSchemaName) ? destCatalogName : destSchemaName;
+
+ sessionInfoProvider.setSourceDatabaseObjects(DBUtil.convertTableToObjectList(tables));
+
+ DatabaseObjectInfo destObject =
+ new DatabaseObjectInfo(destCatalogName, destSchemaName, simpleName, DatabaseObjectType.SCHEMA,
+ sessionInfoProvider.getDestSession().getMetaData());
+ sessionInfoProvider.setDestDatabaseObject(destObject);
+
+ PreferencesManager.initialize(new DBCopyPlugin());
+ DBUtil.setPreferences(PreferencesManager.getPreferences());
+ DialectFactory.isPromptForDialect = false;
+
+ CopyExecutor executor = new CopyExecutor(sessionInfoProvider);
+ executor.addListener(listener);
+ executor.setPref(new CLCopyUICallback());
+ executor.execute();
+
+ while (!listener.isCopyFinished())
+ {
+ Thread.sleep(2000);
+ }
+ listener.checkErrors();
+
+ }
+
+ public void setSourceSession(ISession sourceSession)
+ {
+ sessionInfoProvider.setSourceSession(sourceSession);
+ }
+
+ public void setDestSession(ISession destSession)
+ {
+ sessionInfoProvider.setDestSession(destSession);
+ }
+
+ private ITableInfo getTableInfo(ISession session, String schemaName, String catalogName, String tableName)
+ throws SQLException
+ {
+ ISQLDatabaseMetaData md = session.getMetaData();
+ ITableInfo[] result = md.getTables(catalogName, schemaName, tableName, new String[] { "TABLE" }, null);
+ if (result.length == 0)
+ {
+ throw new IllegalStateException("Source table to be copied (" + tableName
+ + ") could not be located in schema (" + schemaName + ") and/or catalog (" + catalogName
+ + ") for alias: " + session.getAlias().getName());
+ }
+ return result[0];
+ }
+
+ public void setSourceSchemaName(String sourceSchemaName)
+ {
+ this.sourceSchemaName = sourceSchemaName;
+ }
+
+ public void setSourceCatalogName(String sourceCatalogName)
+ {
+ this.sourceCatalogName = sourceCatalogName;
+ }
+
+ public void setTableList(List<String> tableList) throws SQLException
+ {
+ for (String tableStr : tableList)
+ {
+ tables.add(getTableInfo(sessionInfoProvider.getSourceSession(), sourceSchemaName, sourceCatalogName,
+ tableStr));
+ }
+
+ }
+
+ public void setTableList(String tableListStr) throws SQLException
+ {
+ String[] parts = tableListStr.split(",");
+ for (String tableStr : parts)
+ {
+ tables.add(getTableInfo(sessionInfoProvider.getSourceSession(), sourceSchemaName, sourceCatalogName,
+ tableStr));
+ }
+ }
+
+ public void setDestSchemaName(String destSchemaName)
+ {
+ this.destSchemaName = destSchemaName;
+ }
+
+ public void setDestCatalogName(String destCatalogName)
+ {
+ this.destCatalogName = destCatalogName;
+ }
+}
Copied: trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java (from rev 6475, trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java)
===================================================================
--- trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java (rev 0)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2011 Rob Manning
+ * man...@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.plugins.dbcopy.cli;
+
+import java.util.List;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.SessionInfoProvider;
+
+public class SessionInfoProviderImpl implements SessionInfoProvider
+{
+
+ private ISession sourceSession = null;
+ private ISession destSession = null;
+ private IDatabaseObjectInfo destSelectedDatabaseObject = null;
+ private List<IDatabaseObjectInfo> sourceSelectedDatabaseObjects = null;
+
+
+
+ @Override
+ public ISession getDestSession()
+ {
+ return destSession;
+ }
+
+ @Override
+ public ISession getSourceSession()
+ {
+ return sourceSession;
+ }
+
+ @Override
+ public IDatabaseObjectInfo getDestDatabaseObject()
+ {
+ return destSelectedDatabaseObject;
+ }
+
+ @Override
+ public List<IDatabaseObjectInfo> getSourceDatabaseObjects()
+ {
+ return sourceSelectedDatabaseObjects;
+ }
+
+ @Override
+ public void setSourceSession(ISession session)
+ {
+ this.sourceSession = session;
+ }
+
+ @Override
+ public void setDestSession(ISession session)
+ {
+ this.destSession = session;
+ }
+
+ @Override
+ public void setDestDatabaseObject(IDatabaseObjectInfo info)
+ {
+ this.destSelectedDatabaseObject = info;
+ }
+
+ @Override
+ public void setSourceDatabaseObjects(List<IDatabaseObjectInfo> dbObjList)
+ {
+ this.sourceSelectedDatabaseObjects = dbObjList;
+ }
+
+}
Copied: trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionUtil.java (from rev 6475, trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionUtil.java)
===================================================================
--- trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionUtil.java (rev 0)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionUtil.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) 2011 Rob Manning
+ * man...@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.plugins.dbcopy.cli;
+
+import java.util.Iterator;
+
+import net.sourceforge.squirrel_sql.client.IApplication;
+import net.sourceforge.squirrel_sql.client.gui.db.DataCache;
+import net.sourceforge.squirrel_sql.client.gui.db.SQLAlias;
+import net.sourceforge.squirrel_sql.client.resources.SquirrelResources;
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.client.session.SessionManager;
+import net.sourceforge.squirrel_sql.client.util.ApplicationFiles;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLAlias;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLDriver;
+import net.sourceforge.squirrel_sql.fw.sql.SQLConnection;
+import net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager;
+
+public class SessionUtil
+{
+
+ private DataCache dataCache = null;
+
+ private IApplication applicationStub = new ApplicationStub();
+
+ private SQLDriverManager sqlDriverManager = new SQLDriverManager();
+
+ private ApplicationFiles applicationFiles = new ApplicationFiles();
+
+ private SquirrelResources squirrelResources =
+ new SquirrelResources(SquirrelResources.BUNDLE_BASE_NAME);
+
+ public SessionUtil() {
+ dataCache =
+ new DataCache(sqlDriverManager, applicationFiles.getDatabaseDriversFile(),
+ applicationFiles.getDatabaseAliasesFile(), squirrelResources.getDefaultDriversUrl(),
+ applicationStub);
+
+ }
+
+ public ISession getSessionForAlias(String alias) throws Exception
+ {
+ System.out.println("Creating session for alias: "+alias);
+ Iterator<ISQLAlias> i = dataCache.aliases();
+
+ while (i.hasNext())
+ {
+ ISQLAlias sqlAlias = i.next();
+ if (alias.equals(sqlAlias.getName()))
+ {
+
+ ISQLDriver sqlDriver = dataCache.getDriver(sqlAlias.getDriverIdentifier());
+ sqlDriverManager.registerSQLDriver(sqlDriver);
+ SQLConnection conn =
+ sqlDriverManager.getConnection(sqlDriver, sqlAlias, sqlAlias.getUserName(),
+ sqlAlias.getPassword(), sqlAlias.getDriverPropertiesClone());
+
+ SessionManager sessionManager = applicationStub.getSessionManager();
+ ISession result =
+ sessionManager.createSession(applicationStub, sqlDriver, (SQLAlias) sqlAlias, conn,
+ sqlAlias.getUserName(), sqlAlias.getPassword());
+ return result;
+ }
+ }
+ throw new RuntimeException("Alias (" + alias + ") was not found");
+ }
+
+}
Copied: trunk/sql12/cli/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessorTest.java (from rev 6475, trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessorTest.java)
===================================================================
--- trunk/sql12/cli/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessorTest.java (rev 0)
+++ trunk/sql12/cli/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessorTest.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -0,0 +1,86 @@
+package net.sourceforge.squirrel_sql.plugins.dbcopy.cli;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.commons.cli.ParseException;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class CommandLineArgumentProcessorTest
+{
+ private static final String SOURCE_SCHEMA = "dbcopydest";
+ private static final String DEST_SCHEMA = "public";
+ private static final String FIRST_TABLE = "tableA";
+ private static final String SECOND_TABLE = "tableB";
+ private static final String TWO_TABLE_LIST = FIRST_TABLE +","+SECOND_TABLE;
+ private static final String DEST_SESSION_NAME = "PostgreSQL (10.0.1.42:5432)";
+ private static final String SOURCE_SESSION_NAME = "Oracle 11g (oracle-01 - dbcopydest)";
+ private CommandLineArgumentProcessor classUnderTest;
+
+ private static final String[] singleTableArgs = new String[] {
+ "--" + CommandLineArgumentProcessor.SOURCE_SESSION,
+ SOURCE_SESSION_NAME,
+ "--" + CommandLineArgumentProcessor.DEST_SESSION,
+ DEST_SESSION_NAME,
+ "--" + CommandLineArgumentProcessor.TABLE_LIST,
+ FIRST_TABLE,
+ "--" + CommandLineArgumentProcessor.SOURCE_SCHEMA,
+ SOURCE_SCHEMA,
+ "--" + CommandLineArgumentProcessor.DEST_SCHEMA,
+ DEST_SCHEMA
+ };
+
+ private static final String[] twoTableArgs = new String[] {
+ "--" + CommandLineArgumentProcessor.SOURCE_SESSION,
+ SOURCE_SESSION_NAME,
+ "--" + CommandLineArgumentProcessor.DEST_SESSION,
+ DEST_SESSION_NAME,
+ "--" + CommandLineArgumentProcessor.TABLE_LIST,
+ TWO_TABLE_LIST,
+ "--" + CommandLineArgumentProcessor.SOURCE_SCHEMA,
+ SOURCE_SCHEMA,
+ "--" + CommandLineArgumentProcessor.DEST_SCHEMA,
+ DEST_SCHEMA
+ };
+
+
+ @Before
+ public void setUp() throws ParseException {
+ classUnderTest = new CommandLineArgumentProcessor(singleTableArgs);
+
+ }
+
+ @After
+ public void tearDown() {
+ classUnderTest = null;
+ }
+
+ @Test
+ public void testGetSourceAliasName() throws ParseException
+ {
+ assertEquals(SOURCE_SESSION_NAME, classUnderTest.getSourceAliasName());
+ }
+
+ @Test
+ public void testGetDestAliasName()
+ {
+ assertEquals(DEST_SESSION_NAME, classUnderTest.getDestAliasName());
+ }
+
+ @Test
+ public void testGetDestSchemaName()
+ {
+ assertEquals(DEST_SCHEMA, classUnderTest.getDestSchemaName());
+ }
+
+ @Test
+ public void testGetTableList() throws ParseException
+ {
+ assertEquals(FIRST_TABLE, classUnderTest.getTableList().get(0));
+ classUnderTest = new CommandLineArgumentProcessor(twoTableArgs);
+ assertEquals(FIRST_TABLE, classUnderTest.getTableList().get(0));
+ assertEquals(SECOND_TABLE, classUnderTest.getTableList().get(1));
+ }
+
+}
Deleted: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java 2011-11-17 01:36:28 UTC (rev 6512)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -1,280 +0,0 @@
-/*
- * Copyright (C) 2011 Rob Manning
- * man...@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.plugins.dbcopy.cli;
-
-import javax.swing.Action;
-import javax.swing.JComponent;
-import javax.swing.JMenu;
-
-import net.sourceforge.squirrel_sql.client.ApplicationListener;
-import net.sourceforge.squirrel_sql.client.FontInfoStore;
-import net.sourceforge.squirrel_sql.client.IApplication;
-import net.sourceforge.squirrel_sql.client.action.ActionCollection;
-import net.sourceforge.squirrel_sql.client.gui.WindowManager;
-import net.sourceforge.squirrel_sql.client.gui.db.DataCache;
-import net.sourceforge.squirrel_sql.client.gui.desktopcontainer.DesktopStyle;
-import net.sourceforge.squirrel_sql.client.gui.mainframe.MainFrame;
-import net.sourceforge.squirrel_sql.client.plugin.IPlugin;
-import net.sourceforge.squirrel_sql.client.plugin.IPluginManager;
-import net.sourceforge.squirrel_sql.client.preferences.PreferenceType;
-import net.sourceforge.squirrel_sql.client.preferences.SquirrelPreferences;
-import net.sourceforge.squirrel_sql.client.resources.SquirrelResources;
-import net.sourceforge.squirrel_sql.client.session.ISQLEntryPanelFactory;
-import net.sourceforge.squirrel_sql.client.session.SessionManager;
-import net.sourceforge.squirrel_sql.client.session.mainpanel.SQLHistory;
-import net.sourceforge.squirrel_sql.fw.gui.action.wikiTable.IWikiTableConfigurationFactory;
-import net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager;
-import net.sourceforge.squirrel_sql.fw.util.IMessageHandler;
-import net.sourceforge.squirrel_sql.fw.util.TaskThreadPool;
-
-public class ApplicationStub implements IApplication
-{
-
- private SessionManager sessionManager = null;
-
- private SquirrelPreferences squirrelPreferences = new SquirrelPreferences();
-
- private TaskThreadPool threadPool = new TaskThreadPool();
-
- public ApplicationStub()
- {
- sessionManager = new SessionManager(this);
- }
-
- @Override
- public void addApplicationListener(ApplicationListener l)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void addToMenu(int menuId, JMenu menu)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void addToMenu(int menuId, Action action)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void addToStatusBar(JComponent comp)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public ActionCollection getActionCollection()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public DataCache getDataCache()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public DesktopStyle getDesktopStyle()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public IPlugin getDummyAppPlugin()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public FontInfoStore getFontInfoStore()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public MainFrame getMainFrame()
- {
- return null;
- }
-
- @Override
- public IMessageHandler getMessageHandler()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public IPluginManager getPluginManager()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public SquirrelResources getResources()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public SQLDriverManager getSQLDriverManager()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public ISQLEntryPanelFactory getSQLEntryPanelFactory()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public SQLHistory getSQLHistory()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public SessionManager getSessionManager()
- {
- return sessionManager;
- }
-
- @Override
- public SquirrelPreferences getSquirrelPreferences()
- {
- return squirrelPreferences;
- }
-
- @Override
- public TaskThreadPool getThreadPool()
- {
- return threadPool;
- }
-
- @Override
- public IWikiTableConfigurationFactory getWikiTableConfigFactory()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public WindowManager getWindowManager()
- {
-
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void openURL(String url)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void removeApplicationListener(ApplicationListener l)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void removeFromStatusBar(JComponent comp)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void saveApplicationState()
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void savePreferences(PreferenceType preferenceType)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void setSQLEntryPanelFactory(ISQLEntryPanelFactory factory)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void showErrorDialog(String msg)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void showErrorDialog(Throwable th)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public void showErrorDialog(String msg, Throwable th)
- {
- throw new UnsupportedOperationException();
-
- }
-
- @Override
- public boolean shutdown(boolean updateLaunchScript)
- {
- return false;
- }
-
- @Override
- public void startup()
- {
- throw new UnsupportedOperationException();
-
- }
-
-}
Deleted: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java 2011-11-17 01:36:28 UTC (rev 6512)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2011 Rob Manning
- * man...@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.plugins.dbcopy.cli;
-
-import net.sourceforge.squirrel_sql.plugins.dbcopy.event.AnalysisEvent;
-import net.sourceforge.squirrel_sql.plugins.dbcopy.event.CopyEvent;
-import net.sourceforge.squirrel_sql.plugins.dbcopy.event.CopyTableListener;
-import net.sourceforge.squirrel_sql.plugins.dbcopy.event.ErrorEvent;
-import net.sourceforge.squirrel_sql.plugins.dbcopy.event.RecordEvent;
-import net.sourceforge.squirrel_sql.plugins.dbcopy.event.StatementEvent;
-import net.sourceforge.squirrel_sql.plugins.dbcopy.event.TableEvent;
-
-public class CLCopyListener implements CopyTableListener
-{
-
- private boolean copyFinished = false;
-
- private ErrorEvent errorEvent = null;
-
- public boolean isCopyFinished()
- {
- return copyFinished;
- }
-
- public void checkErrors() throws Exception {
- if (errorEvent != null) {
- throw errorEvent.getException();
- }
- }
-
- @Override
- public void analyzingTable(TableEvent e)
- {
- }
-
- @Override
- public void copyFinished(int seconds)
- {
- copyFinished = true;
- }
-
- @Override
- public void copyStarted(CopyEvent e)
- {
- }
-
- @Override
- public void handleError(ErrorEvent e)
- {
- System.err.println("Encountered the following exception: " + e.getException().getMessage());
- e.getException().printStackTrace();
- errorEvent = e;
- copyFinished = true;
- }
-
- @Override
- public void recordCopied(RecordEvent e)
- {
- System.out.println("Copied " + e.toString());
- }
-
- @Override
- public void statementExecuted(StatementEvent e)
- {
- System.out.println("Executed " + e.toString());
- }
-
- @Override
- public void tableAnalysisStarted(AnalysisEvent e)
- {
- }
-
- @Override
- public void tableCopyFinished(TableEvent e)
- {
- System.out.println("Finished table copy for table: "+e.getTableName()+" (table #"+e.getTableNumber()+" of "+e.getTableCount()+")");
- }
-
- @Override
- public void tableCopyStarted(TableEvent e)
- {
- System.out.println("Starting table copy for table: "+e.getTableName());
- }
-
-}
Deleted: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java 2011-11-17 01:36:28 UTC (rev 6512)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -1,40 +0,0 @@
-/*
- * Copyright (C) 2011 Rob Manning
- * man...@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.plugins.dbcopy.cli;
-
-import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
-import net.sourceforge.squirrel_sql.plugins.dbcopy.UICallbacks;
-
-public class CLCopyUICallback implements UICallbacks
-{
-
- @Override
- public boolean appendRecordsToExisting(String tableName) throws UserCancelledOperationException
- {
- return false;
- }
-
- @Override
- public boolean deleteTableData(String tableName) throws UserCancelledOperationException
- {
- return true;
- }
-
-}
Deleted: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java 2011-11-17 01:36:28 UTC (rev 6512)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -1,175 +0,0 @@
-/*
- * Copyright (C) 2011 Rob Manning
- * man...@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.plugins.dbcopy.cli;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.commons.cli.CommandLine;
-import org.apache.commons.cli.CommandLineParser;
-import org.apache.commons.cli.GnuParser;
-import org.apache.commons.cli.HelpFormatter;
-import org.apache.commons.cli.Option;
-import org.apache.commons.cli.OptionBuilder;
-import org.apache.commons.cli.OptionGroup;
-import org.apache.commons.cli.Options;
-import org.apache.commons.cli.ParseException;
-
-/**
- * Class that processes arguments that are specific to the DBCopy command-line.
- */
-public class CommandLineArgumentProcessor
-{
- public static final String SOURCE_CATALOG = "source-catalog";
-
- public static final String SOURCE_SCHEMA = "source-schema";
-
- public static final String DEST_CATALOG = "dest-catalog";
-
- public static final String DEST_SCHEMA = "dest-schema";
-
- public static final String TABLE_PATTERN = "table-pattern";
-
- public static final String TABLE_LIST = "table-list";
-
- public static final String DEST_SESSION = "dest-alias";
-
- public static final String SOURCE_SESSION = "source-alias";
-
- private Options options = new Options();
-
- private CommandLine cmd = null;
-
- public CommandLineArgumentProcessor(String[] args) throws ParseException
- {
- createOptions();
- CommandLineParser parser = new GnuParser();
- try {
- cmd = parser.parse(options, args);
- } catch (ParseException e) {
- HelpFormatter formatter = new HelpFormatter();
- System.out.println(e.getMessage());
- System.out.println();
- formatter.printHelp("DBCopyCLI", options, true);
- throw e;
- }
- }
-
- @SuppressWarnings("static-access")
- private void createOptions()
- {
- Option sourceOption =
- OptionBuilder.hasArg().isRequired().withLongOpt(SOURCE_SESSION).withDescription(
- "The name of the source alias to copy tables from").create();
- options.addOption(sourceOption);
-
- Option destOption =
- OptionBuilder.hasArg().isRequired().withLongOpt(DEST_SESSION).withDescription(
- "The name of the destination alias to copy tables to").create();
- options.addOption(destOption);
-
- Option sourceSchemaOption =
- OptionBuilder.hasArg().withLongOpt(SOURCE_SCHEMA).withDescription(
- "The source schema to copy tables from").create();
-
- Option sourceCatalogOption =
- OptionBuilder.hasArg().withLongOpt(SOURCE_CATALOG).withDescription(
- "The source catalog to copy tables from").create();
-
- OptionGroup sourceSchemaGroup = new OptionGroup();
- sourceSchemaGroup.setRequired(true);
- sourceSchemaGroup.addOption(sourceSchemaOption);
- sourceSchemaGroup.addOption(sourceCatalogOption);
-
- options.addOptionGroup(sourceSchemaGroup);
-
- Option listOption =
- OptionBuilder.hasArg().withLongOpt(TABLE_LIST).withDescription(
- "A comma-delimited list of tables to copy").create();
- Option patternOption =
- OptionBuilder.hasArg().withLongOpt(TABLE_PATTERN).withDescription(
- "A regexp pattern to match source table names").create();
-
- OptionGroup tableGroup = new OptionGroup();
- tableGroup.setRequired(true);
- tableGroup.addOption(listOption);
- tableGroup.addOption(patternOption);
-
- options.addOptionGroup(tableGroup);
-
- Option destSchemaOption =
- OptionBuilder.hasArg().withLongOpt(DEST_SCHEMA).withDescription(
- "The destination schema to copy tables into").create();
-
- Option destCatalogOption =
- OptionBuilder.hasArg().withLongOpt(DEST_CATALOG).withDescription(
- "The destination catalog to copy tables into").create();
-
- OptionGroup destSchemaGroup = new OptionGroup();
- destSchemaGroup.setRequired(true);
- destSchemaGroup.addOption(destSchemaOption);
- destSchemaGroup.addOption(destCatalogOption);
-
- options.addOptionGroup(destSchemaGroup);
-
-
- }
-
- public String getSourceAliasName() {
- return cmd.getOptionValue(SOURCE_SESSION);
- }
-
- public String getDestAliasName() {
- return cmd.getOptionValue(DEST_SESSION);
- }
-
- public String getDestSchemaName() {
- return cmd.getOptionValue(DEST_SCHEMA);
- }
-
- public String getDestCatalogName() {
- return cmd.getOptionValue(DEST_CATALOG);
- }
-
- public String getSourceCatalogName() {
- return cmd.getOptionValue(SOURCE_CATALOG);
- }
-
- public String getSourceSchemaName() {
- return cmd.getOptionValue(SOURCE_SCHEMA);
- }
-
- public List<String> getTableList() {
- List<String> result = new ArrayList<String>();
- if (cmd.hasOption(TABLE_LIST)) {
- String tableListStr = cmd.getOptionValue(TABLE_LIST);
- if (tableListStr.contains(",")) {
- String[] parts = tableListStr.split(",");
- for (String part : parts) {
- result.add(part);
- }
- } else {
- result.add(tableListStr);
- }
- }
- // TODO: add support for regular expression.
- return result;
- }
-}
Deleted: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java 2011-11-17 01:36:28 UTC (rev 6512)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java 2011-11-19 04:54:47 UTC (rev 6513)
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2011 Rob Manning
- * man...@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....
[truncated message content] |