Class DBConfiguration
java.lang.Object
org.javalite.activejdbc.connection_config.DBConfiguration
- Direct Known Subclasses:
AbstractDBConfig
,DBSpec
- Author:
- igor on 12/2/16.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addConnectionConfig(ConnectionConfig connectionConfig)
Adds a new connection config for an environment.static void
addConnectionConfig(ConnectionConfig connectionConfig, boolean override)
Deprecated.static void
Clears connection configs for current environmentprotected static void
clearConnectionConfigs(String env)
static List<ConnectionConfig>
getConnectionConfigs(String env)
Provides a list of all connection configs corresponding to a given environment.static List<ConnectionConfig>
getConnectionConfigsExceptTesting(String dbName)
Returns all connections which correspond dbName and current environmentstatic List<ConnectionConfig>
Provides a list of all connection configs corresponding to a current environment.static List<ConnectionConfig>
static void
loadConfiguration(String file)
Configures multiple database connections from a single property file.static void
-
Constructor Details
-
DBConfiguration
public DBConfiguration()
-
-
Method Details
-
addConnectionConfig
Deprecated.- Parameters:
override
- is irrelevant. This method will always override previous configurations for the same environment and with the same name.
-
addConnectionConfig
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
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
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
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
-
loadConfiguration
Configures multiple database connections from a single property file. Example content for such file:development.driver=org.mariadb.jdbc.Driver development.username=john development.password=pwd development.url=jdbc:mysql://localhost/proj_dev test.driver=org.mariadb.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=org.mariadb.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.
-
getTestConnectionConfigs
- Returns:
- list of
ConnectionConfig
objects that are marked for testing.
-
addConnectionConfig(ConnectionConfig)
.