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

public Class LegacyLimitHandler

extends AbstractLimitHandler
Class Inheritance
Annotations
@SuppressWarnings:deprecation
Imports
org.hibernate.dialect.Dialect, org.hibernate.engine.spi.RowSelection

Limit handler that delegates all operations to the underlying dialect.
Author
Lukasz Antoniak (lukasz dot antoniak at gmail dot com)

Field Summary

Modifier and TypeField and Description
private final Dialect

Constructor Summary

AccessConstructor and Description
public
LegacyLimitHandler(Dialect
The dialect
dialect
)

Constructs a LegacyLimitHandler

Method Summary

Modifier and TypeMethod and Description
public boolean
bindLimitParametersFirst()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.bindLimitParametersFirst.

Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?
public boolean
bindLimitParametersInReverseOrder()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.bindLimitParametersInReverseOrder.

ANSI SQL defines the LIMIT clause to be in the form LIMIT offset, limit.
public int
convertToFirstRowValue(int
The user-supplied, zero-based first row offset.
zeroBasedFirstResult
)

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.convertToFirstRowValue.

Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset.
public boolean
forceLimitUsage()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.forceLimitUsage.

Generally, if there is no limit applied to a Hibernate query we do not apply any limits to the SQL query.
public String
processSql(String
the SQL query to process.
sql
,
RowSelection
the selection criteria for rows.
selection
)

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.processSql.

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

Return processed SQL query.
public boolean
supportsLimit()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.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()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.supportsLimitOffset.

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

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

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.supportsVariableLimit.

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

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.useMaxForLimit.

Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows?
Inherited from org.hibernate.dialect.pagination.AbstractLimitHandler:
bindLimitParametersbindLimitParametersAtEndOfQuerybindLimitParametersAtStartOfQuerygetMaxOrLimitsetMaxRows

Field Detail

dialectback to summary
private final Dialect dialect

Constructor Detail

LegacyLimitHandlerback to summary
public LegacyLimitHandler(Dialect dialect)

Constructs a LegacyLimitHandler

Parameters
dialect:Dialect

The dialect

Method Detail

bindLimitParametersFirstback to summary
public boolean bindLimitParametersFirst()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.bindLimitParametersFirst.

Doc from org.hibernate.dialect.pagination.AbstractLimitHandler.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

Annotations
@Override
bindLimitParametersInReverseOrderback to summary
public boolean bindLimitParametersInReverseOrder()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.bindLimitParametersInReverseOrder.

Doc from org.hibernate.dialect.pagination.AbstractLimitHandler.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

Annotations
@Override
convertToFirstRowValueback to summary
public int convertToFirstRowValue(int zeroBasedFirstResult)

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.convertToFirstRowValue.

Doc from org.hibernate.dialect.pagination.AbstractLimitHandler.convertToFirstRowValue.

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.

Annotations
@Override
forceLimitUsageback to summary
public boolean forceLimitUsage()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.forceLimitUsage.

Doc from org.hibernate.dialect.pagination.AbstractLimitHandler.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.

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

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.processSql.

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
supportsLimitback to summary
public boolean supportsLimit()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.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()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.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()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.supportsVariableLimit.

Doc from org.hibernate.dialect.pagination.AbstractLimitHandler.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.

Annotations
@Override
useMaxForLimitback to summary
public boolean useMaxForLimit()

Overrides org.hibernate.dialect.pagination.AbstractLimitHandler.useMaxForLimit.

Doc from org.hibernate.dialect.pagination.AbstractLimitHandler.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.

Annotations
@Override