/** * 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)); } }
/** * This method is used internally by framework. * * @param spec specification for a JDBC connection. */ private DB openJdbc(ConnectionJdbcSpec spec) { if(spec.getProps()!= null){ return open(spec.getDriver(), spec.getUrl(), spec.getProps()); }else{ return open(spec.getDriver(), spec.getUrl(), spec.getUser(), spec.getPassword()); } }
/** * This method is used internally by framework. * * @param spec specification for a JDBC connection. */ private DB openJdbc(ConnectionJdbcSpec spec) { if(spec.getProps()!= null){ return open(spec.getDriver(), spec.getUrl(), spec.getProps()); }else{ return open(spec.getDriver(), spec.getUrl(), spec.getUser(), spec.getPassword()); } }
private void loadConnectionsSpecs() { try{ String propertyFileName = properties == null ? "database.properties" : properties.getProperty(PropertyName.EnvConnectionsFile.name, "database.properties"); Properties connectionProps = readPropertyFile(propertyFileName); for (String env : getEnvironments(connectionProps)) { String jndiName = env + "." + "jndi"; if (connectionProps.containsKey(jndiName)) { connectionSpecMap.put(env, new ConnectionJndiSpec(connectionProps.getProperty(jndiName))); } else { String driver = connectionProps.getProperty(env + ".driver"); String userName = connectionProps.getProperty(env + ".username"); String password = connectionProps.getProperty(env + ".password"); String url = connectionProps.getProperty(env + ".url"); if (driver == null || userName == null || password == null || url == null) { throw new InitException("Four JDBC properties are expected: driver, username, password, url for environment: " + env); } connectionSpecMap.put(env, new ConnectionJdbcSpec(driver, url, userName, password)); } } }catch(Exception e){ // in case property file not found, do nothing } overrideFromEnvironmentVariables(); overrideFromSystemProperties(); }
/** * 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)); } }
private void createJdbcWrapper(String env, String driver, String url, String userName, String password) { ConnectionSpecWrapper wrapper = new ConnectionSpecWrapper(); if(env.equals("test")){ wrapper.setEnvironment("development"); wrapper.setTesting(true); } else if(env.endsWith(".test")) { wrapper.setEnvironment(env.split("\\.")[0]); wrapper.setTesting(true); }else{ wrapper.setEnvironment(env); } ConnectionJdbcSpec connectionSpec = new ConnectionJdbcSpec(driver, url, userName, password); wrapper.setConnectionSpec(connectionSpec); addConnectionWrapper(wrapper, false); }
/** * Configure expanded JDBC parameters for opening a connection if needed * @param driver class name of driver * @param url JDBC URL * @param props properties with additional parameters a driver can take. */ public void jdbc(String driver, String url, Properties props) { connectionWrapper.setConnectionSpec(new ConnectionJdbcSpec(driver, url, props)); }
/** * Configure standard JDBC parameters for opening a connection. * * @param driver class name of driver * @param url JDBC URL * @param user user name * @param password password */ public void jdbc(String driver, String url, String user, String password) { connectionWrapper.setConnectionSpec(new ConnectionJdbcSpec(driver, url, user, password)); }
/** * 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)); } }
private void loadConnectionsSpecs() { try{ String propertyFileName = properties == null ? "database.properties" : properties.getProperty(PropertyName.EnvConnectionsFile.name, "database.properties"); Properties connectionProps = readPropertyFile(propertyFileName); for (String env : getEnvironments(connectionProps)) { String jndiName = env + "." + "jndi"; if (connectionProps.containsKey(jndiName)) { connectionSpecMap.put(env, new ConnectionJndiSpec(connectionProps.getProperty(jndiName))); } else { String driver = connectionProps.getProperty(env + ".driver"); String userName = connectionProps.getProperty(env + ".username"); String password = connectionProps.getProperty(env + ".password"); String url = connectionProps.getProperty(env + ".url"); if (driver == null || userName == null || password == null || url == null) { throw new InitException("Four JDBC properties are expected: driver, username, password, url for environment: " + env); } connectionSpecMap.put(env, new ConnectionJdbcSpec(driver, url, userName, password)); } } }catch(Exception e){ // in case property file not found, do nothing } overrideFromEnvironmentVariables(); overrideFromSystemProperties(); }
private void createJdbcWrapper(String env, String driver, String url, String userName, String password) { ConnectionSpecWrapper wrapper = new ConnectionSpecWrapper(); if(env.equals("test")){ wrapper.setEnvironment("development"); wrapper.setTesting(true); } else if(env.endsWith(".test")) { wrapper.setEnvironment(env.split("\\.")[0]); wrapper.setTesting(true); }else{ wrapper.setEnvironment(env); } ConnectionJdbcSpec connectionSpec = new ConnectionJdbcSpec(driver, url, userName, password); wrapper.setConnectionSpec(connectionSpec); addConnectionWrapper(wrapper, false); }