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

public interface Database extends PrioritizedService, AutoCloseable
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 Details

      • databaseChangeLogTableName

        static final String databaseChangeLogTableName
      • databaseChangeLogLockTableName

        static final String databaseChangeLogLockTableName
      • COMPLETE_SQL_SCOPE_KEY

        static final String COMPLETE_SQL_SCOPE_KEY
        See Also:
    • Method Details

      • isCorrectDatabaseImplementation

        boolean isCorrectDatabaseImplementation(DatabaseConnection conn) throws DatabaseException
        Is this AbstractDatabase subclass the correct one to use for the given connection.
        Throws:
        DatabaseException
      • getDefaultDriver

        String getDefaultDriver(String url)
        If this database understands the given url, return the default driver class name. Otherwise return null.
      • getConnection

        DatabaseConnection getConnection()
      • setConnection

        void setConnection(DatabaseConnection conn)
      • 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

        String getDatabaseProductVersion() throws DatabaseException
        Throws:
        DatabaseException
      • getDatabaseMajorVersion

        int getDatabaseMajorVersion() throws DatabaseException
        Throws:
        DatabaseException
      • getDatabaseMinorVersion

        int getDatabaseMinorVersion() throws DatabaseException
        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

        default String 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

        void setDefaultCatalogName(String catalogName) throws DatabaseException
        Throws:
        DatabaseException
      • getDefaultSchemaName

        String getDefaultSchemaName()
      • getDefaultScaleForNativeDataType

        Integer getDefaultScaleForNativeDataType(String nativeDataType)
        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

        void setDefaultSchemaName(String schemaName) throws DatabaseException
        Throws:
        DatabaseException
      • getDefaultPort

        Integer getDefaultPort()
      • getFetchSize

        Integer getFetchSize()
      • getLiquibaseCatalogName

        String getLiquibaseCatalogName()
      • setLiquibaseCatalogName

        void setLiquibaseCatalogName(String catalogName)
      • getLiquibaseSchemaName

        String getLiquibaseSchemaName()
      • setLiquibaseSchemaName

        void setLiquibaseSchemaName(String schemaName)
      • supportsInitiallyDeferrableColumns

        boolean supportsInitiallyDeferrableColumns()
        Returns whether this database support initially deferrable columns.
      • supportsSequences

        @Deprecated boolean supportsSequences()
        Deprecated.
        please call supports(Class) with the Sequence type instead
        Whether this database supports sequences
      • supportsDropTableCascadeConstraints

        boolean supportsDropTableCascadeConstraints()
      • supportsAutoIncrement

        boolean supportsAutoIncrement()
      • getDateLiteral

        String getDateLiteral(String isoDate)
      • getCurrentDateTimeFunction

        String getCurrentDateTimeFunction()
        Returns database-specific function for generating the current date/time.
      • setCurrentDateTimeFunction

        void setCurrentDateTimeFunction(String function)
      • 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

        void setDatabaseChangeLogTableName(String tableName)
        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

        void setDatabaseChangeLogLockTableName(String tableName)
        Set the table name of the change log lock to the given table name
        Parameters:
        tableName -
      • getLiquibaseTablespaceName

        String getLiquibaseTablespaceName()
      • setLiquibaseTablespaceName

        void setLiquibaseTablespaceName(String tablespaceName)
      • getConcatSql

        String getConcatSql(String... values)
        Returns SQL to concat the passed values.
      • setCanCacheLiquibaseTableInfo

        void setCanCacheLiquibaseTableInfo(boolean canCacheLiquibaseTableInfo)
      • dropDatabaseObjects

        void dropDatabaseObjects(CatalogAndSchema schema) throws LiquibaseException
        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

        default void addCompleteSqlToScope(String completeSql)
      • tag

        @Deprecated void tag(String tagString) throws DatabaseException
        Deprecated.
        Tags the database changelog with the given string.
        Throws:
        DatabaseException
      • doesTagExist

        @Deprecated boolean doesTagExist(String tag) throws DatabaseException
        Throws:
        DatabaseException
      • isSystemObject

        boolean isSystemObject(DatabaseObject example)
      • isLiquibaseObject

        boolean isLiquibaseObject(DatabaseObject object)
      • getViewDefinition

        String getViewDefinition(CatalogAndSchema schema, String name) throws DatabaseException
        Throws:
        DatabaseException
      • getDateLiteral

        String getDateLiteral(Date date)
      • getTimeLiteral

        String getTimeLiteral(Time time)
      • getDateTimeLiteral

        String getDateTimeLiteral(Timestamp timeStamp)
      • getDateLiteral

        String getDateLiteral(Date defaultDateValue)
      • escapeObjectName

        String escapeObjectName(String catalogName, String schemaName, String objectName, Class<? extends DatabaseObject> objectType)
      • escapeTableName

        String escapeTableName(String catalogName, String schemaName, String tableName)
      • escapeIndexName

        String escapeIndexName(String catalogName, String schemaName, String indexName)
      • escapeObjectName

        String escapeObjectName(String objectName, Class<? extends DatabaseObject> objectType)
      • 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

        String 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. "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 use escapeColumnName(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 to escapeColumnName(String, String, String, String) but allows control over whether function-like names should be left unquoted.
      • escapeColumnNameList

        String 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. "return").
        Parameters:
        columnNames - list of column names
        Returns:
        escaped column name list
      • supportsTablespaces

        boolean supportsTablespaces()
      • supportsCatalogs

        @Deprecated boolean supportsCatalogs()
        Deprecated.
        please call supports(Class) with the Catalog type instead
        Whether this database supports catalogs
      • supports

        default boolean supports(Class<? extends DatabaseObject> object)
        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 boolean supportsSchemas()
        Deprecated.
        please call supports(Class) with the Schema type instead
        Whether this database supports schemas
      • supportsCatalogInObjectName

        boolean supportsCatalogInObjectName(Class<? extends DatabaseObject> type)
      • generatePrimaryKeyName

        String generatePrimaryKeyName(String tableName)
      • escapeSequenceName

        String escapeSequenceName(String catalogName, String schemaName, String sequenceName)
      • escapeViewName

        String escapeViewName(String catalogName, String schemaName, String viewName)
      • getRunStatus

        Returns the run status for the given ChangeSet
        Throws:
        DatabaseException
        DatabaseHistoryException
      • getRanChangeSet

        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

        List<RanChangeSet> getRanChangeSetList() throws DatabaseException
        Returns the ChangeSets that have been run against the current database.
        Throws:
        DatabaseException
      • getRanDate

        Throws:
        DatabaseException
        DatabaseHistoryException
      • removeRanStatus

        void removeRanStatus(ChangeSet changeSet) throws DatabaseException
        Throws:
        DatabaseException
      • commit

        void commit() throws DatabaseException
        Throws:
        DatabaseException
      • rollback

        void rollback() throws DatabaseException
        Throws:
        DatabaseException
      • escapeStringForDatabase

        String escapeStringForDatabase(String string)
      • close

        void close() throws DatabaseException
        Specified by:
        close in interface AutoCloseable
        Throws:
        DatabaseException
      • supportsRestrictForeignKeys

        boolean supportsRestrictForeignKeys()
      • escapeConstraintName

        String escapeConstraintName(String constraintName)
      • isAutoCommit

        boolean isAutoCommit() throws DatabaseException
        Throws:
        DatabaseException
      • setAutoCommit

        void setAutoCommit(boolean b) throws DatabaseException
        Throws:
        DatabaseException
      • isSafeToRunUpdate

        boolean isSafeToRunUpdate() throws DatabaseException
        Throws:
        DatabaseException
      • executeStatements

        void executeStatements(Change change, DatabaseChangeLog changeLog, List<SqlVisitor> sqlVisitors) throws LiquibaseException
        Throws:
        LiquibaseException
      • execute

        void execute(SqlStatement[] statements, List<SqlVisitor> sqlVisitors) throws LiquibaseException
        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

        Date parseDate(String dateAsString) throws DateParseException
        Throws:
        DateParseException
      • getDateFunctions

        List<DatabaseFunction> getDateFunctions()
        Returns list of database native date functions
      • resetInternalState

        void resetInternalState()
      • supportsForeignKeyDisable

        boolean supportsForeignKeyDisable()
      • disableForeignKeyChecks

        boolean disableForeignKeyChecks() throws DatabaseException
        Throws:
        DatabaseException
      • enableForeignKeyChecks

        void enableForeignKeyChecks() throws DatabaseException
        Throws:
        DatabaseException
      • isCaseSensitive

        boolean isCaseSensitive()
      • isReservedWord

        boolean isReservedWord(String string)
      • correctSchema

        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

        String correctObjectName(String name, Class<? extends DatabaseObject> objectType)
        Fix the object name to the format the database expects, handling changes in case, etc.
      • isFunction

        boolean isFunction(String string)
      • getDataTypeMaxParameters

        int getDataTypeMaxParameters(String dataTypeName)
      • getDefaultSchema

        CatalogAndSchema getDefaultSchema()
      • dataTypeIsNotModifiable

        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 modifier
        Parameters:
        typeName - type name
        Returns:
        Whether data type can have a modifier
      • generateDatabaseFunctionValue

        String generateDatabaseFunctionValue(DatabaseFunction databaseFunction)
        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

        void setObjectQuotingStrategy(ObjectQuotingStrategy quotingStrategy)
      • 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

        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.
        Parameters:
        catalog - catalog name to be tested
        schema - 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

        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.
        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

        boolean supportsBatchUpdates() throws DatabaseException
        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

        void addReservedWords(Collection<String> words)
      • escapeDataTypeName

        String escapeDataTypeName(String dataTypeName)
      • unescapeDataTypeName

        String unescapeDataTypeName(String dataTypeName)
      • unescapeDataTypeString

        String unescapeDataTypeString(String dataTypeString)
      • validate

        ValidationErrors validate()
      • failOnDefferable

        default boolean failOnDefferable()
      • afterUpdate

        default void afterUpdate() throws LiquibaseException
        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 calling TempObjectQuotingStrategy.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

        default boolean supportsCreateIfNotExists(Class<? extends DatabaseObject> type)
        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

        default void checkDatabaseConnection() throws DatabaseException
        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

        default String 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.