Package liquibase.database.core
Class MySQLDatabase
- java.lang.Object
-
- liquibase.database.AbstractJdbcDatabase
-
- liquibase.database.core.MySQLDatabase
-
- All Implemented Interfaces:
AutoCloseable
,Database
,PrioritizedService
- Direct Known Subclasses:
MariaDBDatabase
public class MySQLDatabase extends AbstractJdbcDatabase
Encapsulates MySQL database support.
-
-
Field Summary
Fields Modifier and Type Field Description static Pattern
PRECISION_PATTERN
-
Fields inherited from class liquibase.database.AbstractJdbcDatabase
caseSensitive, currentDateTimeFunction, dateFunctions, defaultAutoIncrementBy, defaultAutoIncrementStartWith, defaultCatalogName, defaultSchemaName, quotingStrategy, sequenceCurrentValueFunction, sequenceNextValueFunction, unmodifiableDataTypes, unquotedObjectsAreUppercased
-
Fields inherited from interface liquibase.database.Database
COMPLETE_SQL_SCOPE_KEY
-
Fields inherited from interface liquibase.servicelocator.PrioritizedService
COMPARATOR, PRIORITY_DATABASE, PRIORITY_DEFAULT
-
-
Constructor Summary
Constructors Constructor Description MySQLDatabase()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
correctObjectName(String name, Class<? extends DatabaseObject> objectType)
Fix the object name to the format the database expects, handling changes in case, etc.boolean
createsIndexesForForeignKeys()
boolean
disableForeignKeyChecks()
void
enableForeignKeyChecks()
String
escapeIndexName(String catalogName, String schemaName, String indexName)
String
escapeStringForDatabase(String string)
protected boolean
generateAutoIncrementBy(BigInteger incrementBy)
protected boolean
generateAutoIncrementStartWith(BigInteger startWith)
String
generateDatabaseFunctionValue(DatabaseFunction databaseFunction)
Some function names are placeholders that need to be replaced with the specific database value.protected String
getAutoIncrementClause()
protected String
getAutoIncrementClosing()
protected String
getAutoIncrementOpening()
protected String
getAutoIncrementStartWithClause()
String
getConcatSql(String... values)
Returns SQL to concat the passed values.protected String
getCurrentDateTimeFunction(int precision)
int
getDatabasePatchVersion()
protected String
getDefaultDatabaseProductName()
String
getDefaultDriver(String url)
If this database understands the given url, return the default driver class name.int
getDefaultFractionalDigitsForTimestamp()
Returns the default timestamp fractional digits if nothing is specified.Integer
getDefaultPort()
String
getLineComment()
Returns database-specific line comment string.int
getMaxFractionalDigitsForTimestamp()
Most relational databases support 9 fractional digits, and subclasses must overwrite this method if they support less than that.protected String
getMinimumVersionForFractionalDigitsForTimestamp()
int
getPriority()
protected String
getQuotingEndCharacter()
protected String
getQuotingStartCharacter()
CatalogAndSchema
getSchemaFromJdbcInfo(String rawCatalogName, String rawSchemaName)
String
getShortName()
Returns an all-lower-case short name of the product.String
getTableOptionAutoIncrementStartWithClause(BigInteger startWith)
boolean
isCorrectDatabaseImplementation(DatabaseConnection conn)
Is this AbstractDatabase subclass the correct one to use for the given connection.boolean
isMinimumMySQLVersion(String minimumVersion)
Checks whether this instance of a MySQL database is equal to or greater than the specified version.boolean
isReservedWord(String string)
protected boolean
mustQuoteObjectName(String objectName, Class<? extends DatabaseObject> objectType)
boolean
supportsCatalogs()
boolean
supportsCreateIfNotExists(Class<? extends DatabaseObject> type)
Does the database support the "if not exits" syntax?boolean
supportsDatabaseChangeLogHistory()
Does the particular database implementation support the database changelog history feature and associated table?boolean
supportsForeignKeyDisable()
boolean
supportsInitiallyDeferrableColumns()
Returns whether this database support initially deferrable columns.boolean
supportsSchemas()
boolean
supportsSequences()
Does the database type support sequence.boolean
supportsTablespaces()
void
warnAboutAlterColumn(String changeName, Warnings warnings)
-
Methods inherited from class liquibase.database.AbstractJdbcDatabase
addReservedWords, canCreateChangeLogTable, close, commit, correctSchema, correctSchema, dataTypeIsNotModifiable, doesTagExist, dropDatabaseObjects, equals, escapeColumnName, escapeColumnName, escapeColumnNameList, escapeConstraintName, escapeDataTypeName, escapeObjectName, escapeObjectName, escapeSequenceName, escapeTableName, escapeViewName, execute, executeRollbackStatements, executeRollbackStatements, executeStatements, filterRollbackVisitors, generatePrimaryKeyName, get, getAutoCommitMode, getAutoIncrementByClause, getAutoIncrementClause, getAutoIncrementClause, getConnection, getConnectionCatalogName, getConnectionSchemaName, getConnectionSchemaNameCallStatement, getContainingObjects, getCurrentDateTimeFunction, getDatabaseChangeLogLockTableName, getDatabaseChangeLogTableName, getDatabaseMajorVersion, getDatabaseMinorVersion, getDatabaseProductName, getDatabaseProductVersion, getDataTypeMaxParameters, getDateFunctions, getDateLiteral, getDateLiteral, getDateLiteral, getDateTimeLiteral, getDefaultCatalogName, getDefaultScaleForNativeDataType, getDefaultSchema, getDefaultSchemaName, getFetchSize, getJdbcCatalogName, getJdbcCatalogName, getJdbcSchemaName, getJdbcSchemaName, getLiquibaseCatalogName, getLiquibaseSchemaName, getLiquibaseTablespaceName, getName, getObjectQuotingStrategy, getOutputDefaultCatalog, getOutputDefaultSchema, getQuotingEndReplacement, getRanChangeSet, getRanChangeSetList, getRanDate, getRawDatabaseChangeLogLockTableName, getRawDatabaseChangeLogTableName, getRunStatus, getSchemaAndCatalogCase, getSystemSchema, getSystemTables, getSystemViews, getTimeLiteral, getViewDefinition, hashCode, isAutoCommit, isCaseSensitive, isCatalogOrSchemaType, isCurrentTimeFunction, isDateOnly, isDateTime, isDefaultCatalog, isDefaultSchema, isFunction, isLiquibaseObject, isSafeToRunUpdate, isSystemObject, isSystemView, isTimeOnly, isTimestamp, jdbcCallsCatalogsSchemas, markChangeSetExecStatus, parseDate, quoteObject, removeRanStatus, requiresExplicitNullForColumns, requiresPassword, requiresUsername, resetInternalState, rollback, saveRollbackStatement, saveStatements, set, setAutoCommit, setCanCacheLiquibaseTableInfo, setCaseSensitive, setConnection, setCurrentDateTimeFunction, setDatabaseChangeLogLockTableName, setDatabaseChangeLogTableName, setDefaultCatalogName, setDefaultSchemaName, setLiquibaseCatalogName, setLiquibaseSchemaName, setLiquibaseTablespaceName, setObjectQuotingStrategy, setOutputDefaultCatalog, setOutputDefaultSchema, startsWithNumeric, supportsAutoIncrement, supportsBatchUpdates, supportsCatalogInObjectName, supportsDDLInTransaction, supportsDropTableCascadeConstraints, supportsNotNullConstraintNames, supportsPrimaryKeyNames, supportsRestrictForeignKeys, tag, toString, unescapeDataTypeName, unescapeDataTypeString, validate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface liquibase.database.Database
addCompleteSqlToScope, afterUpdate, dropDatabaseObjects, failOnDefferable, getDisplayName, temporarilySetObjectQuotingStrategy
-
-
-
-
Field Detail
-
PRECISION_PATTERN
public static final Pattern PRECISION_PATTERN
-
-
Method Detail
-
getShortName
public String getShortName()
Description copied from interface:Database
Returns an all-lower-case short name of the product. Used for end-user selecting of database type such as the DBMS precondition.
-
correctObjectName
public String correctObjectName(String name, Class<? extends DatabaseObject> objectType)
Description copied from interface:Database
Fix the object name to the format the database expects, handling changes in case, etc.- Specified by:
correctObjectName
in interfaceDatabase
- Overrides:
correctObjectName
in classAbstractJdbcDatabase
-
getDefaultDatabaseProductName
protected String getDefaultDatabaseProductName()
- Specified by:
getDefaultDatabaseProductName
in classAbstractJdbcDatabase
-
getDefaultPort
public Integer getDefaultPort()
-
getPriority
public int getPriority()
-
isCorrectDatabaseImplementation
public boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException
Description copied from interface:Database
Is this AbstractDatabase subclass the correct one to use for the given connection.- Throws:
DatabaseException
-
getDefaultDriver
public String getDefaultDriver(String url)
Description copied from interface:Database
If this database understands the given url, return the default driver class name. Otherwise return null.
-
supportsSequences
public boolean supportsSequences()
Description copied from class:AbstractJdbcDatabase
Does the database type support sequence.- Specified by:
supportsSequences
in interfaceDatabase
- Overrides:
supportsSequences
in classAbstractJdbcDatabase
-
supportsInitiallyDeferrableColumns
public boolean supportsInitiallyDeferrableColumns()
Description copied from interface:Database
Returns whether this database support initially deferrable columns.
-
mustQuoteObjectName
protected boolean mustQuoteObjectName(String objectName, Class<? extends DatabaseObject> objectType)
- Overrides:
mustQuoteObjectName
in classAbstractJdbcDatabase
-
getLineComment
public String getLineComment()
Description copied from class:AbstractJdbcDatabase
Returns database-specific line comment string.- Specified by:
getLineComment
in interfaceDatabase
- Overrides:
getLineComment
in classAbstractJdbcDatabase
-
getAutoIncrementClause
protected String getAutoIncrementClause()
- Overrides:
getAutoIncrementClause
in classAbstractJdbcDatabase
-
generateAutoIncrementStartWith
protected boolean generateAutoIncrementStartWith(BigInteger startWith)
- Overrides:
generateAutoIncrementStartWith
in classAbstractJdbcDatabase
-
getTableOptionAutoIncrementStartWithClause
public String getTableOptionAutoIncrementStartWithClause(BigInteger startWith)
-
generateAutoIncrementBy
protected boolean generateAutoIncrementBy(BigInteger incrementBy)
- Overrides:
generateAutoIncrementBy
in classAbstractJdbcDatabase
-
getAutoIncrementOpening
protected String getAutoIncrementOpening()
- Overrides:
getAutoIncrementOpening
in classAbstractJdbcDatabase
-
getAutoIncrementClosing
protected String getAutoIncrementClosing()
- Overrides:
getAutoIncrementClosing
in classAbstractJdbcDatabase
-
getAutoIncrementStartWithClause
protected String getAutoIncrementStartWithClause()
- Overrides:
getAutoIncrementStartWithClause
in classAbstractJdbcDatabase
-
getConcatSql
public String getConcatSql(String... values)
Description copied from interface:Database
Returns SQL to concat the passed values.- Specified by:
getConcatSql
in interfaceDatabase
- Overrides:
getConcatSql
in classAbstractJdbcDatabase
-
supportsTablespaces
public boolean supportsTablespaces()
-
supportsSchemas
public boolean supportsSchemas()
- Specified by:
supportsSchemas
in interfaceDatabase
- Overrides:
supportsSchemas
in classAbstractJdbcDatabase
-
supportsCatalogs
public boolean supportsCatalogs()
- Specified by:
supportsCatalogs
in interfaceDatabase
- Overrides:
supportsCatalogs
in classAbstractJdbcDatabase
-
escapeIndexName
public String escapeIndexName(String catalogName, String schemaName, String indexName)
- Specified by:
escapeIndexName
in interfaceDatabase
- Overrides:
escapeIndexName
in classAbstractJdbcDatabase
-
supportsForeignKeyDisable
public boolean supportsForeignKeyDisable()
- Specified by:
supportsForeignKeyDisable
in interfaceDatabase
- Overrides:
supportsForeignKeyDisable
in classAbstractJdbcDatabase
-
disableForeignKeyChecks
public boolean disableForeignKeyChecks() throws DatabaseException
- Specified by:
disableForeignKeyChecks
in interfaceDatabase
- Overrides:
disableForeignKeyChecks
in classAbstractJdbcDatabase
- Throws:
DatabaseException
-
enableForeignKeyChecks
public void enableForeignKeyChecks() throws DatabaseException
- Specified by:
enableForeignKeyChecks
in interfaceDatabase
- Overrides:
enableForeignKeyChecks
in classAbstractJdbcDatabase
- Throws:
DatabaseException
-
getSchemaFromJdbcInfo
public CatalogAndSchema getSchemaFromJdbcInfo(String rawCatalogName, String rawSchemaName)
- Overrides:
getSchemaFromJdbcInfo
in classAbstractJdbcDatabase
-
escapeStringForDatabase
public String escapeStringForDatabase(String string)
- Specified by:
escapeStringForDatabase
in interfaceDatabase
- Overrides:
escapeStringForDatabase
in classAbstractJdbcDatabase
-
createsIndexesForForeignKeys
public boolean createsIndexesForForeignKeys()
- Specified by:
createsIndexesForForeignKeys
in interfaceDatabase
- Overrides:
createsIndexesForForeignKeys
in classAbstractJdbcDatabase
-
isReservedWord
public boolean isReservedWord(String string)
- Specified by:
isReservedWord
in interfaceDatabase
- Overrides:
isReservedWord
in classAbstractJdbcDatabase
-
getDatabasePatchVersion
public int getDatabasePatchVersion() throws DatabaseException
- Throws:
DatabaseException
-
getMaxFractionalDigitsForTimestamp
public int getMaxFractionalDigitsForTimestamp()
Description copied from class:AbstractJdbcDatabase
Most relational databases support 9 fractional digits, and subclasses must overwrite this method if they support less than that.- Specified by:
getMaxFractionalDigitsForTimestamp
in interfaceDatabase
- Overrides:
getMaxFractionalDigitsForTimestamp
in classAbstractJdbcDatabase
- Returns:
- the maximum number of supported fractional digits in TIMESTAMP columns
-
isMinimumMySQLVersion
public boolean isMinimumMySQLVersion(String minimumVersion)
Checks whether this instance of a MySQL database is equal to or greater than the specified version.- Parameters:
minimumVersion
- the minimum version to check- Returns:
true
if this instance of a MySQL database is equal to or greater than the specified version,false
otherwise
-
getMinimumVersionForFractionalDigitsForTimestamp
protected String getMinimumVersionForFractionalDigitsForTimestamp()
-
getQuotingStartCharacter
protected String getQuotingStartCharacter()
- Overrides:
getQuotingStartCharacter
in classAbstractJdbcDatabase
-
getQuotingEndCharacter
protected String getQuotingEndCharacter()
- Overrides:
getQuotingEndCharacter
in classAbstractJdbcDatabase
-
getDefaultFractionalDigitsForTimestamp
public int getDefaultFractionalDigitsForTimestamp()
Returns the default timestamp fractional digits if nothing is specified.
fractional seconds: "The fsp value, if given, must be in the range 0 to 6. A value of 0 signifies that there is no fractional part. If omitted, the default precision is 0. (This differs from the STANDARD SQL default of 6, for compatibility with previous MySQL versions.)"- Specified by:
getDefaultFractionalDigitsForTimestamp
in interfaceDatabase
- Overrides:
getDefaultFractionalDigitsForTimestamp
in classAbstractJdbcDatabase
- Returns:
- always 0
-
getCurrentDateTimeFunction
protected String getCurrentDateTimeFunction(int precision)
-
generateDatabaseFunctionValue
public String generateDatabaseFunctionValue(DatabaseFunction databaseFunction)
Description copied from interface:Database
Some function names are placeholders that need to be replaced with the specific database value. e.g. nextSequenceValue(sequenceName) should be replaced with NEXT_VAL('sequenceName') for Postgresql- Specified by:
generateDatabaseFunctionValue
in interfaceDatabase
- Overrides:
generateDatabaseFunctionValue
in classAbstractJdbcDatabase
- Parameters:
databaseFunction
- database function to check.- Returns:
- the string value to use for an update or generate
-
supportsCreateIfNotExists
public boolean supportsCreateIfNotExists(Class<? extends DatabaseObject> type)
Description copied from interface:Database
Does the database support the "if not exits" syntax?- Parameters:
type
- the DatabaseObject type to be checked.- Returns:
- true if the "if not exists" syntax is supported, false otherwise.
-
supportsDatabaseChangeLogHistory
public boolean supportsDatabaseChangeLogHistory()
Description copied from interface:Database
Does the particular database implementation support the database changelog history feature and associated table?- Returns:
- true if supported, false otherwise
-
-