Class AbstractSql2008Backend

All Implemented Interfaces:
Backend
Direct Known Subclasses:
Firebird

public abstract class AbstractSql2008Backend extends AbstractSql2003Backend
Common to all SQL2008 backends.

Paging uses the standard OFFSET and FETCH FIRST clauses instead of the window function of AbstractSql2003Backend.

Author:
harald
  • Field Details

  • Constructor Details

    • AbstractSql2008Backend

      public AbstractSql2008Backend()
      Parent constructor.
  • Method Details

    • buildSelectSql

      public void buildSelectSql(StringBuilder sqlBuilder, boolean writeLock, int limit, int offset)
      Creates a select statement string from an inner SQL string.

      sqlBuilder is anything like [SELECT] FROM... WHERE... ORDER BY....
      It is decorated with a leading SELECT, if missing, plus optional LIMIT, OFFSET and FOR UPDATE clauses according to the given parameters.

      Notice that not all backends support a write lock combined with a limit or offset.

      With a limit or offset, the original select is wrapped into an enclosing select that filters by row number. A write lock cannot be combined with a limit or offset, since most databases refuse FOR UPDATE within a nested select.

      The clauses follow the order of the SQL standard: the OFFSET clause precedes the FETCH FIRST clause and the locking clause comes last. The trailing parameters are bound in the same order (see setTrailingSelectParameters(BackendPreparedStatement, int, int, int)).

      Specified by:
      buildSelectSql in interface Backend
      Overrides:
      buildSelectSql in class AbstractSql2003Backend
      Parameters:
      sqlBuilder - the SQL builder, initially containing the inner SQL with or without leading SELECT
      writeLock - true if the select should write-lock
      limit - the limit value, ≤ 0 if no limit clause
      offset - the offset value, ≤ 0 if no offset clause
    • setTrailingSelectParameters

      public int setTrailingSelectParameters(BackendPreparedStatement stmt, int index, int limit, int offset)
      Sets optional parameters after applying the original parameters.

      Because the limit is applied as an upper bound of the row number, it is bound as offset + limit.

      The offset is bound before the limit, which is the number of rows to fetch.

      Specified by:
      setTrailingSelectParameters in interface Backend
      Overrides:
      setTrailingSelectParameters in class AbstractSql2003Backend
      Parameters:
      stmt - the prepared statement
      index - the first parameter index
      limit - the limit value, ≤ 0 if no limit clause
      offset - the offset value, ≤ 0 if no offset clause
      Returns:
      the next parameter index