Github user nlippke commented on a diff in the pull request:

    https://github.com/apache/activemq-artemis/pull/1822#discussion_r178460259
  
    --- Diff: 
artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/AbstractJDBCDriver.java
 ---
    @@ -189,17 +187,27 @@ private static void createTableIfNotExists(Connection 
connection,
                    if (sqlWarning != null) {
                       logger.warn(JDBCUtils.appendSQLExceptionDetails(new 
StringBuilder(), sqlWarning));
                    }
    -               try (Statement statement = connection.createStatement()) {
    -                  for (String sql : sqls) {
    -                     statement.executeUpdate(sql);
    -                     final SQLWarning statementSqlWarning = 
statement.getWarnings();
    -                     if (statementSqlWarning != null) {
    -                        
logger.warn(JDBCUtils.appendSQLExceptionDetails(new StringBuilder(), 
statementSqlWarning, sql));
    -                     }
    +            } else {
    +               try (Statement statement = connection.createStatement();
    +                     ResultSet cntRs = 
statement.executeQuery(sqlProvider.getCountJournalRecordsSQL())) {
    +                  if (rs.next() && rs.getInt(1) > 0) {
    --- End diff --
    
    @franz1981, @clebertsuconic: Indeed, the branch was broken. I've fixed it 
with the following patch:
    ~~~
    --- 
a/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/AbstractJDBCDriver.java
    +++ 
b/artemis-jdbc-store/src/main/java/org/apache/activemq/artemis/jdbc/store/drivers/AbstractJDBCDriver.java
    @@ -190,8 +190,9 @@ public abstract class AbstractJDBCDriver {
                 } else {
                    try (Statement statement = connection.createStatement();
                          ResultSet cntRs = 
statement.executeQuery(sqlProvider.getCountJournalRecordsSQL())) {
    -                  if (rs.next() && rs.getInt(1) > 0) {
    +                  if (cntRs.next() && cntRs.getInt(1) > 0) {
                          logger.tracef("Table %s did exist but is not empty. 
Skipping initialization.", tableName);
    +                     return;
                       } else {
                          sqls = Arrays.copyOfRange(sqls, 1, sqls.length);
                       }
    ~~~
    With this patch the tests run fine and I do not get those PK violations 
anymore. Please have look.


---

Reply via email to