Revision: 6521
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=6521&view=rev
Author: manningr
Date: 2011-11-19 19:36:14 +0000 (Sat, 19 Nov 2011)
Log Message:
-----------
Added support for specifying a table pattern, rather than a table list. Also updated documentation.
Modified Paths:
--------------
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/plugins/dbcopy/src/main/resources/doc/command-line.html
Added Paths:
-----------
trunk/sql12/cli/dbcopy/src/main/resources/
trunk/sql12/cli/dbcopy/src/main/resources/log4j.properties
Modified: 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/CommandLineArgumentProcessor.java 2011-11-19 05:12:26 UTC (rev 6520)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/CommandLineArgumentProcessor.java 2011-11-19 19:36:14 UTC (rev 6521)
@@ -156,9 +156,13 @@
return cmd.getOptionValue(SOURCE_SCHEMA);
}
+ public String getTablePattern() {
+ return cmd.getOptionValue(TABLE_PATTERN);
+ }
+
public List<String> getTableList() {
List<String> result = new ArrayList<String>();
- if (cmd.hasOption(TABLE_LIST)) {
+ if (hasTableList()) {
String tableListStr = cmd.getOptionValue(TABLE_LIST);
if (tableListStr.contains(",")) {
String[] parts = tableListStr.split(",");
@@ -169,7 +173,11 @@
result.add(tableListStr);
}
}
- // TODO: add support for regular expression.
return result;
}
+
+ public boolean hasTableList() {
+ return cmd.hasOption(TABLE_LIST);
+ }
+
}
Modified: 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/DBCopyCLI.java 2011-11-19 05:12:26 UTC (rev 6520)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyCLI.java 2011-11-19 19:36:14 UTC (rev 6521)
@@ -43,7 +43,13 @@
runner.setDestCatalogName(argProcessor.getDestCatalogName());
runner.setSourceSession(sessionUtil.getSessionForAlias(argProcessor.getSourceAliasName()));
runner.setDestSession(sessionUtil.getSessionForAlias(argProcessor.getDestAliasName()));
+ if (argProcessor.hasTableList()) {
+ runner.setTableList(argProcessor.getTableList());
+ } else {
+ runner.setTablePattern(argProcessor.getTablePattern());
+ }
runner.run();
+
}
catch (MissingOptionException e)
{
Modified: 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/DBCopyRunner.java 2011-11-19 05:12:26 UTC (rev 6520)
+++ trunk/sql12/cli/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/cli/DBCopyRunner.java 2011-11-19 19:36:14 UTC (rev 6521)
@@ -23,8 +23,6 @@
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;
@@ -37,6 +35,8 @@
import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager;
import net.sourceforge.squirrel_sql.plugins.dbcopy.util.DBUtil;
+import org.apache.commons.lang.StringUtils;
+
public class DBCopyRunner
{
private SessionInfoProvider sessionInfoProvider = new SessionInfoProviderImpl();
@@ -115,6 +115,25 @@
this.sourceCatalogName = sourceCatalogName;
}
+ public void setTablePattern(String pattern) throws SQLException
+ {
+ ISession sourceSession = sessionInfoProvider.getSourceSession();
+ String catalog = (sourceCatalogName==null || sourceCatalogName.equals("")) ? null : sourceCatalogName;
+ String schema = (sourceSchemaName==null || sourceSchemaName.equals("")) ? null : sourceSchemaName;
+ ISQLDatabaseMetaData md = sourceSession.getMetaData();
+
+ ITableInfo[] infos = md.getTables(catalog, schema, pattern, new String[] { "TABLE" }, null);
+ if (infos == null || infos.length == 0) {
+ System.err.println("No tables were found that match the specified :");
+ System.err.println(" catalog: "+catalog);
+ System.err.println(" schema: "+schema);
+ System.err.println(" pattern: "+pattern);
+ }
+ for (ITableInfo info : infos) {
+ tables.add(info);
+ }
+ }
+
public void setTableList(List<String> tableList) throws SQLException
{
for (String tableStr : tableList)
Added: trunk/sql12/cli/dbcopy/src/main/resources/log4j.properties
===================================================================
--- trunk/sql12/cli/dbcopy/src/main/resources/log4j.properties (rev 0)
+++ trunk/sql12/cli/dbcopy/src/main/resources/log4j.properties 2011-11-19 19:36:14 UTC (rev 6521)
@@ -0,0 +1,11 @@
+log4j.rootLogger=info, file
+
+log4j.appender.file=org.apache.log4j.RollingFileAppender
+log4j.appender.file.File=dbcopy-cli.log
+log4j.appender.file.MaxFileSize=1024KB
+log4j.appender.file.MaxBackupIndex=5
+log4j.appender.file.layout=org.apache.log4j.PatternLayout
+log4j.appender.file.layout.ConversionPattern=%d{ISO8601} [%t] %-5p %c %x - %m%n
+
+log4j.logger.org.hibernate.dialect=WARN
+
Modified: trunk/sql12/plugins/dbcopy/src/main/resources/doc/command-line.html
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/resources/doc/command-line.html 2011-11-19 05:12:26 UTC (rev 6520)
+++ trunk/sql12/plugins/dbcopy/src/main/resources/doc/command-line.html 2011-11-19 19:36:14 UTC (rev 6521)
@@ -4,17 +4,33 @@
</head>
<body>
+
+<p>
+
As of version 1.15 of the DBCopy Plugin, a new command-line interface is available for
copying tables. This can be useful for scripts in cases where copying is to be done
-in an automated way without a user present. There is a super-jar available for
-download here: repo1.maven.org/maven2/net/sf/squirrel-sql/cli/dbcopy/<version>
+in an automated way without a user present. Aliases that are configured in the SQuirreL SQL Client
+can be referenced using command-line parameters. This alias re-use keeps the amount of configuration to
+a minimum.
-It can be run with this command:
+</p><p>
-java -jar dbcopy-cli-<version>.jar
+There is a super-jar available for
+download here:
-and has the following usage:
+<br>
+<a href="http://repo1.maven.org/maven2/net/sf/squirrel-sql/cli/dbcopy-cli/1.0.3/dbcopy-cli-1.0.3.jar">
+http://repo1.maven.org/maven2/net/sf/squirrel-sql/cli/dbcopy-cli/1.0.3/dbcopy-cli-1.0.3.jar</a>
+
+</p><p>
+
+Once the jar file is downloaded, it can be run with this command:
+
+java -jar dbcopy-cli-1.0.3.jar
+
+This will display the following usage:
+
<pre>
usage: DBCopyCLI --dest-alias <arg> --dest-catalog <arg> | --dest-schema
<arg> --source-alias <arg> --source-catalog <arg> |
@@ -31,7 +47,31 @@
--table-pattern <arg> A regexp pattern to match source table names
</pre>
+Examples:
+<p>
+To copy the tables employee, customer and address from an alias called "Derby (dbcopysrc)" to
+a database with alias "DB2 (DBCPDST)", issue the following command with a comma-delimited list
+of tables:
+<pre>
+java -jar dbcopy-cli-1.0.3-SNAPSHOT.jar --source-alias "Derby (dbcopysrc)"
+ --dest-alias "DB2 (DBCPDST)"
+ --source-catalog ""
+ --source-schema "DBCOPY"
+ --dest-catalog ""
+ --dest-schema "DBCPDST"
+ --table-list employee,employer,customer,address
+</pre>
+</p>
+To copy all tables matching the pattern "emp*", use the --table-pattern argument instead of the
+--table-list :
+<pre>
+java -jar dbcopy-cli-1.0.3-SNAPSHOT.jar --source-alias "Derby (dbcopysrc)"
+ --dest-alias "DB2 (DBCPDST)"
+ --source-catalog ""
+ --source-schema "DBCOPY"
+ --dest-catalog ""
+ --dest-schema "DBCPDST"
+ --table-pattern "emp%"
+</pre>
</body>
-
-
</html>
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|