Class AbstractSqlPagingQueryProvider
- All Implemented Interfaces:
PagingQueryProvider
- Direct Known Subclasses:
Db2PagingQueryProvider
,DerbyPagingQueryProvider
,H2PagingQueryProvider
,HanaPagingQueryProvider
,HsqlPagingQueryProvider
,MariaDBPagingQueryProvider
,MySqlPagingQueryProvider
,OraclePagingQueryProvider
,PostgresPagingQueryProvider
,SqlitePagingQueryProvider
,SqlServerPagingQueryProvider
,SqlWindowingPagingQueryProvider
,SybasePagingQueryProvider
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 "sortKeys". Note: The columns that make up the sort key must be a true key and not just a column to order by. It is important to have a unique key constraint on the sort key to guarantee that no data is lost between executions.
- Since:
- 2.0
- Author:
- Thomas Risberg, Dave Syer, Michael Minella, Mahmoud Ben Hassine, Benjamin Hetz
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract String
generateFirstPageQuery
(int pageSize) Method generating the query string to be used for retrieving the first page.abstract String
generateRemainingPagesQuery
(int pageSize) Method generating the query string to be used for retrieving the pages following the first page.protected String
The getter for the group by clauseint
The number of parameters that are declared in the queryprotected String
getSortKeyPlaceHolder
(String keyName) The sort key placeholder will vary depending on whether named parameters or traditional placeholders are used in query strings.A Map<String, Boolean> of sort columns as the key and boolean for ascending/descending (ascending = true).The sort key (unique single column name) without alias.protected String
void
init
(DataSource dataSource) Check mandatory properties.boolean
Indicate whether the generated queries use named parameter syntax.void
setFromClause
(String fromClause) void
setGroupClause
(String groupClause) The setter for the group by clausevoid
setSelectClause
(String selectClause) void
setSortKeys
(Map<String, Order> sortKeys) void
setWhereClause
(String whereClause)
-
Constructor Details
-
AbstractSqlPagingQueryProvider
public AbstractSqlPagingQueryProvider()
-
-
Method Details
-
setGroupClause
The setter for the group by clause- Parameters:
groupClause
- SQL GROUP BY clause part of the SQL query string
-
getGroupClause
The getter for the group by clause- Returns:
- SQL GROUP BY clause part of the SQL query string
-
setSelectClause
- Parameters:
selectClause
- SELECT clause part of SQL query string
-
getSelectClause
- Returns:
- SQL SELECT clause part of SQL query string
-
setFromClause
- Parameters:
fromClause
- FROM clause part of SQL query string
-
getFromClause
- Returns:
- SQL FROM clause part of SQL query string
-
setWhereClause
- Parameters:
whereClause
- WHERE clause part of SQL query string
-
getWhereClause
- Returns:
- SQL WHERE clause part of SQL query string
-
setSortKeys
- Parameters:
sortKeys
- key to use to sort and limit page content
-
getSortKeys
A Map<String, Boolean> of sort columns as the key and boolean for ascending/descending (ascending = true).- Specified by:
getSortKeys
in interfacePagingQueryProvider
- Returns:
- sortKey key to use to sort and limit page content
-
getParameterCount
public int getParameterCount()Description copied from interface:PagingQueryProvider
The number of parameters that are declared in the query- Specified by:
getParameterCount
in interfacePagingQueryProvider
- 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 interfacePagingQueryProvider
- Returns:
- true if named parameter syntax is used
-
getSortKeyPlaceHolder
The sort key placeholder will vary depending on whether named parameters or traditional placeholders are used in query strings.- Specified by:
getSortKeyPlaceHolder
in interfacePagingQueryProvider
- Parameters:
keyName
- The sort key name- Returns:
- place holder for sortKey.
-
init
Check mandatory properties.- Specified by:
init
in interfacePagingQueryProvider
- Parameters:
dataSource
- DataSource to use for any initialization- Throws:
Exception
- for errors when initializing- See Also:
-
InitializingBean.afterPropertiesSet()
-
generateFirstPageQuery
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 interfacePagingQueryProvider
- Parameters:
pageSize
- number of rows to read per page- Returns:
- query string
-
generateRemainingPagesQuery
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 interfacePagingQueryProvider
- Parameters:
pageSize
- number of rows to read per page- Returns:
- query string
-
getSortKeysWithoutAliases
Description copied from interface:PagingQueryProvider
The sort key (unique single column name) without alias.- Specified by:
getSortKeysWithoutAliases
in interfacePagingQueryProvider
- Returns:
- sortKey key to use to sort and limit page content (without alias)
-