Author: tfischer
Date: Thu Nov 29 19:52:03 2012
New Revision: 1415341
URL: http://svn.apache.org/viewvc?rev=1415341&view=rev
Log:
TORQUE-182 Additional methods for handling associated objects
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/setAndSaveReferencing.vm
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SetAndSaveTest.java
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/setAndSaveReferencing.vm
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/setAndSaveReferencing.vm?rev=1415341&r1=1415340&r2=1415341&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/setAndSaveReferencing.vm
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/setAndSaveReferencing.vm
Thu Nov 29 19:52:03 2012
@@ -235,11 +235,16 @@
else
{
toLinkTo.${adder}(toSaveElement);
+#if ($torqueGen.booleanOption("torque.om.trackNew"))
+ toSaveElement.setNew(false);
+#end
+#if ($torqueGen.booleanOption("torque.om.trackModified"))
if (!toSaveElement.valueEquals(intersection.get(listIndex)))
{
//force saving if content differs
toSaveElement.setModified(true);
}
+#end
#if ($saveMethodsInDbObjects != "true")
${foreignTablePeerClassName}.save(toSaveElement, connection);
#else
Modified:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SetAndSaveTest.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SetAndSaveTest.java?rev=1415341&r1=1415340&r2=1415341&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SetAndSaveTest.java
(original)
+++
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/SetAndSaveTest.java
Thu Nov 29 19:52:03 2012
@@ -441,10 +441,14 @@ public class SetAndSaveTest extends Base
OIntegerPk oIntegerPk = testData.getOIntegerPkList().get(2);
List<NullableOIntegerFk> fkList = new ArrayList<NullableOIntegerFk>();
- // object already associated to this object
+ // copy object already associated to this object
NullableOIntegerFk alreadyAssociated
- = testData.getNullableOIntegerFkList().get(1);
- alreadyAssociated.setName("modified");
+ = testData.getNullableOIntegerFkList().get(1).copy();
+ // id does not get copied, set manually
+ alreadyAssociated.setId(
+ testData.getNullableOIntegerFkList().get(1).getId());
+ alreadyAssociated.setName("modifiedName");
+ alreadyAssociated.setNew(true); // saving must also work with wrong
new flag
alreadyAssociated.setModified(false); // saving must work without the
modified flag
fkList.add(alreadyAssociated);
@@ -462,12 +466,17 @@ public class SetAndSaveTest extends Base
oIntegerPk.getId(),
cachedFks.get(0).getFk());
assertEquals(
- testData.getNullableOIntegerFkList().get(1).getName(),
+ "modifiedName",
cachedFks.get(0).getName());
// check database
+ List<NullableOIntegerFk>expectedInDb
+ = new ArrayList<NullableOIntegerFk>();
+ expectedInDb.addAll(cachedFks);
+ expectedInDb.add(testData.getNullableOIntegerFkList().get(0));
+ expectedInDb.add(testData.getNullableOIntegerFkList().get(3));
ForeignKeySchemaData.assertNullableOIntegerFksInDatabaseEquals(
- cachedFks);
+ expectedInDb);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]