Class MySQLAdapter
java.lang.Object
org.apache.cayenne.dba.JdbcAdapter
org.apache.cayenne.dba.mysql.MySQLAdapter
- All Implemented Interfaces:
DbAdapter
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
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.
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
FieldsFields inherited from class JdbcAdapter
caseInsensitiveCollations, ejbqlTranslatorFactory, extendedTypes, logger, quotingStrategy, resourceLocator, supportsBatchUpdates, supportsGeneratedKeys, supportsUniqueConstraints, typesHandlerModifier and TypeFieldDescriptionprotected booleanprotected EJBQLTranslatorFactoryprotected ExtendedTypeMapprotected JdbcEventLoggerprotected QuotingStrategyprotected ResourceLocatorprotected booleanprotected booleanprotected booleanprotected TypesHandler -
Constructor Summary
ConstructorsConstructorDescriptionMySQLAdapter(RuntimeProperties runtimeProperties, List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ResourceLocator resourceLocator, ValueObjectTypeRegistry valueObjectTypeRegistry) -
Method Summary
Modifier and TypeMethodDescriptionvoidbindParameter(PreparedStatement statement, ParameterBinding binding) Binds an object value to PreparedStatement's parameter.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 voidInstalls appropriate ExtendedTypes used as converters for passing values between JDBC and Java layers.protected EJBQLTranslatorFactoryCreates and returns anEJBQLTranslatorFactoryused to generate visitors for EJBQL to SQL translations.protected QuotingStrategycreateTable(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.dropTableStatements(DbEntity table) Returns a collection of SQL statements needed to drop a database table.Uses special action builder to create the right action.voidsetStorageEngine(String engine) booleantypeSupportsLength(int type) Returns true if supplied type can have a length attribute as a part of column definitionMethods inherited from class JdbcAdapter
createFkConstraint, createUniqueConstraint, externalTypesForJdbcType, findResource, getBatchTerminator, getEjbqlTranslatorFactory, getExtendedTypes, getJdbcEventLogger, getPkGenerator, getQuotingStrategy, getSelectTranslator, getSystemSchemas, getType, initExtendedTypes, setEjbqlTranslatorFactory, setPkGenerator, setSupportsBatchUpdates, setSupportsGeneratedKeys, setSupportsUniqueConstraints, sizeAndPrecision, supportsBatchUpdates, supportsCatalogsOnReverseEngineering, supportsGeneratedKeys, supportsUniqueConstraints, tableTypeForTable, tableTypeForView, typeSupportsScale, unwrapModifier and TypeMethodDescriptionReturns a SQL string that can be used to create a foreign key constraint for the relationship.createUniqueConstraint(DbEntity source, Collection<DbAttribute> columns) Returns a DDL string to create a unique constraint over a set of columns.String[]externalTypesForJdbcType(int type) Returns an array of RDBMS types that can be used with JDBCtype.protected URLfindResource(String name) Locates and returns a named adapter resource.Returns default separator - a semicolon.Returns a translator factory for EJBQL to SQL translation.Returns a map of ExtendedTypes that is used to translate values between Java and JDBC layer.Returns primary key generator associated with this DbAdapter.Returns SQL identifier quoting strategy objectgetSelectTranslator(FluentSelect<?, ?> query, EntityResolver entityResolver) static StringgetType(DbAdapter adapter, DbAttribute column) protected voidinitExtendedTypes(List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ValueObjectTypeRegistry valueObjectTypeRegistry) voidsetEjbqlTranslatorFactory(EJBQLTranslatorFactory ejbqlTranslatorFactory) Sets a translator factory for EJBQL to SQL translation.voidsetPkGenerator(PkGenerator pkGenerator) Sets new primary key generator.voidsetSupportsBatchUpdates(boolean flag) voidsetSupportsGeneratedKeys(boolean flag) voidsetSupportsUniqueConstraints(boolean flag) static StringsizeAndPrecision(DbAdapter adapter, DbAttribute column) booleanReturnstrueif the target database supports batch updates.booleanReturns true.booleanReturns true if a target database supports key autogeneration.booleanReturns true.Returns the name of the table type (as returned byDatabaseMetaData.getTableTypes) for a simple user table.Returns the name of the table type (as returned byDatabaseMetaData.getTableTypes) for a view table.booleantypeSupportsScale(int type) Returns true if supplied type can have a scale attribute as a part of column definition.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, waitMethods inherited from interface DbAdapter
supportsGeneratedKeysForBatchInsertsModifier and TypeMethodDescriptiondefault booleanReturns true if a target database supports key autogeneration in a batch insert.
-
Field Details
-
storageEngine
-
-
Constructor Details
-
MySQLAdapter
public MySQLAdapter(RuntimeProperties runtimeProperties, List<ExtendedType> defaultExtendedTypes, List<ExtendedType> userExtendedTypes, List<ExtendedTypeFactory> extendedTypeFactories, ResourceLocator resourceLocator, ValueObjectTypeRegistry valueObjectTypeRegistry)
-
-
Method Details
-
createQuotingStrategy
- Overrides:
createQuotingStrategyin classJdbcAdapter
-
getSqlTreeProcessor
- Specified by:
getSqlTreeProcessorin interfaceDbAdapter- Overrides:
getSqlTreeProcessorin classJdbcAdapter- Returns:
SQLTreeProcessorthat can adjust SQL tree to specific database flavour- Since:
- 4.2
-
getAction
-
dropTableStatements
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
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
-
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
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
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
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
- Specified by:
getSystemCatalogsin interfaceDbAdapter- Overrides:
getSystemCatalogsin classJdbcAdapter- Returns:
- list of system catalogs
-
getStorageEngine
- Since:
- 3.0
-
setStorageEngine
- Since:
- 3.0
-