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 tv...@apache.org on 2012/08/09 20:39:32 UTC
svn commit: r1371367 -
/db/torque/torque4/trunk/torque-runtime/src/main/java/org/apache/torque/util/LargeSelect.java
Author: tv
Date: Thu Aug 9 18:39:32 2012
New Revision: 1371367
URL: http://svn.apache.org/viewvc?rev=1371367&view=rev
Log:
- Changed method signature to take a generified BasePeerImpl object instead of a RecordMapper
- Removed support for old Criteria
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=1371367&r1=1371366&r2=1371367&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 Aug 9 18:39:32 2012
@@ -34,8 +34,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.torque.Torque;
import org.apache.torque.TorqueException;
-import org.apache.torque.criteria.CriteriaInterface;
-import org.apache.torque.om.mapper.RecordMapper;
import org.apache.torque.sql.SqlBuilder;
/**
@@ -71,17 +69,13 @@ import org.apache.torque.sql.SqlBuilder;
* <code>setOffset()</code> and <code>setLimit()</code> 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
- * <code>Criteria</code> will only pass the offset and limit through to MySQL
- * and PostgreSQL (with a few changes to <code>DBOracle</code> and <code>
- * BasePeer</code> Oracle support can be implemented by utilizing the <code>
- * rownum</code> pseudo column).
+ * the Torque API when it is not (not so efficient).
*
* <p>As <code>LargeSelect</code> must re-execute the query each time the user
* pages out of the window of loaded data, you should consider the impact of
* non-index sort orderings and other criteria that will require the DBMS to
* execute the entire query before filtering down to the offset and limit either
- * internally or via Village.
+ * internally or via Torque.
*
* <p>The memory limit defaults to 5 times the page size you specify, but
* alternative constructors and the class method <code>setMemoryPageLimit()
@@ -91,7 +85,7 @@ import org.apache.torque.sql.SqlBuilder;
* <p>Typically you will create a <code>LargeSelect</code> using your <code>
* Criteria</code> (perhaps created from the results of a search parameter
* page), page size, memory page limit, return class name (for which you may
- * have defined a business object class before hand) and mapper class
+ * have defined a business object class before hand) and peer class
* and place this in user.Temp thus:
*
* <pre>
@@ -141,9 +135,6 @@ public class LargeSelect<T> implements R
/** How much of the memory block is currently occupied with result data. */
private volatile int currentlyFilledTo = -1;
- /** The database name to get from Torque. */
- private String dbName;
-
/** The memory store of results. */
private transient List<T> results = null;
@@ -175,15 +166,15 @@ public class LargeSelect<T> implements R
private int totalRecords = 0;
/** The criteria used for the query. */
- private CriteriaInterface<?> criteria = null;
+ private org.apache.torque.criteria.Criteria criteria = null;
/** The last page of results that were returned. */
private transient List<T> lastResults;
/**
- * The Mapper used to map the database records into objects.
+ * The BasePeerImpl object that handles database selects.
*/
- private RecordMapper<T> mapper = null;
+ private BasePeerImpl<T> peer = null;
/**
* The default value (">") used to indicate that the total number of
@@ -237,25 +228,25 @@ public class LargeSelect<T> implements R
* @param criteria object used by BasePeer to build the query. In order to
* allow this class to utilize database server implemented offsets and
* limits (when available), the provided criteria must not have any limit or
- * offset defined. The criteria <b>must</b> however include the definition of
- * select columns.
+ * offset defined.
+ *
* @param pageSize number of rows to return in one block.
- * @param recordMapper the mapper that will be used to build the result records
+ * @param peerImpl the peer that will be used to do the select operations
*
* @throws IllegalArgumentException if <code>criteria</code> uses one or
* both of offset and limit, if <code>pageSize</code> is less than 1 or
* the Criteria object does not contain SELECT columns.
*/
public LargeSelect(
- CriteriaInterface<?> criteria,
+ org.apache.torque.criteria.Criteria criteria,
int pageSize,
- RecordMapper<T> recordMapper)
+ BasePeerImpl<T> peerImpl)
{
this(
criteria,
pageSize,
LargeSelect.DEFAULT_MEMORY_LIMIT_PAGES,
- recordMapper);
+ peerImpl);
}
/**
@@ -264,15 +255,15 @@ public class LargeSelect<T> implements R
* time, maintaining a maximum of <code>memoryPageLimit</code> pages of
* results in memory.
*
- * @param criteria object used by BasePeer to build the query. In order to
+ * @param criteria object used by BasePeerImpl to build the query. In order to
* allow this class to utilize database server implemented offsets and
* limits (when available), the provided criteria must not have any limit or
- * offset defined. The criteria <b>must</b> however include the definition of
- * select columns.
+ * offset defined.
+ *
* @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 recordMapper the mapper that will be used to build the result records
+ * @param peerImpl the peer that will be used to do the select operations
*
* @throws IllegalArgumentException if <code>criteria</code> uses one or
* both of offset and limit, if <code>pageSize</code> or <code>
@@ -280,18 +271,12 @@ public class LargeSelect<T> implements R
* contain SELECT columns..
*/
public LargeSelect(
- CriteriaInterface<?> criteria,
+ org.apache.torque.criteria.Criteria criteria,
int pageSize,
int memoryPageLimit,
- RecordMapper<T> recordMapper)
+ BasePeerImpl<T> peerImpl)
{
- this.mapper = recordMapper;
-
- if (criteria.getSelectColumns().size() == 0)
- {
- throw new IllegalArgumentException(
- "The Criteria object does not contain SELECT columns.");
- }
+ this.peer = peerImpl;
if (criteria.getOffset() != 0 || criteria.getLimit() != -1)
{
@@ -314,7 +299,6 @@ public class LargeSelect<T> implements R
this.pageSize = pageSize;
this.memoryLimit = pageSize * memoryPageLimit;
this.criteria = criteria;
- dbName = criteria.getDbName();
blockEnd = blockBegin + memoryLimit - 1;
startQuery(pageSize);
}
@@ -329,8 +313,7 @@ public class LargeSelect<T> implements R
* <code>pageSize</code> results.
* @throws IllegalArgumentException when <code>pageNo</code> is not
* greater than zero.
- * @throws TorqueException if invoking the <code>populateObjects()<code>
- * method runs into problems or a sleep is unexpectedly interrupted.
+ * @throws TorqueException if a sleep is unexpectedly interrupted.
*/
public List<T> getPage(int pageNumber) throws TorqueException
{
@@ -346,9 +329,8 @@ public class LargeSelect<T> implements R
* Gets the next page of rows.
*
* @return a <code>List</code> of query results containing a maximum of
- * <code>pageSize</code> reslts.
- * @throws TorqueException if invoking the <code>populateObjects()<code>
- * method runs into problems or a sleep is unexpectedly interrupted.
+ * <code>pageSize</code> results.
+ * @throws TorqueException if a sleep is unexpectedly interrupted.
*/
public List<T> getNextResults() throws TorqueException
{
@@ -364,8 +346,7 @@ public class LargeSelect<T> implements R
*
* @return a <code>List</code> of query results containing a maximum of
* <code>pageSize</code> results.
- * @throws TorqueException if invoking the <code>populateObjects()<code>
- * method runs into problems or a sleep is unexpectedly interrupted.
+ * @throws TorqueException if a sleep is unexpectedly interrupted.
*/
public List<T> getCurrentPageResults() throws TorqueException
{
@@ -378,8 +359,7 @@ public class LargeSelect<T> implements R
*
* @return a <code>List</code> of query results containing a maximum of
* <code>pageSize</code> results.
- * @throws TorqueException if invoking the <code>populateObjects()<code>
- * method runs into problems or a sleep is unexpectedly interrupted.
+ * @throws TorqueException if a sleep is unexpectedly interrupted.
*/
public List<T> getPreviousResults() throws TorqueException
{
@@ -406,8 +386,7 @@ public class LargeSelect<T> implements R
* @param start the starting row.
* @return a <code>List</code> of query results containing a maximum of
* <code>pageSize</code> results.
- * @throws TorqueException if invoking the <code>populateObjects()<code>
- * method runs into problems or a sleep is unexpectedly interrupted.
+ * @throws TorqueException if a sleep is unexpectedly interrupted.
*/
private List<T> getResults(int start) throws TorqueException
{
@@ -425,8 +404,7 @@ public class LargeSelect<T> implements R
* @throws IllegalArgumentException if <code>size > memoryLimit</code> or
* <code>start</code> and <code>size</code> result in a situation that is
* not catered for.
- * @throws TorqueException if invoking the <code>populateObjects()<code>
- * method runs into problems or a sleep is unexpectedly interrupted.
+ * @throws TorqueException if a sleep is unexpectedly interrupted.
*/
private synchronized List<T> getResults(int start, int size)
throws TorqueException
@@ -568,23 +546,9 @@ public class LargeSelect<T> implements R
* columns not fully qualified will not be modified.
*/
String query;
- if (criteria instanceof Criteria)
- {
- BasePeer.correctBooleans((Criteria) criteria, null);
- query = SqlBuilder.buildQuery((Criteria) criteria).toString();
- }
- else
- {
- BasePeer.correctBooleans(
- (org.apache.torque.criteria.Criteria) criteria,
- null);
- query = SqlBuilder.buildQuery(
- (org.apache.torque.criteria.Criteria) criteria)
- .toString();
- }
-
- // Get a connection to the db.
- conn = Transaction.begin(dbName);
+ peer.correctBooleans(criteria);
+ peer.setDbName(criteria);
+ query = SqlBuilder.buildQuery(criteria).toString();
// Execute the query.
if (log.isDebugEnabled())
@@ -595,6 +559,9 @@ public class LargeSelect<T> implements R
log.debug("run(): blockEnd = " + blockEnd);
}
+ // Get a connection to the db.
+ conn = Transaction.begin(criteria.getDbName());
+
// Continue getting rows one page at a time until the memory limit
// is reached, all results have been retrieved, or the rest
// of the results have been determined to be irrelevant.
@@ -605,26 +572,11 @@ public class LargeSelect<T> implements R
{
if (log.isDebugEnabled())
{
- log.debug("run(): Invoking BasePeer.doSelect()");
+ log.debug("run(): Invoking BasePeerImpl.doSelect()");
}
- List<T> tempResults;
- if (criteria instanceof Criteria)
- {
- tempResults = BasePeer.doSelect(
- (Criteria) criteria,
- mapper,
- null,
- conn);
- }
- else
- {
- tempResults = BasePeer.doSelect(
- (org.apache.torque.criteria.Criteria) criteria,
- mapper,
- null,
- conn);
- }
+ List<T> tempResults = peer.doSelect(criteria, conn);
+
if (tempResults.size() < criteria.getLimit())
{
allRecordsRetrieved = true;
@@ -673,6 +625,9 @@ public class LargeSelect<T> implements R
}
}
+ Transaction.commit(conn);
+ conn = null;
+
if (log.isDebugEnabled())
{
log.debug("run(): While loop terminated because either:");
@@ -686,9 +641,6 @@ public class LargeSelect<T> implements R
log.debug("run(): - blockEnd: " + blockEnd);
log.debug("run(): - results.size(): " + results.size());
}
-
- Transaction.commit(conn);
- conn = null;
}
catch (Exception e)
{
@@ -704,6 +656,7 @@ public class LargeSelect<T> implements R
// Make sure getResults() finally returns if we die.
queryCompleted = true;
+
if (log.isDebugEnabled())
{
log.debug("Exiting query thread");
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org