public abstract class AbstractLimitHandler extends Object implements LimitHandler
Default implementation of LimitHandler interface.
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractLimitHandler() |
| Modifier and Type | Method and Description |
|---|---|
protected int |
bindLimitParameters(RowSelection selection,
PreparedStatement statement,
int index)
Default implementation of binding parameter values needed by the LIMIT clause.
|
int |
bindLimitParametersAtEndOfQuery(RowSelection selection,
PreparedStatement statement,
int index)
Bind parameter values needed by the LIMIT clause after original SELECT statement.
|
int |
bindLimitParametersAtStartOfQuery(RowSelection selection,
PreparedStatement statement,
int index)
Bind parameter values needed by the LIMIT clause before original SELECT statement.
|
boolean |
bindLimitParametersFirst()
Does the <tt>LIMIT</tt> clause come at the start of the
<tt>SELECT</tt> statement, rather than at the end?
|
boolean |
bindLimitParametersInReverseOrder()
ANSI SQL defines the LIMIT clause to be in the form LIMIT offset, limit.
|
int |
convertToFirstRowValue(int zeroBasedFirstResult)
Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset.
|
boolean |
forceLimitUsage()
Generally, if there is no limit applied to a Hibernate query we do not apply any limits
to the SQL query.
|
protected int |
getMaxOrLimit(RowSelection selection)
Some dialect-specific LIMIT clauses require the maximum last row number
(aka, first_row_number + total_row_count), while others require the maximum
returned row count (the total maximum number of rows to return).
|
String |
processSql(String sql,
RowSelection selection)
Return processed SQL query.
|
void |
setMaxRows(RowSelection selection,
PreparedStatement statement)
Use JDBC API to limit the number of rows returned by the SQL query.
|
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 <tt>LIMIT</tt> clause take a "maximum" row number instead
of a total number of returned rows?
<p/>
This is easiest understood via an example.
|
public boolean supportsLimit()
LimitHandlerDoes this handler support some form of limiting query results via a SQL clause?
supportsLimit in interface LimitHandlerpublic boolean supportsLimitOffset()
LimitHandlerDoes this handler’s LIMIT support (if any) additionally support specifying an offset?
supportsLimitOffset in interface LimitHandlerpublic boolean supportsVariableLimit()
Does this handler support bind variables (i.e., prepared statement parameters) for its limit/offset?
public boolean bindLimitParametersInReverseOrder()
ANSI SQL defines the LIMIT clause to be in the form LIMIT offset, limit. Does this dialect require us to bind the parameters in reverse order?
public boolean bindLimitParametersFirst()
Does the <tt>LIMIT</tt> clause come at the start of the <tt>SELECT</tt> statement, rather than at the end?
public boolean useMaxForLimit()
Does the <tt>LIMIT</tt> clause take a "maximum" row number instead of a total number of returned rows? <p/> 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) <p/> So essentially, is limit relative from offset? Or is limit absolute?
public boolean forceLimitUsage()
Generally, if there is no limit applied to a Hibernate query we do not apply any limits to the SQL query. This option forces that the limit be written to the SQL query.
public int convertToFirstRowValue(int zeroBasedFirstResult)
Hibernate 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.
<p/>
NOTE: what gets passed into processSql(String, org.hibernate.engine.spi.RowSelection)
is the zero-based offset. Dialects which do not supportsVariableLimit() should take care to perform
any needed first-row-conversion calls prior to injecting the limit values into the SQL string.
zeroBasedFirstResult - The user-supplied, zero-based first row offset.Query.setFirstResult(int),
Criteria.setFirstResult(int)public String processSql(String sql, RowSelection selection)
LimitHandlerReturn processed SQL query.
processSql in interface LimitHandlersql - the SQL query to process.selection - the selection criteria for rows.public int bindLimitParametersAtStartOfQuery(RowSelection selection, PreparedStatement statement, int index) throws SQLException
LimitHandlerBind parameter values needed by the LIMIT clause before original SELECT statement.
bindLimitParametersAtStartOfQuery in interface LimitHandlerselection - 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
LimitHandlerBind parameter values needed by the LIMIT clause after original SELECT statement.
bindLimitParametersAtEndOfQuery in interface LimitHandlerselection - 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 void setMaxRows(RowSelection selection, PreparedStatement statement) throws SQLException
LimitHandlerUse JDBC API to limit the number of rows returned by the SQL query. Typically handlers that do not support LIMIT clause should implement this method.
setMaxRows in interface LimitHandlerselection - the selection criteria for rows.statement - Statement which number of returned rows shall be limited.SQLException - Indicates problems while limiting maximum rows returned.protected final int bindLimitParameters(RowSelection selection, PreparedStatement statement, int index) throws SQLException
Default implementation of binding parameter values needed by the LIMIT clause.
selection - 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 final int getMaxOrLimit(RowSelection selection)
Some dialect-specific LIMIT clauses require the maximum last row number (aka, first_row_number + total_row_count), while others require the maximum returned row count (the total maximum number of rows to return).
selection - the selection criteria for rows.Copyright © 2001-2018 Red Hat, Inc. All Rights Reserved.