Top Description Fields Constructors Methods
org.hibernate.dialect.pagination

public abstract Class AbstractLimitHandler

extends Object
implements LimitHandler
Class Inheritance
All Implemented Interfaces
org.hibernate.dialect.pagination.LimitHandler
Known Direct Subclasses
org.hibernate.dialect.pagination.AbstractNoOffsetLimitHandler, org.hibernate.dialect.pagination.AbstractSimpleLimitHandler, org.hibernate.dialect.pagination.LegacyDB2LimitHandler, org.hibernate.dialect.pagination.LegacyOracleLimitHandler, org.hibernate.dialect.pagination.NoopLimitHandler, org.hibernate.dialect.pagination.OffsetFetchLimitHandler, org.hibernate.dialect.pagination.Oracle12LimitHandler, org.hibernate.dialect.pagination.SQLServer2005LimitHandler
Imports
java.sql.PreparedStatement, .SQLException, java.util.regex.Matcher, .Pattern, org.hibernate.query.Query, org.hibernate.query.spi.Limit

Default implementation of LimitHandler interface.
Author
Lukasz Antoniak

Field Summary

Modifier and TypeField and Description
private static final Pattern
private static final Pattern
public static LimitHandler
private static final Pattern
private static final Pattern

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected final int

Returns:

The number of parameter values bound.
bindLimitParameters
(Limit
the limit.
limit
,
PreparedStatement
Statement to which to bind limit parameter values.
statement
,
int
Index from which to start binding.
index
)

Default implementation of binding parameter values needed by the LIMIT clause.

public int
public int
public boolean

Returns:

true if limit parameters come before other parameters
bindLimitParametersFirst
()

Does the offset/limit clause come at the start of the SELECT statement, or at the end of the query?

public boolean

Returns:

true if the correct order is limit then offset
bindLimitParametersInReverseOrder
()

Usually, the offset comes before the limit, but occasionally the offset is specified after the limit.

public int

Returns:

The resulting offset, adjusted to one-based if necessary.
convertToFirstRowValue
(int
The user-supplied, zero-based first row offset.
zeroBasedFirstResult
)

The API method Query#setFirstResult(int) accepts a zero-based offset.

public boolean

Returns:

true to force limit into SQL query even if none specified in Hibernate query; false otherwise.
forceLimitUsage
()

Generally, if there is no limit applied to a Hibernate query we do not apply any limits to the SQL query.

protected final int

Returns:

The first row
getFirstRow
(Limit
The limit
limit
)

Retrieve the indicated first row for pagination

protected Pattern
getForUpdatePattern()

The offset/limit clauses typically must come before the FOR UPDATEish clauses, so we need a way to identify these clauses in the text of the whole query.

protected final int

Returns:

The appropriate value to bind into the limit clause.
getMaxOrLimit
(Limit
The limit
limit
)

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).

public static boolean

Returns:

Whether a first row limit was indicated
hasFirstRow
(Limit
The limit
limit
)

Is a first row limit indicated?

public static boolean

Returns:

Whether a max row limit was indicated
hasMaxRows
(Limit
The limit
limit
)

Is a max row limit indicated?

protected static String
insertAfterDistinct(String limitOffsetClause, String sqlStatement)

Insert a fragment of SQL right after SELECT, SELECT DISTINCT, or SELECT ALL.

protected static String
insertAfterSelect(String limitOffsetClause, String sqlStatement)

Insert a fragment of SQL right after SELECT, but before DISTINCT or ALL.

protected String
insertAtEnd(String limitOffsetClause, String sqlStatement)

Insert a fragment of SQL right at the very end of the query.

protected String
insertBeforeForUpdate(String limitOffsetClause, String sqlStatement)

Insert a fragment of SQL right before the FOR UPDATEish clauses at the end of the query.

public String
public void
public boolean
supportsLimit()

Implements org.hibernate.dialect.pagination.LimitHandler.supportsLimit.

Does this handler support limiting query results?
public boolean
supportsLimitOffset()

Implements org.hibernate.dialect.pagination.LimitHandler.supportsLimitOffset.

Does this handler support combinations of limit and offset?
public boolean
supportsOffset()

Implements org.hibernate.dialect.pagination.LimitHandler.supportsOffset.

Does this handler support offsetting query results without also specifying a limit?
public boolean

Returns:

true if bind variables can be used
supportsVariableLimit
()

Does this handler support bind variables (JDBC prepared statement parameters) for its limit/offset?

public boolean

Returns:

true if the limit clause expects the number of the last row, false if it expects the page size
useMaxForLimit
()

Does the limit clause expect the number of the last row, or the "page size", the maximum number of rows we want to receive?

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

END_PATTERNback to summary
private static final Pattern END_PATTERN
FOR_UPDATE_PATTERNback to summary
private static final Pattern FOR_UPDATE_PATTERN
NO_LIMITback to summary
public static LimitHandler NO_LIMIT
SELECT_DISTINCT_PATTERNback to summary
private static final Pattern SELECT_DISTINCT_PATTERN
SELECT_PATTERNback to summary
private static final Pattern SELECT_PATTERN

Constructor Detail

AbstractLimitHandlerback to summary
public AbstractLimitHandler()

Method Detail

bindLimitParametersback to summary
protected final int bindLimitParameters(Limit limit, PreparedStatement statement, int index) throws SQLException

Default implementation of binding parameter values needed by the LIMIT clause.

Parameters
limit:Limit

the limit.

statement:PreparedStatement

Statement to which to bind limit parameter values.

index:int

Index from which to start binding.

Returns:int

The number of parameter values bound.

Exceptions
SQLException:
Indicates problems binding parameter values.
bindLimitParametersAtEndOfQueryback to summary
public int bindLimitParametersAtEndOfQuery(Limit limit, PreparedStatement statement, int index) throws SQLException

Implements org.hibernate.dialect.pagination.LimitHandler.bindLimitParametersAtEndOfQuery.

Annotations
@Override
bindLimitParametersAtStartOfQueryback to summary
public int bindLimitParametersAtStartOfQuery(Limit limit, PreparedStatement statement, int index) throws SQLException

Implements org.hibernate.dialect.pagination.LimitHandler.bindLimitParametersAtStartOfQuery.

Annotations
@Override
bindLimitParametersFirstback to summary
public boolean bindLimitParametersFirst()

Does the offset/limit clause come at the start of the SELECT statement, or at the end of the query?

Returns:boolean

true if limit parameters come before other parameters

bindLimitParametersInReverseOrderback to summary
public boolean bindLimitParametersInReverseOrder()

Usually, the offset comes before the limit, but occasionally the offset is specified after the limit. Does this dialect require us to bind the parameters in reverse order?

Returns:boolean

true if the correct order is limit then offset

convertToFirstRowValueback to summary
public int convertToFirstRowValue(int zeroBasedFirstResult)

The API method Query#setFirstResult(int) accepts a zero-based offset. Does this dialect require a one-based offset to be specified in the offset clause?

Implementation Note

The value passed into AbstractLimitHandler#processSql(String, Limit) has a zero-based offset. Handlers 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.

Parameters
zeroBasedFirstResult:int

The user-supplied, zero-based first row offset.

Returns:int

The resulting offset, adjusted to one-based if necessary.

forceLimitUsageback to summary
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.

Returns:boolean

true to force limit into SQL query even if none specified in Hibernate query; false otherwise.

getFirstRowback to summary
protected final int getFirstRow(Limit limit)

Retrieve the indicated first row for pagination

Parameters
limit:Limit

The limit

Returns:int

The first row

getForUpdatePatternback to summary
protected Pattern getForUpdatePattern()

The offset/limit clauses typically must come before the FOR UPDATEish clauses, so we need a way to identify these clauses in the text of the whole query.

getMaxOrLimitback to summary
protected final int getMaxOrLimit(Limit limit)

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).

Parameters
limit:Limit

The limit

Returns:int

The appropriate value to bind into the limit clause.

hasFirstRowback to summary
public static boolean hasFirstRow(Limit limit)

Is a first row limit indicated?

Parameters
limit:Limit

The limit

Returns:boolean

Whether a first row limit was indicated

hasMaxRowsback to summary
public static boolean hasMaxRows(Limit limit)

Is a max row limit indicated?

Parameters
limit:Limit

The limit

Returns:boolean

Whether a max row limit was indicated

insertAfterDistinctback to summary
protected static String insertAfterDistinct(String limitOffsetClause, String sqlStatement)

Insert a fragment of SQL right after SELECT, SELECT DISTINCT, or SELECT ALL.

insertAfterSelectback to summary
protected static String insertAfterSelect(String limitOffsetClause, String sqlStatement)

Insert a fragment of SQL right after SELECT, but before DISTINCT or ALL.

insertAtEndback to summary
protected String insertAtEnd(String limitOffsetClause, String sqlStatement)

Insert a fragment of SQL right at the very end of the query.

insertBeforeForUpdateback to summary
protected String insertBeforeForUpdate(String limitOffsetClause, String sqlStatement)

Insert a fragment of SQL right before the FOR UPDATEish clauses at the end of the query.

processSqlback to summary
public String processSql(String sql, Limit limit)

Implements org.hibernate.dialect.pagination.LimitHandler.processSql.

Annotations
@Override
setMaxRowsback to summary
public void setMaxRows(Limit limit, PreparedStatement statement) throws SQLException

Implements org.hibernate.dialect.pagination.LimitHandler.setMaxRows.

Annotations
@Override
supportsLimitback to summary
public boolean supportsLimit()

Implements org.hibernate.dialect.pagination.LimitHandler.supportsLimit.

Doc from org.hibernate.dialect.pagination.LimitHandler.supportsLimit.

Does this handler support limiting query results?

Returns:boolean

True if this handler supports limit alone.

Annotations
@Override
supportsLimitOffsetback to summary
public boolean supportsLimitOffset()

Implements org.hibernate.dialect.pagination.LimitHandler.supportsLimitOffset.

Doc from org.hibernate.dialect.pagination.LimitHandler.supportsLimitOffset.

Does this handler support combinations of limit and offset?

Returns:boolean

True if the handler supports an offset within the limit support.

Annotations
@Override
supportsOffsetback to summary
public boolean supportsOffset()

Implements org.hibernate.dialect.pagination.LimitHandler.supportsOffset.

Doc from org.hibernate.dialect.pagination.LimitHandler.supportsOffset.

Does this handler support offsetting query results without also specifying a limit?

Returns:boolean

True if this handler supports offset alone.

supportsVariableLimitback to summary
public boolean supportsVariableLimit()

Does this handler support bind variables (JDBC prepared statement parameters) for its limit/offset?

Returns:boolean

true if bind variables can be used

useMaxForLimitback to summary
public boolean useMaxForLimit()

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's Query#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 than Query#setFirstResult(int).

Returns:boolean

true if the limit clause expects the number of the last row, false if it expects the page size