* @throws Exception if a database error occurs
*/
public void testDeleteByCriteriaWithJoins() throws Exception
{
ForeignKeySchemaData.clearTablesInDatabase();
ForeignKeySchemaData testData
= ForeignKeySchemaData.getDefaultTestData();
testData.save();
// call delete method
Criteria criteria = new Criteria();
criteria.addJoin(
NullableOIntegerFkPeer.FK,
OIntegerPkPeer.ID,
Criteria.INNER_JOIN);
criteria.and(
OIntegerPkPeer.ID,
testData.getOIntegerPkList().get(0).getId());
try
{
int deletedCount = NullableOIntegerFkPeer.doDelete(criteria);
assertEquals(1, deletedCount);
}
catch (TorqueException e)
{
log.debug("Delete by joins does not work for this database.");
return;
}
// check that the last two entries remains in the NullableOIntegerFk
// table
List<NullableOIntegerFk> nullableOIntegerFkList
= getNullableOIntegerFkList();
assertEquals(2, nullableOIntegerFkList.size());
assertTrue(nullableOIntegerFkList.contains(
testData.getNullableOIntegerFkList().get(1)));
assertTrue(nullableOIntegerFkList.contains(
testData.getNullableOIntegerFkList().get(2)));
// check that no associated object has been deleted
List<OIntegerPk> oIntegerPkList
= OIntegerPkPeer.doSelect(new Criteria());
assertEquals(3, oIntegerPkList.size());