Skip to content

Commit

Permalink
Remove the internal ownerConnection() method in favour of getConnecti…
Browse files Browse the repository at this point in the history
…on(un,pw)
  • Loading branch information
rbygrave committed Nov 17, 2023
1 parent d8fa7da commit eccf2f3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void initialiseDatabase() throws SQLException {
} catch (SQLException e) {
Log.info("Obtaining connection using ownerUsername:{0} to initialise database", config.getOwnerUsername());
// expected when user does not exist, obtain a connection using owner credentials
try (Connection ownerConnection = ownerConnection(config.getOwnerUsername(), config.getOwnerPassword())) {
try (Connection ownerConnection = getConnection(config.getOwnerUsername(), config.getOwnerPassword())) {
// initialise the DB (typically create the user/role using the owner credentials etc)
InitDatabase initDatabase = config.getInitDatabase();
initDatabase.run(ownerConnection, config);
Expand Down Expand Up @@ -431,16 +431,6 @@ private Connection initConnection(Connection conn) throws SQLException {
return conn;
}

/**
* Create an un-pooled connection with the given username and password.
*/
private Connection ownerConnection(String username, String password) throws SQLException {
Properties properties = new Properties(connectionProps);
properties.setProperty("user", username);
properties.setProperty("password", password);
return createConnection(properties, true);
}

private Connection createConnection() throws SQLException {
return createConnection(connectionProps, true);
}
Expand All @@ -450,7 +440,7 @@ private Connection createConnection(Properties properties, boolean notifyIsDown)
return initConnection(newConnection(properties));
} catch (SQLException ex) {
if (notifyIsDown) {
notifyDataSourceIsDown(null);
notifyDataSourceIsDown(ex);
}
throw ex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ void test_with_clientInfo() throws SQLException {
// clientInfo.setProperty("ClientHostname", "ci-hostname");

DataSourcePool pool = DataSourceBuilder.create()
.setUrl("jdbc:postgresql://127.0.0.1:9999/app")
.url("jdbc:postgresql://127.0.0.1:9999/app")
// our application credentials (typically same as db and schema name with Postgres)
.setUsername("app")
.setPassword("app_pass")
// database owner credentials used to create the "app" role as needed
.setOwnerUsername("db_owner")
.setOwnerPassword("test")
.setClientInfo(clientInfo)
.username("app")
.password("app_pass")
.ownerUsername("db_owner")
.ownerPassword("test")
.clientInfo(clientInfo)
.build();

try {
Expand Down

0 comments on commit eccf2f3

Please sign in to comment.