Class BaseDatabase
- java.lang.Object
-
- migratedb.v1.core.internal.database.base.BaseDatabase
-
- All Implemented Interfaces:
Closeable,AutoCloseable,Database
- 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 extends Object implements Database
Abstraction for database-specific functionality.
-
-
Field Summary
Fields Modifier and Type Field Description protected Configurationconfigurationprotected DatabaseTypedatabaseTypeprotected JdbcConnectionFactoryjdbcConnectionFactoryprotected JdbcTemplatejdbcTemplateprotected ConnectionrawMainJdbcConnectionThe main JDBC connection, without any wrapping.
-
Constructor Summary
Constructors Constructor Description BaseDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory)
-
Method Summary
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface migratedb.v1.core.api.internal.database.base.Database
catalogIsSchema, ensureSupported, getBooleanFalse, getBooleanTrue, getRawCreateScript, supportsChangingCurrentSchema, supportsDdlTransactions
-
-
-
-
Field Detail
-
databaseType
protected final DatabaseType databaseType
-
configuration
protected final Configuration configuration
-
jdbcConnectionFactory
protected final JdbcConnectionFactory jdbcConnectionFactory
-
jdbcTemplate
protected final JdbcTemplate jdbcTemplate
-
rawMainJdbcConnection
protected final Connection rawMainJdbcConnection
The main JDBC connection, without any wrapping.
-
-
Constructor Detail
-
BaseDatabase
public BaseDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory)
-
-
Method Detail
-
doGetSession
protected abstract Session doGetSession(Connection connection)
Retrieves a MigrateDB session for this JDBC connection.
-
getVersion
public final Version getVersion()
- Specified by:
getVersionin interfaceDatabase- 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:
getDefaultDelimiterin interfaceDatabase
-
getCatalog
public final String getCatalog()
- Specified by:
getCatalogin interfaceDatabase- 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:
getCurrentUserin interfaceDatabase
-
doGetCurrentUser
protected String doGetCurrentUser() throws SQLException
- Throws:
SQLException
-
quote
public final String quote(String... identifiers)
Description copied from interface:DatabaseQuotes these identifiers for use in SQL queries. Multiple identifiers will be quoted and separated by a dot.
-
getOpenQuote
protected String getOpenQuote()
-
getCloseQuote
protected String getCloseQuote()
-
getEscapedQuote
protected String getEscapedQuote()
-
usesSingleSession
public boolean usesSingleSession()
- Specified by:
usesSingleSessionin interfaceDatabase- Returns:
- Whether a single session is used for both schema history table management and applying migrations.
-
getJdbcMetaData
public DatabaseMetaData getJdbcMetaData()
- Specified by:
getJdbcMetaDatain interfaceDatabase
-
getMainSession
public Session getMainSession()
- Specified by:
getMainSessionin interfaceDatabase- Returns:
- The main session used to manipulate the schema history.
-
getMigrationSession
public Session getMigrationSession()
- Specified by:
getMigrationSessionin interfaceDatabase- Returns:
- The migration session 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:DatabaseRetrieves the script used to create the schema history table.- Specified by:
getCreateScriptin interfaceDatabase- 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:
getInsertStatementin interfaceDatabase
-
getBaselineStatement
public final String getBaselineStatement(Table table)
- Specified by:
getBaselineStatementin interfaceDatabase
-
getSelectStatement
public String getSelectStatement(Table table)
- Specified by:
getSelectStatementin interfaceDatabase
-
getInstalledBy
public final String getInstalledBy()
- Specified by:
getInstalledByin interfaceDatabase
-
close
public void close()
-
getDatabaseType
public DatabaseType getDatabaseType()
- Specified by:
getDatabaseTypein interfaceDatabase
-
supportsEmptyMigrationDescription
public boolean supportsEmptyMigrationDescription()
- Specified by:
supportsEmptyMigrationDescriptionin interfaceDatabase
-
supportsMultiStatementTransactions
public boolean supportsMultiStatementTransactions()
- Specified by:
supportsMultiStatementTransactionsin interfaceDatabase
-
getAllSchemas
public List<? extends Schema> getAllSchemas()
- Specified by:
getAllSchemasin interfaceDatabase
-
-