db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r415115 - in /db/ddlutils/trunk/src/java/org/apache/ddlutils/platform: cloudscape/ db2/ derby/ firebird/ hsqldb/ interbase/ mysql/ postgresql/ sybase/
Date Sun, 18 Jun 2006 09:10:57 GMT
Author: tomdz
Date: Sun Jun 18 02:10:56 2006
New Revision: 415115

URL: http://svn.apache.org/viewvc?rev=415115&view=rev
Log:
Added support for reading back auto-increment values
Added support for unescaping special characters in the back-read default value

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapeBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapeBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapeBuilder.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapeBuilder.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapeBuilder.java
Sun Jun 18 02:10:56 2006
@@ -49,4 +49,12 @@
     {
         print("GENERATED ALWAYS AS IDENTITY");
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getSelectLastIdentityValues(Table table)
+    {
+        return "VALUES IDENTITY_VAL_LOCAL()";
+    }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Builder.java Sun Jun 18
02:10:56 2006
@@ -84,6 +84,14 @@
     /**
      * {@inheritDoc}
      */
+    public String getSelectLastIdentityValues(Table table)
+    {
+        return "VALUES IDENTITY_VAL_LOCAL()";
+    }
+
+    /**
+     * {@inheritDoc}
+     */
     public void writeExternalIndexDropStmt(Table table, Index index) throws IOException
     {
         // Index names in DB2 are unique to a schema and hence Derby does not

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyModelReader.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyModelReader.java Sun
Jun 18 02:10:56 2006
@@ -19,7 +19,6 @@
 import java.sql.SQLException;
 import java.util.Map;
 
-import org.apache.commons.lang.StringUtils;
 import org.apache.ddlutils.Platform;
 import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.ForeignKey;
@@ -67,17 +66,7 @@
             }
             else if (TypeMap.isTextType(column.getTypeCode()))
             {
-                // Derby escapes the single quote even when returning the default value
-                // so we have to unescape it
-                if ((defaultValue.length() >= 2) && defaultValue.startsWith("'")
&& defaultValue.endsWith("'"))
-                {
-                    defaultValue = "'" + StringUtils.replace(defaultValue.substring(1, defaultValue.length()
- 1), "''", "'") + "'";
-                }
-                else
-                {
-                    defaultValue = StringUtils.replace(defaultValue, "''", "'");
-                }
-                column.setDefaultValue(defaultValue);
+                column.setDefaultValue(unescape(defaultValue, "'", "''"));
             }
         }
         return column;

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdBuilder.java
Sun Jun 18 02:10:56 2006
@@ -152,9 +152,8 @@
 
     /**
      * {@inheritDoc}
-     * @todo : we are kind of stuck here, since last insert id needs the database name..
      */
-    public String getSelectLastInsertId(Table table)
+    public String getSelectLastIdentityValues(Table table)
     {
         Column[] columns = table.getAutoIncrementColumns();
 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbBuilder.java Sun
Jun 18 02:10:56 2006
@@ -65,7 +65,7 @@
     /**
      * {@inheritDoc}
      */
-    public String getSelectLastInsertId(Table table) 
+    public String getSelectLastIdentityValues(Table table) 
     {
         return "CALL IDENTITY()";
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbModelReader.java
Sun Jun 18 02:10:56 2006
@@ -20,9 +20,11 @@
 import java.util.Map;
 
 import org.apache.ddlutils.Platform;
+import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.ForeignKey;
 import org.apache.ddlutils.model.Index;
 import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.model.TypeMap;
 import org.apache.ddlutils.platform.DatabaseMetaDataWrapper;
 import org.apache.ddlutils.platform.JdbcModelReader;
 
@@ -64,6 +66,21 @@
         }
         
         return table;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    protected Column readColumn(DatabaseMetaDataWrapper metaData, Map values) throws SQLException
+    {
+        Column column = super.readColumn(metaData, values);
+
+        if (TypeMap.isTextType(column.getTypeCode()) &&
+            (column.getDefaultValue() != null))
+        {
+            column.setDefaultValue(unescape(column.getDefaultValue(), "'", "''"));
+        }
+        return column;
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbaseBuilder.java
Sun Jun 18 02:10:56 2006
@@ -158,4 +158,31 @@
     {
         // we're using a generator
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getSelectLastIdentityValues(Table table)
+    {
+        Column[] columns = table.getAutoIncrementColumns();
+
+        if (columns.length == 0)
+        {
+            return null;
+        }
+        else
+        {
+            StringBuffer result = new StringBuffer();
+    
+            result.append("SELECT ");
+            for (int idx = 0; idx < columns.length; idx++)
+            {
+                result.append("GEN_ID(");
+                result.append(getConstraintName("gen", table, columns[idx].getName(), null));
+                result.append(", 0)");
+            }
+            result.append(" FROM RDB$DATABASE");
+            return result.toString();
+        }
+    }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlBuilder.java Sun Jun
18 02:10:56 2006
@@ -104,7 +104,7 @@
      * Since ddlutils expects the real column name of the field that is autoincrementing,
the
      * column has an alias of that column name.
      */
-    public String getSelectLastInsertId(Table table)
+    public String getSelectLastIdentityValues(Table table)
     {
         String autoIncrementKeyName = "";
         if (table.getAutoIncrementColumns().length > 0)

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
Sun Jun 18 02:10:56 2006
@@ -73,9 +73,7 @@
 
         for (int idx = 0; idx < columns.length; idx++)
         {
-            print("DROP SEQUENCE ");
-            printIdentifier(getConstraintName(null, table, columns[idx].getName(), "seq"));
-            printEndOfStatement();
+            dropAutoIncrementSequence(table, columns[idx]);
         }
     }
 
@@ -120,6 +118,19 @@
     }
 
     /**
+     * Creates the auto-increment sequence that is then used in the column.
+     *  
+     * @param table  The table
+     * @param column The column
+     */
+    private void dropAutoIncrementSequence(Table table, Column column) throws IOException
+    {
+        print("DROP SEQUENCE ");
+        printIdentifier(getConstraintName(null, table, column.getName(), "seq"));
+        printEndOfStatement();
+    }
+
+    /**
      * {@inheritDoc}
      */
     protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
@@ -132,7 +143,7 @@
     /**
      * {@inheritDoc}
      */
-    public String getSelectLastInsertId(Table table)
+    public String getSelectLastIdentityValues(Table table)
     {
         Column[] columns = table.getAutoIncrementColumns();
 
@@ -241,5 +252,9 @@
         print("DROP COLUMN ");
         printIdentifier(getColumnName(change.getColumn()));
         printEndOfStatement();
+        if (change.getColumn().isAutoIncrement())
+        {
+            dropAutoIncrementSequence(change.getChangedTable(), change.getColumn());
+        }
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java
Sun Jun 18 02:10:56 2006
@@ -26,6 +26,7 @@
 import org.apache.ddlutils.model.ForeignKey;
 import org.apache.ddlutils.model.Index;
 import org.apache.ddlutils.model.Table;
+import org.apache.ddlutils.model.TypeMap;
 import org.apache.ddlutils.platform.DatabaseMetaDataWrapper;
 import org.apache.ddlutils.platform.JdbcModelReader;
 
@@ -147,6 +148,10 @@
                     case Types.TIMESTAMP:
                         defaultValue = extractDelimitedDefaultValue(defaultValue);
                         break;
+                }
+                if (TypeMap.isTextType(column.getTypeCode()))
+                {
+                    defaultValue = unescape(defaultValue, "'", "\\'");
                 }
             }
             column.setDefaultValue(defaultValue);

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java?rev=415115&r1=415114&r2=415115&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java Sun
Jun 18 02:10:56 2006
@@ -188,7 +188,7 @@
 		}
 		else
 		{
-			return super.extractColumnValue(resultSet, columnName, jdbcType);
+			return super.extractColumnValue(resultSet, columnName, 0, jdbcType);
 		}
 	}
 



Mime
View raw message