public abstract class AbstractDBConfig extends DBConfiguration implements InitConfig
app.config.DbConfig
.
It is used to configure database connections for various environments and modes.
ACTIVE_ENV
is not provided, the framework defaults to "development".
1. public class DbConfig extends AbstractDBConfig { 2. public void init() { 3. environment("development").jndi("jdbc/kitchensink_development"); 4. environment("development").testing().jdbc("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/kitchensink_test", "root", "****"); 5. environment("hudson").testing().jdbc("com.mysql.jdbc.Driver", "jdbc:mysql://172.30.64.31/kitchensink_test", "root", "****"); 6. environment("production").jndi("jdbc/kitchensink_production"); 7. } 8.}The code above is an example from Kitchensink project. Lets examine it line by line.
Constructor and Description |
---|
AbstractDBConfig() |
Modifier and Type | Method and Description |
---|---|
void |
configFile(String file)
Configures multiple database connections from a single property file.
|
ConnectionBuilder |
environment(String environment) |
ConnectionBuilder |
environment(String environment,
boolean override) |
addConnectionConfig, addConnectionConfig, clearConnectionConfigs, clearConnectionConfigs, getConnectionConfigs, getConnectionConfigsExceptTesting, getConnectionConfigsForCurrentEnv, getTestConnectionConfigs, loadConfiguration, resetConnectionConfigs
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
completeInit, init
public ConnectionBuilder environment(String environment)
environment
- name of environment (corresponds to env var ACTIVE_ENV)public ConnectionBuilder environment(String environment, boolean override)
environment
- name of environment (corresponds to env var ACTIVE_ENV)override
- not used. Any consecutive configuration will override a previous configuration if the following parameters are the same: DB name, environment, testing.public void configFile(String file)
development.driver=com.mysql.jdbc.Driver development.username=john development.password=pwd development.url=jdbc:mysql://localhost/proj_dev test.driver=com.mysql.jdbc.Driver test.username=mary test.password=pwd1 test.url=jdbc:mysql://localhost/test production.jndi=java:comp/env/jdbc/prodRules and limitations of using a file-based configuration:
environment(String)
file
- path to a file. Can be located on classpath, or on a file system. First searched on classpath,
then on file system.Copyright © 2020 JavaLite. All rights reserved.