类 SQLServer2005LimitHandler
- java.lang.Object
-
- org.hibernate.dialect.pagination.AbstractLimitHandler
-
- org.hibernate.dialect.pagination.SQLServer2005LimitHandler
-
- 所有已实现的接口:
LimitHandler
- 直接已知子类:
SQLServer2012LimitHandler
public class SQLServer2005LimitHandler extends AbstractLimitHandler
LIMIT clause handler compatible with SQL Server 2005 and later.- 作者:
- Lukasz Antoniak (lukasz dot antoniak at gmail dot com), Chris Cranford
-
-
构造器概要
构造器 构造器 说明 SQLServer2005LimitHandler()Constructs a SQLServer2005LimitHandler
-
方法概要
所有方法 实例方法 具体方法 修饰符和类型 方法 说明 protected voidaddTopExpression(StringBuilder sql, int offset)AddsTOPexpression.intbindLimitParametersAtEndOfQuery(RowSelection selection, PreparedStatement statement, int index)Bind parameter values needed by the LIMIT clause after original SELECT statement.intbindLimitParametersAtStartOfQuery(RowSelection selection, PreparedStatement statement, int index)Bind parameter values needed by the LIMIT clause before original SELECT statement.intconvertToFirstRowValue(int zeroBasedFirstResult)Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset.protected voidencloseWithOuterQuery(StringBuilder sql, int offset)Encloses original SQL statement with outer query that provides __hibernate_row_nr__ column.protected StringfillAliasInSelectClause(StringBuilder sb, int offset)Adds missing aliases in provided SELECT clause and returns coma-separated list of them.StringprocessSql(String sql, RowSelection selection)Add a LIMIT clause to the given SQL SELECT (HHH-2655: ROW_NUMBER for Paging) The LIMIT SQL will look like:booleansupportsLimit()Does this handler support some form of limiting query results via a SQL clause?booleansupportsLimitOffset()Does this handler's LIMIT support (if any) additionally support specifying an offset?booleansupportsVariableLimit()Does this handler support bind variables (i.e., prepared statement parameters) for its limit/offset?booleanuseMaxForLimit()Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows?-
从类继承的方法 org.hibernate.dialect.pagination.AbstractLimitHandler
bindLimitParameters, bindLimitParametersFirst, bindLimitParametersInReverseOrder, forceLimitUsage, getMaxOrLimit, setMaxRows
-
-
-
-
方法详细资料
-
supportsLimit
public boolean supportsLimit()
从接口复制的说明:LimitHandlerDoes this handler support some form of limiting query results via a SQL clause?- 指定者:
supportsLimit在接口中LimitHandler- 覆盖:
supportsLimit在类中AbstractLimitHandler- 返回:
- True if this handler supports some form of LIMIT.
-
useMaxForLimit
public boolean useMaxForLimit()
从类复制的说明:AbstractLimitHandlerDoes the LIMIT clause take a "maximum" row number instead of a total number of returned rows? This is easiest understood via an example. Consider you have a table with 20 rows, but you only want to retrieve rows number 11 through 20. Generally, a limit with offset would say that the offset = 11 and the limit = 10 (we only want 10 rows at a time); this is specifying the total number of returned rows. Some dialects require that we instead specify offset = 11 and limit = 20, where 20 is the "last" row we want relative to offset (i.e. total number of rows = 20 - 11 = 9) So essentially, is limit relative from offset? Or is limit absolute?- 覆盖:
useMaxForLimit在类中AbstractLimitHandler- 返回:
- True if limit is relative from offset; false otherwise.
-
supportsLimitOffset
public boolean supportsLimitOffset()
从接口复制的说明:LimitHandlerDoes this handler's LIMIT support (if any) additionally support specifying an offset?- 指定者:
supportsLimitOffset在接口中LimitHandler- 覆盖:
supportsLimitOffset在类中AbstractLimitHandler- 返回:
- True if the handler supports an offset within the limit support.
-
supportsVariableLimit
public boolean supportsVariableLimit()
从类复制的说明:AbstractLimitHandlerDoes this handler support bind variables (i.e., prepared statement parameters) for its limit/offset?- 覆盖:
supportsVariableLimit在类中AbstractLimitHandler- 返回:
- True if bind variables can be used; false otherwise.
-
convertToFirstRowValue
public int convertToFirstRowValue(int zeroBasedFirstResult)
从类复制的说明:AbstractLimitHandlerHibernate APIs explicitly state that setFirstResult() should be a zero-based offset. Here we allow the Dialect a chance to convert that value based on what the underlying db or driver will expect. NOTE: what gets passed intoAbstractLimitHandler.processSql(String, org.hibernate.engine.spi.RowSelection)is the zero-based offset. Dialects which do notAbstractLimitHandler.supportsVariableLimit()should take care to perform any needed first-row-conversion calls prior to injecting the limit values into the SQL string.- 覆盖:
convertToFirstRowValue在类中AbstractLimitHandler- 参数:
zeroBasedFirstResult- The user-supplied, zero-based first row offset.- 返回:
- The corresponding db/dialect specific offset.
- 另请参阅:
Query.setFirstResult(int),Criteria.setFirstResult(int)
-
processSql
public String processSql(String sql, RowSelection selection)
Add a LIMIT clause to the given SQL SELECT (HHH-2655: ROW_NUMBER for Paging) The LIMIT SQL will look like:WITH query AS ( SELECT inner_query.* , ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __hibernate_row_nr__ FROM ( original_query_with_top_if_order_by_present_and_all_aliased_columns ) inner_query ) SELECT alias_list FROM query WHERE __hibernate_row_nr__ >= offset AND __hibernate_row_nr__ < offset + lastWhen offset equals 0, onlyTOP(?)expression is added to the original query.- 指定者:
processSql在接口中LimitHandler- 覆盖:
processSql在类中AbstractLimitHandler- 参数:
sql- the SQL query to process.selection- the selection criteria for rows.- 返回:
- A new SQL statement with the LIMIT clause applied.
-
bindLimitParametersAtStartOfQuery
public int bindLimitParametersAtStartOfQuery(RowSelection selection, PreparedStatement statement, int index) throws SQLException
从接口复制的说明:LimitHandlerBind parameter values needed by the LIMIT clause before original SELECT statement.- 指定者:
bindLimitParametersAtStartOfQuery在接口中LimitHandler- 覆盖:
bindLimitParametersAtStartOfQuery在类中AbstractLimitHandler- 参数:
selection- the selection criteria for rows.statement- Statement to which to bind limit parameter values.index- Index from which to start binding.- 返回:
- The number of parameter values bound.
- 抛出:
SQLException- Indicates problems binding parameter values.
-
bindLimitParametersAtEndOfQuery
public int bindLimitParametersAtEndOfQuery(RowSelection selection, PreparedStatement statement, int index) throws SQLException
从接口复制的说明:LimitHandlerBind parameter values needed by the LIMIT clause after original SELECT statement.- 指定者:
bindLimitParametersAtEndOfQuery在接口中LimitHandler- 覆盖:
bindLimitParametersAtEndOfQuery在类中AbstractLimitHandler- 参数:
selection- the selection criteria for rows.statement- Statement to which to bind limit parameter values.index- Index from which to start binding.- 返回:
- The number of parameter values bound.
- 抛出:
SQLException- Indicates problems binding parameter values.
-
fillAliasInSelectClause
protected String fillAliasInSelectClause(StringBuilder sb, int offset)
Adds missing aliases in provided SELECT clause and returns coma-separated list of them. If query takes advantage of expressions like * or {table}.* inside SELECT clause, method returns *.- 参数:
sb- SQL query.offset- the starting offset.- 返回:
- List of aliases separated with comas or *.
-
encloseWithOuterQuery
protected void encloseWithOuterQuery(StringBuilder sql, int offset)
Encloses original SQL statement with outer query that provides __hibernate_row_nr__ column.- 参数:
sql- SQL query.offset- SQL query offset.
-
addTopExpression
protected void addTopExpression(StringBuilder sql, int offset)
AddsTOPexpression. Parameter value is bind inbindLimitParametersAtStartOfQuery(RowSelection, PreparedStatement, int)method.- 参数:
sql- SQL query.offset- the offset where top expression pattern matching should begin.
-
-