You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by tf...@apache.org on 2011/05/15 21:37:42 UTC

svn commit: r1103512 - in /db/torque/torque4/trunk: torque-runtime/src/main/java/org/apache/torque/util/ torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/ torque-templates/src/main/resources/org/apache/torque/templ...

Author: tfischer
Date: Sun May 15 19:37:41 2011
New Revision: 1103512

URL: http://svn.apache.org/viewvc?rev=1103512&view=rev
Log:
TORQUE-13: return the number of deleted datasets in doDelete methods

Modified:
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java
    db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
    db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/doDelete.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/DataTest.java

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java?rev=1103512&r1=1103511&r2=1103512&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeer.java Sun May 15 19:37:41 2011
@@ -109,17 +109,25 @@ public abstract class BasePeer
      * @param table The table to delete records from.
      * @param column The column in the where clause.
      * @param value The value of the column.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
+     *
+     * @deprecated The value is not SQL escaped.
+     *             Better use doDelete(Criteria, String, Connection)
+     *             for automatic escaping and more flexibility.
+     *             This method will be removed in a future version of Torque.
      */
-    public static void deleteAll(
+    public static int deleteAll(
         Connection con,
         String table,
         String column,
         int value)
         throws TorqueException
     {
-        getBasePeerImpl().deleteAll(con, table, column, value);
+        return getBasePeerImpl().deleteAll(con, table, column, value);
     }
 
     /**
@@ -131,13 +139,21 @@ public abstract class BasePeer
      * @param table The table to delete records from.
      * @param column The column in the where clause.
      * @param value The value of the column.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
+     *
+     * @deprecated The value is not SQL escaped.
+     *             Better use doDelete(Criteria, String)
+     *             for automatic escaping and more flexibility.
+     *             This method will be removed in a future version of Torque.
      */
-    public static void deleteAll(String table, String column, int value)
+    public static int deleteAll(String table, String column, int value)
         throws TorqueException
     {
-        getBasePeerImpl().deleteAll(table, column, value);
+        return getBasePeerImpl().deleteAll(table, column, value);
     }
 
     /**
@@ -145,14 +161,17 @@ public abstract class BasePeer
      * Criteria.
      *
      * @param criteria The criteria to use.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      * @deprecated This method causes unexpected results when joins are used.
      *              Please use doDelete(Criteria, String).
      */
-    public static void doDelete(Criteria criteria) throws TorqueException
+    public static int doDelete(Criteria criteria) throws TorqueException
     {
-        getBasePeerImpl().doDelete(criteria);
+        return getBasePeerImpl().doDelete(criteria);
     }
 
     /**
@@ -166,13 +185,16 @@ public abstract class BasePeer
      * @param tableName the name of the table to delete records from.
      *         If set to null, the name of the table(s) can be extracted from
      *         the criteria, but this can cause unexpected results.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    protected static void doDelete(Criteria criteria, String tableName)
+    public static int doDelete(Criteria criteria, String tableName)
             throws TorqueException
     {
-        getBasePeerImpl().doDelete(criteria, tableName);
+        return getBasePeerImpl().doDelete(criteria, tableName);
     }
 
     /**
@@ -180,15 +202,19 @@ public abstract class BasePeer
      *
      * @param criteria The criteria to use.
      * @param con A Connection.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
+     *
      * @deprecated This method causes unexpected results when joins are used.
      *              Please use doDelete(Criteria, String, Connection).
      */
-    public static void doDelete(Criteria criteria, Connection con)
+    public static int doDelete(Criteria criteria, Connection con)
         throws TorqueException
     {
-        getBasePeerImpl().doDelete(criteria, con);
+        return getBasePeerImpl().doDelete(criteria, con);
     }
 
     /**

Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java?rev=1103512&r1=1103511&r2=1103512&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java (original)
+++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/BasePeerImpl.java Sun May 15 19:37:41 2011
@@ -111,17 +111,24 @@ public class BasePeerImpl implements Ser
 
     /**
      * Convenience method that uses straight JDBC to delete multiple
-     * rows.  Village throws an Exception when multiple rows are
-     * deleted.
+     * rows.
      *
      * @param con A Connection.
      * @param table The table to delete records from.
      * @param column The column in the where clause.
      * @param value The value of the column.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
+     *
+     * @deprecated The value is not SQL escaped.
+     *             Better use doDelete(Criteria, String, Connection)
+     *             for automatic escaping and more flexibility.
+     *             This method will be removed in a future version of Torque.
      */
-    public void deleteAll(
+    public int deleteAll(
         Connection con,
         String table,
         String column,
@@ -141,7 +148,7 @@ public class BasePeerImpl implements Ser
                 .append(" = ")
                 .append(value);
 
-            statement.executeUpdate(query.toString());
+            return statement.executeUpdate(query.toString());
         }
         catch (SQLException e)
         {
@@ -165,17 +172,24 @@ public class BasePeerImpl implements Ser
 
     /**
      * Convenience method that uses straight JDBC to delete multiple
-     * rows.  Village throws an Exception when multiple rows are
-     * deleted.  This method attempts to get the default database from
+     * rows. This method attempts to get the default database from
      * the pool.
      *
      * @param table The table to delete records from.
      * @param column The column in the where clause.
      * @param value The value of the column.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
+     *
+     * @deprecated The value is not SQL escaped.
+     *             Better use doDelete(Criteria, String)
+     *             for automatic escaping and more flexibility.
+     *             This method will be removed in a future version of Torque.
      */
-    public void deleteAll(String table, String column, int value)
+    public int deleteAll(String table, String column, int value)
         throws TorqueException
     {
         Connection con = null;
@@ -183,7 +197,7 @@ public class BasePeerImpl implements Ser
         {
             // Get a connection to the db.
             con = Torque.getConnection(Torque.getDefaultDB());
-            deleteAll(con, table, column, value);
+            return deleteAll(con, table, column, value);
         }
         finally
         {
@@ -196,14 +210,18 @@ public class BasePeerImpl implements Ser
      * Criteria.
      *
      * @param criteria The criteria to use.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
+     *
      * @deprecated This method causes unexpected results when joins are used.
      *              Please use doDelete(Criteria, String).
      */
-    protected void doDelete(Criteria criteria) throws TorqueException
+    protected int doDelete(Criteria criteria) throws TorqueException
     {
-        doDelete(criteria, (String) null);
+        return doDelete(criteria, (String) null);
     }
 
     /**
@@ -214,10 +232,13 @@ public class BasePeerImpl implements Ser
      * @param tableName the name of the table to delete records from.
      *         If set to null, the name of the table(s) can be extracted from
      *         the criteria, but this can cause unexpected results.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public void doDelete(Criteria criteria, String tableName)
+    public int doDelete(Criteria criteria, String tableName)
             throws TorqueException
     {
         Connection con = null;
@@ -226,8 +247,9 @@ public class BasePeerImpl implements Ser
             con = Transaction.beginOptional(
                     criteria.getDbName(),
                     criteria.isUseTransaction());
-            doDelete(criteria, tableName, con);
+            int result = doDelete(criteria, tableName, con);
             Transaction.commit(con);
+            return result;
         }
         catch (TorqueException e)
         {
@@ -240,13 +262,16 @@ public class BasePeerImpl implements Ser
      * Method to perform deletes based on values and keys in a Criteria.
      *
      * @param criteria The criteria to use.
-     * @param con A Connection.
+     * @param con the Connection to be used for deleting.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      * @deprecated This method causes unexpected results when joins are used.
      *              Please use doDelete(Criteria, String, Connection).
      */
-    protected void doDelete(Criteria criteria, Connection con)
+    protected int doDelete(Criteria criteria, Connection con)
         throws TorqueException
     {
         Criteria.Criterion criterion
@@ -256,7 +281,7 @@ public class BasePeerImpl implements Ser
         {
             throw new TorqueException("Unqualified column name in criteria");
         }
-        doDelete(criteria, tableName, con);
+        return doDelete(criteria, tableName, con);
     }
 
     /**
@@ -267,6 +292,8 @@ public class BasePeerImpl implements Ser
      * @param tableName the name of the table to delete records from, not null.
      * @param con The database connection for deletion, not null.
      *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
@@ -1169,8 +1196,8 @@ public class BasePeerImpl implements Ser
 
         if (pk != null && updateValues.containsKey(pk.getFullyQualifiedName()))
         {
-            selectCriteria = new Criteria(2);
-            selectCriteria.put(pk.getFullyQualifiedName(),
+            selectCriteria = new Criteria();
+            selectCriteria.add(pk.getFullyQualifiedName(),
                 updateValues.remove(pk.getFullyQualifiedName()));
         }
         else

Modified: db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/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/base/doDelete.vm?rev=1103512&r1=1103511&r2=1103512&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/doDelete.vm (original)
+++ db/torque/torque4/trunk/torque-templates/src/main/resources/org/apache/torque/templates/om/templates/peer/base/doDelete.vm Sun May 15 19:37:41 2011
@@ -28,85 +28,103 @@
 ## as velocity variables.  
 ##
     /**
-     * Method to do deletes.
+     * Deletes rows from a database table.
+     *
+     * @param criteria defines the rows to be deleted, not null.
+     *
+     * @return the number of deleted rows.
      *
-     * @param criteria object containing data that is used DELETE from database.
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-     public static void doDelete(Criteria criteria) throws TorqueException
+     public static int doDelete(Criteria criteria) throws TorqueException
      {
-        ${peerImplGetter}().doDelete(criteria);
+        return ${peerImplGetter}().doDelete(criteria);
      }
 
     /**
-     * Method to do deletes.  This method is to be used during a transaction,
-     * otherwise use the doDelete(Criteria) method.  It will take care of
-     * the connection details internally.
+     * Deletes rows from a table.  This method is to be used 
+     * during a transaction, otherwise use the doDelete(Criteria) method.
+      *
+     * @param criteria defines the rows to be deleted, not null.
+     * @param con the connection to use, not null.
+     *
+     * @return the number of deleted rows.
      *
-     * @param criteria object containing data that is used DELETE from database.
-     * @param con the connection to use
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-     public static void doDelete(Criteria criteria, Connection con)
+     public static int doDelete(Criteria criteria, Connection con)
         throws TorqueException
      {
-        ${peerImplGetter}().doDelete(criteria, con);
+        return ${peerImplGetter}().doDelete(criteria, con);
      }
 
     /**
-     * Method to delete.
-     * @param obj the data object to delete in the database.
+     * Deletes a data object, i.e. a row in a table, in the database.
+     *
+     * @param obj the data object to delete in the database, not null.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public static void doDelete($dbObjectClassName obj) throws TorqueException
+    public static int doDelete($dbObjectClassName obj) throws TorqueException
     {
-        ${peerImplGetter}().doDelete(obj);
+        return ${peerImplGetter}().doDelete(obj);
     }
 
     /**
-     * Method to delete.  This method is to be used during a transaction,
-     * otherwise use the doDelete($dbObjectClassName) method.  It will take
-     * care of the connection details internally.
+     * Deletes a data object, i.e. a row in a table, in the database.
+     * This method is to be used during a transaction, otherwise use the
+     * doDelete($dbObjectClassName) method.
+     *
+     * @param obj the data object to delete in the database, not null.
+     * @param con the connection to use, not null.
+     *
+     * @return the number of deleted rows.
      *
-     * @param obj the data object to delete in the database.
-     * @param con the connection to use
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public static void doDelete($dbObjectClassName obj, Connection con)
+    public static int doDelete($dbObjectClassName obj, Connection con)
         throws TorqueException
     {
         ## TODO use buildSelectCriteria if no pk is present
-        ${peerImplGetter}().doDelete(obj, con);
+        return ${peerImplGetter}().doDelete(obj, con);
     }
 
     /**
-     * Method to do deletes.
+     * Deletes a row in the database.
+     *
+     * @param pk the ObjectKey that identifies the row to delete.
+     *
+     * @return the number of deleted rows.
      *
-     * @param pk ObjectKey that is used DELETE from database.
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public static void doDelete(ObjectKey pk) throws TorqueException
+    public static int doDelete(ObjectKey pk) throws TorqueException
     {
-        ${peerImplGetter}().doDelete(pk, (Connection) null);
+        return ${peerImplGetter}().doDelete(pk, (Connection) null);
     }
 
     /**
-     * Method to delete.  This method is to be used during a transaction,
-     * otherwise use the doDelete(ObjectKey) method.  It will take
-     * care of the connection details internally.
+     * 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.
      *
-     * @param pk the primary key for the object to delete in the database.
-     * @param con the connection to use
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public static void doDelete(ObjectKey pk, Connection con)
+    public static int doDelete(ObjectKey pk, Connection con)
         throws TorqueException
     {
-        ${peerImplGetter}().doDelete(pk, con);
+        return ${peerImplGetter}().doDelete(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=1103512&r1=1103511&r2=1103512&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 Sun May 15 19:37:41 2011
@@ -28,13 +28,16 @@
 ## as velocity variables.  
 ##
     /**
-     * Method to do deletes.
+     * Deletes rows from a database table.
+     *
+     * @param criteria defines the rows to be deleted, not null.
+     *
+     * @return the number of deleted rows.
      *
-     * @param criteria object containing data that is used DELETE from database.
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-     public void doDelete(Criteria criteria) throws TorqueException
+     public int doDelete(Criteria criteria) throws TorqueException
      {
         Connection connection = null;
         try
@@ -42,9 +45,10 @@
             connection = Transaction.beginOptional(
                     ${peerClassName}.DATABASE_NAME,
                     true);
-            doDelete(criteria, connection);
+            int deletedRows = doDelete(criteria, connection);
             Transaction.commit(connection);
             connection = null;
+            return deletedRows;
         }
         finally
         {
@@ -56,77 +60,93 @@
      }
 
     /**
-     * Method to do deletes.  This method is to be used during a transaction,
-     * otherwise use the doDelete(Criteria) method.  It will take care of
-     * the connection details internally.
+     * Deletes rows from a table.  This method is to be used 
+     * during a transaction, otherwise use the doDelete(Criteria) method.
+      *
+     * @param criteria defines the rows to be deleted, not null.
+     * @param con the connection to use, not null.
+     *
+     * @return the number of deleted rows.
      *
-     * @param criteria object containing data that is used DELETE from database.
-     * @param con the connection to use
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-     public void doDelete(Criteria criteria, Connection con)
+     public int doDelete(Criteria criteria, Connection con)
         throws TorqueException
      {
         correctBooleans(criteria);
 
         setDbName(criteria);
 
-        doDelete(criteria, ${peerClassName}.TABLE_NAME, con);
+        return doDelete(criteria, ${peerClassName}.TABLE_NAME, con);
      }
 
     /**
-     * @param obj the data object to delete in the database.
+     * Deletes a data object, i.e. a row in a table, in the database.
+     *
+     * @param obj the data object to delete in the database, not null.
+     *
+     * @return the number of deleted rows.
+     *
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public void doDelete($dbObjectClassName obj) throws TorqueException
+    public int doDelete($dbObjectClassName obj) throws TorqueException
     {
         ## TODO use buildSelectCriteria if no pk is present
-        doDelete(buildCriteria(obj.getPrimaryKey()));
+        return doDelete(buildCriteria(obj.getPrimaryKey()));
     }
 
     /**
-     * Method to delete.  This method is to be used during a transaction,
-     * otherwise use the doDelete($dbObjectClassName) method.  It will take
-     * care of the connection details internally.
+     * Deletes a data object, i.e. a row in a table, in the database.
+     * This method is to be used during a transaction, otherwise use the
+     * doDelete($dbObjectClassName) method.
+     *
+     * @param obj the data object to delete in the database, not null.
+     * @param con the connection to use, not null.
+     *
+     * @return the number of deleted rows.
      *
-     * @param obj the data object to delete in the database.
-     * @param con the connection to use
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public void doDelete($dbObjectClassName obj, Connection con)
+    public int doDelete($dbObjectClassName obj, Connection con)
         throws TorqueException
     {
         ## TODO use buildSelectCriteria if no pk is present
-        doDelete(buildCriteria(obj.getPrimaryKey()), con);
+        return doDelete(buildCriteria(obj.getPrimaryKey()), con);
     }
 
     /**
-     * Method to do deletes.
+     * Deletes a row in the database.
+     *
+     * @param pk the ObjectKey that identifies the row to delete.
+     *
+     * @return the number of deleted rows.
      *
-     * @param pk ObjectKey that is used DELETE from database.
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public void doDelete(ObjectKey pk) throws TorqueException
+    public int doDelete(ObjectKey pk) throws TorqueException
     {
-        doDelete(pk, (Connection) null);
+        return doDelete(pk, (Connection) null);
     }
 
     /**
-     * Method to delete.  This method is to be used during a transaction,
-     * otherwise use the doDelete(ObjectKey) method.  It will take
-     * care of the connection details internally.
+     * 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.
      *
-     * @param pk the primary key for the object to delete in the database.
-     * @param con the connection to use
      * @throws TorqueException Any exceptions caught during processing will be
      *         rethrown wrapped into a TorqueException.
      */
-    public void doDelete(ObjectKey pk, Connection con)
+    public int doDelete(ObjectKey pk, Connection con)
         throws TorqueException
     {
-        doDelete(buildCriteria(pk), con);
+        return doDelete(buildCriteria(pk), con);
     }

Modified: db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java
URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java?rev=1103512&r1=1103511&r2=1103512&view=diff
==============================================================================
--- db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java (original)
+++ db/torque/torque4/trunk/torque-test/src/test/java/org/apache/torque/DataTest.java Sun May 15 19:37:41 2011
@@ -1001,7 +1001,7 @@ public class DataTest extends BaseRuntim
         {
             Criteria criteria = new Criteria();
             criteria.add(BookPeer.BOOK_ID, (Long) null, Criteria.NOT_EQUAL);
-            BookPeer.doDelete(criteria, null);
+            BookPeer.doDelete(criteria, (Connection) null);
             fail("NullPointerException expected");
         }
         catch (NullPointerException e)



---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org