|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.github.drinkjava2.jdialects.hibernatesrc.pagination.AbstractLimitHandler
com.github.drinkjava2.jdialects.hibernatesrc.pagination.SQLServer2005LimitHandler
public class SQLServer2005LimitHandler
LIMIT clause handler compatible with SQL Server 2005 and later.
| Field Summary | |
|---|---|
protected boolean |
topAdded
|
| Constructor Summary | |
|---|---|
SQLServer2005LimitHandler()
Constructs a SQLServer2005LimitHandler |
|
| Method Summary | |
|---|---|
protected void |
addTopExpression(StringBuilder sql)
Adds TOP expression. |
int |
bindLimitParametersAtEndOfQuery(RowSelection selection,
PreparedStatement statement,
int index)
Bind parameter values needed by the LIMIT clause afterQuery original SELECT statement. |
int |
bindLimitParametersAtStartOfQuery(RowSelection selection,
PreparedStatement statement,
int index)
Bind parameter values needed by the LIMIT clause beforeQuery original SELECT statement. |
int |
convertToFirstRowValue(int zeroBasedFirstResult)
Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset. |
protected void |
encloseWithOuterQuery(StringBuilder sql)
Encloses original SQL statement with outer query that provides __hibernate_row_nr__ column. |
protected String |
fillAliasInSelectClause(StringBuilder sb)
Adds missing aliases in provided SELECT clause and returns coma-separated list of them. |
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: |
boolean |
supportsLimit()
Does this handler support some form of limiting query results via a SQL clause? |
boolean |
supportsLimitOffset()
Does this handler's LIMIT support (if any) additionally support specifying an offset? |
boolean |
supportsVariableLimit()
Does this handler support bind variables (i.e., prepared statement parameters) for its limit/offset? |
boolean |
useMaxForLimit()
Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows? This is easiest understood via an example. |
| Methods inherited from class com.github.drinkjava2.jdialects.hibernatesrc.pagination.AbstractLimitHandler |
|---|
bindLimitParameters, bindLimitParametersFirst, bindLimitParametersInReverseOrder, forceLimitUsage, getMaxOrLimit, setMaxRows |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected boolean topAdded
| Constructor Detail |
|---|
public SQLServer2005LimitHandler()
| Method Detail |
|---|
public boolean supportsLimit()
LimitHandler
supportsLimit in interface LimitHandlersupportsLimit in class AbstractLimitHandlerpublic boolean useMaxForLimit()
AbstractLimitHandler
useMaxForLimit in class AbstractLimitHandlerpublic boolean supportsLimitOffset()
LimitHandler
supportsLimitOffset in interface LimitHandlersupportsLimitOffset in class AbstractLimitHandlerpublic boolean supportsVariableLimit()
AbstractLimitHandler
supportsVariableLimit in class AbstractLimitHandlerpublic int convertToFirstRowValue(int zeroBasedFirstResult)
AbstractLimitHandlerAbstractLimitHandler#processSql(String, com.github.drinkjava2.jdialects.hibernatesrc.pagination.hibernate.engine.spi.RowSelection) is the zero-based offset.
Dialects which do not AbstractLimitHandler.supportsVariableLimit() should take care to perform any needed first-row-conversion
calls prior to injecting the limit values into the SQL string.
convertToFirstRowValue in class AbstractLimitHandlerzeroBasedFirstResult - The user-supplied, zero-based first row offset.
org.hibernate.Query#setFirstResult,
org.hibernate.Criteria#setFirstResult
public String processSql(String sql,
RowSelection selection)
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 + last
When offset equals 0, only TOP(?) expression is
added to the original query.
processSql in interface LimitHandlerprocessSql in class AbstractLimitHandlersql - the SQL query to process.selection - the selection criteria for rows.
public int bindLimitParametersAtStartOfQuery(RowSelection selection,
PreparedStatement statement,
int index)
throws SQLException
LimitHandler
bindLimitParametersAtStartOfQuery in interface LimitHandlerbindLimitParametersAtStartOfQuery in class AbstractLimitHandlerselection - the selection criteria for rows.statement - Statement to which to bind limit parameter values.index - Index from which to start binding.
SQLException - Indicates problems binding parameter values.
public int bindLimitParametersAtEndOfQuery(RowSelection selection,
PreparedStatement statement,
int index)
throws SQLException
LimitHandler
bindLimitParametersAtEndOfQuery in interface LimitHandlerbindLimitParametersAtEndOfQuery in class AbstractLimitHandlerselection - the selection criteria for rows.statement - Statement to which to bind limit parameter values.index - Index from which to start binding.
SQLException - Indicates problems binding parameter values.protected String fillAliasInSelectClause(StringBuilder sb)
sb - SQL query.
protected void encloseWithOuterQuery(StringBuilder sql)
sql - SQL query.protected void addTopExpression(StringBuilder sql)
TOP expression. Parameter value is bind in
bindLimitParametersAtStartOfQuery(RowSelection, PreparedStatement, int)
method.
sql - SQL query.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||