Class DB2iDialect

All Implemented Interfaces:
FunctionContributor, TypeContributor, ConversionContext

public class DB2iDialect extends DB2Dialect
A SQL dialect for DB2 for IBM i version 7.1 and above, previously known as "DB2/400".
  • Constructor Details

  • Method Details

    • getMinimumSupportedVersion

      protected DatabaseVersion getMinimumSupportedVersion()
      Description copied from class: Dialect
      Get the version of the SQL dialect that is the minimum supported by this implementation.
      Overrides:
      getMinimumSupportedVersion in class DB2Dialect
    • initializeFunctionRegistry

      public void initializeFunctionRegistry(FunctionContributions functionContributions)
      Description copied from class: Dialect
      Initialize the given registry with any dialect-specific functions.

      Support for certain SQL functions is required, and if the database does not support a required function, then the dialect must define a way to emulate it.

      These required functions include the functions defined by the JPA query language specification:

      • avg(arg) - aggregate function
      • count([distinct ]arg) - aggregate function
      • max(arg) - aggregate function
      • min(arg) - aggregate function
      • sum(arg) - aggregate function
      • coalesce(arg0, arg1, ...)
      • nullif(arg0, arg1)
      • lower(arg)
      • upper(arg)
      • length(arg)
      • concat(arg0, arg1, ...)
      • locate(pattern, string[, start])
      • substring(string, start[, length])
      • trim([[spec ][character ]from] string)
      • abs(arg)
      • mod(arg0, arg1)
      • sqrt(arg)
      • current date
      • current time
      • current timestamp
      Along with an additional set of functions defined by ANSI SQL:
      • any(arg) - aggregate function
      • every(arg) - aggregate function
      • var_samp(arg) - aggregate function
      • var_pop(arg) - aggregate function
      • stddev_samp(arg) - aggregate function
      • stddev_pop(arg) - aggregate function
      • cast(arg as Type)
      • extract(field from arg)
      • ln(arg)
      • exp(arg)
      • power(arg0, arg1)
      • floor(arg)
      • ceiling(arg)
      • position(pattern in string)
      • substring(string from start[ for length])
      • overlay(string placing replacement from start[ for length])
      And the following functions for working with java.time types:
      • local date
      • local time
      • local datetime
      • offset datetime
      • instant
      And a number of additional "standard" functions:
      • left(string, length)
      • right(string, length)
      • replace(string, pattern, replacement)
      • pad(string with length spec[ character])
      • repeat(string, times)
      • pi
      • log10(arg)
      • log(base, arg)
      • sign(arg)
      • sin(arg)
      • cos(arg)
      • tan(arg)
      • asin(arg)
      • acos(arg)
      • atan(arg)
      • atan2(arg0, arg1)
      • round(arg0[, arg1])
      • truncate(arg0[, arg1])
      • sinh(arg)
      • tanh(arg)
      • cosh(arg)
      • least(arg0, arg1, ...)
      • greatest(arg0, arg1, ...)
      • degrees(arg)
      • radians(arg)
      • bitand(arg1, arg1)
      • bitor(arg1, arg1)
      • bitxor(arg1, arg1)
      • format(datetime as pattern)
      • collate(string as collation)
      • str(arg) - synonym of cast(a as String)
      • ifnull(arg0, arg1) - synonym of coalesce(a, b)
      Finally, the following functions are defined as abbreviations for extract(), and desugared by the parser:
      • second(arg) - synonym of extract(second from a)
      • minute(arg) - synonym of extract(minute from a)
      • hour(arg) - synonym of extract(hour from a)
      • day(arg) - synonym of extract(day from a)
      • month(arg) - synonym of extract(month from a)
      • year(arg) - synonym of extract(year from a)
      Note that according to this definition, the second() function returns a floating point value, contrary to the integer type returned by the native function with this name on many databases. Thus, we don't just naively map these HQL functions to the native SQL functions with the same names.
      Overrides:
      initializeFunctionRegistry in class DB2Dialect
    • getDB2Version

      public DatabaseVersion getDB2Version()
      Description copied from class: DB2Dialect
      DB2 LUW Version
      Overrides:
      getDB2Version in class DB2Dialect
    • getCreateIndexString

      public String getCreateIndexString(boolean unique)
      Description copied from class: Dialect
      The command used to create an index, usually create index or create unique index.
      Overrides:
      getCreateIndexString in class Dialect
      Parameters:
      unique - true if the index is a unique index
      Returns:
      The command used to create an index.
    • getCreateIndexTail

      public String getCreateIndexTail(boolean unique, List<Column> columns)
      Description copied from class: Dialect
      A string to be appended to the end of the create index command, usually to specify that null values are to be considered distinct.
      Overrides:
      getCreateIndexTail in class DB2Dialect
    • supportsIfExistsBeforeTableName

      public boolean supportsIfExistsBeforeTableName()
      Description copied from class: Dialect
      For dropping a table, can the phrase if exists be applied before the table name?
      Overrides:
      supportsIfExistsBeforeTableName in class DB2Dialect
      Returns:
      true if if exists can be applied before the table name
    • supportsDistinctFromPredicate

      public boolean supportsDistinctFromPredicate()
      Description copied from class: Dialect
      Does this dialect support some kind of distinct from predicate?

      That is, does it support syntax like:

       ... where FIRST_NAME IS DISTINCT FROM LAST_NAME
       
      Overrides:
      supportsDistinctFromPredicate in class DB2Dialect
      Returns:
      True if this SQL dialect is known to support some kind of distinct from predicate; false otherwise
    • supportsUpdateReturning

      public boolean supportsUpdateReturning()
      Description copied from class: Dialect
      Does this dialect fully support returning arbitrary generated column values after execution of an update statement, using native SQL syntax?

      Defaults to the value of Dialect.supportsInsertReturning() but can be overridden to explicitly disable this for updates.

      Overrides:
      supportsUpdateReturning in class Dialect
      See Also:
    • getSequenceSupport

      public SequenceSupport getSequenceSupport()
      No support for sequences.
      Overrides:
      getSequenceSupport in class DB2Dialect
    • getQuerySequencesString

      public String getQuerySequencesString()
      Description copied from class: Dialect
      Get the select command used retrieve the names of all sequences.
      Overrides:
      getQuerySequencesString in class DB2Dialect
      Returns:
      The select command; or null if sequences are not supported.
    • getLimitHandler

      public LimitHandler getLimitHandler()
      Description copied from class: Dialect
      Obtain a LimitHandler that implements pagination support for Query.setMaxResults(int) and Query.setFirstResult(int).
      Overrides:
      getLimitHandler in class DB2Dialect
    • getIdentityColumnSupport

      public IdentityColumnSupport getIdentityColumnSupport()
      Description copied from class: Dialect
      Get the appropriate IdentityColumnSupport for this dialect.
      Overrides:
      getIdentityColumnSupport in class DB2Dialect
      Returns:
      the IdentityColumnSupport
    • supportsSkipLocked

      public boolean supportsSkipLocked()
      Description copied from class: Dialect
      Does this dialect support SKIP_LOCKED timeout.
      Overrides:
      supportsSkipLocked in class DB2Dialect
      Returns:
      true if SKIP_LOCKED is supported
    • getSqlAstTranslatorFactory

      public SqlAstTranslatorFactory getSqlAstTranslatorFactory()
      Description copied from class: Dialect
      Return a SqlAstTranslatorFactory specific to this dialect, or null to use the standard translator.
      Overrides:
      getSqlAstTranslatorFactory in class DB2Dialect
      See Also:
    • rowId

      public String rowId(String rowId)
      Description copied from class: DB2Dialect
      The more "standard" syntax is rid_bit(alias) but here we use alias.rowid.

      There is also an alternative rid() of type bigint, but it cannot be used with partitioning.

      Overrides:
      rowId in class DB2Dialect
      Parameters:
      rowId - the name specified by RowId.value(), which is ignored if Dialect.getRowIdColumnString(java.lang.String) is not overridden
    • rowIdSqlType

      public int rowIdSqlType()
      Description copied from class: Dialect
      The JDBC type code of the rowid-like pseudo-column which acts as a high-performance row locator.
      Overrides:
      rowIdSqlType in class DB2Dialect
      Returns:
      Types.ROWID by default
    • getRowIdColumnString

      public String getRowIdColumnString(String rowId)
      Description copied from class: Dialect
      If this dialect requires that the rowid column be declared explicitly, return the DDL column definition.
      Overrides:
      getRowIdColumnString in class Dialect
      Returns:
      the DDL column definition, or null if the rowid is an implicit pseudo-column
    • getForUpdateString

      public String getForUpdateString()
      Description copied from class: Dialect
      Get the string to append to SELECT statements to acquire pessimistic UPGRADE locks for this dialect.
      Overrides:
      getForUpdateString in class DB2Dialect
      Returns:
      The appropriate FOR UPDATE clause string.
    • getForUpdateSkipLockedString

      public String getForUpdateSkipLockedString()
      Description copied from class: Dialect
      Retrieves the FOR UPDATE SKIP LOCKED syntax specific to this dialect.
      Overrides:
      getForUpdateSkipLockedString in class DB2Dialect
      Returns:
      The appropriate FOR UPDATE SKIP LOCKED clause string.
    • getForUpdateSkipLockedString

      public String getForUpdateSkipLockedString(String aliases)
      Description copied from class: Dialect
      Get the FOR UPDATE OF column_list SKIP LOCKED fragment appropriate for this dialect, given the aliases of the columns to be write locked.
      Overrides:
      getForUpdateSkipLockedString in class DB2Dialect
      Parameters:
      aliases - The columns to be write locked.
      Returns:
      The appropriate FOR UPDATE colunm_list SKIP LOCKED clause string.
    • getWriteLockString

      public String getWriteLockString(int timeout)
      Description copied from class: Dialect
      Get the string to append to SELECT statements to acquire pessimistic WRITE locks for this dialect.

      Location of the returned string is treated the same as Dialect.getForUpdateString().

      Overrides:
      getWriteLockString in class DB2Dialect
      Parameters:
      timeout - in milliseconds, -1 for indefinite wait and 0 for no wait.
      Returns:
      The appropriate LOCK clause string.
    • getReadLockString

      public String getReadLockString(int timeout)
      Description copied from class: Dialect
      Get the string to append to SELECT statements to acquire READ locks for this dialect.

      Location of the returned string is treated the same as Dialect.getForUpdateString().

      Overrides:
      getReadLockString in class DB2Dialect
      Parameters:
      timeout - in milliseconds, -1 for indefinite wait and 0 for no wait.
      Returns:
      The appropriate LOCK clause string.