public class MySQLAdapter extends JdbcAdapter
Foreign key constraints are supported by InnoDB engine and NOT supported by
MyISAM engine. This adapter by default assumes MyISAM, so
supportsFkConstraints will be false. Users can manually change
this by calling setSupportsFkConstraints(true) or better by using an
AutoAdapter, i.e. not entering the adapter
name at all for the DataNode, letting Cayenne guess it in runtime. In the
later case Cayenne will check the table_type MySQL variable to
detect whether InnoDB is the default, and configure the adapter accordingly.
| Modifier and Type | Field and Description |
|---|---|
protected String |
storageEngine |
batchQueryBuilderFactory, caseInsensitiveCollations, ejbqlTranslatorFactory, extendedTypes, logger, quotingStrategy, resourceLocator, supportsBatchUpdates, supportsGeneratedKeys, supportsUniqueConstraints, typesHandler| Constructor and Description |
|---|
MySQLAdapter(RuntimeProperties runtimeProperties,
List<ExtendedType> defaultExtendedTypes,
List<ExtendedType> userExtendedTypes,
List<ExtendedTypeFactory> extendedTypeFactories,
ResourceLocator resourceLocator,
ValueObjectTypeRegistry valueObjectTypeRegistry) |
| Modifier and Type | Method and Description |
|---|---|
void |
bindParameter(PreparedStatement statement,
ParameterBinding binding)
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 meta data).
|
protected void |
configureExtendedTypes(ExtendedTypeMap map)
Installs appropriate ExtendedTypes used as converters for passing values
between JDBC and Java layers.
|
protected EJBQLTranslatorFactory |
createEJBQLTranslatorFactory()
Creates and returns an
EJBQLTranslatorFactory used to generate
visitors for EJBQL to SQL translations. |
protected PkGenerator |
createPkGenerator()
Creates and returns a primary key generator.
|
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.
|
QualifierTranslator |
getQualifierTranslator(QueryAssembler queryAssembler)
Creates and returns a default implementation of a qualifier translator.
|
SelectTranslator |
getSelectTranslator(SelectQuery<?> query,
EntityResolver entityResolver)
Returns a SelectTranslator that works with the adapter target database.
|
String |
getStorageEngine() |
void |
setStorageEngine(String engine) |
boolean |
typeSupportsLength(int type)
Returns true if supplied type can have a length attribute as a part of
column definition
|
createFkConstraint, createUniqueConstraint, externalTypesForJdbcType, findResource, getBatchQueryBuilderFactory, getBatchTerminator, getEjbqlTranslatorFactory, getExtendedTypes, getJdbcEventLogger, getPkGenerator, getQuotingStrategy, getQuotingStrategy, getType, initExtendedTypes, setBatchQueryBuilderFactory, setEjbqlTranslatorFactory, setPkGenerator, setSupportsBatchUpdates, setSupportsGeneratedKeys, setSupportsUniqueConstraints, sizeAndPrecision, supportsBatchUpdates, supportsCatalogsOnReverseEngineering, supportsGeneratedKeys, supportsUniqueConstraints, tableTypeForTable, tableTypeForView, unwrapprotected String storageEngine
public MySQLAdapter(RuntimeProperties runtimeProperties, List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ResourceLocator resourceLocator, ValueObjectTypeRegistry valueObjectTypeRegistry)
protected QuotingStrategy createQuotingStrategy()
createQuotingStrategy in class JdbcAdapterpublic SelectTranslator getSelectTranslator(SelectQuery<?> query, EntityResolver entityResolver)
DbAdaptergetSelectTranslator in interface DbAdaptergetSelectTranslator in class JdbcAdapterpublic QualifierTranslator getQualifierTranslator(QueryAssembler queryAssembler)
JdbcAdaptergetQualifierTranslator in interface DbAdaptergetQualifierTranslator in class JdbcAdapterpublic SQLAction getAction(Query query, DataNode node)
getAction in interface DbAdaptergetAction in class JdbcAdapterpublic Collection<String> dropTableStatements(DbEntity table)
DbAdapterdropTableStatements in interface DbAdapterdropTableStatements in class JdbcAdapterprotected void configureExtendedTypes(ExtendedTypeMap map)
configureExtendedTypes in class JdbcAdapterpublic DbAttribute buildAttribute(String name, String typeName, int type, int size, int precision, boolean allowNulls)
DbAdapterbuildAttribute in interface DbAdapterbuildAttribute in class JdbcAdaptername - database column nametypeName - database specific type name, may be used as a hint to
determine the right JDBC type.type - JDBC column typesize - 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 parameterpublic void bindParameter(PreparedStatement statement, ParameterBinding binding) throws SQLException, Exception
DbAdapterbindParameter in interface DbAdapterbindParameter in class JdbcAdapterSQLExceptionExceptionprotected PkGenerator createPkGenerator()
createPkGenerator in class JdbcAdapterprotected EJBQLTranslatorFactory createEJBQLTranslatorFactory()
JdbcAdapterEJBQLTranslatorFactory used to generate
visitors for EJBQL to SQL translations. This method should be overriden
by subclasses that need to customize EJBQL generation.createEJBQLTranslatorFactory in class JdbcAdapterpublic String createTable(DbEntity entity)
createTable in interface DbAdaptercreateTable in class JdbcAdapterprotected void createTableAppendPKClause(StringBuffer sqlBuffer, DbEntity entity)
createTableAppendPKClause in class JdbcAdapterpublic void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)
createTableAppendColumn in interface DbAdaptercreateTableAppendColumn in class JdbcAdaptersqlBuffer - the StringBuffer to append the column type tocolumn - the DbAttribute defining the column to append type forpublic boolean typeSupportsLength(int type)
JdbcAdaptertypeSupportsLength in interface DbAdaptertypeSupportsLength in class JdbcAdapterpublic String getStorageEngine()
public void setStorageEngine(String engine)
Copyright © 2001–2023 Apache Cayenne. All rights reserved.