Java Doc for LargeSelect.java in  » Database-ORM » Torque » org » apache » torque » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » Torque » org.apache.torque.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.apache.torque.util.LargeSelect

LargeSelect
public class LargeSelect implements Runnable,Serializable(Code)
This class can be used to retrieve a large result set from a database query. The query is started and then rows are returned a page at a time. The LargeSelect is meant to be placed into the Session or User.Temp, so that it can be used in response to several related requests. Note that in order to use LargeSelect you need to be willing to accept the fact that the result set may become inconsistent with the database if updates are processed subsequent to the queries being executed. Specifying a memory page limit of 1 will give you a consistent view of the records but the totals may not be accurate and the performance will be terrible. In most cases the potential for inconsistencies data should not cause any serious problems and performance should be pretty good (but read on for further warnings).

The idea here is that the full query result would consume too much memory and if displayed to a user the page would be too long to be useful. Rather than loading the full result set into memory, a window of data (the memory limit) is loaded and retrieved a page at a time. If a request occurs for data that falls outside the currently loaded window of data then a new query is executed to fetch the required data. Performance is optimized by starting a thread to execute the database query and fetch the results. This will perform best when paging forwards through the data, but a minor optimization where the window is moved backwards by two rather than one page is included for when a user pages past the beginning of the window.

As the query is performed in in steps, it is often the case that the total number of records and pages of data is unknown. LargeSelect 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 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 rownum pseudo column).

As LargeSelect 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.

The memory limit defaults to 5 times the page size you specify, but alternative constructors and the class method setMemoryPageLimit() allow you to override this for a specific instance of LargeSelect or future instances respectively.

Some of 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 addSelectColumns(Criteria) and populateObjects(List) methods to add the necessary select columns to the criteria (only if it doesn't already contain any) and to convert query results from Village Record objects to a class defined within the builder class. 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() , populateObjects(), row2Object() and populateObject() methods 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 and return class name (for which you may have defined a business object class before hand) and place this in user.Temp thus:

 data.getUser().setTemp("someName", largeSelect);
 

In your template you will then use something along the lines of:

 #set($largeSelect = $data.User.getTemp("someName"))
 #set($searchop = $data.Parameters.getString("searchop"))
 #if($searchop.equals("prev"))
 #set($recs = $largeSelect.PreviousResults)
 #else
 #if($searchop.equals("goto"))
 #set($recs = $largeSelect.getPage($data.Parameters.getInt("page", 1)))
 #else
 #set($recs = $largeSelect.NextResults)
 #end
 #end
 

...to move through the records. LargeSelect implements a number of convenience methods that make it easy to add all of the necessary bells and whistles to your template.
author:
   John D. McNally
author:
   Scott Eade
version:
   $Id: LargeSelect.java 534001 2007-05-01 10:46:05Z tv $



Field Summary
final public static  intDEFAULT_MEMORY_LIMIT_PAGES
     The default value for the maximum number of pages of data to be retained in memory.
final public static  StringDEFAULT_MORE_INDICATOR
     The default value (">") used to indicate that the total number of records or pages is unknown.

Constructor Summary
public  LargeSelect(Criteria criteria, int pageSize)
     Creates a LargeSelect whose results are returned as a List containing a maximum of pageSize Village Record objects at a time, maintaining a maximum of LargeSelect.memoryPageLimit pages of results in memory.
Parameters:
  criteria - object used by BasePeer to build the query.
public  LargeSelect(Criteria criteria, int pageSize, int memoryPageLimit)
     Creates a LargeSelect whose results are returned as a List containing a maximum of pageSize Village Record objects at a time, maintaining a maximum of memoryPageLimit pages of results in memory.
Parameters:
  criteria - object used by BasePeer to build the query.
public  LargeSelect(Criteria criteria, int pageSize, String returnBuilderClassName)
     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 time, maintaining a maximum of LargeSelect.memoryPageLimit pages of results in memory.
Parameters:
  criteria - object used by BasePeer to build the query.
public  LargeSelect(Criteria criteria, int pageSize, int memoryPageLimit, String returnBuilderClassName)
     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 time, maintaining a maximum of memoryPageLimit pages of results in memory.
Parameters:
  criteria - object used by BasePeer to build the query.

Method Summary
public  intgetCurrentPageNumber()
     Retrieve the number of the current page.
public  ListgetCurrentPageResults()
     Provide access to the results from the current page.
public  intgetCurrentPageSize()
     Provides a count of the number of rows to be displayed on the current page - for the last page this may be less than the configured page size.
public  intgetFirstRecordNoForPage()
     Provide the record number of the first row included on the current page.
public  intgetLastRecordNoForPage()
     Provide the record number of the last row included on the current page.
public static  intgetMemoryPageLimit()
     Retrieves the multiplier that will be used to compute the memory limit when a constructor with no memory page limit is used - the memory limit will be this number multiplied by the page size.
public static  StringgetMoreIndicator()
     Retrieve the more pages/records indicator.
public  ListgetNextResults()
     Gets the next page of rows.
public  booleangetNextResultsAvailable()
     Indicates if further result pages are available.
public  ListgetPage(int pageNumber)
     Retrieve a specific page, if it exists.
Parameters:
  pageNumber - the number of the page to be retrieved - must begreater than zero.
public  StringgetPageProgressText()
     A convenience method that provides text showing progress through the selected rows on a page basis.
public  intgetPageSize()
     Retrieve the page size.
public  booleangetPaginated()
     Provide an indication of whether or not paging of results will be required.
public  ListgetPreviousResults()
     Gets the previous page of rows.
public  booleangetPreviousResultsAvailable()
     Indicates if previous results pages are available.
public  StringgetRecordProgressText()
     A convenience method that provides text showing progress through the selected rows on a record basis.
public  StringgetSearchParam(String name)
     Retrieve a search parameter.
public  StringgetSearchParam(String name, String defaultValue)
     Retrieve a search parameter.
public  intgetTotalPages()
     Retrieve the total number of pages of search results that are known to exist (this will be the actual value when the query has completeted (see getQyeryCompleted()).
public  intgetTotalRecords()
     Retrieve the total number of search result records that are known to exist (this will be the actual value when the query has completeted (see getTotalsFinalized()).
public  booleangetTotalsFinalized()
     Provide access to indicator that the total values for the number of records and pages are now accurate as opposed to known upper limits.
public  booleanhasResultsAvailable()
     Indicates if any results are available.
public synchronized  voidinvalidateResult()
     Clear the query result so that the query is reexecuted when the next page is retrieved.
public  voidremoveSearchParam(String name)
     Remove a value from the search parameters.
public  voidrun()
     A background thread that retrieves the rows.
public static  voidsetMemoryPageLimit(int memoryPageLimit)
     Sets the multiplier that will be used to compute the memory limit when a constructor with no memory page limit is used - the memory limit will be this number multiplied by the page size.
public static  voidsetMoreIndicator(String moreIndicator)
     Provide a way of changing the more pages/records indicator.
public  voidsetSearchParam(String name, String value)
     Set a search parameter.
public  StringtoString()
     Provide something useful for debugging purposes.

Field Detail
DEFAULT_MEMORY_LIMIT_PAGES
final public static int DEFAULT_MEMORY_LIMIT_PAGES(Code)
The default value for the maximum number of pages of data to be retained in memory.



DEFAULT_MORE_INDICATOR
final public static String DEFAULT_MORE_INDICATOR(Code)
The default value (">") used to indicate that the total number of records or pages is unknown.




Constructor Detail
LargeSelect
public LargeSelect(Criteria criteria, int pageSize)(Code)
Creates a LargeSelect whose results are returned as a List containing a maximum of pageSize Village Record objects at a time, maintaining a maximum of LargeSelect.memoryPageLimit pages of results in memory.
Parameters:
  criteria - object used by BasePeer to build the query. In order toallow this class to utilise database server implemented offsets andlimits (when available), the provided criteria must not have any limit oroffset defined.
Parameters:
  pageSize - number of rows to return in one block.
throws:
  IllegalArgumentException - if criteria uses one orboth of offset and limit, or if pageSize is less than 1;



LargeSelect
public LargeSelect(Criteria criteria, int pageSize, int memoryPageLimit)(Code)
Creates a LargeSelect whose results are returned as a List containing a maximum of pageSize Village Record objects at a time, maintaining a maximum of memoryPageLimit pages of results in memory.
Parameters:
  criteria - object used by BasePeer to build the query. In order toallow this class to utilise database server implemented offsets andlimits (when available), the provided criteria must not have any limit oroffset defined.
Parameters:
  pageSize - number of rows to return in one block.
Parameters:
  memoryPageLimit - maximum number of pages worth of rows to be heldin memory at one time.
throws:
  IllegalArgumentException - if criteria uses one orboth of offset and limit, or if pageSize ormemoryLimitPages are less than 1;



LargeSelect
public LargeSelect(Criteria criteria, int pageSize, String returnBuilderClassName)(Code)
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 time, maintaining a maximum of LargeSelect.memoryPageLimit pages of results in memory.
Parameters:
  criteria - object used by BasePeer to build the query. In order toallow this class to utilise database server implemented offsets andlimits (when available), the provided criteria must not have any limit oroffset defined. If the criteria does not include the definition of anyselect columns the addSelectColumns(Criteria) method ofthe class named as returnBuilderClassName will be used toadd them.
Parameters:
  pageSize - number of rows to return in one block.
Parameters:
  returnBuilderClassName - The name of the class that will be used tobuild the result records (may implement addSelectColumns(Criteria) and must implement populateObjects(List)).
throws:
  IllegalArgumentException - if criteria uses one orboth of offset and limit, if pageSize is less than 1, or ifproblems are experienced locating and invoking either one or both ofaddSelectColumns(Criteria) and populateObjects(List) in the class named returnBuilderClassName.



LargeSelect
public LargeSelect(Criteria criteria, int pageSize, int memoryPageLimit, String returnBuilderClassName)(Code)
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 time, maintaining a maximum of memoryPageLimit pages of results in memory.
Parameters:
  criteria - object used by BasePeer to build the query. In order toallow this class to utilise database server implemented offsets andlimits (when available), the provided criteria must not have any limit oroffset defined. If the criteria does not include the definition of anyselect columns the addSelectColumns(Criteria) method ofthe class named as returnBuilderClassName will be used toadd them.
Parameters:
  pageSize - number of rows to return in one block.
Parameters:
  memoryPageLimit - maximum number of pages worth of rows to be heldin memory at one time.
Parameters:
  returnBuilderClassName - The name of the class that will be used tobuild the result records (may implement addSelectColumns(Criteria) and must implement populateObjects(List)).
throws:
  IllegalArgumentException - if criteria uses one orboth of offset and limit, if pageSize or memoryLimitPages are less than 1, or if problems are experiencedlocating and invoking either one or both of addSelectColumns(Criteria) and populateObjects(List)in the class named returnBuilderClassName.




Method Detail
getCurrentPageNumber
public int getCurrentPageNumber()(Code)
Retrieve the number of the current page. the current page number.



getCurrentPageResults
public List getCurrentPageResults() throws TorqueException(Code)
Provide access to the results from the current page. a List of query results containing a maximum ofpageSize reslts.
throws:
  TorqueException - if invoking the populateObjects()method runs into problems or a sleep is unexpectedly interrupted.



getCurrentPageSize
public int getCurrentPageSize() throws TorqueException(Code)
Provides a count of the number of rows to be displayed on the current page - for the last page this may be less than the configured page size. the number of records that are included on the current page ofresults.
throws:
  TorqueException - if invoking the populateObjects()method runs into problems or a sleep is unexpectedly interrupted.



getFirstRecordNoForPage
public int getFirstRecordNoForPage()(Code)
Provide the record number of the first row included on the current page. The record number of the first row of the current page.



getLastRecordNoForPage
public int getLastRecordNoForPage() throws TorqueException(Code)
Provide the record number of the last row included on the current page. the record number of the last row of the current page.
throws:
  TorqueException - if invoking the populateObjects()method runs into problems or a sleep is unexpectedly interrupted.



getMemoryPageLimit
public static int getMemoryPageLimit()(Code)
Retrieves the multiplier that will be used to compute the memory limit when a constructor with no memory page limit is used - the memory limit will be this number multiplied by the page size.



getMoreIndicator
public static String getMoreIndicator()(Code)
Retrieve the more pages/records indicator.



getNextResults
public List getNextResults() throws TorqueException(Code)
Gets the next page of rows. a List of query results containing a maximum ofpageSize reslts.
throws:
  TorqueException - if invoking the populateObjects()method runs into problems or a sleep is unexpectedly interrupted.



getNextResultsAvailable
public boolean getNextResultsAvailable()(Code)
Indicates if further result pages are available. true when further results are available.



getPage
public List getPage(int pageNumber) throws TorqueException(Code)
Retrieve a specific page, if it exists.
Parameters:
  pageNumber - the number of the page to be retrieved - must begreater than zero. An empty List will be returned ifpageNumber exceeds the total number of pages that exist. a List of query results containing a maximum ofpageSize results.
throws:
  IllegalArgumentException - when pageNo is notgreater than zero.
throws:
  TorqueException - if invoking the populateObjects()method runs into problems or a sleep is unexpectedly interrupted.



getPageProgressText
public String getPageProgressText()(Code)
A convenience method that provides text showing progress through the selected rows on a page basis. progress text in the form of "1 of > 5" where ">" can beconfigured using setMoreIndicator().



getPageSize
public int getPageSize()(Code)
Retrieve the page size. the number of records returned on each invocation ofgetNextResults()/getPreviousResults().



getPaginated
public boolean getPaginated()(Code)
Provide an indication of whether or not paging of results will be required. true when multiple pages of results exist.



getPreviousResults
public List getPreviousResults() throws TorqueException(Code)
Gets the previous page of rows. a List of query results containing a maximum ofpageSize reslts.
throws:
  TorqueException - if invoking the populateObjects()method runs into problems or a sleep is unexpectedly interrupted.



getPreviousResultsAvailable
public boolean getPreviousResultsAvailable()(Code)
Indicates if previous results pages are available. true when previous results are available.



getRecordProgressText
public String getRecordProgressText() throws TorqueException(Code)
A convenience method that provides text showing progress through the selected rows on a record basis. progress text in the form of "26 - 50 of > 250" where ">"can be configured using setMoreIndicator().
throws:
  TorqueException - if invoking the populateObjects()method runs into problems or a sleep is unexpectedly interrupted.



getSearchParam
public String getSearchParam(String name)(Code)
Retrieve a search parameter. This acts as a convenient place to store parameters that relate to the LargeSelect to make it easy to get at them in order to repopulate search parameters on a form when the next page of results is retrieved - they in no way effect the operation of LargeSelect.
Parameters:
  name - the search parameter key to retrieve. the value of the search parameter.



getSearchParam
public String getSearchParam(String name, String defaultValue)(Code)
Retrieve a search parameter. This acts as a convenient place to store parameters that relate to the LargeSelect to make it easy to get at them in order to repopulate search parameters on a form when the next page of results is retrieved - they in no way effect the operation of LargeSelect.
Parameters:
  name - the search parameter key to retrieve.
Parameters:
  defaultValue - the default value to return if the key is not found. the value of the search parameter.



getTotalPages
public int getTotalPages()(Code)
Retrieve the total number of pages of search results that are known to exist (this will be the actual value when the query has completeted (see getQyeryCompleted()). The convenience method getPageProgressText() may be more useful for presenting to users. the number of pages of results known to exist (not accurate untilgetTotalsFinalized() returns true).



getTotalRecords
public int getTotalRecords()(Code)
Retrieve the total number of search result records that are known to exist (this will be the actual value when the query has completeted (see getTotalsFinalized()). The convenience method getRecordProgressText() may be more useful for presenting to users. the number of result records known to exist (not accurate untilgetTotalsFinalized() returns true).



getTotalsFinalized
public boolean getTotalsFinalized()(Code)
Provide access to indicator that the total values for the number of records and pages are now accurate as opposed to known upper limits. true when the totals are known to have been fullycomputed.



hasResultsAvailable
public boolean hasResultsAvailable()(Code)
Indicates if any results are available. true of any results are available.



invalidateResult
public synchronized void invalidateResult() throws TorqueException(Code)
Clear the query result so that the query is reexecuted when the next page is retrieved. You may want to invoke this method if you are returning to a page after performing an operation on an item in the result set.
throws:
  TorqueException - if a sleep is interrupted.



removeSearchParam
public void removeSearchParam(String name)(Code)
Remove a value from the search parameters.
Parameters:
  name - the search parameter key to remove.



run
public void run()(Code)
A background thread that retrieves the rows.



setMemoryPageLimit
public static void setMemoryPageLimit(int memoryPageLimit)(Code)
Sets the multiplier that will be used to compute the memory limit when a constructor with no memory page limit is used - the memory limit will be this number multiplied by the page size.
Parameters:
  memoryPageLimit - the maximum number of pages to be in memoryat one time.



setMoreIndicator
public static void setMoreIndicator(String moreIndicator)(Code)
Provide a way of changing the more pages/records indicator.
Parameters:
  moreIndicator - the indicator to use in place of the default(">").



setSearchParam
public void setSearchParam(String name, String value)(Code)
Set a search parameter. If the value is null then the key will be removed from the parameters.
Parameters:
  name - the search parameter key to set.
Parameters:
  value - the value of the search parameter to store.



toString
public String toString()(Code)
Provide something useful for debugging purposes. some basic information about this instance of LargeSelect.



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.