Revision: 3995
Author: [email protected]
Date: Thu Nov 25 13:42:55 2010
Log: Updated the fixes to 3063 and 1827. The CompareDMFormatter should not have known about platform specific DDL generation so the diff chunks are now passed to the generators. Also the class level alter variable is no longer in existence and a local boolean is passed down to the correct method instead.
http://code.google.com/p/power-architect/source/detail?r=3995

Modified:
 /trunk/src/main/java/ca/sqlpower/architect/ddl/DDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/MySqlDDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/OracleDDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/ddl/PostgresDDLGenerator.java
/trunk/src/main/java/ca/sqlpower/architect/ddl/SQLServer2005DDLGenerator.java
 /trunk/src/main/java/ca/sqlpower/architect/swingui/CompareDMFormatter.java

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/DDLGenerator.java Wed Jul 7 11:16:36 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/DDLGenerator.java Thu Nov 25 13:42:55 2010
@@ -24,6 +24,7 @@
 import java.util.List;
 import java.util.Map;

+import ca.sqlpower.diff.DiffChunk;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLIndex;
 import ca.sqlpower.sqlobject.SQLObject;
@@ -121,11 +122,16 @@

     /**
* Appends the DDL statement for modifying the given column's datatype and - * nullability in its parent table in this DDL Generator's target schema/catalog.
-     *
- * @param c The column to create a MODIFY or ALTER COLUMN statement for.
+     * nullability in its parent table in this DDL Generator's target
+     * schema/catalog.
+     *
+     * @param c
+ * The column to create a MODIFY or ALTER COLUMN statement for.
+     * @param diffChunk
+ * A collection of changes that need to be done to the column. + * Helpful to decide what to include in the modify column script.
      */
-    public void modifyColumn(SQLColumn c);
+    public void modifyColumn(SQLColumn c, DiffChunk<SQLObject> diffChunk);

     /**
      * Appends the DDL statement for creating the given FK relationship
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Thu Jul 22 12:40:28 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/GenericDDLGenerator.java Thu Nov 25 13:42:55 2010
@@ -37,6 +37,7 @@
 import ca.sqlpower.architect.DepthFirstSearch;
 import ca.sqlpower.architect.ddl.DDLStatement.StatementType;
 import ca.sqlpower.architect.profile.ProfileFunctionDescriptor;
+import ca.sqlpower.diff.DiffChunk;
 import ca.sqlpower.object.SPResolverRegistry;
 import ca.sqlpower.object.SPVariableHelper;
 import ca.sqlpower.object.SPVariableResolver;
@@ -667,7 +668,7 @@

        }

-       public void modifyColumn(SQLColumn c) {
+       public void modifyColumn(SQLColumn c, DiffChunk<SQLObject> diffChunk) {
                Map<String, SQLObject> colNameMap = new HashMap<String, 
SQLObject>();
                SQLTable t = c.getParent();
                print("\nALTER TABLE ");
@@ -698,6 +699,32 @@
         * it in the context of a valid SQL statement.
         */
protected String columnDefinition(SQLColumn c, Map<String, SQLObject> colNameMap) {
+           return columnDefinition(c, colNameMap, true);
+       }
+
+    /**
+ * Creates a SQL DDL snippet which consists of the column name, data type,
+     * default value, and nullability clauses.
+     *
+     * @param c
+     *            The column to generate the DDL snippet for.
+     * @param colNameMap
+ * Dirty hack for coming up with unique physical names. The final + * physical name generated in the SQL snippet will be stored in
+     *            this map. If you don't care about producing unique column
+     *            names, just pass in a freshly-created map. See
+     *            {...@link #createPhysicalName(Map, SQLObject)} for more
+     *            information.
+     * @param alterNullability
+     *            If true the nullability of the column will be changed. If
+ * false it will be skipped. For Oracle if a column is currently
+     *            null you cannot alter it to be null again.
+ * @return The SQL snippet that describes the given column. The returned
+     *         string is not delimited at the beginning or end: you're
+ * responsible for properly putting it in the context of a valid SQL
+     *         statement.
+     */
+ protected String columnDefinition(SQLColumn c, Map<String, SQLObject> colNameMap, boolean alterNullability) {
         StringBuffer def = new StringBuffer();

         // Column name
@@ -714,7 +741,9 @@
             def.append(defaultValue);
         }

-        def.append(columnNullability(c));
+        if (alterNullability) {
+            def.append(columnNullability(c));
+        }

         List<SQLCheckConstraint> checkConstraints;
         List<SQLEnumeration> enumerations;
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/MySqlDDLGenerator.java Fri Jul 9 08:00:06 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/MySqlDDLGenerator.java Thu Nov 25 13:42:55 2010
@@ -30,6 +30,7 @@
 import org.apache.log4j.Logger;

 import ca.sqlpower.architect.ddl.DDLStatement.StatementType;
+import ca.sqlpower.diff.DiffChunk;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLEnumeration;
 import ca.sqlpower.sqlobject.SQLIndex;
@@ -703,7 +704,7 @@
     }

     @Override
-    public void modifyColumn(SQLColumn c) {
+    public void modifyColumn(SQLColumn c, DiffChunk<SQLObject> diffChunk) {
Map<String, SQLObject> colNameMap = new HashMap<String, SQLObject>();
         SQLTable t = c.getParent();
         print("\nALTER TABLE ");
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/OracleDDLGenerator.java Fri Nov 5 13:35:04 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/OracleDDLGenerator.java Thu Nov 25 13:42:55 2010
@@ -28,6 +28,8 @@
 import org.apache.log4j.Logger;

 import ca.sqlpower.architect.ddl.DDLStatement.StatementType;
+import ca.sqlpower.diff.DiffChunk;
+import ca.sqlpower.diff.PropertyChange;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLIndex;
 import ca.sqlpower.sqlobject.SQLIndex.AscendDescend;
@@ -50,8 +52,6 @@
                super();
        }

-       private boolean alter = true;
-
        public static final String GENERATOR_VERSION = "$Revision$";

private static final Logger logger = Logger.getLogger(OracleDDLGenerator.class);
@@ -322,37 +322,34 @@
      * "ALTER COLUMN".
      */
     @Override
-    public void modifyColumn(SQLColumn c) {
+    public void modifyColumn(SQLColumn c, DiffChunk<SQLObject> diffChunk) {
+        boolean alter = false;
+        for (PropertyChange change : diffChunk.getPropertyChanges()) {
+            if (change.getPropertyName().equals("nullable")) {
+                alter = true;
+                break;
+            }
+        }
+
                Map<String, SQLObject> colNameMap = new HashMap<String, 
SQLObject>();
                SQLTable t = c.getParent();
                print("\nALTER TABLE ");
                print(toQualifiedName(t.getPhysicalName()));
                print(" MODIFY ");
-               print(columnDefinition(c,colNameMap));
+               print(columnDefinition(c,colNameMap, alter));
                endStatement(StatementType.MODIFY, c);
        }

-    /**
- * We need to tell if the nullability is changing or not because Oracle syntax requires NULL if - * you are changing to NULL, but if is the same, if you add the NULL, it doesn't work.
-     * Same for NOT NULL. Yay oracle.
-     */
-    public void modifyColumn(SQLColumn c, boolean alter) {
-        this.alter = alter;
-        modifyColumn(c);
-        this.alter = true;
-    }
-
-    protected String columnNullability(SQLColumn c) {
+ protected String columnNullability(SQLColumn c, boolean alterNullability) {
         GenericTypeDescriptor td = failsafeGetTypeDescriptor(c);
         if (c.isDefinitelyNullable()) {
                        if (! td.isNullable()) {
                                throw new UnsupportedOperationException
("The data type "+td.getName()+" is not nullable on the target database platform.");
                        }
-                       return alter ? " NULL" : "";
+                       return " NULL";
                } else {
-                       return alter ? " NOT NULL" : "";
+                       return " NOT NULL";
                }
     }

=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/PostgresDDLGenerator.java Wed Jul 7 11:16:36 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/PostgresDDLGenerator.java Thu Nov 25 13:42:55 2010
@@ -28,6 +28,7 @@
 import org.apache.log4j.Logger;

 import ca.sqlpower.architect.ddl.DDLStatement.StatementType;
+import ca.sqlpower.diff.DiffChunk;
 import ca.sqlpower.sql.SQL;
 import ca.sqlpower.sqlobject.SQLColumn;
 import ca.sqlpower.sqlobject.SQLIndex;
@@ -276,7 +277,7 @@
     }

     @Override
-    public void modifyColumn(SQLColumn c) {
+    public void modifyColumn(SQLColumn c, DiffChunk<SQLObject> diffChunk) {
Map<String, SQLObject> colNameMap = new HashMap<String, SQLObject>();
         SQLTable t = c.getParent();
         print("\nALTER TABLE ONLY ");
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/ddl/SQLServer2005DDLGenerator.java Mon May 10 11:25:06 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/ddl/SQLServer2005DDLGenerator.java Thu Nov 25 13:42:55 2010
@@ -21,6 +21,10 @@

 import java.sql.SQLException;

+import ca.sqlpower.diff.DiffChunk;
+import ca.sqlpower.diff.PropertyChange;
+import ca.sqlpower.sqlobject.SQLColumn;
+import ca.sqlpower.sqlobject.SQLObject;
 import ca.sqlpower.sqlobject.SQLRelationship;
 import ca.sqlpower.sqlobject.SQLRelationship.UpdateDeleteRule;

@@ -56,4 +60,27 @@
     public boolean supportsUpdateAction(SQLRelationship r) {
         return r.getUpdateRule() != UpdateDeleteRule.RESTRICT;
     }
-}
+
+    @Override
+    public void modifyColumn(SQLColumn c, DiffChunk<SQLObject> diffChunk) {
+        if (diffChunk.getPropertyChanges().size() == 1) {
+ PropertyChange propertyChange = diffChunk.getPropertyChanges().get(0);
+            String newVal = propertyChange.getNewValue();
+            String oldVal = propertyChange.getOldValue();
+            String dateType = "DATE";
+            String timeType = "TIME";
+            String timestampType = "TIMESTAMP";
+            if (propertyChange.getPropertyName().equals("type") &&
+ (newVal.equalsIgnoreCase(dateType) || newVal.equalsIgnoreCase(timeType) ||
+                            newVal.equalsIgnoreCase(timestampType)) &&
+ (oldVal.equalsIgnoreCase(dateType) || oldVal.equalsIgnoreCase(timeType) ||
+                            oldVal.equalsIgnoreCase(timestampType))) {
+ //skip becuase they are actually of the same type for SQL Server.
+            } else {
+                super.modifyColumn(c, diffChunk);
+            }
+        } else {
+            super.modifyColumn(c, diffChunk);
+        }
+    }
+}
=======================================
--- /trunk/src/main/java/ca/sqlpower/architect/swingui/CompareDMFormatter.java Wed Nov 24 14:04:42 2010 +++ /trunk/src/main/java/ca/sqlpower/architect/swingui/CompareDMFormatter.java Thu Nov 25 13:42:55 2010
@@ -39,8 +39,6 @@

 import ca.sqlpower.architect.ddl.DDLGenerator;
 import ca.sqlpower.architect.ddl.LiquibaseDDLGenerator;
-import ca.sqlpower.architect.ddl.OracleDDLGenerator;
-import ca.sqlpower.architect.ddl.SQLServer2005DDLGenerator;
 import ca.sqlpower.architect.diff.ArchitectDiffException;
 import ca.sqlpower.architect.swingui.CompareDMPanel.SourceOrTargetStuff;
import ca.sqlpower.architect.swingui.CompareDMSettings.SourceOrTargetSettings;
@@ -287,41 +285,7 @@
             } else if (chunk.getType() == DiffType.SQL_MODIFIED) {
                 if (chunk.getData() instanceof SQLColumn) {
                     SQLColumn c = (SQLColumn) chunk.getData();
- if(OracleDDLGenerator.class.isAssignableFrom(gen.getClass())) {
-                        boolean changeNull = false;
- for (PropertyChange change : chunk.getPropertyChanges()) { - if (change.getPropertyName().equals("nullable")) {
-                                changeNull = true;
-                                break;
-                            }
-                        }
- ((OracleDDLGenerator)gen).modifyColumn(c, changeNull); - } else if (SQLServer2005DDLGenerator.class.isAssignableFrom(gen.getClass())) { - //Fix for the first part of bug 1827. All time data types in sql server - //collapse to Datetime which then gets converted to a timestamp.
-                        if (chunk.getPropertyChanges().size() == 1) {
- PropertyChange propertyChange = chunk.getPropertyChanges().get(0);
-                            String newVal = propertyChange.getNewValue();
-                            String oldVal = propertyChange.getOldValue();
-                            String dateType = "DATE";
-                            String timeType = "TIME";
-                            String timestampType = "TIMESTAMP";
- if (propertyChange.getPropertyName().equals("type") && - (newVal.equalsIgnoreCase(dateType) || newVal.equalsIgnoreCase(timeType) || - newVal.equalsIgnoreCase(timestampType)) && - (oldVal.equalsIgnoreCase(dateType) || oldVal.equalsIgnoreCase(timeType) || - oldVal.equalsIgnoreCase(timestampType))) { - //skip becuase they are actually of the same type for SQL Server.
-                            } else {
-                                gen.modifyColumn(c);
-                            }
-
-                        } else {
-                            gen.modifyColumn(c);
-                        }
-
-                    } else
-                        gen.modifyColumn(c);
+                    gen.modifyColumn(c, chunk);
                 }
                 for (PropertyChange change : chunk.getPropertyChanges()) {
                     if (change.getPropertyName().equals("remarks")) {

Reply via email to