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 701E9DC75 for ; Thu, 5 Jul 2012 20:02:04 +0000 (UTC) Received: (qmail 84913 invoked by uid 500); 5 Jul 2012 20:02:04 -0000 Delivered-To: apmail-db-torque-dev-archive@db.apache.org Received: (qmail 84890 invoked by uid 500); 5 Jul 2012 20:02:04 -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 84882 invoked by uid 500); 5 Jul 2012 20:02:04 -0000 Received: (qmail 84879 invoked by uid 99); 5 Jul 2012 20:02:04 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Jul 2012 20:02:04 +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; Thu, 05 Jul 2012 20:02:00 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 81CAB23889DE; Thu, 5 Jul 2012 20:01:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1357857 - /db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java Date: Thu, 05 Jul 2012 20:01:39 -0000 To: torque-commits@db.apache.org From: tv@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120705200139.81CAB23889DE@eris.apache.org> Author: tv Date: Thu Jul 5 20:01:39 2012 New Revision: 1357857 URL: http://svn.apache.org/viewvc?rev=1357857&view=rev Log: Experimental cleanup of the interface Attempt to fix a long standing bug: getResults() does not return if the background thread dies unexpectedly. Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java Modified: db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java URL: http://svn.apache.org/viewvc/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java?rev=1357857&r1=1357856&r2=1357857&view=diff ============================================================================== --- db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java (original) +++ db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java Thu Jul 5 20:01:39 2012 @@ -22,7 +22,6 @@ package org.apache.torque.util; import java.io.IOException; import java.io.ObjectInputStream; import java.io.Serializable; -import java.lang.reflect.Method; import java.sql.Connection; import java.util.ArrayList; import java.util.Hashtable; @@ -68,14 +67,14 @@ import org.apache.torque.sql.SqlBuilder; * provides various methods for indicating how many records and pages it is * currently aware of and for presenting this information to users. * - *

LargeSelect utilises the Criteria methods + *

LargeSelect utilizes the Criteria methods * setOffset() and setLimit() to limit the amount of * data retrieved from the database - these values are either passed through to * the DBMS when supported (efficient with the caveat below) or handled by * the Village API when it is not (not so efficient). At time of writing * Criteria will only pass the offset and limit through to MySQL * and PostgreSQL (with a few changes to DBOracle and - * BasePeer Oracle support can be implemented by utilising the + * BasePeer Oracle support can be implemented by utilizing the * rownum pseudo column). * *

As LargeSelect must re-execute the query each time the user @@ -89,16 +88,6 @@ import org.apache.torque.sql.SqlBuilder; * allow you to override this for a specific instance of * LargeSelect or future instances respectively. * - *

The constructors allow you to specify the name of the class to use - * to build the returnd rows. This works by using reflection to find - * the addSelectColumns(Criteria) - * method to add the necessary select columns to the criteria (only if it - * doesn't already contain any). - * This allows you to use any of the Torque generated Peer classes, but also - * makes it fairly simple to construct business object classes that can be used - * for this purpose (simply copy and customise the addSelectColumns() - * method from an existing Peer class). - * *

Typically you will create a LargeSelect using your * Criteria (perhaps created from the results of a search parameter * page), page size, memory page limit, return class name (for which you may @@ -187,16 +176,11 @@ public class LargeSelect implements R /** The criteria used for the query. */ private CriteriaInterface criteria = null; + /** The last page of results that were returned. */ private transient List lastResults; /** - * The class that is possibly used to construct the criteria and used - * to transform the Village Records into the desired OM or business objects. - */ - private Class returnBuilderClass = null; - - /** * The Mapper used to map the database records into objects. */ private RecordMapper mapper = null; @@ -212,7 +196,7 @@ public class LargeSelect implements R * unknown (default: ">"). You can use setMoreIndicator() * to change this to whatever value you like (e.g. "more than"). */ - private static String moreIndicator = DEFAULT_MORE_INDICATOR; + private String moreIndicator = DEFAULT_MORE_INDICATOR; /** * The default value for the maximum number of pages of data to be retained @@ -224,7 +208,7 @@ public class LargeSelect implements R * The maximum number of pages of data to be retained in memory. Use * setMemoryPageLimit() to provide your own value. */ - private static int memoryPageLimit = DEFAULT_MEMORY_LIMIT_PAGES; + private int memoryPageLimit = DEFAULT_MEMORY_LIMIT_PAGES; /** * The number of milliseconds to sleep when the result of a query @@ -251,115 +235,64 @@ public class LargeSelect implements R * pages of results in memory. * * @param criteria object used by BasePeer to build the query. In order to - * allow this class to utilise database server implemented offsets and + * allow this class to utilize database server implemented offsets and * limits (when available), the provided criteria must not have any limit or - * offset defined. If the criteria does not include the definition of any - * select columns the addSelectColumns(Criteria) method of - * the class named as returnBuilderClassName will be used to - * add them. + * offset defined. The criteria must however include the definition of + * select columns. * @param pageSize number of rows to return in one block. - * @param returnBuilderClassName The name of the class that will be used to - * build the result records (may implement addSelectColumns(Criteria) - * and must implement populateObjects(List)). + * @param recordMapper the mapper that will be used to build the result records + * * @throws IllegalArgumentException if criteria uses one or - * both of offset and limit, if pageSize is less than 1, or if - * problems are experienced locating and invoking either one or both of - * addSelectColumns(Criteria) and populateObjects(List) - * in the class named returnBuilderClassName. + * both of offset and limit, if pageSize is less than 1 or + * the Criteria object does not contain SELECT columns. */ public LargeSelect( CriteriaInterface criteria, int pageSize, - String returnBuilderClassName, RecordMapper recordMapper) { this( criteria, pageSize, - LargeSelect.memoryPageLimit, - returnBuilderClassName, + LargeSelect.DEFAULT_MEMORY_LIMIT_PAGES, recordMapper); } /** * Creates a LargeSelect whose results are returned as a List - * containing a maximum of pageSize objects of the type - * defined within the class named returnBuilderClassName at a + * containing a maximum of pageSize objects of the type T at a * time, maintaining a maximum of memoryPageLimit pages of * results in memory. * * @param criteria object used by BasePeer to build the query. In order to - * allow this class to utilise database server implemented offsets and + * allow this class to utilize database server implemented offsets and * limits (when available), the provided criteria must not have any limit or - * offset defined. If the criteria does not include the definition of any - * select columns the addSelectColumns(Criteria) method of - * the class named as returnBuilderClassName will be used to - * add them. + * offset defined. The criteria must however include the definition of + * select columns. * @param pageSize number of rows to return in one block. * @param memoryPageLimit maximum number of pages worth of rows to be held * in memory at one time. - * @param returnBuilderClassName The name of the class that will be used to - * build the result records (may implement addSelectColumns(Criteria) - * and must implement populateObjects(List)). + * @param recordMapper the mapper that will be used to build the result records + * * @throws IllegalArgumentException if criteria uses one or * both of offset and limit, if pageSize or - * memoryLimitPages are less than 1, or if problems are experienced - * locating and invoking either one or both of - * addSelectColumns(Criteria) and populateObjects(List) - * in the class named returnBuilderClassName. + * memoryLimitPages are less than 1 or the Criteria object does not + * contain SELECT columns.. */ public LargeSelect( CriteriaInterface criteria, int pageSize, int memoryPageLimit, - String returnBuilderClassName, RecordMapper recordMapper) { this.mapper = recordMapper; - try - { - this.returnBuilderClass = Class.forName(returnBuilderClassName); - // Add the select columns if necessary. - if (criteria.getSelectColumns().size() == 0) - { - Class[] argTypes = {criteria.getClass()}; - Method selectColumnAdder = - returnBuilderClass.getMethod("addSelectColumns", argTypes); - Object[] theArgs = {criteria}; - selectColumnAdder.invoke(returnBuilderClass.newInstance(), - theArgs); - } - } - catch (Exception e) + if (criteria.getSelectColumns().size() == 0) { throw new IllegalArgumentException( - "The class named as returnBuilderClassName does not " - + "provide the necessary facilities - see javadoc."); + "The Criteria object does not contain SELECT columns."); } - init(criteria, pageSize, memoryPageLimit); - } - - /** - * Called by the constructors to start the query. - * - * @param criteria Object used by BasePeer to build the query. - * In order to allow this class to utilise database server implemented - * offsets and limits (when available), the provided criteria must not have - * any limit or offset defined. - * @param pageSize number of rows to return in one block. - * @param memoryLimitPages maximum number of pages worth of rows to be held - * in memory at one time. - * @throws IllegalArgumentException if criteria uses one or - * both of offset and limit and if pageSize or - * memoryLimitPages are less than 1; - */ - private void init( - CriteriaInterface criteria, - int pageSize, - int memoryLimitPages) - { if (criteria.getOffset() != 0 || criteria.getLimit() != -1) { throw new IllegalArgumentException( @@ -372,14 +305,14 @@ public class LargeSelect implements R "pageSize must be greater than zero."); } - if (memoryLimitPages < 1) + if (memoryPageLimit < 1) { throw new IllegalArgumentException( "memoryPageLimit must be greater than zero."); } this.pageSize = pageSize; - this.memoryLimit = pageSize * memoryLimitPages; + this.memoryLimit = pageSize * memoryPageLimit; this.criteria = criteria; dbName = criteria.getDbName(); blockEnd = blockBegin + memoryLimit - 1; @@ -430,7 +363,7 @@ public class LargeSelect implements R * Provide access to the results from the current page. * * @return a List of query results containing a maximum of - * pageSize reslts. + * pageSize results. * @throws TorqueException if invoking the populateObjects() * method runs into problems or a sleep is unexpectedly interrupted. */ @@ -444,7 +377,7 @@ public class LargeSelect implements R * Gets the previous page of rows. * * @return a List of query results containing a maximum of - * pageSize reslts. + * pageSize results. * @throws TorqueException if invoking the populateObjects() * method runs into problems or a sleep is unexpectedly interrupted. */ @@ -510,7 +443,7 @@ public class LargeSelect implements R + ") exceeds memory limit (" + memoryLimit + ")."); } - // Request was for a block of rows which should be in progess. + // Request was for a block of rows which should be in progress. // If the rows have not yet been returned, wait for them to be // retrieved. if (start >= blockBegin && (start + size - 1) <= blockEnd) @@ -762,6 +695,9 @@ public class LargeSelect implements R { Torque.closeConnection(conn); threadRunning = false; + + // Make sure getResults() finally returns if we die. + queryCompleted = true; if (log.isDebugEnabled()) { log.debug("Exiting query thread"); @@ -928,17 +864,17 @@ public class LargeSelect implements R * @param moreIndicator the indicator to use in place of the default * (">"). */ - public static void setMoreIndicator(String moreIndicator) + public void setMoreIndicator(String moreIndicator) { - LargeSelect.moreIndicator = moreIndicator; + this.moreIndicator = moreIndicator; } /** * Retrieve the more pages/records indicator. */ - public static String getMoreIndicator() + public String getMoreIndicator() { - return LargeSelect.moreIndicator; + return this.moreIndicator; } /** @@ -949,9 +885,9 @@ public class LargeSelect implements R * @param memoryPageLimit the maximum number of pages to be in memory * at one time. */ - public static void setMemoryPageLimit(int memoryPageLimit) + public void setMemoryPageLimit(int memoryPageLimit) { - LargeSelect.memoryPageLimit = memoryPageLimit; + this.memoryPageLimit = memoryPageLimit; } /** @@ -959,9 +895,9 @@ public class LargeSelect implements R * when a constructor with no memory page limit is used - the memory limit * will be this number multiplied by the page size. */ - public static int getMemoryPageLimit() + public int getMemoryPageLimit() { - return LargeSelect.memoryPageLimit; + return this.memoryPageLimit; } /** --------------------------------------------------------------------- To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org For additional commands, e-mail: torque-dev-help@db.apache.org