Class DBConfiguration

  • Direct Known Subclasses:
    DBSpec

    public class DBConfiguration
    extends Object
    Author:
    igor on 12/2/16.
    • Constructor Detail

      • DBConfiguration

        public DBConfiguration()
    • Method Detail

      • addConnectionConfig

        public static void addConnectionConfig​(ConnectionConfig connectionConfig,
                                               boolean override)
        Parameters:
        override - is irrelevant. This method will always override previous configurations for the same environment and with the same name.
      • addConnectionConfig

        public static void addConnectionConfig​(ConnectionConfig connectionConfig)
        Adds a new connection config for an environment. This method will always override previous configurations for the same environment and with the same name and marked for testing or not.
        Parameters:
        connectionConfig - connection configuration object
      • getConnectionConfigsForCurrentEnv

        public static List<ConnectionConfig> getConnectionConfigsForCurrentEnv()
        Provides a list of all connection configs corresponding to a current environment.
        Returns:
        a list of all connection configs corresponding to a current environment.
      • getConnectionConfigs

        public static List<ConnectionConfig> getConnectionConfigs​(String env)
        Provides a list of all connection configs corresponding to a given environment.
        Parameters:
        env - name of environment, such as "development", "production", etc.
        Returns:
        a list of all connection configs corresponding to a given environment.
      • getConnectionConfigsExceptTesting

        public static List<ConnectionConfig> getConnectionConfigsExceptTesting​(String dbName)
        Returns all connections which correspond dbName and current environment
        Returns:
        all connections which correspond dbName and current environment
      • clearConnectionConfigs

        public static void clearConnectionConfigs()
        Clears connection configs for current environment
      • resetConnectionConfigs

        public static void resetConnectionConfigs()
      • clearConnectionConfigs

        protected static void clearConnectionConfigs​(String env)
      • loadConfiguration

        public static void loadConfiguration​(String file)
        Configures multiple database connections from a single property file. Example content for such file:
             development.driver=com.mysql.cj.jdbc.Driver
             development.username=john
             development.password=pwd
             development.url=jdbc:mysql://localhost/proj_dev
        
             test.driver=com.mysql.cj.jdbc.Driver
             test.username=mary
             test.password=pwd1
             test.url=jdbc:mysql://localhost/test
        
             production.jndi=java:comp/env/jdbc/prod
        
             # this one is to run migrations in production remotely
             production.remote.driver=com.mysql.cj.jdbc.Driver
             production.remote.username=root
             production.remote.password=xxx
             production.remote.url=jdbc:mysql://127.0.0.1:3307/poj1_production
        
         
        Rules and limitations of using a file-based configuration:
        • Only one database connection can be configured per environment (with the exception of development and test connections only in development environment)
        • Currently additional database parameters need to be specified as a part of a database URL
        • Database connection named "test" in the database configuration file is for "development" environment and is automatically marked for testing (will be used during tests)
        • All connections specified in a property file automatically assigned DB name "default"
        Parameters:
        file - path to a file. Can be located on classpath, or on a file system. First searched on classpath, then on file system.