org.springframework.batch.item.database.support
Class AbstractSqlPagingQueryProvider

java.lang.Object
  extended by org.springframework.batch.item.database.support.AbstractSqlPagingQueryProvider
All Implemented Interfaces:
PagingQueryProvider
Direct Known Subclasses:
H2PagingQueryProvider, HsqlPagingQueryProvider, MySqlPagingQueryProvider, OraclePagingQueryProvider, PostgresPagingQueryProvider, SqlWindowingPagingQueryProvider

public abstract class AbstractSqlPagingQueryProvider
extends Object
implements PagingQueryProvider

Abstract SQL Paging Query Provider to serve as a base class for all provided SQL paging query providers. Any implementation must provide a way to specify the select clause, from clause and optionally a where clause. In addition a way to specify a single column sort key must also be provided. This sort key will be used to provide the paging functionality. It is recommended that there should be an index for the sort key to provide better performance. Provides properties and preparation for the mandatory "selectClause" and "fromClause" as well as for the optional "whereClause". Also provides property for the mandatory "sortKey".

Since:
2.0
Author:
Thomas Risberg, Dave Syer

Constructor Summary
AbstractSqlPagingQueryProvider()
           
 
Method Summary
abstract  String generateFirstPageQuery(int pageSize)
          Method generating the query string to be used for retrieving the first page.
abstract  String generateJumpToItemQuery(int itemIndex, int pageSize)
          Method generating the query string to be used for jumping to a specific item position.
abstract  String generateRemainingPagesQuery(int pageSize)
          Method generating the query string to be used for retrieving the pages following the first page.
protected  String getFromClause()
           
 int getParameterCount()
          The number of parameters that are declared in the query
protected  String getSelectClause()
           
 String getSortKey()
          The sort key (unique single column name).
protected  String getSortKeyPlaceHolder()
          The sort key placeholder will vary depending on whether named parameters or traditional placeholders are used in query strings.
 String getSortKeyWithoutAlias()
          The sort key (unique single column name) without alias.
protected  String getWhereClause()
           
 void init(DataSource dataSource)
          Check mandatory properties.
 boolean isAscending()
          Get the flag that signals that the sort key is applied ascending.
 boolean isUsingNamedParameters()
          Indicate whether the generated queries use named parameter syntax.
 void setAscending(boolean ascending)
          Set the flag that signals that the sort key is applied ascending (default true).
 void setFromClause(String fromClause)
           
 void setSelectClause(String selectClause)
           
 void setSortKey(String sortKey)
           
 void setWhereClause(String whereClause)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractSqlPagingQueryProvider

public AbstractSqlPagingQueryProvider()
Method Detail

setSelectClause

public void setSelectClause(String selectClause)
Parameters:
selectClause - SELECT clause part of SQL query string

getSelectClause

protected String getSelectClause()
Returns:
SQL SELECT clause part of SQL query string

setFromClause

public void setFromClause(String fromClause)
Parameters:
fromClause - FROM clause part of SQL query string

getFromClause

protected String getFromClause()
Returns:
SQL FROM clause part of SQL query string

setWhereClause

public void setWhereClause(String whereClause)
Parameters:
whereClause - WHERE clause part of SQL query string

getWhereClause

protected String getWhereClause()
Returns:
SQL WHERE clause part of SQL query string

setSortKey

public void setSortKey(String sortKey)
Parameters:
sortKey - key to use to sort and limit page content

setAscending

public void setAscending(boolean ascending)
Set the flag that signals that the sort key is applied ascending (default true).

Parameters:
ascending - the ascending value to set

isAscending

public boolean isAscending()
Get the flag that signals that the sort key is applied ascending.

Returns:
the ascending flag

getSortKey

public String getSortKey()
Description copied from interface: PagingQueryProvider
The sort key (unique single column name).

Specified by:
getSortKey in interface PagingQueryProvider
Returns:
sortKey key to use to sort and limit page content

getSortKeyWithoutAlias

public String getSortKeyWithoutAlias()
Description copied from interface: PagingQueryProvider
The sort key (unique single column name) without alias.

Specified by:
getSortKeyWithoutAlias in interface PagingQueryProvider
Returns:
sortKey key to use to sort and limit page content (without alias)

getParameterCount

public int getParameterCount()
Description copied from interface: PagingQueryProvider
The number of parameters that are declared in the query

Specified by:
getParameterCount in interface PagingQueryProvider
Returns:
number of parameters

isUsingNamedParameters

public boolean isUsingNamedParameters()
Description copied from interface: PagingQueryProvider
Indicate whether the generated queries use named parameter syntax.

Specified by:
isUsingNamedParameters in interface PagingQueryProvider
Returns:
true if named parameter syntax is used

getSortKeyPlaceHolder

protected String getSortKeyPlaceHolder()
The sort key placeholder will vary depending on whether named parameters or traditional placeholders are used in query strings.

Returns:
place holder for sortKey.

init

public void init(DataSource dataSource)
          throws Exception
Check mandatory properties.

Specified by:
init in interface PagingQueryProvider
Parameters:
dataSource - DataSource to use for any initialization
Throws:
Exception
See Also:
InitializingBean.afterPropertiesSet()

generateFirstPageQuery

public abstract String generateFirstPageQuery(int pageSize)
Method generating the query string to be used for retrieving the first page. This method must be implemented in sub classes.

Specified by:
generateFirstPageQuery in interface PagingQueryProvider
Parameters:
pageSize - number of rows to read per page
Returns:
query string

generateRemainingPagesQuery

public abstract String generateRemainingPagesQuery(int pageSize)
Method generating the query string to be used for retrieving the pages following the first page. This method must be implemented in sub classes.

Specified by:
generateRemainingPagesQuery in interface PagingQueryProvider
Parameters:
pageSize - number of rows to read per page
Returns:
query string

generateJumpToItemQuery

public abstract String generateJumpToItemQuery(int itemIndex,
                                               int pageSize)
Method generating the query string to be used for jumping to a specific item position. This method must be implemented in sub classes.

Specified by:
generateJumpToItemQuery in interface PagingQueryProvider
Parameters:
itemIndex - the index of the item to jump to
pageSize - number of rows to read per page
Returns:
query string


Copyright © 2013 SpringSource. All Rights Reserved.