db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tfisc...@apache.org
Subject svn commit: r1336999 - in /db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util: BasePeer.java BasePeerImpl.java
Date Fri, 11 May 2012 01:49:08 GMT
Author: tfischer
Date: Fri May 11 01:49:07 2012
New Revision: 1336999

URL: http://svn.apache.org/viewvc?rev=1336999&view=rev
Log:
TORQUE-200 also add methods to retrieve single objects to BasePeer 

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

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=1336999&r1=1336998&r2=1336999&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
Fri May 11 01:49:07 2012
@@ -94,6 +94,7 @@ public abstract class BasePeer
      * @deprecated This method is not used any more and will be removed in a
      *             future version of Torque.
      */
+    @Deprecated
     public String[] initCriteriaKeys(
         String tableName,
         String[] columnNames)
@@ -119,6 +120,7 @@ public abstract class BasePeer
      *             for automatic escaping and more flexibility.
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int deleteAll(
         Connection con,
         String table,
@@ -148,6 +150,7 @@ public abstract class BasePeer
      *             for automatic escaping and more flexibility.
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int deleteAll(String table, String column, int value)
         throws TorqueException
     {
@@ -169,6 +172,7 @@ public abstract class BasePeer
      *                 TableMap).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int doDelete(Criteria criteria) throws TorqueException
     {
         return getBasePeerImpl().doDelete(criteria);
@@ -188,6 +192,7 @@ public abstract class BasePeer
      *                 org.apache.torque.criteria.Criteria, TableMap).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int doDelete(org.apache.torque.criteria.Criteria criteria)
             throws TorqueException
     {
@@ -210,6 +215,7 @@ public abstract class BasePeer
      *                 TableMap, Connection).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int doDelete(Criteria criteria, Connection con)
         throws TorqueException
     {
@@ -232,6 +238,7 @@ public abstract class BasePeer
      *                 TableMap, Connection).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int doDelete(org.apache.torque.criteria.Criteria criteria,
             Connection con)
         throws TorqueException
@@ -256,6 +263,7 @@ public abstract class BasePeer
      *                 org.apache.torque.criteria.Criteria, String).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int doDelete(Criteria criteria, TableMap tableMap)
             throws TorqueException
     {
@@ -298,6 +306,7 @@ public abstract class BasePeer
      *                 org.apache.torque.criteria.Criteria, String, Connection).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int doDelete(
                 Criteria criteria,
                 TableMap tableMap,
@@ -401,6 +410,7 @@ public abstract class BasePeer
      *             RecordMapper, TableMap).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static <T> List<T> doSelect(
                 Criteria criteria,
                 RecordMapper<T> mapper,
@@ -450,6 +460,7 @@ public abstract class BasePeer
      *             RecordMapper, TableMap, Connection).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static <T> List<T> doSelect(
             Criteria criteria,
             RecordMapper<T> mapper,
@@ -550,6 +561,59 @@ public abstract class BasePeer
     }
 
     /**
+     * Selects at most a single row from a database an maps them to objects.
+     *
+     * @param criteria A Criteria specifying the records to select, not null.
+     * @param mapper The mapper creating the objects from the resultSet,
+     *        not null.
+     * @param defaultTableMap The table map used for the
+     *        unqualified columns in the query, not null.
+     *
+     * @return The selected row, or null if no records was selected.
+     *
+     * @throws TorqueException if querying the database fails.
+     */
+    public static <T> T doSelectSingleRecord(
+                org.apache.torque.criteria.Criteria criteria,
+                RecordMapper<T> mapper,
+                TableMap defaultTableMap)
+            throws TorqueException
+    {
+        return getBasePeerImpl().doSelectSingleRecord(
+                criteria,
+                mapper,
+                defaultTableMap);
+    }
+
+    /**
+     * Selects at most a single row from a database an maps them to objects.
+     *
+     * @param criteria A Criteria specifying the records to select, not null.
+     * @param mapper The mapper creating the objects from the resultSet,
+     *        not null.
+     * @param defaultTableMap The table map used for the
+     *        unqualified columns in the query, not null.
+     * @param connection the database connection, not null.
+     *
+     * @return The selected row, or null if no records was selected.
+     *
+     * @throws TorqueException if querying the database fails.
+     */
+    public static <T> T doSelectSingleRecord(
+                org.apache.torque.criteria.Criteria criteria,
+                RecordMapper<T> mapper,
+                TableMap defaultTableMap,
+                Connection connection)
+            throws TorqueException
+    {
+        return getBasePeerImpl().doSelectSingleRecord(
+                criteria,
+                mapper,
+                defaultTableMap,
+                connection);
+    }
+
+    /**
      * Updates rows in the DB.  Checks if a <i>single</i> primary key
      * is specified in the updateValues object and uses it to perform
      * the update.  If no primary key is specified
@@ -628,6 +692,7 @@ public abstract class BasePeer
      *                 org.apache.torque.criteria.Criteria, ColumnValues).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int doUpdate(
                 Criteria selectCriteria,
                 ColumnValues updateValues)
@@ -673,6 +738,7 @@ public abstract class BasePeer
      *                 ColumnValues, Connection).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static int doUpdate(
                 Criteria criteria,
                 ColumnValues updateValues,
@@ -772,6 +838,7 @@ public abstract class BasePeer
      *                 org.apache.torque.criteria.Criteria, TableMap).
      *             This method will be removed in a future version of Torque.
      */
+    @Deprecated
     public static void correctBooleans(
                 Criteria criteria,
                 TableMap defaultTableMap)

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=1336999&r1=1336998&r2=1336999&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
Fri May 11 01:49:07 2012
@@ -1440,6 +1440,78 @@ public class BasePeerImpl implements Ser
     }
 
     /**
+     * Selects at most a single row from a database an maps them to objects.
+     *
+     * @param criteria A Criteria specifying the records to select, not null.
+     * @param mapper The mapper creating the objects from the resultSet,
+     *        not null.
+     * @param defaultTableMap The table map used for the
+     *        unqualified columns in the query, not null.
+     *
+     * @return The selected row, or null if no records was selected.
+     *
+     * @throws TorqueException if querying the database fails.
+     */
+    public <T> T doSelectSingleRecord(
+                org.apache.torque.criteria.Criteria criteria,
+                RecordMapper<T> mapper,
+                TableMap defaultTableMap)
+            throws TorqueException
+    {
+        List<T> resultList = doSelect(criteria, mapper, defaultTableMap);
+        T result = null;
+        if (resultList.size() > 1)
+        {
+            throw new TooManyRowsException("Criteria " + criteria
+                + " matched more than one record");
+        }
+        if (!resultList.isEmpty())
+        {
+            result = resultList.get(0);
+        }
+        return result;
+    }
+
+    /**
+     * Selects at most a single row from a database an maps them to objects.
+     *
+     * @param criteria A Criteria specifying the records to select, not null.
+     * @param mapper The mapper creating the objects from the resultSet,
+     *        not null.
+     * @param defaultTableMap The table map used for the
+     *        unqualified columns in the query, not null.
+     * @param connection the database connection, not null.
+     *
+     * @return The selected row, or null if no records was selected.
+     *
+     * @throws TorqueException if querying the database fails.
+     */
+    public <T> T doSelectSingleRecord(
+                org.apache.torque.criteria.Criteria criteria,
+                RecordMapper<T> mapper,
+                TableMap defaultTableMap,
+                Connection connection)
+            throws TorqueException
+    {
+        List<T> resultList = doSelect(
+                criteria,
+                mapper,
+                defaultTableMap,
+                connection);
+        T result = null;
+        if (resultList.size() > 1)
+        {
+            throw new TooManyRowsException("Criteria " + criteria
+                + " matched more than one record");
+        }
+        if (!resultList.isEmpty())
+        {
+            result = resultList.get(0);
+        }
+        return result;
+    }
+
+    /**
      * Convenience method used to update rows in the DB.  Checks if a
      * <i>single</i> primary key is specified in the Criteria
      * object and uses it to perform the update.  If no primary key is



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


Mime
View raw message