SQLServerAdapter (cayenne-doc: Cayenne Documentation 5.0-M2 API)
Description: declaration: package: org.apache.cayenne.dba.sqlserver, class: SQLServerAdapter

# Class SQLServerAdapter

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

All Implemented Interfaces:
  `DbAdapter`

public class SQLServerAdapter extends SybaseAdapter

Cayenne DbAdapter implementation for Microsoft SQL Server engine.

### Microsoft Driver Settings

Sample connection settings to use with MS SQL Server are shown below:

          sqlserver.jdbc.username = test
          sqlserver.jdbc.password = secret
          sqlserver.jdbc.url = jdbc:sqlserver://192.168.0.65;databaseName=cayenne;SelectMethod=cursor
          sqlserver.jdbc.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver

Note on case-sensitive LIKE: if your application requires case-sensitive LIKE support, ask your DBA to configure the database to use a case-senstitive collation (one with "CS" in symbolic collation name instead of "CI", e.g. "SQL_Latin1_general_CP1_CS_AS").

### jTDS Driver Settings

jTDS is an open source driver that can be downloaded from http://jtds.sourceforge.net . It supports both SQLServer and Sybase. Sample SQLServer settings are the following:

          sqlserver.jdbc.username = test
          sqlserver.jdbc.password = secret
          sqlserver.jdbc.url = jdbc:jtds:sqlserver://192.168.0.65/cayenne
          sqlserver.jdbc.driver = net.sourceforge.jtds.jdbc.Driver

Since:
  1.1

- ## Field Summary

  ### Fields inherited from class JdbcAdapter

  `caseInsensitiveCollations, ejbqlTranslatorFactory, extendedTypes, logger, quotingStrategy, resourceLocator, supportsBatchUpdates, supportsGeneratedKeys, supportsUniqueConstraints, typesHandler`
  Modifier and Type
  Field
  Description
  `protected boolean`
  `caseInsensitiveCollations`
  `protected EJBQLTranslatorFactory`
  `ejbqlTranslatorFactory`
  `protected ExtendedTypeMap`
  `extendedTypes`
  `protected JdbcEventLogger`
  `logger`
  `protected QuotingStrategy`
  `quotingStrategy`
  `protected ResourceLocator`
  `resourceLocator`
  `protected boolean`
  `supportsBatchUpdates`
  `protected boolean`
  `supportsGeneratedKeys`
  `protected boolean`
  `supportsUniqueConstraints`
  `protected TypesHandler`
  `typesHandler`

- ## Constructor Summary

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `configureExtendedTypes(ExtendedTypeMap map)`
  Installs appropriate ExtendedTypes as converters for passing values between JDBC and Java layers.
  `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.
  `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 SybaseAdapter

  `bindParameter, createEJBQLTranslatorFactory, createQuotingStrategy, createTableAppendColumn, getBatchTerminator`
  Modifier and Type
  Method
  Description
  `void`
  `bindParameter(PreparedStatement statement, ParameterBinding binding)`
  Binds an object value to PreparedStatement's parameter.
  `protected EJBQLTranslatorFactory`
  `createEJBQLTranslatorFactory()`
  Creates and returns an `EJBQLTranslatorFactory` used to generate visitors for EJBQL to SQL translations.
  `protected QuotingStrategy`
  `createQuotingStrategy()`
  `void`
  `createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)`
  Overrides super implementation to correctly set up identity columns.
  `String`
  `getBatchTerminator()`
  Returns word "go".

  ### Methods inherited from class JdbcAdapter

  `buildAttribute, createFkConstraint, createTable, createTableAppendPKClause, dropTableStatements, externalTypesForJdbcType, findResource, getEjbqlTranslatorFactory, getExtendedTypes, getJdbcEventLogger, getPkGenerator, getQuotingStrategy, getSelectTranslator, getType, initExtendedTypes, setEjbqlTranslatorFactory, setPkGenerator, setSupportsBatchUpdates, setSupportsGeneratedKeys, setSupportsUniqueConstraints, sizeAndPrecision, supportsBatchUpdates, supportsCatalogsOnReverseEngineering, supportsGeneratedKeys, supportsUniqueConstraints, tableTypeForTable, tableTypeForView, typeSupportsLength, typeSupportsScale, unwrap`
  Modifier and Type
  Method
  Description
  `DbAttribute`
  `buildAttribute(String name, String typeName, int type, int size, int scale, boolean allowNulls)`
  Creates and returns a DbAttribute based on supplied parameters (usually obtained from database meta data).
  `String`
  `createFkConstraint(DbRelationship rel)`
  Returns a SQL string that can be used to create a foreign key constraint for the relationship.
  `String`
  `createTable(DbEntity entity)`
  Returns a SQL string that can be used to create database table corresponding to `ent` parameter.
  `protected void`
  `createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity)`
  `Collection<String>`
  `dropTableStatements(DbEntity table)`
  Returns a collection of SQL statements needed to drop a database table.
  `String[]`
  `externalTypesForJdbcType(int type)`
  Returns an array of RDBMS types that can be used with JDBC `type`.
  `protected URL`
  `findResource(String name)`
  Locates and returns a named adapter resource.
  `EJBQLTranslatorFactory`
  `getEjbqlTranslatorFactory()`
  Returns a translator factory for EJBQL to SQL translation.
  `ExtendedTypeMap`
  `getExtendedTypes()`
  Returns a map of ExtendedTypes that is used to translate values between Java and JDBC layer.
  `JdbcEventLogger`
  `getJdbcEventLogger()`
  `PkGenerator`
  `getPkGenerator()`
  Returns primary key generator associated with this DbAdapter.
  `QuotingStrategy`
  `getQuotingStrategy()`
  Returns SQL identifier quoting strategy object
  `SelectTranslator`
  `getSelectTranslator(FluentSelect<?,?> query, EntityResolver entityResolver)`
  `static String`
  `getType(DbAdapter adapter, DbAttribute column)`
  `protected void`
  `initExtendedTypes(List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ValueObjectTypeRegistry valueObjectTypeRegistry)`
  `void`
  `setEjbqlTranslatorFactory(EJBQLTranslatorFactory ejbqlTranslatorFactory)`
  Sets a translator factory for EJBQL to SQL translation.
  `void`
  `setPkGenerator(PkGenerator pkGenerator)`
  Sets new primary key generator.
  `void`
  `setSupportsBatchUpdates(boolean flag)`
  `void`
  `setSupportsGeneratedKeys(boolean flag)`
  `void`
  `setSupportsUniqueConstraints(boolean flag)`
  `static String`
  `sizeAndPrecision(DbAdapter adapter, DbAttribute column)`
  `boolean`
  `supportsBatchUpdates()`
  Returns `true` if the target database supports batch updates.
  `boolean`
  `supportsCatalogsOnReverseEngineering()`
  Returns true.
  `boolean`
  `supportsGeneratedKeys()`
  Returns true if a target database supports key autogeneration.
  `boolean`
  `supportsUniqueConstraints()`
  Returns true.
  `String`
  `tableTypeForTable()`
  Returns the name of the table type (as returned by `DatabaseMetaData.getTableTypes`) for a simple user table.
  `String`
  `tableTypeForView()`
  Returns the name of the table type (as returned by `DatabaseMetaData.getTableTypes`) for a view table.
  `boolean`
  `typeSupportsLength(int type)`
  Returns true if supplied type can have a length attribute as a part of column definition
  `boolean`
  `typeSupportsScale(int type)`
  Returns true if supplied type can have a scale attribute as a part of column definition.
  `DbAdapter`
  `unwrap()`
  Simply returns this, as JdbcAdapter is not a wrapper.

  ### Methods inherited from class Object

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

- ## Constructor Details

  - ### SQLServerAdapter

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

- ## Method Details

  - ### supportsGeneratedKeysForBatchInserts

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

  - ### getSqlTreeProcessor

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

  - ### configureExtendedTypes

    protected void configureExtendedTypes(ExtendedTypeMap map)
    Description copied from class: `SybaseAdapter`
    Installs appropriate ExtendedTypes as converters for passing values between JDBC and Java layers.
    Overrides:
      `configureExtendedTypes` in class `SybaseAdapter`

  - ### 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