com.geekologue.md4j.dao.hibernate
Class HbmQueryResultPage

java.lang.Object
  extended by com.geekologue.md4j.dao.hibernate.HbmQueryResultPage
All Implemented Interfaces:
Page, java.io.Serializable

public class HbmQueryResultPage
extends java.lang.Object
implements Page

Hibernate-based implementation of the Page interface. Used by Hibernate-based DAOs to page Hibernate Queries, Criteria Queries as well as POJO collection references.

Paging a query is as simple as:

 Page page = new HbmQueryResultPage(session, session
                   .createQuery("from Type obj order by obj.prop desc"),
                   pageNumber, maxResults);
 

Which will only load maxResults+1 objects from the database. You can also page a collection like:

 Page page = new HbmQueryResultPage(session, object.getChildren(), pageNumber,
                   maxResults);
 

Version:
$Revision$
Author:
Manos Batsis 7 Sep 2004
See Also:
Serialized Form

Constructor Summary
HbmQueryResultPage(org.hibernate.Criteria query, java.util.Set projectionProps, int number, int size)
          Constructor that will page a criteria query without loading all results
HbmQueryResultPage(org.hibernate.Query query, int number, int size)
          Constructor that will page a query without loading all results
HbmQueryResultPage(org.hibernate.Session session, java.util.Set collection, int number, int size)
          Constructor that will page a collection.
 
Method Summary
 int getFirstResultIndex()
          Get the index of the first result in the page
 int getLastResultIndex()
           
 java.util.List getList()
          Get the page of results as the list
 int getNext()
           
 int getPageNumber()
          Get the page number
 int getPageSize()
          return pageSize The page size
 java.util.Map getParentOptions()
           
 int getPrevious()
           
 int getTotalPageCount()
          Get the total number of pages that can be used to divide the total results using the current page size.
 int getTotalResultCount()
           
 boolean isFirst()
          See if this page is the first
 boolean isLast()
          See if this page is the last
 void setList(java.util.List newList)
          Set the list of results for this page.
 void setParentOptions(java.util.Map opts)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HbmQueryResultPage

public HbmQueryResultPage(org.hibernate.Query query,
                          int number,
                          int size)
Constructor that will page a query without loading all results

Parameters:
session - The hibernate session that created the query
query - The query with any (named or positional) parameters already set
number - The page number (1,2,3...n)
size - The number of entries a page should contain

HbmQueryResultPage

public HbmQueryResultPage(org.hibernate.Criteria query,
                          java.util.Set projectionProps,
                          int number,
                          int size)
Constructor that will page a criteria query without loading all results

Parameters:
session - The hibernate session that created the query
query - The criteria query
number - The page number (1,2,3...n)
size - The number of entries a page should contain

HbmQueryResultPage

public HbmQueryResultPage(org.hibernate.Session session,
                          java.util.Set collection,
                          int number,
                          int size)
Constructor that will page a collection. Lazy collections are not initialized. Untested.

Parameters:
session - The Hibernate Session to use
collection - The collection to page, e.g.: foo.getBars();
pageNumber - The page number (1,2,3...n)
pageSize - The number of entries a page should contain
Throws:
org.hibernate.HibernateException
Method Detail

getTotalResultCount

public int getTotalResultCount()
Specified by:
getTotalResultCount in interface Page
Returns:
Returns the total number of results the query can return, of which this page instance contains a subset.

getTotalPageCount

public int getTotalPageCount()
Get the total number of pages that can be used to divide the total results using the current page size.

Specified by:
getTotalPageCount in interface Page
Returns:
the total number of pages

isFirst

public boolean isFirst()
See if this page is the first

Specified by:
isFirst in interface Page
Returns:
true if first, false otherwise

isLast

public boolean isLast()
See if this page is the last

Specified by:
isLast in interface Page
Returns:
true if last, false otherwise

getList

public java.util.List getList()
Get the page of results as the list

Specified by:
getList in interface Page
Returns:
the list containing the results for this page

getPageNumber

public int getPageNumber()
Get the page number

Specified by:
getPageNumber in interface Page
Returns:
the page number as given to the constructor

getFirstResultIndex

public int getFirstResultIndex()
Get the index of the first result in the page

Specified by:
getFirstResultIndex in interface Page

getPageSize

public final int getPageSize()
return pageSize The page size

Returns:
the page size

getLastResultIndex

public final int getLastResultIndex()
Returns:
Returns the last result index

getNext

public final int getNext()
Returns:
Returns the number of the next page

getPrevious

public final int getPrevious()
Returns:
Returns the number of the previous page

setList

public void setList(java.util.List newList)
Description copied from interface: Page
Set the list of results for this page. You may want to use this method after processing the list obtained via getList()

Specified by:
setList in interface Page
Parameters:
newList - the list of results to set for this page

getParentOptions

public java.util.Map getParentOptions()
Specified by:
getParentOptions in interface Page
See Also:
Page.getParentOptions()

setParentOptions

public void setParentOptions(java.util.Map opts)


Copyright © 2003-2007 Manos Batsis. All Rights Reserved.