Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,18 @@ private void createTableIfNotExists(String tableName, String... sqls) throws SQL
} else {
try (Statement statement = connection.createStatement();
ResultSet cntRs = statement.executeQuery(sqlProvider.getCountJournalRecordsSQL())) {
if (rs.next() && rs.getInt(1) > 0) {
int rows;
if (cntRs.next() && (rows = cntRs.getInt(1)) > 0) {
logger.tracef("Table %s did exist but is not empty. Skipping initialization.", tableName);
if (logger.isDebugEnabled()) {
final long expectedRows = Stream.of(sqls).map(String::toUpperCase).filter(sql -> sql.contains("INSERT INTO")).count();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure you meant this INSERT to only happen if debug?

Copy link
Copy Markdown
Contributor Author

@franz1981 franz1981 Apr 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, I meant that the check should be performed only with debug log level to help spotting weird behaviours.
It is not the most robust check ever, but it is pretty helpfull for HA (for example).

Copy link
Copy Markdown
Contributor Author

@franz1981 franz1981 Apr 5, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clebertsuconic Please do not merge it yet...because on DB2 it is creating some problems.
I will close it to avoid being merged accidentally 👍

if (rows < expectedRows) {
logger.debug("Table " + tableName + " was expected to contain " + expectedRows + " rows while it has " + rows + " rows.");
}
}
return;
} else {
assert sqls[0].toUpperCase().contains("CREATE TABLE") : "The first SQL statement must be a CREATE TABLE";
sqls = Arrays.copyOfRange(sqls, 1, sqls.length);
}
}
Expand Down