Class MsSql

All Implemented Interfaces:
Backend

@Service(Backend.class) public class MsSql extends AbstractSql2003Backend
Backend for Microsoft SQL Server.
Author:
harald
  • Field Details

  • Constructor Details

    • MsSql

      public MsSql()
      Creates the MS-Sql backend.
  • Method Details

    • isFilteredIndexSupported

      public boolean isFilteredIndexSupported()
      Description copied from interface: Backend
      Returns whether backend supports filtered indexes.
      Specified by:
      isFilteredIndexSupported in interface Backend
      Overrides:
      isFilteredIndexSupported in class AbstractBackend
      Returns:
      true if supported, false if the model will raise an error if a filtered index is used
    • isMatchingUrl

      public boolean isMatchingUrl(String url)
      Description copied from interface: Backend
      Checks whether the backend belongs to the given jdbc url.
      If multiple backend implementations are provided for the same database type, only one backend should match the URL. The others must be selected via name.
      Parameters:
      url - the jdbc url
      Returns:
      true if matches
    • getName

      public String getName()
      Description copied from interface: Backend
      Gets the name of the backend.
      Returns:
      the name
    • getDriverClassName

      public String getDriverClassName()
      Description copied from interface: Backend
      Gets the JDBC driver class name.
      Returns:
      the class name
    • getXADataSourceClassName

      public String getXADataSourceClassName()
      Description copied from interface: Backend
      Gets the name of the JDBC driver's XADataSource class.
      Required for connections taking part in global (XA) transactions.
      Specified by:
      getXADataSourceClassName in interface Backend
      Overrides:
      getXADataSourceClassName in class AbstractBackend
      Returns:
      the class name, null if the backend does not support XA
    • getBackendId

      public String getBackendId(Connection connection)
      Description copied from interface: Backend
      Determines the unique id or name used by the backend for a given connection.

      Useful to figure out the corresponding ManagedConnection from the backend's logfiles.

      Parameters:
      connection - the jdbc connection
      Returns:
      the backend id, null if none
    • 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.

      A limit without an offset is implemented via TOP, which ignores the write lock.

      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
    • setLeadingSelectParameters

      public int setLeadingSelectParameters(BackendPreparedStatement stmt, int limit, int offset)
      Description copied from interface: Backend
      Sets optional parameters before applying the original parameters.
      Specified by:
      setLeadingSelectParameters in interface Backend
      Overrides:
      setLeadingSelectParameters in class AbstractSql2003Backend
      Parameters:
      stmt - the prepared statement
      limit - the limit value, ≤ 0 if no limit clause
      offset - the offset value, ≤ 0 if no offset clause
      Returns:
      the next parameter index
    • setTrailingSelectParameters

      public int setTrailingSelectParameters(BackendPreparedStatement stmt, int index, int limit, int offset)
      Description copied from class: AbstractSql2003Backend
      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.

      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
    • getMaxSize

      public int getMaxSize(SqlType sqlType)
      Description copied from interface: Backend
      Returns the maximum size for a given SQL type.
      Specified by:
      getMaxSize in interface Backend
      Overrides:
      getMaxSize in class AbstractBackend
      Parameters:
      sqlType - the SQL-type
      Returns:
      the maximum size, 0 if unlimited, -1 for types without a size
    • sqlTypeToString

      public String sqlTypeToString(SqlType sqlType, int size)
      Description copied from interface: Backend
      Converts the java SQL type to the database type name.
      Specified by:
      sqlTypeToString in interface Backend
      Overrides:
      sqlTypeToString in class AbstractBackend
      Parameters:
      sqlType - the java SQL type
      size - the column's size
      Returns:
      the corresponding type string
    • jdbcTypeToSqlType

      public SqlType[] jdbcTypeToSqlType(int jdbcType, int size, int scale)
      Description copied from interface: Backend
      Converts the JDBC data type integer to Tentackle SqlTypes.

      There may be more than one SqlType returned!

      Specified by:
      jdbcTypeToSqlType in interface Backend
      Overrides:
      jdbcTypeToSqlType in class AbstractBackend
      Parameters:
      jdbcType - the jdbc data type
      size - the column size
      scale - the column's scale
      Returns:
      the SqlTypes, empty array if no mapping available or no exact match (not generated by Tentackle)
      See Also:
    • sqlRenameIndex

      public String sqlRenameIndex(String tableName, String oldIndexName, String newIndexName)
      Description copied from interface: Backend
      Generates SQL code to rename an index.
      Specified by:
      sqlRenameIndex in interface Backend
      Overrides:
      sqlRenameIndex in class AbstractBackend
      Parameters:
      tableName - the table name
      oldIndexName - the old index name
      newIndexName - the new index name
      Returns:
      the SQL code, null if not supported by the backend and the index must be dropped and re-created
    • isTransientTransactionException

      public boolean isTransientTransactionException(SQLException ex)
      Description copied from interface: Backend
      Determines whether the exception is transient and retrying the transaction may succeed.
      Typical transient exceptions are thrown when a deadlock is detected or when serialized transaction isolation is used.

      Other transient errors are not covered by this method (e.g., connection timeouts, etc...).

      Specified by:
      isTransientTransactionException in interface Backend
      Overrides:
      isTransientTransactionException in class AbstractBackend
      Parameters:
      ex - the exception
      Returns:
      true if retrying the transaction may succeed
    • isDropIfExistsSupported

      protected boolean isDropIfExistsSupported()
      Description copied from class: AbstractBackend
      Adds "IF EXISTS" to drop clauses, if supported by the backend.
      Makes migration a little more robust in case the same SQL scripts are applied to different databases than those used to generate the migration scripts for.
      Overrides:
      isDropIfExistsSupported in class AbstractBackend
      Returns:
      true if supported
    • isSqlxmlSupported

      public boolean isSqlxmlSupported()
      Description copied from interface: Backend
      Returns whether the backend supports the JDBC SQLXML binding natively, i.e., a native XML column type plus a driver implementing createSQLXML/setSQLXML/getSQLXML.
      If not, XML content is emulated as CLOB/VARCHAR.
      Specified by:
      isSqlxmlSupported in interface Backend
      Overrides:
      isSqlxmlSupported in class AbstractBackend
      Returns:
      true if supported, false if emulated