Thanks Franz, 

this sounds all supi-dupi interesting but has nothing to with the issue. 
It is as simple as I noticed.
>From the code:

JdbcSharedStateManager.java:
protected void createSchema() throws SQLException {
      try {
         createTable(sqlProvider.createNodeManagerStoreTableSQL(),
sqlProvider.createNodeIdSQL(), sqlProvider.createStateSQL(),
sqlProvider.createLiveLockSQL(), sqlProvider.createBackupLockSQL());
      } catch (SQLException e) {
         //no op: if a table already exists is not a problem in this case,
the prepareStatements() call will fail right after it if the table is not
correctly initialized
         if (logger.isDebugEnabled()) {
            logger.debug("Error while creating the schema of the JDBC shared
state manager", e);
         }
      }
   }

Obviously here the table is being created along with some other initial data
import.

Then later in AbstractJDBCDriver.java:

private static void createTableIfNotExists(Connection connection,
                                              String tableName,
                                              String... sqls) throws
SQLException {
      logger.tracef("Validating if table %s didn't exist before creating",
tableName);
      try {
         connection.setAutoCommit(false);
         try (ResultSet rs = connection.getMetaData().getTables(null, null,
tableName, null)) {
            if (rs != null && !rs.next()) {
               if (logger.isTraceEnabled()) {
                  logger.tracef("Table %s did not exist, creating it with
SQL=%s", tableName, Arrays.toString(sqls));
               }
               final SQLWarning sqlWarning = rs.getWarnings();
               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));
                     }
                  }
               }
            }
         }
         connection.commit();
         ...

So if table exists, don't do anything. If it doesn't exist, fill with
initial data.

This implementation could be improved by the case where the table exists,
but is empty which should lead to the same initial setup as the case where
the table does not exist.

Can this be fixed? 

Thanks, 
Archibald



--
Sent from: http://activemq.2283324.n4.nabble.com/ActiveMQ-User-f2341805.html

Reply via email to