db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r399869 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/platform/ java/org/apache/ddlutils/platform/derby/ test/org/apache/ddlutils/io/
Date Thu, 04 May 2006 22:02:00 GMT
Author: tomdz
Date: Thu May  4 15:01:59 2006
New Revision: 399869

URL: http://svn.apache.org/viewcvs?rev=399869&view=rev
Log:
Fixes for the Derby platform
Fixes to the alteration tests

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java

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=399869&r1=399868&r2=399869&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 Thu May  4 15:01:59
2006
@@ -904,7 +904,7 @@
         }
 
         print("INSERT INTO ");
-        printlnIdentifier(getTableName(targetTable));
+        printIdentifier(getTableName(targetTable));
         print(" (");
         for (Iterator columnIt = columns.keySet().iterator(); columnIt.hasNext();)
         {
@@ -927,7 +927,7 @@
             }
         }
         print(" FROM ");
-        printlnIdentifier(getTableName(sourceTable));
+        printIdentifier(getTableName(sourceTable));
         printEndOfStatement();
     }
 
@@ -1998,6 +1998,20 @@
         String nativeType = (String)getPlatformInfo().getNativeType(column.getTypeCode());
 
         return nativeType == null ? column.getType() : nativeType;
+    }
+
+    /**
+     * Returns the bare database-native type for the given column without any size specifies.
+     * 
+     * @param column The column
+     * @return The native type
+     */
+    protected String getBareNativeType(Column column)
+    {
+        String nativeType = getNativeType(column);
+        int    sizePos    = nativeType.indexOf(SIZE_PLACEHOLDER);
+
+        return sizePos >= 0 ? nativeType.substring(0, sizePos) : nativeType;
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java?rev=399869&r1=399868&r2=399869&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyBuilder.java Thu May
 4 15:01:59 2006
@@ -21,7 +21,9 @@
 
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Index;
 import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.model.TypeMap;
 import org.apache.ddlutils.platform.cloudscape.CloudscapeBuilder;
 import org.apache.ddlutils.util.Jdbc3Utils;
 
@@ -65,5 +67,46 @@
     protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
     {
         print("GENERATED BY DEFAULT AS IDENTITY");
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public void writeExternalIndexDropStmt(Table table, Index index) throws IOException
+    {
+        // Index names in Derby are unique to a schema and hence Derby does not
+        // use the ON <tablename> clause
+        print("DROP INDEX ");
+        printIdentifier(getIndexName(index));
+        printEndOfStatement();
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void writeCastExpression(Column sourceColumn, Column targetColumn) throws IOException
+    {
+        String sourceNativeType = getBareNativeType(sourceColumn);
+        String targetNativeType = getBareNativeType(targetColumn);
+
+        if (sourceNativeType.equals(targetNativeType))
+        {
+            printIdentifier(getColumnName(sourceColumn));
+        }
+        else
+        {
+            // Derby currently has the limitation that it cannot convert numeric values
+            // to VARCHAR, though it can convert them to CHAR
+            if (TypeMap.isNumericType(sourceColumn.getTypeCode()) &&
+                "VARCHAR".equalsIgnoreCase(targetNativeType))
+            {
+                targetNativeType = "CHAR";
+            }
+
+            print(targetNativeType);
+            print("(");
+            printIdentifier(getColumnName(sourceColumn));
+            print(")");
+        }
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java?rev=399869&r1=399868&r2=399869&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java Thu May
 4 15:01:59 2006
@@ -19,6 +19,7 @@
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.SQLException;
+import java.sql.Types;
 import java.util.Iterator;
 import java.util.Map;
 
@@ -48,6 +49,8 @@
     public DerbyPlatform()
     {
         super();
+        getPlatformInfo().addNativeTypeMapping(Types.DOUBLE, "DOUBLE");
+        getPlatformInfo().addNativeTypeMapping(Types.FLOAT,  "DOUBLE", Types.DOUBLE);
         setSqlBuilder(new DerbyBuilder(this));
         setModelReader(new DerbyModelReader(this));
     }

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java?rev=399869&r1=399868&r2=399869&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java Thu May  4 15:01:59
2006
@@ -260,7 +260,11 @@
 
         insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) });
 
+        // since some databases require/automatically make the column required
+        // we use it like this in this test in order to avoid problems when
+        // comparing the model from the live database with our assumed one
     	model.getTable(0).getColumn(1).setAutoIncrement(true);
+        model.getTable(0).getColumn(1).setRequired(true);
 
     	alterDatabase(model);
 
@@ -969,7 +973,7 @@
 
     	newPkColumn.setName("pk");
     	newPkColumn.setTypeCode(Types.VARCHAR);
-    	newPkColumn.setSize("20");
+    	newPkColumn.setSize("32");
     	newPkColumn.setPrimaryKey(true);
     	newPkColumn.setRequired(true);
     	newTable.setName("roundtrip2");



Mime
View raw message