Package com.blazebit.persistence.spi
Interface DbmsLimitHandler
public interface DbmsLimitHandler
Handler for applying SQL LIMIT and OFFSET to a query.
Similar to Hibernates LimitHandler interface.
- Since:
- 1.2.0
- Author:
- Christian Beikov
-
Method Summary
Modifier and TypeMethodDescriptionvoid
applySql
(StringBuilder sqlSb, boolean isSubquery, String limit, String offset) Apply the LIMIT and OFFSET clause on the given SQL.Apply the LIMIT and OFFSET clause on the given SQL as parameters.applySqlInlined
(String sql, boolean isSubquery, Integer limit, Integer offset) LikeapplySql(String, boolean, Integer, Integer)
but inlines the parameter values.int
bindLimitParametersAtEndOfQuery
(Integer limit, Integer offset, PreparedStatement statement, int index) Bind parameter values needed by the LIMIT clause after original SELECT statement.int
bindLimitParametersAtStartOfQuery
(Integer limit, Integer offset, PreparedStatement statement, int index) Bind parameter values needed by the LIMIT clause before original SELECT statement.boolean
Returns whether the parameter value for OFFSET should be added to the value of LIMIT.void
setMaxRows
(Integer limit, Integer offset, PreparedStatement statement) Use JDBC API to limit the number of rows returned by the SQL query.boolean
Returns whether the dbms supports LIMIT via SQL.boolean
Returns whether the dbms supports OFFSET via SQL.
-
Method Details
-
supportsLimit
boolean supportsLimit()Returns whether the dbms supports LIMIT via SQL.- Returns:
- True if LIMIT is supported, otherwise false
-
supportsLimitOffset
boolean supportsLimitOffset()Returns whether the dbms supports OFFSET via SQL.- Returns:
- True if OFFSET is supported, otherwise false
-
limitIncludesOffset
boolean limitIncludesOffset()Returns whether the parameter value for OFFSET should be added to the value of LIMIT.- Returns:
- True if OFFSET should be added to LIMIT, otherwise false
-
applySql
Apply the LIMIT and OFFSET clause on the given SQL as parameters. If parameters are not supported by the DBMS the values should be inlined.- Parameters:
sql
- the sql query on which to applyisSubquery
- whether the query is a subquerylimit
- the limit or nulloffset
- the offset or null- Returns:
- Query statement with LIMIT clause applied.
-
applySqlInlined
LikeapplySql(String, boolean, Integer, Integer)
but inlines the parameter values.- Parameters:
sql
- the sql query on which to applyisSubquery
- whether the query is a subquerylimit
- the limit or nulloffset
- the offset or null- Returns:
- Query statement with LIMIT clause applied.
-
applySql
Apply the LIMIT and OFFSET clause on the given SQL.- Parameters:
sqlSb
- the string builder containing the sql query on which to applyisSubquery
- whether the query is a subquerylimit
- the limit value or nulloffset
- the offset value or null
-
bindLimitParametersAtStartOfQuery
int bindLimitParametersAtStartOfQuery(Integer limit, Integer offset, PreparedStatement statement, int index) throws SQLException Bind parameter values needed by the LIMIT clause before original SELECT statement.- Parameters:
limit
- the limit or nulloffset
- the offset or nullstatement
- the statement to which to apply parametersindex
- the index on which to bind parameters- Returns:
- The number of parameter values bound
- Throws:
SQLException
- Indicates problems binding parameter values
-
bindLimitParametersAtEndOfQuery
int bindLimitParametersAtEndOfQuery(Integer limit, Integer offset, PreparedStatement statement, int index) throws SQLException Bind parameter values needed by the LIMIT clause after original SELECT statement.- Parameters:
limit
- the limit or nulloffset
- the offset or nullstatement
- the statement to which to apply parametersindex
- the index on which to bind parameters- Returns:
- The number of parameter values bound
- Throws:
SQLException
- Indicates problems binding parameter values
-
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:
limit
- the limit or nulloffset
- the offset or nullstatement
- the statement on which to apply max rows- Throws:
SQLException
- Indicates problems while limiting maximum rows returned
-