Interface DatabaseType

    • Method Detail

      • getName

        String getName()
        Returns:
        The human-readable name for this database type.
      • getNullType

        int getNullType()
        Returns:
        The JDBC type used to represent null in prepared statements.
      • handlesJDBCUrl

        boolean handlesJDBCUrl​(String url)
        Check if this database type should handle the given JDBC url
        Parameters:
        url - The JDBC url.
        Returns:
        true if this handles the JDBC url, false if 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 if matchesJDBCUrl previously returned true.
        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 by getDriverClass is not available.
        Parameters:
        url - The JDBC url.
        classLoader - The classLoader to check for driver classes.
        Returns:
        The JDBC driver. null if 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:
        true if this handles the product name and version, false if 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 by modifyConfigConnectionProps and modifyOverridingConnectionProps
        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 by modifyOverridingConnectionProps
        Parameters:
        config - The MigrateDB configuration to read properties from
        props - 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 by setDefaultConnectionProps and modifyConfigConnectionProps and 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.)