Author: tomdz Date: Wed Sep 12 22:45:52 2007 New Revision: 575177 URL: http://svn.apache.org/viewvc?rev=575177&view=rev Log: Added support for handling platforms that don't support setDefault actions for onUpdate/onDelete
Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.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=575177&r1=575176&r2=575177&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/PlatformInfo.java Wed Sep 12 22:45:52 2007 @@ -56,6 +56,9 @@ /** Whether embedded foreign key constraints are explicitly named. */ private boolean _embeddedForeignKeysNamed = false; + /** Whether the set-default action is supportd for onDelete/onUpdate in a foreign key. */ + private boolean _setDefaultActionSupported = true; + /** Whether non-unique indices are supported. */ private boolean _indicesSupported = true; @@ -284,6 +287,28 @@ public void setEmbeddedForeignKeysNamed(boolean embeddedForeignKeysNamed) { _embeddedForeignKeysNamed = embeddedForeignKeysNamed; + } + + /** + * Determines whether the set-default action is supported for onUpdate/onDelete + * in foreign keys. + * + * @return <code>true</code> if set-default is supported + */ + public boolean isSetDefaultActionSupported() + { + return _setDefaultActionSupported; + } + + /** + * Specifies whether the set-default action is supported for onUpdate/onDelete + * in foreign keys. + * + * @param setDefaultActionSupported <code>true</code> if set-default is supported + */ + public void setSetDefaultActionSupported(boolean setDefaultActionSupported) + { + _setDefaultActionSupported = setDefaultActionSupported; } /** Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java?rev=575177&r1=575176&r2=575177&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/derby/DerbyPlatform.java Wed Sep 12 22:45:52 2007 @@ -51,6 +51,7 @@ public DerbyPlatform() { super(); + getPlatformInfo().setSetDefaultActionSupported(false); getPlatformInfo().addNativeTypeMapping(Types.DOUBLE, "DOUBLE"); getPlatformInfo().addNativeTypeMapping(Types.FLOAT, "DOUBLE", Types.DOUBLE); setSqlBuilder(new DerbyBuilder(this)); Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java?rev=575177&r1=575176&r2=575177&view=diff ============================================================================== --- db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java (original) +++ db/ddlutils/trunk/src/test/org/apache/ddlutils/io/TestConstraints.java Wed Sep 12 22:45:52 2007 @@ -509,7 +509,7 @@ } /** - * Tests two tables with a foreign key with a cascade onDelete action. + * Tests two tables with a foreign key with a set-null onDelete action. */ public void testForeignKeyWithOnDeleteSetNull() { @@ -551,5 +551,53 @@ assertEquals(1, beansTable2.size()); assertEquals(new Integer(5), beansTable2.get(0), "pk"); assertEquals((Object)null, beansTable2.get(0), "avalue"); + } + + /** + * Tests two tables with a foreign key with a det-default onDelete action. + */ + public void testForeignKeyWithOnDeleteSetDefault() + { + if (getPlatformInfo().isSetDefaultActionSupported()) + { + final String modelXml = + "<?xml version='1.0' encoding='ISO-8859-1'?>\n"+ + "<database 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='0'/>\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_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"); + + deleteRow("roundtrip_1", new Object[] { new Integer(1) }); + + beansTable1 = getRows("roundtrip_1"); + beansTable2 = getRows("roundtrip_2"); + + assertEquals(0, beansTable1.size()); + assertEquals(1, beansTable2.size()); + assertEquals(new Integer(5), beansTable2.get(0), "pk"); + assertEquals(new Integer(0), beansTable2.get(0), "avalue"); + } } }