Class BaseDatabase<C extends Connection<?>>

java.lang.Object
migratedb.v1.core.internal.database.base.BaseDatabase<C>
All Implemented Interfaces:
Closeable, AutoCloseable, Database<C>
Direct Known Subclasses:
BigQueryDatabase, CockroachDBDatabase, DB2Database, DerbyDatabase, FirebirdDatabase, H2Database, HSQLDBDatabase, IgniteThinDatabase, InformixDatabase, MySQLDatabase, OracleDatabase, PostgreSQLDatabase, RedshiftDatabase, SAPHANADatabase, SnowflakeDatabase, SpannerDatabase, SQLiteDatabase, SQLServerDatabase, SybaseASEDatabase

public abstract class BaseDatabase<C extends Connection<?>> extends Object implements Database<C>
Abstraction for database-specific functionality.
  • Field Details

    • databaseType

      protected final DatabaseType databaseType
    • configuration

      protected final Configuration configuration
    • jdbcConnectionFactory

      protected final JdbcConnectionFactory jdbcConnectionFactory
    • jdbcMetaData

      protected final DatabaseMetaData jdbcMetaData
    • jdbcTemplate

      protected JdbcTemplate jdbcTemplate
    • rawMainJdbcConnection

      protected final Connection rawMainJdbcConnection
      The main JDBC connection, without any wrapping.
  • Constructor Details

  • Method Details

    • doGetConnection

      protected abstract C doGetConnection(Connection connection)
      Retrieves a MigrateDB Connection for this JDBC connection.
    • getVersion

      public final Version getVersion()
      Specified by:
      getVersion in interface Database<C extends Connection<?>>
      Returns:
      The 'major.minor' version of this database.
    • ensureDatabaseIsRecentEnough

      protected final void ensureDatabaseIsRecentEnough(String oldestSupportedVersion)
    • recommendMigrateDbUpgradeIfNecessary

      protected final void recommendMigrateDbUpgradeIfNecessary(String newestSupportedVersion)
    • recommendMigrateDbUpgradeIfNecessaryForMajorVersion

      protected final void recommendMigrateDbUpgradeIfNecessaryForMajorVersion(String newestSupportedVersion)
    • computeVersionDisplayName

      protected String computeVersionDisplayName(Version version)
      Compute the user-friendly display name for this database version.
    • getDefaultDelimiter

      public Delimiter getDefaultDelimiter()
      Specified by:
      getDefaultDelimiter in interface Database<C extends Connection<?>>
    • getCatalog

      public final String getCatalog()
      Specified by:
      getCatalog in interface Database<C extends Connection<?>>
      Returns:
      The name of the database, by default as determined by JDBC.
    • doGetCatalog

      protected String doGetCatalog() throws SQLException
      Throws:
      SQLException
    • getCurrentUser

      public final String getCurrentUser()
      Specified by:
      getCurrentUser in interface Database<C extends Connection<?>>
    • doGetCurrentUser

      protected String doGetCurrentUser() throws SQLException
      Throws:
      SQLException
    • quote

      public final String quote(String... identifiers)
      Description copied from interface: Database
      Quotes these identifiers for use in SQL queries. Multiple identifiers will be quoted and separated by a dot.
      Specified by:
      quote in interface Database<C extends Connection<?>>
    • doQuote

      protected String doQuote(String identifier)
      Quotes this identifier for use in SQL queries.
    • getOpenQuote

      protected String getOpenQuote()
    • getCloseQuote

      protected String getCloseQuote()
    • getEscapedQuote

      protected String getEscapedQuote()
    • unQuote

      public String unQuote(String identifier)
      Specified by:
      unQuote in interface Database<C extends Connection<?>>
    • useSingleConnection

      public boolean useSingleConnection()
      Specified by:
      useSingleConnection in interface Database<C extends Connection<?>>
      Returns:
      Whether to use a single connection for both schema history table management and applying migrations.
    • getJdbcMetaData

      public DatabaseMetaData getJdbcMetaData()
      Specified by:
      getJdbcMetaData in interface Database<C extends Connection<?>>
    • getMainConnection

      public final C getMainConnection()
      Specified by:
      getMainConnection in interface Database<C extends Connection<?>>
      Returns:
      The main connection used to manipulate the schema history.
    • getMigrationConnection

      public final C getMigrationConnection()
      Specified by:
      getMigrationConnection in interface Database<C extends Connection<?>>
      Returns:
      The migration connection used to apply migrations.
    • determineVersion

      protected Version determineVersion()
      Returns:
      The major and minor version of the database.
    • getCreateScript

      public final SqlScript getCreateScript(SqlScriptFactory sqlScriptFactory, Table<?,?> table, boolean baseline)
      Description copied from interface: Database
      Retrieves the script used to create the schema history table.
      Specified by:
      getCreateScript in interface Database<C extends Connection<?>>
      Parameters:
      sqlScriptFactory - The factory used to create the SQL script.
      table - The table to create.
      baseline - Whether to include the creation of a baseline marker.
    • getInsertStatement

      public String getInsertStatement(Table<?,?> table)
      Specified by:
      getInsertStatement in interface Database<C extends Connection<?>>
    • getBaselineStatement

      public final String getBaselineStatement(Table<?,?> table)
      Specified by:
      getBaselineStatement in interface Database<C extends Connection<?>>
    • getSelectStatement

      public String getSelectStatement(Table<?,?> table)
      Specified by:
      getSelectStatement in interface Database<C extends Connection<?>>
    • getInstalledBy

      public final String getInstalledBy()
      Specified by:
      getInstalledBy in interface Database<C extends Connection<?>>
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Database<C extends Connection<?>>
    • getDatabaseType

      public DatabaseType getDatabaseType()
      Specified by:
      getDatabaseType in interface Database<C extends Connection<?>>
    • supportsEmptyMigrationDescription

      public boolean supportsEmptyMigrationDescription()
      Specified by:
      supportsEmptyMigrationDescription in interface Database<C extends Connection<?>>
    • supportsMultiStatementTransactions

      public boolean supportsMultiStatementTransactions()
      Specified by:
      supportsMultiStatementTransactions in interface Database<C extends Connection<?>>
    • cleanPreSchemas

      public void cleanPreSchemas()
      Description copied from interface: Database
      Cleans all the objects in this database that need to be cleaned before each schema.
      Specified by:
      cleanPreSchemas in interface Database<C extends Connection<?>>
    • doCleanPreSchemas

      protected void doCleanPreSchemas() throws SQLException
      Cleans all the objects in this database that need to be cleaned before each schema.
      Throws:
      SQLException - when the clean failed.
    • cleanPostSchemas

      public void cleanPostSchemas(Schema<?,?>[] schemas)
      Description copied from interface: Database
      Cleans all the objects in this database that need to be cleaned after each schema.
      Specified by:
      cleanPostSchemas in interface Database<C extends Connection<?>>
      Parameters:
      schemas - The list of schemas managed by MigrateDB.
    • doCleanPostSchemas

      protected void doCleanPostSchemas(Schema<?,?>[] schemas) throws SQLException
      Cleans all the objects in this database that need to be cleaned after each schema.
      Parameters:
      schemas - The list of schemas managed by MigrateDB.
      Throws:
      SQLException - when the clean failed.
    • getAllSchemas

      public Schema<?,?>[] getAllSchemas()
      Specified by:
      getAllSchemas in interface Database<C extends Connection<?>>