db-ddlutils-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject svn commit: r603162 - in /db/ddlutils/trunk/src: java/org/apache/ddlutils/ java/org/apache/ddlutils/alteration/ java/org/apache/ddlutils/platform/cloudscape/ java/org/apache/ddlutils/platform/firebird/ java/org/apache/ddlutils/platform/mssql/ java/org/...
Date Tue, 11 Dec 2007 07:47:11 GMT
Author: tomdz
Date: Mon Dec 10 23:47:04 2007
New Revision: 603162

URL: http://svn.apache.org/viewvc?rev=603162&view=rev
Log:
Some bug fixes and test tweaks

Modified:
    db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapePlatform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java
    db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybasePlatform.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAddColumn.java
    db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.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=603162&r1=603161&r2=603162&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java Mon Dec 10 23:47:04 2007
@@ -65,6 +65,9 @@
     /** Whether identity specification is supported for non-primary key columns. */
     private boolean _nonPKIdentityColumnsSupported = true;
 
+    /** Whether multiple identity columns in the same table are supported. */
+    private boolean _multipleIdentityColumnsSupported = true;
+
     /** Whether the auto-increment definition is done via the DEFAULT part of the column
definition. */
     private boolean _defaultValueUsedForIdentitySpec = false;
 
@@ -353,6 +356,27 @@
     public void setNonPKIdentityColumnsSupported(boolean supportingNonPKIdentityColumns)
     {
         _nonPKIdentityColumnsSupported = supportingNonPKIdentityColumns;
+    }
+
+    /**
+     * Determines whether multiple columns in the same table can be auto-incrementing (IDENTITY
columns).
+     *
+     * @return <code>true</code> if multiple columns can be auto-incrementing
in the same table
+     */
+    public boolean isMultipleIdentityColumnsSupported()
+    {
+        return _multipleIdentityColumnsSupported;
+    }
+
+    /**
+     * Specifies whether multiple columns in the same table can be auto-incrementing (IDENTITY
columns).
+     *
+     * @param supportingMultipleIdentityColumns <code>true</code> if multiple
columns can be auto-incrementing
+     *                                          in the same table
+     */
+    public void setMultipleIdentityColumnsSupported(boolean supportingMultipleIdentityColumns)
+    {
+        _multipleIdentityColumnsSupported = supportingMultipleIdentityColumns;
     }
 
     /**

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java?rev=603162&r1=603161&r2=603162&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/alteration/ColumnDefinitionChange.java
Mon Dec 10 23:47:04 2007
@@ -113,8 +113,8 @@
             return true;
         }
         else if (scaleMatters &&
-                 (sourceColumn.getPrecisionRadix() != targetColumn.getPrecisionRadix()) ||
-                  (sourceColumn.getScale() != targetColumn.getScale()))
+                 ((sourceColumn.getPrecisionRadix() != targetColumn.getPrecisionRadix())
||
+                  (sourceColumn.getScale() != targetColumn.getScale())))
         {
             return true;
         }

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapePlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapePlatform.java?rev=603162&r1=603161&r2=603162&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapePlatform.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/cloudscape/CloudscapePlatform.java
Mon Dec 10 23:47:04 2007
@@ -49,6 +49,7 @@
         info.setSystemForeignKeyIndicesAlwaysNonUnique(true);
         info.setPrimaryKeyColumnAutomaticallyRequired(true);
         info.setIdentityColumnAutomaticallyRequired(true);
+        info.setMultipleIdentityColumnsSupported(false);
 
         // BINARY and VARBINARY will also be handled by CloudscapeBuilder.getSqlType
         info.addNativeTypeMapping(Types.ARRAY,         "BLOB",                     Types.BLOB);

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java?rev=603162&r1=603161&r2=603162&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
(original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/firebird/FirebirdModelReader.java
Mon Dec 10 23:47:04 2007
@@ -40,7 +40,6 @@
 import org.apache.ddlutils.model.TypeMap;
 import org.apache.ddlutils.platform.DatabaseMetaDataWrapper;
 import org.apache.ddlutils.platform.JdbcModelReader;
-import org.apache.ddlutils.platform.MetaDataColumnDescriptor;
 
 /**
  * The Jdbc Model Reader for Firebird.
@@ -174,7 +173,7 @@
 
     	try
     	{
-            ResultSet rs = stmt.executeQuery("SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS");
+            ResultSet rs = stmt.executeQuery("SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS
WHERE RDB$GENERATOR_NAME NOT LIKE '%$%'");
 
             while (rs.next())
             {

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java?rev=603162&r1=603161&r2=603162&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java Mon Dec
10 23:47:04 2007
@@ -74,6 +74,7 @@
         info.setMaxIdentifierLength(128);
         info.setPrimaryKeyColumnAutomaticallyRequired(true);
         info.setIdentityColumnAutomaticallyRequired(true);
+        info.setMultipleIdentityColumnsSupported(false);
 
         info.addNativeTypeMapping(Types.ARRAY,         "IMAGE",         Types.LONGVARBINARY);
         // BIGINT will be mapped back to BIGINT by the model reader 

Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java?rev=603162&r1=603161&r2=603162&view=diff
==============================================================================
--- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java (original)
+++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sapdb/SapDbPlatform.java Mon Dec
10 23:47:04 2007
@@ -63,6 +63,7 @@
 
         info.setMaxIdentifierLength(32);
         info.setPrimaryKeyColumnAutomaticallyRequired(true);
+        info.setMultipleIdentityColumnsSupported(false);
         info.setCommentPrefix("/*");
         info.setCommentSuffix("*/");
 

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=603162&r1=603161&r2=603162&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 Mon
Dec 10 23:47:04 2007
@@ -81,6 +81,7 @@
         info.setMaxIdentifierLength(28);
         info.setNullAsDefaultValueRequired(true);
         info.setIdentityColumnAutomaticallyRequired(true);
+        info.setMultipleIdentityColumnsSupported(false);
         info.setCommentPrefix("/*");
         info.setCommentSuffix("*/");
 

Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java
URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java?rev=603162&r1=603161&r2=603162&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/TestDatabaseWriterBase.java Mon Dec 10
23:47:04 2007
@@ -22,12 +22,19 @@
 import java.io.FileInputStream;
 import java.io.InputStream;
 import java.io.StringReader;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.util.ArrayList;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 
 import javax.sql.DataSource;
 
+import junit.framework.AssertionFailedError;
+
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.beanutils.DynaBean;
 import org.apache.commons.beanutils.DynaProperty;
@@ -36,6 +43,8 @@
 import org.apache.ddlutils.io.DataToDatabaseSink;
 import org.apache.ddlutils.model.Database;
 import org.apache.ddlutils.platform.CreationParameters;
+import org.apache.ddlutils.platform.firebird.FirebirdPlatform;
+import org.apache.ddlutils.platform.interbase.InterbasePlatform;
 
 /**
  * Base class for database writer tests.
@@ -233,12 +242,19 @@
      */
     protected void tearDown() throws Exception
     {
-        if (_model != null)
+        try
         {
-            dropDatabase();
-            _model = null;
+            if (_model != null)
+            {
+                dropDatabase();
+                _model = null;
+            }
+        }
+        finally
+        {
+            assertAndEnsureClearDatabase();
+            super.tearDown();
         }
-        super.tearDown();
     }
 
     /**
@@ -267,7 +283,7 @@
             _model = model;
 
             getPlatform().setSqlCommentsOn(false);
-            getPlatform().createTables(_model, getTableCreationParameters(_model), false,
false);
+            getPlatform().createModel(_model, getTableCreationParameters(_model), false,
false);
         }
         catch (Exception ex)
         {
@@ -292,21 +308,19 @@
     /**
      * Alters the database to match the given model.
      * 
-     * @param model The model
+     * @param desiredModel The model
      */
-    protected void alterDatabase(Database model) throws DatabaseOperationException
+    protected void alterDatabase(Database desiredModel) throws DatabaseOperationException
     {
-        Properties props   = getTestProperties();
-        String     catalog = props.getProperty(DDLUTILS_CATALOG_PROPERTY);
-        String     schema  = props.getProperty(DDLUTILS_SCHEMA_PROPERTY);
-
         try
         {
-            _model = model;
+            _model = desiredModel;
             _model.resetDynaClassCache();
 
+            Database liveModel = readModelFromDatabase(desiredModel.getName());
+
             getPlatform().setSqlCommentsOn(false);
-            getPlatform().alterTables(catalog, schema, null, _model, getTableCreationParameters(_model),
false);
+            getPlatform().alterModel(liveModel, _model, getTableCreationParameters(_model),
false);
         }
         catch (Exception ex)
         {
@@ -344,10 +358,171 @@
      */
     protected void dropDatabase() throws DatabaseOperationException
     {
-        getPlatform().dropTables(_model, true);
+        getPlatform().dropModel(_model, true);
     }
 
     /**
+     * Checks that the database is clear, and if not clears it (no tables, sequences etc.
left) and
+     * throws an {@link AssertionFailedError}.
+     */
+    protected void assertAndEnsureClearDatabase()
+    {
+        Database liveModel = readModelFromDatabase("tmp");
+        boolean  hasStuff  = false;
+
+        if (liveModel.getTableCount() > 0)
+        {
+            hasStuff = true;
+            try
+            {
+                getPlatform().dropModel(liveModel, true);
+            }
+            catch (Exception ex)
+            {
+                getLog().error("Could not clear database", ex);
+            }
+        }
+        if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            Connection connection = null;
+
+            try
+            {
+                connection = getPlatform().borrowConnection();
+
+                hasStuff = hasStuff | dropTriggers(connection);
+                hasStuff = hasStuff | dropGenerators(connection);
+            }
+            catch (Exception ex)
+            {
+                getLog().error("Could not clear database", ex);
+            }
+            finally
+            {
+                getPlatform().returnConnection(connection);
+            }
+        }
+        // TODO: Check for sequences
+        if (hasStuff)
+        {
+            fail("Database is not empty after test");
+        }
+    }
+
+    /**
+     * Drops generators left by a test in a Firebird/Interbase database.
+     * 
+     * @param connection The database connection
+     * @return Whether generators were dropped
+     */
+    private boolean dropGenerators(Connection connection)
+    {
+        Statement stmt          = null;
+        boolean   hasGenerators = false;
+
+        try
+        {
+            stmt = connection.createStatement();
+
+            ResultSet rs    = stmt.executeQuery("SELECT RDB$GENERATOR_NAME FROM RDB$GENERATORS
WHERE RDB$GENERATOR_NAME NOT LIKE '%$%'");
+            List      names = new ArrayList();
+    
+            while (rs.next())
+            {
+                names.add(rs.getString(1));
+            }
+            rs.close();
+    
+            for (Iterator it = names.iterator(); it.hasNext();)
+            {
+                String name = (String)it.next();
+
+                if (name.toLowerCase().startsWith("gen_"))
+                {
+                    hasGenerators = true;
+                    stmt.execute("DROP GENERATOR " + name);
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            getLog().error("Error while dropping the remaining generators", ex);
+        }
+        finally
+        {
+            if (stmt != null)
+            {
+                try
+                {
+                    stmt.close();
+                }
+                catch (Exception ex)
+                {
+                    getLog().error("Error while clearing the database", ex);
+                }
+            }
+        }
+        return hasGenerators;
+    }
+
+    /**
+     * Drops triggers left by a test in a Firebird/Interbase database.
+     * 
+     * @param connection The database connection
+     * @return Whether triggers were dropped
+     */
+    private boolean dropTriggers(Connection connection)
+    {
+        Statement stmt        = null;
+        boolean   hasTriggers = false;
+
+        try
+        {
+            stmt = connection.createStatement();
+
+            ResultSet rs    = stmt.executeQuery("SELECT * FROM RDB$TRIGGERS WHERE RDB$SYSTEM_FLAG
IS NULL OR RDB$SYSTEM_FLAG = 0");
+            List      names = new ArrayList();
+    
+            while (rs.next())
+            {
+                names.add(rs.getString(1));
+            }
+            rs.close();
+    
+            for (Iterator it = names.iterator(); it.hasNext();)
+            {
+                String name = (String)it.next();
+
+                if (name.toLowerCase().startsWith("trg_"))
+                {
+                    hasTriggers = true;
+                    stmt.execute("DROP TRIGGER " + name);
+                }
+            }
+        }
+        catch (Exception ex)
+        {
+            getLog().error("Error while dropping the remaining triggers", ex);
+        }
+        finally
+        {
+            if (stmt != null)
+            {
+                try
+                {
+                    stmt.close();
+                }
+                catch (Exception ex)
+                {
+                    getLog().error("Error while clearing the database", ex);
+                }
+            }
+        }
+        return hasTriggers;
+    }
+    
+    /**
      * Reads the database model from a live database.
      * 
      * @param databaseName The name of the resulting database
@@ -370,11 +545,9 @@
      */
     protected String getAlterTablesSql(Database desiredModel)
     {
-    	Properties props   = getTestProperties();
-        String     catalog = props.getProperty(DDLUTILS_CATALOG_PROPERTY);
-        String     schema  = props.getProperty(DDLUTILS_SCHEMA_PROPERTY);
+        Database liveModel = readModelFromDatabase(desiredModel.getName());
 
-        return getPlatform().getAlterTablesSql(catalog, schema, null, desiredModel);
+        return getPlatform().getAlterModelSql(liveModel, desiredModel, getTableCreationParameters(desiredModel));
     }
 
     /**

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=603162&r1=603161&r2=603162&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 Mon Dec 10 23:47:04
2007
@@ -27,12 +27,11 @@
 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.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;
 
 /**
@@ -158,11 +157,9 @@
     public void testAddSecondAutoIncrementColumn()
     {
         if (!getPlatformInfo().isNonPKIdentityColumnsSupported() ||
-            SybasePlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MaxDbPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            SapDbPlatform.DATABASENAME.equals(getPlatform().getName()))
+            !getPlatformInfo().isMultipleIdentityColumnsSupported())
         {
-            // Sybase and MaxDb/SapDb does not support more than one identity column per
table
+            // Some databases do not support more than one identity column per table
             return;
         }
 
@@ -468,12 +465,14 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -531,6 +530,10 @@
         {
             assertEquals(new BigDecimal(1), beans.get(0), "pk");
         }
+        else if (HsqlDbPlatform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            assertEquals(new Integer(0), beans.get(0), "pk");
+        }
         else
         {
             assertEquals(new Integer(1), beans.get(0), "pk");
@@ -545,7 +548,8 @@
         if (Db2Platform.DATABASENAME.equals(getPlatform().getName()) ||
             Db2v8Platform.DATABASENAME.equals(getPlatform().getName()) ||
             SybasePlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            InterbasePlatform.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;
         }
@@ -580,13 +584,15 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -626,13 +632,15 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -713,12 +721,14 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -830,13 +840,15 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -1055,16 +1067,19 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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()))
+        else if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+                 InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             assertEquals(new Integer(1), beans.get(0), "pk");
             assertEquals((Object)null,   beans.get(0), "avalue");
         }
-        else {
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -1153,7 +1168,8 @@
 
         List beans = getRows("roundtrip");
 
-        if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
+        if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             assertEquals(new Integer(1), beans.get(0), "pk");
             assertEquals((Object)null,   beans.get(0), "avalue");
@@ -1251,18 +1267,21 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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()))
+        else if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+                 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 {
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -1397,11 +1416,18 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            assertEquals(new Integer(1), beans.get(0), "pk");
+            assertEquals((Object)null,   beans.get(0), "avalue");
+        }
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -1490,7 +1516,15 @@
 
         List beans = getRows("roundtrip");
 
-        assertEquals(new Integer(1), beans.get(0), "avalue");
+        assertEquals(new Integer(1), beans.get(0), "pk");
+        if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            assertEquals((Object)null, beans.get(0), "avalue");
+        }
+        else
+        {
+            assertEquals(new Integer(1), beans.get(0), "avalue");
+        }
     }
 
     /**
@@ -1580,12 +1614,20 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else if (FirebirdPlatform.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());
         }
     }
@@ -1633,12 +1675,20 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            assertEquals(new Integer(1), beans.get(0), "pk");
+            assertEquals(new Integer(1), beans.get(0), "avalue1");
+            assertEquals((Object)null,   beans.get(0), "avalue2");
+        }
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -1791,18 +1841,21 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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()))
+        else if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+                 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 {
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -1904,7 +1957,8 @@
 
         List beans = getRows("roundtrip");
 
-        if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
+        if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             assertEquals(new Integer(1), beans.get(0), "pk");
             assertEquals(new Integer(2), beans.get(0), "avalue1");
@@ -2017,20 +2071,23 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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()))
+        else if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+                 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 {
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -2185,14 +2242,22 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else if (FirebirdPlatform.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());
         }
     }
@@ -2294,8 +2359,16 @@
 
         List beans = getRows("roundtrip");
 
+        assertEquals(new Integer(1), beans.get(0), "pk");
         assertEquals(new Integer(2), beans.get(0), "avalue1");
-        assertEquals(new Integer(1), beans.get(0), "avalue2");
+        if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
+        {
+            assertEquals((Object)null, beans.get(0), "avalue2");
+        }
+        else
+        {
+            assertEquals(new Integer(1), beans.get(0), "avalue2");
+        }
     }
 
     /**
@@ -2398,13 +2471,22 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else if (FirebirdPlatform.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());
         }
     }
@@ -2458,13 +2540,22 @@
         List beans = getRows("roundtrip");
 
         if (MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) ||
-            MySql50Platform.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 {
+        else if (FirebirdPlatform.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((Object)null,    beans.get(0), "avalue3");
+        }
+        else
+        {
             assertTrue(beans.isEmpty());
         }
     }
@@ -2576,6 +2667,14 @@
      */
     public void testAddFKAndLocalRequiredColumn()
     {
+        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;
+        }
+
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
@@ -2615,7 +2714,8 @@
         List beans2 = getRows("roundtrip2");
 
         assertEquals(new BigDecimal(1), beans1.get(0), "pk");
-        if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
+        if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             assertEquals(new Integer(2), beans2.get(0), "pk");
             assertEquals((Object)null,   beans2.get(0), "avalue");
@@ -2725,7 +2825,8 @@
 
         assertEquals(new Integer(1), beans1.get(0), "pk");
         assertEquals(new Integer(2), beans2.get(0), "pk");
-        if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
+        if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             assertEquals((Object)null, beans2.get(0), "avalue");
         }
@@ -2788,6 +2889,14 @@
      */
     public void testAddFKAndMultipleLocalColumns()
     {
+        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;
+        }
+
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
@@ -2832,7 +2941,8 @@
 
         assertEquals(new Integer(1), beans1.get(0), "pk1");
         assertEquals(new Double(2),  beans1.get(0), "pk2");
-        if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
+        if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             assertEquals(new Integer(3), beans2.get(0), "pk");
             assertEquals((Object)null,   beans2.get(0), "avalue1");
@@ -3302,7 +3412,8 @@
         assertEquals(new Integer(1), beans1.get(0), "pk2");
         assertEquals(new Integer(2), beans2.get(0), "pk");
         assertEquals(new Integer(1), beans2.get(0), "avalue1");
-        if (InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
+        if (FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()) ||
+            InterbasePlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             assertEquals((Object)null, beans2.get(0), "avalue2");
         }

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=603162&r1=603161&r2=603162&view=diff
==============================================================================
--- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java (original)
+++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestAlteration.java Mon Dec 10 23:47:04
2007
@@ -27,6 +27,7 @@
 
 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;
 import org.apache.ddlutils.platform.mysql.MySql50Platform;
 import org.apache.ddlutils.platform.mysql.MySqlPlatform;
@@ -1416,6 +1417,12 @@
      */
     public void testDropFKAndCorrespondingIndex()
     {
+        if (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;
+        }
+
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
@@ -1476,6 +1483,12 @@
      */
     public void testDropFKButNotCorrespondingIndex()
     {
+        if (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;
+        }
+
         final String model1Xml = 
             "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+
             "<database name='roundtriptest'>\n"+
@@ -1541,8 +1554,11 @@
     public void testDropFKAndDifferentIndexWithSameName()
     {
         // 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()) ||
-            MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
+            MySql50Platform.DATABASENAME.equals(getPlatform().getName()) ||
+            FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             return;
         }
@@ -1607,8 +1623,11 @@
     public void testDropFKButNotDifferentIndexWithSameName()
     {
         // 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()) ||
-            MySql50Platform.DATABASENAME.equals(getPlatform().getName()))
+            MySql50Platform.DATABASENAME.equals(getPlatform().getName()) ||
+            FirebirdPlatform.DATABASENAME.equals(getPlatform().getName()))
         {
             return;
         }



Mime
View raw message