# Class SQLServerAdapter

java.lang.Object
org.apache.cayenne.dba.JdbcAdapter
org.apache.cayenne.dba.sqlserver.SQLServerAdapter

All Implemented Interfaces:
  `DbAdapter`

public class SQLServerAdapter extends JdbcAdapter
Cayenne DbAdapter implementation for Microsoft SQL Server RDBMS.

Since:
  1.1

- ## Field Summary

  ### Fields inherited from class JdbcAdapter

  `caseInsensitiveCollations, defaultCharColumnLength, ejbqlTranslator, extendedTypes, logger, nativeColumnTypes, quotingStrategy, supportsBatchUpdates, supportsGeneratedKeys, supportsUniqueConstraints`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SQLServerAdapter(RuntimeProperties runtimeProperties, List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ValueObjectTypeRegistry valueObjectTypeRegistry)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `bind(PreparedStatement statement, Object value, int psPosition, int psType, int psScale, ExtendedType binder)`
  Binds a raw value to a statement parameter.
  `protected void`
  `configureExtendedTypes(ExtendedTypeMap map)`
  Called from `JdbcAdapter.initExtendedTypes(List, List, List, ValueObjectTypeRegistry)` to load adapter-specific types into the ExtendedTypeMap right after the default types are loaded, but before the DI overrides are.
  `protected EJBQLTranslator`
  `createEJBQLTranslator()`
  Creates and returns an `EJBQLTranslator` used to generate visitors for EJBQL to SQL translations.
  `protected NativeColumnType[]`
  `createNativeTypes()`
  Returns the database-native types supported by this adapter.
  `PkGenerator`
  `createPkGenerator()`
  Returns a `SQLServerPkGenerator`.
  `protected QuotingStrategy`
  `createQuotingStrategy()`
  `void`
  `createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)`
  Overrides super implementation to correctly set up identity columns.
  `String`
  `createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns)`
  Generates DDL to create unique index that allows multiple NULL values to comply with ANSI SQL, that is default behaviour for other RDBMS.
  `SQLAction`
  `getAction(Query query, DataNode node)`
  Uses SQLServerActionBuilder to create the right action.
  `String`
  `getBatchTerminator()`
  Returns the word "go".
  `SQLTreeProcessor`
  `getSqlTreeProcessor()`
  `List<String>`
  `getSystemCatalogs()`
  `List<String>`
  `getSystemSchemas()`
  `Integer`
  `getVersion()`
  `void`
  `setVersion(Integer version)`
  `boolean`
  `supportsGeneratedKeysForBatchInserts()`
  Not supported, see: mssql-jdbc #245

  ### Methods inherited from class JdbcAdapter

  `bindParameter, bindParameter, buildAttribute, createFkConstraint, createTable, createTableAppendPKClause, defaultCharColumnLength, dropTableStatements, externalTypesForJdbcType, getEjbqlTranslator, getExtendedTypes, getProcedureTranslator, getQuotingStrategy, getQuotingStrategy, getSelectTranslator, getSQLLogger, getType, initExtendedTypes, nativeColumnTypes, setEjbqlTranslator, setEjbqlTranslatorFactory, setSupportsBatchUpdates, setSupportsGeneratedKeys, setSupportsUniqueConstraints, sizeAndPrecision, sizeAndScale, supportsBatchUpdates, supportsCatalogsOnReverseEngineering, supportsGeneratedKeys, supportsUniqueConstraints, tableTypeForTable, tableTypeForView, typeSupportsLength, typeSupportsScale, unwrap`

  ### Methods inherited from class Object

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

  ### Methods inherited from interface DbAdapter

  `getEjbqlTranslatorFactory, preferredBindingType, preferredNativeColumnType`

- ## Constructor Details

  - ### SQLServerAdapter

    public SQLServerAdapter(RuntimeProperties runtimeProperties, List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ValueObjectTypeRegistry valueObjectTypeRegistry)

- ## Method Details

  - ### createNativeTypes

    protected NativeColumnType[] createNativeTypes()
    Description copied from class: `JdbcAdapter`
    Returns the database-native types supported by this adapter.
    Overrides:
      `createNativeTypes` in class `JdbcAdapter`

  - ### createQuotingStrategy

    protected QuotingStrategy createQuotingStrategy()
    Overrides:
      `createQuotingStrategy` in class `JdbcAdapter`

  - ### createEJBQLTranslator

    protected EJBQLTranslator createEJBQLTranslator()
    Description copied from class: `JdbcAdapter`
    Creates and returns an `EJBQLTranslator` used to generate visitors for EJBQL to SQL translations. This method should be overriden by subclasses that need to customize EJBQL generation.
    Overrides:
      `createEJBQLTranslator` in class `JdbcAdapter`

  - ### getBatchTerminator

    public String getBatchTerminator()
    Returns the word "go".
    Specified by:
      `getBatchTerminator` in interface `DbAdapter`
    Overrides:
      `getBatchTerminator` in class `JdbcAdapter`

  - ### bind

    protected void bind(PreparedStatement statement, Object value, int psPosition, int psType, int psScale, ExtendedType binder) throws Exception
    Description copied from class: `JdbcAdapter`
    Binds a raw value to a statement parameter. This is the single extension point shared by both `bindParameter` overloads; adapters that need database-specific handling (e.g. of NULLs) should override this method rather than the public overloads.
    Overrides:
      `bind` in class `JdbcAdapter`
    Throws:
      `Exception`

  - ### createTableAppendColumn

    public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)
    Overrides super implementation to correctly set up identity columns.
    Specified by:
      `createTableAppendColumn` in interface `DbAdapter`
    Overrides:
      `createTableAppendColumn` in class `JdbcAdapter`
    Parameters:
      `sqlBuffer` - the `StringBuffer` to append the column type to
      `column` - the `DbAttribute` defining the column to append type for

  - ### supportsGeneratedKeysForBatchInserts

    public boolean supportsGeneratedKeysForBatchInserts()
    Not supported, see: mssql-jdbc #245
    See Also:
      - `DbAdapter.supportsGeneratedKeys()`

  - ### createPkGenerator

    public PkGenerator createPkGenerator()
    Returns a `SQLServerPkGenerator`.
    Specified by:
      `createPkGenerator` in interface `DbAdapter`
    Overrides:
      `createPkGenerator` in class `JdbcAdapter`

  - ### getSqlTreeProcessor

    public SQLTreeProcessor getSqlTreeProcessor()
    Specified by:
      `getSqlTreeProcessor` in interface `DbAdapter`
    Overrides:
      `getSqlTreeProcessor` in class `JdbcAdapter`
    Returns:
      `SQLTreeProcessor` that can adjust SQL tree to specific database flavour
    Since:
      4.2

  - ### configureExtendedTypes

    protected void configureExtendedTypes(ExtendedTypeMap map)
    Description copied from class: `JdbcAdapter`
    Called from `JdbcAdapter.initExtendedTypes(List, List, List, ValueObjectTypeRegistry)` to load adapter-specific types into the ExtendedTypeMap right after the default types are loaded, but before the DI overrides are. This method has specific implementations in JdbcAdapter subclasses.
    Overrides:
      `configureExtendedTypes` in class `JdbcAdapter`

  - ### getAction

    public SQLAction getAction(Query query, DataNode node)
    Uses SQLServerActionBuilder to create the right action.
    Specified by:
      `getAction` in interface `DbAdapter`
    Overrides:
      `getAction` in class `JdbcAdapter`
    Since:
      1.2

  - ### getSystemSchemas

    public List<String> getSystemSchemas()
    Specified by:
      `getSystemSchemas` in interface `DbAdapter`
    Overrides:
      `getSystemSchemas` in class `JdbcAdapter`
    Returns:
      list of system schemas

  - ### getSystemCatalogs

    public List<String> getSystemCatalogs()
    Specified by:
      `getSystemCatalogs` in interface `DbAdapter`
    Overrides:
      `getSystemCatalogs` in class `JdbcAdapter`
    Returns:
      list of system catalogs

  - ### getVersion

    public Integer getVersion()

  - ### setVersion

    public void setVersion(Integer version)
    Parameters:
      `version` - of the server as provided by the JDBC driver
    Since:
      4.2

  - ### createUniqueConstraint

    public String createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns)
    Generates DDL to create unique index that allows multiple NULL values to comply with ANSI SQL, that is default behaviour for other RDBMS.
    Example:

        CREATE UNIQUE NONCLUSTERED INDEX _idx_entity_attribute
        ON entity(attribute)
        WHERE attribute IS NOT NULL

    Specified by:
      `createUniqueConstraint` in interface `DbAdapter`
    Overrides:
      `createUniqueConstraint` in class `JdbcAdapter`
    Parameters:
      `source` - entity for the index
      `columns` - source columns for the index
    Returns:
      DDL to create unique index
    Since:
      4.2.1