Class AbstractTransactSQLDialect

java.lang.Object
org.hibernate.dialect.Dialect
org.hibernate.dialect.AbstractTransactSQLDialect
All Implemented Interfaces:
FunctionContributor, TypeContributor, ConversionContext
Direct Known Subclasses:
SQLServerDialect, SybaseDialect

public abstract class AbstractTransactSQLDialect extends Dialect
An abstract base class for Sybase and MS SQL Server dialects.
  • Constructor Details

    • AbstractTransactSQLDialect

      public AbstractTransactSQLDialect(DatabaseVersion version)
    • AbstractTransactSQLDialect

      public AbstractTransactSQLDialect(DialectResolutionInfo info)
  • Method Details

    • columnType

      protected String columnType(int sqlTypeCode)
      Description copied from class: Dialect
      The database column type name for a given JDBC type code defined in Types or SqlTypes. This default implementation returns the ANSI-standard type name.

      This method may be overridden by concrete Dialects as an alternative to Dialect.registerColumnTypes(TypeContributions, ServiceRegistry) for simple registrations.

      Note that:

      1. Implementations of this method are expected to define a sensible mapping forTypes.NCLOB Types.NCHAR, and Types.NVARCHAR. On some database, these types are simply remapped to CLOB, CHAR, and VARCHAR.
      2. Mappings for Types.TIMESTAMP and Types.TIMESTAMP_WITH_TIMEZONE should support explicit specification of precision if possible.
      3. As specified by DdlTypeRegistry.getDescriptor(int), this method never receives Types.LONGVARCHAR, Types.LONGNVARCHAR, nor Types.LONGVARBINARY, which are considered synonyms for their non-LONG counterparts.
      4. On the other hand, the types SqlTypes.LONG32VARCHAR, SqlTypes.LONG32NVARCHAR, and SqlTypes.LONG32VARBINARY are not synonyms, and implementations of this method must define sensible mappings, for example to database-native TEXT or CLOB types.
      Overrides:
      columnType in class Dialect
      Parameters:
      sqlTypeCode - a SQL type code
      Returns:
      a column type name, with $l, $p, $s placeholders for length, precision, scale
      See Also:
    • getDefaultStatementBatchSize

      public int getDefaultStatementBatchSize()
      Description copied from class: Dialect
      The default value to use for the configuration property "hibernate.jdbc.batch_size".
      Overrides:
      getDefaultStatementBatchSize in class Dialect
    • 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 Dialect
      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
    • getPreferredSqlTypeCodeForBoolean

      public int getPreferredSqlTypeCodeForBoolean()
      Description copied from class: Dialect
      The JDBC type code to use for mapping properties of Java type boolean.

      Usually Types.BOOLEAN or Types.BIT.

      Overrides:
      getPreferredSqlTypeCodeForBoolean in class Dialect
      Returns:
      one of the type codes defined by Types.
    • 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 Dialect
    • trimPattern

      public String trimPattern(TrimSpec specification, boolean isWhitespace)
      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 and a ?2 placeholder for the trim character if isWhitespace was false.
      Overrides:
      trimPattern in class Dialect
      Parameters:
      specification - leading, trailing or both
      isWhitespace - true if the trim character is a whitespace and can be omitted, false if it must be explicit and a ?2 placeholder should be included in the pattern
    • replaceLtrimRtrim

      @Deprecated(forRemoval=true) public static String replaceLtrimRtrim(TrimSpec specification, char character)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • replaceLtrimRtrim

      public static String replaceLtrimRtrim(TrimSpec specification, boolean isWhitespace)
    • getAddColumnString

      public String getAddColumnString()
      Description copied from class: Dialect
      The subcommand of the alter table command used to add a column to a table, usually add column or add.
      Overrides:
      getAddColumnString in class Dialect
      Returns:
      The add column fragment.
    • qualifyIndexName

      public boolean qualifyIndexName()
      Description copied from class: Dialect
      Do we need to qualify index names with the schema name?
      Overrides:
      qualifyIndexName in class Dialect
      Returns:
      true if we do
    • 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 Dialect
      Returns:
      The appropriate FOR UPDATE clause string.
    • getWriteRowLockStrategy

      public RowLockStrategy getWriteRowLockStrategy()
      Description copied from class: Dialect
      The row lock strategy to use for write locks.
      Overrides:
      getWriteRowLockStrategy in class Dialect
    • 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 Dialect
      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.
    • applyLocksToSql

      public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map<String,String[]> keyColumnNames)
      Description copied from class: Dialect
      Modifies the given SQL, applying the appropriate updates for the specified lock modes and key columns.

      This allows emulation of SELECT FOR UPDATE for dialects which do not support the standard syntax.

      Overrides:
      applyLocksToSql in class Dialect
      Parameters:
      sql - the SQL string to modify
      aliasedLockOptions - lock options indexed by aliased table names.
      keyColumnNames - a map of key columns indexed by aliased table names.
      Returns:
      the modified SQL string.
    • registerResultSetOutParameter

      public int registerResultSetOutParameter(CallableStatement statement, int col) throws SQLException
      Description copied from class: Dialect
      Registers a parameter capable of returning a ResultSet by position, either an OUT parameter, or a REF_CURSOR parameter as defined in Java 8.
      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.
    • getResultSet

      public ResultSet getResultSet(CallableStatement ps) throws SQLException
      Description copied from class: Dialect
      Given a callable statement previously processed by Dialect.registerResultSetOutParameter(java.sql.CallableStatement, int), extract the ResultSet from the OUT parameter.
      Overrides:
      getResultSet in class Dialect
      Parameters:
      ps - The callable statement.
      Returns:
      The extracted result set.
      Throws:
      SQLException - Indicates problems extracting the result set.
    • supportsCurrentTimestampSelection

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

      public boolean isCurrentTimestampSelectStringCallable()
      Description copied from class: Dialect
      Is the command returned by Dialect.getCurrentTimestampSelectString() treated as callable?

      Typically, this indicates the use of the JDBC escape syntax.

      Overrides:
      isCurrentTimestampSelectStringCallable in class Dialect
      Returns:
      if the Dialect.getCurrentTimestampSelectString() is treated as callable; false otherwise.
    • getCurrentTimestampSelectString

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

      public NullOrdering getNullOrdering()
      Description copied from class: Dialect
      Returns the default ordering of null.
      Overrides:
      getNullOrdering in class Dialect
    • requiresCastForConcatenatingNonStrings

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

      public SqmMultiTableMutationStrategy getFallbackSqmMutationStrategy(EntityMappingType entityDescriptor, RuntimeModelCreationContext runtimeModelCreationContext)
      Description copied from class: Dialect
      Overrides:
      getFallbackSqmMutationStrategy in class Dialect
      See Also:
    • getFallbackSqmInsertStrategy

      public SqmMultiTableInsertStrategy getFallbackSqmInsertStrategy(EntityMappingType entityDescriptor, RuntimeModelCreationContext runtimeModelCreationContext)
      Description copied from class: Dialect
      Overrides:
      getFallbackSqmInsertStrategy in class Dialect
      See Also:
    • getSupportedTemporaryTableKind

      public TemporaryTableKind getSupportedTemporaryTableKind()
      Description copied from class: Dialect
      The kind of temporary tables that are supported on this database.
      Overrides:
      getSupportedTemporaryTableKind in class Dialect
    • getTemporaryTableCreateCommand

      public String getTemporaryTableCreateCommand()
      Description copied from class: Dialect
      The command to create a temporary table.
      Overrides:
      getTemporaryTableCreateCommand in class Dialect
    • getTemporaryTableAfterUseAction

      public AfterUseAction getTemporaryTableAfterUseAction()
      Description copied from class: Dialect
      The action to take after finishing use of a temporary table.
      Overrides:
      getTemporaryTableAfterUseAction in class Dialect
    • getTemporaryTableBeforeUseAction

      public BeforeUseAction getTemporaryTableBeforeUseAction()
      Description copied from class: Dialect
      The action to take before beginning use of a temporary table.
      Overrides:
      getTemporaryTableBeforeUseAction in class Dialect
    • getSelectGUIDString

      public String getSelectGUIDString()
      Description copied from class: Dialect
      Get the command used to select a GUID from the database.

      Optional operation.

      Overrides:
      getSelectGUIDString in class Dialect
      Returns:
      The appropriate command.
    • 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.
    • 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.
    • 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 Dialect
      Returns:
      True if readers block writers to achieve REPEATABLE_READ; 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.
    • getIdentityColumnSupport

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

      public boolean supportsPartitionBy()
      Description copied from class: Dialect
      Does is dialect support partition by?
      Overrides:
      supportsPartitionBy in class Dialect
    • appendBinaryLiteral

      public void appendBinaryLiteral(SqlAppender appender, byte[] bytes)
      Description copied from class: Dialect
      Append a binary literal to the given SqlAppender.
      Overrides:
      appendBinaryLiteral in class Dialect