/** * Finds a connection {@link ConnectionSpec} that corresponds to system properties, * environment variables of <code>database.properties</code> configuration, whichever is found first. * Configuration of system properties overrides environment variables, which overrides * <code>database.properties</code>. * * @return {@link ConnectionSpec} used by {@link DB#open()} to open a "default" connection, as well as {@link Base#open()} methods. */ public ConnectionSpec getCurrentConnectionSpec(){ return getConnectionSpec(getEnvironment()); }
/** * Overrides current environment's connection spec from system properties. */ private void overrideFromSystemProperties() { String url = System.getProperty("activejdbc.url"); String user = System.getProperty("activejdbc.user"); String password = System.getProperty("activejdbc.password"); String driver = System.getProperty("activejdbc.driver"); if(!blank(url) && !blank(user) && !blank(driver)){ connectionSpecMap.put(getEnvironment(), new ConnectionJdbcSpec(driver, url, user, password)); } String jndi = System.getProperty("activejdbc.jndi"); if(!blank(jndi)){ connectionSpecMap.put(getEnvironment(), new ConnectionJndiSpec(jndi)); } }
/** * Overrides current environment's connection spec from system properties. */ private void overrideFromEnvironmentVariables() { String url = System.getenv("ACTIVEJDBC.URL"); String user = System.getenv("ACTIVEJDBC.USER"); String password = System.getenv("ACTIVEJDBC.PASSWORD"); String driver = System.getenv("ACTIVEJDBC.DRIVER"); if(!blank(url) && !blank(user) && !blank(password) && !blank(driver)){ connectionSpecMap.put(getEnvironment(), new ConnectionJdbcSpec(driver, url, user, password)); } String jndi = System.getenv("ACTIVEJDBC.JNDI"); if(!blank(jndi)){ connectionSpecMap.put(getEnvironment(), new ConnectionJndiSpec(jndi)); } }
/** * This method will open a connection defined in the file 'database.properties' located at * root of classpath. The connection picked up from the file is defined by <code>ACTIVE_ENV</code> * environment variable or <code>active_env</code> system property. * If this variable is not defined, it defaults to 'development' environment. * * <p></p> * If there is JUnit on classpath, this method assumes it is running under test, and defaults to 'test'. * * @see Configuration#getEnvironment() */ public DB open(){ Configuration config = Registry.instance().getConfiguration(); ConnectionSpec spec = config.getCurrentConnectionSpec(); if(spec == null){ throw new DBException("Could not find configuration in a property file for environment: " + config.getEnvironment() + ". Are you sure you have a database.properties file configured?"); } return open(spec); }
/** * Finds a connection {@link ConnectionSpec} that corresponds to system properties, * environment variables of <code>database.properties</code> configuration, whichever is found first. * Configuration of system properties overrides environment variables, which overrides * <code>database.properties</code>. * * @return {@link ConnectionSpec} used by {@link DB#open()} to open a "default" connection, as well as {@link Base#open()} methods. */ public ConnectionSpec getCurrentConnectionSpec(){ return getConnectionSpec(getEnvironment()); }
/** * Overrides current environment's connection spec from system properties. */ private void overrideFromEnvironmentVariables() { String url = System.getenv("ACTIVEJDBC.URL"); String user = System.getenv("ACTIVEJDBC.USER"); String password = System.getenv("ACTIVEJDBC.PASSWORD"); String driver = System.getenv("ACTIVEJDBC.DRIVER"); if(!blank(url) && !blank(user) && !blank(password) && !blank(driver)){ connectionSpecMap.put(getEnvironment(), new ConnectionJdbcSpec(driver, url, user, password)); } String jndi = System.getenv("ACTIVEJDBC.JNDI"); if(!blank(jndi)){ connectionSpecMap.put(getEnvironment(), new ConnectionJndiSpec(jndi)); } }
/** * Overrides current environment's connection spec from system properties. */ private void overrideFromSystemProperties() { String url = System.getProperty("activejdbc.url"); String user = System.getProperty("activejdbc.user"); String password = System.getProperty("activejdbc.password"); String driver = System.getProperty("activejdbc.driver"); if(!blank(url) && !blank(user) && !blank(password) && !blank(driver)){ connectionSpecMap.put(getEnvironment(), new ConnectionJdbcSpec(driver, url, user, password)); } String jndi = System.getProperty("activejdbc.jndi"); if(!blank(jndi)){ connectionSpecMap.put(getEnvironment(), new ConnectionJndiSpec(jndi)); } }
/** * This method will open a connection defined in the file 'database.properties' located at * root of classpath. The connection picked up from the file is defined by <code>ACTIVE_ENV</code> * environment variable or <code>active_env</code> system property. * If this variable is not defined, it defaults to 'development' environment. * * <p></p> * If there is JUnit on classpath, this method assumes it is running under test, and defaults to 'test'. * * @see Configuration#getEnvironment() */ public DB open(){ Configuration config = Registry.instance().getConfiguration(); ConnectionSpec spec = config.getCurrentConnectionSpec(); if(spec == null){ throw new DBException("Could not find configuration in a property file for environment: " + config.getEnvironment() + ". Are you sure you have a database.properties file configured?"); } return open(spec); }