Author: tv
Date: Fri Aug 5 10:25:31 2016
New Revision: 1755276
URL: http://svn.apache.org/viewvc?rev=1755276&view=rev
Log:
TORQUE-346: Move some doDelete methods
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/impl/base/doDelete.vm
Modified:
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
URL:
http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java?rev=1755276&r1=1755275&r2=1755276&view=diff
==============================================================================
---
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
(original)
+++
db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/AbstractPeerImpl.java
Fri Aug 5 10:25:31 2016
@@ -81,6 +81,20 @@ public abstract class AbstractPeerImpl<T
public abstract Criteria buildSelectCriteria(T obj);
/**
+ * Build a Criteria object which selects all objects which have a given
+ * primary key.
+ *
+ * This method should never be called because if the table has a primary
key,
+ * it must be overridden in the generated code.
+ *
+ * @param pk the primary key value to build the criteria from, not null.
+ */
+ public Criteria buildCriteria(ObjectKey pk)
+ {
+ throw new RuntimeException("buildCriteria(ObjectKey) called on table
without primary key");
+ }
+
+ /**
* Returns the contents of the object as ColumnValues object.
* Primary key columns which are generated on insertion are not
* added to the returned object if they still have their initial
@@ -233,4 +247,53 @@ public abstract class AbstractPeerImpl<T
obj.setModified(false);
return result;
}
+
+ /**
+ * Deletes a row in the database.
+ *
+ * @param pk the ObjectKey that identifies the row to delete.
+ *
+ * @return the number of deleted rows.
+ *
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
+ */
+ public int doDelete(ObjectKey pk) throws TorqueException
+ {
+ Connection connection = null;
+ try
+ {
+ connection = Transaction.begin(getDatabaseName());
+ int deletedRows = doDelete(pk, connection);
+ Transaction.commit(connection);
+ connection = null;
+ return deletedRows;
+ }
+ finally
+ {
+ if (connection != null)
+ {
+ Transaction.safeRollback(connection);
+ }
+ }
+ }
+
+ /**
+ * Deletes a row in the database.
+ * This method is to be used during a transaction,
+ * otherwise use the doDelete(ObjectKey) method.
+ *
+ * @param pk the ObjectKey that identifies the row to delete.
+ * @param con the connection to use for deleting, not null.
+ *
+ * @return the number of deleted rows.
+ *
+ * @throws TorqueException Any exceptions caught during processing will be
+ * rethrown wrapped into a TorqueException.
+ */
+ public int doDelete(ObjectKey pk, Connection con)
+ throws TorqueException
+ {
+ return doDelete(buildCriteria(pk), con);
+ }
}
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=1755276&r1=1755275&r2=1755276&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
Fri Aug 5 10:25:31 2016
@@ -132,53 +132,4 @@
#end
return result;
}
-
- /**
- * Deletes a row in the database.
- *
- * @param pk the ObjectKey that identifies the row to delete.
- *
- * @return the number of deleted rows.
- *
- * @throws TorqueException Any exceptions caught during processing will be
- * rethrown wrapped into a TorqueException.
- */
- public int doDelete(ObjectKey pk) throws TorqueException
- {
- Connection connection = null;
- try
- {
- connection = Transaction.begin(getDatabaseName());
- int deletedRows = doDelete(pk, connection);
- Transaction.commit(connection);
- connection = null;
- return deletedRows;
- }
- finally
- {
- if (connection != null)
- {
- Transaction.safeRollback(connection);
- }
- }
- }
-
- /**
- * Deletes a row in the database.
- * This method is to be used during a transaction,
- * otherwise use the doDelete(ObjectKey) method.
- *
- * @param pk the ObjectKey that identifies the row to delete.
- * @param con the connection to use for deleting, not null.
- *
- * @return the number of deleted rows.
- *
- * @throws TorqueException Any exceptions caught during processing will be
- * rethrown wrapped into a TorqueException.
- */
- public int doDelete(ObjectKey pk, Connection con)
- throws TorqueException
- {
- return doDelete(buildCriteria(pk), con);
- }
#end
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]