Thread: [Squirrel-sql-commits] SF.net SVN: squirrel-sql:[6319] trunk/sql12/plugins/dbcopy/src/main/java/ n
A Java SQL client for any JDBC compliant database
Brought to you by:
colbell,
gerdwagner
From: <man...@us...> - 2011-07-27 22:23:59
|
Revision: 6319 http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6319&view=rev Author: manningr Date: 2011-07-27 22:23:52 +0000 (Wed, 27 Jul 2011) Log Message: ----------- License header and TODO cleanup. Modified 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/SessionInfoProviderImpl.java Modified: 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-07-27 22:21:46 UTC (rev 6318) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/ApplicationStub.java 2011-07-27 22:23:52 UTC (rev 6319) @@ -1,3 +1,22 @@ +/* + * 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; @@ -248,7 +267,6 @@ @Override public boolean shutdown(boolean updateLaunchScript) { - return false; } Modified: 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-07-27 22:21:46 UTC (rev 6318) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java 2011-07-27 22:23:52 UTC (rev 6319) @@ -1,3 +1,22 @@ +/* + * 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; @@ -12,16 +31,15 @@ { private boolean copyFinished = false; - - public boolean isCopyFinished() { + + public boolean isCopyFinished() + { return copyFinished; } - + @Override public void analyzingTable(TableEvent e) { - // TODO Auto-generated method stub - } @Override @@ -33,14 +51,12 @@ @Override public void copyStarted(CopyEvent e) { - // TODO Auto-generated method stub - } @Override public void handleError(ErrorEvent e) { - System.err.println("Encountered the following exception: "+e.getException().getMessage()); + System.err.println("Encountered the following exception: " + e.getException().getMessage()); e.getException().printStackTrace(); copyFinished = true; } @@ -48,36 +64,26 @@ @Override public void recordCopied(RecordEvent e) { - // TODO Auto-generated method stub - } @Override public void statementExecuted(StatementEvent e) { - // TODO Auto-generated method stub - } @Override public void tableAnalysisStarted(AnalysisEvent e) { - // TODO Auto-generated method stub - } @Override public void tableCopyFinished(TableEvent e) { - // TODO Auto-generated method stub - } @Override public void tableCopyStarted(TableEvent e) { - // TODO Auto-generated method stub - } } Modified: 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-07-27 22:21:46 UTC (rev 6318) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyUICallback.java 2011-07-27 22:23:52 UTC (rev 6319) @@ -1,3 +1,22 @@ +/* + * 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; Modified: 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-07-27 22:21:46 UTC (rev 6318) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java 2011-07-27 22:23:52 UTC (rev 6319) @@ -1,3 +1,22 @@ +/* + * 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; @@ -37,8 +56,6 @@ private Options options = new Options(); private CommandLine cmd = null; - - private boolean valid = true; public CommandLineArgumentProcessor(String[] args) throws ParseException { @@ -46,11 +63,11 @@ CommandLineParser parser = new GnuParser(); try { cmd = parser.parse(options, args); - } catch (Exception e) { + } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); - System.out.println(e.getMessage()); + System.err.println(e.getMessage()); formatter.printHelp("DBCopyCLI", options, true); - valid = false; + throw e; } } @@ -114,41 +131,6 @@ } - public boolean isValid() { - return valid; - } - - public void validate() - { - try - { - if (!cmd.hasOption(SOURCE_SESSION)) - { - throw new ParseException("Missing " + SOURCE_SESSION); - } - if (!cmd.hasOption(DEST_SESSION)) - { - throw new ParseException("Missing " + DEST_SESSION); - } - if (!cmd.hasOption(TABLE_LIST) && !cmd.hasOption(TABLE_PATTERN)) - { - throw new ParseException("Must specify either " + TABLE_LIST + " or " + TABLE_PATTERN); - } - if (!cmd.hasOption(DEST_SCHEMA)) - { - throw new ParseException("Missing " + DEST_SCHEMA); - } - } - catch (ParseException e) - { - HelpFormatter formatter = new HelpFormatter(); - System.out.println(e.getMessage()); - formatter.printHelp("DBCopyCLI", options, true); - System.exit(1); - - } - } - public String getSourceAliasName() { return cmd.getOptionValue(SOURCE_SESSION); } Modified: 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-07-27 22:21:46 UTC (rev 6318) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java 2011-07-27 22:23:52 UTC (rev 6319) @@ -1,3 +1,22 @@ +/* + * 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; @@ -4,10 +23,6 @@ import java.util.ArrayList; import java.util.Iterator; -import org.apache.commons.cli.HelpFormatter; -import org.apache.commons.cli.ParseException; -import org.apache.commons.lang.StringUtils; - 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; @@ -24,16 +39,14 @@ import net.sourceforge.squirrel_sql.fw.sql.ITableInfo; import net.sourceforge.squirrel_sql.fw.sql.SQLConnection; import net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager; -import net.sourceforge.squirrel_sql.fw.sql.TableInfo; -import net.sourceforge.squirrel_sql.fw.util.StringUtilities; -import net.sourceforge.squirrel_sql.fw.util.Utilities; 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.event.CopyTableListener; import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager; import net.sourceforge.squirrel_sql.plugins.dbcopy.util.DBUtil; +import org.apache.commons.lang.StringUtils; + /* * Copyright (C) 2011 Rob Manning * man...@us... @@ -66,16 +79,16 @@ private static DataCache dataCache = null; - private static ISession sourceSession = null; - - // private static ISession destSession = null; - private static SessionInfoProvider sessionInfoProvider = new SessionInfoProviderImpl(); private static ArrayList<ITableInfo> tables = new ArrayList<ITableInfo>(); private static CLCopyListener listener = new CLCopyListener(); + private static ISession sourceSession = null; + + private static ISession destSession = null; + /** * @param args */ @@ -93,10 +106,11 @@ applicationFiles.getDatabaseAliasesFile(), squirrelResources.getDefaultDriversUrl(), applicationStub); - ISession destSession = getSessionForAlias(argProcessor.getDestAliasName()); + setDestSession(getSessionForAlias(argProcessor.getDestAliasName())); + setSourceSession(getSessionForAlias(argProcessor.getSourceAliasName())); - sessionInfoProvider.setSourceSession(getSessionForAlias(argProcessor.getSourceAliasName())); - sessionInfoProvider.setDestSession(destSession); + sessionInfoProvider.setSourceSession(getSourceSession()); + sessionInfoProvider.setDestSession(getDestSession()); for (String tableStr : argProcessor.getTableList()) { tables.add(getTableInfo(sessionInfoProvider.getSourceSession(), sourceSchemaName, sourceCatalogName, @@ -107,7 +121,7 @@ DatabaseObjectInfo destObject = new DatabaseObjectInfo(destCatalogName, destSchemaName, simpleName, DatabaseObjectType.SCHEMA, - destSession.getMetaData()); + getDestSession().getMetaData()); sessionInfoProvider.setDestDatabaseObject(destObject); PreferencesManager.initialize(new DBCopyPlugin()); @@ -118,8 +132,9 @@ executor.addListener(listener); executor.setPref(new CLCopyUICallback()); executor.execute(); - - while (!listener.isCopyFinished()) { + + while (!listener.isCopyFinished()) + { System.out.print("."); Thread.sleep(2000); } @@ -131,6 +146,12 @@ { 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]; } @@ -165,4 +186,24 @@ } throw new RuntimeException("Alias (" + alias + ") was not found"); } + + public static void setSourceSession(ISession sourceSession) + { + DBCopyCLI.sourceSession = sourceSession; + } + + public static ISession getSourceSession() + { + return sourceSession; + } + + public static void setDestSession(ISession destSession) + { + DBCopyCLI.destSession = destSession; + } + + public static ISession getDestSession() + { + return destSession; + } } Modified: 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/SessionInfoProviderImpl.java 2011-07-27 22:21:46 UTC (rev 6318) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionInfoProviderImpl.java 2011-07-27 22:23:52 UTC (rev 6319) @@ -1,3 +1,22 @@ +/* + * 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; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2011-08-20 19:18:05
|
Revision: 6373 http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6373&view=rev Author: manningr Date: 2011-08-20 19:17:58 +0000 (Sat, 20 Aug 2011) Log Message: ----------- Better logging. Refactored main class to strip out the meat (DBCopyRunner) which is now also used in the integration environment for testing. Modified Paths: -------------- 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/DBCopyCLI.java Added Paths: ----------- 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/SessionUtil.java Modified: 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-08-20 19:10:40 UTC (rev 6372) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CLCopyListener.java 2011-08-20 19:17:58 UTC (rev 6373) @@ -31,12 +31,20 @@ { 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) { @@ -58,6 +66,7 @@ { System.err.println("Encountered the following exception: " + e.getException().getMessage()); e.getException().printStackTrace(); + errorEvent = e; copyFinished = true; } @@ -81,11 +90,13 @@ @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()); } } Modified: 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-08-20 19:10:40 UTC (rev 6372) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java 2011-08-20 19:17:58 UTC (rev 6373) @@ -19,191 +19,27 @@ package net.sourceforge.squirrel_sql.plugins.dbcopy.cli; -import java.sql.SQLException; -import java.util.ArrayList; -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.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.ISQLAlias; -import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData; -import net.sourceforge.squirrel_sql.fw.sql.ISQLDriver; -import net.sourceforge.squirrel_sql.fw.sql.ITableInfo; -import net.sourceforge.squirrel_sql.fw.sql.SQLConnection; -import net.sourceforge.squirrel_sql.fw.sql.SQLDriverManager; -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; - -import org.apache.commons.lang.StringUtils; - -/* - * 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 - */ - public class DBCopyCLI { - private static IApplication applicationStub = new ApplicationStub(); - private static ApplicationFiles applicationFiles = new ApplicationFiles(); + private static SessionUtil sessionUtil = new SessionUtil(); - private static SquirrelResources squirrelResources = - new SquirrelResources(SquirrelResources.BUNDLE_BASE_NAME); + private static DBCopyRunner runner = new DBCopyRunner(); - private static SQLDriverManager sqlDriverManager = new SQLDriverManager(); - - private static DataCache dataCache = null; - - private static SessionInfoProvider sessionInfoProvider = new SessionInfoProviderImpl(); - - private static ArrayList<ITableInfo> tables = new ArrayList<ITableInfo>(); - - private static CLCopyListener listener = new CLCopyListener(); - - private static ISession sourceSession = null; - - private static ISession destSession = null; - /** * @param args */ public static void main(String[] args) throws Exception - { + { CommandLineArgumentProcessor argProcessor = new CommandLineArgumentProcessor(args); - String sourceSchemaName = argProcessor.getSourceSchemaName(); - String sourceCatalogName = argProcessor.getSourceCatalogName(); - String destSchemaName = argProcessor.getDestSchemaName(); - String destCatalogName = argProcessor.getDestCatalogName(); - String simpleName = StringUtils.isEmpty(destSchemaName) ? destCatalogName : destSchemaName; - - dataCache = - new DataCache(sqlDriverManager, applicationFiles.getDatabaseDriversFile(), - applicationFiles.getDatabaseAliasesFile(), squirrelResources.getDefaultDriversUrl(), - applicationStub); - - setDestSession(getSessionForAlias(argProcessor.getDestAliasName())); - setSourceSession(getSessionForAlias(argProcessor.getSourceAliasName())); - - sessionInfoProvider.setSourceSession(getSourceSession()); - sessionInfoProvider.setDestSession(getDestSession()); - for (String tableStr : argProcessor.getTableList()) - { - tables.add(getTableInfo(sessionInfoProvider.getSourceSession(), sourceSchemaName, sourceCatalogName, - tableStr)); - } - - sessionInfoProvider.setSourceDatabaseObjects(DBUtil.convertTableToObjectList(tables)); - - DatabaseObjectInfo destObject = - new DatabaseObjectInfo(destCatalogName, destSchemaName, simpleName, DatabaseObjectType.SCHEMA, - 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()) - { - System.out.print("."); - Thread.sleep(2000); - } - + 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(); } - private static 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]; - } - - private static ISession getSessionForAlias(String alias) throws Exception - { - 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()); - - // Class.forName(driver.getDriverClassName()); - - // Connection con = - // DriverManager.getConnection(sqlAlias.getUrl(), sqlAlias.getUserName(), sqlAlias.getPassword()); - - // SQLConnection conn = new SQLConnection(con, sqlAlias.getDriverPropertiesClone(), driver); - 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"); - } - - public static void setSourceSession(ISession sourceSession) - { - DBCopyCLI.sourceSession = sourceSession; - } - - public static ISession getSourceSession() - { - return sourceSession; - } - - public static void setDestSession(ISession destSession) - { - DBCopyCLI.destSession = destSession; - } - - public static ISession getDestSession() - { - return destSession; - } } Added: 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/DBCopyRunner.java (rev 0) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyRunner.java 2011-08-20 19:17:58 UTC (rev 6373) @@ -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; + } +} Added: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionUtil.java =================================================================== --- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionUtil.java (rev 0) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/SessionUtil.java 2011-08-20 19:17:58 UTC (rev 6373) @@ -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"); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2011-11-06 21:02:35
|
Revision: 6473 http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6473&view=rev Author: manningr Date: 2011-11-06 21:02:29 +0000 (Sun, 06 Nov 2011) Log Message: ----------- Don't present the user with a stack trace when required options are missing. Modified Paths: -------------- 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 Modified: 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-05 14:20:37 UTC (rev 6472) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java 2011-11-06 21:02:29 UTC (rev 6473) @@ -65,7 +65,8 @@ cmd = parser.parse(options, args); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); - System.err.println(e.getMessage()); + System.out.println(e.getMessage()); + System.out.println(); formatter.printHelp("DBCopyCLI", options, true); throw e; } Modified: 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-05 14:20:37 UTC (rev 6472) +++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java 2011-11-06 21:02:29 UTC (rev 6473) @@ -19,7 +19,9 @@ package net.sourceforge.squirrel_sql.plugins.dbcopy.cli; +import org.apache.commons.cli.MissingOptionException; + public class DBCopyCLI { @@ -31,15 +33,22 @@ * @param args */ public static void main(String[] args) throws Exception - { - 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(); + { + 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. + } } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |