private DB open(String driver, String url, String user, String password, Properties properties){ checkExistingConnection(name); try { Class.forName(driver); Connection connection; connection = properties == null ? DriverManager.getConnection(url, user, password) : DriverManager.getConnection(url, properties); LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection); ConnectionsAccess.attach(name, connection, url); return this; } catch (Exception e) { throw new InitException("Failed to connect to JDBC URL: " + url + " with user: " + user, e); } }
/** * Opens a connection from JNDI based on a registered name. This assumes that there is a <code>jndi.properties</code> * file with proper JNDI configuration in it. * * @param jndiName name of a configured data source. */ public DB open(String jndiName) { checkExistingConnection(name); try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(jndiName); Connection connection = ds.getConnection(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection); ConnectionsAccess.attach(name, connection, jndiName); return this; } catch (Exception e) { throw new InitException("Failed to connect to JNDI name: " + jndiName, e); } }
/** * This method is used internally by the framework. * * @param spec specification for a JDBC connection. */ public DB open(ConnectionSpec spec) { checkExistingConnection(name); if (spec instanceof ConnectionJdbcSpec) { return openJdbc((ConnectionJdbcSpec) spec); } else if (spec instanceof ConnectionJndiSpec) { return openJndi((ConnectionJndiSpec) spec); } else if (spec instanceof ConnectionDataSourceSpec) { return openDataSource((ConnectionDataSourceSpec) spec); } else { throw new IllegalArgumentException("this spec not supported: " + spec.getClass()); } }
/** * Opens a connection from a datasource. This methods gives a high level control while sourcing a DB connection. * * @param datasource datasource will be used to acquire a connection. */ public DB open(DataSource datasource) { checkExistingConnection(name); try { Connection connection = datasource.getConnection(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection); ConnectionsAccess.attach(name, connection, datasource.toString()); return this; } catch (SQLException e) { throw new InitException(e); } }
/** * Opens a new connection from JNDI data source by name using explicit JNDI properties. This method can be used in cases * when file <code>jndi.properties</code> cannot be easily updated. * * @param jndiName name of JNDI data source. * @param jndiProperties JNDI properties */ public DB open(String jndiName, Properties jndiProperties) { checkExistingConnection(name); try { Context ctx = new InitialContext(jndiProperties); DataSource ds = (DataSource) ctx.lookup(jndiName); Connection connection = ds.getConnection(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection); ConnectionsAccess.attach(name, connection, jndiProperties.contains("url") ? jndiProperties.getProperty("url") : jndiName); return this; } catch (Exception e) { throw new InitException("Failed to connect to JNDI name: " + jndiName, e); } }
/** * Opens a connection from a datasource. This methods gives a high level control while sourcing a DB connection. * * @param datasource datasource will be used to acquire a connection. */ public void open(DataSource datasource) { checkExistingConnection(name); try { Connection connection = datasource.getConnection(); ConnectionsAccess.attach(name, connection, datasource.toString()); } catch (SQLException e) { throw new InitException(e); } }
/** * Opens a connection from JNDI based on a registered name. This assumes that there is a <code>jndi.properties</code> * file with proper JNDI configuration in it. * * @param jndiName name of a configured data source. */ public void open(String jndiName) { checkExistingConnection(name); try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(jndiName); Connection connection = ds.getConnection(); ConnectionsAccess.attach(name, connection, jndiName); } catch (Exception e) { throw new InitException("Failed to connect to JNDI name: " + jndiName, e); } }
/** * This method is used internally by framework. * * @param spec specification for a JDBC connection. */ public void open(ConnectionSpec spec) { checkExistingConnection(name); if (spec instanceof ConnectionJdbcSpec) { openJdbc((ConnectionJdbcSpec) spec); } else if(spec instanceof ConnectionJndiSpec) { openJndi((ConnectionJndiSpec) spec); } else { throw new IllegalArgumentException("this spec not supported: " + spec.getClass()); } }
/** * Opens a new connection in case additional driver-specific parameters need to be passed in. * * @param driver driver class name * @param url JDBC URL * @param props connection properties */ public void open(String driver, String url, Properties props) { checkExistingConnection(name); try { Class.forName(driver); Connection connection = DriverManager.getConnection(url, props); ConnectionsAccess.attach(name, connection, url); } catch (Exception e) { throw new InitException("Failed to connect to JDBC URL: " + url, e); } }
/** * Opens a new connection based on JDBC properties and attaches it to a current thread. * * @param driver class name of driver * @param url URL connection to DB * @param user user name. * @param password password. */ public void open(String driver, String url, String user, String password) { checkExistingConnection(name); try { Class.forName(driver); Connection connection = DriverManager.getConnection(url, user, password); ConnectionsAccess.attach(name, connection, url); } catch (Exception e) { throw new InitException("Failed to connect to JDBC URL: " + url, e); } }
private DB open(String driver, String url, String user, String password, Properties properties){ checkExistingConnection(name); try { Class.forName(driver); Connection connection; connection = properties == null ? DriverManager.getConnection(url, user, password) : DriverManager.getConnection(url, properties); LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection); ConnectionsAccess.attach(name, connection, url); return this; } catch (Exception e) { throw new InitException("Failed to connect to JDBC URL: " + url, e); } }
/** * Opens a new connection from JNDI data source by name using explicit JNDI properties. This method can be used in cases * when file <code>jndi.properties</code> cannot be easily updated. * * @param jndiName name of JNDI data source. * @param jndiProperties JNDI properties */ public void open(String jndiName, Properties jndiProperties) { checkExistingConnection(name); try { Context ctx = new InitialContext(jndiProperties); DataSource ds = (DataSource) ctx.lookup(jndiName); Connection connection = ds.getConnection(); ConnectionsAccess.attach(name, connection, jndiProperties.contains("url") ? jndiProperties.getProperty("url") : jndiName); } catch (Exception e) { throw new InitException("Failed to connect to JNDI name: " + jndiName, e); } }
/** * Opens a connection from JNDI based on a registered name. This assumes that there is a <code>jndi.properties</code> * file with proper JNDI configuration in it. * * @param jndiName name of a configured data source. */ public DB open(String jndiName) { checkExistingConnection(name); try { Context ctx = new InitialContext(); DataSource ds = (DataSource) ctx.lookup(jndiName); Connection connection = ds.getConnection(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection); ConnectionsAccess.attach(name, connection, jndiName); return this; } catch (Exception e) { throw new InitException("Failed to connect to JNDI name: " + jndiName, e); } }
/** * Opens a connection from a datasource. This methods gives a high level control while sourcing a DB connection. * * @param datasource datasource will be used to acquire a connection. */ public DB open(DataSource datasource) { checkExistingConnection(name); try { Connection connection = datasource.getConnection(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection); ConnectionsAccess.attach(name, connection, datasource.toString()); return this; } catch (SQLException e) { throw new InitException(e); } }
/** * This method is used internally by the framework. * * @param spec specification for a JDBC connection. */ public DB open(ConnectionSpec spec) { checkExistingConnection(name); if (spec instanceof ConnectionJdbcSpec) { return openJdbc((ConnectionJdbcSpec) spec); } else if (spec instanceof ConnectionJndiSpec) { return openJndi((ConnectionJndiSpec) spec); } else if (spec instanceof ConnectionDataSourceSpec) { return openDataSource((ConnectionDataSourceSpec) spec); } else { throw new IllegalArgumentException("this spec not supported: " + spec.getClass()); } }
/** * Opens a new connection from JNDI data source by name using explicit JNDI properties. This method can be used in cases * when file <code>jndi.properties</code> cannot be easily updated. * * @param jndiName name of JNDI data source. * @param jndiProperties JNDI properties */ public DB open(String jndiName, Properties jndiProperties) { checkExistingConnection(name); try { Context ctx = new InitialContext(jndiProperties); DataSource ds = (DataSource) ctx.lookup(jndiName); Connection connection = ds.getConnection(); LogFilter.log(LOGGER, LogLevel.DEBUG, "Opened connection: " + connection); ConnectionsAccess.attach(name, connection, jndiProperties.contains("url") ? jndiProperties.getProperty("url") : jndiName); return this; } catch (Exception e) { throw new InitException("Failed to connect to JNDI name: " + jndiName, e); } }