/** * Creates a connection to the underlying containerized database instance. * * @param queryString query string parameters that should be appended to the JDBC connection URL. * The '?' character must be included * @return a Connection * @throws SQLException if there is a repeated failure to create the connection */ public Connection createConnection(String queryString) throws SQLException { final Properties info = new Properties(); info.put("user", this.getUsername()); info.put("password", this.getPassword()); final String url = constructUrlForConnection(queryString); final Driver jdbcDriverInstance = getJdbcDriverInstance(); try { return Unreliables.retryUntilSuccess(getConnectTimeoutSeconds(), TimeUnit.SECONDS, () -> DB_CONNECT_RATE_LIMIT.getWhenReady(() -> jdbcDriverInstance.connect(url, info))); } catch (Exception e) { throw new SQLException("Could not create new connection", e); } }
private ResultSet performQuery(JdbcDatabaseContainer container, String sql) throws SQLException { HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setJdbcUrl(container.getJdbcUrl()); hikariConfig.setUsername(container.getUsername()); hikariConfig.setPassword(container.getPassword()); HikariDataSource ds = new HikariDataSource(hikariConfig); Statement statement = ds.getConnection().createStatement(); statement.execute(sql); ResultSet resultSet = statement.getResultSet(); resultSet.next(); return resultSet; } }
@Bean( name = "dhisConfigurationProvider" ) public DhisConfigurationProvider dhisConfigurationProvider() { TestDhisConfigurationProvider dhisConfigurationProvider = new TestDhisConfigurationProvider(); JdbcDatabaseContainer<?> postgreSQLContainer = initContainer(); Properties properties = new Properties(); properties.setProperty( "connection.url", postgreSQLContainer.getJdbcUrl() ); properties.setProperty( "connection.dialect", "org.hisp.dhis.hibernate.dialect.DhisPostgresDialect" ); properties.setProperty( "connection.driver_class", "org.postgresql.Driver" ); properties.setProperty( "connection.username", postgreSQLContainer.getUsername() ); properties.setProperty( "connection.password", postgreSQLContainer.getPassword() ); dhisConfigurationProvider.addProperties( properties ); return dhisConfigurationProvider; }
/** * Creates a connection to the underlying containerized database instance. * * @param queryString query string parameters that should be appended to the JDBC connection URL. * The '?' character must be included * @return a Connection * @throws SQLException if there is a repeated failure to create the connection */ public Connection createConnection(String queryString) throws SQLException { final Properties info = new Properties(); info.put("user", this.getUsername()); info.put("password", this.getPassword()); final String url = constructUrlForConnection(queryString); final Driver jdbcDriverInstance = getJdbcDriverInstance(); try { return Unreliables.retryUntilSuccess(getConnectTimeoutSeconds(), TimeUnit.SECONDS, () -> DB_CONNECT_RATE_LIMIT.getWhenReady(() -> jdbcDriverInstance.connect(url, info))); } catch (Exception e) { throw new SQLException("Could not create new connection", e); } }