Package org.hibernate.dialect.pagination
Class SQLServer2005LimitHandler
- java.lang.Object
-
- org.hibernate.dialect.pagination.AbstractLimitHandler
-
- org.hibernate.dialect.pagination.SQLServer2005LimitHandler
-
- All Implemented Interfaces:
LimitHandler
public class SQLServer2005LimitHandler extends AbstractLimitHandler
-
-
Field Summary
-
Fields inherited from class org.hibernate.dialect.pagination.AbstractLimitHandler
NO_LIMIT
-
-
Constructor Summary
Constructors Constructor Description SQLServer2005LimitHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intbindLimitParametersAtEndOfQuery(Limit limit, PreparedStatement statement, int index)intbindLimitParametersAtStartOfQuery(Limit limit, PreparedStatement statement, int index)intconvertToFirstRowValue(int zeroBasedFirstResult)The API methodQuery.setFirstResult(int)accepts a zero-based offset.StringprocessSql(String sql, Limit limit)When the offset of the current row is 0, add atop(?)clause to the given SQL query.booleansupportsLimit()Does this handler support limiting query results?booleansupportsVariableLimit()Does this handler support bind variables (JDBC prepared statement parameters) for its limit/offset?booleanuseMaxForLimit()Does the limit clause expect the number of the last row, or the "page size", the maximum number of rows we want to receive? Hibernate'sQuery.setMaxResults(int)accepts the page size, so the number of the last row is obtained by adding the number of the first row, which is one greater thanQuery.setFirstResult(int).-
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
processSql
-
-
-
-
Method Detail
-
supportsLimit
public final boolean supportsLimit()
Description copied from interface:LimitHandlerDoes this handler support limiting query results?- Specified by:
supportsLimitin interfaceLimitHandler- Overrides:
supportsLimitin classAbstractLimitHandler- Returns:
- True if this handler supports limit alone.
-
useMaxForLimit
public final boolean useMaxForLimit()
Description copied from class:AbstractLimitHandlerDoes the limit clause expect the number of the last row, or the "page size", the maximum number of rows we want to receive? Hibernate'sQuery.setMaxResults(int)accepts the page size, so the number of the last row is obtained by adding the number of the first row, which is one greater thanQuery.setFirstResult(int).- Overrides:
useMaxForLimitin classAbstractLimitHandler- Returns:
- true if the limit clause expects the number of the last row, false if it expects the page size
-
supportsVariableLimit
public final boolean supportsVariableLimit()
Description copied from class:AbstractLimitHandlerDoes this handler support bind variables (JDBC prepared statement parameters) for its limit/offset?- Overrides:
supportsVariableLimitin classAbstractLimitHandler- Returns:
- true if bind variables can be used
-
convertToFirstRowValue
public int convertToFirstRowValue(int zeroBasedFirstResult)
Description copied from class:AbstractLimitHandlerThe API methodQuery.setFirstResult(int)accepts a zero-based offset. Does this dialect require a one-based offset to be specified in the offset clause?- Overrides:
convertToFirstRowValuein classAbstractLimitHandler- Parameters:
zeroBasedFirstResult- The user-supplied, zero-based first row offset.- Returns:
- The resulting offset, adjusted to one-based if necessary.
-
processSql
public String processSql(String sql, Limit limit)
When the offset of the current row is 0, add atop(?)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 therow_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 atop()clause added iff the query has anorder byclause, 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:
processSqlin interfaceLimitHandler- Overrides:
processSqlin classAbstractLimitHandler- Returns:
- A new SQL statement
-
bindLimitParametersAtStartOfQuery
public int bindLimitParametersAtStartOfQuery(Limit limit, PreparedStatement statement, int index) throws SQLException
- Specified by:
bindLimitParametersAtStartOfQueryin interfaceLimitHandler- Overrides:
bindLimitParametersAtStartOfQueryin classAbstractLimitHandler- Throws:
SQLException
-
bindLimitParametersAtEndOfQuery
public int bindLimitParametersAtEndOfQuery(Limit limit, PreparedStatement statement, int index) throws SQLException
- Specified by:
bindLimitParametersAtEndOfQueryin interfaceLimitHandler- Overrides:
bindLimitParametersAtEndOfQueryin classAbstractLimitHandler- Throws:
SQLException
-
-