Top Description 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.CUBRIDLimitHandler, org.hibernate.dialect.pagination.Informix10LimitHandler, org.hibernate.dialect.pagination.LegacyFirstLimitHandler, org.hibernate.dialect.pagination.LegacyLimitHandler, org.hibernate.dialect.pagination.NoopLimitHandler, org.hibernate.dialect.pagination.Oracle12LimitHandler, org.hibernate.dialect.pagination.SQL2008StandardLimitHandler, org.hibernate.dialect.pagination.SQLServer2005LimitHandler, org.hibernate.dialect.pagination.SybaseASE157LimitHandler, org.hibernate.dialect.pagination.TopLimitHandler, org.hibernate.dialect.HSQLDialect.HSQLLimitHandler, org.hibernate.dialect.DerbyDialect.DerbyLimitHandler
Imports
java.sql.PreparedStatement, .SQLException, org.hibernate.engine.spi.RowSelection

Default implementation of LimitHandler interface.
Author
Lukasz Antoniak (lukasz dot antoniak at gmail dot com)

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
protected final int

Returns:

The number of parameter values bound.
bindLimitParameters
(RowSelection
the selection criteria for rows.
selection
,
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
bindLimitParametersAtEndOfQuery(RowSelection
the selection criteria for rows.
selection
,
PreparedStatement
Statement to which to bind limit parameter values.
statement
,
int
Index from which to start binding.
index
)

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

Bind parameter values needed by the LIMIT clause after original SELECT statement.
public int
bindLimitParametersAtStartOfQuery(RowSelection
the selection criteria for rows.
selection
,
PreparedStatement
Statement to which to bind limit parameter values.
statement
,
int
Index from which to start binding.
index
)

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

Bind parameter values needed by the LIMIT clause before original SELECT statement.
public boolean

Returns:

true if limit parameters should come before other parameters
bindLimitParametersFirst
()

Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?

public boolean

Returns:

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

ANSI SQL defines the LIMIT clause to be in the form LIMIT offset, limit.

public int

Returns:

The corresponding db/dialect specific offset.
convertToFirstRowValue
(int
The user-supplied, zero-based first row offset.
zeroBasedFirstResult
)

Hibernate APIs explicitly state that setFirstResult() should be 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 appropriate value to bind into the limit clause.
getMaxOrLimit
(RowSelection
the selection criteria for rows.
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).

public String
processSql(String
the SQL query to process.
sql
,
RowSelection
the selection criteria for rows.
selection
)

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

Return processed SQL query.
public void
setMaxRows(RowSelection
the selection criteria for rows.
selection
,
PreparedStatement
Statement which number of returned rows shall be limited.
statement
)

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

Use JDBC API to limit the number of rows returned by the SQL query.
public boolean
supportsLimit()

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

Does this handler support some form of limiting query results via a SQL clause?
public boolean
supportsLimitOffset()

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

Does this handler's LIMIT support (if any) additionally support specifying an offset?
public boolean

Returns:

True if bind variables can be used; false otherwise.
supportsVariableLimit
()

Does this handler support bind variables (i.e., prepared statement parameters) for its limit/offset?

public boolean

Returns:

True if limit is relative from offset; false otherwise.
useMaxForLimit
()

Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows?

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

AbstractLimitHandlerback to summary
protected AbstractLimitHandler()

Method Detail

bindLimitParametersback to summary
protected final int bindLimitParameters(RowSelection selection, PreparedStatement statement, int index) throws SQLException

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

Parameters
selection:RowSelection

the selection criteria for rows.

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(RowSelection selection, PreparedStatement statement, int index) throws SQLException

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

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

Bind parameter values needed by the LIMIT clause after original SELECT statement.

Parameters
selection:RowSelection

the selection criteria for rows.

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.

Annotations
@Override
Exceptions
SQLException:
Indicates problems binding parameter values.
bindLimitParametersAtStartOfQueryback to summary
public int bindLimitParametersAtStartOfQuery(RowSelection selection, PreparedStatement statement, int index) throws SQLException

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

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

Bind parameter values needed by the LIMIT clause before original SELECT statement.

Parameters
selection:RowSelection

the selection criteria for rows.

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.

Annotations
@Override
Exceptions
SQLException:
Indicates problems binding parameter values.
bindLimitParametersFirstback to summary
public boolean bindLimitParametersFirst()

Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?

Returns:boolean

true if limit parameters should come before other parameters

bindLimitParametersInReverseOrderback to summary
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?

Returns:boolean

true if the correct order is limit, offset

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

Note

what gets passed into AbstractLimitHandler#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.

Parameters
zeroBasedFirstResult:int

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

Returns:int

The corresponding db/dialect specific offset.

See Also
org.hibernate.Query#setFirstResult, org.hibernate.Criteria#setFirstResult
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.

getMaxOrLimitback to summary
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).

Parameters
selection:RowSelection

the selection criteria for rows.

Returns:int

The appropriate value to bind into the limit clause.

processSqlback to summary
public String processSql(String sql, RowSelection selection)

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

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

Return processed SQL query.

Parameters
sql:String

the SQL query to process.

selection:RowSelection

the selection criteria for rows.

Returns:String

Query statement with LIMIT clause applied.

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

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

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

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

Parameters
selection:RowSelection

the selection criteria for rows.

statement:PreparedStatement

Statement which number of returned rows shall be limited.

Annotations
@Override
Exceptions
SQLException:
Indicates problems while limiting maximum rows returned.
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 some form of limiting query results via a SQL clause?

Returns:boolean

True if this handler supports some form of LIMIT.

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's LIMIT support (if any) additionally support specifying an offset?

Returns:boolean

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

Annotations
@Override
supportsVariableLimitback to summary
public boolean supportsVariableLimit()

Does this handler support bind variables (i.e., prepared statement parameters) for its limit/offset?

Returns:boolean

True if bind variables can be used; false otherwise.

useMaxForLimitback to summary
public 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. 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?

Returns:boolean

True if limit is relative from offset; false otherwise.