Class BaseDatabaseType
- java.lang.Object
-
- migratedb.core.internal.database.base.BaseDatabaseType
-
- All Implemented Interfaces:
DatabaseType
- Direct Known Subclasses:
BigQueryDatabaseType,CockroachDBDatabaseType,DB2DatabaseType,DerbyDatabaseType,FirebirdDatabaseType,H2DatabaseType,HSQLDBDatabaseType,IgniteThinDatabaseType,InformixDatabaseType,MariaDBDatabaseType,MySQLDatabaseType,OracleDatabaseType,PostgreSQLDatabaseType,RedshiftDatabaseType,SAPHANADatabaseType,SnowflakeDatabaseType,SpannerDatabaseType,SQLiteDatabaseType,SQLServerDatabaseType,SybaseASEJConnectDatabaseType,SybaseASEJTDSDatabaseType,TestContainersDatabaseType
public abstract class BaseDatabaseType extends Object implements DatabaseType
-
-
Field Summary
Fields Modifier and Type Field Description protected static StringAPPLICATION_NAMEThis is useful for databases that allow setting this in order to easily correlate individual application with database connections.protected static LogLOG
-
Constructor Summary
Constructors Constructor Description BaseDatabaseType()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidalterConnectionAsNeeded(Connection connection, Configuration configuration)Carries out any manipulation on the Connection that is required by MigrateDB's configDatabase<?>createDatabase(Configuration configuration, boolean printInfo, JdbcConnectionFactory jdbcConnectionFactory)Initializes the Database class, and optionally prints some information.abstract Database<?>createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory)Initializes the Database used by this Database Type.DatabaseExecutionStrategycreateExecutionStrategy(Connection connection)Initializes the DatabaseExecutionStrategy used by this Database Type.abstract BaseParsercreateParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext)Initializes the Parser used by this Database Type.SqlScriptExecutorFactorycreateSqlScriptExecutorFactory(JdbcConnectionFactory jdbcConnectionFactory, CallbackExecutor callbackExecutor)Initializes the SqlScriptExecutorFactory used by this Database Type.SqlScriptFactorycreateSqlScriptFactory(Configuration configuration, ParsingContext parsingContext)Initializes the SqlScriptFactory used by this Database Type.ExecutionTemplatecreateTransactionalExecutionTemplate(Connection connection, boolean rollbackOnException)Initializes the ExecutionTemplate used by this Database Type.booleandetectPasswordRequiredByUrl(String url)Detects whether a password is required from configuration.booleandetectUserRequiredByUrl(String url)Detects whether a user is required from configuration.booleanexternalAuthPropertiesRequired(String url, String username, String password)Detects whether or not external authentication is required.StringgetBackupDriverClass(String url, ClassLoader classLoader)Retrieves a second choice backup driver for a JDBC url, in case the one returned bygetDriverClassis not available.static PatterngetDefaultJDBCCredentialsPattern()Gets a regex that identifies credentials in the JDBC URL, where they conform to the default URL pattern.abstract StringgetDriverClass(String url, ClassLoader classLoader)Get the driver class used to handle this JDBC url.PropertiesgetExternalAuthProperties(String url, String username)PatterngetJDBCCredentialsPattern()A regex that identifies credentials in the JDBC URL, where they conform to a pattern specific to this database.abstract StringgetName()abstract intgetNullType()intgetPriority()When identifying database types, the priority with which this type will be used.static StringgetSelectVersionOutput(Connection connection)Retrieves the version string for a connection as described by SELECT VERSION(), which may differ from the connection metadata.abstract booleanhandlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection)This allows more fine-grained control over which DatabaseType handles which connection.abstract booleanhandlesJDBCUrl(String url)Whether this database type should handle the given JDBC url.StringinstantiateClassExtendedErrorMessage()voidmodifyConfigConnectionProps(Configuration config, Properties props, ClassLoader classLoader)Set any necessary connection properties based on MigrateDB's configuration.voidmodifyDefaultConnectionProps(String url, Properties props, ClassLoader classLoader)Set the default connection properties for this database.voidmodifyOverridingConnectionProps(Map<String,String> props)These will override anything set bysetDefaultConnectionPropsandsetConfigConnectionPropsand should only be used if neither of those can satisfy your requirement.voidshutdownDatabase(String url, Driver driver)Only applicable to embedded databases that require this.StringtoString()
-
-
-
Field Detail
-
LOG
protected static final Log LOG
-
APPLICATION_NAME
protected static final String APPLICATION_NAME
This is useful for databases that allow setting this in order to easily correlate individual application with database connections.- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public abstract String getName()
- Specified by:
getNamein interfaceDatabaseType- Returns:
- The human-readable name for this database.
-
getNullType
public abstract int getNullType()
- Specified by:
getNullTypein interfaceDatabaseType- Returns:
- The JDBC type used to represent
nullin prepared statements.
-
handlesJDBCUrl
public abstract boolean handlesJDBCUrl(String url)
Whether this database type should handle the given JDBC url.- Specified by:
handlesJDBCUrlin interfaceDatabaseType- Parameters:
url- The JDBC url.- Returns:
trueif this handles the JDBC url,falseif not.
-
getPriority
public int getPriority()
When identifying database types, the priority with which this type will be used. High numbers indicate that this type will be used in preference to others.- Specified by:
getPriorityin interfaceDatabaseType
-
getJDBCCredentialsPattern
public Pattern getJDBCCredentialsPattern()
A regex that identifies credentials in the JDBC URL, where they conform to a pattern specific to this database. The first captured group should represent the password text, so that it can be redacted if necessary.- Specified by:
getJDBCCredentialsPatternin interfaceDatabaseType- Returns:
- The URL regex.
-
getDefaultJDBCCredentialsPattern
public static Pattern getDefaultJDBCCredentialsPattern()
Gets a regex that identifies credentials in the JDBC URL, where they conform to the default URL pattern. The first captured group represents the password text.
-
getDriverClass
public abstract String getDriverClass(String url, ClassLoader classLoader)
Description copied from interface:DatabaseTypeGet the driver class used to handle this JDBC url. This will only be called ifmatchesJDBCUrlpreviously returnedtrue.- Specified by:
getDriverClassin interfaceDatabaseType- Parameters:
url- The JDBC url.classLoader- The classLoader to check for driver classes.- Returns:
- The full driver class name to be instantiated to handle this url.
-
getBackupDriverClass
public String getBackupDriverClass(String url, ClassLoader classLoader)
Retrieves a second choice backup driver for a JDBC url, in case the one returned bygetDriverClassis not available.- Specified by:
getBackupDriverClassin interfaceDatabaseType- Parameters:
url- The JDBC url.classLoader- The classLoader to check for driver classes.- Returns:
- The JDBC driver class name,
nullif none.
-
handlesDatabaseProductNameAndVersion
public abstract boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection)
This allows more fine-grained control over which DatabaseType handles which connection. MigrateDB will use the first DatabaseType that returns true for this method.- Specified by:
handlesDatabaseProductNameAndVersionin interfaceDatabaseType- Parameters:
databaseProductName- The product name returned by the database.databaseProductVersion- The product version returned by the database.connection- The connection used to connect to the database.- Returns:
trueif this handles the product name and version,falseif not.
-
createDatabase
public Database<?> createDatabase(Configuration configuration, boolean printInfo, JdbcConnectionFactory jdbcConnectionFactory)
Description copied from interface:DatabaseTypeInitializes the Database class, and optionally prints some information.- Specified by:
createDatabasein interfaceDatabaseType- Parameters:
configuration- The MigrateDB configuration.printInfo- Where the DB info should be printed in the logs.jdbcConnectionFactory- The current connection factory.- Returns:
- The appropriate Database class.
-
createDatabase
public abstract Database<?> createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory)
Description copied from interface:DatabaseTypeInitializes the Database used by this Database Type.- Specified by:
createDatabasein interfaceDatabaseType- Parameters:
configuration- The MigrateDB configuration.jdbcConnectionFactory- The current connection factory.- Returns:
- The Database.
-
createParser
public abstract BaseParser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext)
Description copied from interface:DatabaseTypeInitializes the Parser used by this Database Type.- Specified by:
createParserin interfaceDatabaseType- Parameters:
configuration- The MigrateDB configuration.- Returns:
- The Parser.
-
createSqlScriptFactory
public SqlScriptFactory createSqlScriptFactory(Configuration configuration, ParsingContext parsingContext)
Description copied from interface:DatabaseTypeInitializes the SqlScriptFactory used by this Database Type.- Specified by:
createSqlScriptFactoryin interfaceDatabaseType- Parameters:
configuration- The MigrateDB configuration.- Returns:
- The SqlScriptFactory.
-
createSqlScriptExecutorFactory
public SqlScriptExecutorFactory createSqlScriptExecutorFactory(JdbcConnectionFactory jdbcConnectionFactory, CallbackExecutor callbackExecutor)
Description copied from interface:DatabaseTypeInitializes the SqlScriptExecutorFactory used by this Database Type.- Specified by:
createSqlScriptExecutorFactoryin interfaceDatabaseType- Parameters:
jdbcConnectionFactory- The current connection factory.- Returns:
- The SqlScriptExecutorFactory.
-
createExecutionStrategy
public DatabaseExecutionStrategy createExecutionStrategy(Connection connection)
Description copied from interface:DatabaseTypeInitializes the DatabaseExecutionStrategy used by this Database Type.- Specified by:
createExecutionStrategyin interfaceDatabaseType- Returns:
- The DatabaseExecutionStrategy.
-
createTransactionalExecutionTemplate
public ExecutionTemplate createTransactionalExecutionTemplate(Connection connection, boolean rollbackOnException)
Description copied from interface:DatabaseTypeInitializes the ExecutionTemplate used by this Database Type.- Specified by:
createTransactionalExecutionTemplatein interfaceDatabaseType- Returns:
- The ExecutionTemplate.
-
getSelectVersionOutput
public static String getSelectVersionOutput(Connection connection)
Retrieves the version string for a connection as described by SELECT VERSION(), which may differ from the connection metadata.
-
modifyDefaultConnectionProps
public void modifyDefaultConnectionProps(String url, Properties props, ClassLoader classLoader)
Set the default connection properties for this database. These can be overridden bysetConfigConnectionPropsandsetOverridingConnectionProps.- Specified by:
modifyDefaultConnectionPropsin interfaceDatabaseType- Parameters:
url- The JDBC url.props- The properties to write to.classLoader- The classLoader to use.
-
modifyConfigConnectionProps
public void modifyConfigConnectionProps(Configuration config, Properties props, ClassLoader classLoader)
Set any necessary connection properties based on MigrateDB's configuration. These can be overridden bysetOverridingConnectionProps.- Specified by:
modifyConfigConnectionPropsin interfaceDatabaseType- Parameters:
config- The MigrateDB configuration to read properties from.props- The properties to write to.classLoader- The classLoader to use.
-
modifyOverridingConnectionProps
public void modifyOverridingConnectionProps(Map<String,String> props)
These will override anything set bysetDefaultConnectionPropsandsetConfigConnectionPropsand should only be used if neither of those can satisfy your requirement.- Specified by:
modifyOverridingConnectionPropsin interfaceDatabaseType- Parameters:
props- The properties to write to.
-
shutdownDatabase
public void shutdownDatabase(String url, Driver driver)
Only applicable to embedded databases that require this.- Specified by:
shutdownDatabasein interfaceDatabaseType- Parameters:
url- The JDBC url used to create the database.driver- The driver created for the url.
-
detectUserRequiredByUrl
public boolean detectUserRequiredByUrl(String url)
Detects whether a user is required from configuration. This may not be the case if the driver supports other authentication mechanisms, or supports the user being encoded in the URL.- Specified by:
detectUserRequiredByUrlin interfaceDatabaseType- Parameters:
url- The url to check- Returns:
- true if a username needs to be provided
-
detectPasswordRequiredByUrl
public boolean detectPasswordRequiredByUrl(String url)
Detects whether a password is required from configuration. This may not be the case if the driver supports other authentication mechanisms, or supports the password being encoded in the URL.- Specified by:
detectPasswordRequiredByUrlin interfaceDatabaseType- Parameters:
url- The url to check- Returns:
- true if a password needs to be provided
-
externalAuthPropertiesRequired
public boolean externalAuthPropertiesRequired(String url, String username, String password)
Description copied from interface:DatabaseTypeDetects whether or not external authentication is required.- Specified by:
externalAuthPropertiesRequiredin interfaceDatabaseType- Returns:
- true if external authentication is required, else false.
-
getExternalAuthProperties
public Properties getExternalAuthProperties(String url, String username)
- Specified by:
getExternalAuthPropertiesin interfaceDatabaseType- Parameters:
url- The JDBC url.username- The username for the connection.- Returns:
- Authentication properties from database specific locations (e.g. pgpass)
-
alterConnectionAsNeeded
public void alterConnectionAsNeeded(Connection connection, Configuration configuration)
Description copied from interface:DatabaseTypeCarries out any manipulation on the Connection that is required by MigrateDB's config- Specified by:
alterConnectionAsNeededin interfaceDatabaseType- Parameters:
connection- The JDBC connection.configuration- The MigrateDB configuration.
-
instantiateClassExtendedErrorMessage
public String instantiateClassExtendedErrorMessage()
- Specified by:
instantiateClassExtendedErrorMessagein interfaceDatabaseType- Returns:
- A hint on the requirements for creating database instances (libs on class path, etc.)
-
-