Interface DatabaseType
-
- All Known Implementing Classes:
BaseDatabaseType,BigQueryDatabaseType,CockroachDBDatabaseType,DB2DatabaseType,DerbyDatabaseType,FirebirdDatabaseType,H2DatabaseType,HSQLDBDatabaseType,IgniteThinDatabaseType,InformixDatabaseType,MariaDBDatabaseType,MySQLDatabaseType,OracleDatabaseType,PostgreSQLDatabaseType,RedshiftDatabaseType,SAPHANADatabaseType,SnowflakeDatabaseType,SpannerDatabaseType,SQLiteDatabaseType,SQLServerDatabaseType,SybaseASEJConnectDatabaseType,SybaseASEJTDSDatabaseType,SynapseDatabaseType,TestContainersDatabaseType,TiDBDatabaseType,YugabyteDBDatabaseType
public interface DatabaseTypeExtension point for supported database types. Instances are unmodifiable.
-
-
Method Summary
All Methods Instance Methods Abstract 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.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.ParsercreateParser(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.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.StringgetName()intgetNullType()intgetPriority()When identifying database types, the priority with which this type will be used.booleanhandlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection)Check if this database type handles the connection product name and version.booleanhandlesJDBCUrl(String url)Check if this database type should handle the given JDBC urlStringinstantiateClassExtendedErrorMessage()voidmodifyConfigConnectionProps(Configuration config, Properties props, ClassLoader classLoader)Changes any necessary connection properties based on MigrateDB's configuration.voidmodifyDefaultConnectionProps(String url, Properties props, ClassLoader classLoader)Changes the default connection properties for this database.voidmodifyOverridingConnectionProps(Map<String,String> props)Changes any overriding connection properties.voidshutdownDatabase(String url, Driver driver)Shutdown the database that was opened (only applicable to embedded databases that require this).
-
-
-
Method Detail
-
getName
String getName()
- Returns:
- The human-readable name for this database type.
-
getNullType
int getNullType()
- Returns:
- The JDBC type used to represent
nullin prepared statements.
-
handlesJDBCUrl
boolean handlesJDBCUrl(String url)
Check if this database type should handle the given JDBC url- Parameters:
url- The JDBC url.- Returns:
trueif this handles the JDBC url,falseif not.
-
getPriority
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.
-
getJDBCCredentialsPattern
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.- Returns:
- The URL regex.
-
getDriverClass
String getDriverClass(String url, ClassLoader classLoader)
Get the driver class used to handle this JDBC url. This will only be called ifmatchesJDBCUrlpreviously returnedtrue.- 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
String getBackupDriverClass(String url, ClassLoader classLoader)
Retrieves a second choice backup driver for a JDBC url, in case the one returned bygetDriverClassis not available.- Parameters:
url- The JDBC url.classLoader- The classLoader to check for driver classes.- Returns:
- The JDBC driver.
nullif none.
-
handlesDatabaseProductNameAndVersion
boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection)
Check if this database type handles the connection product name and version. This allows more fine-grained control over which DatabaseType handles which connection. MigrateDB will use the first DatabaseType that returns true for this method.- 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
Database<?> createDatabase(Configuration configuration, boolean printInfo, JdbcConnectionFactory jdbcConnectionFactory)
Initializes the Database class, and optionally prints some information.- Parameters:
configuration- The MigrateDB configuration.jdbcConnectionFactory- The current connection factory.printInfo- Where the DB info should be printed in the logs.- Returns:
- The appropriate Database class.
-
createDatabase
Database<?> createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory)
Initializes the Database used by this Database Type.- Parameters:
configuration- The MigrateDB configuration.jdbcConnectionFactory- The current connection factory.- Returns:
- The Database.
-
createParser
Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext)
Initializes the Parser used by this Database Type.- Parameters:
configuration- The MigrateDB configuration.- Returns:
- The Parser.
-
createSqlScriptFactory
SqlScriptFactory createSqlScriptFactory(Configuration configuration, ParsingContext parsingContext)
Initializes the SqlScriptFactory used by this Database Type.- Parameters:
configuration- The MigrateDB configuration.- Returns:
- The SqlScriptFactory.
-
createSqlScriptExecutorFactory
SqlScriptExecutorFactory createSqlScriptExecutorFactory(JdbcConnectionFactory jdbcConnectionFactory, CallbackExecutor callbackExecutor)
Initializes the SqlScriptExecutorFactory used by this Database Type.- Parameters:
jdbcConnectionFactory- The current connection factory.- Returns:
- The SqlScriptExecutorFactory.
-
createExecutionStrategy
DatabaseExecutionStrategy createExecutionStrategy(Connection connection)
Initializes the DatabaseExecutionStrategy used by this Database Type.- Returns:
- The DatabaseExecutionStrategy.
-
createTransactionalExecutionTemplate
ExecutionTemplate createTransactionalExecutionTemplate(Connection connection, boolean rollbackOnException)
Initializes the ExecutionTemplate used by this Database Type.- Returns:
- The ExecutionTemplate.
-
modifyDefaultConnectionProps
void modifyDefaultConnectionProps(String url, Properties props, ClassLoader classLoader)
Changes the default connection properties for this database. These can be overridden bymodifyConfigConnectionPropsandmodifyOverridingConnectionProps- Parameters:
url- The JDBC url.props- The properties to write to.classLoader- The classLoader to use.
-
modifyConfigConnectionProps
void modifyConfigConnectionProps(Configuration config, Properties props, ClassLoader classLoader)
Changes any necessary connection properties based on MigrateDB's configuration. These can be overridden bymodifyOverridingConnectionProps- Parameters:
config- The MigrateDB configuration to read properties fromprops- The properties to write to.classLoader- The classLoader to use.
-
modifyOverridingConnectionProps
void modifyOverridingConnectionProps(Map<String,String> props)
Changes any overriding connection properties. These will override anything set bysetDefaultConnectionPropsandmodifyConfigConnectionPropsand should only be used if neither of those can satisfy your requirement.- Parameters:
props- The properties to write to.
-
shutdownDatabase
void shutdownDatabase(String url, Driver driver)
Shutdown the database that was opened (only applicable to embedded databases that require this).- Parameters:
url- The JDBC url used to create the database.driver- The driver created for the url.
-
detectUserRequiredByUrl
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- Parameters:
url- The url to check- Returns:
- true if a username needs to be provided
-
detectPasswordRequiredByUrl
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- Parameters:
url- The url to check- Returns:
- true if a password needs to be provided
-
externalAuthPropertiesRequired
boolean externalAuthPropertiesRequired(String url, String username, String password)
Detects whether or not external authentication is required.- Returns:
- true if external authentication is required, else false.
-
getExternalAuthProperties
Properties getExternalAuthProperties(String url, String username)
- Parameters:
url- The JDBC url.username- The username for the connection.- Returns:
- Authentication properties from database specific locations (e.g. pgpass)
-
alterConnectionAsNeeded
void alterConnectionAsNeeded(Connection connection, Configuration configuration)
Carries out any manipulation on the Connection that is required by MigrateDB's config- Parameters:
connection- The JDBC connection.configuration- The MigrateDB configuration.
-
instantiateClassExtendedErrorMessage
String instantiateClassExtendedErrorMessage()
- Returns:
- A hint on the requirements for creating database instances (libs on class path, etc.)
-
-