Class SQLServerDialect

    • Constructor Detail

      • SQLServerDialect

        public SQLServerDialect()
    • Method Detail

      • castType

        protected String castType​(int sqlTypeCode)
        Description copied from class: Dialect
        The SQL type to use in cast( ... as ... ) expressions when casting to the target type represented by the given JDBC type code.
        Overrides:
        castType in class Dialect
        Parameters:
        sqlTypeCode - The JDBC type code representing the target type
        Returns:
        The SQL type to use in cast()
      • resolveSqlTypeDescriptor

        public JdbcType resolveSqlTypeDescriptor​(String columnTypeName,
                                                 int jdbcTypeCode,
                                                 int precision,
                                                 int scale,
                                                 JdbcTypeRegistry jdbcTypeRegistry)
        Description copied from class: Dialect
        Assigns an appropriate JdbcType to a column of a JDBC result set based on the column type name, JDBC type code, precision, and scale.
        Overrides:
        resolveSqlTypeDescriptor in class AbstractTransactSQLDialect
        Parameters:
        columnTypeName - the column type name
        jdbcTypeCode - the type code
        precision - the precision or 0
        scale - the scale or 0
        Returns:
        an appropriate instance of JdbcType
      • 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
      • getMaxNVarcharLength

        public int getMaxNVarcharLength()
        Description copied from class: Dialect
        The biggest size value that can be supplied as argument to a Types.NVARCHAR-like type.

        For longer column lengths, use some sort of ntext-like type for the column.

        Overrides:
        getMaxNVarcharLength in class Dialect
      • getMaxIdentifierLength

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

        public void contributeTypes​(TypeContributions typeContributions,
                                    ServiceRegistry serviceRegistry)
        Description copied from class: Dialect
        A callback which allows the Dialect to contribute types.
        Overrides:
        contributeTypes in class Dialect
        Parameters:
        typeContributions - Callback to contribute the types
        serviceRegistry - The service registry
      • 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])
        • 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 AbstractTransactSQLDialect
      • trimPattern

        public String trimPattern​(TrimSpec specification,
                                  char character)
        Description copied from class: Dialect
        Obtain a pattern for the SQL equivalent to a trim() function call. The resulting pattern must contain a ?1 placeholder for the argument of type String.
        Overrides:
        trimPattern in class AbstractTransactSQLDialect
        Parameters:
        specification - leading or trailing
        character - the character to trim
      • castPattern

        public String castPattern​(CastType from,
                                  CastType to)
        Description copied from class: Dialect
        Obtain a pattern for the SQL equivalent to a cast() function call. The resulting pattern must contain ?1 and ?2 placeholders for the arguments.
        Overrides:
        castPattern in class Dialect
        Parameters:
        from - a CastType indicating the type of the value argument
        to - a CastType indicating the type the value argument is cast to
      • currentTimestamp

        public String currentTimestamp()
        Description copied from class: Dialect
        Translation of the HQL/JPQL current_timestamp function, which maps to the Java type Timestamp which is a datetime with no time zone. This contradicts ANSI SQL where current_timestamp has the type TIMESTAMP WITH TIME ZONE.

        It is recommended to override this in dialects for databases which support localtimestamp or timestamp at local.

        Overrides:
        currentTimestamp in class Dialect
      • currentTime

        public String currentTime()
        Description copied from class: Dialect
        Translation of the HQL/JPQL current_time function, which maps to the Java type Time which is a time with no time zone. This contradicts ANSI SQL where current_time has the type TIME WITH TIME ZONE.

        It is recommended to override this in dialects for databases which support localtime or time at local.

        Overrides:
        currentTime in class Dialect
      • currentDate

        public String currentDate()
        Description copied from class: Dialect
        Translation of the HQL/JPQL current_date function, which maps to the Java type Date, and of the HQL local_date function which maps to the Java type LocalDate.
        Overrides:
        currentDate in class Dialect
      • currentTimestampWithTimeZone

        public String currentTimestampWithTimeZone()
        Description copied from class: Dialect
        Translation of the HQL offset_datetime function, which maps to the Java type OffsetDateTime which is a datetime with a time zone. This in principle correctly maps to the ANSI SQL current_timestamp which has the type TIMESTAMP WITH TIME ZONE.
        Overrides:
        currentTimestampWithTimeZone in class Dialect
      • getNoColumnsInsertString

        public String getNoColumnsInsertString()
        Description copied from class: Dialect
        The fragment used to insert a row without specifying any column values, usually just (), but sometimes default values.
        Overrides:
        getNoColumnsInsertString in class Dialect
        Returns:
        The appropriate empty values clause.
      • 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
      • 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 Dialect
        Returns:
        True if this SQL dialect is known to support some kind of distinct from predicate; false otherwise
      • closeQuote

        public char closeQuote()
        Description copied from class: Dialect
        The character specific to this dialect used to close a quoted identifier.
        Overrides:
        closeQuote in class Dialect
        Returns:
        The dialect-specific close quote character.
      • 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 Dialect
        Returns:
        true if if exists can be applied before the table name
      • supportsIfExistsBeforeConstraintName

        public boolean supportsIfExistsBeforeConstraintName()
        Description copied from class: Dialect
        For dropping a constraint with an alter table statement, can the phrase if exists be applied before the constraint name?
        Overrides:
        supportsIfExistsBeforeConstraintName in class Dialect
        Returns:
        true if if exists can be applied before the constraint name
      • openQuote

        public char openQuote()
        Description copied from class: Dialect
        The character specific to this dialect used to begin a quoted identifier.
        Overrides:
        openQuote in class Dialect
        Returns:
        The dialect-specific open quote character.
      • appendLockHint

        public String appendLockHint​(LockOptions lockOptions,
                                     String tableName)
        Description copied from class: Dialect
        Some dialects support an alternative means to SELECT FOR UPDATE, whereby a "lock hint" is appended to the table name in the from clause.
        Overrides:
        appendLockHint in class AbstractTransactSQLDialect
        Parameters:
        lockOptions - The lock options to apply
        tableName - The name of the table to which to apply the lock hint.
        Returns:
        The table with any required lock hints.
      • getCurrentTimestampSelectString

        public String getCurrentTimestampSelectString()
        The current_timestamp is more accurate, but only known to be supported in SQL Server 7.0 and later and Sybase not known to support it at all

        The command used to retrieve the current timestamp from the database.

        Overrides:
        getCurrentTimestampSelectString in class AbstractTransactSQLDialect
      • supportsCircularCascadeDeleteConstraints

        public boolean supportsCircularCascadeDeleteConstraints()
        Description copied from class: Dialect
        Does this dialect support definition of cascade delete constraints which can cause circular chains?
        Overrides:
        supportsCircularCascadeDeleteConstraints in class Dialect
        Returns:
        True if circular cascade delete constraints are 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 AbstractTransactSQLDialect
        Returns:
        True if writers block readers to achieve READ_COMMITTED; false otherwise.
      • doesRepeatableReadCauseReadersToBlockWriters

        public boolean doesRepeatableReadCauseReadersToBlockWriters()
        Description copied from class: Dialect
        For the underlying database, is REPEATABLE_READ isolation implemented by forcing writers to wait for read locks to be released?
        Overrides:
        doesRepeatableReadCauseReadersToBlockWriters in class AbstractTransactSQLDialect
        Returns:
        True if readers block writers to achieve REPEATABLE_READ; false otherwise.
      • 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 a number smaller than zero.
        Overrides:
        getInExpressionCountLimit in class Dialect
        Returns:
        The limit, or a non-positive integer to indicate no limit.
      • supportsNonQueryWithCTE

        public boolean supportsNonQueryWithCTE()
        Description copied from class: Dialect
        Does this dialect support insert, update, and delete statements with Common Table Expressions (CTEs)?
        Overrides:
        supportsNonQueryWithCTE in class Dialect
        Returns:
        true if non-query statements are supported with CTE
      • 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
      • supportsNoWait

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

        public boolean supportsWait()
        Description copied from class: Dialect
        Does this dialect support WAIT timeout.
        Overrides:
        supportsWait in class Dialect
        Returns:
        true if WAIT is supported
      • 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.
      • getQueryHintString

        public String getQueryHintString​(String sql,
                                         String hints)
        Description copied from class: Dialect
        Apply a hint to the given SQL query.

        The entire query is provided, allowing full control over the placement and syntax of the hint.

        By default, ignore the hint and simply return the query.

        Overrides:
        getQueryHintString in class Dialect
        Parameters:
        sql - The query to which to apply the hint.
        hints - The hints to apply
        Returns:
        The modified SQL
      • supportsNullPrecedence

        public boolean supportsNullPrecedence()
        Description copied from class: Dialect
        Does this dialect support nulls first and nulls last?
        Overrides:
        supportsNullPrecedence in class Dialect
      • 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.
      • supportsRecursiveCTE

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

        public boolean supportsFetchClause​(FetchClauseType type)
        Description copied from class: Dialect
        Does this dialect support the given FETCH clause type.
        Overrides:
        supportsFetchClause in class Dialect
        Parameters:
        type - The fetch clause type
        Returns:
        true if the underlying database supports the given fetch clause type, false otherwise. The default is false.
      • getDefaultTimestampPrecision

        public int getDefaultTimestampPrecision()
        SQL server supports up to 7 decimal digits of fractional second precision in a datetime2, but since its duration arithmetic functions try to fit durations into an int, which is impossible with such high precision, so default to generating datetime2(3) columns.
        Overrides:
        getDefaultTimestampPrecision in class Dialect
        Returns:
        the default precision, in decimal digits, of the fractional seconds field
      • getFractionalSecondPrecisionInNanos

        public long getFractionalSecondPrecisionInNanos()
        SQL server supports up to 7 decimal digits of fractional second precision in datetime2, but unfortunately its duration arithmetic functions have a nasty habit of overflowing. So to give ourselves a little extra headroom, we will use microsecond as the native unit of precision (but even then we have to use tricks when calling dateadd()).
        Overrides:
        getFractionalSecondPrecisionInNanos in class Dialect
        Returns:
        the precision, specified as a quantity of nanoseconds
        See Also:
        TemporalUnit.NATIVE
      • timestampaddPattern

        public String timestampaddPattern​(TemporalUnit unit,
                                          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
      • timestampdiffPattern

        public String timestampdiffPattern​(TemporalUnit unit,
                                           TemporalType fromTemporalType,
                                           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
      • 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
      • datetimeFormat

        public static Replacer datetimeFormat​(String format)
      • appendUUIDLiteral

        public void appendUUIDLiteral​(SqlAppender appender,
                                      UUID literal)
        Description copied from class: Dialect
        Append a literal SQL uuid representing the given Java UUID.

        This is usually a cast() expression, but it might be a function call.

        Overrides:
        appendUUIDLiteral in class Dialect
      • getCreateTemporaryTableColumnAnnotation

        public String getCreateTemporaryTableColumnAnnotation​(int sqlTypeCode)
        Description copied from class: Dialect
        Annotation to be appended to the end of each COLUMN clause for temporary tables.
        Overrides:
        getCreateTemporaryTableColumnAnnotation in class Dialect
        Parameters:
        sqlTypeCode - The SQL type code
        Returns:
        The annotation to be appended, for example, COLLATE DATABASE_DEFAULT in SQL Server
      • 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
      • 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 Dialect
      • getAlterColumnTypeString

        public String getAlterColumnTypeString​(String columnName,
                                               String columnType,
                                               String columnDefinition)
        Description copied from class: Dialect
        The fragment of an alter table command which modifies a column type, or null if column types cannot be modified. Often alter column col_name set data type col_type.
        Overrides:
        getAlterColumnTypeString in class Dialect
        Parameters:
        columnName - the name of the column
        columnType - the new type of the column
        columnDefinition - the full column definition
        Returns:
        a fragment to be appended to alter table
      • supportsAlterColumnType

        public boolean supportsAlterColumnType()
        Description copied from class: Dialect
        Does this dialect support modifying the type of an existing column?
        Overrides:
        supportsAlterColumnType in class Dialect
      • 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
      • hasDataTypeBeforeGeneratedAs

        public boolean hasDataTypeBeforeGeneratedAs()
        Description copied from class: Dialect
        Is an explicit column type required for generated as columns?
        Overrides:
        hasDataTypeBeforeGeneratedAs in class Dialect
        Returns:
        true if an explicit type is required