db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r602807 [13/15] - in /db/ddlutils/trunk: ./ src/java/org/apache/ddlutils/ src/java/org/apache/ddlutils/alteration/ src/java/org/apache/ddlutils/model/ src/java/org/apache/ddlutils/platform/ src/java/org/apache/ddlutils/platform/axion/ src/j...
Date Mon, 10 Dec 2007 08:21:39 GMT
Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java?rev=602807&r1=602806&r2=602807&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java Mon Dec 10 00:20:47 2007
@@ -27,11 +27,20 @@
 
 import org.apache.commons.beanutils.DynaBean;
 import org.apache.ddlutils.model.Database;
+import org.apache.ddlutils.platform.mckoi.MckoiPlatform;
+import org.apache.ddlutils.platform.mysql.MySql50Platform;
+import org.apache.ddlutils.platform.mysql.MySqlPlatform;
 import org.apache.ddlutils.platform.sybase.SybasePlatform;
 
 /**
  * Performs tests for the alteration of databases.
- * 
+ *
+ * TODO: add more tests, esp. combining multiple changes
+ *       - change datatype/size and add to/remove from pk
+ *       - change datatype/size and add/remove pk that uses the column
+ *       - change type of column in index and foreign key
+ *       - drop index with columns in a foreign key
+ *       - ...
  * @version $Revision: $
  */
 public class TestAlteration extends RoundtripTestBase
@@ -180,6 +189,56 @@
     }
 
     /**
+     * Tests the alteration of the sizes of PK and FK columns.
+     */
+    public void testChangePKAndFKSizes()
+    {
+        final String model1Xml = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            "<database name='roundtriptest'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk' type='VARCHAR' size='32' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='fk' type='VARCHAR' size='32' required='false'/>\n"+
+            "    <foreign-key foreignTable='roundtrip1'>\n"+
+            "      <reference local='fk' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
+            "  </table>\n"+
+            "</database>";
+        final String model2Xml = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            "<database name='roundtriptest'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk' type='VARCHAR' size='128' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='fk' type='VARCHAR' size='128' required='false'/>\n"+
+            "    <foreign-key foreignTable='roundtrip1'>\n"+
+            "      <reference local='fk' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
+            "  </table>\n"+
+            "</database>";
+
+        createDatabase(model1Xml);
+
+        insertRow("roundtrip1", new Object[] { "test" });
+        insertRow("roundtrip2", new Object[] { new Integer(1), "test" });
+
+        alterDatabase(model2Xml);
+
+        assertEquals(getAdjustedModel(),
+                     readModelFromDatabase("roundtriptest"));
+
+        List     beans = getRows("roundtrip2");
+        DynaBean bean  = (DynaBean)beans.get(0);
+
+        assertEquals((Object)"test", bean, "fk");
+    }
+
+    /**
      * Tests the alteration of the datatypes of columns of a PK and FK that
      * will be dropped.
      */
@@ -686,15 +745,19 @@
     }
 
     /**
-     * Tests the addition of a column.
+     * Tests the change of the order of the columns of a table.
      */
-    public void testAddColumn()
+    public void testChangeColumnOrder()
     {
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue1' type='VARCHAR' size='32'/>\n"+
+            "    <column name='avalue4' type='VARCHAR' size='5'/>\n"+
+            "    <column name='avalue3' type='DOUBLE' default='1.0'/>\n"+
+            "    <column name='avalue2' type='INTEGER'/>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
@@ -702,13 +765,54 @@
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='VARCHAR' size='32'/>\n"+
+            "    <column name='avalue1' type='VARCHAR' size='32'/>\n"+
+            "    <column name='avalue2' type='INTEGER'/>\n"+
+            "    <column name='avalue3' type='DOUBLE' default='1.0'/>\n"+
+            "    <column name='avalue4' type='VARCHAR' size='5'/>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1) });
+        insertRow("roundtrip", new Object[] { new Integer(1), "test", "value", null, null });
+
+        alterDatabase(model2Xml);
+
+        assertEquals(getAdjustedModel(),
+                     readModelFromDatabase("roundtriptest"));
+
+        List beans = getRows("roundtrip");
+
+        assertEquals((Object)"test", beans.get(0), "avalue1");
+        assertEquals((Object)null, beans.get(0), "avalue2");
+        assertEquals(new Double(1.0), beans.get(0), "avalue3");
+        assertEquals((Object)"value", beans.get(0), "avalue4");
+    }
+
+    /**
+     * Tests the removal of a column.
+     */
+    public void testDropColumn()
+    {
+        final String model1Xml = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            "<database name='roundtriptest'>\n"+
+            "  <table name='roundtrip'>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue' type='VARCHAR' size='50'/>\n"+
+            "  </table>\n"+
+            "</database>";
+        final String model2Xml = 
+            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            "<database name='roundtriptest'>\n"+
+            "  <table name='roundtrip'>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "</database>";
+
+        createDatabase(model1Xml);
+
+        insertRow("roundtrip", new Object[] { new Integer(1), "test" });
 
     	alterDatabase(model2Xml);
 
@@ -717,51 +821,50 @@
 
         List beans = getRows("roundtrip");
 
-        assertEquals((Object)null, beans.get(0), "avalue");
+        assertEquals(new Integer(1), beans.get(0), "pk");
     }
 
     /**
-     * Tests the addition of an auto-increment column.
+     * Tests the removal of an auto-increment column.
      */
-    public void testAddAutoIncrementColumn()
+    public void testDropAutoIncrementColumn()
     {
-    	if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
-    	{
-    		return;
-    	}
+        if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
+        {
+            return;
+        }
 
-        // we need special catering for Sybase which does not support identity for INTEGER columns
         boolean      isSybase  = SybasePlatform.DATABASENAME.equals(getPlatform().getName());
-        final String model1Xml = 
+        final String model1Xml;
+        final String model2Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
-        final String model2Xml;
 
         if (isSybase)
         {
-            model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
                         "<database name='roundtriptest'>\n"+
                         "  <table name='roundtrip'>\n"+
                         "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-                        "    <column name='avalue' type='NUMERIC' size='12,0' autoIncrement='true' required='true'/>\n"+
+                        "    <column name='avalue' type='NUMERIC' size='12,0' required='true' autoIncrement='true'/>\n"+
                         "  </table>\n"+
                         "</database>";
         }
         else
         {
-            model2Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
+            model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
                         "<database name='roundtriptest'>\n"+
                         "  <table name='roundtrip'>\n"+
                         "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-                        "    <column name='avalue' type='INTEGER' autoIncrement='true' required='true'/>\n"+
+                        "    <column name='avalue' type='INTEGER' autoIncrement='true'/>\n"+
                         "  </table>\n"+
                         "</database>";
         }
-
+        
         createDatabase(model1Xml);
 
         insertRow("roundtrip", new Object[] { new Integer(1) });
@@ -773,29 +876,20 @@
 
         List beans = getRows("roundtrip");
 
-        if (isSybase)
-        {
-            assertEquals(new BigDecimal(1), beans.get(0), "avalue");
-        }
-        else
-        {
-            Object avalue = ((DynaBean)beans.get(0)).get("avalue");
-
-            assertTrue((avalue == null) || new Integer(1).equals(avalue));
-        }
+        assertEquals(new Integer(1), beans.get(0), "pk");
     }
 
     /**
-     * Tests the addition of several columns.
+     * Tests the addition of a column to the pk.
      */
-    public void testAddColumns()
+    public void testAddColumnToPK()
     {
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue3' type='DOUBLE' default='1.0'/>\n"+
+            "    <column name='avalue' type='VARCHAR' size='50' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
@@ -803,42 +897,35 @@
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='VARCHAR' size='32'/>\n"+
-            "    <column name='avalue2' type='INTEGER'/>\n"+
-            "    <column name='avalue3' type='DOUBLE' default='1.0'/>\n"+
-            "    <column name='avalue4' type='VARCHAR' size='16'/>\n"+
+            "    <column name='avalue' type='VARCHAR' size='50' primaryKey='true' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), new Double(3.0) });
+        insertRow("roundtrip", new Object[] { new Integer(1), "test" });
 
-        alterDatabase(model2Xml);
+    	alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
         List beans = getRows("roundtrip");
 
-        assertEquals((Object)null, beans.get(0), "avalue1");
-        assertEquals((Object)null, beans.get(0), "avalue2");
-        assertEquals(new Double(3.0), beans.get(0), "avalue3");
-        assertEquals((Object)null, beans.get(0), "avalue4");
+        assertEquals((Object)"test", beans.get(0), "avalue");
     }
 
     /**
-     * Tests the addition of several columns at the end of the table.
+     * Tests the removal of a column from the pk.
      */
-    public void testAddColumnsAtTheEnd()
+    public void testRemoveColumnFromPK()
     {
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='VARCHAR' size='32'/>\n"+
-            "    <column name='avalue2' type='INTEGER'/>\n"+
+            "    <column name='avalue' type='VARCHAR' size='50' primaryKey='true' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
@@ -846,50 +933,35 @@
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='VARCHAR' size='32'/>\n"+
-            "    <column name='avalue2' type='INTEGER'/>\n"+
-            "    <column name='avalue3' type='DOUBLE' default='1.0'/>\n"+
-            "    <column name='avalue4' type='VARCHAR' size='16'/>\n"+
+            "    <column name='avalue' type='VARCHAR' size='50' primaryKey='false' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), "test", new Integer(3) });
+        insertRow("roundtrip", new Object[] { new Integer(1), "test" });
 
-        alterDatabase(model2Xml);
+    	alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
         List beans = getRows("roundtrip");
 
-        assertEquals((Object)"test", beans.get(0), "avalue1");
-        assertEquals(new Integer(3), beans.get(0), "avalue2");
-
-        // we cannot be sure whether the default algorithm is used (which will apply the
-        // default value even to existing columns with NULL in it) or the database supports
-        // it dircetly (in which case it might still be NULL)
-        Object avalue3 = ((DynaBean)beans.get(0)).get("avalue3");
-
-        assertTrue((avalue3 == null) || new Double(1.0).equals(avalue3));
-        
-        assertEquals((Object)null, beans.get(0), "avalue4");
+        assertEquals((Object)"test", beans.get(0), "avalue");
     }
 
     /**
-     * Tests the addition of a column with a default value. Note that depending
-     * on whether the database supports this via a statement, this test may fail.
-     * For instance, Sql Server has a statement for this which means that the
-     * existing value in column avalue won't be changed and thus the test fails.
+     * Tests the removal of a pk column.
      */
-    public void testAddColumnWithDefault()
+    public void testDropPKColumn()
     {
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue' type='VARCHAR' size='50' primaryKey='true' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
@@ -897,39 +969,40 @@
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='INTEGER' default='2'/>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1) });
+        insertRow("roundtrip", new Object[] { new Integer(1), "test" });
 
-        alterDatabase(model2Xml);
+    	alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
         List beans = getRows("roundtrip");
 
-        // we cannot be sure whether the default algorithm is used (which will apply the
-        // default value even to existing columns with NULL in it) or the database supports
-        // it dircetly (in which case it might still be NULL)
-        Object avalue = ((DynaBean)beans.get(0)).get("avalue");
-
-        assertTrue((avalue == null) || new Integer(2).equals(avalue));
+        assertEquals(new Integer(1), beans.get(0), "pk");
     }
 
     /**
-     * Tests the addition of a column that is set to NOT NULL.
+     * Tests the addition of an index.
      */
-    public void testAddRequiredColumn()
+    public void testAddIndex()
     {
+        if (!getPlatformInfo().isIndicesSupported())
+        {
+            return;
+        }
+
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue1' type='VARCHAR' size='50'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
@@ -937,38 +1010,46 @@
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='INTEGER' default='2' required='true'/>\n"+
+            "    <column name='avalue1' type='VARCHAR' size='50'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
+            "    <index name='test'>\n"+
+            "      <index-column name='avalue1'/>\n"+
+            "      <index-column name='avalue2'/>\n"+
+            "    </index>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1) });
+        insertRow("roundtrip", new Object[] { new Integer(1), null, new Integer(2) });
 
-        alterDatabase(model2Xml);
+    	alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
         List beans = getRows("roundtrip");
 
-        assertEquals(new Integer(2), beans.get(0), "avalue");
+        assertEquals((Object)null, beans.get(0), "avalue1");
+        assertEquals(new Integer(2), beans.get(0), "avalue2");
     }
 
     /**
-     * Tests the change of the order of the columns of a table.
+     * Tests the addition of an unique index.
      */
-    public void testChangeColumnOrder()
+    public void testAddUniqueIndex()
     {
+        if (!getPlatformInfo().isIndicesSupported())
+        {
+            return;
+        }
+
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='VARCHAR' size='32'/>\n"+
-            "    <column name='avalue4' type='VARCHAR' size='5'/>\n"+
-            "    <column name='avalue3' type='DOUBLE' default='1.0'/>\n"+
-            "    <column name='avalue2' type='INTEGER'/>\n"+
+            "    <column name='avalue' type='INTEGER'/>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
@@ -976,41 +1057,43 @@
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='VARCHAR' size='32'/>\n"+
-            "    <column name='avalue2' type='INTEGER'/>\n"+
-            "    <column name='avalue3' type='DOUBLE' default='1.0'/>\n"+
-            "    <column name='avalue4' type='VARCHAR' size='5'/>\n"+
+            "    <column name='avalue' type='INTEGER'/>\n"+
+            "    <unique name='test'>\n"+
+            "      <unique-column name='avalue'/>\n"+
+            "    </unique>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), "test", "value", null, null });
+        insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) });
 
-        alterDatabase(model2Xml);
+    	alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
         List beans = getRows("roundtrip");
 
-        assertEquals((Object)"test", beans.get(0), "avalue1");
-        assertEquals((Object)null, beans.get(0), "avalue2");
-        assertEquals(new Double(1.0), beans.get(0), "avalue3");
-        assertEquals((Object)"value", beans.get(0), "avalue4");
+        assertEquals(new Integer(2), beans.get(0), "avalue");
     }
 
     /**
-     * Tests the removal of a column.
+     * Tests the removal of an unique index.
      */
-    public void testDropColumn()
+    public void testDropUniqueIndex()
     {
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='VARCHAR' size='50'/>\n"+
+            "    <column name='avalue1' type='DOUBLE'/>\n"+
+            "    <column name='avalue2' type='VARCHAR' size='50'/>\n"+
+            "    <unique name='test_index'>\n"+
+            "      <unique-column name='avalue2'/>\n"+
+            "      <unique-column name='avalue1'/>\n"+
+            "    </unique>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
@@ -1018,12 +1101,14 @@
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue1' type='DOUBLE'/>\n"+
+            "    <column name='avalue2' type='VARCHAR' size='50'/>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), "test" });
+        insertRow("roundtrip", new Object[] { new Integer(1), new Double(2.0), "test" });
 
     	alterDatabase(model2Xml);
 
@@ -1032,285 +1117,148 @@
 
         List beans = getRows("roundtrip");
 
-        assertEquals(new Integer(1), beans.get(0), "pk");
+        assertEquals(new Double(2.0), beans.get(0), "avalue1");
+        assertEquals((Object)"test", beans.get(0), "avalue2");
     }
 
     /**
-     * Tests the removal of an auto-increment column.
+     * Tests the removal of an index that has column that are also used by foreign keys. This is a
+     * test esp. for the handling of http://bugs.mysql.com/bug.php?id=21395.
      */
-    public void testDropAutoIncrementColumn()
+    public void testDropIndexOverlappingWithForeignKeys()
     {
-        if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
-        {
-            return;
-        }
-
-        boolean      isSybase  = SybasePlatform.DATABASENAME.equals(getPlatform().getName());
-        final String model1Xml;
-        final String model2Xml = 
+        final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
             "  </table>\n"+
-            "</database>";
-
-        if (isSybase)
-        {
-            model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-                        "<database name='roundtriptest'>\n"+
-                        "  <table name='roundtrip'>\n"+
-                        "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-                        "    <column name='avalue' type='NUMERIC' size='12,0' required='true' autoIncrement='true'/>\n"+
-                        "  </table>\n"+
-                        "</database>";
-        }
-        else
-        {
-            model1Xml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-                        "<database name='roundtriptest'>\n"+
-                        "  <table name='roundtrip'>\n"+
-                        "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-                        "    <column name='avalue' type='INTEGER' autoIncrement='true'/>\n"+
-                        "  </table>\n"+
-                        "</database>";
-        }
-        
-        createDatabase(model1Xml);
-
-        insertRow("roundtrip", new Object[] { new Integer(1) });
-
-    	alterDatabase(model2Xml);
-
-        assertEquals(getAdjustedModel(),
-                     readModelFromDatabase("roundtriptest"));
-
-        List beans = getRows("roundtrip");
-
-        assertEquals(new Integer(1), beans.get(0), "pk");
-    }
-
-    /**
-     * Tests the addition of a column to the pk.
-     */
-    public void testAddColumnToPK()
-    {
-        final String model1Xml = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-            "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip2'>\n"+
+            "    <column name='pk' type='VARCHAR' size='50' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip3'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='VARCHAR' size='50' required='true'/>\n"+
+            "    <column name='avalue1' type='INTEGER'/>\n"+
+            "    <column name='avalue2' type='VARCHAR' size='50'/>\n"+
+            "    <index name='test_index'>\n"+
+            "      <index-column name='avalue2'/>\n"+
+            "      <index-column name='avalue1'/>\n"+
+            "    </index>\n"+
+            "    <foreign-key foreignTable='roundtrip1'>\n"+
+            "      <reference local='avalue1' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
+            "    <foreign-key foreignTable='roundtrip2'>\n"+
+            "      <reference local='avalue2' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='VARCHAR' size='50' primaryKey='true' required='true'/>\n"+
             "  </table>\n"+
-            "</database>";
-
-        createDatabase(model1Xml);
-
-        insertRow("roundtrip", new Object[] { new Integer(1), "test" });
-
-    	alterDatabase(model2Xml);
-
-        assertEquals(getAdjustedModel(),
-                     readModelFromDatabase("roundtriptest"));
-
-        List beans = getRows("roundtrip");
-
-        assertEquals((Object)"test", beans.get(0), "avalue");
-    }
-
-    /**
-     * Tests the removal of a column from the pk.
-     */
-    public void testRemoveColumnFromPK()
-    {
-        final String model1Xml = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-            "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
-            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='VARCHAR' size='50' primaryKey='true' required='true'/>\n"+
+            "  <table name='roundtrip2'>\n"+
+            "    <column name='pk' type='VARCHAR' size='50' primaryKey='true' required='true'/>\n"+
             "  </table>\n"+
-            "</database>";
-        final String model2Xml = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-            "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip3'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='VARCHAR' size='50' primaryKey='false' required='true'/>\n"+
+            "    <column name='avalue1' type='INTEGER'/>\n"+
+            "    <column name='avalue2' type='VARCHAR' size='50'/>\n"+
+            "    <foreign-key foreignTable='roundtrip1'>\n"+
+            "      <reference local='avalue1' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
+            "    <foreign-key foreignTable='roundtrip2'>\n"+
+            "      <reference local='avalue2' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), "test" });
+        insertRow("roundtrip1", new Object[] { new Integer(1) });
+        insertRow("roundtrip2", new Object[] { "test" });
+        insertRow("roundtrip3", new Object[] { new Integer(1), new Integer(1), "test" });
 
-    	alterDatabase(model2Xml);
+        alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
-        List beans = getRows("roundtrip");
+        List beans1 = getRows("roundtrip1");
+        List beans2 = getRows("roundtrip2");
+        List beans3 = getRows("roundtrip3");
 
-        assertEquals((Object)"test", beans.get(0), "avalue");
+        assertEquals(new Integer(1), beans1.get(0), "pk");
+        assertEquals((Object)"test", beans2.get(0), "pk");
+        assertEquals(new Integer(1), beans3.get(0), "pk");
+        assertEquals(new Integer(1), beans3.get(0), "avalue1");
+        assertEquals((Object)"test", beans3.get(0), "avalue2");
     }
 
     /**
-     * Tests the addition of a pk column.
+     * Tests the removal of an index that has column that are also referenced by a remote foreign key. 
      */
-    public void testAddPKColumn()
+    public void testDropIndexOverlappingWithRemoteForeignKey()
     {
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue' type='VARCHAR' size='50'/>\n"+
+            "    <index name='test_index'>\n"+
+            "      <index-column name='pk'/>\n"+
+            "      <index-column name='avalue'/>\n"+
+            "    </index>\n"+
             "  </table>\n"+
-            "</database>";
-        final String model2Xml = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-            "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip2'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='INTEGER' default='0' primaryKey='true' required='true'/>\n"+
-            "  </table>\n"+
-            "</database>";
-
-        createDatabase(model1Xml);
-
-        insertRow("roundtrip", new Object[] { new Integer(1) });
-
-    	alterDatabase(model2Xml);
-
-        assertEquals(getAdjustedModel(),
-                     readModelFromDatabase("roundtriptest"));
-
-        List beans = getRows("roundtrip");
-
-        assertEquals(new Integer(0), beans.get(0), "avalue");
-    }
-
-    /**
-     * Tests the addition of a primary key and a column.
-     */
-    public void testAddPKAndColumn()
-    {
-        final String model1Xml = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-            "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
-            "    <column name='pk' type='INTEGER' required='true'/>\n"+
+            "    <column name='avalue' type='INTEGER'/>\n"+
+            "    <foreign-key foreignTable='roundtrip1'>\n"+
+            "      <reference local='avalue' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='INTEGER' default='0'/>\n"+
-            "  </table>\n"+
-            "</database>";
-
-        createDatabase(model1Xml);
-
-        insertRow("roundtrip", new Object[] { new Integer(1) });
-
-        alterDatabase(model2Xml);
-
-        assertEquals(getAdjustedModel(),
-                     readModelFromDatabase("roundtriptest"));
-
-        List beans = getRows("roundtrip");
-
-        // we cannot be sure whether the default algorithm is used (which will apply the
-        // default value even to existing columns with NULL in it) or the database supports
-        // it dircetly (in which case it might still be NULL)
-        Object avalue = ((DynaBean)beans.get(0)).get("avalue");
-
-        assertTrue((avalue == null) || new Integer(0).equals(avalue));
-    }
-
-    /**
-     * Tests the addition of a primary key and a primary key column.
-     */
-    public void testAddPKAndPKColumn()
-    {
-        final String model1Xml = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-            "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
-            "    <column name='pk' type='INTEGER' required='true'/>\n"+
+            "    <column name='avalue' type='VARCHAR' size='50'/>\n"+
             "  </table>\n"+
-            "</database>";
-        final String model2Xml = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-            "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip2'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='INTEGER' primaryKey='true' required='true' default='0'/>\n"+
+            "    <column name='avalue' type='INTEGER'/>\n"+
+            "    <foreign-key foreignTable='roundtrip1'>\n"+
+            "      <reference local='avalue' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1) });
+        insertRow("roundtrip1", new Object[] { new Integer(1), "test" });
+        insertRow("roundtrip2", new Object[] { new Integer(1), new Integer(1) });
 
         alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
-        List beans = getRows("roundtrip");
-
-        assertEquals(new Integer(0), beans.get(0), "avalue");
-    }
-
-    /**
-     * Tests the removal of a pk column.
-     */
-    public void testDropPKColumn()
-    {
-        final String model1Xml = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-            "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
-            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='VARCHAR' size='50' primaryKey='true' required='true'/>\n"+
-            "  </table>\n"+
-            "</database>";
-        final String model2Xml = 
-            "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
-            "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
-            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "  </table>\n"+
-            "</database>";
-
-        createDatabase(model1Xml);
-
-        insertRow("roundtrip", new Object[] { new Integer(1), "test" });
-
-    	alterDatabase(model2Xml);
-
-        assertEquals(getAdjustedModel(),
-                     readModelFromDatabase("roundtriptest"));
-
-        List beans = getRows("roundtrip");
+        List beans1 = getRows("roundtrip1");
+        List beans2 = getRows("roundtrip2");
 
-        assertEquals(new Integer(1), beans.get(0), "pk");
+        assertEquals(new Integer(1), beans1.get(0), "pk");
+        assertEquals((Object)"test", beans1.get(0), "avalue");
+        assertEquals(new Integer(1), beans2.get(0), "pk");
+        assertEquals(new Integer(1), beans2.get(0), "avalue");
     }
 
     /**
-     * Tests the addition of an index.
+     * Tests the removal of a column from an index.
      */
-    public void testAddIndex()
+    public void testRemoveColumnFromUniqueIndex()
     {
         if (!getPlatformInfo().isIndicesSupported())
         {
@@ -1322,8 +1270,12 @@
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='VARCHAR' size='50'/>\n"+
-            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
+            "    <column name='avalue1' type='DOUBLE'/>\n"+
+            "    <column name='avalue2' type='INTEGER'/>\n"+
+            "    <unique name='test_index'>\n"+
+            "      <unique-column name='avalue1'/>\n"+
+            "      <unique-column name='avalue2'/>\n"+
+            "    </unique>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
@@ -1331,18 +1283,17 @@
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='VARCHAR' size='50'/>\n"+
-            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
-            "    <index name='test'>\n"+
-            "      <index-column name='avalue1'/>\n"+
-            "      <index-column name='avalue2'/>\n"+
-            "    </index>\n"+
+            "    <column name='avalue1' type='DOUBLE'/>\n"+
+            "    <column name='avalue2' type='INTEGER'/>\n"+
+            "    <unique name='test_index'>\n"+
+            "      <unique-column name='avalue1'/>\n"+
+            "    </unique>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), null, new Integer(2) });
+        insertRow("roundtrip", new Object[] { new Integer(1), new Double(2.0), new Integer(3) });
 
     	alterDatabase(model2Xml);
 
@@ -1351,236 +1302,291 @@
 
         List beans = getRows("roundtrip");
 
-        assertEquals((Object)null, beans.get(0), "avalue1");
-        assertEquals(new Integer(2), beans.get(0), "avalue2");
+        assertEquals(new Double(2.0), beans.get(0), "avalue1");
+        assertEquals(new Integer(3), beans.get(0), "avalue2");
     }
 
     /**
-     * Tests the addition of an unique index.
+     * Tests the addition of a foreign key.
      */
-    public void testAddUniqueIndex()
-    {
-        if (!getPlatformInfo().isIndicesSupported())
-        {
-            return;
-        }
-
+    public void testAddFK()
+    {
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='INTEGER'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
+            "    <column name='pk' type='VARCHAR' size='32' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue' type='INTEGER' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='INTEGER'/>\n"+
-            "    <unique name='test'>\n"+
-            "      <unique-column name='avalue'/>\n"+
-            "    </unique>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
+            "    <column name='pk' type='VARCHAR' size='32' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue' type='INTEGER' required='true'/>\n"+
+            "    <foreign-key name='test' foreignTable='roundtrip1'>\n"+
+            "      <reference local='avalue' foreign='pk'/>\n"+
+            "    </foreign-key>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) });
+        insertRow("roundtrip1", new Object[] { new Integer(1) });
+        insertRow("roundtrip2", new Object[] { "2", new Integer(1) });
 
     	alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
-        List beans = getRows("roundtrip");
+        List beans1 = getRows("roundtrip1");
+        List beans2 = getRows("roundtrip2");
 
-        assertEquals(new Integer(2), beans.get(0), "avalue");
+        assertEquals(new Integer(1), beans1.get(0), "pk");
+        assertEquals((Object)"2", beans2.get(0), "pk");
+        assertEquals(new Integer(1), beans2.get(0), "avalue");
     }
 
     /**
-     * Tests the removal of an unique index.
+     * Tests the removal of a foreign key.
      */
-    public void testDropUniqueIndex()
+    public void testDropFK()
     {
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk1' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk2' type='DOUBLE' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='DOUBLE'/>\n"+
-            "    <column name='avalue2' type='VARCHAR' size='50'/>\n"+
-            "    <unique name='test_index'>\n"+
-            "      <unique-column name='avalue2'/>\n"+
-            "      <unique-column name='avalue1'/>\n"+
-            "    </unique>\n"+
+            "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
+            "    <foreign-key foreignTable='roundtrip1'>\n"+
+            "      <reference local='avalue2' foreign='pk1'/>\n"+
+            "      <reference local='avalue1' foreign='pk2'/>\n"+
+            "    </foreign-key>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk1' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk2' type='DOUBLE' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='DOUBLE'/>\n"+
-            "    <column name='avalue2' type='VARCHAR' size='50'/>\n"+
+            "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), new Double(2.0), "test" });
+        insertRow("roundtrip1", new Object[] { new Integer(1), new Double(2.0) });
+        insertRow("roundtrip2", new Object[] { new Integer(2), new Double(2.0), new Integer(1) });
 
     	alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
-        List beans = getRows("roundtrip");
+        List beans1 = getRows("roundtrip1");
+        List beans2 = getRows("roundtrip2");
 
-        assertEquals(new Double(2.0), beans.get(0), "avalue1");
-        assertEquals((Object)"test", beans.get(0), "avalue2");
+        assertEquals(new Integer(1), beans1.get(0), "pk1");
+        assertEquals(new Double(2.0), beans1.get(0), "pk2");
+        assertEquals(new Integer(2), beans2.get(0), "pk");
+        assertEquals(new Double(2.0), beans2.get(0), "avalue1");
+        assertEquals(new Integer(1), beans2.get(0), "avalue2");
     }
 
     /**
-     * Tests the addition of a column to an index.
+     * Tests removing a foreign key and an index that has the same name and same column.
      */
-    public void testAddColumnToIndex()
+    public void testDropFKAndCorrespondingIndex()
     {
-        if (!getPlatformInfo().isIndicesSupported())
-        {
-            return;
-        }
-
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk1' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk2' type='DOUBLE' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='DOUBLE'/>\n"+
-            "    <column name='avalue2' type='VARCHAR' size='40'/>\n"+
-            "    <index name='test_index'>\n"+
+            "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
+            "    <index name='test'>\n"+
+            "      <index-column name='avalue2'/>\n"+
             "      <index-column name='avalue1'/>\n"+
             "    </index>\n"+
+            "    <foreign-key name='test' foreignTable='roundtrip1'>\n"+
+            "      <reference local='avalue2' foreign='pk1'/>\n"+
+            "      <reference local='avalue1' foreign='pk2'/>\n"+
+            "    </foreign-key>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk1' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk2' type='DOUBLE' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='DOUBLE'/>\n"+
-            "    <column name='avalue2' type='VARCHAR' size='40'/>\n"+
-            "    <index name='test_index'>\n"+
-            "      <index-column name='avalue1'/>\n"+
-            "      <index-column name='avalue2'/>\n"+
-            "    </index>\n"+
+            "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), new Double(2.0), "test" });
+        insertRow("roundtrip1", new Object[] { new Integer(1), new Double(2.0) });
+        insertRow("roundtrip2", new Object[] { new Integer(2), new Double(2.0), new Integer(1) });
 
-    	alterDatabase(model2Xml);
+        alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
-        List beans = getRows("roundtrip");
+        List beans1 = getRows("roundtrip1");
+        List beans2 = getRows("roundtrip2");
 
-        assertEquals(new Double(2.0), beans.get(0), "avalue1");
-        assertEquals((Object)"test", beans.get(0), "avalue2");
+        assertEquals(new Integer(1), beans1.get(0), "pk1");
+        assertEquals(new Double(2.0), beans1.get(0), "pk2");
+        assertEquals(new Integer(2), beans2.get(0), "pk");
+        assertEquals(new Double(2.0), beans2.get(0), "avalue1");
+        assertEquals(new Integer(1), beans2.get(0), "avalue2");
     }
 
     /**
-     * Tests the removal of a column from an index.
+     * Tests removing a foreign key but not the index that has the same name and same column.
      */
-    public void testRemoveColumnFromUniqueIndex()
+    public void testDropFKButNotCorrespondingIndex()
     {
-        if (!getPlatformInfo().isIndicesSupported())
-        {
-            return;
-        }
-
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk1' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk2' type='DOUBLE' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "  <table name='roundtrip2'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='DOUBLE'/>\n"+
-            "    <column name='avalue2' type='INTEGER'/>\n"+
-            "    <unique name='test_index'>\n"+
-            "      <unique-column name='avalue1'/>\n"+
-            "      <unique-column name='avalue2'/>\n"+
-            "    </unique>\n"+
+            "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
+            "    <index name='test'>\n"+
+            "      <index-column name='avalue2'/>\n"+
+            "      <index-column name='avalue1'/>\n"+
+            "    </index>\n"+
+            "    <foreign-key name='test' foreignTable='roundtrip1'>\n"+
+            "      <reference local='avalue2' foreign='pk1'/>\n"+
+            "      <reference local='avalue1' foreign='pk2'/>\n"+
+            "    </foreign-key>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
-            "  <table name='roundtrip'>\n"+
+            "  <table name='roundtrip1'>\n"+
+            "    <column name='pk1' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk2' type='DOUBLE' primaryKey='true' required='true'/>\n"+
+            "  </table>\n"+
+            "    <index name='test'>\n"+
+            "      <index-column name='avalue2'/>\n"+
+            "      <index-column name='avalue1'/>\n"+
+            "    </index>\n"+
+            "  <table name='roundtrip2'>\n"+
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue1' type='DOUBLE'/>\n"+
-            "    <column name='avalue2' type='INTEGER'/>\n"+
-            "    <unique name='test_index'>\n"+
-            "      <unique-column name='avalue1'/>\n"+
-            "    </unique>\n"+
+            "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip", new Object[] { new Integer(1), new Double(2.0), new Integer(3) });
+        insertRow("roundtrip1", new Object[] { new Integer(1), new Double(2.0) });
+        insertRow("roundtrip2", new Object[] { new Integer(2), new Double(2.0), new Integer(1) });
 
-    	alterDatabase(model2Xml);
+        alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
-        List beans = getRows("roundtrip");
+        List beans1 = getRows("roundtrip1");
+        List beans2 = getRows("roundtrip2");
 
-        assertEquals(new Double(2.0), beans.get(0), "avalue1");
-        assertEquals(new Integer(3), beans.get(0), "avalue2");
+        assertEquals(new Integer(1), beans1.get(0), "pk1");
+        assertEquals(new Double(2.0), beans1.get(0), "pk2");
+        assertEquals(new Integer(2), beans2.get(0), "pk");
+        assertEquals(new Double(2.0), beans2.get(0), "avalue1");
+        assertEquals(new Integer(1), beans2.get(0), "avalue2");
     }
 
     /**
-     * Tests the addition of a foreign key.
+     * Tests removing a foreign key and an index that has the same name but different columns.
      */
-    public void testAddFK()
+    public void testDropFKAndDifferentIndexWithSameName()
     {
+        // MySql/InnoDB doesn't allow the creation of a foreign key and index with the same name
+        if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            return;
+        }
+
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip1'>\n"+
-            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk1' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk2' type='DOUBLE' primaryKey='true' required='true'/>\n"+
             "  </table>\n"+
             "  <table name='roundtrip2'>\n"+
-            "    <column name='pk' type='VARCHAR' size='32' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='INTEGER' required='true'/>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
+            "    <index name='test'>\n"+
+            "      <index-column name='avalue1'/>\n"+
+            "    </index>\n"+
+            "    <foreign-key name='test' foreignTable='roundtrip1'>\n"+
+            "      <reference local='avalue2' foreign='pk1'/>\n"+
+            "      <reference local='avalue1' foreign='pk2'/>\n"+
+            "    </foreign-key>\n"+
             "  </table>\n"+
             "</database>";
         final String model2Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
             "  <table name='roundtrip1'>\n"+
-            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk1' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='pk2' type='DOUBLE' primaryKey='true' required='true'/>\n"+
             "  </table>\n"+
             "  <table name='roundtrip2'>\n"+
-            "    <column name='pk' type='VARCHAR' size='32' primaryKey='true' required='true'/>\n"+
-            "    <column name='avalue' type='INTEGER' required='true'/>\n"+
-            "    <foreign-key name='test' foreignTable='roundtrip1'>\n"+
-            "      <reference local='avalue' foreign='pk'/>\n"+
-            "    </foreign-key>\n"+
+            "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
+            "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
+            "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
             "  </table>\n"+
             "</database>";
 
         createDatabase(model1Xml);
 
-        insertRow("roundtrip1", new Object[] { new Integer(1) });
-        insertRow("roundtrip2", new Object[] { "2", new Integer(1) });
+        insertRow("roundtrip1", new Object[] { new Integer(1), new Double(2.0) });
+        insertRow("roundtrip2", new Object[] { new Integer(2), new Double(2.0), new Integer(1) });
 
-    	alterDatabase(model2Xml);
+        alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
@@ -1588,16 +1594,25 @@
         List beans1 = getRows("roundtrip1");
         List beans2 = getRows("roundtrip2");
 
-        assertEquals(new Integer(1), beans1.get(0), "pk");
-        assertEquals((Object)"2", beans2.get(0), "pk");
-        assertEquals(new Integer(1), beans2.get(0), "avalue");
+        assertEquals(new Integer(1), beans1.get(0), "pk1");
+        assertEquals(new Double(2.0), beans1.get(0), "pk2");
+        assertEquals(new Integer(2), beans2.get(0), "pk");
+        assertEquals(new Double(2.0), beans2.get(0), "avalue1");
+        assertEquals(new Integer(1), beans2.get(0), "avalue2");
     }
 
     /**
-     * Tests the removal of a foreign key.
+     * Tests removing a foreign key but not the index that has the same name but different columns.
      */
-    public void testDropFK()
+    public void testDropFKButNotDifferentIndexWithSameName()
     {
+        // MySql/InnoDB doesn't allow the creation of a foreign key and index with the same name
+        if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            return;
+        }
+
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
@@ -1609,7 +1624,10 @@
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
             "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
             "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
-            "    <foreign-key foreignTable='roundtrip1'>\n"+
+            "    <index name='test'>\n"+
+            "      <index-column name='avalue1'/>\n"+
+            "    </index>\n"+
+            "    <foreign-key name='test' foreignTable='roundtrip1'>\n"+
             "      <reference local='avalue2' foreign='pk1'/>\n"+
             "      <reference local='avalue1' foreign='pk2'/>\n"+
             "    </foreign-key>\n"+
@@ -1626,6 +1644,9 @@
             "    <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
             "    <column name='avalue1' type='DOUBLE' required='true'/>\n"+
             "    <column name='avalue2' type='INTEGER' required='true'/>\n"+
+            "    <index name='test'>\n"+
+            "      <index-column name='avalue1'/>\n"+
+            "    </index>\n"+
             "  </table>\n"+
             "</database>";
 
@@ -1634,7 +1655,7 @@
         insertRow("roundtrip1", new Object[] { new Integer(1), new Double(2.0) });
         insertRow("roundtrip2", new Object[] { new Integer(2), new Double(2.0), new Integer(1) });
 
-    	alterDatabase(model2Xml);
+        alterDatabase(model2Xml);
 
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
@@ -2194,6 +2215,24 @@
         assertEquals(getAdjustedModel(),
                      readModelFromDatabase("roundtriptest"));
 
-        assertTrue(getRows("roundtrip").isEmpty());
+        List beans = getRows("roundtrip");
+
+        if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            // McKoi can actually handle this, though interestingly it will result in a null value for the pk
+            assertEquals((Object)null,   beans.get(0), "pk");
+            assertEquals((Object)"test", beans.get(0), "avalue");
+        }
+        else if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+                 MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            // Same with MySql except it uses the default value for the datatype
+            assertEquals(new Integer(0), beans.get(0), "pk");
+            assertEquals((Object)"test", beans.get(0), "avalue");
+        }
+        else
+        {
+            assertTrue(beans.isEmpty());
+        }
     }
 }



Mime
View raw message