/** /** * Runs an SQL script (read in using the Reader parameter). * * @param reader * - the source of the script * @throws SQLException * if any SQL errors occur * @throws IOException * if there is an error reading from the Reader */ public void runScript(Reader reader) throws IOException, SQLException { try { boolean originalAutoCommit = connection.getAutoCommit(); try { if (originalAutoCommit != autoCommit) { connection.setAutoCommit(autoCommit); } runScript(connection, reader); } finally { connection.setAutoCommit(originalAutoCommit); } } catch (IOException | SQLException e) { throw e; } catch (Exception e) { throw new RuntimeException("Error running script. Cause: " + e, e); } }
/** /** * Runs an SQL script (read in using the Reader parameter). * * @param reader * - the source of the script * @throws SQLException * if any SQL errors occur * @throws IOException * if there is an error reading from the Reader */ public void runScript(Reader reader) throws IOException, SQLException { try { boolean originalAutoCommit = connection.getAutoCommit(); try { if (originalAutoCommit != autoCommit) { connection.setAutoCommit(autoCommit); } runScript(connection, reader); } finally { connection.setAutoCommit(originalAutoCommit); } } catch (IOException | SQLException e) { throw e; } catch (Exception e) { throw new RuntimeException("Error running script. Cause: " + e, e); } }
@Override protected void createIndexes() throws SQLException { try { ScriptRunner runner = new ScriptRunner(connection.getJDBCConnection(), false, false); StringBuilder script = new StringBuilder(); for(String line : IOUtils.readLines(KiWiPostgresHandler.class.getResourceAsStream("create_indexes.sql"))) { if(!line.startsWith("--")) { script.append(line); script.append(" "); } } log.debug("PostgreSQL: running SQL script '{}'", script.toString()); runner.runScript(new StringReader(script.toString())); } catch (IOException ex) { throw new SQLException("error while creating indexes",ex); } }
@Override protected void dropIndexes() throws SQLException { try { ScriptRunner runner = new ScriptRunner(connection.getJDBCConnection(), false, false); StringBuilder script = new StringBuilder(); for(String line : IOUtils.readLines(KiWiPostgresHandler.class.getResourceAsStream("drop_indexes.sql"))) { if(!line.startsWith("--")) { script.append(line); script.append(" "); } } log.debug("PostgreSQL: running SQL script '{}'", script.toString()); runner.runScript(new StringReader(script.toString())); } catch (IOException ex) { throw new SQLException("error while dropping indexes",ex); } }
@Override protected void dropIndexes() throws SQLException { try { ScriptRunner runner = new ScriptRunner(connection.getJDBCConnection(), false, false); StringBuilder script = new StringBuilder(); for(String line : IOUtils.readLines(KiWiPostgresHandler.class.getResourceAsStream("drop_indexes.sql"))) { if(!line.startsWith("--")) { script.append(line); script.append(" "); } } log.debug("PostgreSQL: running SQL script '{}'", script.toString()); runner.runScript(new StringReader(script.toString())); } catch (IOException ex) { throw new SQLException("error while dropping indexes",ex); } }
@Override protected void createIndexes() throws SQLException { try { ScriptRunner runner = new ScriptRunner(connection.getJDBCConnection(), false, false); StringBuilder script = new StringBuilder(); for(String line : IOUtils.readLines(KiWiPostgresHandler.class.getResourceAsStream("create_indexes.sql"))) { if(!line.startsWith("--")) { script.append(line); script.append(" "); } } log.debug("PostgreSQL: running SQL script '{}'", script.toString()); runner.runScript(new StringReader(script.toString())); } catch (IOException ex) { throw new SQLException("error while creating indexes",ex); } }
runner.runScript(new StringReader(script.toString())); String script_lang = script.toString().replaceAll("@LANGUAGE@", lang).replaceAll("@CONFIGURATION@", pg_configuration); log.debug("PostgreSQL: running SQL script '{}'", script_lang); runner.runScript(new StringReader(script_lang)); runner.runScript(new StringReader(script.toString()));
runner.runScript(new StringReader(configuration.getDialect().getDropScript(scriptName)));
runner.runScript(new StringReader(configuration.getDialect().getDropScript(scriptName)));