Package org.hibernate.dialect.pagination
Class LegacyLimitHandler
- java.lang.Object
-
- org.hibernate.dialect.pagination.AbstractLimitHandler
-
- org.hibernate.dialect.pagination.LegacyLimitHandler
-
- All Implemented Interfaces:
LimitHandler
public class LegacyLimitHandler extends AbstractLimitHandler
Limit handler that delegates all operations to the underlying dialect.
-
-
Constructor Summary
Constructors Constructor Description LegacyLimitHandler(Dialect dialect)Constructs a LegacyLimitHandler
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanbindLimitParametersFirst()Does the LIMIT clause come at the start of the SELECT statement, rather than at the end?booleanbindLimitParametersInReverseOrder()ANSI SQL defines the LIMIT clause to be in the form LIMIT offset, limit.intconvertToFirstRowValue(int zeroBasedFirstResult)Hibernate APIs explicitly state that setFirstResult() should be a zero-based offset.booleanforceLimitUsage()Generally, if there is no limit applied to a Hibernate query we do not apply any limits to the SQL query.java.lang.StringprocessSql(java.lang.String sql, RowSelection selection)Return processed SQL query.booleansupportsLimit()Does this handler support some form of limiting query results via a SQL clause?booleansupportsLimitOffset()Does this handler's LIMIT support (if any) additionally support specifying an offset?booleansupportsVariableLimit()Does this handler support bind variables (i.e., prepared statement parameters) for its limit/offset?booleanuseMaxForLimit()Does the LIMIT clause take a "maximum" row number instead of a total number of returned rows?-
Methods inherited from class org.hibernate.dialect.pagination.AbstractLimitHandler
bindLimitParameters, bindLimitParametersAtEndOfQuery, bindLimitParametersAtStartOfQuery, getMaxOrLimit, setMaxRows
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.hibernate.dialect.pagination.LimitHandler
processSql
-
-
-
-
Constructor Detail
-
LegacyLimitHandler
public LegacyLimitHandler(Dialect dialect)
Constructs a LegacyLimitHandler- Parameters:
dialect- The dialect
-
-
Method Detail
-
supportsLimit
public boolean supportsLimit()
Description copied from interface:LimitHandlerDoes this handler support some form of limiting query results via a SQL clause?- Specified by:
supportsLimitin interfaceLimitHandler- Overrides:
supportsLimitin classAbstractLimitHandler- Returns:
- True if this handler supports some form of LIMIT.
-
supportsLimitOffset
public boolean supportsLimitOffset()
Description copied from interface:LimitHandlerDoes this handler's LIMIT support (if any) additionally support specifying an offset?- Specified by:
supportsLimitOffsetin interfaceLimitHandler- Overrides:
supportsLimitOffsetin classAbstractLimitHandler- Returns:
- True if the handler supports an offset within the limit support.
-
supportsVariableLimit
public boolean supportsVariableLimit()
Description copied from class:AbstractLimitHandlerDoes this handler support bind variables (i.e., prepared statement parameters) for its limit/offset?- Overrides:
supportsVariableLimitin classAbstractLimitHandler- Returns:
- True if bind variables can be used; false otherwise.
-
bindLimitParametersInReverseOrder
public boolean bindLimitParametersInReverseOrder()
Description copied from class:AbstractLimitHandlerANSI 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?- Overrides:
bindLimitParametersInReverseOrderin classAbstractLimitHandler- Returns:
- true if the correct order is limit, offset
-
bindLimitParametersFirst
public boolean bindLimitParametersFirst()
Description copied from class:AbstractLimitHandlerDoes the LIMIT clause come at the start of the SELECT statement, rather than at the end?- Overrides:
bindLimitParametersFirstin classAbstractLimitHandler- Returns:
- true if limit parameters should come before other parameters
-
useMaxForLimit
public boolean useMaxForLimit()
Description copied from class:AbstractLimitHandlerDoes 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?- Overrides:
useMaxForLimitin classAbstractLimitHandler- Returns:
- True if limit is relative from offset; false otherwise.
-
forceLimitUsage
public boolean forceLimitUsage()
Description copied from class:AbstractLimitHandlerGenerally, 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.- Overrides:
forceLimitUsagein classAbstractLimitHandler- Returns:
- True to force limit into SQL query even if none specified in Hibernate query; false otherwise.
-
convertToFirstRowValue
public int convertToFirstRowValue(int zeroBasedFirstResult)
Description copied from class:AbstractLimitHandlerHibernate 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 intoAbstractLimitHandler.processSql(String, org.hibernate.engine.spi.RowSelection)is the zero-based offset. Dialects which do notAbstractLimitHandler.supportsVariableLimit()should take care to perform any needed first-row-conversion calls prior to injecting the limit values into the SQL string.- Overrides:
convertToFirstRowValuein classAbstractLimitHandler- Parameters:
zeroBasedFirstResult- The user-supplied, zero-based first row offset.- Returns:
- The corresponding db/dialect specific offset.
- See Also:
Query.setFirstResult(int),Criteria.setFirstResult(int)
-
processSql
public java.lang.String processSql(java.lang.String sql, RowSelection selection)Description copied from interface:LimitHandlerReturn processed SQL query.- Specified by:
processSqlin interfaceLimitHandler- Overrides:
processSqlin classAbstractLimitHandler- Parameters:
sql- the SQL query to process.selection- the selection criteria for rows.- Returns:
- Query statement with LIMIT clause applied.
-
-