# Class MySQLAdapter

java.lang.Object
org.apache.cayenne.dba.JdbcAdapter
org.apache.cayenne.dba.mysql.MySQLAdapter

All Implemented Interfaces:
  `DbAdapter`

public class MySQLAdapter extends JdbcAdapter
DbAdapter implementation for MySQL RDBMS.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected String`
  `storageEngine`

  ### Fields inherited from class JdbcAdapter

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

- ## Constructor Summary

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

- ## Method Summary

  Modifier and Type
  Method
  Description
  `DbAttribute`
  `buildAttribute(String name, String typeName, int type, int maxLength, int scale, boolean allowNulls)`
  Creates and returns a DbAttribute based on supplied parameters (usually obtained from database metadata).
  `protected void`
  `configureExtendedTypes(ExtendedTypeMap map)`
  Installs appropriate ExtendedTypes used as converters for passing values between JDBC and Java layers.
  `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 `MySQLPkGenerator`.
  `protected QuotingStrategy`
  `createQuotingStrategy()`
  `String`
  `createTable(DbEntity entity)`
  Overrides super implementation to explicitly set table engine to InnoDB if FK constraints are supported by this adapter.
  `void`
  `createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)`
  Appends AUTO_INCREMENT clause to the column definition for generated columns.
  `protected void`
  `createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity)`
  Customizes PK clause semantics to ensure that generated columns are in the beginning of the PK definition, as this seems to be a requirement for InnoDB tables.
  `Collection<String>`
  `dropTableStatements(DbEntity table)`
  Returns a collection of SQL statements needed to drop a database table.
  `SQLAction`
  `getAction(Query query, DataNode node)`
  Uses special action builder to create the right action.
  `ProcedureTranslator`
  `getProcedureTranslator(ProcedureQuery query, EntityResolver entityResolver)`
  Returns the `ProcedureTranslator` for the given query.
  `SQLTreeProcessor`
  `getSqlTreeProcessor()`
  `String`
  `getStorageEngine()`
  `List<String>`
  `getSystemCatalogs()`
  `int`
  `preferredBindingType(int jdbcType)`
  Returns the JDBC type that this adapter prefers to bind for a given mapped JDBC type.
  `void`
  `setStorageEngine(String engine)`
  `boolean`
  `typeSupportsLength(int type)`
  Returns true if supplied type can have a length attribute as a part of column definition

  ### Methods inherited from class JdbcAdapter

  `bind, bindParameter, bindParameter, createFkConstraint, createUniqueConstraint, defaultCharColumnLength, externalTypesForJdbcType, getBatchTerminator, getEjbqlTranslator, getExtendedTypes, getQuotingStrategy, getQuotingStrategy, getSelectTranslator, getSQLLogger, getSystemSchemas, getType, initExtendedTypes, nativeColumnTypes, setEjbqlTranslator, setEjbqlTranslatorFactory, setSupportsBatchUpdates, setSupportsGeneratedKeys, setSupportsUniqueConstraints, sizeAndPrecision, sizeAndScale, supportsBatchUpdates, supportsCatalogsOnReverseEngineering, supportsGeneratedKeys, supportsUniqueConstraints, tableTypeForTable, tableTypeForView, typeSupportsScale, unwrap`

  ### Methods inherited from class Object

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

  ### Methods inherited from interface DbAdapter

  `getEjbqlTranslatorFactory, preferredNativeColumnType, supportsGeneratedKeysForBatchInserts`

- ## Field Details

  - ### storageEngine

    protected String storageEngine

- ## Constructor Details

  - ### MySQLAdapter

    public MySQLAdapter(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`

  - ### createPkGenerator

    public PkGenerator createPkGenerator()
    Returns a `MySQLPkGenerator`.
    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

  - ### getAction

    public SQLAction getAction(Query query, DataNode node)
    Uses special action builder to create the right action.
    Specified by:
      `getAction` in interface `DbAdapter`
    Overrides:
      `getAction` in class `JdbcAdapter`
    Since:
      1.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`
    Overrides:
      `getProcedureTranslator` in class `JdbcAdapter`
    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`
    Overrides:
      `dropTableStatements` in class `JdbcAdapter`
    Since:
      3.0

  - ### configureExtendedTypes

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

  - ### buildAttribute

    public DbAttribute buildAttribute(String name, String typeName, int type, int maxLength, int scale, 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`
    Overrides:
      `buildAttribute` in class `JdbcAdapter`
    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
      `maxLength` - database column size (ignored if less than zero)
      `scale` - database column scale, i.e. the number of decimal digits (ignored if less than zero)
      `allowNulls` - database column nullable parameter

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

  - ### 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`
    Since:
      3.0

  - ### createTable

    public String createTable(DbEntity entity)
    Overrides super implementation to explicitly set table engine to InnoDB if FK constraints are supported by this adapter.
    Specified by:
      `createTable` in interface `DbAdapter`
    Overrides:
      `createTable` in class `JdbcAdapter`

  - ### createTableAppendPKClause

    protected void createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity)
    Customizes PK clause semantics to ensure that generated columns are in the beginning of the PK definition, as this seems to be a requirement for InnoDB tables.
    Overrides:
      `createTableAppendPKClause` in class `JdbcAdapter`
    Since:
      1.2

  - ### createTableAppendColumn

    public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)
    Appends AUTO_INCREMENT clause to the column definition for generated 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

  - ### typeSupportsLength

    public boolean typeSupportsLength(int type)
    Description copied from class: `JdbcAdapter`
    Returns true if supplied type can have a length attribute as a part of column definition
    Specified by:
      `typeSupportsLength` in interface `DbAdapter`
    Overrides:
      `typeSupportsLength` in class `JdbcAdapter`

  - ### getSystemCatalogs

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

  - ### getStorageEngine

    public String getStorageEngine()
    Since:
      3.0

  - ### setStorageEngine

    public void setStorageEngine(String engine)
    Since:
      3.0