Package liquibase.database
Interface Database
- All Superinterfaces:
AutoCloseable
,PrioritizedService
- All Known Implementing Classes:
AbstractDb2Database
,AbstractJdbcDatabase
,CockroachDatabase
,DB2Database
,Db2zDatabase
,DerbyDatabase
,EnterpriseDBDatabase
,FirebirdDatabase
,H2Database
,HsqlDatabase
,InformixDatabase
,Ingres9Database
,MariaDBDatabase
,MockDatabase
,MSSQLDatabase
,MySQLDatabase
,OracleDatabase
,PostgresDatabase
,SnowflakeDatabase
,SQLiteDatabase
,SybaseASADatabase
,SybaseDatabase
,UnsupportedDatabase
Interface that every DBMS supported by this software must implement. Most methods belong into ont of these
categories:
Information about the capabilities of the DBMS (e.g. can it work with catalogs? with schemas?)
changing and manipulating types defined in the SQL standard into native types and vice-versa
creating strings for use in SQL statements, e.g. literals for dates, time, numerals, etc.
-
Field Summary
Fields inherited from interface liquibase.servicelocator.PrioritizedService
COMPARATOR, PRIORITY_DATABASE, PRIORITY_DEFAULT
-
Method Summary
Modifier and TypeMethodDescriptiondefault void
addCompleteSqlToScope
(String completeSql) void
addReservedWords
(Collection<String> words) default void
Allows the database to perform actions after an update is finished, i.e. after the last change of a changelog was applied.default void
Some databases (such as MongoDB) require you to verify the connection to the database to ensure that the database is accessible.void
close()
void
commit()
correctObjectName
(String name, Class<? extends DatabaseObject> objectType) Fix the object name to the format the database expects, handling changes in case, etc.correctSchema
(CatalogAndSchema schema) Deprecated.boolean
boolean
dataTypeIsNotModifiable
(String typeName) Types like int4 in postgres cannot have a modifier. e.g. int4(10) Checks whether the type is allowed to have a modifierboolean
boolean
doesTagExist
(String tag) Deprecated.UseChangeLogHistoryService.tagExists(String)
insteadvoid
dropDatabaseObjects
(CatalogAndSchema schema) Drops all objects in a specified schema.default void
dropDatabaseObjects
(CatalogAndSchema schemaToDrop, SnapshotControl snapshotControl) void
escapeColumnName
(String catalogName, String schemaName, String tableName, String columnName) Escapes a single column name in a database-dependent manner so reserved words can be used as a column name (i.e.escapeColumnName
(String catalogName, String schemaName, String tableName, String columnName, boolean quoteNamesThatMayBeFunctions) Deprecated.Know if you should quote the name or not, and useescapeColumnName(String, String, String, String)
which will quote things that look like functions, or leave it along as you see fit.escapeColumnNameList
(String columnNames) Escapes a list of column names in a database-dependent manner so reserved words can be used as a column name (i.e.escapeConstraintName
(String constraintName) escapeDataTypeName
(String dataTypeName) escapeIndexName
(String catalogName, String schemaName, String indexName) escapeObjectName
(String objectName, Class<? extends DatabaseObject> objectType) escapeObjectName
(String catalogName, String schemaName, String objectName, Class<? extends DatabaseObject> objectType) escapeSequenceName
(String catalogName, String schemaName, String sequenceName) escapeStringForDatabase
(String string) escapeTableName
(String catalogName, String schemaName, String tableName) escapeViewName
(String catalogName, String schemaName, String viewName) void
execute
(SqlStatement[] statements, List<SqlVisitor> sqlVisitors) void
executeRollbackStatements
(Change change, List<SqlVisitor> sqlVisitors) void
executeRollbackStatements
(SqlStatement[] statements, List<SqlVisitor> sqlVisitors) void
executeStatements
(Change change, DatabaseChangeLog changeLog, List<SqlVisitor> sqlVisitors) default boolean
default String
Returns a custom message to be displayed upon successful execution of the connect command.generateDatabaseFunctionValue
(DatabaseFunction databaseFunction) Some function names are placeholders that need to be replaced with the specific database value.generatePrimaryKeyName
(String tableName) boolean
Auto-commit mode to run ingetAutoIncrementClause
(BigInteger startWith, BigInteger incrementBy, String generationType, Boolean defaultOnNull) Returns database-specific auto-increment DDL clause.getConcatSql
(String... values) Returns SQL to concat the passed values.Returns database-specific function for generating the current date/time.int
int
Returns the name of the database product according to the underlying database.int
getDataTypeMaxParameters
(String dataTypeName) Returns list of database native date functionsgetDateLiteral
(String isoDate) getDateLiteral
(Date date) getDateLiteral
(Date defaultDateValue) getDateTimeLiteral
(Timestamp timeStamp) getDefaultDriver
(String url) If this database understands the given url, return the default driver class name.int
When a TIMESTAMP column without the parameter "number of fractional digits" is created, what is the default value?getDefaultScaleForNativeDataType
(String nativeDataType) Returns the default precision for a given native data type, e.g.default String
int
Determines the maximum precision (number of fractional digits) for TIMESTAMP columns for the given database.boolean
boolean
Should the schema be included in identifiers even if it is the default schema?getRanChangeSet
(ChangeSet changeSet) Returns the ChangeSets that have been run against the current database.getRanDate
(ChangeSet changeSet) getRunStatus
(ChangeSet changeSet) Returns the run status for the given ChangeSetReturns an all-lower-case short name of the product.getTimeLiteral
(Time time) getViewDefinition
(CatalogAndSchema schema, String name) boolean
boolean
boolean
Is this AbstractDatabase subclass the correct one to use for the given connection.boolean
isDefaultCatalog
(String catalog) If the database supports catalogs, test if a given catalog name equals to the default catalog of the current logged in user.boolean
isDefaultSchema
(String catalog, String schema) If the database supports schemas, test if a given combination of catalog and schema name equals to the default catalog and schema of the current logged in user.boolean
isFunction
(String string) boolean
isLiquibaseObject
(DatabaseObject object) boolean
isReservedWord
(String string) boolean
boolean
isSystemObject
(DatabaseObject example) void
markChangeSetExecStatus
(ChangeSet changeSet, ChangeSet.ExecType execType) After the changeset has been run against the database this method will update the change log table with the information.void
removeRanStatus
(ChangeSet changeSet) boolean
Does the database require explicit NULL for nullable columns?boolean
boolean
void
void
rollback()
void
saveRollbackStatement
(Change change, List<SqlVisitor> sqlVisitors, Writer writer) void
saveStatements
(Change change, List<SqlVisitor> sqlVisitors, Writer writer) void
setAutoCommit
(boolean b) void
setCanCacheLiquibaseTableInfo
(boolean canCacheLiquibaseTableInfo) void
void
setCurrentDateTimeFunction
(String function) void
setDatabaseChangeLogLockTableName
(String tableName) Set the table name of the change log lock to the given table namevoid
setDatabaseChangeLogTableName
(String tableName) Sets the table name of the change log to the given table name.void
setDefaultCatalogName
(String catalogName) void
setDefaultSchemaName
(String schemaName) void
setLiquibaseCatalogName
(String catalogName) void
setLiquibaseSchemaName
(String schemaName) void
setLiquibaseTablespaceName
(String tablespaceName) void
setObjectQuotingStrategy
(ObjectQuotingStrategy quotingStrategy) void
setOutputDefaultCatalog
(boolean outputDefaultCatalog) void
setOutputDefaultSchema
(boolean outputDefaultSchema) Whether the default schema should be included in generated SQLdefault boolean
supports
(Class<? extends DatabaseObject> object) Whether this database supports the specified object type.boolean
boolean
Does the database support batched DML (INSERT/UPDATE/DELETE/MERGE/...) statements sent in a single call to the database?boolean
supportsCatalogInObjectName
(Class<? extends DatabaseObject> type) boolean
Deprecated.please callsupports(Class)
with theCatalog
type insteaddefault boolean
supportsCreateIfNotExists
(Class<? extends DatabaseObject> type) Does the database support the "if not exits" syntax?default boolean
Does the particular database implementation support the database changelog history feature and associated table?boolean
Determines if the database supports DDL within a transaction or not.boolean
boolean
boolean
Returns whether this database support initially deferrable columns.boolean
Does this database treat NOT NULL as an own kind of CONSTRAINT (in addition of simply being a column property)?boolean
boolean
boolean
Deprecated.please callsupports(Class)
with theSchema
type insteadboolean
Deprecated.please callsupports(Class)
with theSequence
type insteadboolean
void
Deprecated.UseChangeLogHistoryService.tag(String)
insteaddefault TempObjectQuotingStrategy
temporarilySetObjectQuotingStrategy
(ObjectQuotingStrategy objectQuotingStrategy) Temporarily set the database's object quoting strategy.unescapeDataTypeName
(String dataTypeName) unescapeDataTypeString
(String dataTypeString) validate()
Methods inherited from interface liquibase.servicelocator.PrioritizedService
getPriority
-
Field Details
-
databaseChangeLogTableName
-
databaseChangeLogLockTableName
-
COMPLETE_SQL_SCOPE_KEY
- See Also:
-
-
Method Details
-
isCorrectDatabaseImplementation
Is this AbstractDatabase subclass the correct one to use for the given connection.- Throws:
DatabaseException
-
getDefaultDriver
If this database understands the given url, return the default driver class name. Otherwise return null. -
getConnection
DatabaseConnection getConnection() -
setConnection
-
requiresUsername
boolean requiresUsername() -
requiresPassword
boolean requiresPassword() -
getAutoCommitMode
boolean getAutoCommitMode()Auto-commit mode to run in -
supportsDDLInTransaction
boolean supportsDDLInTransaction()Determines if the database supports DDL within a transaction or not.- Returns:
- True if the database supports DDL within a transaction, otherwise false.
-
getDatabaseProductName
String getDatabaseProductName()Returns the name of the database product according to the underlying database. -
getDatabaseProductVersion
- Throws:
DatabaseException
-
getDatabaseMajorVersion
- Throws:
DatabaseException
-
getDatabaseMinorVersion
- Throws:
DatabaseException
-
getShortName
String getShortName()Returns an all-lower-case short name of the product. Used for end-user selecting of database type such as the DBMS precondition. -
getDisplayName
- Returns:
- a properly formatted name of the product. Used for situations where the database is printed to the console. Example: "Snowflake" (note the capitalization)
-
getDefaultCatalogName
String getDefaultCatalogName() -
setDefaultCatalogName
- Throws:
DatabaseException
-
getDefaultSchemaName
String getDefaultSchemaName() -
getDefaultScaleForNativeDataType
Returns the default precision for a given native data type, e.g. "datetime2" for Microsoft SQL Server.- Parameters:
nativeDataType
- the name of the native data type (case-insensitive).- Returns:
- The default precision of the native data type, or null if the type is unknown to this database.
-
setDefaultSchemaName
- Throws:
DatabaseException
-
getDefaultPort
Integer getDefaultPort() -
getFetchSize
Integer getFetchSize() -
getLiquibaseCatalogName
String getLiquibaseCatalogName() -
setLiquibaseCatalogName
-
getLiquibaseSchemaName
String getLiquibaseSchemaName() -
setLiquibaseSchemaName
-
supportsInitiallyDeferrableColumns
boolean supportsInitiallyDeferrableColumns()Returns whether this database support initially deferrable columns. -
supportsSequences
Deprecated.please callsupports(Class)
with theSequence
type insteadWhether this database supports sequences -
supportsDropTableCascadeConstraints
boolean supportsDropTableCascadeConstraints() -
supportsAutoIncrement
boolean supportsAutoIncrement() -
getDateLiteral
-
getCurrentDateTimeFunction
String getCurrentDateTimeFunction()Returns database-specific function for generating the current date/time. -
setCurrentDateTimeFunction
-
getLineComment
String getLineComment() -
getAutoIncrementClause
String getAutoIncrementClause(BigInteger startWith, BigInteger incrementBy, String generationType, Boolean defaultOnNull) Returns database-specific auto-increment DDL clause. -
getDatabaseChangeLogTableName
String getDatabaseChangeLogTableName() -
setDatabaseChangeLogTableName
Sets the table name of the change log to the given table name.- Parameters:
tableName
- the name of the change log table to set
-
getDatabaseChangeLogLockTableName
String getDatabaseChangeLogLockTableName() -
setDatabaseChangeLogLockTableName
Set the table name of the change log lock to the given table name- Parameters:
tableName
-
-
getLiquibaseTablespaceName
String getLiquibaseTablespaceName() -
setLiquibaseTablespaceName
-
getConcatSql
Returns SQL to concat the passed values. -
setCanCacheLiquibaseTableInfo
void setCanCacheLiquibaseTableInfo(boolean canCacheLiquibaseTableInfo) -
dropDatabaseObjects
Drops all objects in a specified schema.- Parameters:
schema
- schema (catalog+)schema to drop- Throws:
LiquibaseException
- if any problem occurs
-
dropDatabaseObjects
default void dropDatabaseObjects(CatalogAndSchema schemaToDrop, SnapshotControl snapshotControl) throws LiquibaseException - Throws:
LiquibaseException
-
addCompleteSqlToScope
-
tag
Deprecated.UseChangeLogHistoryService.tag(String)
insteadTags the database changelog with the given string.- Throws:
DatabaseException
-
doesTagExist
Deprecated.UseChangeLogHistoryService.tagExists(String)
instead- Throws:
DatabaseException
-
isSystemObject
-
isLiquibaseObject
-
getViewDefinition
- Throws:
DatabaseException
-
getDateLiteral
-
getTimeLiteral
-
getDateTimeLiteral
-
getDateLiteral
-
escapeObjectName
-
escapeTableName
-
escapeIndexName
-
escapeObjectName
-
getMaxFractionalDigitsForTimestamp
int getMaxFractionalDigitsForTimestamp()Determines the maximum precision (number of fractional digits) for TIMESTAMP columns for the given database. Might not always be able to give an exact answer since, for some DBMS, it depends on the actual software version if fractional digits are supported. A warning should be logged in this case.- Returns:
- the number of allowed fractional digits for TIMESTAMP columns. May return 0.
-
getDefaultFractionalDigitsForTimestamp
int getDefaultFractionalDigitsForTimestamp()When a TIMESTAMP column without the parameter "number of fractional digits" is created, what is the default value?- Returns:
- The default number of fractional digits for TIMESTAMP columns
-
escapeColumnName
Escapes a single column name in a database-dependent manner so reserved words can be used as a column name (i.e. "return").- Parameters:
schemaName
-tableName
-columnName
- column name- Returns:
- escaped column name
-
escapeColumnName
@Deprecated String escapeColumnName(String catalogName, String schemaName, String tableName, String columnName, boolean quoteNamesThatMayBeFunctions) Deprecated.Know if you should quote the name or not, and useescapeColumnName(String, String, String, String)
which will quote things that look like functions, or leave it along as you see fit. Don't rely on this function guessing.Similar toescapeColumnName(String, String, String, String)
but allows control over whether function-like names should be left unquoted. -
escapeColumnNameList
Escapes a list of column names in a database-dependent manner so reserved words can be used as a column name (i.e. "return").- Parameters:
columnNames
- list of column names- Returns:
- escaped column name list
-
supportsTablespaces
boolean supportsTablespaces() -
supportsCatalogs
Deprecated.please callsupports(Class)
with theCatalog
type insteadWhether this database supports catalogs -
supports
Whether this database supports the specified object type. It is invoking the deprecated methods to ensure that extensions are not broken, but once those are removed it will return only true- Parameters:
object
- the object type to check- Returns:
- true if the database supports the object type, false otherwise
-
getSchemaAndCatalogCase
CatalogAndSchema.CatalogAndSchemaCase getSchemaAndCatalogCase() -
supportsSchemas
Deprecated.please callsupports(Class)
with theSchema
type insteadWhether this database supports schemas -
supportsCatalogInObjectName
-
generatePrimaryKeyName
-
escapeSequenceName
-
escapeViewName
-
getRunStatus
ChangeSet.RunStatus getRunStatus(ChangeSet changeSet) throws DatabaseException, DatabaseHistoryException Returns the run status for the given ChangeSet -
getRanChangeSet
RanChangeSet getRanChangeSet(ChangeSet changeSet) throws DatabaseException, DatabaseHistoryException -
markChangeSetExecStatus
void markChangeSetExecStatus(ChangeSet changeSet, ChangeSet.ExecType execType) throws DatabaseException After the changeset has been run against the database this method will update the change log table with the information.- Throws:
DatabaseException
-
getRanChangeSetList
Returns the ChangeSets that have been run against the current database.- Throws:
DatabaseException
-
getRanDate
-
removeRanStatus
- Throws:
DatabaseException
-
commit
- Throws:
DatabaseException
-
rollback
- Throws:
DatabaseException
-
escapeStringForDatabase
-
close
- Specified by:
close
in interfaceAutoCloseable
- Throws:
DatabaseException
-
supportsRestrictForeignKeys
boolean supportsRestrictForeignKeys() -
escapeConstraintName
-
isAutoCommit
- Throws:
DatabaseException
-
setAutoCommit
- Throws:
DatabaseException
-
isSafeToRunUpdate
- Throws:
DatabaseException
-
executeStatements
void executeStatements(Change change, DatabaseChangeLog changeLog, List<SqlVisitor> sqlVisitors) throws LiquibaseException - Throws:
LiquibaseException
-
execute
- Throws:
LiquibaseException
-
saveStatements
void saveStatements(Change change, List<SqlVisitor> sqlVisitors, Writer writer) throws IOException, LiquibaseException - Throws:
IOException
LiquibaseException
-
executeRollbackStatements
void executeRollbackStatements(Change change, List<SqlVisitor> sqlVisitors) throws LiquibaseException - Throws:
LiquibaseException
-
executeRollbackStatements
void executeRollbackStatements(SqlStatement[] statements, List<SqlVisitor> sqlVisitors) throws LiquibaseException - Throws:
LiquibaseException
-
saveRollbackStatement
void saveRollbackStatement(Change change, List<SqlVisitor> sqlVisitors, Writer writer) throws IOException, LiquibaseException - Throws:
IOException
LiquibaseException
-
parseDate
- Throws:
DateParseException
-
getDateFunctions
List<DatabaseFunction> getDateFunctions()Returns list of database native date functions -
resetInternalState
void resetInternalState() -
supportsForeignKeyDisable
boolean supportsForeignKeyDisable() -
disableForeignKeyChecks
- Throws:
DatabaseException
-
enableForeignKeyChecks
- Throws:
DatabaseException
-
isCaseSensitive
boolean isCaseSensitive() -
isReservedWord
-
correctSchema
Deprecated.Returns a new CatalogAndSchema adjusted for this database. Examples of adjustments include: fixes for case issues, replacing null schema or catalog names with the default values removing set schema or catalog names if they are not supported -
correctObjectName
Fix the object name to the format the database expects, handling changes in case, etc. -
isFunction
-
getDataTypeMaxParameters
-
getDefaultSchema
CatalogAndSchema getDefaultSchema() -
dataTypeIsNotModifiable
Types like int4 in postgres cannot have a modifier. e.g. int4(10) Checks whether the type is allowed to have a modifier- Parameters:
typeName
- type name- Returns:
- Whether data type can have a modifier
-
generateDatabaseFunctionValue
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- Parameters:
databaseFunction
- database function to check.- Returns:
- the string value to use for an update or generate
-
getObjectQuotingStrategy
ObjectQuotingStrategy getObjectQuotingStrategy() -
setObjectQuotingStrategy
-
createsIndexesForForeignKeys
boolean createsIndexesForForeignKeys() -
getOutputDefaultSchema
boolean getOutputDefaultSchema()Should the schema be included in identifiers even if it is the default schema?- Returns:
- true (if the schema should be included in every case) or false (omit if default schema)
-
setOutputDefaultSchema
void setOutputDefaultSchema(boolean outputDefaultSchema) Whether the default schema should be included in generated SQL -
isDefaultSchema
If the database supports schemas, test if a given combination of catalog and schema name equals to the default catalog and schema of the current logged in user.- Parameters:
catalog
- catalog name to be testedschema
- schema name to be tested- Returns:
- if the database supports catalogs: true if it is the default schema, false if not. If it does not support schemas, the behaviour of this method is undefined (please call supportsSchemas first!)
-
isDefaultCatalog
If the database supports catalogs, test if a given catalog name equals to the default catalog of the current logged in user.- Parameters:
catalog
- catalog name to be tested- Returns:
- if the database supports catalogs: true if it is the default catalog, false if not. If it does not support catalogs, the behaviour of this method is undefined (please call supportsCatalog first!)
-
getOutputDefaultCatalog
boolean getOutputDefaultCatalog() -
setOutputDefaultCatalog
void setOutputDefaultCatalog(boolean outputDefaultCatalog) -
supportsPrimaryKeyNames
boolean supportsPrimaryKeyNames() -
supportsNotNullConstraintNames
boolean supportsNotNullConstraintNames()Does this database treat NOT NULL as an own kind of CONSTRAINT (in addition of simply being a column property)? This will affect the CONSTRAINT clause SQL generators.- Returns:
- true if the database supports naming NOT NULL constraints, false if not.
-
supportsBatchUpdates
Does the database support batched DML (INSERT/UPDATE/DELETE/MERGE/...) statements sent in a single call to the database?- Returns:
- true if the database has this capability for all DML statements, false in all other cases
- Throws:
DatabaseException
-
requiresExplicitNullForColumns
boolean requiresExplicitNullForColumns()Does the database require explicit NULL for nullable columns?- Returns:
- true if the database behaves incorrectly if NULL is not explicitly specified, false if it behaves like any good RDBMS should.
-
getSystemSchema
String getSystemSchema() -
addReservedWords
-
escapeDataTypeName
-
unescapeDataTypeName
-
unescapeDataTypeString
-
validate
ValidationErrors validate() -
failOnDefferable
default boolean failOnDefferable() -
afterUpdate
Allows the database to perform actions after an update is finished, i.e. after the last change of a changelog was applied.- Throws:
LiquibaseException
-
temporarilySetObjectQuotingStrategy
default TempObjectQuotingStrategy temporarilySetObjectQuotingStrategy(ObjectQuotingStrategy objectQuotingStrategy) Temporarily set the database's object quoting strategy. The caller is responsible for callingTempObjectQuotingStrategy.close()
on the returned object to reset the object quoting strategy back to its original setting.- Parameters:
objectQuotingStrategy
- the desired quoting strategy- Returns:
- an object that, when closed, will reset the databases object quoting strategy to the original setting
-
supportsCreateIfNotExists
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
default boolean supportsDatabaseChangeLogHistory()Does the particular database implementation support the database changelog history feature and associated table?- Returns:
- true if supported, false otherwise
-
checkDatabaseConnection
Some databases (such as MongoDB) require you to verify the connection to the database to ensure that the database is accessible. It can be "ping" signal to the database- Throws:
DatabaseException
-
generateConnectCommandSuccessMessage
Returns a custom message to be displayed upon successful execution of the connect command. This method can be overridden by a database implementation to provide a specific message. If not overridden, it returns null by default.- Returns:
- A custom success message for the connect command, or null if not provided.
-
CatalogAndSchema.standardize(Database)