return new DBCPDataSource(dataSource);
@Override public Object unwrap(Class c) throws SQLException { if (isWrapperFor(c)) { return getWrapped(); } return null; } }
public void tearDown() throws Exception { final String leakMessage = "Expected no active connection, either there is a connection leak " + "or you forgot to close some object holding onto connections in the tests (e.g., a reader, an iterator)"; if (dataSource instanceof BasicDataSource) { BasicDataSource bds = (BasicDataSource) dataSource; assertEquals(leakMessage, 0, bds.getNumActive()); } else if (dataSource instanceof DBCPDataSource) { BasicDataSource bds = (BasicDataSource) ((DBCPDataSource) dataSource).getWrapped(); assertEquals(leakMessage, 0, bds.getNumActive()); } if (dataSource instanceof BasicDataSource) { BasicDataSource bds = (BasicDataSource) dataSource; bds.close(); } else if (dataSource instanceof ManageableDataSource) { ((ManageableDataSource) dataSource).close(); } }
username = ((BasicDataSource) ((DBCPDataSource) dataSource).unwrap(DataSource.class)) .getUsername(); } catch (SQLException e) {
protected DataSource createDataSource(Map params, SQLDialect dialect) throws IOException { BasicDataSource dataSource = new BasicDataSource(); dataSource.setUrl(getJDBCUrl(params)); String username = (String) USER.lookUp(params); if (username != null) { dataSource.setUsername(username); } String password = (String) PASSWD.lookUp(params); if (password != null) { dataSource.setPassword(password); } dataSource.setDriverClassName("org.h2.Driver"); dataSource.setPoolPreparedStatements(false); return new DBCPDataSource(dataSource); }
@Override public Object unwrap(Class c) throws SQLException { if (isWrapperFor(c)) { return getWrapped(); } return null; } }
/** * Creates a data source by reading properties from a file called 'db.properties', located * paralell to the test setup instance. */ protected DataSource createDataSource() throws IOException { Properties db = fixture; BasicDataSource dataSource = new BasicDataSource(); dataSource.setDriverClassName(db.getProperty("driver")); dataSource.setUrl(db.getProperty("url")); if (db.containsKey("user")) { dataSource.setUsername(db.getProperty("user")); } else if (db.containsKey("username")) { dataSource.setUsername(db.getProperty("username")); } if (db.containsKey("password")) { dataSource.setPassword(db.getProperty("password")); } dataSource.setPoolPreparedStatements(true); dataSource.setAccessToUnderlyingConnectionAllowed(true); dataSource.setMinIdle(1); dataSource.setMaxActive(4); // if we cannot get a connection within 5 seconds give up dataSource.setMaxWait(5000); initializeDataSource(dataSource, db); // return a closeable data source (DisposableDataSource interface) // so that the connection pool will be tore down on datastore dispose return new DBCPDataSource(dataSource); }
return new DBCPDataSource(dataSource);
return new DBCPDataSource(dataSource);
dataSource.setPoolPreparedStatements(false); return new DBCPDataSource(dataSource);
return new DBCPDataSource(dataSource);
return new DBCPDataSource(dataSource);
return new DBCPDataSource(dataSource);