org.springframework.batch.item.database.support

## Class AbstractSqlPagingQueryProvider

- java.lang.Object
- - org.springframework.batch.item.database.support.AbstractSqlPagingQueryProvider

- All Implemented Interfaces:
    PagingQueryProvider
  Direct Known Subclasses:
    H2PagingQueryProvider, HsqlPagingQueryProvider, MySqlPagingQueryProvider, OraclePagingQueryProvider, PostgresPagingQueryProvider, SqlitePagingQueryProvider, SqlWindowingPagingQueryProvider

      public abstract class AbstractSqlPagingQueryProvider
      extends java.lang.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 "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

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractSqlPagingQueryProvider()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `abstract java.lang.String` | `generateFirstPageQuery(int pageSize)` Method generating the query string to be used for retrieving the first page.
    `abstract java.lang.String` | `generateJumpToItemQuery(int itemIndex, int pageSize)` Method generating the query string to be used for jumping to a specific item position.
    `abstract java.lang.String` | `generateRemainingPagesQuery(int pageSize)` Method generating the query string to be used for retrieving the pages following the first page.
    `protected java.lang.String` | `getFromClause()`
    `java.lang.String` | `getGroupClause()` The getter for the group by clause
    `int` | `getParameterCount()` The number of parameters that are declared in the query
    `protected java.lang.String` | `getSelectClause()`
    `java.lang.String` | `getSortKeyPlaceHolder(java.lang.String keyName)` The sort key placeholder will vary depending on whether named parameters or traditional placeholders are used in query strings.
    `java.util.Map<java.lang.String,Order>` | `getSortKeys()` A Map<String, Boolean> of sort columns as the key and boolean for ascending/descending (ascending = true).
    `java.util.Map<java.lang.String,Order>` | `getSortKeysWithoutAliases()` The sort key (unique single column name) without alias.
    `protected java.lang.String` | `getWhereClause()`
    `void` | `init(javax.sql.DataSource dataSource)` Check mandatory properties.
    `boolean` | `isUsingNamedParameters()` Indicate whether the generated queries use named parameter syntax.
    `void` | `setFromClause(java.lang.String fromClause)`
    `void` | `setGroupClause(java.lang.String groupClause)` The setter for the group by clause
    `void` | `setSelectClause(java.lang.String selectClause)`
    `void` | `setSortKeys(java.util.Map<java.lang.String,Order> sortKeys)`
    `void` | `setWhereClause(java.lang.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

    - #### setGroupClause

          public void setGroupClause(java.lang.String groupClause)

      The setter for the group by clause
      Parameters:
        `groupClause` - SQL GROUP BY clause part of the SQL query string

    - #### getGroupClause

          public java.lang.String getGroupClause()

      The getter for the group by clause
      Returns:
        SQL GROUP BY clause part of the SQL query string

    - #### setSelectClause

          public void setSelectClause(java.lang.String selectClause)

      Parameters:
        `selectClause` - SELECT clause part of SQL query string

    - #### getSelectClause

          protected java.lang.String getSelectClause()

      Returns:
        SQL SELECT clause part of SQL query string

    - #### setFromClause

          public void setFromClause(java.lang.String fromClause)

      Parameters:
        `fromClause` - FROM clause part of SQL query string

    - #### getFromClause

          protected java.lang.String getFromClause()

      Returns:
        SQL FROM clause part of SQL query string

    - #### setWhereClause

          public void setWhereClause(java.lang.String whereClause)

      Parameters:
        `whereClause` - WHERE clause part of SQL query string

    - #### getWhereClause

          protected java.lang.String getWhereClause()

      Returns:
        SQL WHERE clause part of SQL query string

    - #### setSortKeys

          public void setSortKeys(java.util.Map<java.lang.String,Order> sortKeys)

      Parameters:
        `sortKeys` - key to use to sort and limit page content

    - #### getSortKeys

          public java.util.Map<java.lang.String,Order> getSortKeys()

      A Map<String, Boolean> of sort columns as the key and boolean for ascending/descending (ascending = true).
      Specified by:
        `getSortKeys` in interface `PagingQueryProvider`
      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 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

          public java.lang.String getSortKeyPlaceHolder(java.lang.String keyName)

      The sort key placeholder will vary depending on whether named parameters or traditional placeholders are used in query strings.
      Specified by:
        `getSortKeyPlaceHolder` in interface `PagingQueryProvider`
      Parameters:
        `keyName` - The sort key name
      Returns:
        place holder for sortKey.

    - #### init

          public void init(javax.sql.DataSource dataSource)
                    throws java.lang.Exception

      Check mandatory properties.
      Specified by:
        `init` in interface `PagingQueryProvider`
      Parameters:
        `dataSource` - DataSource to use for any initialization
      Throws:
        `java.lang.Exception` - for errors when initializing
      See Also:
        `InitializingBean.afterPropertiesSet()`

    - #### generateFirstPageQuery

          public abstract java.lang.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 java.lang.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 java.lang.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

    - #### getSortKeysWithoutAliases

          public java.util.Map<java.lang.String,Order> getSortKeysWithoutAliases()

      Description copied from interface: `PagingQueryProvider`
      The sort key (unique single column name) without alias.
      Specified by:
        `getSortKeysWithoutAliases` in interface `PagingQueryProvider`
      Returns:
        sortKey key to use to sort and limit page content (without alias)