Class DB2Dialect

    • Method Detail

      • createUniqueDelegate

        protected UniqueDelegate createUniqueDelegate()
      • getMaxVarcharLength

        public int getMaxVarcharLength()
        Description copied from class: Dialect
        The biggest size value that can be supplied as argument to a Types.VARCHAR-like type. For longer column lengths, use some sort of text-like type for the column.
        Overrides:
        getMaxVarcharLength in class Dialect
      • getDefaultDecimalPrecision

        public int getDefaultDecimalPrecision()
        Description copied from class: Dialect
        This is the default precision for a generated column mapped to a BigInteger or BigDecimal.

        Usually returns the maximum precision of the database, except when there is no such maximum precision, or the maximum precision is very high.

        Overrides:
        getDefaultDecimalPrecision in class Dialect
        Returns:
        the default precision, in decimal digits
      • supportsPredicateAsExpression

        protected boolean supportsPredicateAsExpression()
        Description copied from class: Dialect
        Whether a predicate like `a > 0` can appear in an expression context e.g. a select item list.
        Overrides:
        supportsPredicateAsExpression in class Dialect
      • supportsDistinctFromPredicate

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

        This is, does it support syntax like ... where FIRST_NAME IS DISTINCT FROM LAST_NAME?

        Overrides:
        supportsDistinctFromPredicate in class Dialect
        Returns:
        True if this SQL dialect is known to support some kind of distinct from predicate; false otherwise
      • initializeFunctionRegistry

        public void initializeFunctionRegistry​(QueryEngine queryEngine)
        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])
        • 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)
        • 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 Dialect
      • getDropSchemaCommand

        public String[] getDropSchemaCommand​(String schemaName)
        Description copied from class: Dialect
        Get the SQL command used to drop the named schema
        Overrides:
        getDropSchemaCommand in class Dialect
        Parameters:
        schemaName - The name of the schema to be dropped.
        Returns:
        The drop commands
      • getFractionalSecondPrecisionInNanos

        public long getFractionalSecondPrecisionInNanos()
        Since we're using seconds_between() and add_seconds(), it makes sense to use seconds as the "native" precision.
        Overrides:
        getFractionalSecondPrecisionInNanos in class Dialect
        Returns:
        the precision, specified as a quantity of nanoseconds
        See Also:
        TemporalUnit.NATIVE
      • timestampdiffPattern

        public String timestampdiffPattern​(TemporalUnit unit,
                                           jakarta.persistence.TemporalType fromTemporalType,
                                           jakarta.persistence.TemporalType toTemporalType)
        Description copied from class: Dialect
        Obtain a pattern for the SQL equivalent to a timestampdiff() function call. The resulting pattern must contain ?1, ?2, and ?3 placeholders for the arguments.
        Overrides:
        timestampdiffPattern in class Dialect
        Parameters:
        unit - the first argument
        fromTemporalType - true if the first argument is a timestamp, false if a date
        toTemporalType - true if the second argument is
      • timestampdiffPatternV10

        public static String timestampdiffPatternV10​(TemporalUnit unit,
                                                     jakarta.persistence.TemporalType fromTemporalType,
                                                     jakarta.persistence.TemporalType toTemporalType)
      • timestampaddPattern

        public String timestampaddPattern​(TemporalUnit unit,
                                          jakarta.persistence.TemporalType temporalType,
                                          IntervalType intervalType)
        Description copied from class: Dialect
        Obtain a pattern for the SQL equivalent to a timestampadd() function call. The resulting pattern must contain ?1, ?2, and ?3 placeholders for the arguments.
        Overrides:
        timestampaddPattern in class Dialect
        Parameters:
        unit - The unit to add to the temporal
        temporalType - The type of the temporal
        intervalType - The type of interval to add or null if it's not a native interval
      • dropConstraints

        public boolean dropConstraints()
        Description copied from class: Dialect
        Do we need to drop constraints before dropping tables in this dialect?
        Overrides:
        dropConstraints in class Dialect
        Returns:
        True if constraints must be dropped prior to dropping the table; false otherwise.
      • getQuerySequencesString

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

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

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

        public String getForUpdateSkipLockedString()
        Description copied from class: Dialect
        Retrieves the FOR UPDATE SKIP LOCKED syntax specific to this dialect.
        Overrides:
        getForUpdateSkipLockedString in class Dialect
        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 Dialect
        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 WRITE locks for this dialect. Location of the returned string is treated the same as getForUpdateString.
        Overrides:
        getWriteLockString in class Dialect
        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 getForUpdateString.
        Overrides:
        getReadLockString in class Dialect
        Parameters:
        timeout - in milliseconds, -1 for indefinite wait and 0 for no wait.
        Returns:
        The appropriate LOCK clause string.
      • supportsOuterJoinForUpdate

        public boolean supportsOuterJoinForUpdate()
        Description copied from class: Dialect
        Does this dialect support FOR UPDATE in conjunction with outer joined rows?
        Overrides:
        supportsOuterJoinForUpdate in class Dialect
        Returns:
        True if outer joined rows can be locked via FOR UPDATE.
      • supportsExistsInSelect

        public boolean supportsExistsInSelect()
        Description copied from class: Dialect
        Does the dialect support an exists statement in the select clause?
        Overrides:
        supportsExistsInSelect in class Dialect
        Returns:
        True if exists checks are allowed in the select clause; false otherwise.
      • supportsLockTimeouts

        public boolean supportsLockTimeouts()
        Description copied from class: Dialect
        Informational metadata about whether this dialect is known to support specifying timeouts for requested lock acquisitions.
        Overrides:
        supportsLockTimeouts in class Dialect
        Returns:
        True is this dialect supports specifying lock timeouts.
      • requiresCastForConcatenatingNonStrings

        public boolean requiresCastForConcatenatingNonStrings()
        Description copied from class: Dialect
        Does this dialect/database require casting of non-string arguments in a concat function?
        Overrides:
        requiresCastForConcatenatingNonStrings in class Dialect
        Returns:
        true if casting of non-string arguments in concat is required
      • getSelectClauseNullString

        public String getSelectClauseNullString​(int sqlType,
                                                TypeConfiguration typeConfiguration)
        Description copied from class: Dialect
        Given a Types type code, determine an appropriate null value to use in a select clause.

        One thing to consider here is that certain databases might require proper casting for the nulls here since the select here will be part of a UNION/UNION ALL.

        Overrides:
        getSelectClauseNullString in class Dialect
        Parameters:
        sqlType - The Types type code.
        typeConfiguration - The type configuration
        Returns:
        The appropriate select clause value fragment.
      • selectNullString

        public static String selectNullString​(int sqlType)
      • registerResultSetOutParameter

        public int registerResultSetOutParameter​(CallableStatement statement,
                                                 int col)
                                          throws SQLException
        Description copied from class: Dialect
        Registers a parameter (either OUT, or the new REF_CURSOR param type available in Java 8) capable of returning ResultSet *by position*. Pre-Java 8, registering such ResultSet-returning parameters varied greatly across database and drivers; hence its inclusion as part of the Dialect contract.
        Overrides:
        registerResultSetOutParameter in class Dialect
        Parameters:
        statement - The callable statement.
        col - The bind position at which to register the output param.
        Returns:
        The number of (contiguous) bind positions used.
        Throws:
        SQLException - Indicates problems registering the param.
      • supportsCommentOn

        public boolean supportsCommentOn()
        Description copied from class: Dialect
        Does this dialect support commenting on tables and columns?
        Overrides:
        supportsCommentOn in class Dialect
        Returns:
        true if commenting is supported
      • supportsCurrentTimestampSelection

        public boolean supportsCurrentTimestampSelection()
        Description copied from class: Dialect
        Does this dialect support a way to retrieve the database's current timestamp value?
        Overrides:
        supportsCurrentTimestampSelection in class Dialect
        Returns:
        True if the current timestamp can be retrieved; false otherwise.
      • getCurrentTimestampSelectString

        public String getCurrentTimestampSelectString()
        Description copied from class: Dialect
        Retrieve the command used to retrieve the current timestamp from the database.
        Overrides:
        getCurrentTimestampSelectString in class Dialect
        Returns:
        The command.
      • supportsParametersInInsertSelect

        public boolean supportsParametersInInsertSelect()
        Description copied from class: Dialect
        Does this dialect support parameters within the SELECT clause of INSERT ... SELECT ... statements?
        Overrides:
        supportsParametersInInsertSelect in class Dialect
        Returns:
        True if this is supported; false otherwise.
      • doesReadCommittedCauseWritersToBlockReaders

        public boolean doesReadCommittedCauseWritersToBlockReaders()
        Description copied from class: Dialect
        For the underlying database, is READ_COMMITTED isolation implemented by forcing readers to wait for write locks to be released?
        Overrides:
        doesReadCommittedCauseWritersToBlockReaders in class Dialect
        Returns:
        True if writers block readers to achieve READ_COMMITTED; false otherwise.
      • supportsTupleDistinctCounts

        public boolean supportsTupleDistinctCounts()
        Description copied from class: Dialect
        Does this dialect support count(distinct a,b)?
        Overrides:
        supportsTupleDistinctCounts in class Dialect
        Returns:
        True if the database supports counting distinct tuples; false otherwise.
      • contributeTypes

        public void contributeTypes​(TypeContributions typeContributions,
                                    ServiceRegistry serviceRegistry)
        Description copied from class: Dialect
        Allows the Dialect to contribute additional types
        Overrides:
        contributeTypes in class Dialect
        Parameters:
        typeContributions - Callback to contribute the types
        serviceRegistry - The service registry
      • buildSQLExceptionConversionDelegate

        public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate()
        Description copied from class: Dialect
        Build an instance of a SQLExceptionConversionDelegate for interpreting dialect-specific error or SQLState codes.

        If this method is overridden to return a non-null value, the default SQLExceptionConverter will use the returned SQLExceptionConversionDelegate in addition to the following standard delegates:

        1. a "static" delegate based on the JDBC 4 defined SQLException hierarchy;
        2. a delegate that interprets SQLState codes for either X/Open or SQL-2003 codes, depending on java.sql.DatabaseMetaData#getSQLStateType

        It is strongly recommended that specific Dialect implementations override this method, since interpretation of a SQL error is much more accurate when based on the vendor-specific ErrorCode rather than the SQLState.

        Specific Dialects may override to return whatever is most appropriate for that vendor.

        Overrides:
        buildSQLExceptionConversionDelegate in class Dialect
        Returns:
        The SQLExceptionConversionDelegate for this dialect
      • getMaxIdentifierLength

        public int getMaxIdentifierLength()
        Description copied from class: Dialect
        What is the maximum identifier length supported by the dialect?
        Overrides:
        getMaxIdentifierLength in class Dialect
        Returns:
        The maximum length.
      • supportsValuesList

        public boolean supportsValuesList()
        Description copied from class: Dialect
        Does this dialect support values lists of form VALUES (1), (2), (3)?
        Overrides:
        supportsValuesList in class Dialect
        Returns:
        true if values list are supported
      • supportsPartitionBy

        public boolean supportsPartitionBy()
        Description copied from class: Dialect
        Does the underlying database support partition by?
        Overrides:
        supportsPartitionBy in class Dialect
      • supportsNonQueryWithCTE

        public boolean supportsNonQueryWithCTE()
        Description copied from class: Dialect
        Does this dialect support insert, update, and delete statements with Common Table Expressions?
        Overrides:
        supportsNonQueryWithCTE in class Dialect
        Returns:
        true if non-query statements are supported with CTE
      • supportsRecursiveCTE

        public boolean supportsRecursiveCTE()
        Description copied from class: Dialect
        Does this dialect/database support recursive CTEs (Common Table Expressions)?
        Overrides:
        supportsRecursiveCTE in class Dialect
        Returns:
        true if recursive CTEs are supported
      • supportsOffsetInSubquery

        public boolean supportsOffsetInSubquery()
        Description copied from class: Dialect
        Does this dialect support offset in subqueries? For example: select * from Table1 where col1 in (select col1 from Table2 order by col2 limit 1 offset 1)
        Overrides:
        supportsOffsetInSubquery in class Dialect
        Returns:
        true if it does
      • supportsWindowFunctions

        public boolean supportsWindowFunctions()
        Description copied from class: Dialect
        Does this dialect support window functions like row_number() over (..)?
        Overrides:
        supportsWindowFunctions in class Dialect
        Returns:
        true if the underlying database supports window functions, false otherwise. The default is false.
      • supportsLateral

        public boolean supportsLateral()
        Description copied from class: Dialect
        Does this dialect support the SQL lateral keyword or a proprietary alternative?
        Overrides:
        supportsLateral in class Dialect
        Returns:
        true if the underlying database supports lateral, false otherwise. The default is false.
      • appendDatetimeFormat

        public void appendDatetimeFormat​(SqlAppender appender,
                                         String format)
        Description copied from class: Dialect
        Translate the given datetime format string from the pattern language defined by Java's DateTimeFormatter to whatever pattern language is understood by the native datetime formatting function for this database (often the to_char() function).

        Since it's never possible to translate every pattern letter sequences understood by DateTimeFormatter, only the following subset of pattern letters is accepted by Hibernate:

        • G: era
        • y: year of era
        • Y: year of week-based year
        • M: month of year
        • w: week of week-based year (ISO week number)
        • W: week of month
        • E: day of week (name)
        • e: day of week (number)
        • d: day of month
        • D: day of year
        • a: AM/PM
        • H: hour of day (24 hour time)
        • h: hour of AM/PM (12 hour time)
        • m: minutes
        • s: seconds
        • z,Z,x: timezone offset
        In addition, punctuation characters and single-quoted literal strings are accepted.

        Appends a pattern accepted by the function that formats dates and times in this dialect to a SQL fragment that is being constructed.

        Overrides:
        appendDatetimeFormat in class Dialect
      • getInExpressionCountLimit

        public int getInExpressionCountLimit()
        Description copied from class: Dialect
        Return the limit that the underlying database places on the number of elements in an IN predicate. If the database defines no such limits, simply return zero or less-than-zero.
        Overrides:
        getInExpressionCountLimit in class Dialect
        Returns:
        int The limit, or zero-or-less to indicate no limit.
      • generatedAs

        public String generatedAs​(String generatedAs)
        Description copied from class: Dialect
        The generated as clause, or similar, for generated column declarations in DDL statements.
        Overrides:
        generatedAs in class Dialect
        Parameters:
        generatedAs - a SQL expression used to generate the column value
        Returns:
        The generated as clause containing the given expression
      • getDisableConstraintStatement

        public String getDisableConstraintStatement​(String tableName,
                                                    String name)
        Description copied from class: Dialect
        A SQL statement that temporarily disables checking of the given foreign key constraint.
        Overrides:
        getDisableConstraintStatement in class Dialect
        Parameters:
        tableName - the name of the table
        name - the name of the constraint
      • getEnableConstraintStatement

        public String getEnableConstraintStatement​(String tableName,
                                                   String name)
        Description copied from class: Dialect
        A SQL statement that re-enables checking of the given foreign key constraint.
        Overrides:
        getEnableConstraintStatement in class Dialect
        Parameters:
        tableName - the name of the table
        name - the name of the constraint
      • getTruncateTableStatement

        public String getTruncateTableStatement​(String tableName)
        Description copied from class: Dialect
        A SQL statement that truncates the given table.
        Overrides:
        getTruncateTableStatement in class Dialect
        Parameters:
        tableName - the name of the table