Author: tomdz Date: Wed Nov 5 22:34:24 2008 New Revision: 711776 URL: http://svn.apache.org/viewvc?rev=711776&view=rev Log: Added a more generic way to handle cascade action capabilities of the individual platforms which also fixes DDLUTILS-222: ON UPDATE, ON DELETE errors for MS Sql Server - does not implement default "RESTRICT"
Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/Platform.java db/ddlutils/trunk/src/main/java/org/apache/ddlutils/PlatformInfo.java db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/PlatformImplBase.java db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java db/ddlutils/trunk/src/test/java/org/apache/ddlutils/TestAgainstLiveDatabaseBase.java db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestConstraints.java Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/Platform.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/Platform.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/Platform.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/Platform.java Wed Nov 5 22:34:24 2008 @@ -199,6 +199,42 @@ */ public void setForeignKeysSorted(boolean foreignKeysSorted); + /** + * Determines whether the default action for ON UPDATE is used if the specified one is not supported by the platform. + * If this is set to <code>false</code>, then an exception will be thrown if the action is not supported. By default, this + * is set to <code>true</code> meaning that the default action would be used. + * + * @return <code>true</code> if the default action is used + */ + public boolean isDefaultOnUpdateActionUsedIfUnsupported(); + + /** + * Specifies whether the default action for ON UPDATE shall be used if the specified one is not supported by the platform. + * If this is set to <code>false</code>, then an exception will be thrown if the action is not supported. By default, this + * is set to <code>true</code> meaning that the default action would be used. + * + * @param useDefault If <code>true</code> then the default action will be used + */ + public void setDefaultOnUpdateActionUsedIfUnsupported(boolean useDefault); + + /** + * Determines whether the default action for ON DELETE is used if the specified one is not supported by the platform. + * If this is set to <code>false</code>, then an exception will be thrown if the action is not supported. By default, this + * is set to <code>true</code> meaning that the default action would be used. + * + * @return <code>true</code> if the default action is used + */ + public boolean isDefaultOnDeleteActionUsedIfUnsupported(); + + /** + * Specifies whether the default action for ON DELETE shall be used if the specified one is not supported by the platform. + * If this is set to <code>false</code>, then an exception will be thrown if the action is not supported. By default, this + * is set to <code>true</code> meaning that the default action would be used. + * + * @param useDefault If <code>true</code> then the default action will be used + */ + public void setDefaultOnDeleteActionUsedIfUnsupported(boolean useDefault); + // functionality /** Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/PlatformInfo.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/PlatformInfo.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/PlatformInfo.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/PlatformInfo.java Wed Nov 5 22:34:24 2008 @@ -21,11 +21,13 @@ import java.lang.reflect.Field; import java.sql.Types; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.ddlutils.model.CascadeActionEnum; /** * Conatains information about the database platform such as supported features and native type mappings. @@ -166,6 +168,18 @@ /** Contains those JDBC types whose corresponding native types are types that have precision and scale on this platform. */ private HashSet _typesWithPrecisionAndScale = new HashSet(); + /** The default ON UPDATE action. */ + private CascadeActionEnum _defaultOnUpdateAction = CascadeActionEnum.NONE; + + /** The default ON DELETE action. */ + private CascadeActionEnum _defaultOnDeleteAction = CascadeActionEnum.NONE; + + /** Contains the supported ON UPDATE actions. */ + private HashSet _supportedOnUpdateActions = new HashSet(); + + /** Contains the supported ON DELETE actions. */ + private HashSet _supportedOnDeleteActions = new HashSet(); + /** * Creates a new platform info object. */ @@ -187,6 +201,9 @@ _typesWithPrecisionAndScale.add(new Integer(Types.DECIMAL)); _typesWithPrecisionAndScale.add(new Integer(Types.NUMERIC)); + + _supportedOnUpdateActions.addAll(CascadeActionEnum.getEnumList()); + _supportedOnDeleteActions.addAll(CascadeActionEnum.getEnumList()); } // properties influencing the definition of columns @@ -201,6 +218,7 @@ { return _nullAsDefaultValueRequired; } + /** * Specifies whether a NULL needs to be explicitly stated when the column * has no specified default value. Default is false. @@ -1174,4 +1192,88 @@ _typesWithPrecisionAndScale.remove(new Integer(sqlTypeCode)); } } + + /** + * Sets the actions that this platform supports for ON UPDATE. + * + * @param actions The actions + */ + public void setSupportedOnUpdateActions(CascadeActionEnum[] actions) + { + _supportedOnUpdateActions.clear(); + _supportedOnUpdateActions.addAll(Arrays.asList(actions)); + } + + /** + * Determines whether the given action is supported for ON UPDATE on this platform. + * + * @param action The action + * @return <code>true</code> if the action is supported + */ + public boolean isActionSupportedForOnUpdate(CascadeActionEnum action) + { + return _supportedOnUpdateActions.contains(action); + } + + /** + * Sets the actions that this platform supports for ON DELETE. + * + * @param actions The actions + */ + public void setSupportedOnDeleteActions(CascadeActionEnum[] actions) + { + _supportedOnDeleteActions.clear(); + _supportedOnDeleteActions.addAll(Arrays.asList(actions)); + } + + /** + * Determines whether the given action is supported for ON DELETE on this platform. + * + * @param action The action + * @return <code>true</code> if the action is supported + */ + public boolean isActionSupportedForOnDelete(CascadeActionEnum action) + { + return _supportedOnDeleteActions.contains(action); + } + + /** + * Returns the default ON UPDATE action that is used if none is specified. + * + * @return The default action + */ + public CascadeActionEnum getDefaultOnUpdateAction() + { + return _defaultOnUpdateAction; + } + + /** + * Sets the default ON UPDATE action that is used if none is specified. + * + * @return The default action + */ + public void setDefaultOnUpdateAction(CascadeActionEnum defaultOnUpdateAction) + { + _defaultOnUpdateAction = defaultOnUpdateAction; + } + + /** + * Returns the default ON DELETE action that is used if none is specified. + * + * @return The default action + */ + public CascadeActionEnum getDefaultOnDeleteAction() + { + return _defaultOnDeleteAction; + } + + /** + * Sets the default ON DELETE action that is used if none is specified. + * + * @return The default action + */ + public void setDefaultOnDeleteAction(CascadeActionEnum defaultOnDeleteAction) + { + _defaultOnDeleteAction = defaultOnDeleteAction; + } } Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/JdbcModelReader.java Wed Nov 5 22:34:24 2008 @@ -929,8 +929,8 @@ { fk = new ForeignKey(fkName); fk.setForeignTableName((String)values.get("PKTABLE_NAME")); - fk.setOnUpdate(convertAction((Short)values.get("UPDATE_RULE"))); - fk.setOnDelete(convertAction((Short)values.get("DELETE_RULE"))); + fk.setOnUpdate(convertAction((Short)values.get("UPDATE_RULE"), getPlatformInfo().getDefaultOnUpdateAction())); + fk.setOnDelete(convertAction((Short)values.get("DELETE_RULE"), getPlatformInfo().getDefaultOnDeleteAction())); knownFks.put(fkName, fk); } @@ -950,11 +950,12 @@ * [EMAIL PROTECTED] DatabaseMetaData} class) to a [EMAIL PROTECTED] CascadeActionEnum}. * * @param jdbcActionValue The jdbc action value + * @param defaultAction The default action * @return The enum value */ - protected CascadeActionEnum convertAction(Short jdbcActionValue) + protected CascadeActionEnum convertAction(Short jdbcActionValue, CascadeActionEnum defaultAction) { - CascadeActionEnum action = CascadeActionEnum.NONE; + CascadeActionEnum action = defaultAction; if (jdbcActionValue != null) { Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/PlatformImplBase.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/PlatformImplBase.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/PlatformImplBase.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/PlatformImplBase.java Wed Nov 5 22:34:24 2008 @@ -116,6 +116,10 @@ private boolean _identityOverrideOn; /** Whether read foreign keys shall be sorted alphabetically. */ private boolean _foreignKeysSorted; + /** Whether to use the default ON UPDATE action if the specified one is unsupported. */ + private boolean _useDefaultOnUpdateActionIfUnsupported = true; + /** Whether to use the default ON DELETE action if the specified one is unsupported. */ + private boolean _useDefaultOnDeleteActionIfUnsupported = true; /** * [EMAIL PROTECTED] @@ -254,6 +258,38 @@ } /** + * [EMAIL PROTECTED] + */ + public boolean isDefaultOnUpdateActionUsedIfUnsupported() + { + return _useDefaultOnUpdateActionIfUnsupported; + } + + /** + * [EMAIL PROTECTED] + */ + public void setDefaultOnUpdateActionUsedIfUnsupported(boolean useDefault) + { + _useDefaultOnUpdateActionIfUnsupported = useDefault; + } + + /** + * [EMAIL PROTECTED] + */ + public boolean isDefaultOnDeleteActionUsedIfUnsupported() + { + return _useDefaultOnDeleteActionIfUnsupported; + } + + /** + * [EMAIL PROTECTED] + */ + public void setDefaultOnDeleteActionUsedIfUnsupported(boolean useDefault) + { + _useDefaultOnDeleteActionIfUnsupported = useDefault; + } + + /** * Returns the log for this platform. * * @return The log Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/SqlBuilder.java Wed Nov 5 22:34:24 2008 @@ -1957,10 +1957,25 @@ */ private void writeForeignKeyOnDeleteAction(Table table, ForeignKey foreignKey) throws IOException { - if (foreignKey.getOnDelete() != CascadeActionEnum.NONE) + CascadeActionEnum action = foreignKey.getOnDelete(); + + if (!getPlatformInfo().isActionSupportedForOnDelete(action)) + { + if (getPlatform().isDefaultOnDeleteActionUsedIfUnsupported()) + { + _log.info("The platform does not support the " + action + " action for onDelete; using " + getPlatformInfo().getDefaultOnDeleteAction() + " instead"); + action = getPlatformInfo().getDefaultOnDeleteAction(); + } + else + { + throw new ModelException("The platform does not support the action '" + action + + "' for onDelete in foreign key in table " + table.getName()); + } + } + if (action != getPlatformInfo().getDefaultOnDeleteAction()) { print(" ON DELETE "); - switch (foreignKey.getOnDelete().getValue()) + switch (action.getValue()) { case CascadeActionEnum.VALUE_CASCADE: print("CASCADE"); @@ -1978,7 +1993,7 @@ print("NO ACTION"); break; default: - throw new ModelException("Unsupported cascade value '" + foreignKey.getOnDelete().getValue() + + throw new ModelException("Unsupported cascade value '" + action + "' for onDelete in foreign key in table " + table.getName()); } } @@ -1992,10 +2007,25 @@ */ private void writeForeignKeyOnUpdateAction(Table table, ForeignKey foreignKey) throws IOException { - if (foreignKey.getOnUpdate() != CascadeActionEnum.NONE) + CascadeActionEnum action = foreignKey.getOnUpdate(); + + if (!getPlatformInfo().isActionSupportedForOnUpdate(action)) + { + if (getPlatform().isDefaultOnUpdateActionUsedIfUnsupported()) + { + _log.info("The platform does not support the " + action + " action for onUpdate; using " + getPlatformInfo().getDefaultOnUpdateAction() + " instead"); + action = getPlatformInfo().getDefaultOnUpdateAction(); + } + else + { + throw new ModelException("The platform does not support the action '" + action + + "' for onUpdate in foreign key in table " + table.getName()); + } + } + if (action != getPlatformInfo().getDefaultOnUpdateAction()) { print(" ON UPDATE "); - switch (foreignKey.getOnUpdate().getValue()) + switch (action.getValue()) { case CascadeActionEnum.VALUE_CASCADE: print("CASCADE"); @@ -2013,7 +2043,7 @@ print("NO ACTION"); break; default: - throw new ModelException("Unsupported cascade value '" + foreignKey.getOnUpdate().getValue() + + throw new ModelException("Unsupported cascade value '" + action + "' for onUpdate in foreign key in table " + table.getName()); } } Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java Wed Nov 5 22:34:24 2008 @@ -27,9 +27,11 @@ import java.util.Map; import org.apache.ddlutils.DatabaseOperationException; +import org.apache.ddlutils.PlatformInfo; import org.apache.ddlutils.alteration.AddColumnChange; import org.apache.ddlutils.alteration.TableChange; import org.apache.ddlutils.alteration.TableDefinitionChangesPredicate; +import org.apache.ddlutils.model.CascadeActionEnum; import org.apache.ddlutils.model.Table; import org.apache.ddlutils.platform.DefaultTableDefinitionChangesPredicate; import org.apache.ddlutils.platform.cloudscape.CloudscapePlatform; @@ -56,8 +58,15 @@ public DerbyPlatform() { super(); - getPlatformInfo().addNativeTypeMapping(Types.DOUBLE, "DOUBLE"); - getPlatformInfo().addNativeTypeMapping(Types.FLOAT, "DOUBLE", Types.DOUBLE); + + PlatformInfo info = getPlatformInfo(); + + info.addNativeTypeMapping(Types.DOUBLE, "DOUBLE"); + info.addNativeTypeMapping(Types.FLOAT, "DOUBLE", Types.DOUBLE); + info.setSupportedOnUpdateActions(new CascadeActionEnum[] { CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT }); + info.setSupportedOnDeleteActions(new CascadeActionEnum[] { CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT, + CascadeActionEnum.CASCADE, CascadeActionEnum.SET_NULL }); + setSqlBuilder(new DerbyBuilder(this)); setModelReader(new DerbyModelReader(this)); } Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java Wed Nov 5 22:34:24 2008 @@ -19,6 +19,7 @@ * under the License. */ +import java.sql.DatabaseMetaData; import java.sql.Date; import java.sql.ResultSet; import java.sql.SQLException; @@ -32,6 +33,7 @@ import org.apache.ddlutils.DdlUtilsException; import org.apache.ddlutils.Platform; +import org.apache.ddlutils.model.CascadeActionEnum; import org.apache.ddlutils.model.Column; import org.apache.ddlutils.model.Index; import org.apache.ddlutils.model.Table; @@ -228,4 +230,19 @@ return column; } + + /** + * [EMAIL PROTECTED] + */ + protected CascadeActionEnum convertAction(Short jdbcActionValue, CascadeActionEnum defaultAction) + { + CascadeActionEnum action = defaultAction; + + // for whatever reason, the sql server jdbc driver returns restrict even though the DB does not support RESTRICT + if ((jdbcActionValue != null) && (jdbcActionValue.shortValue() == DatabaseMetaData.importedKeyCascade)) + { + action = CascadeActionEnum.CASCADE; + } + return action; + } } Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mssql/MSSqlPlatform.java Wed Nov 5 22:34:24 2008 @@ -37,6 +37,7 @@ import org.apache.ddlutils.alteration.RemovePrimaryKeyChange; import org.apache.ddlutils.alteration.TableChange; import org.apache.ddlutils.alteration.TableDefinitionChangesPredicate; +import org.apache.ddlutils.model.CascadeActionEnum; import org.apache.ddlutils.model.Column; import org.apache.ddlutils.model.Database; import org.apache.ddlutils.model.Table; @@ -75,6 +76,8 @@ info.setPrimaryKeyColumnAutomaticallyRequired(true); info.setIdentityColumnAutomaticallyRequired(true); info.setMultipleIdentityColumnsSupported(false); + info.setSupportedOnUpdateActions(new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE }); + info.setSupportedOnDeleteActions(new CascadeActionEnum[] { CascadeActionEnum.CASCADE, CascadeActionEnum.NONE }); info.addNativeTypeMapping(Types.ARRAY, "IMAGE", Types.LONGVARBINARY); // BIGINT will be mapped back to BIGINT by the model reader Modified: db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java (original) +++ db/ddlutils/trunk/src/main/java/org/apache/ddlutils/platform/mysql/MySqlPlatform.java Wed Nov 5 22:34:24 2008 @@ -32,6 +32,7 @@ import org.apache.ddlutils.alteration.RemovePrimaryKeyChange; import org.apache.ddlutils.alteration.TableChange; import org.apache.ddlutils.alteration.TableDefinitionChangesPredicate; +import org.apache.ddlutils.model.CascadeActionEnum; import org.apache.ddlutils.model.Column; import org.apache.ddlutils.model.Database; import org.apache.ddlutils.model.Table; @@ -75,6 +76,10 @@ info.setCommentPrefix("#"); // Double quotes are only allowed for delimiting identifiers if the server SQL mode includes ANSI_QUOTES info.setDelimiterToken("`"); + info.setSupportedOnUpdateActions(new CascadeActionEnum[] { CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT, + CascadeActionEnum.CASCADE, CascadeActionEnum.SET_NULL }); + info.setSupportedOnDeleteActions(new CascadeActionEnum[] { CascadeActionEnum.NONE, CascadeActionEnum.RESTRICT, + CascadeActionEnum.CASCADE, CascadeActionEnum.SET_NULL }); info.addNativeTypeMapping(Types.ARRAY, "LONGBLOB", Types.LONGVARBINARY); info.addNativeTypeMapping(Types.BIT, "TINYINT(1)"); Modified: db/ddlutils/trunk/src/test/java/org/apache/ddlutils/TestAgainstLiveDatabaseBase.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/java/org/apache/ddlutils/TestAgainstLiveDatabaseBase.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/test/java/org/apache/ddlutils/TestAgainstLiveDatabaseBase.java (original) +++ db/ddlutils/trunk/src/test/java/org/apache/ddlutils/TestAgainstLiveDatabaseBase.java Wed Nov 5 22:34:24 2008 @@ -1308,28 +1308,27 @@ getPlatform().getSqlBuilder().shortenName(expected.getForeignTableName().toUpperCase(), getSqlBuilder().getMaxTableNameLength()), getPlatform().getSqlBuilder().shortenName(actual.getForeignTableName().toUpperCase(), getSqlBuilder().getMaxTableNameLength())); } - if ((expected.getOnUpdate() == CascadeActionEnum.NONE) || (expected.getOnUpdate() == CascadeActionEnum.RESTRICT)) - { - assertTrue("Not the same onUpdate setting in foreign key "+actual.getName()+".", - (actual.getOnUpdate() == CascadeActionEnum.NONE) || (actual.getOnUpdate() == CascadeActionEnum.RESTRICT)); - } - else - { - assertEquals("Not the same onUpdate setting in foreign key "+actual.getName()+".", - expected.getOnUpdate(), - actual.getOnUpdate()); - } - if ((expected.getOnDelete() == CascadeActionEnum.NONE) || (expected.getOnDelete() == CascadeActionEnum.RESTRICT)) + + CascadeActionEnum realExpectedOnUpdateAction = expected.getOnUpdate(); + + if (!getPlatformInfo().isActionSupportedForOnUpdate(realExpectedOnUpdateAction)) { - assertTrue("Not the same onDelete setting in foreign key "+actual.getName()+".", - (actual.getOnDelete() == CascadeActionEnum.NONE) || (actual.getOnDelete() == CascadeActionEnum.RESTRICT)); + realExpectedOnUpdateAction = getPlatformInfo().getDefaultOnUpdateAction(); } - else + assertEquals("Not the same onUpdate setting in foreign key "+actual.getName()+".", + realExpectedOnUpdateAction, + actual.getOnUpdate()); + + CascadeActionEnum realExpectedOnDeleteAction = expected.getOnDelete(); + + if (!getPlatformInfo().isActionSupportedForOnDelete(realExpectedOnDeleteAction)) { - assertEquals("Not the same onDelete setting in foreign key "+actual.getName()+".", - expected.getOnDelete(), - actual.getOnDelete()); + realExpectedOnDeleteAction = getPlatformInfo().getDefaultOnDeleteAction(); } + assertEquals("Not the same onDelete setting in foreign key "+actual.getName()+".", + realExpectedOnDeleteAction, + actual.getOnDelete()); + assertEquals("Not the same number of references in foreign key "+actual.getName()+".", expected.getReferenceCount(), actual.getReferenceCount()); Modified: db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestConstraints.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestConstraints.java?rev=711776&r1=711775&r2=711776&view=diff ============================================================================== --- db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestConstraints.java (original) +++ db/ddlutils/trunk/src/test/java/org/apache/ddlutils/io/TestConstraints.java Wed Nov 5 22:34:24 2008 @@ -27,11 +27,8 @@ import org.apache.commons.lang.StringUtils; import org.apache.ddlutils.DdlUtilsException; import org.apache.ddlutils.TestAgainstLiveDatabaseBase; +import org.apache.ddlutils.model.CascadeActionEnum; import org.apache.ddlutils.model.Database; -import org.apache.ddlutils.platform.derby.DerbyPlatform; -import org.apache.ddlutils.platform.firebird.FirebirdPlatform; -import org.apache.ddlutils.platform.mysql.MySql50Platform; -import org.apache.ddlutils.platform.mysql.MySqlPlatform; import org.apache.ddlutils.platform.sybase.SybasePlatform; /** @@ -485,45 +482,47 @@ */ public void testForeignKeyWithOnDeleteRestrict() { - if (!FirebirdPlatform.DATABASENAME.equals(getPlatform().getName())) + if (!getPlatformInfo().isActionSupportedForOnDelete(CascadeActionEnum.RESTRICT)) { - final String modelXml = - "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ - "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ - " <table name='roundtrip_1'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " </table>\n"+ - " <table name='roundtrip_2'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " <column name='avalue' type='INTEGER' required='true'/>\n"+ - " <foreign-key foreignTable='roundtrip_1' onDelete='restrict'>\n"+ - " <reference local='avalue' foreign='pk'/>\n"+ - " </foreign-key>\n"+ - " </table>\n"+ - "</database>"; - - performConstraintsTest(modelXml, true); - - insertRow("roundtrip_1", new Object[] { new Integer(1) }); - insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); - - List beansTable1 = getRows("roundtrip_1"); - List beansTable2 = getRows("roundtrip_2"); - - assertEquals(1, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(1), beansTable1.get(0), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals(new Integer(1), beansTable2.get(0), "avalue"); - - try - { - deleteRow("roundtrip_1", new Object[] { new Integer(1) }); - fail(); - } - catch (DdlUtilsException ex) - {} + return; + } + + final String modelXml = + "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ + " <table name='roundtrip_1'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " </table>\n"+ + " <table name='roundtrip_2'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " <column name='avalue' type='INTEGER' required='true'/>\n"+ + " <foreign-key foreignTable='roundtrip_1' onDelete='restrict'>\n"+ + " <reference local='avalue' foreign='pk'/>\n"+ + " </foreign-key>\n"+ + " </table>\n"+ + "</database>"; + + performConstraintsTest(modelXml, true); + + insertRow("roundtrip_1", new Object[] { new Integer(1) }); + insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); + + List beansTable1 = getRows("roundtrip_1"); + List beansTable2 = getRows("roundtrip_2"); + + assertEquals(1, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(1), beansTable1.get(0), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(1), beansTable2.get(0), "avalue"); + + try + { + deleteRow("roundtrip_1", new Object[] { new Integer(1) }); + fail(); } + catch (DdlUtilsException ex) + {} } /** @@ -531,6 +530,11 @@ */ public void testForeignKeyWithOnDeleteCascade() { + if (!getPlatformInfo().isActionSupportedForOnDelete(CascadeActionEnum.CASCADE)) + { + return; + } + final String modelXml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ @@ -574,6 +578,11 @@ */ public void testForeignKeyWithOnDeleteSetNull() { + if (!getPlatformInfo().isActionSupportedForOnDelete(CascadeActionEnum.SET_NULL)) + { + return; + } + final String modelXml = "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ @@ -615,56 +624,56 @@ } /** - * Tests two tables with a foreign key with a det-default onDelete action. + * Tests two tables with a foreign key with a set-default onDelete action. */ public void testForeignKeyWithOnDeleteSetDefault() { - if (!DerbyPlatform.DATABASENAME.equals(getPlatform().getName()) && - !MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) && - !MySql50Platform.DATABASENAME.equals(getPlatform().getName())) - { - final String modelXml = - "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ - "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ - " <table name='roundtrip_1'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " </table>\n"+ - " <table name='roundtrip_2'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " <column name='avalue' type='INTEGER' required='false' default='2'/>\n"+ - " <foreign-key foreignTable='roundtrip_1' onDelete='setdefault'>\n"+ - " <reference local='avalue' foreign='pk'/>\n"+ - " </foreign-key>\n"+ - " </table>\n"+ - "</database>"; - - performConstraintsTest(modelXml, true); - - insertRow("roundtrip_1", new Object[] { new Integer(1) }); - insertRow("roundtrip_1", new Object[] { new Integer(2) }); - insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); - - List beansTable1 = getRows("roundtrip_1"); - List beansTable2 = getRows("roundtrip_2"); - - assertEquals(2, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(1), beansTable1.get(0), "pk"); - assertEquals(new Integer(2), beansTable1.get(1), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals(new Integer(1), beansTable2.get(0), "avalue"); - - deleteRow("roundtrip_1", new Object[] { new Integer(1) }); - - beansTable1 = getRows("roundtrip_1"); - beansTable2 = getRows("roundtrip_2"); - - assertEquals(1, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(2), beansTable1.get(0), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals(new Integer(2), beansTable2.get(0), "avalue"); + if (!getPlatformInfo().isActionSupportedForOnDelete(CascadeActionEnum.SET_DEFAULT)) + { + return; } + + final String modelXml = + "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ + " <table name='roundtrip_1'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " </table>\n"+ + " <table name='roundtrip_2'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " <column name='avalue' type='INTEGER' required='false' default='2'/>\n"+ + " <foreign-key foreignTable='roundtrip_1' onDelete='setdefault'>\n"+ + " <reference local='avalue' foreign='pk'/>\n"+ + " </foreign-key>\n"+ + " </table>\n"+ + "</database>"; + + performConstraintsTest(modelXml, true); + + insertRow("roundtrip_1", new Object[] { new Integer(1) }); + insertRow("roundtrip_1", new Object[] { new Integer(2) }); + insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); + + List beansTable1 = getRows("roundtrip_1"); + List beansTable2 = getRows("roundtrip_2"); + + assertEquals(2, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(1), beansTable1.get(0), "pk"); + assertEquals(new Integer(2), beansTable1.get(1), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(1), beansTable2.get(0), "avalue"); + + deleteRow("roundtrip_1", new Object[] { new Integer(1) }); + + beansTable1 = getRows("roundtrip_1"); + beansTable2 = getRows("roundtrip_2"); + + assertEquals(1, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(2), beansTable1.get(0), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(2), beansTable2.get(0), "avalue"); } /** @@ -672,45 +681,47 @@ */ public void testForeignKeyWithOnUpdateRestrict() { - if (!FirebirdPlatform.DATABASENAME.equals(getPlatform().getName())) + if (!getPlatformInfo().isActionSupportedForOnUpdate(CascadeActionEnum.RESTRICT)) { - final String modelXml = - "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ - "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ - " <table name='roundtrip_1'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " </table>\n"+ - " <table name='roundtrip_2'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " <column name='avalue' type='INTEGER' required='true'/>\n"+ - " <foreign-key foreignTable='roundtrip_1' onUpdate='restrict'>\n"+ - " <reference local='avalue' foreign='pk'/>\n"+ - " </foreign-key>\n"+ - " </table>\n"+ - "</database>"; - - performConstraintsTest(modelXml, true); - - insertRow("roundtrip_1", new Object[] { new Integer(1) }); - insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); - - List beansTable1 = getRows("roundtrip_1"); - List beansTable2 = getRows("roundtrip_2"); - - assertEquals(1, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(1), beansTable1.get(0), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals(new Integer(1), beansTable2.get(0), "avalue"); - - try - { - updateRow("roundtrip_1", (DynaBean)beansTable1.get(0), new Object[] { new Integer(5) }); - fail(); - } - catch (DdlUtilsException ex) - {} + return; + } + + final String modelXml = + "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ + " <table name='roundtrip_1'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " </table>\n"+ + " <table name='roundtrip_2'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " <column name='avalue' type='INTEGER' required='true'/>\n"+ + " <foreign-key foreignTable='roundtrip_1' onUpdate='restrict'>\n"+ + " <reference local='avalue' foreign='pk'/>\n"+ + " </foreign-key>\n"+ + " </table>\n"+ + "</database>"; + + performConstraintsTest(modelXml, true); + + insertRow("roundtrip_1", new Object[] { new Integer(1) }); + insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); + + List beansTable1 = getRows("roundtrip_1"); + List beansTable2 = getRows("roundtrip_2"); + + assertEquals(1, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(1), beansTable1.get(0), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(1), beansTable2.get(0), "avalue"); + + try + { + updateRow("roundtrip_1", (DynaBean)beansTable1.get(0), new Object[] { new Integer(5) }); + fail(); } + catch (DdlUtilsException ex) + {} } /** @@ -718,48 +729,50 @@ */ public void testForeignKeyWithOnUpdateCascade() { - if (!DerbyPlatform.DATABASENAME.equals(getPlatform().getName())) + if (!getPlatformInfo().isActionSupportedForOnUpdate(CascadeActionEnum.CASCADE)) { - final String modelXml = - "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ - "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ - " <table name='roundtrip_1'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " </table>\n"+ - " <table name='roundtrip_2'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " <column name='avalue' type='INTEGER' required='true'/>\n"+ - " <foreign-key foreignTable='roundtrip_1' onUpdate='cascade'>\n"+ - " <reference local='avalue' foreign='pk'/>\n"+ - " </foreign-key>\n"+ - " </table>\n"+ - "</database>"; - - performConstraintsTest(modelXml, true); - - insertRow("roundtrip_1", new Object[] { new Integer(1) }); - insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); - - List beansTable1 = getRows("roundtrip_1"); - List beansTable2 = getRows("roundtrip_2"); - - assertEquals(1, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(1), beansTable1.get(0), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals(new Integer(1), beansTable2.get(0), "avalue"); - - updateRow("roundtrip_1", (DynaBean)beansTable1.get(0), new Object[] { new Integer(2) }); - - beansTable1 = getRows("roundtrip_1"); - beansTable2 = getRows("roundtrip_2"); - - assertEquals(1, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(2), beansTable1.get(0), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals(new Integer(2), beansTable2.get(0), "avalue"); + return; } + + final String modelXml = + "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ + " <table name='roundtrip_1'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " </table>\n"+ + " <table name='roundtrip_2'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " <column name='avalue' type='INTEGER' required='true'/>\n"+ + " <foreign-key foreignTable='roundtrip_1' onUpdate='cascade'>\n"+ + " <reference local='avalue' foreign='pk'/>\n"+ + " </foreign-key>\n"+ + " </table>\n"+ + "</database>"; + + performConstraintsTest(modelXml, true); + + insertRow("roundtrip_1", new Object[] { new Integer(1) }); + insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); + + List beansTable1 = getRows("roundtrip_1"); + List beansTable2 = getRows("roundtrip_2"); + + assertEquals(1, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(1), beansTable1.get(0), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(1), beansTable2.get(0), "avalue"); + + updateRow("roundtrip_1", (DynaBean)beansTable1.get(0), new Object[] { new Integer(2) }); + + beansTable1 = getRows("roundtrip_1"); + beansTable2 = getRows("roundtrip_2"); + + assertEquals(1, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(2), beansTable1.get(0), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(2), beansTable2.get(0), "avalue"); } /** @@ -767,48 +780,50 @@ */ public void testForeignKeyWithOnUpdateSetNull() { - if (!DerbyPlatform.DATABASENAME.equals(getPlatform().getName())) + if (!getPlatformInfo().isActionSupportedForOnUpdate(CascadeActionEnum.SET_NULL)) { - final String modelXml = - "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ - "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ - " <table name='roundtrip_1'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " </table>\n"+ - " <table name='roundtrip_2'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " <column name='avalue' type='INTEGER' required='false'/>\n"+ - " <foreign-key foreignTable='roundtrip_1' onUpdate='setnull'>\n"+ - " <reference local='avalue' foreign='pk'/>\n"+ - " </foreign-key>\n"+ - " </table>\n"+ - "</database>"; - - performConstraintsTest(modelXml, true); - - insertRow("roundtrip_1", new Object[] { new Integer(1) }); - insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); - - List beansTable1 = getRows("roundtrip_1"); - List beansTable2 = getRows("roundtrip_2"); - - assertEquals(1, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(1), beansTable1.get(0), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals(new Integer(1), beansTable2.get(0), "avalue"); - - updateRow("roundtrip_1", (DynaBean)beansTable1.get(0), new Object[] { new Integer(2) }); - - beansTable1 = getRows("roundtrip_1"); - beansTable2 = getRows("roundtrip_2"); - - assertEquals(1, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(2), beansTable1.get(0), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals((Object)null, beansTable2.get(0), "avalue"); + return; } + + final String modelXml = + "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ + " <table name='roundtrip_1'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " </table>\n"+ + " <table name='roundtrip_2'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " <column name='avalue' type='INTEGER' required='false'/>\n"+ + " <foreign-key foreignTable='roundtrip_1' onUpdate='setnull'>\n"+ + " <reference local='avalue' foreign='pk'/>\n"+ + " </foreign-key>\n"+ + " </table>\n"+ + "</database>"; + + performConstraintsTest(modelXml, true); + + insertRow("roundtrip_1", new Object[] { new Integer(1) }); + insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(1) }); + + List beansTable1 = getRows("roundtrip_1"); + List beansTable2 = getRows("roundtrip_2"); + + assertEquals(1, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(1), beansTable1.get(0), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(1), beansTable2.get(0), "avalue"); + + updateRow("roundtrip_1", (DynaBean)beansTable1.get(0), new Object[] { new Integer(2) }); + + beansTable1 = getRows("roundtrip_1"); + beansTable2 = getRows("roundtrip_2"); + + assertEquals(1, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(2), beansTable1.get(0), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals((Object)null, beansTable2.get(0), "avalue"); } /** @@ -816,52 +831,52 @@ */ public void testForeignKeyWithOnUpdateSetDefault() { - if (!DerbyPlatform.DATABASENAME.equals(getPlatform().getName()) && - !MySqlPlatform.DATABASENAME.equals(getPlatform().getName()) && - !MySql50Platform.DATABASENAME.equals(getPlatform().getName())) - { - final String modelXml = - "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ - "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ - " <table name='roundtrip_1'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " </table>\n"+ - " <table name='roundtrip_2'>\n"+ - " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ - " <column name='avalue' type='INTEGER' required='false' default='1'/>\n"+ - " <foreign-key foreignTable='roundtrip_1' onUpdate='setdefault'>\n"+ - " <reference local='avalue' foreign='pk'/>\n"+ - " </foreign-key>\n"+ - " </table>\n"+ - "</database>"; - - performConstraintsTest(modelXml, true); - - insertRow("roundtrip_1", new Object[] { new Integer(1) }); - insertRow("roundtrip_1", new Object[] { new Integer(2) }); - insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(2) }); - - List beansTable1 = getRows("roundtrip_1"); - List beansTable2 = getRows("roundtrip_2"); - - assertEquals(2, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(1), beansTable1.get(0), "pk"); - assertEquals(new Integer(2), beansTable1.get(1), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals(new Integer(2), beansTable2.get(0), "avalue"); - - updateRow("roundtrip_1", (DynaBean)beansTable1.get(1), new Object[] { new Integer(0) }); - - beansTable1 = getRows("roundtrip_1", "pk"); - beansTable2 = getRows("roundtrip_2", "pk"); - - assertEquals(2, beansTable1.size()); - assertEquals(1, beansTable2.size()); - assertEquals(new Integer(0), beansTable1.get(0), "pk"); - assertEquals(new Integer(1), beansTable1.get(1), "pk"); - assertEquals(new Integer(5), beansTable2.get(0), "pk"); - assertEquals(new Integer(1), beansTable2.get(0), "avalue"); + if (!getPlatformInfo().isActionSupportedForOnUpdate(CascadeActionEnum.SET_DEFAULT)) + { + return; } + + final String modelXml = + "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ + "<database xmlns='" + DatabaseIO.DDLUTILS_NAMESPACE + "' name='roundtriptest'>\n"+ + " <table name='roundtrip_1'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " </table>\n"+ + " <table name='roundtrip_2'>\n"+ + " <column name='pk' type='INTEGER' primaryKey='true' required='true'/>\n"+ + " <column name='avalue' type='INTEGER' required='false' default='1'/>\n"+ + " <foreign-key foreignTable='roundtrip_1' onUpdate='setdefault'>\n"+ + " <reference local='avalue' foreign='pk'/>\n"+ + " </foreign-key>\n"+ + " </table>\n"+ + "</database>"; + + performConstraintsTest(modelXml, true); + + insertRow("roundtrip_1", new Object[] { new Integer(1) }); + insertRow("roundtrip_1", new Object[] { new Integer(2) }); + insertRow("roundtrip_2", new Object[] { new Integer(5), new Integer(2) }); + + List beansTable1 = getRows("roundtrip_1"); + List beansTable2 = getRows("roundtrip_2"); + + assertEquals(2, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(1), beansTable1.get(0), "pk"); + assertEquals(new Integer(2), beansTable1.get(1), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(2), beansTable2.get(0), "avalue"); + + updateRow("roundtrip_1", (DynaBean)beansTable1.get(1), new Object[] { new Integer(0) }); + + beansTable1 = getRows("roundtrip_1", "pk"); + beansTable2 = getRows("roundtrip_2", "pk"); + + assertEquals(2, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(0), beansTable1.get(0), "pk"); + assertEquals(new Integer(1), beansTable1.get(1), "pk"); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(1), beansTable2.get(0), "avalue"); } }