Skip to content

Commit

Permalink
Revert DB setup to the connection method
Browse files Browse the repository at this point in the history
Since DB could be not available before the connection the setup is moved
back to the connection method.
  • Loading branch information
fmarco76 committed Sep 25, 2024
1 parent 142568c commit 5f28b99
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,18 @@ public void initInternal () throws LifecycleException {
if (saltLength != null) {
handler.setSaltLength(Integer.parseInt(saltLength));
}

String createFile = info.getProperty("dbcreate.file");
if (createFile != null) {
try{
connect();
setup(createFile);
} catch (Exception e) {
throw new LifecycleException("DB creation failed. Creation file: " + createFile, e);
}
}

}

/**
* This method will create the tables if they do not exist.
*/
public void setup(String createFile) throws Exception {
public void setup() throws Exception {

logger.info("Setting up PostgreSQL realm");

String createFile = info.getProperty("dbcreate.file");
if (createFile == null) {
return;
}
String content = new String(Files.readAllBytes(Paths.get(createFile)));

String[] stats = content.split(";");
Expand Down Expand Up @@ -179,6 +171,7 @@ public void connect() throws Exception {
if (connection == null) { // create the initial connection
logger.info("Connecting to " + url);
connection = DriverManager.getConnection(url, info);
setup();
return;
}

Expand Down

0 comments on commit 5f28b99

Please sign in to comment.