db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r893941 - in /db/ddlutils/trunk/src: main/java/org/apache/ddlutils/platform/ main/java/org/apache/ddlutils/platform/maxdb/ main/java/org/apache/ddlutils/platform/sapdb/ test/java/org/apache/ddlutils/platform/
Date Sat, 26 Dec 2009 06:28:55 GMT
Author: tomdz
Date: Sat Dec 26 06:28:54 2009
New Revision: 893941

URL: http://svn.apache.org/viewvc?rev=893941&view=rev
Log:
SapDB/MaxDB fixes

Modified:
    db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java
    db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/maxdb/MaxDbBuilder.java
    db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java
    db/ddlutils/trunk/src/test/java/org/apache/ddlutils/platform/TestSapDbPlatform.java

Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java?rev=893941&r1=893940&r2=893941&view=diff
==============================================================================
--- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java Sat Dec 26
06:28:54 2009
@@ -448,8 +448,8 @@
     /**
      * Writes a statement that copies the data from the source to the target table. Note
      * that this copies only those columns that are in both tables.
-     * Database-specific implementations might redefine this method though they usually
-     * it suffices to redefine the {@link #writeCastExpression(Column, Column)} method.
+     * Database-specific implementations might redefine this method though it usually
+     * suffices to redefine the {@link #writeCastExpression(Column, Column)} method.
      * 
      * @param sourceTable The source table
      * @param targetTable The target table
@@ -1956,7 +1956,7 @@
      * @param table      The table
      * @param foreignKey The foreignkey
      */
-    private void writeForeignKeyOnDeleteAction(Table table, ForeignKey foreignKey) throws
IOException
+    protected void writeForeignKeyOnDeleteAction(Table table, ForeignKey foreignKey) throws
IOException
     {
         CascadeActionEnum action = foreignKey.getOnDelete();
 
@@ -2006,7 +2006,7 @@
      * @param table      The table
      * @param foreignKey The foreignkey
      */
-    private void writeForeignKeyOnUpdateAction(Table table, ForeignKey foreignKey) throws
IOException
+    protected void writeForeignKeyOnUpdateAction(Table table, ForeignKey foreignKey) throws
IOException
     {
         CascadeActionEnum action = foreignKey.getOnUpdate();
 

Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/maxdb/MaxDbBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/maxdb/MaxDbBuilder.java?rev=893941&r1=893940&r2=893941&view=diff
==============================================================================
--- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/maxdb/MaxDbBuilder.java (original)
+++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/maxdb/MaxDbBuilder.java Sat
Dec 26 06:28:54 2009
@@ -23,7 +23,6 @@
 
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Column;
-import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.ForeignKey;
 import org.apache.ddlutils.model.Table;
 import org.apache.ddlutils.platform.sapdb.SapDbBuilder;
@@ -66,32 +65,6 @@
     /**
      * {@inheritDoc}
      */
-    public void createForeignKey(Database database, Table table, ForeignKey foreignKey) throws
IOException
-    {
-        if (foreignKey.getForeignTableName() == null)
-        {
-            _log.warn("Foreign key table is null for key " + foreignKey);
-        }
-        else
-        {
-            writeTableAlterStmt(table);
-
-            print("ADD CONSTRAINT ");
-            printIdentifier(getForeignKeyName(table, foreignKey));
-            print(" FOREIGN KEY (");
-            writeLocalReferences(foreignKey);
-            print(") REFERENCES ");
-            printIdentifier(getTableName(database.findTable(foreignKey.getForeignTableName())));
-            print(" (");
-            writeForeignReferences(foreignKey);
-            print(")");
-            printEndOfStatement();
-        }
-    }
-
-    /**
-     * {@inheritDoc}
-     */
     public void dropForeignKey(Table table, ForeignKey foreignKey) throws IOException
     {
         writeTableAlterStmt(table);

Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java?rev=893941&r1=893940&r2=893941&view=diff
==============================================================================
--- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java (original)
+++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/sapdb/SapDbBuilder.java Sat
Dec 26 06:28:54 2009
@@ -22,11 +22,15 @@
 import java.io.IOException;
 
 import org.apache.ddlutils.Platform;
+import org.apache.ddlutils.alteration.ColumnDefinitionChange;
+import org.apache.ddlutils.model.CascadeActionEnum;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.ForeignKey;
 import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.model.TypeMap;
 import org.apache.ddlutils.platform.SqlBuilder;
+import org.apache.ddlutils.util.StringUtilsExt;
 
 /**
  * The SQL Builder for SapDB.
@@ -85,26 +89,10 @@
     /**
      * {@inheritDoc}
      */
-    public void createForeignKey(Database database, Table table, ForeignKey foreignKey) throws
IOException
+    protected void writeForeignKeyOnDeleteAction(Table table, ForeignKey foreignKey) throws
IOException
     {
-        if (foreignKey.getForeignTableName() == null)
-        {
-            _log.warn("Foreign key table is null for key " + foreignKey);
-        }
-        else
-        {
-            writeTableAlterStmt(table);
-
-            print(" ADD FOREIGN KEY ");
-            printIdentifier(getForeignKeyName(table, foreignKey));
-            print(" (");
-            writeLocalReferences(foreignKey);
-            print(") REFERENCES ");
-            printIdentifier(getTableName(database.findTable(foreignKey.getForeignTableName())));
-            print(" (");
-            writeForeignReferences(foreignKey);
-            print(")");
-            printEndOfStatement();
+        if (foreignKey.getOnDelete() != CascadeActionEnum.NONE) {
+            super.writeForeignKeyOnDeleteAction(table, foreignKey);
         }
     }
 
@@ -236,4 +224,27 @@
         }
         printEndOfStatement();
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected void writeCastExpression(Column sourceColumn, Column targetColumn) throws IOException
+    {
+        boolean charSizeChanged = TypeMap.isTextType(targetColumn.getTypeCode()) &&
+                                  TypeMap.isTextType(targetColumn.getTypeCode()) &&
+                                  ColumnDefinitionChange.isSizeChanged(getPlatformInfo(),
sourceColumn, targetColumn) &&
+                                  !StringUtilsExt.isEmpty(targetColumn.getSize());
+
+        if (charSizeChanged)
+        {
+            print("SUBSTR(");
+        }
+        printIdentifier(getColumnName(sourceColumn));
+        if (charSizeChanged)
+        {
+            print(",1,");
+            print(targetColumn.getSize());
+            print(")");
+        }
+    }
 }

Modified: db/ddlutils/trunk/src/test/java/org/apache/ddlutils/platform/TestSapDbPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/java/org/apache/ddlutils/platform/TestSapDbPlatform.java?rev=893941&r1=893940&r2=893941&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/java/org/apache/ddlutils/platform/TestSapDbPlatform.java (original)
+++ db/ddlutils/trunk/src/test/java/org/apache/ddlutils/platform/TestSapDbPlatform.java Sat
Dec 26 06:28:54 2009
@@ -136,8 +136,8 @@
             "    \"COL_FK\" INTEGER NOT NULL,\n"+
             "    PRIMARY KEY (\"COL_PK\")\n"+
             ");\n"+
-            "ALTER TABLE \"table2\" ADD FOREIGN KEY \"table2_FK_COL_FK_COL_FK_2_table1\"
(\"COL_FK_1\", \"COL_FK_2\") REFERENCES \"table1\" (\"COL_PK_2\", \"COL_PK_1\");\n"+
-            "ALTER TABLE \"table3\" ADD FOREIGN KEY \"testfk\" (\"COL_FK\") REFERENCES \"table2\"
(\"COL_PK\");\n",
+            "ALTER TABLE \"table2\" ADD CONSTRAINT \"table2_FK_COL_FK_COL_FK_2_table1\" FOREIGN
KEY(\"COL_FK_1\", \"COL_FK_2\") REFERENCES \"table1\" (\"COL_PK_2\", \"COL_PK_1\");\n"+
+            "ALTER TABLE \"table3\" ADD CONSTRAINT \"testfk\" FOREIGN KEY(\"COL_FK\") REFERENCES
\"table2\" (\"COL_PK\");\n",
             getTableConstraintTestDatabaseCreationSql());
     }
 



Mime
View raw message