You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ddlutils-dev@db.apache.org by to...@apache.org on 2007/12/13 07:19:17 UTC
svn commit: r603834 [1/2] - in /db/ddlutils/trunk/src:
java/org/apache/ddlutils/ java/org/apache/ddlutils/platform/
java/org/apache/ddlutils/platform/db2/
java/org/apache/ddlutils/platform/hsqldb/
java/org/apache/ddlutils/platform/interbase/ java/org/a...
Author: tomdz
Date: Wed Dec 12 22:19:16 2007
New Revision: 603834
URL: http://svn.apache.org/viewvc?rev=603834&view=rev
Log:
Additional fixes and test tweaks
Added:
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestChangeColumn.java
Modified:
db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Platform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlPlatform.java
db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAddColumn.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestDropColumn.java
db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestInsertColumn.java
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java Wed Dec 12 22:19:16 2007
@@ -49,7 +49,13 @@
/** Whether primary key constraints are embedded inside the create table statement. */
private boolean _primaryKeyEmbedded = true;
-
+
+ /** Whether primary key columns have to be required, too. */
+ private boolean _primaryKeyColumnsHaveToBeRequired = false;
+
+ /** Whether mixed identity and non-identity columns in a primary key is supported. */
+ private boolean _mixingIdentityAndNormalPrimaryKeyColumnsSupported = true;
+
/** Whether foreign key constraints are embedded inside the create table statement. */
private boolean _foreignKeysEmbedded = false;
@@ -63,7 +69,7 @@
private boolean _indicesEmbedded = false;
/** Whether identity specification is supported for non-primary key columns. */
- private boolean _nonPKIdentityColumnsSupported = true;
+ private boolean _nonPrimaryKeyIdentityColumnsSupported = true;
/** Whether multiple identity columns in the same table are supported. */
private boolean _multipleIdentityColumnsSupported = true;
@@ -253,6 +259,47 @@
}
/**
+ * Determines whether the primary key constraints have to be required, as well.
+ *
+ * @return <code>true</code> if pk constraints have to be required
+ */
+ public boolean isPrimaryKeyColumnsHaveToBeRequired()
+ {
+ return _primaryKeyColumnsHaveToBeRequired;
+ }
+
+ /**
+ * Specifies whether the primary key constraints have to be required, as well.
+ *
+ * @param primaryKeyColumnsHaveToBeRequired Whether pk constraints need to be required
+ */
+ public void setPrimaryKeyColumnsHaveToBeRequired(boolean primaryKeyColumnsHaveToBeRequired)
+ {
+ _primaryKeyColumnsHaveToBeRequired = primaryKeyColumnsHaveToBeRequired;
+ }
+
+ /**
+ * Determines whether primary key can contain identity and non-identity columns at the same time.
+ *
+ * @return <code>true</code> if idenity and non-identity columns can be mixed in the pk
+ */
+ public boolean isMixingIdentityAndNormalPrimaryKeyColumnsSupported()
+ {
+ return _mixingIdentityAndNormalPrimaryKeyColumnsSupported;
+ }
+
+ /**
+ * Specifies whether primary key can contain identity and non-identity columns at the same time.
+ *
+ * @param mixingIdentityAndNormalPrimaryKeyColumnsSupported Whether idenity and non-identity columns
+ * can be mixed in the pk
+ */
+ public void setMixingIdentityAndNormalPrimaryKeyColumnsSupported(boolean mixingIdentityAndNormalPrimaryKeyColumnsSupported)
+ {
+ _mixingIdentityAndNormalPrimaryKeyColumnsSupported = mixingIdentityAndNormalPrimaryKeyColumnsSupported;
+ }
+
+ /**
* Determines whether foreign key constraints are embedded in the create
* table clause or as seperate alter table statements. Per default,
* foreign keys are external.
@@ -342,9 +389,9 @@
*
* @return <code>true</code> if normal non-PK columns can be auto-incrementing
*/
- public boolean isNonPKIdentityColumnsSupported()
+ public boolean isNonPrimaryKeyIdentityColumnsSupported()
{
- return _nonPKIdentityColumnsSupported;
+ return _nonPrimaryKeyIdentityColumnsSupported;
}
/**
@@ -353,9 +400,9 @@
* @param supportingNonPKIdentityColumns <code>true</code> if normal non-PK columns can
* be auto-incrementing
*/
- public void setNonPKIdentityColumnsSupported(boolean supportingNonPKIdentityColumns)
+ public void setNonPrimaryKeyIdentityColumnsSupported(boolean supportingNonPKIdentityColumns)
{
- _nonPKIdentityColumnsSupported = supportingNonPKIdentityColumns;
+ _nonPrimaryKeyIdentityColumnsSupported = supportingNonPKIdentityColumns;
}
/**
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/SqlBuilder.java Wed Dec 12 22:19:16 2007
@@ -1361,7 +1361,7 @@
}
if (column.isAutoIncrement() && !getPlatformInfo().isDefaultValueUsedForIdentitySpec())
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported() && !column.isPrimaryKey())
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported() && !column.isPrimaryKey())
{
throw new ModelException("Column "+column.getName()+" in table "+table.getName()+" is auto-incrementing but not a primary key column, which is not supported by the platform");
}
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Platform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Platform.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Platform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2Platform.java Wed Dec 12 22:19:16 2007
@@ -73,6 +73,7 @@
info.setMaxIdentifierLength(18);
info.setIdentityColumnAutomaticallyRequired(true);
+ info.setPrimaryKeyColumnsHaveToBeRequired(true);
// the BINARY types are also handled by Db2Builder.getSqlType(Column)
info.addNativeTypeMapping(Types.ARRAY, "BLOB", Types.BLOB);
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/hsqldb/HsqlDbPlatform.java Wed Dec 12 22:19:16 2007
@@ -60,10 +60,11 @@
{
PlatformInfo info = getPlatformInfo();
- info.setNonPKIdentityColumnsSupported(false);
+ info.setNonPrimaryKeyIdentityColumnsSupported(false);
info.setIdentityOverrideAllowed(false);
info.setSystemForeignKeyIndicesAlwaysNonUnique(true);
info.setPrimaryKeyColumnAutomaticallyRequired(true);
+ info.setMixingIdentityAndNormalPrimaryKeyColumnsSupported(false);
info.addNativeTypeMapping(Types.ARRAY, "LONGVARBINARY", Types.LONGVARBINARY);
info.addNativeTypeMapping(Types.BLOB, "LONGVARBINARY", Types.LONGVARBINARY);
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/interbase/InterbasePlatform.java Wed Dec 12 22:19:16 2007
@@ -72,6 +72,7 @@
info.setCommentPrefix("/*");
info.setCommentSuffix("*/");
info.setSystemForeignKeyIndicesAlwaysNonUnique(true);
+ info.setPrimaryKeyColumnsHaveToBeRequired(true);
// BINARY and VARBINARY are also handled by the InterbaseBuilder.getSqlType method
info.addNativeTypeMapping(Types.ARRAY, "BLOB", Types.LONGVARBINARY);
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java Wed Dec 12 22:19:16 2007
@@ -66,7 +66,9 @@
info.setNullAsDefaultValueRequired(true);
info.setDefaultValuesForLongTypesSupported(false);
// see http://dev.mysql.com/doc/refman/4.1/en/example-auto-increment.html
- info.setNonPKIdentityColumnsSupported(false);
+ info.setNonPrimaryKeyIdentityColumnsSupported(false);
+ info.setMultipleIdentityColumnsSupported(false);
+ info.setMixingIdentityAndNormalPrimaryKeyColumnsSupported(false);
// MySql returns synthetic default values for pk columns
info.setSyntheticDefaultValueForRequiredReturned(true);
info.setPrimaryKeyColumnAutomaticallyRequired(true);
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlBuilder.java Wed Dec 12 22:19:16 2007
@@ -168,6 +168,18 @@
}
/**
+ * {@inheritDoc}
+ */
+ public void addColumn(Table table, Column newColumn) throws IOException
+ {
+ if (newColumn.isAutoIncrement())
+ {
+ createAutoIncrementSequence(table, newColumn);
+ }
+ super.addColumn(table, newColumn);
+ }
+
+ /**
* Writes the SQL to drop a column.
*
* @param table The table
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlModelReader.java Wed Dec 12 22:19:16 2007
@@ -62,7 +62,7 @@
if (table != null)
{
- // PostgreSQL also returns unique indics for non-pk auto-increment columns
+ // PostgreSQL also returns unique indexes for pk and non-pk auto-increment columns
// which are of the form "[table]_[column]_key"
HashMap uniquesByName = new HashMap();
@@ -78,7 +78,8 @@
for (int columnIdx = 0; columnIdx < table.getColumnCount(); columnIdx++)
{
Column column = table.getColumn(columnIdx);
- if (column.isAutoIncrement() && !column.isPrimaryKey())
+
+ if (column.isAutoIncrement())
{
String indexName = table.getName() + "_" + column.getName() + "_key";
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlPlatform.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/postgresql/PostgreSqlPlatform.java Wed Dec 12 22:19:16 2007
@@ -33,6 +33,7 @@
import org.apache.ddlutils.DatabaseOperationException;
import org.apache.ddlutils.PlatformInfo;
import org.apache.ddlutils.alteration.AddColumnChange;
+import org.apache.ddlutils.alteration.ModelComparator;
import org.apache.ddlutils.alteration.RemoveColumnChange;
import org.apache.ddlutils.alteration.TableChange;
import org.apache.ddlutils.alteration.TableDefinitionChangesPredicate;
@@ -65,6 +66,7 @@
{
PlatformInfo info = getPlatformInfo();
+ info.setPrimaryKeyColumnAutomaticallyRequired(true);
// this is the default length though it might be changed when building PostgreSQL
// in file src/include/postgres_ext.h
info.setMaxIdentifierLength(31);
@@ -249,6 +251,17 @@
{
super.setObject(statement, sqlIndex, dynaBean, property);
}
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ protected ModelComparator getModelComparator()
+ {
+ ModelComparator comparator = super.getModelComparator();
+
+ comparator.setCanDropPrimaryKeyColumns(false);
+ return comparator;
}
/**
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java Wed Dec 12 22:19:16 2007
@@ -82,6 +82,7 @@
info.setNullAsDefaultValueRequired(true);
info.setIdentityColumnAutomaticallyRequired(true);
info.setMultipleIdentityColumnsSupported(false);
+ info.setPrimaryKeyColumnsHaveToBeRequired(true);
info.setCommentPrefix("/*");
info.setCommentSuffix("*/");
Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java?rev=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/RunAllTests.java Wed Dec 12 22:19:16 2007
@@ -24,6 +24,7 @@
import org.apache.ddlutils.dynabean.TestDynaSqlQueries;
import org.apache.ddlutils.io.TestAddColumn;
import org.apache.ddlutils.io.TestAlteration;
+import org.apache.ddlutils.io.TestChangeColumn;
import org.apache.ddlutils.io.TestConstraints;
import org.apache.ddlutils.io.TestDataReaderAndWriter;
import org.apache.ddlutils.io.TestDatabaseIO;
@@ -129,6 +130,7 @@
suite.addTestSuite(TestConstraints.class);
suite.addTestSuite(TestAlteration.class);
suite.addTestSuite(TestAddColumn.class);
+ suite.addTestSuite(TestChangeColumn.class);
suite.addTestSuite(TestDropColumn.class);
suite.addTestSuite(TestMisc.class);
}
Modified: 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=603834&r1=603833&r2=603834&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAddColumn.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAddColumn.java Wed Dec 12 22:19:16 2007
@@ -25,11 +25,10 @@
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.firebird.FirebirdPlatform;
import org.apache.ddlutils.platform.hsqldb.HsqlDbPlatform;
import org.apache.ddlutils.platform.interbase.InterbasePlatform;
+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;
@@ -91,7 +90,7 @@
*/
public void testAddAutoIncrementColumn()
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -156,10 +155,9 @@
*/
public void testAddSecondAutoIncrementColumn()
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported() ||
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported() ||
!getPlatformInfo().isMultipleIdentityColumnsSupported())
{
- // Some databases do not support more than one identity column per table
return;
}
@@ -232,10 +230,7 @@
}
/**
- * 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 addition of a column with a default value.
*/
public void testAddColumnWithDefault()
{
@@ -264,11 +259,7 @@
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)
+ List beans = getRows("roundtrip");
Object avalue = ((DynaBean)beans.get(0)).get("avalue");
assertTrue((avalue == null) || new Double(2).equals(avalue));
@@ -279,7 +270,7 @@
*/
public void testAddRequiredAutoIncrementColumn()
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -340,10 +331,7 @@
}
/**
- * 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 addition of a column with a default value.
*/
public void testAddRequiredColumnWithDefault()
{
@@ -372,11 +360,7 @@
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)
+ List beans = getRows("roundtrip");
Object avalue = ((DynaBean)beans.get(0)).get("avalue");
assertTrue((avalue == null) || "sometext".equals(avalue));
@@ -417,18 +401,12 @@
assertEquals(getAdjustedModel(),
readModelFromDatabase("roundtriptest"));
- List beans = getRows("roundtrip");
+ List beans = getRows("roundtrip");
+ Object avalue3 = ((DynaBean)beans.get(0)).get("avalue3");
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");
}
@@ -471,6 +449,12 @@
assertEquals((Object)"", beans.get(0), "pk");
assertEquals(new Integer(1), beans.get(0), "avalue");
}
+ else if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+ {
+ // Mckoi uses null to initialize the new pk column
+ assertEquals((Object)null, beans.get(0), "pk");
+ assertEquals(new Integer(1), beans.get(0), "avalue");
+ }
else
{
assertTrue(beans.isEmpty());
@@ -545,12 +529,8 @@
*/
public void testAddPKAndMultipleColumns()
{
- if (Db2Platform.DATABASENAME.equals(getPlatform().getName()) ||
- Db2v8Platform.DATABASENAME.equals(getPlatform().getName()) ||
- SybasePlatform.DATABASENAME.equals(getPlatform().getName()) ||
- InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
+ if (getPlatformInfo().isPrimaryKeyColumnsHaveToBeRequired())
{
- // Db2, Sybase, Interbase require that all primary key columns be required, but they don't make them so automatically
return;
}
@@ -591,6 +571,13 @@
assertEquals(new Double(2.0), beans.get(0), "pk3");
assertEquals(new Integer(1), beans.get(0), "avalue");
}
+ else if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+ {
+ assertEquals((Object)null, beans.get(0), "pk1");
+ assertEquals((Object)null, 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());
@@ -639,6 +626,13 @@
assertEquals(new Double(2.0), beans.get(0), "pk3");
assertEquals(new Integer(1), beans.get(0), "avalue");
}
+ else if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+ {
+ assertEquals((Object)null, beans.get(0), "pk1");
+ assertEquals((Object)null, 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());
@@ -650,9 +644,8 @@
*/
public void testAddPKAndMultipleColumnsInclAutoIncrement()
{
- if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName()))
+ if (!getPlatformInfo().isMixingIdentityAndNormalPrimaryKeyColumnsSupported())
{
- // the IDENTITY column has to be the only PK column
return;
}
@@ -683,7 +676,19 @@
assertEquals(getAdjustedModel(),
readModelFromDatabase("roundtriptest"));
- assertTrue(getRows("roundtrip").isEmpty());
+ List beans = getRows("roundtrip");
+
+ if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+ {
+ assertEquals(new Integer(1), beans.get(0), "pk1");
+ assertEquals((Object)null, beans.get(0), "pk2");
+ assertEquals((Object)null, beans.get(0), "pk3");
+ assertEquals(new Integer(1), beans.get(0), "avalue");
+ }
+ else
+ {
+ assertTrue(beans.isEmpty());
+ }
}
/**
@@ -727,6 +732,12 @@
assertEquals(new Integer(0), beans.get(0), "pk2");
assertEquals(new Integer(2), beans.get(0), "avalue");
}
+ else if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+ {
+ assertEquals(new Integer(1), beans.get(0), "pk1");
+ assertEquals((Object)null, beans.get(0), "pk2");
+ assertEquals(new Integer(2), beans.get(0), "avalue");
+ }
else
{
assertTrue(beans.isEmpty());
@@ -738,11 +749,8 @@
*/
public void testAddAutoIncrementColumnIntoPK()
{
- if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName()) ||
- MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
- MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
+ if (!getPlatformInfo().isMixingIdentityAndNormalPrimaryKeyColumnsSupported())
{
- // the IDENTITY column has to be the only PK column
return;
}
@@ -847,6 +855,13 @@
assertEquals(new Double(0.0), beans.get(0), "pk3");
assertEquals((Object)null, beans.get(0), "avalue");
}
+ else if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+ {
+ assertEquals(new Integer(1), beans.get(0), "pk1");
+ assertEquals((Object)null, beans.get(0), "pk2");
+ assertEquals((Object)null, beans.get(0), "pk3");
+ assertEquals((Object)null, beans.get(0), "avalue");
+ }
else
{
assertTrue(beans.isEmpty());
@@ -858,11 +873,8 @@
*/
public void testAddMultipleColumnsIntoPKWithAutoIncrement()
{
- if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName()) ||
- MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
- MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
+ if (!getPlatformInfo().isMixingIdentityAndNormalPrimaryKeyColumnsSupported())
{
- // the IDENTITY column has to be the only PK column
return;
}
@@ -887,14 +899,26 @@
createDatabase(model1Xml);
- insertRow("roundtrip", new Object[] { new Integer(1) });
+ insertRow("roundtrip", new Object[] { null, new Integer(1) });
alterDatabase(model2Xml);
assertEquals(getAdjustedModel(),
readModelFromDatabase("roundtriptest"));
- assertTrue(getRows("roundtrip").isEmpty());
+ List beans = getRows("roundtrip");
+
+ if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+ {
+ assertEquals(new Integer(1), beans.get(0), "pk1");
+ assertEquals((Object)null, beans.get(0), "pk2");
+ assertEquals((Object)null, beans.get(0), "pk3");
+ assertEquals(new Integer(1), beans.get(0), "avalue");
+ }
+ else
+ {
+ assertTrue(beans.isEmpty());
+ }
}
/**
@@ -902,9 +926,8 @@
*/
public void testAddMultipleColumnsInclAutoIncrementIntoPK()
{
- if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName()))
+ if (!getPlatformInfo().isMixingIdentityAndNormalPrimaryKeyColumnsSupported())
{
- // the IDENTITY column has to be the only PK column
return;
}
@@ -936,7 +959,19 @@
assertEquals(getAdjustedModel(),
readModelFromDatabase("roundtriptest"));
- assertTrue(getRows("roundtrip").isEmpty());
+ List beans = getRows("roundtrip");
+
+ if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+ {
+ assertEquals(new Integer(1), beans.get(0), "pk1");
+ assertEquals((Object)"text", beans.get(0), "pk2");
+ assertEquals((Object)null, beans.get(0), "pk3");
+ assertEquals(new Integer(1), beans.get(0), "avalue");
+ }
+ else
+ {
+ assertTrue(beans.isEmpty());
+ }
}
/**
@@ -987,7 +1022,8 @@
*/
public void testAddNonUniqueIndexAndAutoIncrementColumn()
{
- if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isIndicesSupported() ||
+ !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -1133,7 +1169,8 @@
*/
public void testAddNonUniqueIndexAndRequiredAutoIncrementColumn()
{
- if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isIndicesSupported() ||
+ !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -1292,6 +1329,7 @@
*/
public void testAddUniqueIndexAndColumn()
{
+ // TODO
if (!getPlatformInfo().isIndicesSupported() ||
InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
{
@@ -1336,7 +1374,8 @@
*/
public void testAddUniqueIndexAndAutoIncrementColumn()
{
- if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isIndicesSupported() ||
+ !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -1481,7 +1520,8 @@
*/
public void testAddUniqueIndexAndRequiredAutoIncrementColumn()
{
- if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isIndicesSupported() ||
+ !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -1575,6 +1615,7 @@
*/
public void testAddUniqueIndexAndMultipleColumns()
{
+ // TODO
if (!getPlatformInfo().isIndicesSupported() ||
InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
{
@@ -1748,7 +1789,8 @@
*/
public void testAddAutoIncrementColumnIntoNonUniqueIndex()
{
- if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isIndicesSupported() ||
+ !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -1916,7 +1958,8 @@
*/
public void testAddRequiredAutoIncrementColumnIntoNonUniqueIndex()
{
- if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isIndicesSupported() ||
+ !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -2097,6 +2140,7 @@
*/
public void testAddColumnIntoUniqueIndex()
{
+ // TODO
if (!getPlatformInfo().isIndicesSupported() ||
InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
{
@@ -2149,7 +2193,7 @@
public void testAddAutoIncrementColumnIntoUniqueIndex()
{
if (!getPlatformInfo().isIndicesSupported() ||
- !getPlatformInfo().isNonPKIdentityColumnsSupported())
+ !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -2241,6 +2285,7 @@
List beans = getRows("roundtrip");
+ // TODO
if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
{
@@ -2318,7 +2363,8 @@
*/
public void testAddRequiredAutoIncrementColumnIntoUniqueIndex()
{
- if (!getPlatformInfo().isIndicesSupported() || !getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isIndicesSupported() ||
+ !getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -2426,6 +2472,7 @@
*/
public void testAddMultipleColumnsIntoUniqueIndex()
{
+ // TODO
if (!getPlatformInfo().isIndicesSupported() ||
InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
{
@@ -2613,7 +2660,7 @@
*/
public void testAddFKAndLocalAutoIncrementColumn()
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -2667,11 +2714,11 @@
*/
public void testAddFKAndLocalRequiredColumn()
{
+ // TODO
if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
{
// MySql does not allow adding a required column to a fk without a default value
- // or as an IDENTITY column
return;
}
@@ -2715,7 +2762,8 @@
assertEquals(new BigDecimal(1), beans1.get(0), "pk");
if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
- InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
+ InterbasePlatform.DATABASENAME.equals(getPlatform().getName()) ||
+ MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
{
assertEquals(new Integer(2), beans2.get(0), "pk");
assertEquals((Object)null, beans2.get(0), "avalue");
@@ -2780,7 +2828,7 @@
*/
public void testAddFKAndLocalRequiredAutoIncrementColumn()
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -2889,11 +2937,11 @@
*/
public void testAddFKAndMultipleLocalColumns()
{
+ // TODO
if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
{
// MySql does not allow adding a required column to a fk without a default value
- // or as an IDENTITY column
return;
}
@@ -2948,6 +2996,12 @@
assertEquals((Object)null, beans2.get(0), "avalue1");
assertEquals((Object)null, beans2.get(0), "avalue2");
}
+ else if (MckoiPlatform.DATABASENAME.equals(getPlatform().getName()))
+ {
+ assertEquals(new Integer(3), beans2.get(0), "pk");
+ assertEquals(new Integer(1), beans2.get(0), "avalue1");
+ assertEquals((Object)null, beans2.get(0), "avalue2");
+ }
else
{
assertTrue(beans2.isEmpty());
@@ -2999,7 +3053,7 @@
*/
public void testAddFKAndForeignAutoIncrementColumn()
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -3195,7 +3249,7 @@
*/
public void testAddAutoIncrementColumnIntoFK()
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -3358,7 +3412,7 @@
*/
public void testAddRequiredAutoIncrementColumnIntoFK()
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
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=603834&r1=603833&r2=603834&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 Wed Dec 12 22:19:16 2007
@@ -19,13 +19,11 @@
* under the License.
*/
-import java.math.BigDecimal;
import java.util.List;
import java.util.Properties;
import junit.framework.Test;
-import org.apache.commons.beanutils.DynaBean;
import org.apache.ddlutils.model.Database;
import org.apache.ddlutils.platform.firebird.FirebirdPlatform;
import org.apache.ddlutils.platform.mckoi.MckoiPlatform;
@@ -57,695 +55,6 @@
}
/**
- * Tests the alteration of a column datatype.
- */
- public void testChangeDatatype1()
- {
- 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='INTEGER' required='false'/>\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"+
- " <column name='avalue' type='DOUBLE' required='false'/>\n"+
- " </table>\n"+
- "</database>";
-
- createDatabase(model1Xml);
-
- insertRow("roundtrip", new Object[] { new Integer(1), new Integer(2) });
-
- alterDatabase(model2Xml);
-
- assertEquals(getAdjustedModel(),
- readModelFromDatabase("roundtriptest"));
-
- List beans = getRows("roundtrip");
-
- assertEquals(new Double(2.0), beans.get(0), "avalue");
- }
-
- /**
- * Tests the alteration of a column datatype.
- */
- public void testChangeDatatype2()
- {
- 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='SMALLINT' 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"+
- " <column name='avalue' type='VARCHAR' size='20' required='true'/>\n"+
- " </table>\n"+
- "</database>";
-
- createDatabase(model1Xml);
-
- insertRow("roundtrip", new Object[] { new Integer(1), new Short((short)2) });
-
- alterDatabase(model2Xml);
-
- assertEquals(getAdjustedModel(),
- readModelFromDatabase("roundtriptest"));
-
- List beans = getRows("roundtrip");
- DynaBean bean = (DynaBean)beans.get(0);
-
- // Some databases (e.g. DB2) pad the string for some reason, so we manually trim it
- if (bean.get("avalue") instanceof String)
- {
- bean.set("avalue", ((String)bean.get("avalue")).trim());
- }
- assertEquals((Object)"2", beans.get(0), "avalue");
- }
-
- /**
- * Tests the alteration of the datatypes of PK and FK columns.
- */
- public void testChangePKAndFKDatatypes()
- {
- 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"+
- " </table>\n"+
- " <table name='roundtrip2'>\n"+
- " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
- " <column name='fk' type='INTEGER' 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[] { new Integer(1) });
- insertRow("roundtrip2", new Object[] { new Integer(1), new Integer(1) });
-
- alterDatabase(model2Xml);
-
- assertEquals(getAdjustedModel(),
- readModelFromDatabase("roundtriptest"));
-
- List beans = getRows("roundtrip2");
- DynaBean bean = (DynaBean)beans.get(0);
-
- // Some databases (e.g. DB2) pad the string for some reason, so we manually trim it
- if (bean.get("fk") instanceof String)
- {
- bean.set("fk", ((String)bean.get("fk")).trim());
- }
- assertEquals((Object)"1", bean, "fk");
- }
-
- /**
- * 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.
- */
- public void testChangeDroppedPKAndFKDatatypes()
- {
- 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"+
- " </table>\n"+
- " <table name='roundtrip2'>\n"+
- " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
- " <column name='fk' type='INTEGER' 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' primaryKey='false' required='true'/>\n"+
- " </table>\n"+
- " <table name='roundtrip2'>\n"+
- " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
- " <column name='fk' type='VARCHAR' required='false'/>\n"+
- " </table>\n"+
- "</database>";
-
- createDatabase(model1Xml);
-
- insertRow("roundtrip1", new Object[] { new Integer(1) });
- insertRow("roundtrip2", new Object[] { new Integer(1), new Integer(1) });
-
- alterDatabase(model2Xml);
-
- assertEquals(getAdjustedModel(),
- readModelFromDatabase("roundtriptest"));
-
- List beans = getRows("roundtrip2");
- DynaBean bean = (DynaBean)beans.get(0);
-
- // Some databases (e.g. DB2) pad the string for some reason, so we manually trim it
- if (bean.get("fk") instanceof String)
- {
- bean.set("fk", ((String)bean.get("fk")).trim());
- }
- assertEquals((Object)"1", bean, "fk");
- }
-
- /**
- * Tests the alteration of the datatypes of a column that is indexed.
- */
- public void testChangeIndexColumnDatatype()
- {
- 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='avalue' type='NUMERIC' size='8' required='false'/>\n"+
- " <index name='avalue_index'>\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"+
- " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
- " <column name='avalue' type='INTEGER' required='false'/>\n"+
- " <index name='avalue_index'>\n"+
- " <index-column name='avalue'/>\n"+
- " </index>\n"+
- " </table>\n"+
- "</database>";
-
- createDatabase(model1Xml);
-
- insertRow("roundtrip", new Object[] { new Integer(1), new Integer(1) });
- insertRow("roundtrip", new Object[] { new Integer(2), new Integer(10) });
-
- alterDatabase(model2Xml);
-
- assertEquals(getAdjustedModel(),
- readModelFromDatabase("roundtriptest"));
-
- List beans = getRows("roundtrip");
-
- assertEquals(new Integer(1), beans.get(0), "avalue");
- assertEquals(new Integer(10), beans.get(1), "avalue");
- }
-
- /**
- * Tests the alteration of the datatypes of an indexed column where
- * the index will be dropped.
- */
- public void testChangeDroppedIndexColumnDatatype()
- {
- 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='NUMERIC' size='8' required='false'/>\n"+
- " <index name='avalue_index'>\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"+
- " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
- " <column name='avalue' type='INTEGER' required='false'/>\n"+
- " </table>\n"+
- "</database>";
-
- createDatabase(model1Xml);
-
- insertRow("roundtrip", new Object[] { new Integer(1), new Integer(1) });
- insertRow("roundtrip", new Object[] { new Integer(2), new Integer(10) });
-
- alterDatabase(model2Xml);
-
- assertEquals(getAdjustedModel(),
- readModelFromDatabase("roundtriptest"));
-
- List beans = getRows("roundtrip");
-
- assertEquals(new Integer(1), beans.get(0), "avalue");
- assertEquals(new Integer(10), beans.get(1), "avalue");
- }
-
- /**
- * Tests the alteration of a column size.
- */
- public void testChangeSize()
- {
- 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='20' 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"+
- " <column name='avalue' type='VARCHAR' size='32' 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 alteration of a column's datatype and size.
- */
- public void testChangeDatatypeAndSize()
- {
- 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='CHAR' size='4' 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"+
- " <column name='avalue' type='VARCHAR' size='32' 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 alteration of a column null constraint.
- */
- public void testChangeNull()
- {
- 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='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"+
- " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+
- " <column name='avalue' type='INTEGER' required='false'/>\n"+
- " </table>\n"+
- "</database>";
-
- 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), "avalue");
- }
-
- /**
- * Tests the addition of a column's default value.
- */
- public void testAddDefault()
- {
- 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='DOUBLE'/>\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"+
- " <column name='avalue' type='DOUBLE' default='2.0'/>\n"+
- " </table>\n"+
- "</database>";
-
- createDatabase(model1Xml);
-
- insertRow("roundtrip", new Object[] { new Integer(1), new Double(2.0) });
-
- alterDatabase(model2Xml);
-
- assertEquals(getAdjustedModel(),
- readModelFromDatabase("roundtriptest"));
-
- List beans = getRows("roundtrip");
-
- assertEquals(new Double(2.0), beans.get(0), "avalue");
- }
-
- /**
- * Tests the change of a column default value.
- */
- public void testChangeDefault()
- {
- 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='INTEGER' default='1'/>\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"+
- " <column name='avalue' type='INTEGER' default='20'/>\n"+
- " </table>\n"+
- "</database>";
-
- 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), "avalue");
- }
-
- /**
- * Tests the removal of a column default value.
- */
- public void testDropDefault()
- {
- 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='20' default='test'/>\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"+
- " <column name='avalue' type='VARCHAR' size='20'/>\n"+
- " </table>\n"+
- "</database>";
-
- createDatabase(model1Xml);
-
- insertRow("roundtrip", new Object[] { new Integer(1) });
-
- alterDatabase(model2Xml);
-
- assertEquals(getAdjustedModel(),
- readModelFromDatabase("roundtriptest"));
-
- List beans = getRows("roundtrip");
-
- assertEquals((Object)"test", beans.get(0), "avalue");
- }
-
- /**
- * Tests the change of a column's auto-increment state.
- */
- public void testMakeAutoIncrement()
- {
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
- {
- return;
- }
- // Sybase does not like INTEGER auto-increment columns
- if (SybasePlatform.DATABASENAME.equals(getPlatform().getName()))
- {
- 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='NUMERIC' size='12,0'/>\n"+
- " </table>\n"+
- "</database>";
- 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"+
- " <column name='avalue' type='NUMERIC' size='12,0' autoIncrement='true' required='true'/>\n"+
- " </table>\n"+
- "</database>";
-
- createDatabase(model1Xml);
-
- insertRow("roundtrip", new Object[] { new Integer(1), new BigDecimal(2) });
-
- alterDatabase(model2Xml);
-
- assertEquals(getAdjustedModel(),
- readModelFromDatabase("roundtriptest"));
-
- List beans = getRows("roundtrip");
-
- assertEquals(new BigDecimal(2), beans.get(0), "avalue");
- }
- else
- {
- 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='INTEGER'/>\n"+
- " </table>\n"+
- "</database>";
- 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"+
- " <column name='avalue' type='INTEGER' autoIncrement='true' required='true'/>\n"+
- " </table>\n"+
- "</database>";
-
- 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), "avalue");
- }
- }
-
- /**
- * Tests the removal the column auto-increment status.
- */
- public void testDropAutoIncrement()
- {
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
- {
- return;
- }
-
- boolean isSybase = SybasePlatform.DATABASENAME.equals(getPlatform().getName());
- final String model1Xml;
- final String model2Xml;
-
- 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>";
- 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"+
- " <column name='avalue' type='NUMERIC' size='12,0' required='true' autoIncrement='false'/>\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>";
- 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"+
- " <column name='avalue' type='INTEGER' autoIncrement='false'/>\n"+
- " </table>\n"+
- "</database>";
- }
-
- 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
- {
- assertEquals(new Integer(1), beans.get(0), "avalue");
- }
- }
-
- /**
* Tests the change of the order of the columns of a table.
*/
public void testChangeColumnOrder()
@@ -830,7 +139,7 @@
*/
public void testDropAutoIncrementColumn()
{
- if (!getPlatformInfo().isNonPKIdentityColumnsSupported())
+ if (!getPlatformInfo().isNonPrimaryKeyIdentityColumnsSupported())
{
return;
}
@@ -1417,7 +726,8 @@
*/
public void testDropFKAndCorrespondingIndex()
{
- if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
+ if (!getPlatformInfo().isIndicesSupported() ||
+ FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
{
// Firebird does not allow an index and a foreign key in the same table to have the same name
return;
@@ -1483,7 +793,8 @@
*/
public void testDropFKButNotCorrespondingIndex()
{
- if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
+ if (!getPlatformInfo().isIndicesSupported() ||
+ FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
{
// Firebird does not allow an index and a foreign key in the same table to have the same name
return;
@@ -1556,7 +867,8 @@
// MySql/InnoDB doesn't allow the creation of a foreign key and index with the same name
// unless the index can be used as the FK's index
// Firebird does not allow an index and a foreign key in the same table to have the same name at all
- if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+ if (!getPlatformInfo().isIndicesSupported() ||
+ MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
MySql50Platform.DATABASENAME.equals(getPlatform().getName()) ||
FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
{
@@ -1625,7 +937,8 @@
// MySql/InnoDB doesn't allow the creation of a foreign key and index with the same name
// unless the index can be used as the FK's index
// Firebird does not allow an index and a foreign key in the same table to have the same name at all
- if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+ if (!getPlatformInfo().isIndicesSupported() ||
+ MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
MySql50Platform.DATABASENAME.equals(getPlatform().getName()) ||
FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
{