Revision: 5811
http://squirrel-sql.svn.sourceforge.net/squirrel-sql/?rev=5811&view=rev
Author: manningr
Date: 2010-08-21 17:38:07 +0000 (Sat, 21 Aug 2010)
Log Message:
-----------
Initial changes to convert from Ant build to Maven build
Added Paths:
-----------
trunk/sql12/plugins/dbcopy/pom.xml
trunk/sql12/plugins/dbcopy/src/main/
trunk/sql12/plugins/dbcopy/src/main/java/
trunk/sql12/plugins/dbcopy/src/main/java/net/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/ColTypeMapper.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyProgressMonitor.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyScripter.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPlugin.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPluginResources.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPluginSessionCallback.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/I18NBaseObject.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/SessionInfoProvider.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/UICallbacks.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/CopyTableAction.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/PasteTableAction.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/CopyTableCommand.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/PasteTableCommand.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/AbstractCopyEvent.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/AnalysisEvent.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/CopyEvent.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/CopyTableAdaptor.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/CopyTableListener.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/ErrorEvent.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/RecordEvent.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/StatementEvent.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/TableEvent.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/DBCopyGlobalPreferencesTab.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/DualProgressBarDialog.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/PreferencesPanel.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/prefs/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/prefs/DBCopyPreferenceBean.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/prefs/PreferencesManager.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/DBUtil.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/MemoryDiagnostics.java
trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/ScriptWriter.java
trunk/sql12/plugins/dbcopy/src/main/resources/
trunk/sql12/plugins/dbcopy/src/main/resources/doc/
trunk/sql12/plugins/dbcopy/src/main/resources/net/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/I18NStrings.properties
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/actions/I18NStrings.properties
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/commands/I18NStrings.properties
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/dbcopy.properties
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/gui/I18NStrings.properties
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/images/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/images/copy.gif
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/images/paste.gif
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/util/
trunk/sql12/plugins/dbcopy/src/main/resources/net/sourceforge/squirrel_sql/plugins/dbcopy/util/I18NStrings.properties
trunk/sql12/plugins/dbcopy/src/test/
trunk/sql12/plugins/dbcopy/src/test/java/
trunk/sql12/plugins/dbcopy/src/test/java/net/
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/ColTypeMapperTest.java
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPluginResourcesTest.java
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/DBCopyPluginTest.java
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/event/CopyEventTest.java
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/prefs/
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/prefs/DBCopyPreferenceBeanTest.java
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/
trunk/sql12/plugins/dbcopy/src/test/java/net/sourceforge/squirrel_sql/plugins/dbcopy/util/DBUtilTest.java
Removed Paths:
-------------
trunk/sql12/plugins/dbcopy/doc/
trunk/sql12/plugins/dbcopy/plugin_build.xml
trunk/sql12/plugins/dbcopy/src/net/
Property Changed:
----------------
trunk/sql12/plugins/dbcopy/
Property changes on: trunk/sql12/plugins/dbcopy
___________________________________________________________________
Added: svn:ignore
+ target
.settings
.project
.classpath
Deleted: trunk/sql12/plugins/dbcopy/plugin_build.xml
===================================================================
--- trunk/sql12/plugins/dbcopy/plugin_build.xml 2010-08-21 17:37:29 UTC (rev 5810)
+++ trunk/sql12/plugins/dbcopy/plugin_build.xml 2010-08-21 17:38:07 UTC (rev 5811)
@@ -1,95 +0,0 @@
-<?xml version="1.0"?>
-<!--
- This is an Apache Ant build file to build the DB Copy plugin
- for distribution.
--->
-<project name="plugin-dbcopy" default="build" basedir=".">
- <target name="init">
- <tstamp/>
- <property name="internal_name" value="dbcopy"/>
- <property name="version" value="0.10"/>
-
- <property name="debug" value="on"/>
- <property name="optimize" value="off"/>
- <property name="deprecation" value="on"/>
- <property name="targetVM" value="1.6"/>
-
- <echo message="---------------- ${internal_name} ${version} ----------------"/>
-
- <property environment="env"/>
- </target>
- <target name="initdirs" unless="p_plugin.work_dir">
- <property name="dist_dir" value="../../../squirrel-sql-dist/squirrel-sql"/>
- <property name="plugins_dist_dir" value="${dist_dir}/plugins"/>
- <property name="p_plugin.work_dir" value="${plugins_dist_dir}/${internal_name}/work"/>
- <property name="p_plugin.core_libs_dir" value="${dist_dir}/core/dist/lib"/>
- <property name="p_plugin.dist_dir" value="${plugins_dist_dir}/${internal_name}/dist"/>
- </target>
-
- <!--
- ==================================================================
- Compile the plugin.
- No parameters.
- ==================================================================
- -->
- <target name="build" depends="init, initdirs">
- <uptodate property="build.notRequired"
- targetfile="${p_plugin.dist_dir}/${internal_name}.jar" >
- <srcfiles dir= "src"/>
- </uptodate>
- <antcall target="buildinternal"/>
- </target>
-
- <target name="buildinternal" depends="init, initdirs" unless="build.notRequired">
- <property name="obj_dir" value="${p_plugin.work_dir}/obj"/>
-
- <mkdir dir="${obj_dir}"/>
- <mkdir dir="${p_plugin.dist_dir}"/>
-
- <javac srcdir="src"
- destdir="${obj_dir}"
- deprecation="${deprecation}"
- debug="${debug}"
- optimize="${optimize}"
- includeJavaRuntime="yes"
- source="${targetVM}"
- target="${targetVM}">
-
- <classpath>
- <fileset dir="${p_plugin.core_libs_dir}">
- <include name="**/*.*"/>
- </fileset>
- </classpath>
- </javac>
- <copy todir="${obj_dir}" >
- <fileset dir="src" >
- <include name="**/*.gif"/>
- <include name="**/*.jpg"/>
- <include name="**/*.jpeg"/>
- <include name="**/*.xml"/>
- <include name="**/*.properties"/>
- </fileset>
- </copy>
-
- <jar jarfile="${p_plugin.dist_dir}/${internal_name}.jar" compress="false">
- <fileset dir="${obj_dir}">
- <include name="**/*.*"/>
- </fileset>
- </jar>
-
- <copy todir="${p_plugin.dist_dir}/${internal_name}" >
- <fileset dir="doc" >
- <include name="*.*"/>
- </fileset>
- </copy>
-
- <jar jarfile="${p_plugin.dist_dir}/${internal_name}/src.jar" compress="false">
- <fileset dir=".">
- <include name="src/**/*.*"/>
- <include name="plugin_build.xml"/>
- </fileset>
- </jar>
- </target>
-
-</project>
-
Added: trunk/sql12/plugins/dbcopy/pom.xml
===================================================================
--- trunk/sql12/plugins/dbcopy/pom.xml (rev 0)
+++ trunk/sql12/plugins/dbcopy/pom.xml 2010-08-21 17:38:07 UTC (rev 5811)
@@ -0,0 +1,135 @@
+<project
+ xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>net.sf.squirrel-sql.plugins</groupId>
+ <artifactId>squirrelsql-plugins-parent-pom</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ </parent>
+ <groupId>net.sf.squirrel-sql.plugins</groupId>
+ <artifactId>dbcopy</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+ <name>Dbcopy Plugin</name>
+ <description>Dbcopy Plugin</description>
+ <inceptionYear>2001</inceptionYear>
+ <developers>
+ <developer>
+ <name>Gerd Wagner</name>
+ <roles>
+ <role>Administrator</role>
+ <role>Developer</role>
+ </roles>
+ </developer>
+ <developer>
+ <name>Rob Manning</name>
+ <roles>
+ <role>Developer</role>
+ <role>Release Manager</role>
+ </roles>
+ </developer>
+ </developers>
+ <licenses>
+ <license>
+ <name>GNU Lesser General Public License</name>
+ <url>http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt</url>
+ <distribution>repo</distribution>
+ </license>
+ </licenses>
+ <url>http://www.squirrelsql.org/</url>
+ <scm>
+ <connection>scm:svn:https://squirrel-sql.svn.sourceforge.net/svnroot/squirrel-sql/trunk/sql12/</connection>
+ <developerConnection>scm:svn:http://squirrel-sql.svn.sourceforge.net/viewvc/squirrel-sql/trunk/sql12/</developerConnection>
+ <url>http://squirrel-sql.svn.sourceforge.net/viewvc/squirrel-sql/trunk/sql12/</url>
+ </scm>
+ <issueManagement>
+ <system>SourceForge Tracker</system>
+ <url>http://sourceforge.net/tracker/?group_id=28383%26atid=393414</url>
+ </issueManagement>
+ <ciManagement>
+ <system>Hudson</system>
+ <url>https://www.squirrel-sql.org/hudson/</url>
+ </ciManagement>
+ <dependencies>
+ <dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>fw</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>squirrel-sql</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>squirrel-sql</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>net.sf.squirrel-sql</groupId>
+ <artifactId>squirrelsql-test-utils</artifactId>
+ <version>3.2.0-SNAPSHOT</version>
+ <type>pom</type>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-source-plugin</artifactId>
+ <version>${source-plugin-version}</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire-plugin-version}</version>
+ <configuration>
+ <parallel>${surefire-parallel-type}</parallel>
+ <threadCount>${surefire-thread-count}</threadCount>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>${jar-plugin-version}</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <version>${assembly-plugin-version}</version>
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>findbugs-maven-plugin</artifactId>
+ <version>${findbugs-plugin-version}</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-pmd-plugin</artifactId>
+ <version>${pmd-plugin-version}</version>
+ </plugin>
+ <plugin>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>${checkstyle-plugin-version}</version>
+ </plugin>
+ </plugins>
+ </build>
+ <profiles>
+ <!--
+ Since generating javadoc can be time-consuming, this is not done unless a "javadoc" profile is activated.
+ -->
+ <profile>
+ <id>javadoc</id>
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-javadoc-plugin</artifactId>
+ <version>${javadoc-plugin-version}</version>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
\ No newline at end of file
Copied: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/ColTypeMapper.java (from rev 5805, trunk/sql12/plugins/dbcopy/src/net/sourceforge/squirrel_sql/plugins/dbcopy/ColTypeMapper.java)
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/ColTypeMapper.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/ColTypeMapper.java 2010-08-21 17:38:07 UTC (rev 5811)
@@ -0,0 +1,277 @@
+/*
+ * Copyright (C) 2005 Rob Manning
+ * man...@us...
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; 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;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+
+import javax.swing.JFrame;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
+import net.sourceforge.squirrel_sql.fw.dialects.HibernateDialect;
+import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
+import net.sourceforge.squirrel_sql.fw.sql.JDBCTypeMapper;
+import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
+import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.util.DBUtil;
+
+import org.hibernate.MappingException;
+
+/**
+ * This class uses column type defintions from the source session table column
+ * and uses that information to determine the correct column definition in the
+ * destination database using Hibernate.
+ */
+public class ColTypeMapper {
+
+ /** Logger for this class. */
+ private final static ILogger s_log =
+ LoggerController.createLogger(ColTypeMapper.class);
+
+ /**
+ * Returns null if the user cancelled picking the dialect.
+ *
+ * @param sourceSession
+ * @param destSession
+ * @param TableColumnInfo
+ * @param sourceTableName the name of the table we are copying from. This
+ * might include the schema prefix
+ * @param destTableName the name of the table we are copying to. This
+ * might include the schema prefix
+ * @return
+ */
+ public static String mapColType(ISession sourceSession,
+ ISession destSession,
+ TableColumnInfo colInfo,
+ String sourceTableName,
+ String destTableName)
+ throws UserCancelledOperationException, MappingException
+ {
+ int colJdbcType = colInfo.getDataType();
+
+ // If source column is type 1111 (OTHER), try to use the
+ // column type name to find a type that isn't 1111.
+ colJdbcType = DBUtil.replaceOtherDataType(colInfo, sourceSession);
+
+ // If the source column is DISTINCT and the session is PostgreSQL, try to get the underlying type.
+ colJdbcType = DBUtil.replaceDistinctDataType(colInfo, sourceSession);
+
+ // Oracle can only store DECIMAL type numbers. Since regular non-decimal
+ // numbers appear as "decimal", Oracle's decimal numbers can be rather
+ // large compared to other databases (precision up to 38). Other
+ // databases can only handle this large precision in BIGINT fields, not
+ // decimal, so try to figure out if Oracle is really storing a BIGINT
+ // and claiming it is a DECIMAL. If so, convert the type to BIGINT before
+ // going any further.
+ if (DialectFactory.isOracle(sourceSession.getMetaData())
+ && colJdbcType ==Types.DECIMAL)
+ {
+ // No decimal digits strongly suggests an INTEGER of some type.
+ // Since it's not real easy to tell what kind of int (int2, int4, int8)
+ // just make it an int8 (i.e. BIGINT)
+ if (colInfo.getDecimalDigits() == 0) {
+ colJdbcType = Types.BIGINT;
+ }
+ }
+ // For char or date types this is the maximum number of characters, for
+ // numeric or decimal types this is precision.
+ int size = getColumnLength(sourceSession, colInfo, sourceTableName);
+
+ if (DialectFactory.isPointbase(destSession.getMetaData()) && size <= 0) {
+ if (DBUtil.isBinaryType(colInfo)) {
+ // For PointBase, if type maps to Pointbase "BLOB", and the size
+ // isn't valid (PB requires size for BLOBS) then set it to something
+ // reasonably large, like 16MB. 1 is the default size if no size
+ // is specified. That's practically useless :)
+ size = 16777215;
+ } else {
+ size = 20; // Numbers and such.
+ }
+ }
+ if (DialectFactory.isFirebird(destSession.getMetaData())) {
+ if (colJdbcType == java.sql.Types.DECIMAL) {
+ if (size > 18) {
+ size = 18;
+ }
+ }
+ }
+ String result = null;
+ JFrame mainFrame = destSession.getApplication().getMainFrame();
+ HibernateDialect destDialect =
+ DialectFactory.getDialect(DialectFactory.DEST_TYPE,
+ mainFrame,
+ destSession.getMetaData());
+
+ if (s_log.isDebugEnabled()) {
+ s_log.debug(
+ "ColTypeMapper.mapColType: using dialect type: "+
+ destDialect.getClass().getName()+" to find name for column "+
+ colInfo.getColumnName()+" in table "+destTableName+
+ " with type id="+colJdbcType+" ("+
+ JDBCTypeMapper.getJdbcTypeName(colJdbcType)+")");
+ }
+ if (destDialect != null) {
+ HibernateDialect sourceDialect =
+ DialectFactory.getDialect(DialectFactory.SOURCE_TYPE,
+ mainFrame,
+ sourceSession.getMetaData());
+
+ int precision = sourceDialect.getPrecisionDigits(size, colJdbcType);
+
+ if (precision > destDialect.getMaxPrecision(colJdbcType)) {
+ precision = destDialect.getMaxPrecision(colJdbcType);
+ }
+ int scale = colInfo.getDecimalDigits();
+ if (scale > destDialect.getMaxScale(colJdbcType)) {
+ scale = destDialect.getMaxScale(colJdbcType);
+ }
+ // OK, this is a hack. Currently, when precision == scale, I have
+ // no way to determine if this is valid for the actual data. The
+ // problem comes when the source db's precision/scale are greater -
+ // or reported to be greater - than the precision/scale of the
+ // destination db. In this case, it maximimizes both for the
+ // destination, causing a definition that allows 0 digits to the
+ // left of the decimal. Trouble is, without looking at the actual
+ // data, there is no way to tell if this is valid - in some cases
+ // it will be ok (0.0000000789) in others it will not be ok (100.123).
+ // So for now, make the scale be approx. one-half of the precision
+ // to accomodate the most digits to the left and right of the decimal
+ // and hopefully that covers the majority of cases.
+ if (precision <= scale) {
+ if (precision < scale) {
+ precision = scale;
+ }
+ scale = precision / 2;
+ s_log.debug(
+ "Precision == scale ("+precision+") for the destination " +
+ "database column def. This is most likely incorrect, so " +
+ "setting the scale to a more reasonable value: "+scale);
+
+ }
+ // Some dbs (like McKoi) make -1 the default for scale. Apply the
+ // same hack as above.
+ if (scale < 0) {
+ scale = precision / 2;
+ s_log.debug(
+ "scale is less than 0 for the destination " +
+ "database column def. This is most likely incorrect, so " +
+ "setting the scale to a more reasonable value: "+scale);
+ }
+ result = destDialect.getTypeName(colJdbcType, size, precision, scale);
+ }
+ return result;
+ }
+
+ /**
+ * Gets the declared length of the column, or if the length is less than or
+ * equal to 0, get the max length of the actual data in the column from the
+ * database. In the case of Firebird with certain BLOB types it always
+ * reports 0, so 2GB is hard-coded. In the case of Oracle for CLOBs always
+ * use the maximum value of the column or 4000 whichever is greatest.(Oracle
+ * BLOBs/CLOBs always report 4000 as the column size, even when column
+ * values exceed this length)
+ *
+ * @param sourceSession
+ * @param colInfo
+ * @param tableName
+ * @return
+ */
+ public static int getColumnLength(ISession sourceSession,
+ TableColumnInfo colInfo,
+ String tableName)
+ throws UserCancelledOperationException
+ {
+ if (colInfo.getDataType() == Types.TIMESTAMP
+ || colInfo.getDataType() == Types.DATE
+ || colInfo.getDataType() == Types.TIME)
+ {
+ // Date/Time types never declare a length. Just return something
+ // larger than 0 so we bypass other checks above.
+ return 10;
+ }
+ // Oracle declares the column size to be 4000, regardless of the maximum
+ // length of the CLOB field. So if the Oracle BLOB/CLOB column contains
+ // values that exceed 4000 chars and we use colInfo.getColumnSize() we
+ // might create a destination column that is too small for the data
+ // that will be copied from Oracle. We specify a default value of 4000
+ // in case the table has no records or if the BLOB/CLOB column contains
+ // only null values.
+ if (DialectFactory.isOracle(sourceSession.getMetaData())
+ && (colInfo.getDataType() == Types.CLOB
+ || colInfo.getDataType() == Types.BLOB))
+ {
+ return getColumnLengthBruteForce(sourceSession, colInfo, tableName, 4000);
+ }
+ int length = getColumnLength(sourceSession, colInfo);
+ // As a last resort, get the length of the longest value in the
+ // specified column.
+ if (length <= 0) {
+ length = getColumnLengthBruteForce(sourceSession, colInfo, tableName, 10);
+ }
+ return length;
+ }
+
+ private static int getColumnLength(ISession sourceSession,
+ TableColumnInfo colInfo)
+ throws UserCancelledOperationException
+ {
+ HibernateDialect dialect =
+ DialectFactory.getDialect(DialectFactory.SOURCE_TYPE,
+ sourceSession.getApplication().getMainFrame(),
+ sourceSession.getMetaData());
+ int length = colInfo.getColumnSize();
+ int type = colInfo.getDataType();
+ length = dialect.getColumnLength(length, type);
+ return length;
+ }
+
+ private static int getColumnLengthBruteForce(ISession sourceSession,
+ TableColumnInfo colInfo,
+ String tableName,
+ int defaultLength)
+ throws UserCancelledOperationException
+ {
+ int length = defaultLength;
+ String sql =
+ DBUtil.getMaxColumnLengthSQL(sourceSession,
+ colInfo,
+ tableName,
+ true);
+ ResultSet rs = null;
+ try {
+ rs = DBUtil.executeQuery(sourceSession, sql);
+ if (rs.next()) {
+ length = rs.getInt(1);
+ }
+ if (length <= 0) {
+ length = defaultLength;
+ }
+ } catch (SQLException e) {
+ s_log.error("ColTypeMapper.getColumnLengthBruteForce: encountered " +
+ "unexpected SQLException - "+e.getMessage());
+ } finally {
+ SQLUtilities.closeResultSet(rs);
+ }
+ return length;
+ }
+}
Copied: trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java (from rev 5805, trunk/sql12/plugins/dbcopy/src/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java)
===================================================================
--- trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java (rev 0)
+++ trunk/sql12/plugins/dbcopy/src/main/java/net/sourceforge/squirrel_sql/plugins/dbcopy/CopyExecutor.java 2010-08-21 17:38:07 UTC (rev 5811)
@@ -0,0 +1,831 @@
+/*
+ * Copyright (C) 2005 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;
+
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import net.sourceforge.squirrel_sql.client.session.ISession;
+import net.sourceforge.squirrel_sql.fw.dialects.DialectFactory;
+import net.sourceforge.squirrel_sql.fw.dialects.DialectUtils;
+import net.sourceforge.squirrel_sql.fw.dialects.UserCancelledOperationException;
+import net.sourceforge.squirrel_sql.fw.dialects.CreateScriptPreferences;
+import net.sourceforge.squirrel_sql.fw.sql.IDatabaseObjectInfo;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLConnection;
+import net.sourceforge.squirrel_sql.fw.sql.ISQLDatabaseMetaData;
+import net.sourceforge.squirrel_sql.fw.sql.ITableInfo;
+import net.sourceforge.squirrel_sql.fw.sql.PrimaryKeyInfo;
+import net.sourceforge.squirrel_sql.fw.sql.SQLDatabaseMetaData;
+import net.sourceforge.squirrel_sql.fw.sql.SQLUtilities;
+import net.sourceforge.squirrel_sql.fw.sql.TableColumnInfo;
+import net.sourceforge.squirrel_sql.fw.util.StringManager;
+import net.sourceforge.squirrel_sql.fw.util.StringManagerFactory;
+import net.sourceforge.squirrel_sql.fw.util.log.ILogger;
+import net.sourceforge.squirrel_sql.fw.util.log.LoggerController;
+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;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.DBCopyPreferenceBean;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.prefs.PreferencesManager;
+import net.sourceforge.squirrel_sql.plugins.dbcopy.util.DBUtil;
+
+import org.hibernate.MappingException;
+
+/**
+ * This is the class that performs the table copy using database connections
+ * to two different database schemas.
+ */
+public class CopyExecutor extends I18NBaseObject {
+
+ /** the class that provides out session information */
+ SessionInfoProvider prov = null;
+
+ /** the source session. This comes from prov */
+ ISession sourceSession = null;
+
+ /** the destination session. This comes from prov */
+ ISession destSession = null;
+
+ /** the thread we do the work in */
+ private Thread execThread = null;
+
+ /** what value did autocommit have in dest connection when we received it */
+ private boolean originalAutoCommitValue = true;
+
+ /** what value does autocommit have in dest connection now */
+ private boolean currentAutoCommitValue = true;
+
+ /** the user's preferences */
+ private static DBCopyPreferenceBean prefs =
+ PreferencesManager.getPreferences();
+
+ /** Logger for this class. */
+ private final static ILogger log =
+ LoggerController.createLogger(CopyExecutor.class);
+
+ /** Internationalized strings for this class. */
+ private static final StringManager s_stringMgr =
+ StringManagerFactory.getStringManager(CopyExecutor.class);
+
+ /** the list of ITableInfos that represent the user's last selection. */
+ private ArrayList<ITableInfo> selectedTableInfos = null;
+
+ /** the CopyTableListeners that have registered with this class */
+ private ArrayList<CopyTableListener> listeners =
+ new ArrayList<CopyTableListener>();
+
+ /** whether or not the user cancelled the copy operation */
+ private volatile boolean cancelled = false;
+
+ /** impl that gives us feedback from the user */
+ private UICallbacks pref = null;
+
+ /** the start time in millis that the copy operation began */
+ private long start = 0;
+
+ /** the finish time in millis that the copy operation began */
+ private long end = 0;
+
+ /**
+ * Constructor.
+ *
+ * @param p the provider of information regarding what to copy where.
+ */
+ public CopyExecutor(SessionInfoProvider p) {
+ prov = p;
+ sourceSession = prov.getCopySourceSession();
+ destSession = prov.getCopyDestSession();
+ }
+
+ /**
+ * Starts the thread that executes the copy operation.
+ */
+ public void execute() {
+ Runnable runnable = new Runnable() {
+ public void run() {
+ _execute();
+ }
+ };
+ execThread = new Thread(runnable);
+ execThread.setName("DBCopy Executor Thread");
+ execThread.start();
+ }
+
+ /**
+ * Cancels the copy operation.
+ */
+ public void cancel() {
+ cancelled = true;
+ execThread.interrupt();
+ }
+
+ /**
+ * Performs the table copy operation.
+ */
+ private void _execute() {
+ start = System.currentTimeMillis();
+ boolean encounteredException = false;
+ ISQLConnection destConn = destSession.getSQLConnection();
+ if (!analyzeTables()) {
+ return;
+ }
+ setupAutoCommit(destConn);
+ IDatabaseObjectInfo[] sourceObjs = prov.getSourceSelectedDatabaseObjects();
+ int[] counts = getTableCounts();
+ sendCopyStarted(counts);
+ String destSchema = prov.getDestSelectedDatabaseObject().getSimpleName();
+ String destCatalog = prov.getDestSelectedDatabaseObject().getCatalogName();
+ for (int i = 0; i < sourceObjs.length; i++) {
+ if (false == sourceObjs[i] instanceof ITableInfo) {
+ continue;
+ }
+ ITableInfo sourceTI = (ITableInfo)sourceObjs[i];
+ sendTableCopyStarted(sourceTI, i+1);
+ try {
+ int destTableCount = DBUtil.getTableCount(destSession,
+ destCatalog,
+ destSchema,
+ sourceTI.getSimpleName(),
+ DialectFactory.DEST_TYPE);
+ if (destTableCount == -1) {
+ createTable(sourceTI);
+ }
+ if (destTableCount > 0) {
+ try {
+ String t = sourceTI.getSimpleName();
+ if (pref.appendRecordsToExisting(t)) {
+ /* Do nothing */
+ } else if (pref.deleteTableData(sourceTI.getSimpleName())) {
+ // Yes || Yes to all
+ DBUtil.deleteDataInExistingTable(destSession,
+ destCatalog,
+ destSchema,
+ sourceTI.getSimpleName());
+ } else {
+ continue; // skip this table, try the next.
+ }
+
+ } catch (UserCancelledOperationException e) {
+ cancelled = true;
+ break;
+ }
+ }
+
+ copyTable(sourceTI, counts[i]);
+
+ if (i == sourceObjs.length - 1 && !cancelled) {
+ // We just copied the last table. Now it is safe to copy the
+ // constraints.(Well, that is, if all FK dependencies are met
+ // in the group of tables being copied.
+ // TODO: new feature could be to examine table list for FK's
+ // in tables not in the list then prompt the user to add
+ // those missing tables to the list.
+ copyConstraints(sourceObjs);
+ }
+ if (!cancelled) {
+ sendTableCopyFinished(sourceTI, i+1);
+ sleep(prefs.getTableDelayMillis());
+ }
+ } catch (SQLException e) {
+ encounteredException = true;
+ sendErrorEvent(ErrorEvent.SQL_EXCEPTION_TYPE, e);
+ break;
+ } catch (MappingException e) {
+ encounteredException = true;
+ sendErrorEvent(ErrorEvent.MAPPING_EXCEPTION_TYPE, e);
+ break;
+ } catch (UserCancelledOperationException e) {
+ cancelled = true;
+ break;
+ } catch (Exception e) {
+ encounteredException = true;
+ sendErrorEvent(ErrorEvent.GENERIC_EXCEPTION, e);
+ break;
+ }
+ }
+ restoreAutoCommit(destConn);
+ if (cancelled) {
+ sendErrorEvent(ErrorEvent.USER_CANCELLED_EXCEPTION_TYPE);
+ return;
+ }
+ if (encounteredException) {
+ return;
+ }
+ end = System.currentTimeMillis();
+
+ ISession session = prov.getCopyDestSession();
+ session.getSchemaInfo().reload(prov.getDestSelectedDatabaseObject());
+ session.getSchemaInfo().fireSchemaInfoUpdate();
+
+ notifyCopyFinished();
+ }
+
+ /**
+ * Registers the specified listener to receive copy events from this class.
+ *
+ * @param listener
+ */
+ public void addListener(CopyTableListener listener) {
+ if (listener == null) {
+ throw new IllegalArgumentException("listener cannot be null");
+ }
+ listeners.add(listener);
+ }
+
+ /**
+ * Causes the current thread to sleep for the amount of time specified if
+ * sleepTime > 0. No effect for sleepTime <= 0.
+ *
+ * @param sleepTime time in milliseconds to make the current thread sleep.
+ */
+ private void sleep(long sleepTime) {
+ boolean shouldSleep = prefs.isDelayBetweenObjects();
+ if (!shouldSleep || sleepTime <= 0) {
+ return;
+ }
+ try {
+ Thread.sleep(sleepTime);
+ } catch (InterruptedException e) {
+ // Do Nothing
+ }
+ }
+
+ /**
+ * For all selected tables, loop through their columns and see if the column
+ * name can be used as a column name in the destination database. This
+ * method will send an error event if a table has any column names that
+ * cannot be used in the destination database. This method just returns
+ * true if the user preference is not to test column names.
+ *
+ * @return true if the tables can be created in the destination database;
+ * false is returned otherwise.
+ */
+ private boolean analyzeTables() {
+ boolean result = true;
+ if (!prefs.isTestColumnNames()) {
+ return true;
+ }
+ if (DBUtil.sameDatabaseType(prov.getCopySourceSession(),
+ prov.getCopyDestSession()))
+ {
+ // No need to check column name validity when source and dest are
+ // of the same type of database.
+ return true;
+ }
+ sendAnalysisStarted();
+ try {
+ IDatabaseObjectInfo[] dbObjs = prov.getSourceSelectedDatabaseObjects();
+ for (int tableIdx = 0; tableIdx < dbObjs.length; tableIdx++) {
+ ITableInfo ti = (ITableInfo)dbObjs[tableIdx];
+ sendAnalyzingTable(ti, tableIdx);
+ DBUtil.validateColumnNames(ti, prov);
+ }
+ } catch (MappingException e) {
+ sendErrorEvent(ErrorEvent.MAPPING_EXCEPTION_TYPE, e);
+ result = false;
+ } catch (UserCancelledOperationException e) {
+ sendErrorEvent(ErrorEvent.USER_CANCELLED_EXCEPTION_TYPE, e);
+ result = false;
+ }
+ return result;
+ }
+
+
+ /**
+ * Setup the auto-commit setting on the specified connection to
+ * the user's preference.
+ *
+ * @param con
+ */
+ private void setupAutoCommit(ISQLConnection con) {
+ boolean autoCommitPref = prefs.isAutoCommitEnabled();
+ try {
+ originalAutoCommitValue = con.getAutoCommit();
+ currentAutoCommitValue = originalAutoCommitValue;
+ if (autoCommitPref != originalAutoCommitValue) {
+ con.setAutoCommit(autoCommitPref);
+ currentAutoCommitValue = autoCommitPref;
+ }
+ } catch (SQLException e) {
+ // Don't fool around with manual commit later.
+ currentAutoCommitValue = true;
+ sendErrorEvent(ErrorEvent.SETUP_AUTO_COMMIT_TYPE, e);
+ }
+
+ }
+
+ /**
+ * Restore the auto-commit setting on the specified connection to the
+ * whatever it was previous to our manipulation
+ *
+ * @param con
+ */
+ private void restoreAutoCommit(ISQLConnection con) {
+ if (originalAutoCommitValue == currentAutoCommitValue) {
+ return;
+ }
+ try {
+ con.setAutoCommit(originalAutoCommitValue);
+ } catch (SQLException e) {
+ sendErrorEvent(ErrorEvent.RESTORE_AUTO_COMMIT_TYPE, e);
+ }
+ }
+
+ private int[] getTableCounts() {
+ int[] result = null;
+
+ ISession sourceSession = prov.getCopySourceSession();
+ IDatabaseObjectInfo[] dbObjs = prov.getSourceSelectedDatabaseObjects();
+ if (dbObjs != null) {
+ result = new int[dbObjs.length];
+ selectedTableInfos = new ArrayList<ITableInfo>();
+ for (int i = 0; i < dbObjs.length; i++) {
+ if (false == dbObjs[i] instanceof ITableInfo) {
+ continue;
+ }
+ try {
+ ITableInfo ti = (ITableInfo) dbObjs[i];
+ selectedTableInfos.add(ti);
+ // This doesn't appear to work for PROGRESS RDBMS
+ //result[i] = DBUtil.getTableCount(con, ti.getSimpleName());
+ result[i] =
+ DBUtil.getTableCount(sourceSession,
+ ti.getCatalogName(),
+ ti.getSchemaName(),
+ ti.getSimpleName(),
+ DialectFactory.SOURCE_TYPE);
+ } catch (Exception e) {
+ log.error("",e);
+ result[i] = 0;
+ }
+ }
+ }
+ return result;
+ }
+
+ private void sendAnalysisStarted() {
+ AnalysisEvent event = new AnalysisEvent(prov);
+ Iterator<CopyTableListener> i = listeners.iterator();
+ while (i.hasNext()) {
+ CopyTableListener listener = i.next();
+ listener.tableAnalysisStarted(event);
+ }
+ }
+
+ private void sendAnalyzingTable(ITableInfo ti, int number) {
+ TableEvent event = new TableEvent(prov);
+ event.setTableCount(prov.getSourceSelectedDatabaseObjects().length);
+ event.setTableNumber(number);
+ Iterator<CopyTableListener> i = listeners.iterator();
+ event.setTableName(ti.getSimpleName());
+ while (i.hasNext()) {
+ CopyTableListener listener = i.next();
+ listener.analyzingTable(event);
+ }
+ }
+
+ private void sendCopyStarted(int[] tableCounts) {
+ CopyEvent event = new CopyEvent(prov);
+ event.setTableCounts(tableCounts);
+ Iterator<CopyTableListener> i = listeners.iterator();
+ while (i.hasNext()) {
+ CopyTableListener listener = i.next();
+ listener.copyStarted(event);
+ }
+ }
+
+ private void sendTableCopyStarted(ITableInfo ti, int number) {
+ TableEvent event = new TableEvent(prov);
+ event.setTableNumber(number);
+ event.setTableCount(prov.getSourceSelectedDatabaseObjects().length);
+ event.setTableName(ti.getSimpleName());
+ Iterator<CopyTableListener> i = listeners.iterator();
+ while (i.hasNext()) {
+ CopyTableListener listener = i.next();
+ listener.tableCopyStarted(event);
+ }
+ }
+
+ private void sendTableCopyFinished(ITableInfo ti, int number) {
+ TableEvent event = new TableEvent(prov);
+ event.setTableNumber(number);
+ event.setTableCount(prov.getSourceSelectedDatabaseObjects().length);
+ event.setTableName(ti.getSimpleName());
+ Iterator<CopyTableListener> i = listeners.iterator();
+ while (i.hasNext()) {
+ CopyTableListener listener = i.next();
+ listener.tableCopyFinished(event);
+ }
+ }
+
+ /**
+ * Send an error event message to all CopyTableListeners
+ * @param type the type of the ErrorEvent.
+ */
+ private void sendErrorEvent(int type) {
+ sendErrorEvent(type, null);
+ }
+
+ /**
+ * Send an error event message to all CopyTableListeners
+ * @param type the type of the ErrorEvent.
+ * @param e the exception that was encountered.
+ */
+ private void sendErrorEvent(int type, Exception e) {
+ ErrorEvent event = new ErrorEvent(prov, type);
+ event.setException(e);
+ Iterator<CopyTableListener> i = listeners.iterator();
+ while (i.hasNext()) {
+ CopyTableListener listener = i.next();
+ listener.handleError(event);
+ }
+ }
+
+ private void sendRecordEvent(int number, int count) {
+ RecordEvent event = new RecordEvent(prov, number, count);
+ Iterator<CopyTableListener> i = listeners.iterator();
+ while (i.hasNext()) {
+ CopyTableListener listener = i.next();
+ listener.recordCopied(event);
+ }
+ }
+
+ private void sendStatementEvent(String sql, String[] vals) {
+ StatementEvent event =
+ new StatementEvent(sql, StatementEvent.INSERT_RECORD_TYPE);
+ event.setBindValues(vals);
+ Iterator<CopyTableListener> i = listeners.iterator();
+ while (i.hasNext()) {
+ CopyTableListener listener = i.next();
+ listener.statementExecuted(event);
+ }
+ }
+
+ private void notifyCopyFinished() {
+ int seconds = (int)getElapsedSeconds();
+ Iterator<CopyTableListener> i = listeners.iterator();
+ while (i.hasNext()) {
+ CopyTableListener listener = i.next();
+ listener.copyFinished(seconds);
+ }
+ }
+
+ /**
+ *
+ * @return
+ */
+ private long getElapsedSeconds() {
+ long result = 1;
+ double elapsed = end - start;
+ if (elapsed > 1000) {
+ result = Math.round(elapsed / 1000);
+ }
+ return result;
+ }
+
+ /**
+ *
+ * @param sourceTableInfo
+ * @param sourceTableCount
+ * @throws MappingException
+ * @throws SQLException
+ */
+ private void copyTable(ITableInfo sourceTableInfo, int sourceTableCount)
+ throws MappingException, SQLException, UserCancelledOperationException
+ {
+ PreparedStatement insertStmt = null;
+ ResultSet rs = null;
+ if (cancelled) {
+ return;
+ }
+ if (!PreferencesManager.getPreferences().isCopyData()) {
+ return;
+ }
+ ISQLConnection sourceConn = prov.getCopySourceSession().getSQLConnection();
+ ISQLConnection destConn = prov.getCopyDestSession().getSQLConnection();
+ SQLDatabaseMetaData sourceMetaData = sourceConn.getSQLMetaData();
+ SQLDatabaseMetaData destMetaData = destConn.getSQLMetaData();
+ try {
+ String destSchema =
+ prov.getDestSelectedDatabaseObject().getSimpleName();
+ ITableInfo destTableInfo =
+ DBUtil.getTableInfo(prov.getCopyDestSession(),
+ destSchema,
+ sourceTableInfo.getSimpleName());
+
+ TableColumnInfo[] sourceInfos = sourceMetaData.getColumnInfo(sourceTableInfo);
+ TableColumnInfo[] destInfos = destMetaData.getColumnInfo(destTableInfo);
+
+ destInfos = sort(sourceInfos,
+ destInfos,
+ sourceTableInfo.getQualifiedName(),
+ destTableInfo.getQualifiedName());
+
+ String sourceColList = DBUtil.getColumnList(sourceInfos);
+ String destColList = DBUtil.getColumnList(destInfos);
+
+ String selectSQL = DBUtil.getSelectQuery(prov,
+ sourceColList,
+ sourceTableInfo);
+ String insertSQL = DBUtil.getInsertSQL(prov, destColList,
+ sourceTableInfo,
+ destInfos.length);
+ insertStmt = destConn.prepareStatement(insertSQL);
+
+ int count = 1;
+ int commitCount = prefs.getCommitCount();
+ int columnCount = destInfos.length;
+ String[] bindVarVals = new String[columnCount];
+
+ boolean foundLOBType = false;
+ // Loop through source records...
+ DBUtil.setLastStatement(selectSQL);
+ rs = DBUtil.executeQuery(prov.getCopySourceSession(), selectSQL);
+ DBUtil.setLastStatement(insertSQL);
+ boolean isMysql = DialectFactory.isMySQL(destSession.getMetaData());
+ boolean isSourceOracle =
+ DialectFactory.isOracle(sourceSession.getMetaData());
+ boolean isDestOracle = DialectFactory.isOracle(destSession.getMetaData());
+ while (rs.next() && !cancelled) {
+ // MySQL driver gets unhappy when we use the same
+ // PreparedStatement to bind null and non-null LOB variables
+ // without clearing the parameters first.
+ if (isMysql && foundLOBType)
+ {
+ insertStmt.clearParameters();
+ }
+ StringBuilder lastStmtValuesBuffer = new StringBuilder();
+ lastStmtValuesBuffer.append("\n(Bind variable values: ");
+ for (int i = 0; i < columnCount; i++) {
+
+ int sourceColType = sourceInfos[i].getDataType();
+ // If source column is type 1111 (OTHER), try to use the
+ // column type name to find a type that isn't 1111.
+ sourceColType = DBUtil.replaceOtherDataType(sourceInfos[i], prov.getCopySourceSession());
+ sourceColType = getDateReplacement(sourceColType,
+ isSourceOracle);
+
+ int destColType = destInfos[i].getDataType();
+ // If source column is type 1111 (OTHER), try to use the
+ // column type name to find a type that isn't 1111.
+ destColType = DBUtil.replaceOtherDataType(destInfos[i], prov.getCopyDestSession());
+ destColType = getDateReplacement(destColType, isDestOracle);
+
+
+ String bindVal = DBUtil.bindVariable(insertStmt,
+ sourceColType,
+ destColType,
+ i+1,
+ rs);
+ bindVarVals[i] = bindVal;
+ lastStmtValuesBuffer.append(bindVal);
+ if (i + 1 < columnCount) {
+ lastStmtValuesBuffer.append(", ");
+ }
+ if (isLOBType(destColType)) {
+ foundLOBType = true;
+ }
+ }
+ lastStmtValuesBuffer.append(")");
+ DBUtil.setLastStatementValues(lastStmtValuesBuffer.toString());
+ sendStatementEvent(insertSQL, bindVarVals);
+ insertStmt.executeUpdate();
+ sendRecordEvent(count, sourceTableCount);
+ count++;
+ if (!currentAutoCommitValue) {
+ if ((count % commitCount) == 0) {
+ commitConnection(destConn);
+ }
+ }
+ sleep(prefs.getRecordDelayMillis());
+ }
+ } finally {
+ SQLUtilities.closeResultSet(rs);
+ SQLUtilities.closeStatement(insertStmt);
+ if (!currentAutoCommitValue) {
+ commitConnection(destConn);
+ }
+ }
+ }
+
+ /**
+ * This will return a TIMESTAMP type when the specified type is a DATE and
+ * isOracle is true. This is done so that Oracle dates that have a time
+ * component, will have the time component copied correctly.
+ *
+ * @param session
+ * @param type
+ * @param isOracle
+ * @return
+ */
+ private int getDateReplacement(int type, boolean isOracle)
+ {
+ int result = type;
+ if (isOracle && type == java.sql.Types.DATE) {
+ result = java.sql.Types.TIMESTAMP;
+ }
+ return result;
+ }
+
+ /**
+ * Returns a boolean value indicating whether or not the specific column
+ * type is a binary or LOB column.
+ * @param columnType the JDBC type.
+ *
+ * @return true if the specified type is LOB; false otherwise.
+ */
+ private boolean isLOBType(int columnType) {
+ if (columnType == Types.BLOB
+ || columnType == Types.CLOB
+ || columnType == Types.LONGVARBINARY
+ || columnType == Types.BINARY)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Sorts the specified destInfos array based on the order of the sourceInfos
+ * array. Not a very efficient algorthim, but it gets the job done.
+ * TODO: rewrite this using Collections sorting capability.
+ *
+ * @param sourceInfos
+ * @param destInfos
+ * @param sourceTableName
+ * @param destTableName
+ * @return a re-ordered version of the specified destInfos array
+ * @throws MappingException if the arrays differ in length or column names.
+ */
+ private TableColumnInfo[] sort(TableColumnInfo[] sourceInfos,
+ TableColumnInfo[] destInfos,
+ String sourceTableName,
+ String destTableName)
+ throws MappingException
+ {
+ if (sourceInfos.length != destInfos.length) {
+ //i18n[CopyExecutor.tablecolmismatch=Column count for table {0} in
+ //source database is {1}, but column count for table {2} in
+ //destination database is {3}
+ String msg =
+ s_stringMgr.getString("CopyExecutor.tablecolmismatch",
+ new Object[] {
+ sourceTableName,
+ Integer.valueOf(sourceInfos.length),
+ destTableName,
+ Integer.valueOf(destInfos.length)});
+ throw new MappingException(msg);
+ }
+ ArrayList<TableColumnInfo> result = new ArrayList<TableColumnInfo>();
+
+ for (int sourceIdx = 0; sourceIdx < sourceInfos.length; sourceIdx++) {
+ TableColumnInfo sourceInfo = sourceInfos[sourceIdx];
+ // trim the column name in case of HADB
+ String sourceColumnName = sourceInfo.getColumnName().trim();
+ boolean found = false;
+ int destIdx = 0;
+ while (!found && destIdx < destInfos.length) {
+ TableColumnInfo destInfo = destInfos[destIdx];
+ // trim the column name in case of HADB
+ String destColumnName = destInfo.getColumnName().trim();
+ if (d...
[truncated message content] |