Revision: 3973
Author: [email protected]
Date: Thu Nov 4 08:06:24 2010
Log: Fix for bug 3058: SQL types are now generated for the correct
platforms when performing cross-platform database comparisons.
http://code.google.com/p/power-architect/source/detail?r=3973
Modified:
/trunk/src/main/java/ca/sqlpower/architect/ArchitectUtils.java
/trunk/src/main/java/ca/sqlpower/architect/diff/CompareSQL.java
/trunk/src/main/java/ca/sqlpower/architect/swingui/CompareDMPanel.java
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ArchitectUtils.java Mon Jul
12 07:31:38 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/ArchitectUtils.java Thu Nov
4 08:06:24 2010
@@ -22,6 +22,8 @@
import java.io.IOException;
import java.net.URL;
import java.sql.Types;
+import java.util.Collections;
+import java.util.List;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
@@ -35,6 +37,7 @@
import ca.sqlpower.sqlobject.SQLObjectException;
import ca.sqlpower.sqlobject.SQLRelationship;
import ca.sqlpower.sqlobject.SQLTable;
+import ca.sqlpower.sqlobject.UserDefinedSQLType;
import ca.sqlpower.swingui.SPSUtils;
import ca.sqlpower.util.ExceptionReport;
@@ -332,4 +335,36 @@
return c.getSimpleName();
}
}
-}
+
+ /**
+ * Gets the basic SQL types from the PL.INI file for a session
+ */
+ public static List<UserDefinedSQLType> getSQLTypes(ArchitectSession s)
{
+ return
Collections.unmodifiableList(s.getContext().getPlDotIni().getSQLTypes());
+ }
+
+ /**
+ * Gets the basic SQL type from the list of SQL types by comparing
jdbc codes.
+ */
+ public static UserDefinedSQLType getSQLType(int sqlType,
List<UserDefinedSQLType> types) {
+ for (UserDefinedSQLType st : types) {
+ if (st.getType().equals(sqlType)) {
+ return st;
+ }
+ }
+ throw new IllegalArgumentException(sqlType + " is not a sql
datatype.");
+ }
+
+ /**
+ * Modifies a table so that all its columns have upstream types, using
+ * the types from the session's pl.ini.
+ */
+ public static void setUpstreamTypesInTable(SQLTable table,
ArchitectSession session) {
+ List<UserDefinedSQLType> types = getSQLTypes(session);
+ for (SQLColumn col : table.getColumnsWithoutPopulating()) {
+ if (col.getUserDefinedSQLType().getUpstreamType() == null) {
+ col.setType(getSQLType(col.getType(), types));
+ }
+ }
+ }
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/diff/CompareSQL.java Wed
Sep 8 11:59:31 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/diff/CompareSQL.java Thu
Nov 4 08:06:24 2010
@@ -29,6 +29,7 @@
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
+import ca.sqlpower.architect.ArchitectSession;
import ca.sqlpower.architect.ArchitectUtils;
import ca.sqlpower.dao.PersisterUtils;
import ca.sqlpower.dao.session.SessionPersisterSuperConverter;
@@ -168,7 +169,12 @@
setFinished(false);
setStarted(false);
}
+
public List<DiffChunk<SQLObject>> generateTableDiffs() throws
SQLObjectException {
+ return generateTableDiffs(null);
+ }
+
+ public List<DiffChunk<SQLObject>> generateTableDiffs(ArchitectSession
session) throws SQLObjectException {
setStarted(true);
setFinished(false);
try {
@@ -203,6 +209,10 @@
// Will loop until one or both the list reaches its
last table
while (sourceContinue && targetContinue &&
!isCancelled()) {
logger.debug("Generating table diffs for " +
sourceTable.getName());
+ if (session != null) {
+
ArchitectUtils.setUpstreamTypesInTable(sourceTable, session);
+
ArchitectUtils.setUpstreamTypesInTable(targetTable, session);
+ }
DiffChunk<SQLObject> chunk = null;
int compareResult = getObjectComparator().compare(sourceTable,
targetTable);
@@ -288,6 +298,9 @@
}
// If any tables in the sourceList still exist, the
changes are added
while (sourceContinue && !isCancelled()) {
+ if (session != null) {
+
ArchitectUtils.setUpstreamTypesInTable(sourceTable, session);
+ }
results.add(new
DiffChunk<SQLObject>(sourceTable, DiffType.LEFTONLY));
incProgress(1, sourceTable, null);
//results.addAll(generateColumnDiffs(sourceTable, null));
@@ -301,7 +314,9 @@
//If any remaining tables in the targetList still exist, they are now
being added
while (targetContinue && !isCancelled()) {
-
+ if (session != null) {
+
ArchitectUtils.setUpstreamTypesInTable(targetTable, session);
+ }
results.add(new
DiffChunk<SQLObject>(targetTable, DiffType.RIGHTONLY));
incProgress(1, null, targetTable);
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/CompareDMPanel.java
Mon Jul 12 08:21:11 2010
+++ /trunk/src/main/java/ca/sqlpower/architect/swingui/CompareDMPanel.java
Thu Nov 4 08:06:24 2010
@@ -1313,9 +1313,9 @@
}
setJobSize(sourceComp.getJobSize() +
targetComp.getJobSize());
logger.debug("Generating TableDiffs for source");
- diff = sourceComp.generateTableDiffs();
+ diff = sourceComp.generateTableDiffs(session);
logger.debug("Generating TableDiffs for target");
- diff1 = targetComp.generateTableDiffs();
+ diff1 = targetComp.generateTableDiffs(session);
message = "Finished";
logger.debug("Finished Compare");
}