Author: tfischer
Date: Thu Apr 5 11:57:57 2012
New Revision: 1309800
URL: http://svn.apache.org/viewvc?rev=1309800&view=rev
Log:
TORQUE-116: add a isDeleted() getter for data objects
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedField.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedMethods.vm
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doDelete.vm
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties?rev=1309800&r1=1309799&r2=1309800&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/conf/options.properties
Thu Apr 5 11:57:57 2012
@@ -86,6 +86,8 @@ torque.om.trackModified = true
# or an update command is used when saving, thus, trackNew needs to be set
# to true if addSaveMethods is true
torque.om.trackNew = true
+# Whether it should be tracked if objects were deleted from the database.
+torque.om.trackDeleted = true
# Whether it should be tracked if objects are currently saved.
# This needs to be set to true if torque.om.complexObjectModel is true
# and torque.om.objectIsCaching is true to prevent recursive save calls
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml?rev=1309800&r1=1309799&r2=1309800&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/outlets/dbObject.xml
Thu Apr 5 11:57:57 2012
@@ -60,6 +60,10 @@
<action xsi:type="applyAction"
outlet="torque.om.dbObject.base.newModifiedFields"/>
</mergepoint>
+ <mergepoint name="deletedField">
+ <action xsi:type="applyAction"
+ outlet="torque.om.dbObject.base.deletedField"/>
+ </mergepoint>
<mergepoint name="savingField">
<action xsi:type="applyAction"
outlet="torque.om.dbObject.base.savingField"/>
@@ -87,6 +91,10 @@
<action xsi:type="applyAction"
outlet="torque.om.dbObject.base.newModifiedMethods"/>
</mergepoint>
+ <mergepoint name="deletedMethods">
+ <action xsi:type="applyAction"
+ outlet="torque.om.dbObject.base.deletedMethods"/>
+ </mergepoint>
<mergepoint name="savingMethods">
<action xsi:type="applyAction"
outlet="torque.om.dbObject.base.savingMethods"/>
@@ -238,6 +246,11 @@
path="dbObject/base/newModifiedFields.vm">
</outlet>
+ <outlet name="torque.om.dbObject.base.deletedField"
+ xsi:type="velocityOutlet"
+ path="dbObject/base/deletedField.vm">
+ </outlet>
+
<outlet name="torque.om.dbObject.base.savingField"
xsi:type="velocityOutlet"
path="dbObject/base/savingField.vm">
@@ -268,6 +281,11 @@
path="dbObject/base/newModifiedMethods.vm">
</outlet>
+ <outlet name="torque.om.dbObject.base.deletedMethods"
+ xsi:type="velocityOutlet"
+ path="dbObject/base/deletedMethods.vm">
+ </outlet>
+
<outlet name="torque.om.dbObject.base.savingMethods"
xsi:type="velocityOutlet"
path="dbObject/base/savingMethods.vm">
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm?rev=1309800&r1=1309799&r2=1309800&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/baseDbObject.vm
Thu Apr 5 11:57:57 2012
@@ -100,12 +100,15 @@ $torqueGen.mergepoint("serialVersionUid"
## field definitions for columns
$torqueGen.mergepoint("fieldDefinitions")##
$torqueGen.mergepoint("newModifiedFields")##
-#if ($torqueGen.booleanOption("torque.om.trackSaving"))
+#if ($trackSaving == "true")
$torqueGen.mergepoint("savingField")##
#end
-#if ($torqueGen.booleanOption("torque.om.trackLoading"))
+#if ($trackLoading == "true")
$torqueGen.mergepoint("loadingField")##
#end
+#if ($trackDeleted == "true")
+$torqueGen.mergepoint("deletedField")##
+#end
##
## field definitions for referenced objects
#if ($torqueGen.booleanOption("torque.om.complexObjectModel"))
@@ -120,12 +123,15 @@ $torqueGen.mergepoint("fieldDefinitionsR
## getters and setters for member variables for columns
$torqueGen.mergepoint("gettersSetters")
$torqueGen.mergepoint("newModifiedMethods")
-#if ($torqueGen.booleanOption("torque.om.trackSaving"))
+#if ($trackSaving == "true")
$torqueGen.mergepoint("savingMethods")
#end
#if ($trackLoading == "true")
$torqueGen.mergepoint("loadingMethods")
#end
+#if ($trackDeleted == "true")
+$torqueGen.mergepoint("deletedMethods")
+#end
#if ($torqueGen.booleanOption("torque.om.complexObjectModel"))
$torqueGen.mergepoint("gettersSettersReferencedObjects")
#end
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedField.vm
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedField.vm?rev=1309800&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedField.vm
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedField.vm
Thu Apr 5 11:57:57 2012
@@ -0,0 +1,30 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26
Aug 2005) tfischer $
+##
+## This template creates the deleted field for a BaseDBObject.
+##
+ /**
+ * Flag which indicates whether this object was deleted from the database.
+ * Note that this flags does not always display the current database state,
+ * there is no magical connection between this flag and the database.
+ */
+ private boolean deleted = false;
+
Added:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedMethods.vm
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedMethods.vm?rev=1309800&view=auto
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedMethods.vm
(added)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/dbObject/base/deletedMethods.vm
Thu Apr 5 11:57:57 2012
@@ -0,0 +1,50 @@
+## Licensed to the Apache Software Foundation (ASF) under one
+## or more contributor license agreements. See the NOTICE file
+## distributed with this work for additional information
+## regarding copyright ownership. The ASF licenses this file
+## to you under the Apache License, Version 2.0 (the
+## "License"); you may not use this file except in compliance
+## with the License. You may obtain a copy of the License at
+##
+## http://www.apache.org/licenses/LICENSE-2.0
+##
+## Unless required by applicable law or agreed to in writing,
+## software distributed under the License is distributed on an
+## "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+## KIND, either express or implied. See the License for the
+## specific language governing permissions and limitations
+## under the License.
+##
+######
+##
+## version $Id: MultiExtendBean.vm 240328 2005-08-26 22:02:48 +0200 (Fr, 26
Aug 2005) tfischer $
+##
+## This template creates the getters and setters for the deleted field
+## for a BaseDBObject.
+##
+ /**
+ * Returns whether this object was deleted from the database.
+ * Note that this getter does not automatically reflect database state,
+ * it will be set to true by Torque if doDelete() was called with this
+ * object. Bulk deletes and deletes via primary key do not change
+ * this flag. Also, if doDelete() was called on an object which does
+ * not exist in the database, the deleted flag is set to true even if
+ * it was not deleted.
+ *
+ * @return true if this object was deleted, false otherwise.
+ */
+ public boolean isDeleted()
+ {
+ return deleted;
+ }
+
+ /**
+ * Sets whether this object was deleted from the database.
+ *
+ * @param deleted true if this object was deleted, false otherwise.
+ */
+ public void setDeleted(boolean deleted)
+ {
+ this.deleted = deleted;
+ }
+
Modified:
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doDelete.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/doDelete.vm?rev=1309800&r1=1309799&r2=1309800&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doDelete.vm
(original)
+++
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doDelete.vm
Thu Apr 5 11:57:57 2012
@@ -95,10 +95,14 @@
{
#set ( $primaryKeyColumnElements =
$torqueGen.getChild("primary-keys").getChildren("column"))
#if ($primaryKeyColumnElements.size() > 0)
- return doDelete(buildCriteria(obj.getPrimaryKey()));
+ int result = doDelete(buildCriteria(obj.getPrimaryKey()));
#else
- return doDelete(buildSelectCriteria(obj), getTableMap());
+ int result = doDelete(buildSelectCriteria(obj), getTableMap());
#end
+#if ($trackDeleted == "true")
+ obj.setDeleted(true);
+#end
+ return result;
}
/**
@@ -118,10 +122,14 @@
throws TorqueException
{
#if ($primaryKeyColumnElements.size() > 0)
- return doDelete(buildCriteria(obj.getPrimaryKey()), getTableMap(),
con);
+ int result = doDelete(buildCriteria(obj.getPrimaryKey()),
getTableMap(), con);
#else
- return doDelete(buildSelectCriteria(obj), getTableMap(), con);
+ int result = doDelete(buildSelectCriteria(obj), getTableMap(), con);
+#end
+#if ($trackDeleted == "true")
+ obj.setDeleted(true);
#end
+ return result;
}
#if (!$primaryKeyColumnElements.isEmpty())
@@ -139,7 +147,14 @@
public int doDelete(Collection<${dbObjectClassName}> objects)
throws TorqueException
{
- return doDelete(buildPkCriteria(objects), getTableMap());
+ int result = doDelete(buildPkCriteria(objects), getTableMap());
+#if ($trackDeleted == "true")
+ for (${dbObjectClassName} object : objects)
+ {
+ object.setDeleted(true);
+ }
+#end
+ return result;
}
/**
@@ -148,7 +163,7 @@
* if a transaction is open in the connection, the deletion happens inside
* this transaction.
*
- * @param objects the datas object to delete in the database, not null,
+ * @param objects the data objects to delete in the database, not null,
* may not contain null.
* @param con the connection to use for deleting, not null.
*
@@ -162,7 +177,14 @@
Connection con)
throws TorqueException
{
- return doDelete(buildPkCriteria(objects), getTableMap(), con);
+ int result = doDelete(buildPkCriteria(objects), getTableMap(), con);
+#if ($trackDeleted == "true")
+ for (${dbObjectClassName} object : objects)
+ {
+ object.setDeleted(true);
+ }
+#end
+ return result;
}
/**
Modified:
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java?rev=1309800&r1=1309799&r2=1309800&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java
(original)
+++
db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/generated/peer/DeleteTest.java
Thu Apr 5 11:57:57 2012
@@ -141,6 +141,9 @@ public class DeleteTest extends BaseData
toDelete.setName("nullableOIntegerFk2Changed");
int preDeleteId = toDelete.getId();
+ // check that isDeleted() is false before deletion
+ assertFalse(toDelete.isDeleted());
+
// check that three entries are in the NullableOIntegerFk table
List<NullableOIntegerFk> nullableOIntegerFkList
= getNullableOIntegerFkList();
@@ -151,6 +154,7 @@ public class DeleteTest extends BaseData
int deleted = NullableOIntegerFkPeer.doDelete(toDelete);
assertEquals(1, deleted);
assertEquals(preDeleteId, toDelete.getId().intValue());
+ assertTrue(toDelete.isDeleted());
// check that there are two entries remaining in the database
// and the toDelete object was deleted
@@ -173,6 +177,8 @@ public class DeleteTest extends BaseData
Nopk toDelete = testData.getNopkList().get(1);
+ // check that isDeleted() is false before deletion
+ assertFalse(toDelete.isDeleted());
// check that three entries are in the Nopk table
List<Nopk> nopkList = getNopkList();
assertEquals(3, nopkList.size());
@@ -183,6 +189,7 @@ public class DeleteTest extends BaseData
// call delete method and check result.
int deleted = NopkPeer.doDelete(toDelete);
assertEquals(1, deleted);
+ assertTrue(toDelete.isDeleted());
// check that there are two entries remaining in the database
// and the toDelete object was deleted
@@ -218,6 +225,8 @@ public class DeleteTest extends BaseData
// call delete method and check result.
int deleted = NopkPeer.doDelete(toDelete);
assertEquals(0, deleted);
+ // flag is true even if nothing was deleted
+ assertTrue(toDelete.isDeleted());
// check that there are all entries remaining in the database
// and the toDelete object is still there
@@ -248,6 +257,9 @@ public class DeleteTest extends BaseData
preDeleteIds.add(toDelete.get(0).getId());
preDeleteIds.add(toDelete.get(1).getId());
+ // check that isDeleted() is false before deletion
+ assertFalse(toDelete.get(0).isDeleted());
+ assertFalse(toDelete.get(1).isDeleted());
// check that three entries are in the NullableOIntegerFk table
List<NullableOIntegerFk> nullableOIntegerFkList
= getNullableOIntegerFkList();
@@ -261,6 +273,8 @@ public class DeleteTest extends BaseData
assertEquals(2, deleted);
assertEquals(preDeleteIds.get(0), toDelete.get(0).getId());
assertEquals(preDeleteIds.get(1), toDelete.get(1).getId());
+ assertTrue(toDelete.get(0).isDeleted());
+ assertTrue(toDelete.get(1).isDeleted());
// check that there is one entries remaining in the database
// and the objects contained in toDelete object were deleted
@@ -295,6 +309,9 @@ public class DeleteTest extends BaseData
toDelete.get(0).setId(toDelete.get(0).getId() - 1);
int preDeleteId = toDelete.get(0).getId();
+ // check that isDeleted() is false before deletion
+ assertFalse(toDelete.get(0).isDeleted());
+ assertFalse(toDelete.get(1).isDeleted());
// check that three entries are in the NullableOIntegerFk table
// prior to deletion
List<NullableOIntegerFk> nullableOIntegerFkList
@@ -307,6 +324,9 @@ public class DeleteTest extends BaseData
int deleted = NullableOIntegerFkPeer.doDelete(toDelete);
assertEquals(1, deleted);
assertEquals(preDeleteId, toDelete.get(0).getId().intValue());
+ // flag is true even if the object was not deleted
+ assertTrue(toDelete.get(0).isDeleted());
+ assertTrue(toDelete.get(1).isDeleted());
// check that two entries remain in the database
nullableOIntegerFkList = getNullableOIntegerFkList();
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]