db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r406473 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/ java/org/apache/ddlutils/platform/oracle/ test/org/apache/ddlutils/ test/org/apache/ddlutils/dynabean/
Date Mon, 15 May 2006 00:25:31 GMT
Author: tomdz
Date: Sun May 14 17:25:30 2006
New Revision: 406473

URL: http://svn.apache.org/viewcvs?rev=406473&view=rev
Log:
Fixed alteration test so that they now use the catalog and schema if specified
Enhanced alteration support for Oracle
Introduced new sql statement tokenizer that splits in row-mode

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.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/test/org/apache/ddlutils/TestDatabaseWriterBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java?rev=406473&r1=406472&r2=406473&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java Sun May
14 17:25:30 2006
@@ -36,7 +36,6 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
-import java.util.StringTokenizer;
 
 import org.apache.commons.beanutils.DynaBean;
 import org.apache.commons.beanutils.PropertyUtils;
@@ -56,6 +55,7 @@
 import org.apache.ddlutils.model.TypeMap;
 import org.apache.ddlutils.util.Jdbc3Utils;
 import org.apache.ddlutils.util.JdbcSupport;
+import org.apache.ddlutils.util.SqlTokenizer;
 
 /**
  * Base class for platform implementations.
@@ -224,15 +224,17 @@
         int       errors       = 0;
         int       commandCount = 0;
 
+        // we tokenize the SQL along the delimiters, and we also make sure that only delimiters
+        // at the end of a line or the end of the string are used (row mode)
         try
         {
             statement = connection.createStatement();
-            
-            StringTokenizer tokenizer = new StringTokenizer(sql, ";");
 
-            while (tokenizer.hasMoreTokens())
+            SqlTokenizer tokenizer = new SqlTokenizer(sql);
+
+            while (tokenizer.hasMoreStatements())
             {
-                String command = tokenizer.nextToken();
+                String command = tokenizer.getNextStatement();
                 
                 // ignore whitespace
                 command = command.trim();
@@ -665,7 +667,8 @@
             StringWriter buffer = new StringWriter();
 
             getSqlBuilder().setWriter(buffer);
-            getSqlBuilder().alterDatabase(currentModel, desiredModel, doDrops, modifyColumns);
+            //getSqlBuilder().alterDatabase(currentModel, desiredModel, doDrops, modifyColumns);
+            getSqlBuilder().alterDatabase2(currentModel, desiredModel, null);
             sql = buffer.toString();
         }
         catch (IOException ex)
@@ -698,7 +701,8 @@
             StringWriter buffer = new StringWriter();
 
             getSqlBuilder().setWriter(buffer);
-            getSqlBuilder().alterDatabase(currentModel, desiredModel, params, doDrops, modifyColumns);
+            //getSqlBuilder().alterDatabase(currentModel, desiredModel, params, doDrops,
modifyColumns);
+            getSqlBuilder().alterDatabase2(currentModel, desiredModel, params);
             sql = buffer.toString();
         }
         catch (IOException ex)

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=406473&r1=406472&r2=406473&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 Sun May 14 17:25:30
2006
@@ -766,7 +766,7 @@
                 {
                     ForeignKey targetFk = targetTable.getForeignKey(fkIdx);
                     ForeignKey sourceFk = sourceTable.findForeignKey(targetFk, caseSensitive);
-                    String     refName  = targetFk.getForeignTable().getName();
+                    String     refName  = targetFk.getForeignTableName();
 
                     if (!caseSensitive)
                     {
@@ -2180,7 +2180,7 @@
         {
             boolean shouldUseQuotes = !TypeMap.isNumericType(typeCode);
     
-            if (shouldUseQuotes && (defaultValue != null))
+            if (shouldUseQuotes)
             {
                 // characters are only escaped when within a string literal 
                 print(getPlatformInfo().getValueQuoteToken());

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=406473&r1=406472&r2=406473&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 Sun
May 14 17:25:30 2006
@@ -24,6 +24,7 @@
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.model.Index;
 import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.model.TypeMap;
 import org.apache.ddlutils.platform.SqlBuilder;
@@ -108,6 +109,18 @@
     /**
      * {@inheritDoc}
      */
+    public void writeExternalIndexDropStmt(Table table, Index index) throws IOException
+    {
+        // Index names in Oracle are unique to a schema and hence Oracle does not
+        // use the ON <tablename> clause
+        print("DROP INDEX ");
+        printIdentifier(getIndexName(index));
+        printEndOfStatement();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void createTable(Database database, Table table, Map parameters) throws IOException
     {
         // lets create any sequences
@@ -124,17 +137,24 @@
 
         for (int idx = 0; idx < columns.length; idx++)
         {
+            String columnName  = getColumnName(columns[idx]);
+            String triggerName = getConstraintName("trg", table, columns[idx].getName(),
null);
+
+            // note that the BEGIN ... SELECT ... END; is all in one line and does
+            // not contain a semicolon except for the END-one
+            // this way, the tokenizer will not split the statement before the END
             print("CREATE OR REPLACE TRIGGER ");
-            printIdentifier(getConstraintName("trg", table, columns[idx].getName(), null));
+            printIdentifier(triggerName);
             print(" BEFORE INSERT ON ");
             printIdentifier(getTableName(table));
-            println(" FOR EACH ROW");
-            println("BEGIN");
-            print("SELECT ");
+            print(" REFERENCING NEW AS NEW OLD AS OLD FOR EACH ROW WHEN (new.");
+            printIdentifier(columnName);
+            println(" IS NULL)");
+            print("BEGIN SELECT ");
             printIdentifier(getConstraintName("seq", table, columns[idx].getName(), null));
             print(".nextval INTO :new.");
-            printIdentifier(getColumnName(columns[idx]));
-            print(" FROM dual");
+            printIdentifier(columnName);
+            print(" FROM dual END");
             printEndOfStatement();
         }
     }
@@ -142,24 +162,28 @@
 	/**
      * {@inheritDoc}
      */
-    protected void writeColumnDefaultValue(Table table, Column column) throws IOException
+    protected void printDefaultValue(Object defaultValue, int typeCode) throws IOException
     {
-        String  nativeDefault   = getNativeDefaultValue(column);
-        boolean shouldUseQuotes = !TypeMap.isNumericType(column.getTypeCode()) &&
!nativeDefault.startsWith("TO_DATE(");
-
-        if (shouldUseQuotes)
+        if (defaultValue != null)
         {
-            print(getPlatformInfo().getValueQuoteToken());
-            print(escapeStringValue(nativeDefault));
-            print(getPlatformInfo().getValueQuoteToken());
-        }
-        else
-        {
-            print(nativeDefault);
+            String  defaultValueStr = defaultValue.toString();
+            boolean shouldUseQuotes = !TypeMap.isNumericType(typeCode) && !defaultValueStr.startsWith("TO_DATE(");
+    
+            if (shouldUseQuotes)
+            {
+                // characters are only escaped when within a string literal 
+                print(getPlatformInfo().getValueQuoteToken());
+                print(escapeStringValue(defaultValueStr));
+                print(getPlatformInfo().getValueQuoteToken());
+            }
+            else
+            {
+                print(defaultValueStr);
+            }
         }
-	}
+    }
 
-	/**
+    /**
      * {@inheritDoc}
      */
     protected String getNativeDefaultValue(Column column)
@@ -203,4 +227,14 @@
     {
         // we're using sequences instead
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void createTemporaryTable(Database database, Table table, Map parameters) throws
IOException
+    {
+        // we don't want the auto-increment triggers/sequences for the temporary table
+        super.createTable(database, table, parameters);
+    }
+
 }

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java?rev=406473&r1=406472&r2=406473&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java Sun May 14
17:25:30 2006
@@ -266,13 +266,17 @@
      */
     protected void alterDatabase(Database model) throws DynaSqlException
     {
+        Properties props   = getTestProperties();
+        String     catalog = props.getProperty(DDLUTILS_PROPERTY_PREFIX + "catalog");
+        String     schema  = props.getProperty(DDLUTILS_PROPERTY_PREFIX + "schema");
+
         try
         {
             _model = model;
             _model.resetDynaClassCache();
 
             getPlatform().setSqlCommentsOn(false);
-            getPlatform().alterTables(_model, true, true, false);
+            getPlatform().alterTables(catalog, schema, null, _model, true, true, false);
         }
         catch (Exception ex)
         {

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java?rev=406473&r1=406472&r2=406473&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/dynabean/TestDynaSqlQueries.java Sun May
14 17:25:30 2006
@@ -20,6 +20,7 @@
 
 import org.apache.commons.beanutils.DynaBean;
 import org.apache.ddlutils.TestDatabaseWriterBase;
+import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.platform.ModelBasedResultSetIterator;
 
 /**
@@ -61,14 +62,15 @@
             "  <TestTable Id='3' Text='Text 3'/>"+
             "</data>");
 
-        ModelBasedResultSetIterator it   = (ModelBasedResultSetIterator)getPlatform().query(getModel(),
"SELECT * FROM TestTable");
-        DynaBean        bean = null;
+        ModelBasedResultSetIterator it = (ModelBasedResultSetIterator)getPlatform().query(getModel(),
+                                                                                        
 "SELECT * FROM TestTable",
+                                                                                        
 new Table[] { getModel().getTable(0) });
 
         assertTrue(it.hasNext());
         // we call the method a second time to assert that the result set does not get advanced
twice
         assertTrue(it.hasNext());
 
-        bean = (DynaBean)it.next();
+        DynaBean bean = (DynaBean)it.next();
 
         assertEquals(new Integer(1),
                      getPropertyValue(bean, "Id"));
@@ -119,7 +121,9 @@
             "  <TestTable Id='3' Text='Text 3'/>"+
             "</data>");
 
-        List beans = getPlatform().fetch(getModel(), "SELECT * FROM TestTable");
+        List beans = getPlatform().fetch(getModel(),
+                                         "SELECT * FROM TestTable",
+                                         new Table[] { getModel().getTable(0) });
 
         assertEquals(3,
                      beans.size());
@@ -174,12 +178,13 @@
             "  <TestTable2 Id='3' Avalue='Text 3'/>"+
             "</data>");
 
-        ModelBasedResultSetIterator it   = (ModelBasedResultSetIterator)getPlatform().query(getModel(),
"SELECT Id1, Avalue FROM TestTable1, TestTable2 WHERE Id2 = Id");
-        DynaBean        bean = null;
+        ModelBasedResultSetIterator it = (ModelBasedResultSetIterator)getPlatform().query(getModel(),
+                                                                                        
 "SELECT Id1, Avalue FROM TestTable1, TestTable2 WHERE Id2 = Id",
+                                                                                        
 new Table[] { getModel().getTable(0), getModel().getTable(1) });
 
         assertTrue(it.hasNext());
 
-        bean = (DynaBean)it.next();
+        DynaBean bean = (DynaBean)it.next();
 
         assertEquals(new Integer(2),
                      getPropertyValue(bean, "Id1"));



Mime
View raw message