Return-Path: X-Original-To: apmail-db-torque-dev-archive@www.apache.org Delivered-To: apmail-db-torque-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 90111CB08 for ; Fri, 11 May 2012 01:49:33 +0000 (UTC) Received: (qmail 65587 invoked by uid 500); 11 May 2012 01:49:33 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 65569 invoked by uid 500); 11 May 2012 01:49:33 -0000 Mailing-List: contact torque-dev-help@db.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Apache Torque Developers List" Reply-To: "Apache Torque Developers List" Delivered-To: mailing list torque-dev@db.apache.org Received: (qmail 65561 invoked by uid 500); 11 May 2012 01:49:33 -0000 Received: (qmail 65553 invoked by uid 99); 11 May 2012 01:49:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 May 2012 01:49:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 May 2012 01:49:29 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 329DE2388847; Fri, 11 May 2012 01:49:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: torque-commits@db.apache.org From: tfischer@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120511014908.329DE2388847@eris.apache.org> 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 List doSelect( Criteria criteria, RecordMapper 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 List doSelect( Criteria criteria, RecordMapper 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 doSelectSingleRecord( + org.apache.torque.criteria.Criteria criteria, + RecordMapper 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 doSelectSingleRecord( + org.apache.torque.criteria.Criteria criteria, + RecordMapper mapper, + TableMap defaultTableMap, + Connection connection) + throws TorqueException + { + return getBasePeerImpl().doSelectSingleRecord( + criteria, + mapper, + defaultTableMap, + connection); + } + + /** * Updates rows in the DB. Checks if a single 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 doSelectSingleRecord( + org.apache.torque.criteria.Criteria criteria, + RecordMapper mapper, + TableMap defaultTableMap) + throws TorqueException + { + List 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 doSelectSingleRecord( + org.apache.torque.criteria.Criteria criteria, + RecordMapper mapper, + TableMap defaultTableMap, + Connection connection) + throws TorqueException + { + List 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 * single 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