Class BaseDatabaseType

    • 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
    • Constructor Detail

      • BaseDatabaseType

        public BaseDatabaseType()
    • Method Detail

      • getName

        public abstract String getName()
        Specified by:
        getName in interface DatabaseType
        Returns:
        The human-readable name for this database.
      • getNullType

        public abstract int getNullType()
        Specified by:
        getNullType in interface DatabaseType
        Returns:
        The JDBC type used to represent null in prepared statements.
      • handlesJDBCUrl

        public abstract boolean handlesJDBCUrl​(String url)
        Whether this database type should handle the given JDBC url.
        Specified by:
        handlesJDBCUrl in interface DatabaseType
        Parameters:
        url - The JDBC url.
        Returns:
        true if this handles the JDBC url, false if 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:
        getPriority in interface DatabaseType
      • 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:
        getJDBCCredentialsPattern in interface DatabaseType
        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: DatabaseType
        Get the driver class used to handle this JDBC url. This will only be called if matchesJDBCUrl previously returned true.
        Specified by:
        getDriverClass in interface DatabaseType
        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 by getDriverClass is not available.
        Specified by:
        getBackupDriverClass in interface DatabaseType
        Parameters:
        url - The JDBC url.
        classLoader - The classLoader to check for driver classes.
        Returns:
        The JDBC driver class name, null if 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:
        handlesDatabaseProductNameAndVersion in interface DatabaseType
        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

        public Database<?> createDatabase​(Configuration configuration,
                                          boolean printInfo,
                                          JdbcConnectionFactory jdbcConnectionFactory)
        Description copied from interface: DatabaseType
        Initializes the Database class, and optionally prints some information.
        Specified by:
        createDatabase in interface DatabaseType
        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: DatabaseType
        Initializes the Database used by this Database Type.
        Specified by:
        createDatabase in interface DatabaseType
        Parameters:
        configuration - The MigrateDB configuration.
        jdbcConnectionFactory - The current connection factory.
        Returns:
        The Database.
      • 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 by setConfigConnectionProps and setOverridingConnectionProps.
        Specified by:
        modifyDefaultConnectionProps in interface DatabaseType
        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 by setOverridingConnectionProps.
        Specified by:
        modifyConfigConnectionProps in interface DatabaseType
        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 by setDefaultConnectionProps and setConfigConnectionProps and should only be used if neither of those can satisfy your requirement.
        Specified by:
        modifyOverridingConnectionProps in interface DatabaseType
        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:
        shutdownDatabase in interface DatabaseType
        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:
        detectUserRequiredByUrl in interface DatabaseType
        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:
        detectPasswordRequiredByUrl in interface DatabaseType
        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: DatabaseType
        Detects whether or not external authentication is required.
        Specified by:
        externalAuthPropertiesRequired in interface DatabaseType
        Returns:
        true if external authentication is required, else false.
      • getExternalAuthProperties

        public Properties getExternalAuthProperties​(String url,
                                                    String username)
        Specified by:
        getExternalAuthProperties in interface DatabaseType
        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: DatabaseType
        Carries out any manipulation on the Connection that is required by MigrateDB's config
        Specified by:
        alterConnectionAsNeeded in interface DatabaseType
        Parameters:
        connection - The JDBC connection.
        configuration - The MigrateDB configuration.