Package org.apache.torque.adapter

## Class MssqlAdapter

- java.lang.Object
- - org.apache.torque.adapter.AbstractAdapter
  - - org.apache.torque.adapter.MssqlAdapter

- All Implemented Interfaces:
    `Serializable`, `Adapter`

      public class MssqlAdapter
      extends AbstractAdapter

  This is used to connect to a MSSQL database. This is tested with the jtds driver from sourceforge.
  Version:
    $Id: MssqlAdapter.java 1848527 2018-12-09 16:27:22Z tv $
  Author:
    Gonzalo Diethelm
  See Also:
    Serialized Form

- - ### Field Summary

    - ### Fields inherited from interface org.apache.torque.adapter.Adapter

      `ADAPTER_KEY, AUTODETECT_ADAPTER, DRIVER_KEY`

  - ### Constructor Summary

    Constructors
    Modifier | Constructor | Description
    --- | --- | ---
    `protected` | `MssqlAdapter()` | Empty constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `boolean` | `escapeText()` | Determines whether backslashes (\) should be escaped in explicit SQL strings.
    `void` | `generateLimits​(Query query, long offset, int limit)` | Modify a query to add limit and offset values for MSSQL.
    `String` | `getIDMethodSQL​(Object unused)` | Returns the last value from an identity column (available on a per-session basis from the global variable `@@identity`).
    `IDMethod` | `getIDMethodType()` | Returns the constant from the `IDMethod` interface denoting which type of primary key generation method this type of RDBMS uses.
    `String` | `getUpdateLockClause()` | Returns the clause which acquires a write lock on a row when doing a select.
    `String` | `ignoreCase​(String in)` | This method is used to ignore case.
    `void` | `lockTable​(Connection con, String table)` | Locks the specified table.
    `boolean` | `supportsNativeOffset()` | Returns whether the database natively supports returning results starting at an offset position other than 0.
    `String` | `toUpperCase​(String in)` | This method is used to ignore case.
    `void` | `unlockTable​(Connection con, String table)` | Tries to unlock the specified table.
    `boolean` | `useEscapeClauseForLike()` | Whether an escape clause in like should be used.

    - ### Methods inherited from class org.apache.torque.adapter.AbstractAdapter

      `getStringDelimiter, ignoreCaseInOrderBy, setCapabilities, supportsNativeLimit, useGetGeneratedKeys, useIlike, useMinusForExcept`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### MssqlAdapter

          protected MssqlAdapter()

      Empty constructor.

  - ### Method Detail

    - #### toUpperCase

          public String toUpperCase​(String in)

      This method is used to ignore case.
      Specified by:
        `toUpperCase` in interface `Adapter`
      Specified by:
        `toUpperCase` in class `AbstractAdapter`
      Parameters:
        `in` - The string to transform to upper case.
      Returns:
        The upper case string.

    - #### ignoreCase

          public String ignoreCase​(String in)

      This method is used to ignore case.
      Specified by:
        `ignoreCase` in interface `Adapter`
      Specified by:
        `ignoreCase` in class `AbstractAdapter`
      Parameters:
        `in` - The string whose case to ignore.
      Returns:
        The string in a case that can be ignored.

    - #### getIDMethodType

          public IDMethod getIDMethodType()

      Description copied from class: `AbstractAdapter`
      Returns the constant from the `IDMethod` interface denoting which type of primary key generation method this type of RDBMS uses.
      Specified by:
        `getIDMethodType` in interface `Adapter`
      Specified by:
        `getIDMethodType` in class `AbstractAdapter`
      Returns:
        IDMethod constant
      See Also:
        `Adapter.getIDMethodType()`

    - #### getIDMethodSQL

          public String getIDMethodSQL​(Object unused)

      Returns the last value from an identity column (available on a per-session basis from the global variable `@@identity`).
      Specified by:
        `getIDMethodSQL` in interface `Adapter`
      Specified by:
        `getIDMethodSQL` in class `AbstractAdapter`
      Parameters:
        `unused` - Information used for key generation.
      Returns:
        The most recently inserted database key.
      See Also:
        `Adapter.getIDMethodSQL(Object obj)`

    - #### getUpdateLockClause

          public String getUpdateLockClause()

      Returns the clause which acquires a write lock on a row when doing a select.
      Specified by:
        `getUpdateLockClause` in interface `Adapter`
      Overrides:
        `getUpdateLockClause` in class `AbstractAdapter`
      Returns:
        the SQL clause to acquire a write lock. This implementation returns "WITH (UPDLOCK)";

    - #### lockTable

          public void lockTable​(Connection con,
                                String table)
                         throws SQLException

      Locks the specified table.
      Specified by:
        `lockTable` in interface `Adapter`
      Specified by:
        `lockTable` in class `AbstractAdapter`
      Parameters:
        `con` - The JDBC connection to use.
        `table` - The name of the table to lock.
      Throws:
        `SQLException` - No Statement could be created or executed.

    - #### unlockTable

          public void unlockTable​(Connection con,
                                  String table)
                           throws SQLException

      Tries to unlock the specified table. This implementation does nothing as tables in MSSQL are unlocked when a commit or rollback is issued. This has unintended side effects, as well as we do not know whether to use commit or rollback. The lock will go away automatically when the transaction is ended.
      Specified by:
        `unlockTable` in interface `Adapter`
      Specified by:
        `unlockTable` in class `AbstractAdapter`
      Parameters:
        `con` - The JDBC connection to use.
        `table` - The name of the table to unlock.
      Throws:
        `SQLException` - No Statement could be created or executed.

    - #### supportsNativeOffset

          public boolean supportsNativeOffset()

      Returns whether the database natively supports returning results starting at an offset position other than 0. Return false for MSSQL
      Specified by:
        `supportsNativeOffset` in interface `Adapter`
      Overrides:
        `supportsNativeOffset` in class `AbstractAdapter`
      Returns:
        true if the database natively supports returning results starting at an offset position other than 0.

    - #### generateLimits

          public void generateLimits​(Query query,
                                     long offset,
                                     int limit)
                              throws TorqueException

      Modify a query to add limit and offset values for MSSQL.
      Specified by:
        `generateLimits` in interface `Adapter`
      Overrides:
        `generateLimits` in class `AbstractAdapter`
      Parameters:
        `query` - The query to modify
        `offset` - the offset Value
        `limit` - the limit Value
      Throws:
        `TorqueException` - if any error occurs when building the query

    - #### escapeText

          public boolean escapeText()

      Determines whether backslashes (\) should be escaped in explicit SQL strings. If true is returned, a BACKSLASH will be changed to "\\". If false is returned, a BACKSLASH will be left as "\". Sybase (and MSSQL) doesn't define a default escape character, so false is returned.
      Specified by:
        `escapeText` in interface `Adapter`
      Overrides:
        `escapeText` in class `AbstractAdapter`
      Returns:
        false
      See Also:
        `Adapter.escapeText()`

    - #### useEscapeClauseForLike

          public boolean useEscapeClauseForLike()

      Whether an escape clause in like should be used. Example : select * from AUTHOR where AUTHOR.NAME like '\_%' ESCAPE '\'; MSSQL needs this, so this implementation always returns `true`.
      Specified by:
        `useEscapeClauseForLike` in interface `Adapter`
      Overrides:
        `useEscapeClauseForLike` in class `AbstractAdapter`
      Returns:
        whether the escape clause should be appended or not.