Class BaseDatabase<C extends Connection<?>>
- java.lang.Object
-
- migratedb.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 Summary
Fields Modifier and Type Field Description protected Configurationconfigurationprotected DatabaseTypedatabaseTypeprotected JdbcConnectionFactoryjdbcConnectionFactoryprotected DatabaseMetaDatajdbcMetaDataprotected JdbcTemplatejdbcTemplateprotected ConnectionrawMainJdbcConnectionThe main JDBC connection, without any wrapping.
-
Constructor Summary
Constructors Constructor Description BaseDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcleanPostSchemas(Schema<?,?>[] schemas)Cleans all the objects in this database that need to be cleaned after each schema.voidcleanPreSchemas()Cleans all the objects in this database that need to be cleaned before each schema.voidclose()protected StringcomputeVersionDisplayName(Version version)Compute the user-friendly display name for this database version.protected VersiondetermineVersion()protected voiddoCleanPostSchemas(Schema<?,?>[] schemas)Cleans all the objects in this database that need to be cleaned after each schema.protected voiddoCleanPreSchemas()Cleans all the objects in this database that need to be cleaned before each schema.protected StringdoGetCatalog()protected abstract CdoGetConnection(Connection connection)Retrieves a MigrateDB Connection for this JDBC connection.protected StringdoGetCurrentUser()protected StringdoQuote(String identifier)Quotes this identifier for use in SQL queries.protected voidensureDatabaseIsRecentEnough(String oldestSupportedVersion)Schema<?,?>[]getAllSchemas()StringgetBaselineStatement(Table<?,?> table)StringgetCatalog()protected StringgetCloseQuote()SqlScriptgetCreateScript(SqlScriptFactory sqlScriptFactory, Table<?,?> table, boolean baseline)Retrieves the script used to create the schema history table.StringgetCurrentUser()DatabaseTypegetDatabaseType()DelimitergetDefaultDelimiter()protected StringgetEscapedQuote()StringgetInsertStatement(Table<?,?> table)StringgetInstalledBy()DatabaseMetaDatagetJdbcMetaData()CgetMainConnection()CgetMigrationConnection()protected StringgetOpenQuote()StringgetSelectStatement(Table<?,?> table)VersiongetVersion()Stringquote(String... identifiers)Quotes these identifiers for use in SQL queries.protected voidrecommendMigrateDbUpgradeIfNecessary(String newestSupportedVersion)protected voidrecommendMigrateDbUpgradeIfNecessaryForMajorVersion(String newestSupportedVersion)booleansupportsEmptyMigrationDescription()booleansupportsMultiStatementTransactions()StringunQuote(String identifier)booleanuseSingleConnection()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface migratedb.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
-
jdbcMetaData
protected final DatabaseMetaData jdbcMetaData
-
jdbcTemplate
protected 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
-
doGetConnection
protected abstract C doGetConnection(Connection connection)
Retrieves a MigrateDB Connection for this JDBC connection.
-
getVersion
public final Version getVersion()
- Specified by:
getVersionin interfaceDatabase<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:
getDefaultDelimiterin interfaceDatabase<C extends Connection<?>>
-
getCatalog
public final String getCatalog()
- Specified by:
getCatalogin interfaceDatabase<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:
getCurrentUserin interfaceDatabase<C extends Connection<?>>
-
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.- Specified by:
quotein interfaceDatabase<C extends Connection<?>>
-
getOpenQuote
protected String getOpenQuote()
-
getCloseQuote
protected String getCloseQuote()
-
getEscapedQuote
protected String getEscapedQuote()
-
unQuote
public String unQuote(String identifier)
- Specified by:
unQuotein interfaceDatabase<C extends Connection<?>>
-
useSingleConnection
public boolean useSingleConnection()
- Specified by:
useSingleConnectionin interfaceDatabase<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:
getJdbcMetaDatain interfaceDatabase<C extends Connection<?>>
-
getMainConnection
public final C getMainConnection()
- Specified by:
getMainConnectionin interfaceDatabase<C extends Connection<?>>- Returns:
- The main connection used to manipulate the schema history.
-
getMigrationConnection
public final C getMigrationConnection()
- Specified by:
getMigrationConnectionin interfaceDatabase<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:DatabaseRetrieves the script used to create the schema history table.- Specified by:
getCreateScriptin interfaceDatabase<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:
getInsertStatementin interfaceDatabase<C extends Connection<?>>
-
getBaselineStatement
public final String getBaselineStatement(Table<?,?> table)
- Specified by:
getBaselineStatementin interfaceDatabase<C extends Connection<?>>
-
getSelectStatement
public String getSelectStatement(Table<?,?> table)
- Specified by:
getSelectStatementin interfaceDatabase<C extends Connection<?>>
-
getInstalledBy
public final String getInstalledBy()
- Specified by:
getInstalledByin interfaceDatabase<C extends Connection<?>>
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceDatabase<C extends Connection<?>>
-
getDatabaseType
public DatabaseType getDatabaseType()
- Specified by:
getDatabaseTypein interfaceDatabase<C extends Connection<?>>
-
supportsEmptyMigrationDescription
public boolean supportsEmptyMigrationDescription()
- Specified by:
supportsEmptyMigrationDescriptionin interfaceDatabase<C extends Connection<?>>
-
supportsMultiStatementTransactions
public boolean supportsMultiStatementTransactions()
- Specified by:
supportsMultiStatementTransactionsin interfaceDatabase<C extends Connection<?>>
-
cleanPreSchemas
public void cleanPreSchemas()
Description copied from interface:DatabaseCleans all the objects in this database that need to be cleaned before each schema.- Specified by:
cleanPreSchemasin interfaceDatabase<C extends Connection<?>>
-
doCleanPreSchemas
protected void doCleanPreSchemas() throws SQLExceptionCleans 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:DatabaseCleans all the objects in this database that need to be cleaned after each schema.- Specified by:
cleanPostSchemasin interfaceDatabase<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:
getAllSchemasin interfaceDatabase<C extends Connection<?>>
-
-