Class SQLServer2012LimitHandler

    • Constructor Detail

      • SQLServer2012LimitHandler

        public SQLServer2012LimitHandler()
    • Method Detail

      • supportsVariableLimit

        public boolean supportsVariableLimit()
        Description copied from class: AbstractLimitHandler
        Does this handler support bind variables (i.e., prepared statement parameters) for its limit/offset?
        Overrides:
        supportsVariableLimit in class SQLServer2005LimitHandler
        Returns:
        True if bind variables can be used; false otherwise.
      • processSql

        public java.lang.String processSql​(java.lang.String sql,
                                           RowSelection selection)
        Description copied from class: SQLServer2005LimitHandler
        Add a LIMIT clause to the given SQL SELECT (HHH-2655: ROW_NUMBER for Paging) The LIMIT SQL will look like:
         WITH query AS (
           SELECT inner_query.*
                , ROW_NUMBER() OVER (ORDER BY CURRENT_TIMESTAMP) as __row__
             FROM ( original_query_with_top_if_order_by_present_and_all_aliased_columns ) inner_query
         )
         SELECT alias_list FROM query WHERE __row__ >= offset AND __row__ < offset + last
         
        When offset equals 0, only TOP(?) expression is added to the original query.
        Specified by:
        processSql in interface LimitHandler
        Overrides:
        processSql in class SQLServer2005LimitHandler
        Parameters:
        sql - the SQL query to process.
        selection - the selection criteria for rows.
        Returns:
        A new SQL statement with the LIMIT clause applied.
      • useMaxForLimit

        public boolean useMaxForLimit()
        Description copied from class: AbstractLimitHandler
        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?

        Overrides:
        useMaxForLimit in class SQLServer2005LimitHandler
        Returns:
        True if limit is relative from offset; false otherwise.
      • bindLimitParametersAtEndOfQuery

        public int bindLimitParametersAtEndOfQuery​(RowSelection selection,
                                                   java.sql.PreparedStatement statement,
                                                   int index)
                                            throws java.sql.SQLException
        Description copied from interface: LimitHandler
        Bind parameter values needed by the LIMIT clause after original SELECT statement.
        Specified by:
        bindLimitParametersAtEndOfQuery in interface LimitHandler
        Overrides:
        bindLimitParametersAtEndOfQuery in class SQLServer2005LimitHandler
        Parameters:
        selection - the selection criteria for rows.
        statement - Statement to which to bind limit parameter values.
        index - Index from which to start binding.
        Returns:
        The number of parameter values bound.
        Throws:
        java.sql.SQLException - Indicates problems binding parameter values.