You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by to...@apache.org on 2006/05/17 09:54:06 UTC

svn commit: r407194 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/alteration/ java/org/apache/ddlutils/platform/ java/org/apache/ddlutils/platform/oracle/ java/org/apache/ddlutils/util/ test/org/apache/ddlutils/platform/

Author: tomdz
Date: Wed May 17 00:54:06 2006
New Revision: 407194

URL: http://svn.apache.org/viewcvs?rev=407194&view=rev
Log:
Fixed Oracle auto-increment support

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/util/SqlTokenizer.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle8Platform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle9Platform.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java?rev=407194&r1=407193&r2=407194&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ModelComparator.java Wed May 17 00:54:06 2006
@@ -36,6 +36,8 @@
  * are changed in the process, however, it is also assumed that the models do not
  * change in between.
  * 
+ * TODO: Add support and tests for the change of the column order 
+ * 
  * @version $Revision: $
  */
 public class ModelComparator

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java?rev=407194&r1=407193&r2=407194&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java Wed May 17 00:54:06 2006
@@ -821,7 +821,7 @@
             dropTable(sourceTable);
             createTable(desiredModel, realTargetTable, parameters);
             writeCopyDataStatement(tempTable, targetTable);
-            dropTable(tempTable);
+            dropTemporaryTable(desiredModel, tempTable);
         }
     }
 
@@ -908,6 +908,18 @@
     }
 
     /**
+     * Outputs the DDL to drop the given temporary table. Per default this is simply
+     * a call to {@link #dropTable(Table)}.
+     * 
+     * @param database The database model
+     * @param table    The table
+     */
+    protected void dropTemporaryTable(Database database, Table table) throws IOException 
+    {
+        dropTable(table);
+    }
+
+    /**
      * Creates the target table object that differs from the given target table only in the
      * indices. More specifically, only those indices are used that have not changed.
      * 
@@ -2717,6 +2729,8 @@
      */
     protected void printEndOfStatement() throws IOException
     {
+        // TODO: It might make sense to use a special writer which stores the individual
+        //       statements separately (the end of a statement is identified by this method)
         println(getPlatformInfo().getSqlCommandDelimiter());
         println();
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java?rev=407194&r1=407193&r2=407194&view=diff
==============================================================================
--- 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 Wed May 17 00:54:06 2006
@@ -165,6 +165,10 @@
             print(" FROM dual");
             print(getPlatformInfo().getSqlCommandDelimiter());
             print(" END");
+            // It is important that there is a semicolon at the end of the statement (or more
+            // precisely, at the end of the PL/SQL block), and thus we put two semicolons here
+            // because the tokenizer will remove the one at the end
+            print(getPlatformInfo().getSqlCommandDelimiter());
             printEndOfStatement();
         }
     }
@@ -247,6 +251,14 @@
         super.createTable(database, table, parameters);
     }
 
+    /**
+     * {@inheritDoc}
+     */
+    protected void dropTemporaryTable(Database database, Table table) throws IOException
+    {
+        // likewise, we don't need to drop a sequence or trigger
+        super.dropTable(table);
+    }
 
     /**
      * {@inheritDoc}

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/util/SqlTokenizer.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/util/SqlTokenizer.java?rev=407194&r1=407193&r2=407194&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/util/SqlTokenizer.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/util/SqlTokenizer.java Wed May 17 00:54:06 2006
@@ -4,6 +4,8 @@
 /**
  * A statement tokenizer for SQL strings that splits only at delimiters that
  * are at the end of a line or the end of the SQL (row mode).  
+ * 
+ * TODO: Add awareness of strings, so that semicolons within strings are not parsed
  */
 public class SqlTokenizer
 {

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle8Platform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle8Platform.java?rev=407194&r1=407193&r2=407194&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle8Platform.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle8Platform.java Wed May 17 00:54:06 2006
@@ -113,9 +113,9 @@
             "    PRIMARY KEY (\"COL_PK\", \"COL_PK_AUTO_INCR\")\n"+
             ");\n"+
             "CREATE OR REPLACE TRIGGER \"trg_constraints_L_PK_AUTO_INCR\" BEFORE INSERT ON \"constraints\" FOR EACH ROW WHEN (new.\"COL_PK_AUTO_INCR\" IS NULL)\n"+
-            "BEGIN SELECT \"seq_constraints_L_PK_AUTO_INCR\".nextval INTO :new.\"COL_PK_AUTO_INCR\" FROM dual; END;\n"+
+            "BEGIN SELECT \"seq_constraints_L_PK_AUTO_INCR\".nextval INTO :new.\"COL_PK_AUTO_INCR\" FROM dual; END;;\n"+
             "CREATE OR REPLACE TRIGGER \"trg_constraints_COL_AUTO_INCR\" BEFORE INSERT ON \"constraints\" FOR EACH ROW WHEN (new.\"COL_AUTO_INCR\" IS NULL)\n"+
-            "BEGIN SELECT \"seq_constraints_COL_AUTO_INCR\".nextval INTO :new.\"COL_AUTO_INCR\" FROM dual; END;\n",
+            "BEGIN SELECT \"seq_constraints_COL_AUTO_INCR\".nextval INTO :new.\"COL_AUTO_INCR\" FROM dual; END;;\n",
             createTestDatabase(COLUMN_CONSTRAINT_TEST_SCHEMA));
     }
 

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle9Platform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle9Platform.java?rev=407194&r1=407193&r2=407194&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle9Platform.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle9Platform.java Wed May 17 00:54:06 2006
@@ -103,9 +103,9 @@
             "    PRIMARY KEY (\"COL_PK\", \"COL_PK_AUTO_INCR\")\n"+
             ");\n"+
             "CREATE OR REPLACE TRIGGER \"trg_constraints_L_PK_AUTO_INCR\" BEFORE INSERT ON \"constraints\" FOR EACH ROW WHEN (new.\"COL_PK_AUTO_INCR\" IS NULL)\n"+
-            "BEGIN SELECT \"seq_constraints_L_PK_AUTO_INCR\".nextval INTO :new.\"COL_PK_AUTO_INCR\" FROM dual; END;\n"+
+            "BEGIN SELECT \"seq_constraints_L_PK_AUTO_INCR\".nextval INTO :new.\"COL_PK_AUTO_INCR\" FROM dual; END;;\n"+
             "CREATE OR REPLACE TRIGGER \"trg_constraints_COL_AUTO_INCR\" BEFORE INSERT ON \"constraints\" FOR EACH ROW WHEN (new.\"COL_AUTO_INCR\" IS NULL)\n"+
-            "BEGIN SELECT \"seq_constraints_COL_AUTO_INCR\".nextval INTO :new.\"COL_AUTO_INCR\" FROM dual; END;\n",
+            "BEGIN SELECT \"seq_constraints_COL_AUTO_INCR\".nextval INTO :new.\"COL_AUTO_INCR\" FROM dual; END;;\n",
             createTestDatabase(COLUMN_CONSTRAINT_TEST_SCHEMA));
     }