Class SQLServer2005LimitHandler

java.lang.Object
org.hibernate.dialect.pagination.AbstractLimitHandler
org.hibernate.community.dialect.pagination.SQLServer2005LimitHandler
All Implemented Interfaces:
org.hibernate.dialect.pagination.LimitHandler

public class SQLServer2005LimitHandler extends org.hibernate.dialect.pagination.AbstractLimitHandler
A LimitHandler compatible with SQL Server 2005 and later that uses top() and rownumber().
  • Field Summary

    Fields inherited from class org.hibernate.dialect.pagination.AbstractLimitHandler

    NO_LIMIT
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    bindLimitParametersAtEndOfQuery(org.hibernate.query.spi.Limit limit, PreparedStatement statement, int index)
     
    int
    bindLimitParametersAtStartOfQuery(org.hibernate.query.spi.Limit limit, PreparedStatement statement, int index)
     
    int
    convertToFirstRowValue(int zeroBasedFirstResult)
     
    processSql(String sql, int jdbcParameterCount, @Nullable org.hibernate.sql.ast.spi.ParameterMarkerStrategy parameterMarkerStrategy, org.hibernate.query.spi.QueryOptions queryOptions)
     
    processSql(String sql, org.hibernate.query.spi.Limit limit)
    When the offset of the current row is 0, add a top(?) clause to the given SQL query.
    final boolean
     
    final boolean
     
    final boolean
     

    Methods inherited from class org.hibernate.dialect.pagination.AbstractLimitHandler

    bindLimitParameters, bindLimitParametersFirst, bindLimitParametersInReverseOrder, forceLimitUsage, getFirstRow, getForUpdatePattern, getMaxOrLimit, hasFirstRow, hasMaxRows, insertAfterDistinct, insertAfterSelect, insertAtEnd, insertBeforeForUpdate, setMaxRows, supportsLimitOffset, supportsOffset

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.hibernate.dialect.pagination.LimitHandler

    getParameterPositionStart, processSql, processSqlMutatesState
  • Constructor Details

    • SQLServer2005LimitHandler

      public SQLServer2005LimitHandler()
  • Method Details

    • supportsLimit

      public final boolean supportsLimit()
      Specified by:
      supportsLimit in interface org.hibernate.dialect.pagination.LimitHandler
      Overrides:
      supportsLimit in class org.hibernate.dialect.pagination.AbstractLimitHandler
    • useMaxForLimit

      public final boolean useMaxForLimit()
      Overrides:
      useMaxForLimit in class org.hibernate.dialect.pagination.AbstractLimitHandler
    • supportsVariableLimit

      public final boolean supportsVariableLimit()
      Overrides:
      supportsVariableLimit in class org.hibernate.dialect.pagination.AbstractLimitHandler
    • convertToFirstRowValue

      public int convertToFirstRowValue(int zeroBasedFirstResult)
      Overrides:
      convertToFirstRowValue in class org.hibernate.dialect.pagination.AbstractLimitHandler
    • processSql

      public String processSql(String sql, org.hibernate.query.spi.Limit limit)
      When the offset of the current row is 0, add a top(?) clause to the given SQL query. When the offset is non-zero, wrap the given query in an outer query that limits the results using the row_number() window function.
       with query_ as (
           select row_.*, row_number()
               over (order by current_timestamp) AS rownumber_
           from ( [original-query] ) row_
       )
       select [alias-list] from query_
       where rownumber_ >= ? and rownumber_ < ?
       

      Where [original-query] is the original SQL query, with a top() clause added iff the query has an order by clause, and with generated aliases added to any elements of the projection list that don't already have aliases, and [alias-list] is a list of aliases in the projection list.

      Specified by:
      processSql in interface org.hibernate.dialect.pagination.LimitHandler
      Overrides:
      processSql in class org.hibernate.dialect.pagination.AbstractLimitHandler
      Returns:
      A new SQL statement
    • processSql

      public String processSql(String sql, int jdbcParameterCount, @Nullable org.hibernate.sql.ast.spi.ParameterMarkerStrategy parameterMarkerStrategy, org.hibernate.query.spi.QueryOptions queryOptions)
    • bindLimitParametersAtStartOfQuery

      public int bindLimitParametersAtStartOfQuery(org.hibernate.query.spi.Limit limit, PreparedStatement statement, int index) throws SQLException
      Specified by:
      bindLimitParametersAtStartOfQuery in interface org.hibernate.dialect.pagination.LimitHandler
      Overrides:
      bindLimitParametersAtStartOfQuery in class org.hibernate.dialect.pagination.AbstractLimitHandler
      Throws:
      SQLException
    • bindLimitParametersAtEndOfQuery

      public int bindLimitParametersAtEndOfQuery(org.hibernate.query.spi.Limit limit, PreparedStatement statement, int index) throws SQLException
      Specified by:
      bindLimitParametersAtEndOfQuery in interface org.hibernate.dialect.pagination.LimitHandler
      Overrides:
      bindLimitParametersAtEndOfQuery in class org.hibernate.dialect.pagination.AbstractLimitHandler
      Throws:
      SQLException