Return-Path: Delivered-To: apmail-db-ddlutils-dev-archive@www.apache.org Received: (qmail 77136 invoked from network); 10 Dec 2007 08:24:14 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Dec 2007 08:24:14 -0000 Received: (qmail 97423 invoked by uid 500); 10 Dec 2007 08:24:02 -0000 Delivered-To: apmail-db-ddlutils-dev-archive@db.apache.org Received: (qmail 97405 invoked by uid 500); 10 Dec 2007 08:24:02 -0000 Mailing-List: contact ddlutils-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ddlutils-dev@db.apache.org Delivered-To: mailing list ddlutils-dev@db.apache.org Received: (qmail 97394 invoked by uid 500); 10 Dec 2007 08:24:02 -0000 Delivered-To: apmail-db-ddlutils-commits@db.apache.org Received: (qmail 97391 invoked by uid 99); 10 Dec 2007 08:24:02 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Dec 2007 00:24:02 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 10 Dec 2007 08:23:59 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AA0501A984A; Mon, 10 Dec 2007 00:23:36 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r602807 [12/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 -0000 To: ddlutils-commits@db.apache.org From: tomdz@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071210082336.AA0501A984A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAddColumn.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAddColumn.java?rev=602807&view=auto ============================================================================== --- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAddColumn.java (added) +++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAddColumn.java Mon Dec 10 00:20:47 2007 @@ -0,0 +1,3416 @@ +package org.apache.ddlutils.io; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.math.BigDecimal; +import java.util.List; + +import junit.framework.Test; + +import org.apache.commons.beanutils.DynaBean; +import org.apache.ddlutils.platform.db2.Db2Platform; +import org.apache.ddlutils.platform.db2.Db2v8Platform; +import org.apache.ddlutils.platform.hsqldb.HsqlDbPlatform; +import org.apache.ddlutils.platform.interbase.InterbasePlatform; +import org.apache.ddlutils.platform.maxdb.MaxDbPlatform; +import org.apache.ddlutils.platform.mysql.MySql50Platform; +import org.apache.ddlutils.platform.mysql.MySqlPlatform; +import org.apache.ddlutils.platform.sapdb.SapDbPlatform; +import org.apache.ddlutils.platform.sybase.SybasePlatform; + +/** + * Tests database alterations that add columns. + * + * @version $Revision: $ + */ +public class TestAddColumn extends RoundtripTestBase +{ + /** + * Parameterized test case pattern. + * + * @return The tests + */ + public static Test suite() throws Exception + { + return getTests(TestAddColumn.class); + } + + /** + * Tests the addition of a column. + */ + public void testAddColumn() + { + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals((Object)null, beans.get(0), "avalue"); + } + + /** + * Tests the addition of an auto-increment column. + */ + public void testAddAutoIncrementColumn() + { + 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 = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml; + + if (isSybase) + { + model2Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + } + else + { + model2Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + } + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + 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)); + } + } + + /** + * Tests the addition of another auto-increment column. + */ + public void testAddSecondAutoIncrementColumn() + { + if (!getPlatformInfo().isNonPKIdentityColumnsSupported() || + SybasePlatform.DATABASENAME.equals(getPlatform().getName()) || + MaxDbPlatform.DATABASENAME.equals(getPlatform().getName()) || + SapDbPlatform.DATABASENAME.equals(getPlatform().getName())) + { + // Sybase and MaxDb/SapDb does not support more than one identity column per table + return; + } + + final String model1Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + Object avalue1 = ((DynaBean)beans.get(0)).get("avalue1"); + Object avalue2 = ((DynaBean)beans.get(0)).get("avalue2"); + + assertTrue((avalue1 == null) || new Integer(1).equals(avalue1)); + assertTrue((avalue2 == null) || new Integer(1).equals(avalue2)); + } + + /** + * Tests the addition of a column that is set to NOT NULL. + */ + public void testAddRequiredColumn() + { + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals(new BigDecimal(2), 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. + */ + public void testAddColumnWithDefault() + { + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + 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 directly (in which case it might still be NULL) + Object avalue = ((DynaBean)beans.get(0)).get("avalue"); + + assertTrue((avalue == null) || new Double(2).equals(avalue)); + } + + /** + * Tests the addition of a required auto-increment column. + */ + public void testAddRequiredAutoIncrementColumn() + { + 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 = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml; + + if (isSybase) + { + model2Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + } + else + { + model2Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + } + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + 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)); + } + } + + /** + * 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. + */ + public void testAddRequiredColumnWithDefault() + { + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + 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 directly (in which case it might still be NULL) + Object avalue = ((DynaBean)beans.get(0)).get("avalue"); + + assertTrue((avalue == null) || "sometext".equals(avalue)); + } + + /** + * Tests the addition of several columns at the end of the table. + */ + public void testAddMultipleColumns() + { + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), "test", new Integer(3) }); + + 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"); + } + + /** + * Tests the addition of a primary key and a column. + */ + public void testAddPKAndColumn() + { + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + // MySql uses an empty string to initialize the new pk column + assertEquals((Object)"", beans.get(0), "pk"); + assertEquals(new Integer(1), beans.get(0), "avalue"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of a primary key and an autoincrement column. + */ + public void testAddPKAndAutoIncrementColumn() + { + // we need special catering for Sybase which does not support identity for INTEGER columns + boolean isSybase = SybasePlatform.DATABASENAME.equals(getPlatform().getName()); + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml; + + if (isSybase) + { + model2Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + } + else + { + model2Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + } + + 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), "avalue"); + if (isSybase) + { + assertEquals(new BigDecimal(1), beans.get(0), "pk"); + } + else + { + assertEquals(new Integer(1), beans.get(0), "pk"); + } + } + + /** + * Tests the addition of a primary key and multiple columns. + */ + public void testAddPKAndMultipleColumns() + { + if (Db2Platform.DATABASENAME.equals(getPlatform().getName()) || + Db2v8Platform.DATABASENAME.equals(getPlatform().getName()) || + SybasePlatform.DATABASENAME.equals(getPlatform().getName()) || + InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) { + // Db2, Sybase, Interbase require that all primary key columns be required, but they don't make them so automatically + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(0), beans.get(0), "pk1"); + assertEquals((Object)"", beans.get(0), "pk2"); + assertEquals(new Double(2.0), beans.get(0), "pk3"); + assertEquals(new Integer(1), beans.get(0), "avalue"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of a primary key and multiple required columns. + */ + public void testAddPKAndMultipleRequiredColumns() + { + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(0), beans.get(0), "pk1"); + assertEquals((Object)"", beans.get(0), "pk2"); + assertEquals(new Double(2.0), beans.get(0), "pk3"); + assertEquals(new Integer(1), beans.get(0), "avalue"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of a primary key and multiple columns. + */ + public void testAddPKAndMultipleColumnsInclAutoIncrement() + { + if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName())) + { + // the IDENTITY column has to be the only PK column + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + assertTrue(getRows("roundtrip").isEmpty()); + } + + /** + * Tests the addition of a column to a primary key. + */ + public void testAddColumnIntoPK() + { + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(1), beans.get(0), "pk1"); + assertEquals(new Integer(0), beans.get(0), "pk2"); + assertEquals(new Integer(2), beans.get(0), "avalue"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of an autoincrement column into the primary key. + */ + public void testAddAutoIncrementColumnIntoPK() + { + if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) + { + // the IDENTITY column has to be the only PK column + 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 = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml; + + if (isSybase) + { + model2Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + } + else + { + model2Xml = "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + } + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(-1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals(new Integer(-1), ((DynaBean)beans.get(0)).get("pk1")); + assertEquals(new Integer(2), ((DynaBean)beans.get(0)).get("avalue")); + if (isSybase) + { + assertEquals(new BigDecimal(1), beans.get(0), "pk2"); + } + else + { + assertEquals(new Integer(1), beans.get(0), "pk2"); + } + } + + /** + * Tests the addition of multiple columns into the primary key. + */ + public void testAddMultipleColumnsIntoPK() + { + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(1), beans.get(0), "pk1"); + assertEquals((Object)"", beans.get(0), "pk2"); + assertEquals(new Double(0.0), beans.get(0), "pk3"); + assertEquals((Object)null, beans.get(0), "avalue"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of multiple columns into the primary key which has an auto increment column. + */ + public void testAddMultipleColumnsIntoPKWithAutoIncrement() + { + if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) + { + // the IDENTITY column has to be the only PK column + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + assertTrue(getRows("roundtrip").isEmpty()); + } + + /** + * Tests the addition of multiple columns including one with auto increment into the primary key. + */ + public void testAddMultipleColumnsInclAutoIncrementIntoPK() + { + if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName())) + { + // the IDENTITY column has to be the only PK column + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), "text" }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + assertTrue(getRows("roundtrip").isEmpty()); + } + + /** + * Tests the addition of a non-unique index and a column. + */ + public void testAddNonUniqueIndexAndColumn() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals((Object)null, beans.get(0), "avalue"); + } + + /** + * Tests the addition of a non-unique index and an auto increment column. + */ + public void testAddNonUniqueIndexAndAutoIncrementColumn() + { + if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + Object avalue = ((DynaBean)beans.get(0)).get("avalue"); + + assertTrue((avalue == null) || new Integer(1).equals(avalue)); + } + + /** + * Tests the addition of a non-unique index and a required column. + */ + public void testAddNonUniqueIndexAndRequiredColumn() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new BigDecimal(0), beans.get(0), "avalue"); + } + else if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) + { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals((Object)null, beans.get(0), "avalue"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of a non-unique index and a column with a default value. + */ + public void testAddNonUniqueIndexAndColumnWithDefault() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + Object avalue = ((DynaBean)beans.get(0)).get("avalue"); + + assertTrue((avalue == null) || new Double(2).equals(avalue)); + } + + /** + * Tests the addition of a non-unique index and a required auto increment column. + */ + public void testAddNonUniqueIndexAndRequiredAutoIncrementColumn() + { + if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) + { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals((Object)null, beans.get(0), "avalue"); + } + else + { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(1), beans.get(0), "avalue"); + } + } + + /** + * Tests the addition of a non-unique index and a required column with a default value. + */ + public void testAddNonUniqueIndexAndRequiredColumnWithDefault() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals((Object)"sometext", beans.get(0), "avalue"); + } + + /** + * Tests the addition of a non-unique index and several columns. + */ + public void testAddNonUniqueIndexAndMultipleColumns() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(1), beans.get(0), "avalue1"); + assertEquals((Object)"", beans.get(0), "avalue2"); + } + else if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) + { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals((Object)null, beans.get(0), "avalue1"); + assertEquals((Object)null, beans.get(0), "avalue2"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + + /** + * Tests the addition of an unique index and a column. + */ + public void testAddUniqueIndexAndColumn() + { + if (!getPlatformInfo().isIndicesSupported() || + InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals((Object)null, beans.get(0), "avalue"); + } + + /** + * Tests the addition of an unique index and an auto increment column. + */ + public void testAddUniqueIndexAndAutoIncrementColumn() + { + if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + Object avalue = ((DynaBean)beans.get(0)).get("avalue"); + + assertTrue((avalue == null) || new Integer(1).equals(avalue)); + } + + /** + * Tests the addition of an unique index and a required column. + */ + public void testAddUniqueIndexAndRequiredColumn() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new BigDecimal(0), beans.get(0), "avalue"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of an unique index and a column with a default value. + */ + public void testAddUniqueIndexAndColumnWithDefault() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + Object avalue = ((DynaBean)beans.get(0)).get("avalue"); + + assertTrue((avalue == null) || new Double(2).equals(avalue)); + } + + /** + * Tests the addition of an unique index and a required auto increment column. + */ + public void testAddUniqueIndexAndRequiredAutoIncrementColumn() + { + if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + 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), "avalue"); + } + + /** + * Tests the addition of an unique index and a required column with a default value. + */ + public void testAddUniqueIndexAndRequiredColumnWithDefault() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals((Object)"sometext", beans.get(0), "avalue"); + } + + /** + * Tests the addition of an unique index and several columns. + */ + public void testAddUniqueIndexAndMultipleColumns() + { + if (!getPlatformInfo().isIndicesSupported() || + InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(1), beans.get(0), "avalue1"); + assertEquals((Object)"", beans.get(0), "avalue2"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of an unique index and several required columns. + */ + public void testAddUniqueIndexAndMultipleRequiredColumns() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(1), beans.get(0), "avalue1"); + assertEquals((Object)"", beans.get(0), "avalue2"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of a column into a non-unique index. + */ + public void testAddColumnIntoNonUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals((Object)null, beans.get(0), "avalue2"); + } + + /** + * Tests the addition of an auto increment column into a non-unique index. + */ + public void testAddAutoIncrementColumnIntoNonUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + Object avalue2 = ((DynaBean)beans.get(0)).get("avalue2"); + + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertTrue((avalue2 == null) || new Integer(1).equals(avalue2)); + } + + /** + * Tests the addition of a required column into a non-unique index. + */ + public void testAddRequiredColumnIntoNonUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals(new BigDecimal(0), beans.get(0), "avalue2"); + } + else if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) + { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals((Object)null, beans.get(0), "avalue2"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of a column with a default value into a non-unique index. + */ + public void testAddColumnWithDefaultIntoNonUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + Object avalue2 = ((DynaBean)beans.get(0)).get("avalue2"); + + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertTrue((avalue2 == null) || new Double(2).equals(avalue2)); + } + + /** + * Tests the addition of a required auto increment column into a non-unique index. + */ + public void testAddRequiredAutoIncrementColumnIntoNonUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) + { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals((Object)null, beans.get(0), "avalue2"); + } + else + { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals(new Integer(1), beans.get(0), "avalue2"); + } + } + + /** + * Tests the addition of a required column with a default value into a non-unique index. + */ + public void testAddRequiredColumnWithDefaultIntoNonUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals((Object)"sometext", beans.get(0), "avalue2"); + } + + /** + * Tests the addition of multiple columns into a non-unique index. + */ + public void testAddMultipleColumnsIntoNonUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals(new Integer(3), beans.get(0), "avalue2"); + assertEquals(new Double(0.0), beans.get(0), "avalue3"); + } + else if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) + { + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals((Object)null, beans.get(0), "avalue2"); + assertEquals((Object)null, beans.get(0), "avalue3"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of a column into an unique index. + */ + public void testAddColumnIntoUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported() || + InterbasePlatform.DATABASENAME.equals(getPlatform().getName())) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals((Object)null, beans.get(0), "avalue2"); + } + + /** + * Tests the addition of an auto increment column into an unique index. + */ + public void testAddAutoIncrementColumnIntoUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported() || + !getPlatformInfo().isNonPKIdentityColumnsSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + Object avalue2 = ((DynaBean)beans.get(0)).get("avalue2"); + + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertTrue((avalue2 == null) || new Integer(1).equals(avalue2)); + } + + /** + * Tests the addition of a required column into an unique index. + */ + public void testAddRequiredColumnIntoUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + + createDatabase(model1Xml); + + insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) }); + + alterDatabase(model2Xml); + + assertEquals(getAdjustedModel(), + readModelFromDatabase("roundtriptest")); + + List beans = getRows("roundtrip"); + + if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) || + MySql50Platform.DATABASENAME.equals(getPlatform().getName())) { + // MySql uses the default value for the column's type to initialize + // the new column for existing rows + assertEquals(new Integer(1), beans.get(0), "pk"); + assertEquals(new Integer(2), beans.get(0), "avalue1"); + assertEquals(new BigDecimal(0), beans.get(0), "avalue2"); + } + else { + assertTrue(beans.isEmpty()); + } + } + + /** + * Tests the addition of a column with a default value into an unique index. + */ + public void testAddColumnWithDefaultIntoUniqueIndex() + { + if (!getPlatformInfo().isIndicesSupported()) + { + return; + } + + final String model1Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + " \n"+ + "
\n"+ + "
"; + final String model2Xml = + "\n"+ + "\n"+ + " \n"+ + " \n"+ [... 1192 lines stripped ...]