# Class AutoAdapter

java.lang.Object
org.apache.cayenne.dba.AutoAdapter

All Implemented Interfaces:
  `DbAdapter`

public class AutoAdapter extends Object implements DbAdapter
A DbAdapter that automatically detects the kind of database it is running on and instantiates an appropriate DB-specific adapter, delegating all subsequent method calls to this adapter.

Since:
  1.2

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final DataSource`
  `dataSource`
  `protected final List<DbAdapterDetector>`
  `detectors`
  `protected final AdhocObjectFactory`
  `objectFactory`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `AutoAdapter(AdhocObjectFactory objectFactory, DataSource dataSource, List<DbAdapterDetector> detectors)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `bindParameter(CallableStatement statement, CSParameter<?> parameter)`
  Binds an object value to CallableStatement's parameter.
  `void`
  `bindParameter(PreparedStatement statement, PSParameter<?> parameter)`
  Binds an object value to PreparedStatement's parameter.
  `DbAttribute`
  `buildAttribute(String name, String typeName, int type, int size, int precision, boolean allowNulls)`
  Creates and returns a DbAttribute based on supplied parameters (usually obtained from database metadata).
  `String`
  `createFkConstraint(DbRelationship rel)`
  Returns a SQL string that can be used to create a foreign key constraint for the relationship, or null if foreign keys are not supported.
  `PkGenerator`
  `createPkGenerator()`
  Returns the default primary key generator of the wrapped adapter.
  `String`
  `createTable(DbEntity entity)`
  Returns a SQL string that can be used to create database table corresponding to `entity` parameter.
  `void`
  `createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)`
  Append the column type part of a "create table" to the given `StringBuffer`
  `String`
  `createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns)`
  Returns a DDL string to create a unique constraint over a set of columns, or null if the unique constraints are not supported.
  `protected DbAdapter`
  `defaultAdapter()`
  `int`
  `defaultCharColumnLength()`
  Returns the length to use for an unconstrained character column (a CHAR/VARCHAR-family column with no max length) when this database requires a length.
  `protected DbAdapter`
  `detectAdapter(DatabaseMetaData metaData)`
  `Collection<String>`
  `dropTableStatements(DbEntity table)`
  Returns a collection of SQL statements needed to drop a database table.
  `String[]`
  `externalTypesForJdbcType(int type)`
  Deprecated, for removal: This API element is subject to removal in a future version.
  `SQLAction`
  `getAction(Query query, DataNode node)`
  Returns an instance of SQLAction that should handle the query.
  `protected DbAdapter`
  `getAdapter()`
  Returns a proxied DbAdapter, lazily creating it on first invocation.
  `String`
  `getBatchTerminator()`
  Returns a String used to terminate a batch in command-line tools.
  `EJBQLTranslator`
  `getEjbqlTranslator()`
  Returns the `EJBQLTranslator` for EJBQL to SQL translation.
  `ExtendedTypeMap`
  `getExtendedTypes()`
  Returns a map of ExtendedTypes that is used to translate values between Java and JDBC layer.
  `ProcedureTranslator`
  `getProcedureTranslator(ProcedureQuery query, EntityResolver entityResolver)`
  Returns the `ProcedureTranslator` for the given query.
  `QuotingStrategy`
  `getQuotingStrategy()`
  Deprecated.
  `QuotingStrategy`
  `getQuotingStrategy(DbEntity entity)`
  Resolves the `QuotingStrategy` to use for the given entity: this adapter's strategy when the entity's DataMap enables SQL identifier quoting, and `QuotingStrategy.NONE` otherwise.
  `SelectTranslator`
  `getSelectTranslator(Select<?> query, EntityResolver entityResolver)`
  Returns the `SelectTranslator` for the given query.
  `SQLTreeProcessor`
  `getSqlTreeProcessor()`
  `List<String>`
  `getSystemCatalogs()`
  `List<String>`
  `getSystemSchemas()`
  `protected DbAdapter`
  `loadAdapter()`
  Loads underlying DbAdapter delegate.
  `NativeColumnType[]`
  `nativeColumnTypes(int type)`
  Returns the database-native types that the given JDBC `type` (see `Types`) maps to, or null if the type is not supported.
  `int`
  `preferredBindingType(int jdbcType)`
  Returns the JDBC type that this adapter prefers to bind for a given mapped JDBC type.
  `boolean`
  `supportsBatchUpdates()`
  Returns `true` if the target database supports batch updates.
  `boolean`
  `supportsCatalogsOnReverseEngineering()`
  Returns true if a target database supports catalogs on reverse engineering.
  `boolean`
  `supportsGeneratedKeys()`
  Returns true if a target database supports key autogeneration.
  `boolean`
  `supportsGeneratedKeysForBatchInserts()`
  Returns true if a target database supports key autogeneration in a batch insert.
  `boolean`
  `supportsUniqueConstraints()`
  Returns true if a target database supports UNIQUE constraints.
  `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)`
  `boolean`
  `typeSupportsScale(int type)`
  Returns true if supplied type can have a scale attribute as a part of column definition.
  `DbAdapter`
  `unwrap()`
  Allows the users to get access to the adapter decorated by a given adapter.

  ### Methods inherited from class Object

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

  ### Methods inherited from interface DbAdapter

  `getEjbqlTranslatorFactory, preferredNativeColumnType`

- ## Field Details

  - ### objectFactory

    protected final AdhocObjectFactory objectFactory

  - ### dataSource

    protected final DataSource dataSource

  - ### detectors

    protected final List<DbAdapterDetector> detectors

- ## Constructor Details

  - ### AutoAdapter

    public AutoAdapter(AdhocObjectFactory objectFactory, DataSource dataSource, List<DbAdapterDetector> detectors)

- ## Method Details

  - ### getAdapter

    protected DbAdapter getAdapter()
    Returns a proxied DbAdapter, lazily creating it on first invocation.

  - ### loadAdapter

    protected DbAdapter loadAdapter()
    Loads underlying DbAdapter delegate.

  - ### getSelectTranslator

    public SelectTranslator getSelectTranslator(Select<?> query, EntityResolver entityResolver)
    Description copied from interface: `DbAdapter`
    Returns the `SelectTranslator` for the given query. The default implementation ignores the query, but the parameter is retained so adapters can pick a translator based on it.
    Specified by:
      `getSelectTranslator` in interface `DbAdapter`
    Since:
      4.2

  - ### getProcedureTranslator

    public ProcedureTranslator getProcedureTranslator(ProcedureQuery query, EntityResolver entityResolver)
    Description copied from interface: `DbAdapter`
    Returns the `ProcedureTranslator` for the given query. The default implementation ignores the query, but the parameter is retained so adapters can pick a translator based on it.
    Specified by:
      `getProcedureTranslator` in interface `DbAdapter`
    Since:
      5.0

  - ### getBatchTerminator

    public String getBatchTerminator()
    Description copied from interface: `DbAdapter`
    Returns a String used to terminate a batch in command-line tools. E.g. ";" on Oracle or "go" on Sybase.
    Specified by:
      `getBatchTerminator` in interface `DbAdapter`

  - ### getSqlTreeProcessor

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

  - ### getAction

    public SQLAction getAction(Query query, DataNode node)
    Description copied from interface: `DbAdapter`
    Returns an instance of SQLAction that should handle the query.
    Specified by:
      `getAction` in interface `DbAdapter`

  - ### supportsUniqueConstraints

    public boolean supportsUniqueConstraints()
    Description copied from interface: `DbAdapter`
    Returns true if a target database supports UNIQUE constraints.
    Specified by:
      `supportsUniqueConstraints` in interface `DbAdapter`

  - ### supportsCatalogsOnReverseEngineering

    public boolean supportsCatalogsOnReverseEngineering()
    Description copied from interface: `DbAdapter`
    Returns true if a target database supports catalogs on reverse engineering.
    Specified by:
      `supportsCatalogsOnReverseEngineering` in interface `DbAdapter`

  - ### supportsGeneratedKeys

    public boolean supportsGeneratedKeys()
    Description copied from interface: `DbAdapter`
    Returns true if a target database supports key autogeneration. This feature also requires JDBC3-compliant driver.
    Specified by:
      `supportsGeneratedKeys` in interface `DbAdapter`

  - ### supportsGeneratedKeysForBatchInserts

    public boolean supportsGeneratedKeysForBatchInserts()
    Description copied from interface: `DbAdapter`
    Returns true if a target database supports key autogeneration in a batch insert.
    Specified by:
      `supportsGeneratedKeysForBatchInserts` in interface `DbAdapter`
    Since:
      4.2
    See Also:
      - `DbAdapter.supportsGeneratedKeys()`

  - ### supportsBatchUpdates

    public boolean supportsBatchUpdates()
    Description copied from interface: `DbAdapter`
    Returns `true` if the target database supports batch updates.
    Specified by:
      `supportsBatchUpdates` in interface `DbAdapter`

  - ### typeSupportsLength

    public boolean typeSupportsLength(int type)
    Specified by:
      `typeSupportsLength` in interface `DbAdapter`

  - ### typeSupportsScale

    public boolean typeSupportsScale(int type)
    Description copied from interface: `DbAdapter`
    Returns true if supplied type can have a scale attribute as a part of column definition.
    Specified by:
      `typeSupportsScale` in interface `DbAdapter`
    Since:
      5.0

  - ### defaultCharColumnLength

    public int defaultCharColumnLength()
    Description copied from interface: `DbAdapter`
    Returns the length to use for an unconstrained character column (a CHAR/VARCHAR-family column with no max length) when this database requires a length.
    Specified by:
      `defaultCharColumnLength` in interface `DbAdapter`
    Since:
      5.0

  - ### dropTableStatements

    public Collection<String> dropTableStatements(DbEntity table)
    Description copied from interface: `DbAdapter`
    Returns a collection of SQL statements needed to drop a database table.
    Specified by:
      `dropTableStatements` in interface `DbAdapter`

  - ### createTable

    public String createTable(DbEntity entity)
    Description copied from interface: `DbAdapter`
    Returns a SQL string that can be used to create database table corresponding to `entity` parameter.
    Specified by:
      `createTable` in interface `DbAdapter`

  - ### createUniqueConstraint

    public String createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns)
    Description copied from interface: `DbAdapter`
    Returns a DDL string to create a unique constraint over a set of columns, or null if the unique constraints are not supported.
    Specified by:
      `createUniqueConstraint` in interface `DbAdapter`

  - ### createFkConstraint

    public String createFkConstraint(DbRelationship rel)
    Description copied from interface: `DbAdapter`
    Returns a SQL string that can be used to create a foreign key constraint for the relationship, or null if foreign keys are not supported.
    Specified by:
      `createFkConstraint` in interface `DbAdapter`

  - ### externalTypesForJdbcType

    @Deprecated(since="5.0", forRemoval=true) public String[] externalTypesForJdbcType(int type)
    Deprecated, for removal: This API element is subject to removal in a future version.
    Description copied from interface: `DbAdapter`
    Returns an array of RDBMS types that can be used with JDBC `type`. Valid JDBC types are defined in java.sql.Types.
    Specified by:
      `externalTypesForJdbcType` in interface `DbAdapter`

  - ### nativeColumnTypes

    public NativeColumnType[] nativeColumnTypes(int type)
    Description copied from interface: `DbAdapter`
    Returns the database-native types that the given JDBC `type` (see `Types`) maps to, or null if the type is not supported. The first variant is used for column DDL.
    Specified by:
      `nativeColumnTypes` in interface `DbAdapter`

  - ### getExtendedTypes

    public ExtendedTypeMap getExtendedTypes()
    Description copied from interface: `DbAdapter`
    Returns a map of ExtendedTypes that is used to translate values between Java and JDBC layer.
    Specified by:
      `getExtendedTypes` in interface `DbAdapter`

  - ### createPkGenerator

    public PkGenerator createPkGenerator()
    Returns the default primary key generator of the wrapped adapter.
    Specified by:
      `createPkGenerator` in interface `DbAdapter`

  - ### buildAttribute

    public DbAttribute buildAttribute(String name, String typeName, int type, int size, int precision, boolean allowNulls)
    Description copied from interface: `DbAdapter`
    Creates and returns a DbAttribute based on supplied parameters (usually obtained from database metadata).
    Specified by:
      `buildAttribute` in interface `DbAdapter`
    Parameters:
      `name` - database column name
      `typeName` - database specific type name, may be used as a hint to determine the right JDBC type.
      `type` - JDBC column type
      `size` - database column size (ignored if less than zero)
      `precision` - database column scale, i.e. the number of decimal digits (ignored if less than zero)
      `allowNulls` - database column nullable parameter

  - ### bindParameter

    public void bindParameter(PreparedStatement statement, PSParameter<?> parameter) throws Exception
    Description copied from interface: `DbAdapter`
    Binds an object value to PreparedStatement's parameter.
    Specified by:
      `bindParameter` in interface `DbAdapter`
    Throws:
      `Exception`

  - ### bindParameter

    public void bindParameter(CallableStatement statement, CSParameter<?> parameter) throws Exception
    Description copied from interface: `DbAdapter`
    Binds an object value to CallableStatement's parameter.
    Specified by:
      `bindParameter` in interface `DbAdapter`
    Throws:
      `Exception`

  - ### preferredBindingType

    public int preferredBindingType(int jdbcType)
    Description copied from interface: `DbAdapter`
    Returns the JDBC type that this adapter prefers to bind for a given mapped JDBC type. The default implementation is an identity function; adapters whose drivers require a different type (e.g. remapping the `N*` character types to their non-national counterparts) override this. The returned type is resolved into the `PSParameter` at binding creation time, so it matches the type actually sent to the PreparedStatement.
    Specified by:
      `preferredBindingType` in interface `DbAdapter`
    Since:
      5.0

  - ### tableTypeForTable

    public String tableTypeForTable()
    Description copied from interface: `DbAdapter`
    Returns the name of the table type (as returned by `DatabaseMetaData.getTableTypes`) for a simple user table.
    Specified by:
      `tableTypeForTable` in interface `DbAdapter`

  - ### tableTypeForView

    public String tableTypeForView()
    Description copied from interface: `DbAdapter`
    Returns the name of the table type (as returned by `DatabaseMetaData.getTableTypes`) for a view table.
    Specified by:
      `tableTypeForView` in interface `DbAdapter`

  - ### createTableAppendColumn

    public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)
    Description copied from interface: `DbAdapter`
    Append the column type part of a "create table" to the given `StringBuffer`
    Specified by:
      `createTableAppendColumn` in interface `DbAdapter`
    Parameters:
      `sqlBuffer` - the `StringBuffer` to append the column type to
      `column` - the `DbAttribute` defining the column to append type for

  - ### getQuotingStrategy

    @Deprecated public QuotingStrategy getQuotingStrategy()
    Deprecated.
    Description copied from interface: `DbAdapter`
    Returns the SQL identifier quoting style (start/end quote characters) for this adapter. Whether quoting is applied is decided by the caller, which uses this instance when quoting is enabled and `QuotingStrategy.NONE` otherwise.
    Specified by:
      `getQuotingStrategy` in interface `DbAdapter`

  - ### getQuotingStrategy

    public QuotingStrategy getQuotingStrategy(DbEntity entity)
    Description copied from interface: `DbAdapter`
    Resolves the `QuotingStrategy` to use for the given entity: this adapter's strategy when the entity's DataMap enables SQL identifier quoting, and `QuotingStrategy.NONE` otherwise.
    Specified by:
      `getQuotingStrategy` in interface `DbAdapter`
    Since:
      5.0

  - ### unwrap

    public DbAdapter unwrap()
    Description copied from interface: `DbAdapter`
    Allows the users to get access to the adapter decorated by a given adapter.
    Specified by:
      `unwrap` in interface `DbAdapter`
    Since:
      4.0

  - ### getEjbqlTranslator

    public EJBQLTranslator getEjbqlTranslator()
    Description copied from interface: `DbAdapter`
    Returns the `EJBQLTranslator` for EJBQL to SQL translation.
    Specified by:
      `getEjbqlTranslator` in interface `DbAdapter`
    Since:
      5.0

  - ### getSystemCatalogs

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

  - ### getSystemSchemas

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

  - ### detectAdapter

    protected DbAdapter detectAdapter(DatabaseMetaData metaData) throws SQLException
    Throws:
      `SQLException`

  - ### defaultAdapter

    protected DbAdapter defaultAdapter()