db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r289996 [1/3] - in /db/ddlutils/trunk: ./ src/java/org/apache/ddlutils/ src/java/org/apache/ddlutils/builder/ src/java/org/apache/ddlutils/model/ src/java/org/apache/ddlutils/platform/ src/test/org/apache/ddlutils/ src/test/org/apache/ddlut...
Date Sun, 18 Sep 2005 23:01:23 GMT
Author: tomdz
Date: Sun Sep 18 16:00:38 2005
New Revision: 289996

URL: http://svn.apache.org/viewcvs?rev=289996&view=rev
Log:
The platforms now use delimited identifiers for their operations (DDLUTILS-15) though this can be turned off via the platform info (support in the ant task follows)
Adjusted the test cases accordingly
Added test cases for the column constraints (required, default etc.) and the table constraints (indices etc.)
Changed Derby auto-increment syntax (DDLUTILS-11)

Added:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/DerbyBuilder.java
Modified:
    db/ddlutils/trunk/ToDo.txt
    db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/AxionBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/CloudscapeBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/Db2Builder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/HsqlDbBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/InterbaseBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MckoiBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MySqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/OracleBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/PostgreSqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SapDbBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SqlBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/AxionPlatform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DerbyPlatform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MySqlPlatform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/PlatformImplBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestAxionPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestCloudscapePlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestDB2Platform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestDerbyPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestFirebirdPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestHsqlDbPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestInterbasePlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMaxDbPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMcKoiPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMySqlPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle8Platform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestOracle9Platform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestPostgresqlPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSapDbPlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestSybasePlatform.java

Modified: db/ddlutils/trunk/ToDo.txt
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/ToDo.txt?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/ToDo.txt (original)
+++ db/ddlutils/trunk/ToDo.txt Sun Sep 18 16:00:38 2005
@@ -24,4 +24,10 @@
   and add warnings when they are used (-> logging)
 * It might be useful to add support for the ARRAY jdbc data type in the way that PostgreSQL does, by
   simply adding brackets to the base type instead of using the ARRAY literal as this does not define the base
-  type at all
\ No newline at end of file
+  type at all
+* It would be helpful if the platform impl check the length of user-supplied identifiers (table names,
+  column names, fk names, index names) before any SQL is send to the database
+* Add check for databases that only support one auto-increment field (eg. MySQL, HsqlDb, McKoi)
+* Add ability to specify the sorting direction of an index-column (ascending/descending) - this is at least supported in Derby
+* Rather than dropping the indices/foreign keys that are at the current table, it would be better to simply drop any
+  of the constraints/triggers connected to a table (if that is possible)
\ No newline at end of file

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java Sun Sep 18 16:00:38 2005
@@ -41,8 +41,14 @@
     /** Whether identifiers are case sensitive or not */
     private boolean _caseSensitive = false;
 
+    /** Whether delimited identifiers are used or not */
+    private boolean _useDelimitedIdentifiers = true;
+
+    /** The string used for delimiting SQL identifiers, eg. table names, column names etc. */
+    private String _delimiterToken = "\"";
+
     /** The string used for escaping values when generating textual SQL statements */
-    private String _valueQuoteChar = "'";
+    private String _valueQuoteToken = "'";
 
     /** Whether comments are supported */
     private boolean _commentsSupported = true;
@@ -264,14 +270,59 @@
     }
 
     /**
+     * Determines whether delimited identifiers are used or normal SQL92 identifiers
+     * (which may only contain alphanumerical characters and the underscore, must start
+     * with a letter and cannot be a reserved keyword).
+     * Per default, delimited identifiers are used
+     *
+     * @return <code>true</code> if delimited identifiers are used
+     */
+    public boolean isUseDelimitedIdentifiers()
+    {
+        return _useDelimitedIdentifiers;
+    }
+
+    /**
+     * Determines whether delimited identifiers are used or normal SQL92 identifiers.
+     *
+     * @param useDelimitedIdentifiers <code>true</code> if delimited identifiers are used
+     */
+    public void setUseDelimitedIdentifiers(boolean useDelimitedIdentifiers)
+    {
+        _useDelimitedIdentifiers = useDelimitedIdentifiers;
+    }
+
+    /**
+     * Returns the text that is used to delimit identifiers (eg. table names).
+     * Per default, this is a double quotation character (").
+     *
+     * @return The delimiter text
+     */
+    public String getDelimiterToken()
+    {
+        return _delimiterToken;
+    }
+
+    /**
+     * Sets the text that is used to delimit identifiers (eg. table names).
+     *
+     * @param delimiterToken The delimiter text
+     */
+    public void setDelimiterToken(String delimiterToken)
+    {
+        _delimiterToken = delimiterToken;
+    }
+
+    /**
      * Returns the text that is used for for quoting values (e.g. text) when
      * printing default values and in generates insert/update/delete statements.
+     * Per default, this is a single quotation character (').
      * 
      * @return The quote text
      */
-    public String getValueQuoteChar()
+    public String getValueQuoteToken()
     {
-        return _valueQuoteChar;
+        return _valueQuoteToken;
     }
 
     /**
@@ -280,9 +331,9 @@
      *
      * @param valueQuoteChar The new quote text
      */
-    public void setValueQuoteChar(String valueQuoteChar)
+    public void setValueQuoteToken(String valueQuoteChar)
     {
-        _valueQuoteChar = valueQuoteChar;
+        _valueQuoteToken = valueQuoteChar;
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/AxionBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/AxionBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/AxionBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/AxionBuilder.java Sun Sep 18 16:00:38 2005
@@ -19,7 +19,6 @@
 import java.io.IOException;
 
 import org.apache.ddlutils.PlatformInfo;
-import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Table;
 
 /**
@@ -47,12 +46,7 @@
     public void dropTable(Table table) throws IOException
     { 
         print("DROP TABLE IF EXISTS ");
-        print(getTableName(table));
+        printIdentifier(getTableName(table));
         printEndOfStatement();
-    }
-    
-    protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
-    {
-        print("IDENTITY");
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/CloudscapeBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/CloudscapeBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/CloudscapeBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/CloudscapeBuilder.java Sun Sep 18 16:00:38 2005
@@ -68,7 +68,10 @@
                 return super.getSqlType(column);
         }
     }
-    
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#writeColumnAutoIncrementStmt(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.Column)
+     */
     protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
     {
         print("GENERATED ALWAYS AS IDENTITY");

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/Db2Builder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/Db2Builder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/Db2Builder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/Db2Builder.java Sun Sep 18 16:00:38 2005
@@ -69,18 +69,9 @@
                 return super.getSqlType(column);
         }
     }
-
-    public void dropTable(Table table) throws IOException
-    { 
-        super.dropTable(table);
-        print("DROP SEQUENCE IF EXISTS ");
-        print(getTableName(table));
-        print(".SequenceName");
-        printEndOfStatement();
-    }
     
     protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
     {
-        print("GENERATED ALWAYS AS IDENTITY");
+        print("GENERATED BY DEFAULT AS IDENTITY");
     }
 }

Added: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/DerbyBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/DerbyBuilder.java?rev=289996&view=auto
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/DerbyBuilder.java (added)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/DerbyBuilder.java Sun Sep 18 16:00:38 2005
@@ -0,0 +1,36 @@
+package org.apache.ddlutils.builder;
+
+import java.io.IOException;
+
+import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Table;
+
+/**
+ * The SQL Builder for Derby.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision: 279413 $
+ */
+public class DerbyBuilder extends CloudscapeBuilder
+{
+    /**
+     * Creates a new builder instance.
+     * 
+     * @param info The platform info
+     */
+    public DerbyBuilder(PlatformInfo info)
+    {
+        super(info);
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#writeColumnAutoIncrementStmt(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.Column)
+     */
+    protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
+    {
+        print("GENERATED BY DEFAULT AS IDENTITY");
+    }
+
+}

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/HsqlDbBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/HsqlDbBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/HsqlDbBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/HsqlDbBuilder.java Sun Sep 18 16:00:38 2005
@@ -46,7 +46,7 @@
     public void dropTable(Table table) throws IOException
     { 
         print("DROP TABLE ");
-        print(getTableName(table));
+        printIdentifier(getTableName(table));
         print(" IF EXISTS");
         printEndOfStatement();
     }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/InterbaseBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/InterbaseBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/InterbaseBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/InterbaseBuilder.java Sun Sep 18 16:00:38 2005
@@ -44,26 +44,6 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.ddlutils.builder.SqlBuilder#dropDatabase(org.apache.ddlutils.model.Database)
-     */
-    public void dropTables(Database database) throws IOException
-    {
-        super.dropTables(database);
-        print("COMMIT");
-        printEndOfStatement();
-    }
-
-    /* (non-Javadoc)
-     * @see org.apache.ddlutils.builder.SqlBuilder#createTables(org.apache.ddlutils.model.Database)
-     */
-    public void createTables(Database database) throws IOException
-    {
-        super.createTables(database);
-        print("COMMIT");
-        printEndOfStatement();
-    }
-
-    /* (non-Javadoc)
      * @see org.apache.ddlutils.builder.SqlBuilder#writeExternalForeignKeyCreateStmt(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.ForeignKey)
      */
     protected void writeExternalForeignKeyCreateStmt(Database database, Table table, ForeignKey key) throws IOException
@@ -77,36 +57,55 @@
     }
 
     /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#writeExternalForeignKeyDropStmt(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.ForeignKey)
+     */
+    protected void writeExternalForeignKeyDropStmt(Table table, ForeignKey foreignKey) throws IOException
+    {
+        super.writeExternalForeignKeyDropStmt(table, foreignKey);
+        print("COMMIT");
+        printEndOfStatement();
+    }
+
+    /* (non-Javadoc)
      * @see org.apache.ddlutils.builder.SqlBuilder#createTable(org.apache.ddlutils.model.Table)
      */
     public void createTable(Database database, Table table) throws IOException
     {
         super.createTable(database, table);
+        print("COMMIT");
+        printEndOfStatement();
 
         // creating generator and trigger for auto-increment
-        Column column = table.getAutoIncrementColumn();
+        Column[] columns = table.getAutoIncrementColumn();
 
-        if (column != null)
+        for (int idx = 0; idx < columns.length; idx++)
         {
             print("CREATE GENERATOR ");
-            print(getConstraintName("gen", table, column.getName(), null));
+            printIdentifier(getConstraintName("gen", table, columns[idx].getName(), null));
             printEndOfStatement();
-            print("CREATE TRIGGER trg_");
-            print(getConstraintName("trg", table, column.getName(), null));
+            print("COMMIT");
+            printEndOfStatement();
+            print("SET TERM !!");
+            printEndOfStatement();
+            print("CREATE TRIGGER ");
+            printIdentifier(getConstraintName("trg", table, columns[idx].getName(), null));
             print(" FOR ");
-            println(getTableName(table));
-            println("ACTIVE BEFORE INSERT POSITION 0");
-            println("AS");
+            printlnIdentifier(getTableName(table));
+            println("ACTIVE BEFORE INSERT POSITION 0 AS");
             println("BEGIN");
             print("IF (NEW.");
-            print(getColumnName(column));
+            printIdentifier(getColumnName(columns[idx]));
             println(" IS NULL) THEN");
             print("NEW.");
-            print(getColumnName(column));
+            printIdentifier(getColumnName(columns[idx]));
             print(" = GEN_ID(");
-            print(getConstraintName("gen", table, column.getName(), null));
+            printIdentifier(getConstraintName("gen", table, columns[idx].getName(), null));
             println(", 1);");
-            print("END");
+            println("END !!");
+            print("SET TERM ");
+            print(getPlatformInfo().getSqlCommandDelimiter());
+            println(" !!");
+            print("COMMIT");
             printEndOfStatement();
         }
     }
@@ -131,19 +130,20 @@
      */
     public void dropTable(Table table) throws IOException
     {
-        // dropping generator and trigger for auto-increment
-        Column column = table.getAutoIncrementColumn();
+        // dropping generators for auto-increment
+        Column[] columns = table.getAutoIncrementColumn();
 
-        if (column != null)
+        for (int idx = 0; idx < columns.length; idx++)
         {
-            print("DROP TRIGGER trg_");
-            print(getConstraintName("trg", table, column.getName(), null));
+            print("DELETE FROM RDB$GENERATOR WHERE RDB$GENERATOR_NAME = ");
+            printIdentifier(getConstraintName("gen", table, columns[idx].getName(), null));
             printEndOfStatement();
-            print("DROP GENERATOR gen_");
-            print(getConstraintName("gen", table, column.getName(), null));
+            print("COMMIT");
             printEndOfStatement();
         }
         super.dropTable(table);
+        print("COMMIT");
+        printEndOfStatement();
     }
 
     /* (non-Javadoc)

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MSSqlBuilder.java Sun Sep 18 16:00:38 2005
@@ -17,9 +17,11 @@
  */
 
 import java.io.IOException;
+import java.util.HashMap;
 
 import org.apache.ddlutils.PlatformInfo;
 import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.ForeignKey;
 import org.apache.ddlutils.model.Index;
 import org.apache.ddlutils.model.Table;
@@ -44,21 +46,21 @@
     }
 
     /* (non-Javadoc)
-     * @see org.apache.ddlutils.builder.SqlBuilder#dropExternalForeignKey(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.ForeignKey, int)
+     * @see org.apache.ddlutils.builder.SqlBuilder#createTable(org.apache.ddlutils.model.Database, org.apache.ddlutils.model.Table)
      */
-    protected void writeExternalForeignKeyDropStmt(Table table, ForeignKey foreignKey, int numKey) throws IOException
+    public void createTable(Database database, Table table) throws IOException
     {
-        String constraintName = getConstraintName(null, table, "FK", Integer.toString(numKey));
+        writeQuotationOnStatement();
+        super.createTable(database, table);
+    }
 
-        print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type ='RI' AND name='");
-        print(constraintName);
-        println("'");
-        printIndent();
-        print("ALTER TABLE ");
-        print(getTableName(table));
-        print(" DROP CONSTRAINT ");
-        print(constraintName);
-        printEndOfStatement();
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#alterTable(org.apache.ddlutils.model.Database, org.apache.ddlutils.model.Table, org.apache.ddlutils.model.Database, org.apache.ddlutils.model.Table, boolean, boolean)
+     */
+    protected void alterTable(Database currentModel, Table currentTable, Database desiredModel, Table desiredTable, boolean doDrops, boolean modifyColumns) throws IOException
+    {
+        writeQuotationOnStatement();
+        super.alterTable(currentModel, currentTable, desiredModel, desiredTable, doDrops, modifyColumns);
     }
 
     /* (non-Javadoc)
@@ -68,9 +70,10 @@
     {
         String tableName = getTableName(table);
 
-        print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = '");
-        print(tableName);
-        println("')");
+        writeQuotationOnStatement();
+        print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = ");
+        printIdentifier(tableName);
+        println(")");
         println("BEGIN");
         println("     DECLARE @reftable nvarchar(60), @constraintname nvarchar(60)");
         println("     DECLARE refcursor CURSOR FOR");
@@ -82,9 +85,8 @@
         println("       where tables.id = ref.rkeyid");
         println("         and cons.id = ref.constid");
         println("         and reftables.id = ref.fkeyid");
-        print("         and tables.name = '");
-        print(tableName);
-        println("'");
+        print("         and tables.name = ");
+        printlnIdentifier(tableName);
         println("     OPEN refcursor");
         println("     FETCH NEXT from refcursor into @reftable, @constraintname");
         println("     while @@FETCH_STATUS = 0");
@@ -95,11 +97,23 @@
         println("     CLOSE refcursor");
         println("     DEALLOCATE refcursor");
         print("     DROP TABLE ");
-        println(tableName);
+        printlnIdentifier(tableName);
         print("END");
         printEndOfStatement();
     }
-    
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#dropExternalForeignKeys(org.apache.ddlutils.model.Table)
+     */
+    public void dropExternalForeignKeys(Table table) throws IOException
+    {
+        writeQuotationOnStatement();
+        super.dropExternalForeignKeys(table);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#writeColumnAutoIncrementStmt(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.Column)
+     */
     protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
     {
         print("IDENTITY (1,1) ");
@@ -117,20 +131,85 @@
         return primaryKeyColumns.length > 0;
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#writeExternalIndexDropStmt(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.Index)
+     */
     public void writeExternalIndexDropStmt(Table table, Index index) throws IOException
     {
         print("DROP INDEX ");
-        print( getTableName(table) );
-        print( "." );
-        print( getIndexName(index) );
+        printIdentifier(getTableName(table));
+        print(".");
+        printIdentifier(getIndexName(index));
         printEndOfStatement();
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#writeColumnAlterStmt(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.Column, boolean)
+     */
     public void writeColumnAlterStmt(Table table, Column column, boolean isNewColumn) throws IOException
     {
         writeTableAlterStmt(table);
         print(isNewColumn ? "ADD " : "ALTER COLUMN ");
         writeColumn(table, column);
         printEndOfStatement();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#dropExternalForeignKey(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.ForeignKey, int)
+     */
+    protected void writeExternalForeignKeyDropStmt(Table table, ForeignKey foreignKey, int numKey) throws IOException
+    {
+        String constraintName = getConstraintName(null, table, "FK", Integer.toString(numKey));
+
+        print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type ='RI' AND name=");
+        printIdentifier(constraintName);
+        println();
+        printIndent();
+        print("ALTER TABLE ");
+        printIdentifier(getTableName(table));
+        print(" DROP CONSTRAINT ");
+        printIdentifier(constraintName);
+        printEndOfStatement();
+    }
+
+    /**
+     * Writes the statement that turns on the ability to write delimited identifiers.
+     */
+    private void writeQuotationOnStatement() throws IOException
+    {
+        print("SET quoted_identifier on");
+        printEndOfStatement();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#getDeleteSql(org.apache.ddlutils.model.Table, java.util.HashMap, boolean)
+     */
+    public String getDeleteSql(Table table, HashMap pkValues, boolean genPlaceholders)
+    {
+        return getQuotationOnStatement() + super.getDeleteSql(table, pkValues, genPlaceholders);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#getInsertSql(org.apache.ddlutils.model.Table, java.util.HashMap, boolean)
+     */
+    public String getInsertSql(Table table, HashMap columnValues, boolean genPlaceholders)
+    {
+        return getQuotationOnStatement() + super.getInsertSql(table, columnValues, genPlaceholders);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#getUpdateSql(org.apache.ddlutils.model.Table, java.util.HashMap, boolean)
+     */
+    public String getUpdateSql(Table table, HashMap columnValues, boolean genPlaceholders)
+    {
+        return getQuotationOnStatement() + super.getUpdateSql(table, columnValues, genPlaceholders);
+    }
+
+    /**
+     * Writes the statement that turns on the ability to write delimited identifiers.
+     */
+    private String getQuotationOnStatement()
+    {
+        return "SET quoted_identifier on" + getPlatformInfo().getSqlCommandDelimiter() + "\n";
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MckoiBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MckoiBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MckoiBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MckoiBuilder.java Sun Sep 18 16:00:38 2005
@@ -44,14 +44,15 @@
     public void dropTable(Table table) throws IOException
     { 
         print("DROP TABLE IF EXISTS ");
-        print(getTableName(table));
+        printIdentifier(getTableName(table));
         printEndOfStatement();
     }
 
     protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
     {
-        print("DEFAULT UNIQUEKEY('");
-        print(getTableName(table));
-        print("')");
+        // we start at value 1 to avoid issues with jdbc
+        print("DEFAULT UNIQUEKEY(");
+        printIdentifier(getTableName(table));
+        print(") + 1");
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MySqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MySqlBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MySqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/MySqlBuilder.java Sun Sep 18 16:00:38 2005
@@ -49,7 +49,7 @@
     public void dropTable(Table table) throws IOException
     { 
         print("DROP TABLE IF EXISTS ");
-        print(getTableName(table));
+        printIdentifier(getTableName(table));
         printEndOfStatement();
     }
 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/OracleBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/OracleBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/OracleBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/OracleBuilder.java Sun Sep 18 16:00:38 2005
@@ -43,27 +43,69 @@
         super(info);
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#dropTable(org.apache.ddlutils.model.Table)
+     */
     public void dropTable(Table table) throws IOException
     {
         print("DROP TABLE ");
-        print(getTableName(table));
+        printIdentifier(getTableName(table));
         print(" CASCADE CONSTRAINTS");
         printEndOfStatement();
+
+        Column[] columns = table.getAutoIncrementColumn();
+
+        for (int idx = 0; idx < columns.length; idx++)
+        {
+            print("DROP TRIGGER ");
+            printIdentifier(getConstraintName("trg", table, columns[idx].getName(), null));
+            printEndOfStatement();
+            print("DROP SEQUENCE ");
+            printIdentifier(getConstraintName("seq", table, columns[idx].getName(), null));
+            printEndOfStatement();
+        }
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#dropExternalForeignKeys(org.apache.ddlutils.model.Table)
+     */
+    public void dropExternalForeignKeys(Table table) throws IOException
+    {
+        // no need to as we drop the table with CASCASE CONSTRAINTS
     }
 
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#createTable(org.apache.ddlutils.model.Database, org.apache.ddlutils.model.Table)
+     */
     public void createTable(Database database, Table table) throws IOException
     {
         // lets create any sequences
-        Column column = table.getAutoIncrementColumn();
+        Column[] columns = table.getAutoIncrementColumn();
 
-        if (column != null)
+        for (int idx = 0; idx < columns.length; idx++)
         {
-            createSequence(table, column);
+            print("CREATE SEQUENCE ");
+            printIdentifier(getConstraintName("seq", table, columns[idx].getName(), null));
+            printEndOfStatement();
         }
+
         super.createTable(database, table);
-        if (column != null)
+
+        for (int idx = 0; idx < columns.length; idx++)
         {
-            createSequenceTrigger(table, column);
+            print("CREATE OR REPLACE TRIGGER ");
+            printIdentifier(getConstraintName("trg", table, columns[idx].getName(), null));
+            print(" BEFORE INSERT ON ");
+            printIdentifier(getTableName(table));
+            println(" FOR EACH ROW");
+            println("BEGIN");
+            print("SELECT ");
+            printIdentifier(getConstraintName("seq", table, columns[idx].getName(), null));
+            print(".nextval INTO :new.");
+            printIdentifier(getColumnName(columns[idx]));
+            println(" FROM dual;");
+            print("END");
+            printEndOfStatement();
         }
     }
 
@@ -96,43 +138,11 @@
         }
     }
 
-    protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
-    {
-    }
-
-    /**
-     * Creates a sequence so that values can be auto incremented.
-     * 
-     * @param table  The table
-     * @param column The column
-     */
-    protected void createSequence(Table table, Column column) throws IOException
-    {
-        print("CREATE SEQUENCE ");
-        print(getConstraintName(null, table, "seq", null));
-        printEndOfStatement();
-    }
-
-    /**
-     * Creates a trigger for the auto-increment sequence.
-     * 
-     * @param table  The table
-     * @param column The column
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#writeColumnAutoIncrementStmt(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.Column)
      */
-    protected void createSequenceTrigger(Table table, Column column) throws IOException
+    protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
     {
-        print("CREATE OR REPLACE TRIGGER ");
-        print(getConstraintName(null, table, "trg", null));
-        print(" BEFORE INSERT ON ");
-        println(getTableName(table));
-        println("FOR EACH ROW");
-        println("BEGIN");
-        print("SELECT ");
-        print(getConstraintName(null, table, "seq", null));
-        print(".nextval INTO :new.");
-        print(getColumnName(column));
-        println(" FROM dual;");
-        print("END");
-        printEndOfStatement();
+        // we're using sequences instead
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/PostgreSqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/PostgreSqlBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/PostgreSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/PostgreSqlBuilder.java Sun Sep 18 16:00:38 2005
@@ -48,9 +48,18 @@
     public void dropTable(Table table) throws IOException
     { 
         print("DROP TABLE ");
-        print(getTableName(table));
+        printIdentifier(getTableName(table));
         print(" CASCADE");
         printEndOfStatement();
+
+        Column[] columns = table.getAutoIncrementColumn();
+
+        for (int idx = 0; idx < columns.length; idx++)
+        {
+            print("DROP SEQUENCE ");
+            printIdentifier(getConstraintName(null, table, columns[idx].getName(), "seq"));
+            printEndOfStatement();
+        }
     }
 
     /* (non-Javadoc)
@@ -79,7 +88,7 @@
     private void createAutoIncrementSequence(Table table, Column column) throws IOException
     {
         print("CREATE SEQUENCE ");
-        print(getConstraintName(null, table, column.getName(), "seq"));
+        printIdentifier(getConstraintName(null, table, column.getName(), "seq"));
         printEndOfStatement();
     }
 
@@ -88,9 +97,9 @@
      */
     protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
     {
-        print("UNIQUE DEFAULT nextval('");
-        print(getConstraintName(null, table, column.getName(), "seq"));
-        print("')");
+        print("UNIQUE DEFAULT nextval(");
+        printIdentifier(getConstraintName(null, table, column.getName(), "seq"));
+        print(")");
     }
 
     /* (non-Javadoc)
@@ -98,15 +107,29 @@
      */
     public String getSelectLastInsertId(Table table)
     {
-        Column autoIncrColumn = table.getAutoIncrementColumn();
+        Column[] columns = table.getAutoIncrementColumn();
 
-        if (autoIncrColumn == null)
+        if (columns.length == 0)
         {
             return null;
         }
         else
         {
-            return "SELECT CURRVAL('" + getConstraintName(null, table, autoIncrColumn.getName(), "seq") + "') AS " + autoIncrColumn.getName();
+            StringBuffer result = new StringBuffer();
+    
+            result.append("SELECT ");
+            for (int idx = 0; idx < columns.length; idx++)
+            {
+                if (idx > 0)
+                {
+                    result.append(", ");
+                }
+                result.append("CURRVAL(");
+                result.append(getDelimitedIdentifier(getConstraintName(null, table, columns[idx].getName(), "seq")));
+                result.append(") AS ");
+                result.append(getDelimitedIdentifier(columns[idx].getName()));
+            }
+            return result.toString();
         }
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SapDbBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SapDbBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SapDbBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SapDbBuilder.java Sun Sep 18 16:00:38 2005
@@ -19,6 +19,7 @@
 import java.io.IOException;
 
 import org.apache.ddlutils.PlatformInfo;
+import org.apache.ddlutils.model.Column;
 import org.apache.ddlutils.model.Table;
 
 /**
@@ -46,8 +47,16 @@
     public void dropTable(Table table) throws IOException
     { 
         print("DROP TABLE ");
-        print(getTableName(table));
+        printIdentifier(getTableName(table));
         print(" CASCADE");
         printEndOfStatement();
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#writeColumnAutoIncrementStmt(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.Column)
+     */
+    protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
+    {
+        print("DEFAULT SERIAL(1)");
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SqlBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SqlBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SqlBuilder.java Sun Sep 18 16:00:38 2005
@@ -529,7 +529,7 @@
     public void createTable(Database database, Table table) throws IOException 
     {
         print("CREATE TABLE ");
-        println(getTableName(table));
+        printlnIdentifier(getTableName(table));
         println("(");
 
         writeColumns(table);
@@ -634,7 +634,7 @@
     public void dropTable(Table table) throws IOException
     {
         print("DROP TABLE ");
-        print(getTableName(table));
+        printIdentifier(getTableName(table));
         printEndOfStatement();
     }
 
@@ -670,7 +670,7 @@
         StringBuffer buffer   = new StringBuffer("INSERT INTO ");
         boolean      addComma = false;
 
-        buffer.append(getTableName(table));
+        buffer.append(getDelimitedIdentifier(getTableName(table)));
         buffer.append(" (");
 
         for (int idx = 0; idx < table.getColumnCount(); idx++)
@@ -683,7 +683,7 @@
                 {
                     buffer.append(", ");
                 }
-                buffer.append(column.getName());
+                buffer.append(getDelimitedIdentifier(column.getName()));
                 addComma = true;
             }
         }
@@ -740,7 +740,7 @@
         StringBuffer buffer = new StringBuffer("UPDATE ");
         boolean      addSep = false;
 
-        buffer.append(getTableName(table));
+        buffer.append(getDelimitedIdentifier(getTableName(table)));
         buffer.append(" SET ");
 
         for (int idx = 0; idx < table.getColumnCount(); idx++)
@@ -753,7 +753,7 @@
                 {
                     buffer.append(", ");
                 }
-                buffer.append(column.getName());
+                buffer.append(getDelimitedIdentifier(column.getName()));
                 buffer.append(" = ");
                 if (genPlaceholders)
                 {
@@ -778,7 +778,7 @@
                 {
                     buffer.append(" AND ");
                 }
-                buffer.append(column.getName());
+                buffer.append(getDelimitedIdentifier(column.getName()));
                 buffer.append(" = ");
                 if (genPlaceholders)
                 {
@@ -810,7 +810,7 @@
         StringBuffer buffer = new StringBuffer("DELETE FROM ");
         boolean      addSep = false;
 
-        buffer.append(getTableName(table));
+        buffer.append(getDelimitedIdentifier(getTableName(table)));
         if ((pkValues != null) && !pkValues.isEmpty())
         {
             buffer.append(" WHERE ");
@@ -823,7 +823,7 @@
                 {
                     buffer.append(" AND ");
                 }
-                buffer.append(entry.getKey());
+                buffer.append(getDelimitedIdentifier(entry.getKey().toString()));
                 buffer.append(" = ");
                 if (genPlaceholders)
                 {
@@ -925,7 +925,7 @@
     protected void writeTableAlterStmt(Table table) throws IOException
     {
         print("ALTER TABLE ");
-        println(getTableName(table));
+        printlnIdentifier(getTableName(table));
         printIndent();
     }
 
@@ -967,16 +967,16 @@
     protected void writeColumn(Table table, Column column) throws IOException
     {
         //see comments in columnsDiffer about null/"" defaults
-        print(getColumnName(column));
+        printIdentifier(getColumnName(column));
         print(" ");
         print(getSqlType(column));
 
         if (column.getDefaultValue() != null)
         {
             print(" DEFAULT ");
-            print(getPlatformInfo().getValueQuoteChar());
+            print(getPlatformInfo().getValueQuoteToken());
             print(column.getDefaultValue());
-            print(getPlatformInfo().getValueQuoteChar());
+            print(getPlatformInfo().getValueQuoteToken());
         }
         if (column.isRequired())
         {
@@ -1021,7 +1021,7 @@
     {
         writeTableAlterStmt(table);
         print("DROP COLUMN ");
-        print(getColumnName(column));
+        printIdentifier(getColumnName(column));
         printEndOfStatement();
     }
 
@@ -1090,7 +1090,7 @@
         {
             // Note: TIMESTAMP (java.sql.Timestamp) is properly handled by its toString method
             case Types.DATE:
-                result.append(getPlatformInfo().getValueQuoteChar());
+                result.append(getPlatformInfo().getValueQuoteToken());
                 if (!(value instanceof String) && (_valueDateFormat != null))
                 {
                     // TODO: Can the format method handle java.sql.Date properly ?
@@ -1100,10 +1100,10 @@
                 {
                     result.append(value.toString());
                 }
-                result.append(getPlatformInfo().getValueQuoteChar());
+                result.append(getPlatformInfo().getValueQuoteToken());
                 break;
             case Types.TIME:
-                result.append(getPlatformInfo().getValueQuoteChar());
+                result.append(getPlatformInfo().getValueQuoteToken());
                 if (!(value instanceof String) && (_valueTimeFormat != null))
                 {
                     // TODO: Can the format method handle java.sql.Date properly ?
@@ -1113,14 +1113,14 @@
                 {
                     result.append(value.toString());
                 }
-                result.append(getPlatformInfo().getValueQuoteChar());
+                result.append(getPlatformInfo().getValueQuoteToken());
                 break;
             case Types.REAL:
             case Types.NUMERIC:
             case Types.FLOAT:
             case Types.DOUBLE:
             case Types.DECIMAL:
-                result.append(getPlatformInfo().getValueQuoteChar());
+                result.append(getPlatformInfo().getValueQuoteToken());
                 if (!(value instanceof String) && (_valueNumberFormat != null))
                 {
                     result.append(_valueNumberFormat.format(value));
@@ -1129,12 +1129,12 @@
                 {
                     result.append(value.toString());
                 }
-                result.append(getPlatformInfo().getValueQuoteChar());
+                result.append(getPlatformInfo().getValueQuoteToken());
                 break;
             default:
-                result.append(getPlatformInfo().getValueQuoteChar());
+                result.append(getPlatformInfo().getValueQuoteToken());
                 result.append(value.toString());
-                result.append(getPlatformInfo().getValueQuoteChar());
+                result.append(getPlatformInfo().getValueQuoteToken());
                 break;
         }
         return result.toString();
@@ -1212,10 +1212,25 @@
         }
     }
 
-    protected String getForeignKeyName(ForeignKey fk) {
+    /**
+     * Determines a unique name for the given foreign key.
+     * 
+     * @param fk The foreign key
+     * @return The name
+     */
+    protected String getForeignKeyName(ForeignKey fk)
+    {
         //table and local column should be sufficient - is it possible for one
         //column to reference multiple tables
-        return fk.getFirstReference().getLocalColumnName() + "_" + fk.getForeignTableName();
+        StringBuffer name = new StringBuffer();
+
+        for (int idx = 0; idx < fk.getReferenceCount(); idx++)
+        {
+            name.append(fk.getReference(idx).getLocalColumnName());
+            name.append("_");
+        }
+        name.append(fk.getForeignTableName());
+        return name.toString();
     }
 
     /**
@@ -1276,10 +1291,10 @@
         if ((primaryKeyColumns.length > 0) && shouldGeneratePrimaryKeys(primaryKeyColumns))
         {
             print("ALTER TABLE ");
-            println(getTableName(table));
+            printlnIdentifier(getTableName(table));
             printIndent();
             print("ADD CONSTRAINT ");
-            print(getConstraintName(null, table, "PK", null));
+            printIdentifier(getConstraintName(null, table, "PK", null));
             print(" ");
             writePrimaryKeyStmt(table, primaryKeyColumns);
             printEndOfStatement();
@@ -1318,7 +1333,7 @@
         print("PRIMARY KEY (");
         for (int idx = 0; idx < primaryKeyColumns.length; idx++)
         {
-            print(getColumnName(primaryKeyColumns[idx]));
+            printIdentifier(getColumnName(primaryKeyColumns[idx]));
             if (idx < primaryKeyColumns.length - 1)
             {
                 print(", ");
@@ -1382,15 +1397,15 @@
                 print(" UNIQUE");
             }
             print(" INDEX ");
-            print(getIndexName(index));
+            printIdentifier(getIndexName(index));
             print(" ON ");
-            print(getTableName(table));
+            printIdentifier(getTableName(table));
             print(" (");
 
             for (int idx = 0; idx < index.getColumnCount(); idx++)
             {
                 IndexColumn idxColumn = index.getColumn(idx);
-                Column col = table.findColumn(idxColumn.getName());
+                Column      col       = table.findColumn(idxColumn.getName());
 
                 if (col == null)
                 {
@@ -1401,7 +1416,7 @@
                 {
                     print(", ");
                 }
-                print(getColumnName(col));
+                printIdentifier(getColumnName(col));
             }
 
             print(")");
@@ -1422,7 +1437,7 @@
             writeTableAlterStmt(table);
         }
         print("DROP INDEX ");
-        print(getIndexName(index));
+        printIdentifier(getIndexName(index));
         if (!getPlatformInfo().isUseAlterTableForDrop())
         {
             print(" ON ");
@@ -1456,13 +1471,13 @@
                 if (getPlatformInfo().isEmbeddedForeignKeysNamed())
                 {
                     print("CONSTRAINT ");
-                    print(getConstraintName(null, table, "FK", Integer.toString(idx)));
+                    printIdentifier(getConstraintName(null, table, "FK", Integer.toString(idx)));
                     print(" ");
                 }
                 print("FOREIGN KEY (");
                 writeLocalReferences(key);
                 print(") REFERENCES ");
-                print(getTableName(database.findTable(key.getForeignTableName())));
+                printIdentifier(getTableName(database.findTable(key.getForeignTableName())));
                 print(" (");
                 writeForeignReferences(key);
                 print(")");
@@ -1489,11 +1504,11 @@
             writeTableAlterStmt(table);
 
             print("ADD CONSTRAINT ");
-            print(getConstraintName(null, table, "FK", getForeignKeyName(key)));
+            printIdentifier(key.getName() == null ? getConstraintName(null, table, "FK", getForeignKeyName(key)) : key.getName());
             print(" FOREIGN KEY (");
             writeLocalReferences(key);
             print(") REFERENCES ");
-            print(getTableName(database.findTable(key.getForeignTableName())));
+            printIdentifier(getTableName(database.findTable(key.getForeignTableName())));
             print(" (");
             writeForeignReferences(key);
             print(")");
@@ -1514,7 +1529,7 @@
             {
                 print(", ");
             }
-            print(key.getReference(idx).getLocalColumnName());
+            printIdentifier(key.getReference(idx).getLocalColumnName());
         }
     }
 
@@ -1531,7 +1546,7 @@
             {
                 print(", ");
             }
-            print(key.getReference(idx).getForeignColumnName());
+            printIdentifier(key.getReference(idx).getForeignColumnName());
         }
     }
 
@@ -1547,7 +1562,7 @@
     {
         writeTableAlterStmt(table);
         print("DROP CONSTRAINT ");
-        print(getConstraintName(null, table, "FK", getForeignKeyName(foreignKey)));
+        printIdentifier(foreignKey.getName() == null ? getConstraintName(null, table, "FK", getForeignKeyName(foreignKey)) : foreignKey.getName());
         printEndOfStatement();
     }
 
@@ -1580,7 +1595,7 @@
      */
     protected void printEndOfStatement() throws IOException
     {
-        println(";");
+        println(getPlatformInfo().getSqlCommandDelimiter());
         println();
     }
 
@@ -1600,6 +1615,47 @@
     protected void print(String text) throws IOException
     {
         _writer.write(text);
+    }
+
+    /**
+     * Returns the delimited version of the identifier (if configured).
+     * 
+     * @param identifier The identifier
+     * @return The delimited version of the identifier unless the platform is configured
+     *         to use undelimited identifiers; in that case, the identifier is returned unchanged
+     */
+    protected String getDelimitedIdentifier(String identifier)
+    {
+        if (getPlatformInfo().isUseDelimitedIdentifiers())
+        {
+            return getPlatformInfo().getDelimiterToken() + identifier + getPlatformInfo().getDelimiterToken();
+        }
+        else
+        {
+            return identifier;
+        }
+    }
+
+    /**
+     * Prints the given identifier. For most databases, this will
+     * be a delimited identifier.
+     * 
+     * @param identifier The identifier
+     */
+    protected void printIdentifier(String identifier) throws IOException
+    {
+        print(getDelimitedIdentifier(identifier));
+    }
+
+    /**
+     * Prints the given identifier followed by a newline. For most databases, this will
+     * be a delimited identifier.
+     * 
+     * @param identifier The identifier
+     */
+    protected void printlnIdentifier(String identifier) throws IOException
+    {
+        println(getDelimitedIdentifier(identifier));
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/builder/SybaseBuilder.java Sun Sep 18 16:00:38 2005
@@ -17,9 +17,10 @@
  */
 
 import java.io.IOException;
+import java.util.HashMap;
 
 import org.apache.ddlutils.PlatformInfo;
-import org.apache.ddlutils.model.Column;
+import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.model.ForeignKey;
 import org.apache.ddlutils.model.Table;
 
@@ -43,41 +44,105 @@
     }
 
     /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#createTable(org.apache.ddlutils.model.Database, org.apache.ddlutils.model.Table)
+     */
+    public void createTable(Database database, Table table) throws IOException
+    {
+        writeQuotationOnStatement();
+        super.createTable(database, table);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#alterTable(org.apache.ddlutils.model.Database, org.apache.ddlutils.model.Table, org.apache.ddlutils.model.Database, org.apache.ddlutils.model.Table, boolean, boolean)
+     */
+    protected void alterTable(Database currentModel, Table currentTable, Database desiredModel, Table desiredTable, boolean doDrops, boolean modifyColumns) throws IOException
+    {
+        writeQuotationOnStatement();
+        super.alterTable(currentModel, currentTable, desiredModel, desiredTable, doDrops, modifyColumns);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#dropTable(org.apache.ddlutils.model.Table)
+     */
+    public void dropTable(Table table) throws IOException
+    {
+        writeQuotationOnStatement();
+        print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = ");
+        printIdentifier(getTableName(table));
+        println(")");
+        println("BEGIN");
+        printIndent();
+        print("DROP TABLE ");
+        printlnIdentifier(getTableName(table));
+        print("END");
+        printEndOfStatement();
+    }
+
+    /* (non-Javadoc)
      * @see org.apache.ddlutils.builder.SqlBuilder#dropExternalForeignKey(org.apache.ddlutils.model.Table, org.apache.ddlutils.model.ForeignKey, int)
      */
     protected void writeExternalForeignKeyDropStmt(Table table, ForeignKey foreignKey, int numKey) throws IOException
     {
         String constraintName = getConstraintName(null, table, "FK", Integer.toString(numKey));
 
-        print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type ='RI' AND name=''");
-        print(constraintName);
-        println("')");
+        print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type ='RI' AND name = ");
+        printIdentifier(constraintName);
+        println(")");
         printIndent();
         print("ALTER TABLE ");
-        print(getTableName(table));
+        printIdentifier(getTableName(table));
         print(" DROP CONSTRAINT ");
-        print(constraintName);
+        printIdentifier(constraintName);
         printEndOfStatement();
     }
 
     /* (non-Javadoc)
-     * @see org.apache.ddlutils.builder.SqlBuilder#dropTable(org.apache.ddlutils.model.Table)
+     * @see org.apache.ddlutils.builder.SqlBuilder#dropExternalForeignKeys(org.apache.ddlutils.model.Table)
      */
-    public void dropTable(Table table) throws IOException
-    { 
-        print("IF EXISTS (SELECT 1 FROM sysobjects WHERE type = 'U' AND name = '");
-        print(getTableName(table));
-        println("')");
-        println("BEGIN");
-        printIndent();
-        print("DROP TABLE ");
-        println(getTableName(table));
-        print("END");
+    public void dropExternalForeignKeys(Table table) throws IOException
+    {
+        writeQuotationOnStatement();
+        super.dropExternalForeignKeys(table);
+    }
+
+    /**
+     * Writes the statement that turns on the ability to write delimited identifiers.
+     */
+    private void writeQuotationOnStatement() throws IOException
+    {
+        print("SET quoted_identifier on");
         printEndOfStatement();
     }
 
-    protected void writeColumnAutoIncrementStmt(Table table, Column column) throws IOException
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#getDeleteSql(org.apache.ddlutils.model.Table, java.util.HashMap, boolean)
+     */
+    public String getDeleteSql(Table table, HashMap pkValues, boolean genPlaceholders)
+    {
+        return getQuotationOnStatement() + super.getDeleteSql(table, pkValues, genPlaceholders);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#getInsertSql(org.apache.ddlutils.model.Table, java.util.HashMap, boolean)
+     */
+    public String getInsertSql(Table table, HashMap columnValues, boolean genPlaceholders)
+    {
+        return getQuotationOnStatement() + super.getInsertSql(table, columnValues, genPlaceholders);
+    }
+
+    /* (non-Javadoc)
+     * @see org.apache.ddlutils.builder.SqlBuilder#getUpdateSql(org.apache.ddlutils.model.Table, java.util.HashMap, boolean)
+     */
+    public String getUpdateSql(Table table, HashMap columnValues, boolean genPlaceholders)
+    {
+        return getQuotationOnStatement() + super.getUpdateSql(table, columnValues, genPlaceholders);
+    }
+
+    /**
+     * Writes the statement that turns on the ability to write delimited identifiers.
+     */
+    private String getQuotationOnStatement()
     {
-        print("IDENTITY");
+        return "SET quoted_identifier on" + getPlatformInfo().getSqlCommandDelimiter() + "\n";
     }
 }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/model/Table.java Sun Sep 18 16:00:38 2005
@@ -576,22 +576,19 @@
     }
 
     /**
-     * Returns the auto increment column in this table if there is one.
+     * Returns the auto increment columns in this table.
      * 
-     * @return The column or <code>null</code> if there is none in this table
+     * @return The columns
      */
-    public Column getAutoIncrementColumn()
+    public Column[] getAutoIncrementColumn()
     {
-        for (int idx = 0; idx < getColumnCount(); idx++)
-        {
-            Column column = getColumn(idx);
-
-            if (column.isAutoIncrement())
-            {
-                return column;
+        Collection autoIncrColumns = CollectionUtils.select(_columns, new Predicate() {
+            public boolean evaluate(Object input) {
+                return ((Column)input).isAutoIncrement();
             }
-        }
-        return null;
+        });
+
+        return (Column[])autoIncrColumns.toArray(new Column[autoIncrColumns.size()]);
     }
 
     /* (non-Javadoc)

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/AxionPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/AxionPlatform.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/AxionPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/AxionPlatform.java Sun Sep 18 16:00:38 2005
@@ -46,7 +46,7 @@
         info.setRequiringNullAsDefaultValue(false);
         info.setPrimaryKeyEmbedded(true);
         info.setForeignKeysEmbedded(false);
-        info.setIndicesEmbedded(true);
+        info.setIndicesEmbedded(false);
         info.addNativeTypeMapping(Types.ARRAY,         "BLOB");
         info.addNativeTypeMapping(Types.BINARY,        "VARBINARY");
         info.addNativeTypeMapping(Types.BIT,           "BOOLEAN");

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DerbyPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DerbyPlatform.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DerbyPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/DerbyPlatform.java Sun Sep 18 16:00:38 2005
@@ -7,6 +7,7 @@
 import java.util.Map;
 
 import org.apache.ddlutils.DynaSqlException;
+import org.apache.ddlutils.builder.DerbyBuilder;
 
 /*
  * Copyright 1999-2004 The Apache Software Foundation.
@@ -40,6 +41,13 @@
     public static final String JDBC_DRIVER_EMBEDDED = "org.apache.derby.jdbc.EmbeddedDriver";
     /** The subprotocol used by the derby drivers */
     public static final String JDBC_SUBPROTOCOL     = "derby";
+
+    public DerbyPlatform()
+    {
+        super();
+        // we override the builder
+        setSqlBuilder(new DerbyBuilder(getSqlBuilder().getPlatformInfo()));
+    }
 
     /* (non-Javadoc)
      * @see org.apache.ddlutils.builder.Platform#getName()

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MySqlPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MySqlPlatform.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MySqlPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/MySqlPlatform.java Sun Sep 18 16:00:38 2005
@@ -51,6 +51,8 @@
         info.setForeignKeysEmbedded(false);
         info.setIndicesEmbedded(false);
         info.setCommentPrefix("#");
+        // Double quotes are only allowed for delimiting identifiers if the server SQL mode includes ANSI_QUOTES 
+        info.setDelimiterToken("`");
         // the BINARY types are also handled by MySqlBuilder.getSqlType(Column)
         info.addNativeTypeMapping(Types.ARRAY,         "LONGBLOB");
         info.addNativeTypeMapping(Types.BINARY,        "CHAR");

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=289996&r1=289995&r2=289996&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 Sep 18 16:00:38 2005
@@ -603,34 +603,38 @@
             return;
         }
 
-        Column autoIdColumn = model.findTable(dynaClass.getTableName()).getAutoIncrementColumn();
+        Column[] columns = model.findTable(dynaClass.getTableName()).getAutoIncrementColumn();
 
-        if (autoIdColumn != null)
+        if (columns.length > 0)
         {
-            // We have to remove the auto-increment column as some databases won't like
-            // it being present in the insert command
             SqlDynaProperty[] newProperties = new SqlDynaProperty[properties.length - 1];
             int               newIdx        = 0;
 
-            for (int idx = 0; idx < properties.length; idx++)
+            // We have to remove the auto-increment columns as some databases won't like
+            // it being present in the insert command
+
+            for (int propIdx = 0; propIdx < properties.length; propIdx++)
             {
-                if (properties[idx].getColumn() != autoIdColumn)
+                for (int autoIncrColumnIdx = 0; autoIncrColumnIdx < columns.length; autoIncrColumnIdx++)
                 {
-                    newProperties[newIdx++] = properties[idx];
+                    if (properties[propIdx].getColumn() != columns[autoIncrColumnIdx])
+                    {
+                        newProperties[newIdx++] = properties[propIdx];
+                    }
                 }
             }
             properties = newProperties;
         }
         
         String            insertSql    = createInsertSql(model, dynaClass, properties, null);
-        String            queryIdSql   = autoIdColumn != null ? createSelectLastInsertIdSql(model, dynaClass) : null;
+        String            queryIdSql   = columns.length > 0 ? createSelectLastInsertIdSql(model, dynaClass) : null;
         PreparedStatement statement    = null;
 
         if (_log.isDebugEnabled())
         {
             _log.debug("About to execute SQL: " + insertSql);
         }
-        if ((autoIdColumn != null) && (queryIdSql == null))
+        if ((columns.length > 0) && (queryIdSql == null))
         {
             _log.warn("The database does not support querying for auto-generated pk values");
         }
@@ -678,9 +682,12 @@
 
                 lastInsertedIds.next();
 
-                Object value = lastInsertedIds.getObject(autoIdColumn.getName());
-
-                PropertyUtils.setProperty(dynaBean, autoIdColumn.getName(), value);
+                for (int idx = 0; idx < columns.length; idx++)
+                {
+                    Object value = lastInsertedIds.getObject(columns[idx].getName());
+    
+                    PropertyUtils.setProperty(dynaBean, columns[idx].getName(), value);
+                }
             }
             catch (NoSuchMethodException ex)
             {

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/TestPlatformBase.java Sun Sep 18 16:00:38 2005
@@ -29,70 +29,128 @@
 
 /**
  * Base class for builder tests.
+ * 
+ * @author <a href="mailto:tomdz@apache.org">Thomas Dudziak</a>
+ * @version $Revision$
  */
 public abstract class TestPlatformBase extends TestCase
 {
     /** The database schema for testing the column types */
     public static final String COLUMN_TEST_SCHEMA =
-        "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"+
-        "<database name=\"datatypetest\">\n"+
-        "  <table name=\"coltype\">\n"+
-        "    <column name=\"COL_ARRAY\"           type=\"ARRAY\"/>\n"+
-        "    <column name=\"COL_BIGINT\"          type=\"BIGINT\"/>\n"+
-        "    <column name=\"COL_BINARY\"          type=\"BINARY\"/>\n"+
-        "    <column name=\"COL_BIT\"             type=\"BIT\"/>\n"+
-        "    <column name=\"COL_BLOB\"            type=\"BLOB\"/>\n"+
-        "    <column name=\"COL_BOOLEAN\"         type=\"BOOLEAN\"/>\n"+
-        "    <column name=\"COL_CHAR\"            size=\"15\" type=\"CHAR\"/>\n"+
-        "    <column name=\"COL_CLOB\"            type=\"CLOB\"/>\n"+
-        "    <column name=\"COL_DATALINK\"        type=\"DATALINK\"/>\n"+
-        "    <column name=\"COL_DATE\"            type=\"DATE\"/>\n"+
-        "    <column name=\"COL_DECIMAL\"         type=\"DECIMAL\" size=\"15,3\"/>\n"+
-        "    <column name=\"COL_DECIMAL_NOSCALE\" type=\"DECIMAL\" size=\"15\"/>\n"+
-        "    <column name=\"COL_DISTINCT\"        type=\"DISTINCT\"/>\n"+
-        "    <column name=\"COL_DOUBLE\"          type=\"DOUBLE\"/>\n"+
-        "    <column name=\"COL_FLOAT\"           type=\"FLOAT\"/>\n"+
-        "    <column name=\"COL_INTEGER\"         type=\"INTEGER\"/>\n"+
-        "    <column name=\"COL_JAVA_OBJECT\"     type=\"JAVA_OBJECT\"/>\n"+
-        "    <column name=\"COL_LONGVARBINARY\"   type=\"LONGVARBINARY\"/>\n"+
-        "    <column name=\"COL_LONGVARCHAR\"     type=\"LONGVARCHAR\"/>\n"+
-        "    <column name=\"COL_NULL\"            type=\"NULL\"/>\n"+
-        "    <column name=\"COL_NUMERIC\"         type=\"NUMERIC\" size=\"15\" />\n"+
-        "    <column name=\"COL_OTHER\"           type=\"OTHER\"/>\n"+
-        "    <column name=\"COL_REAL\"            type=\"REAL\"/>\n"+
-        "    <column name=\"COL_REF\"             type=\"REF\"/>\n"+
-        "    <column name=\"COL_SMALLINT\"        type=\"SMALLINT\" size=\"5\"/>\n"+
-        "    <column name=\"COL_STRUCT\"          type=\"STRUCT\"/>\n"+
-        "    <column name=\"COL_TIME\"            type=\"TIME\"/>\n"+
-        "    <column name=\"COL_TIMESTAMP\"       type=\"TIMESTAMP\"/>\n"+
-        "    <column name=\"COL_TINYINT\"         type=\"TINYINT\"/>\n"+
-        "    <column name=\"COL_VARBINARY\"       size=\"15\" type=\"VARBINARY\"/>\n"+
-        "    <column name=\"COL_VARCHAR\"         size=\"15\" type=\"VARCHAR\"/>\n"+
-        "  </table>\n"+
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+        "<database name='datatypetest'>\n" +
+        "  <table name='coltype'>\n" +
+        "    <column name='COL_ARRAY'           type='ARRAY'/>\n" +
+        "    <column name='COL_BIGINT'          type='BIGINT'/>\n" +
+        "    <column name='COL_BINARY'          type='BINARY'/>\n" +
+        "    <column name='COL_BIT'             type='BIT'/>\n" +
+        "    <column name='COL_BLOB'            type='BLOB'/>\n" +
+        "    <column name='COL_BOOLEAN'         type='BOOLEAN'/>\n" +
+        "    <column name='COL_CHAR'            type='CHAR' size='15'/>\n" +
+        "    <column name='COL_CLOB'            type='CLOB'/>\n" +
+        "    <column name='COL_DATALINK'        type='DATALINK'/>\n" +
+        "    <column name='COL_DATE'            type='DATE'/>\n" +
+        "    <column name='COL_DECIMAL'         type='DECIMAL' size='15,3'/>\n" +
+        "    <column name='COL_DECIMAL_NOSCALE' type='DECIMAL' size='15'/>\n" +
+        "    <column name='COL_DISTINCT'        type='DISTINCT'/>\n" +
+        "    <column name='COL_DOUBLE'          type='DOUBLE'/>\n" +
+        "    <column name='COL_FLOAT'           type='FLOAT'/>\n" +
+        "    <column name='COL_INTEGER'         type='INTEGER'/>\n" +
+        "    <column name='COL_JAVA_OBJECT'     type='JAVA_OBJECT'/>\n" +
+        "    <column name='COL_LONGVARBINARY'   type='LONGVARBINARY'/>\n" +
+        "    <column name='COL_LONGVARCHAR'     type='LONGVARCHAR'/>\n" +
+        "    <column name='COL_NULL'            type='NULL'/>\n" +
+        "    <column name='COL_NUMERIC'         type='NUMERIC' size='15' />\n" +
+        "    <column name='COL_OTHER'           type='OTHER'/>\n" +
+        "    <column name='COL_REAL'            type='REAL'/>\n" +
+        "    <column name='COL_REF'             type='REF'/>\n" +
+        "    <column name='COL_SMALLINT'        type='SMALLINT' size='5'/>\n" +
+        "    <column name='COL_STRUCT'          type='STRUCT'/>\n" +
+        "    <column name='COL_TIME'            type='TIME'/>\n" +
+        "    <column name='COL_TIMESTAMP'       type='TIMESTAMP'/>\n" +
+        "    <column name='COL_TINYINT'         type='TINYINT'/>\n" +
+        "    <column name='COL_VARBINARY'       type='VARBINARY' size='15'/>\n" +
+        "    <column name='COL_VARCHAR'         type='VARCHAR' size='15'/>\n" +
+        "  </table>\n" +
+        "</database>";
+
+    /** The database schema for testing column constraints */
+    public static final String COLUMN_CONSTRAINT_TEST_SCHEMA =
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+        "<database name='columnconstraintstest'>\n" +
+        "  <table name='constraints'>\n" +
+        "    <column name='COL_PK' type='VARCHAR' size='32' primaryKey='true'/>\n" +
+        "    <column name='COL_PK_AUTO_INCR' type='INTEGER' primaryKey='true' autoIncrement='true'/>\n" +
+        "    <column name='COL_NOT_NULL' type='BINARY' size='100' required='true'/>\n" +
+        "    <column name='COL_NOT_NULL_DEFAULT' type='DOUBLE' required='true' default='-2.0'/>\n" +
+        "    <column name='COL_DEFAULT' type='CHAR' size='4' default='test'/>\n" +
+        "    <column name='COL_AUTO_INCR' type='BIGINT' autoIncrement='true'/>\n" +
+        "  </table>\n" +
+        "</database>";
+
+    /** The database schema for testing table constraints, ie. foreign keys and indices */
+    public static final String TABLE_CONSTRAINT_TEST_SCHEMA =
+        "<?xml version='1.0' encoding='ISO-8859-1'?>\n" +
+        "<database name='tableconstraintstest'>\n" +
+        "  <table name='table1'>\n" +
+        "    <column name='COL_PK_1' type='VARCHAR' size='32' primaryKey='true' required='true'/>\n" +
+        "    <column name='COL_PK_2' type='INTEGER' primaryKey='true'/>\n" +
+        "    <column name='COL_INDEX_1' type='BINARY' size='100' required='true'/>\n" +
+        "    <column name='COL_INDEX_2' type='DOUBLE' required='true'/>\n" +
+        "    <column name='COL_INDEX_3' type='CHAR' size='4'/>\n" +
+        "    <index name='testindex1'>\n" +
+        "      <index-column name='COL_INDEX_2'/>\n" +
+        "    </index>\n" +
+        "    <unique name='testindex2'>\n" +
+        "      <unique-column name='COL_INDEX_3'/>\n" +
+        "      <unique-column name='COL_INDEX_1'/>\n" +
+        "    </unique>\n" +
+        "  </table>\n" +
+        "  <table name='table2'>\n" +
+        "    <column name='COL_PK' type='INTEGER' primaryKey='true'/>\n" +
+        "    <column name='COL_FK_1' type='INTEGER'/>\n" +
+        "    <column name='COL_FK_2' type='VARCHAR' size='32' required='true'/>\n" +
+        "    <foreign-key foreignTable='table1'>\n" +
+        "      <reference local='COL_FK_1' foreign='COL_PK_2'/>\n" +
+        "      <reference local='COL_FK_2' foreign='COL_PK_1'/>\n" +
+        "    </foreign-key>\n" +
+        "  </table>\n" +
+        "  <table name='table3'>\n" +
+        "    <column name='COL_PK' type='VARCHAR' size='16' primaryKey='true'/>\n" +
+        "    <column name='COL_FK' type='INTEGER' required='true'/>\n" +
+        "    <foreign-key name='testfk' foreignTable='table2'>\n" +
+        "      <reference local='COL_FK' foreign='COL_PK'/>\n" +
+        "    </foreign-key>\n" +
+        "  </table>\n" +
         "</database>";
 
     /** The tested platform */
     private Platform _platform;
+
     /** The writer that the builder of the platform writes to */
     private StringWriter _writer;
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see junit.framework.TestCase#setUp()
      */
     protected void setUp() throws Exception
     {
-        _writer   = new StringWriter();
+        _writer = new StringWriter();
         _platform = PlatformFactory.createNewPlatformInstance(getDatabaseName());
         _platform.getSqlBuilder().setWriter(_writer);
     }
 
-    /* (non-Javadoc)
+    /*
+     * (non-Javadoc)
+     * 
      * @see junit.framework.TestCase#tearDown()
      */
     protected void tearDown() throws Exception
     {
         _platform = null;
-        _writer   = null;
+        _writer = null;
     }
 
     /**
@@ -135,7 +193,8 @@
     /**
      * Parses the database defined in the given XML definition.
      * 
-     * @param dbDef The database XML definition
+     * @param dbDef
+     *            The database XML definition
      * @return The database model
      */
     protected Database parseDatabaseFromString(String dbDef)
@@ -144,13 +203,14 @@
     }
 
     /**
-     * Creates the database creation sql for the test database defined by {@link #COLUMN_TEST_SCHEMA}.
+     * Creates the database creation sql for the given database schema.
      * 
+     * @param schema Th database schema XML
      * @return The sql
      */
-    protected String createTestDatabase() throws IntrospectionException, IOException, SAXException
+    protected String createTestDatabase(String schema) throws IntrospectionException, IOException, SAXException
     {
-        Database testDb = parseDatabaseFromString(COLUMN_TEST_SCHEMA);
+        Database testDb = parseDatabaseFromString(schema);
 
         // we're turning the comment creation off to make testing easier
         getPlatformInfo().setCommentsSupported(false);
@@ -159,23 +219,25 @@
     }
 
     /**
-     * Compares the two strings but ignores any whitespace differences.
-     * It also recognizes special delimiter chars.
+     * Compares the two strings but ignores any whitespace differences. It also
+     * recognizes special delimiter chars.
      * 
-     * @param expected The expected string
-     * @param actual   The actual string
+     * @param expected
+     *            The expected string
+     * @param actual
+     *            The actual string
      */
     protected void assertEqualsIgnoringWhitespaces(String expected, String actual)
     {
-        assertEquals(compressWhitespaces(expected),
-                     compressWhitespaces(actual));
+        assertEquals(compressWhitespaces(expected), compressWhitespaces(actual));
     }
 
     /**
-     * Compresses the whitespaces in the given string to a single space.
-     * Also recognizes special delimiter chars and removes whitespaces before them.
+     * Compresses the whitespaces in the given string to a single space. Also
+     * recognizes special delimiter chars and removes whitespaces before them.
      * 
-     * @param original The original string
+     * @param original
+     *            The original string
      * @return The resulting string
      */
     private String compressWhitespaces(String original)
@@ -197,7 +259,8 @@
             }
             else
             {
-                if ((curChar == ',') || (curChar == ';') || (curChar == '(') || (curChar == ')'))
+                if ((curChar == ',') || (curChar == ';') ||
+                    (curChar == '(') || (curChar == ')'))
                 {
                     if ((oldChar == ' ') && (result.length() > 0))
                     {
@@ -217,4 +280,3 @@
         return result.toString();
     }
 }
-

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestAxionPlatform.java
URL: http://svn.apache.org/viewcvs/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestAxionPlatform.java?rev=289996&r1=289995&r2=289996&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestAxionPlatform.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestAxionPlatform.java Sun Sep 18 16:00:38 2005
@@ -41,41 +41,101 @@
     public void testColumnTypes() throws Exception
     {
         assertEqualsIgnoringWhitespaces(
-            "DROP TABLE IF EXISTS coltype;\n"+
-            "CREATE TABLE coltype\n"+
+            "DROP TABLE IF EXISTS \"coltype\";\n"+
+            "CREATE TABLE \"coltype\"\n"+
             "(\n"+
-            "    COL_ARRAY           BLOB,\n"+
-            "    COL_BIGINT          BIGINT,\n"+
-            "    COL_BINARY          VARBINARY,\n"+
-            "    COL_BIT             BOOLEAN,\n"+
-            "    COL_BLOB            BLOB,\n"+
-            "    COL_BOOLEAN         BOOLEAN,\n"+
-            "    COL_CHAR            CHAR(15),\n"+
-            "    COL_CLOB            CLOB,\n"+
-            "    COL_DATALINK        VARBINARY,\n"+
-            "    COL_DATE            DATE,\n"+
-            "    COL_DECIMAL         NUMBER(15,3),\n"+
-            "    COL_DECIMAL_NOSCALE NUMBER(15,0),\n"+
-            "    COL_DISTINCT        VARBINARY,\n"+
-            "    COL_DOUBLE          FLOAT,\n"+
-            "    COL_FLOAT           FLOAT,\n"+
-            "    COL_INTEGER         INTEGER,\n"+
-            "    COL_JAVA_OBJECT     JAVA_OBJECT,\n"+
-            "    COL_LONGVARBINARY   VARBINARY,\n"+
-            "    COL_LONGVARCHAR     VARCHAR,\n"+
-            "    COL_NULL            VARBINARY,\n"+
-            "    COL_NUMERIC         NUMBER(15,0),\n"+
-            "    COL_OTHER           BLOB,\n"+
-            "    COL_REAL            FLOAT,\n"+
-            "    COL_REF             VARBINARY,\n"+
-            "    COL_SMALLINT        SHORT,\n"+
-            "    COL_STRUCT          VARBINARY,\n"+
-            "    COL_TIME            TIME,\n"+
-            "    COL_TIMESTAMP       TIMESTAMP,\n"+
-            "    COL_TINYINT         SHORT,\n"+
-            "    COL_VARBINARY       VARBINARY(15),\n"+
-            "    COL_VARCHAR         VARCHAR(15)\n"+
+            "    \"COL_ARRAY\"           BLOB,\n"+
+            "    \"COL_BIGINT\"          BIGINT,\n"+
+            "    \"COL_BINARY\"          VARBINARY,\n"+
+            "    \"COL_BIT\"             BOOLEAN,\n"+
+            "    \"COL_BLOB\"            BLOB,\n"+
+            "    \"COL_BOOLEAN\"         BOOLEAN,\n"+
+            "    \"COL_CHAR\"            CHAR(15),\n"+
+            "    \"COL_CLOB\"            CLOB,\n"+
+            "    \"COL_DATALINK\"        VARBINARY,\n"+
+            "    \"COL_DATE\"            DATE,\n"+
+            "    \"COL_DECIMAL\"         NUMBER(15,3),\n"+
+            "    \"COL_DECIMAL_NOSCALE\" NUMBER(15,0),\n"+
+            "    \"COL_DISTINCT\"        VARBINARY,\n"+
+            "    \"COL_DOUBLE\"          FLOAT,\n"+
+            "    \"COL_FLOAT\"           FLOAT,\n"+
+            "    \"COL_INTEGER\"         INTEGER,\n"+
+            "    \"COL_JAVA_OBJECT\"     JAVA_OBJECT,\n"+
+            "    \"COL_LONGVARBINARY\"   VARBINARY,\n"+
+            "    \"COL_LONGVARCHAR\"     VARCHAR,\n"+
+            "    \"COL_NULL\"            VARBINARY,\n"+
+            "    \"COL_NUMERIC\"         NUMBER(15,0),\n"+
+            "    \"COL_OTHER\"           BLOB,\n"+
+            "    \"COL_REAL\"            FLOAT,\n"+
+            "    \"COL_REF\"             VARBINARY,\n"+
+            "    \"COL_SMALLINT\"        SHORT,\n"+
+            "    \"COL_STRUCT\"          VARBINARY,\n"+
+            "    \"COL_TIME\"            TIME,\n"+
+            "    \"COL_TIMESTAMP\"       TIMESTAMP,\n"+
+            "    \"COL_TINYINT\"         SHORT,\n"+
+            "    \"COL_VARBINARY\"       VARBINARY(15),\n"+
+            "    \"COL_VARCHAR\"         VARCHAR(15)\n"+
             ");\n",
-            createTestDatabase());
+            createTestDatabase(COLUMN_TEST_SCHEMA));
+    }
+
+    /**
+     * Tests the column constraints.
+     */
+    public void testColumnConstraints() throws Exception
+    {
+        assertEqualsIgnoringWhitespaces(
+            "DROP TABLE IF EXISTS \"constraints\";\n" +
+            "CREATE TABLE \"constraints\"\n"+
+            "(\n"+
+            "    \"COL_PK\"               VARCHAR(32),\n"+
+            "    \"COL_PK_AUTO_INCR\"     INTEGER IDENTITY,\n"+
+            "    \"COL_NOT_NULL\"         VARBINARY(100) NOT NULL,\n"+
+            "    \"COL_NOT_NULL_DEFAULT\" FLOAT DEFAULT '-2.0' NOT NULL,\n"+
+            "    \"COL_DEFAULT\"          CHAR(4) DEFAULT 'test',\n"+
+            "    \"COL_AUTO_INCR\"        BIGINT IDENTITY,\n"+
+            "    PRIMARY KEY (\"COL_PK\", \"COL_PK_AUTO_INCR\")\n"+
+            ");\n",
+            createTestDatabase(COLUMN_CONSTRAINT_TEST_SCHEMA));
+    }
+
+    /**
+     * Tests the table constraints.
+     */
+    public void testTableConstraints() throws Exception
+    {
+        assertEqualsIgnoringWhitespaces(
+            "ALTER TABLE \"table3\" DROP CONSTRAINT \"testfk\";\n"+
+            "ALTER TABLE \"table2\" DROP CONSTRAINT \"table2_FK_COL_FK_1_COL_FK_2_table1\";\n"+
+            "DROP TABLE IF EXISTS \"table3\";\n"+
+            "DROP TABLE IF EXISTS \"table2\";\n"+
+            "DROP TABLE IF EXISTS \"table1\";\n"+
+            "CREATE TABLE \"table1\"\n"+
+            "(\n"+
+            "    \"COL_PK_1\"    VARCHAR(32) NOT NULL,\n"+
+            "    \"COL_PK_2\"    INTEGER,\n"+
+            "    \"COL_INDEX_1\" VARBINARY(100) NOT NULL,\n"+
+            "    \"COL_INDEX_2\" FLOAT NOT NULL,\n"+
+            "    \"COL_INDEX_3\" CHAR(4),\n"+
+            "    PRIMARY KEY (\"COL_PK_1\", \"COL_PK_2\")\n"+
+            ");\n"+
+            "CREATE INDEX \"testindex1\" ON \"table1\" (\"COL_INDEX_2\");\n"+
+            "CREATE UNIQUE INDEX \"testindex2\" ON \"table1\" (\"COL_INDEX_3\", \"COL_INDEX_1\");\n"+
+            "CREATE TABLE \"table2\"\n"+
+            "(\n"+
+            "    \"COL_PK\"   INTEGER,\n"+
+            "    \"COL_FK_1\" INTEGER,\n"+
+            "    \"COL_FK_2\" VARCHAR(32) NOT NULL,\n"+
+            "    PRIMARY KEY (\"COL_PK\")\n"+
+            ");\n"+
+            "CREATE TABLE \"table3\"\n"+
+            "(\n"+
+            "    \"COL_PK\" VARCHAR(16),\n"+
+            "    \"COL_FK\" INTEGER NOT NULL,\n"+
+            "    PRIMARY KEY (\"COL_PK\")\n"+
+            ");\n"+
+            "ALTER TABLE \"table2\" ADD CONSTRAINT \"table2_FK_COL_FK_1_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",
+            createTestDatabase(TABLE_CONSTRAINT_TEST_SCHEMA));
     }
 }



Mime
View raw message