org.hdpagination.dataaccess.jdbc
Class JdbcQueryTemplate

java.lang.Object
  extended by org.hdpagination.dataaccess.jdbc.JdbcQueryTemplate
All Implemented Interfaces:
QueryTemplate
Direct Known Subclasses:
DB2JdbcQueryTemplate, HSQLDBJdbcQueryTemplate, MySqlJdbcQueryTemplate, OracleJdbcQueryTemplate, PostgreSQLQueryTemplate, SQLAnywhereJdbcQueryTemplate, StandardJdbcQueryTemplate

public abstract class JdbcQueryTemplate
extends java.lang.Object
implements QueryTemplate

The type of QueryTemplate to run a pagination based query against JDBC. Different of database providers (e.g. Oracle, MySQl, DB2, HSQLDB) have their own implementation class which extends from this abstract class. They share common code to execute query but have different way to translate the original sql to a pagination based sql based on their own sql syntax. Because of this, QueryTemplate implementation class for particular database provider must implement its own method convertPaginationSql. For some provider,it even has to override the method convertCountSql if the default way (implemented in this class) to translate the original sql to 'count total records' sql does not work properly in that database.

Since:
1.0
Author:
Liangfeng Ren

Constructor Summary
JdbcQueryTemplate(javax.sql.DataSource dataSource)
           
 
Method Summary
protected  java.lang.String convertCountSql(java.lang.String querySql)
          Translate original query sql to the sql which can be used to query the count of total records.
protected abstract  java.lang.String convertPaginationSql(java.lang.String sql, int pageNo, int pageSize)
          Translate original query sql to pagination based sql
 int countRows(QueryCallback callback)
          query total number of records for this search
 java.util.List query(QueryCallback callback, int pageSize, int pageNo)
          execute query and return only one page of data
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcQueryTemplate

public JdbcQueryTemplate(javax.sql.DataSource dataSource)
Parameters:
dataSource - DataSource that the query is executed against
Method Detail

query

public java.util.List query(QueryCallback callback,
                            int pageSize,
                            int pageNo)
Description copied from interface: QueryTemplate
execute query and return only one page of data

Specified by:
query in interface QueryTemplate
pageSize - number of records per page
pageNo - index of current page,index begins with 0.
Returns:

countRows

public int countRows(QueryCallback callback)
Description copied from interface: QueryTemplate
query total number of records for this search

Specified by:
countRows in interface QueryTemplate
Returns:

convertPaginationSql

protected abstract java.lang.String convertPaginationSql(java.lang.String sql,
                                                         int pageNo,
                                                         int pageSize)
Translate original query sql to pagination based sql

Parameters:
sql - original sql
pageNo - current page number (start from 0)
pageSize - how many records is displayed in one page
Returns:
return pagination based sql

convertCountSql

protected java.lang.String convertCountSql(java.lang.String querySql)
Translate original query sql to the sql which can be used to query the count of total records. If this default translation does not work in one particular database, its corresponding subclass of JdbcQueryTemplate should override this method.

Parameters:
querySql - original sql
Returns:
return sql to query the count of total records.


Copyright © 2008 HDPagination All Rights Reserved.