Package org.apache.cayenne.dba.mysql
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.Foreign Key Constraint Handling
Foreign key constraints are supported by InnoDB engine and NOT supported by MyISAM engine. This adapter by default assumes MyISAM, so
supportsFkConstraintswill be false. Users can manually change this by calling setSupportsFkConstraints(true) or better by using anAutoAdapter, 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.Sample Connection Settings
- Adapter name: org.apache.cayenne.dba.mysql.MySQLAdapter
- DB URL: jdbc:mysql://serverhostname/dbname
- Driver Class: com.mysql.jdbc.Driver
-
-
Field Summary
Fields Modifier and Type Field Description protected StringstorageEngine-
Fields inherited from class org.apache.cayenne.dba.JdbcAdapter
batchQueryBuilderFactory, caseInsensitiveCollations, ejbqlTranslatorFactory, extendedTypes, logger, quotingStrategy, resourceLocator, supportsBatchUpdates, supportsGeneratedKeys, supportsUniqueConstraints, typesHandler
-
-
Constructor Summary
Constructors Constructor Description MySQLAdapter(RuntimeProperties runtimeProperties, List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ResourceLocator resourceLocator, ValueObjectTypeRegistry valueObjectTypeRegistry)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbindParameter(PreparedStatement statement, ParameterBinding binding)Binds an object value to PreparedStatement's parameter.DbAttributebuildAttribute(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 voidconfigureExtendedTypes(ExtendedTypeMap map)Installs appropriate ExtendedTypes used as converters for passing values between JDBC and Java layers.protected EJBQLTranslatorFactorycreateEJBQLTranslatorFactory()Creates and returns anEJBQLTranslatorFactoryused to generate visitors for EJBQL to SQL translations.protected PkGeneratorcreatePkGenerator()Creates and returns a primary key generator.protected QuotingStrategycreateQuotingStrategy()StringcreateTable(DbEntity entity)Overrides super implementation to explicitly set table engine to InnoDB if FK constraints are supported by this adapter.voidcreateTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)Appends AUTO_INCREMENT clause to the column definition for generated columns.protected voidcreateTableAppendPKClause(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.SQLActiongetAction(Query query, DataNode node)Uses special action builder to create the right action.QualifierTranslatorgetQualifierTranslator(QueryAssembler queryAssembler)Creates and returns a default implementation of a qualifier translator.SelectTranslatorgetSelectTranslator(SelectQuery<?> query, EntityResolver entityResolver)Returns a SelectTranslator that works with the adapter target database.StringgetStorageEngine()List<String>getSystemCatalogs()voidsetStorageEngine(String engine)booleantypeSupportsLength(int type)Returns true if supplied type can have a length attribute as a part of column definition-
Methods inherited from class org.apache.cayenne.dba.JdbcAdapter
createFkConstraint, createUniqueConstraint, externalTypesForJdbcType, findResource, getBatchTerminator, getEjbqlTranslatorFactory, getExtendedTypes, getJdbcEventLogger, getPkGenerator, getQuotingStrategy, getSystemSchemas, getType, initExtendedTypes, setEjbqlTranslatorFactory, setPkGenerator, setSupportsBatchUpdates, setSupportsGeneratedKeys, setSupportsUniqueConstraints, sizeAndPrecision, supportsBatchUpdates, supportsCatalogsOnReverseEngineering, supportsGeneratedKeys, supportsUniqueConstraints, tableTypeForTable, tableTypeForView, unwrap
-
-
-
-
Field Detail
-
storageEngine
protected String storageEngine
-
-
Constructor Detail
-
MySQLAdapter
public MySQLAdapter(RuntimeProperties runtimeProperties, List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ResourceLocator resourceLocator, ValueObjectTypeRegistry valueObjectTypeRegistry)
-
-
Method Detail
-
createQuotingStrategy
protected QuotingStrategy createQuotingStrategy()
- Overrides:
createQuotingStrategyin classJdbcAdapter
-
getSelectTranslator
public SelectTranslator getSelectTranslator(SelectQuery<?> query, EntityResolver entityResolver)
Description copied from interface:DbAdapterReturns a SelectTranslator that works with the adapter target database.- Specified by:
getSelectTranslatorin interfaceDbAdapter- Overrides:
getSelectTranslatorin classJdbcAdapter
-
getQualifierTranslator
public QualifierTranslator getQualifierTranslator(QueryAssembler queryAssembler)
Description copied from class:JdbcAdapterCreates and returns a default implementation of a qualifier translator.- Specified by:
getQualifierTranslatorin interfaceDbAdapter- Overrides:
getQualifierTranslatorin classJdbcAdapter
-
getAction
public SQLAction getAction(Query query, DataNode node)
Uses special action builder to create the right action.- Specified by:
getActionin interfaceDbAdapter- Overrides:
getActionin classJdbcAdapter- Since:
- 1.2
-
dropTableStatements
public Collection<String> dropTableStatements(DbEntity table)
Description copied from interface:DbAdapterReturns a collection of SQL statements needed to drop a database table.- Specified by:
dropTableStatementsin interfaceDbAdapter- Overrides:
dropTableStatementsin classJdbcAdapter- Since:
- 3.0
-
configureExtendedTypes
protected void configureExtendedTypes(ExtendedTypeMap map)
Installs appropriate ExtendedTypes used as converters for passing values between JDBC and Java layers.- Overrides:
configureExtendedTypesin classJdbcAdapter
-
buildAttribute
public DbAttribute buildAttribute(String name, String typeName, int type, int size, int precision, boolean allowNulls)
Description copied from interface:DbAdapterCreates and returns a DbAttribute based on supplied parameters (usually obtained from database meta data).- Specified by:
buildAttributein interfaceDbAdapter- Overrides:
buildAttributein classJdbcAdapter- Parameters:
name- 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 parameter
-
bindParameter
public void bindParameter(PreparedStatement statement, ParameterBinding binding) throws SQLException, Exception
Description copied from interface:DbAdapterBinds an object value to PreparedStatement's parameter.- Specified by:
bindParameterin interfaceDbAdapter- Overrides:
bindParameterin classJdbcAdapter- Throws:
SQLExceptionException
-
createPkGenerator
protected PkGenerator createPkGenerator()
Creates and returns a primary key generator. Overrides superclass implementation to return an instance of MySQLPkGenerator that does the correct table locking.- Overrides:
createPkGeneratorin classJdbcAdapter
-
createEJBQLTranslatorFactory
protected EJBQLTranslatorFactory createEJBQLTranslatorFactory()
Description copied from class:JdbcAdapterCreates and returns anEJBQLTranslatorFactoryused to generate visitors for EJBQL to SQL translations. This method should be overriden by subclasses that need to customize EJBQL generation.- Overrides:
createEJBQLTranslatorFactoryin classJdbcAdapter- 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:
createTablein interfaceDbAdapter- Overrides:
createTablein classJdbcAdapter
-
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:
createTableAppendPKClausein classJdbcAdapter- Since:
- 1.2
-
createTableAppendColumn
public void createTableAppendColumn(StringBuffer sqlBuffer, DbAttribute column)
Appends AUTO_INCREMENT clause to the column definition for generated columns.- Specified by:
createTableAppendColumnin interfaceDbAdapter- Overrides:
createTableAppendColumnin classJdbcAdapter- Parameters:
sqlBuffer- theStringBufferto append the column type tocolumn- theDbAttributedefining the column to append type for
-
typeSupportsLength
public boolean typeSupportsLength(int type)
Description copied from class:JdbcAdapterReturns true if supplied type can have a length attribute as a part of column definition- Specified by:
typeSupportsLengthin interfaceDbAdapter- Overrides:
typeSupportsLengthin classJdbcAdapter
-
getSystemCatalogs
public List<String> getSystemCatalogs()
- Specified by:
getSystemCatalogsin interfaceDbAdapter- Overrides:
getSystemCatalogsin classJdbcAdapter- Returns:
- list of system catalogs
-
getStorageEngine
public String getStorageEngine()
- Since:
- 3.0
-
setStorageEngine
public void setStorageEngine(String engine)
- Since:
- 3.0
-
-