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 Detail

      • 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

        String applySql​(String sql,
                        boolean isSubquery,
                        Integer limit,
                        Integer offset)
        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 apply
        isSubquery - whether the query is a subquery
        limit - the limit or null
        offset - the offset or null
        Returns:
        Query statement with LIMIT clause applied.
      • applySqlInlined

        String applySqlInlined​(String sql,
                               boolean isSubquery,
                               Integer limit,
                               Integer offset)
        Like applySql(String, boolean, Integer, Integer) but inlines the parameter values.
        Parameters:
        sql - the sql query on which to apply
        isSubquery - whether the query is a subquery
        limit - the limit or null
        offset - the offset or null
        Returns:
        Query statement with LIMIT clause applied.
      • applySql

        void applySql​(StringBuilder sqlSb,
                      boolean isSubquery,
                      String limit,
                      String offset)
        Apply the LIMIT and OFFSET clause on the given SQL.
        Parameters:
        sqlSb - the string builder containing the sql query on which to apply
        isSubquery - whether the query is a subquery
        limit - the limit value or null
        offset - 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 null
        offset - the offset or null
        statement - the statement to which to apply parameters
        index - 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 null
        offset - the offset or null
        statement - the statement to which to apply parameters
        index - the index on which to bind parameters
        Returns:
        The number of parameter values bound
        Throws:
        SQLException - Indicates problems binding parameter values
      • setMaxRows

        void setMaxRows​(Integer limit,
                        Integer offset,
                        PreparedStatement statement)
                 throws SQLException
        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 null
        offset - the offset or null
        statement - the statement on which to apply max rows
        Throws:
        SQLException - Indicates problems while limiting maximum rows returned