public void doCreateTables()

in src/main/java/org/apache/servicemix/jdbc/adapter/DefaultJDBCAdapter.java [65:116]


    public void doCreateTables(Connection connection) throws SQLException, IOException {
        Statement s = null;
        try {
            // Check to see if the table already exists. If it does, then don't
            // log warnings during startup.
            // Need to run the scripts anyways since they may contain ALTER
            // statements that upgrade a previous version of the table
            boolean alreadyExists = false;
            ResultSet rs = null;
            try {
                rs = connection.getMetaData().getTables(null, null, statements.getFullStoreTableName(),
                        new String[] {"TABLE" });
                alreadyExists = rs.next();
            } catch (Throwable ignore) {
                // Do nothing
            } finally {
                close(rs);
            }

            // If the dataSource is a managed DataSource, executing a statement
            // that throws
            // an exception will make the connection unusable.
            // So if the table already exists, do not try to re-create them
            if (alreadyExists) {
                return;
            }

            s = connection.createStatement();
            String[] createStatments = statements.getCreateSchemaStatements();
            for (int i = 0; i < createStatments.length; i++) {
                // This will fail usually since the tables will be
                // created already.
                try {
                    LOG.debug("Executing SQL: " + createStatments[i]);
                    s.execute(createStatments[i]);
                } catch (SQLException e) {
                    if (alreadyExists) {
                        LOG.debug("Could not create JDBC tables; The message table already existed." + " Failure was: "
                                + createStatments[i] + " Message: " + e.getMessage() + " SQLState: " + e.getSQLState()
                                + " Vendor code: " + e.getErrorCode());
                    } else {
                        LOG.warn("Could not create JDBC tables; they could already exist." + " Failure was: "
                                + createStatments[i] + " Message: " + e.getMessage() + " SQLState: " + e.getSQLState()
                                + " Vendor code: " + e.getErrorCode());
                        JDBCAdapterFactory.log("Failure details: ", e);
                    }
                }
            }
        } finally {
            close(s);
        }
    }