db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r517050 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java test/org/apache/ddlutils/io/TestAlteration.java
Date Sun, 11 Mar 2007 23:43:31 GMT
Author: tomdz
Date: Sun Mar 11 16:43:26 2007
New Revision: 517050

URL: http://svn.apache.org/viewvc?view=rev&rev=517050
Log:
Fix for DDLUTILS-159

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java?view=diff&rev=517050&r1=517049&r2=517050
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java Sun
Mar 11 16:43:26 2007
@@ -372,6 +372,27 @@
                                                 Map      parameters,
                                                 List     changes) throws IOException
     {
+        // While Oracle has an ALTER TABLE MODIFY statement, it is somewhat limited
+        // esp. if there is data in the table, so we don't use it
+        for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
+        {
+            TableChange change = (TableChange)changeIt.next();
+
+            if (change instanceof AddColumnChange)
+            {
+                AddColumnChange addColumnChange = (AddColumnChange)change;
+
+                // Oracle can only add not insert columns
+                // Also, we cannot add NOT NULL columns unless they have a default value
+                if (!addColumnChange.isAtEnd() ||
+                    (addColumnChange.getNewColumn().isRequired() && (addColumnChange.getNewColumn().getDefaultValue()
== null)))
+                {
+                    // we need to rebuild the full table
+                    return;
+                }
+            }
+        }
+
         // First we drop primary keys as necessary
         for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
         {
@@ -401,16 +422,8 @@
 
             if (change instanceof AddColumnChange)
             {
-                AddColumnChange addColumnChange = (AddColumnChange)change;
-
-                // Oracle can only add not insert columns
-                // Also, we cannot add NOT NULL columns unless they have a default value
-                if (addColumnChange.isAtEnd() &&
-                    (!addColumnChange.getNewColumn().isRequired() || (addColumnChange.getNewColumn().getDefaultValue()
!= null)))
-                {
-                    processChange(currentModel, desiredModel, addColumnChange);
-                    changeIt.remove();
-                }
+                processChange(currentModel, desiredModel, (AddColumnChange)change);
+                changeIt.remove();
             }
             else if (change instanceof RemoveColumnChange)
             {

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java?view=diff&rev=517050&r1=517049&r2=517050
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java Sun Mar
11 16:43:26 2007
@@ -98,6 +98,22 @@
                                                 Map      parameters,
                                                 List     changes) throws IOException
     {
+        for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
+        {
+            TableChange change = (TableChange)changeIt.next();
+
+            if (change instanceof AddColumnChange)
+            {
+                AddColumnChange addColumnChange = (AddColumnChange)change;
+
+                // SapDB can only add not insert columns
+                if (!addColumnChange.isAtEnd())
+                {
+                    return;
+                }
+            }
+        }
+
         // First we drop primary keys as necessary
         for (Iterator changeIt = changes.iterator(); changeIt.hasNext();)
         {
@@ -126,14 +142,8 @@
 
             if (change instanceof AddColumnChange)
             {
-                AddColumnChange addColumnChange = (AddColumnChange)change;
-
-                // SapDB can only add not insert columns
-                if (addColumnChange.isAtEnd())
-                {
-                    processChange(currentModel, desiredModel, addColumnChange);
-                    changeIt.remove();
-                }
+                processChange(currentModel, desiredModel, (AddColumnChange)change);
+                changeIt.remove();
             }
             else if (change instanceof ColumnDefaultValueChange)
             {

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java?view=diff&rev=517050&r1=517049&r2=517050
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java Sun Mar 11 16:43:26
2007
@@ -2119,7 +2119,7 @@
                 "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
                 "<database name='roundtriptest'>\n"+
                 "  <table name='roundtrip'>\n"+
-                "    <column name='pk' type='NUMERIC' size='12,0' primaryKey='true' required='true'
autoIncrement='true'/>\n"+
+                "    <column name='pk' type='INTEGER' primaryKey='true' required='true'
autoIncrement='true'/>\n"+
                 "    <column name='avalue' type='VARCHAR' size='20' required='true'/>\n"+
                 "  </table>\n"+
                 "</database>";
@@ -2161,5 +2161,39 @@
         String alterationSql = getPlatform().getAlterTablesSql(catalog, schema, null, model);
 
         assertEqualsIgnoringWhitespaces("", alterationSql);
+    }
+
+    /**
+     * Test for DDLUTILS-159.
+     */
+    public void testRenamePK() throws Exception
+    {
+        final String model1Xml = 
+            "<?xml version='1.0'?>\n" +
+            "<database name='roundtriptest'>\n" +
+            "  <table name='roundtrip'>\n" +
+            "    <column name='id' primaryKey='true' required='true' type='INTEGER'/>\n"
+
+            "    <column name='avalue' primaryKey='false' required='false' type='VARCHAR'
size='40'/>\n" +
+            "  </table>\n" +
+            "</database>";
+        final String model2Xml = 
+            "<?xml version='1.0'?>\n" +
+            "<database name='roundtriptest'>\n" +
+            "  <table name='roundtrip'>\n" +
+            "    <column name='pk' primaryKey='true' required='true' type='INTEGER'/>\n"
+
+            "    <column name='avalue' primaryKey='false' required='false' type='VARCHAR'
size='40'/>\n" +
+            "  </table>\n" +
+            "</database>";
+
+        createDatabase(model1Xml);
+
+        // note that we cannot do this test with values in the table because
+        // the primary key will be re-created and thus won't have values in it
+        // (no renaming)
+
+        alterDatabase(model2Xml);
+
+        assertEquals(getAdjustedModel(),
+                     readModelFromDatabase("roundtriptest"));
     }
 }



Mime
View raw message