org.apache.turbine.util.db
Class LargeSelect

java.lang.Object
  |
  +--org.apache.turbine.util.db.LargeSelect
All Implemented Interfaces:
java.lang.Runnable

public class LargeSelect
extends java.lang.Object
implements java.lang.Runnable

This class can be used to retrieve a large result set from a database query. The query is started and then a small number of rows are returned at any one time. The LargeSelect is meant to be placed into the Session, so that it can be used in response to several related requests. It was written as an example in response to questions regarding Village's and Turbine's ability to handle large queries. The author hoped that the people who were asking for the feature would comment and improve the code, but has received no comments. As the author has had no need for such a class, it remains untested and in all likelihood contains several bugs.

Version:
$Id$
Author:
John D. McNally

Field Summary
private  int blockBegin
           
private  int blockEnd
           
private  int currentlyFilledTo
           
private  DBConnection db
           
private  java.lang.String dbName
           
static java.lang.String DEFAULT_NAME
          Key which may be used to store and retrieve the LargeSelect from the session.
private  boolean killThread
           
private  int memoryLimit
           
private  int miniblock
           
private  java.lang.String name
           
private  int position
           
private  com.workingdogs.village.QueryDataSet qds
           
private  java.lang.String query
           
private  java.util.Vector results
           
private  java.lang.Thread thread
           
 
Constructor Summary
LargeSelect(Criteria criteria, int memoryLimit)
          Creates a LargeSelect whose results are broken up into smaller chunks of approximately 1/100 the maximum number allowed in memory or 100, whichever is smaller.
LargeSelect(Criteria criteria, int memoryLimit, int pageSize)
          Creates a LargeSelect whose results are returned a page at a time.
LargeSelect(java.lang.String name, Criteria criteria, int memoryLimit)
          Creates a LargeSelect whose results are broken up into smaller chunks of approximately 1/100 the maximum number allowed in memory or 100, whichever is smaller.
LargeSelect(java.lang.String name, Criteria criteria, int memoryLimit, int pageSize)
          Creates a LargeSelect whose results are returned a page at a time.
 
Method Summary
 java.util.Vector getNextResults()
          Gets the next block of rows.
 java.util.Vector getPreviousResults()
          Gets a block of rows which have previously been retrieved.
 java.util.Vector getResults(int start)
          Gets a block of rows starting at a specified row.
 java.util.Vector getResults(int start, int size)
          Gets a block of rows starting at a specified row and containing a specified number of rows.
private  void init(java.lang.String name, Criteria criteria, int memoryLimit)
          Called by the constructors to start the query.
 void run()
          A background thread that retrieves the rows.
private  void startQuery(int initialSize)
          Starts a new thread to retrieve the result set.
private  void stopQuery()
          Used to stop filling the memory with the current block of results, if it has been determined that they are no longer relevant.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

miniblock

private int miniblock

memoryLimit

private int memoryLimit

name

private java.lang.String name

blockBegin

private int blockBegin

blockEnd

private int blockEnd

currentlyFilledTo

private int currentlyFilledTo

query

private java.lang.String query

dbName

private java.lang.String dbName

db

private DBConnection db

qds

private com.workingdogs.village.QueryDataSet qds

results

private java.util.Vector results

thread

private java.lang.Thread thread

killThread

private boolean killThread

position

private int position

DEFAULT_NAME

public static final java.lang.String DEFAULT_NAME
Key which may be used to store and retrieve the LargeSelect from the session.
Constructor Detail

LargeSelect

public LargeSelect(Criteria criteria,
                   int memoryLimit)
            throws java.lang.Exception
Creates a LargeSelect whose results are broken up into smaller chunks of approximately 1/100 the maximum number allowed in memory or 100, whichever is smaller. The LargeSelect is stored in the session under the default name "default.large.select".
Parameters:
criteria - Object used by BasePeer to build the query.
memoryLimit - Maximum number of rows to be in memory at one time.
Throws:
Exception, - a generic exception.

LargeSelect

public LargeSelect(java.lang.String name,
                   Criteria criteria,
                   int memoryLimit)
            throws java.lang.Exception
Creates a LargeSelect whose results are broken up into smaller chunks of approximately 1/100 the maximum number allowed in memory or 100, whichever is smaller.
Parameters:
name - Key used to store the LargeSelect in the session.
criteria - Object used by BasePeer to build the query.
memoryLimit - Maximum number of rows to be in memory at one time.
Throws:
Exception, - a generic exception.

LargeSelect

public LargeSelect(Criteria criteria,
                   int memoryLimit,
                   int pageSize)
            throws java.lang.Exception
Creates a LargeSelect whose results are returned a page at a time. The LargeSelect is stored in the session under the default name "default.large.select".
Parameters:
criteria - Object used by BasePeer to build the query.
memoryLimit - Maximum number of rows to be in memory at one time.
pageSize - Number of rows to return in one block.
Throws:
Exception, - a generic exception.

LargeSelect

public LargeSelect(java.lang.String name,
                   Criteria criteria,
                   int memoryLimit,
                   int pageSize)
            throws java.lang.Exception
Creates a LargeSelect whose results are returned a page at a time.
Parameters:
name - Key used to store the LargeSelect in the session.
criteria - Object used by BasePeer to build the query.
memoryLimit - Maximum number of rows to be in memory at one time.
pageSize - Number of rows to return in one block.
Throws:
Exception, - a generic exception.
Method Detail

init

private void init(java.lang.String name,
                  Criteria criteria,
                  int memoryLimit)
           throws java.lang.Exception
Called by the constructors to start the query.
Parameters:
name - Key used to store the LargeSelect in the session.
criteria - Object used by BasePeer to build the query.
memoryLimit - Maximum number of rows to be in memory at one time.
Throws:
Exception, - a generic exception.

getNextResults

public java.util.Vector getNextResults()
                                throws java.lang.Exception
Gets the next block of rows.
Returns:
A Vector of query results.
Throws:
Exception, - a generic exception.

getPreviousResults

public java.util.Vector getPreviousResults()
                                    throws java.lang.Exception
Gets a block of rows which have previously been retrieved.
Returns:
a Vector of query results.
Throws:
Exception, - a generic exception.

getResults

public java.util.Vector getResults(int start)
                            throws java.lang.Exception
Gets a block of rows starting at a specified row. Number of rows in the block was specified in the constructor.
Parameters:
start - The starting row.
Returns:
a Vector of query results.
Throws:
Exception, - a generic exception.

getResults

public java.util.Vector getResults(int start,
                                   int size)
                            throws java.lang.Exception
Gets a block of rows starting at a specified row and containing a specified number of rows.
Parameters:
start - The starting row.
size - The number of rows.
Returns:
a Vector of query results.
Throws:
Exception, - a generic exception.

run

public void run()
A background thread that retrieves the rows.
Specified by:
run in interface java.lang.Runnable

startQuery

private void startQuery(int initialSize)
                 throws java.lang.Exception
Starts a new thread to retrieve the result set.
Parameters:
initialSize - The initial size for each block.
Throws:
Exception, - a generic exception.

stopQuery

private void stopQuery()
                throws java.lang.Exception
Used to stop filling the memory with the current block of results, if it has been determined that they are no longer relevant.
Throws:
Exception, - a generic exception.


Copyright © 1999-2001 Apache Software Foundation. All Rights Reserved.