Java Code Examples for org.apache.ibatis.jdbc.ScriptRunner#setAutoCommit()

The following examples show how to use org.apache.ibatis.jdbc.ScriptRunner#setAutoCommit() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchemaInitSystemStrategy.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("AlibabaRemoveCommentedCode")
    public ScriptRunner getScriptRunner() {
        try {
            Connection connection = this.dataSource.getConnection();
            ScriptRunner runner = new ScriptRunner(connection);
            runner.setAutoCommit(false);
            //遇见错误是否停止
            runner.setStopOnError(true);
            /*
             * 按照那种方式执行 方式一:true则获取整个脚本并执行; 方式二:false则按照自定义的分隔符每行执行;
             */
            runner.setSendFullScript(true);
            // 设置是否输出日志,null不输出日志,不设置自动将日志输出到控制台
            // runner.setLogWriter(null);

            Resources.setCharset(Charset.forName("UTF8"));

//            设置分隔符 runner.setDelimiter(";");
            runner.setFullLineDelimiter(false);
            return runner;
        } catch (Exception ex) {
            throw new BizException(-1, "获取连接失败");
        }
    }
 
Example 2
Source File: SchemaInitSystemStrategy.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("AlibabaRemoveCommentedCode")
    public ScriptRunner getScriptRunner() {
        try {
            Connection connection = this.dataSource.getConnection();
            ScriptRunner runner = new ScriptRunner(connection);
            runner.setAutoCommit(false);
            //遇见错误是否停止
            runner.setStopOnError(true);
            /*
             * 按照那种方式执行 方式一:true则获取整个脚本并执行; 方式二:false则按照自定义的分隔符每行执行;
             */
            runner.setSendFullScript(true);
            // 设置是否输出日志,null不输出日志,不设置自动将日志输出到控制台
            // runner.setLogWriter(null);

            Resources.setCharset(Charset.forName("UTF8"));

//            设置分隔符 runner.setDelimiter(";");
            runner.setFullLineDelimiter(false);
            return runner;
        } catch (Exception ex) {
            throw new BizException(-1, "获取连接失败");
        }
    }
 
Example 3
Source File: BartDBMSUtility.java    From BART with MIT License 6 votes vote down vote up
public static void createDB(AccessConfiguration accessConfiguration) {
        AccessConfiguration tempAccessConfiguration = getTempAccessConfiguration(accessConfiguration);
        Connection connection = null;
        try {
            if (logger.isDebugEnabled()) logger.debug("Creating db: " + accessConfiguration);
//            connection = new SimpleDbConnectionFactory().getConnection(tempAccessConfiguration);
            connection = simpleDataSourceDB.getConnection(tempAccessConfiguration);
//            connection = QueryManager.getConnection(tempAccessConfiguration);
            String createQuery = "create database " + accessConfiguration.getDatabaseName() + ";";
            ScriptRunner scriptRunner = getScriptRunner(connection);
            scriptRunner.setAutoCommit(true);
            scriptRunner.setStopOnError(true);
            scriptRunner.runScript(new StringReader(createQuery));
        } catch (Exception daoe) {
            throw new DBMSException("Unable to create new database " + accessConfiguration.getDatabaseName() + ".\n" + tempAccessConfiguration + "\n" + daoe.getLocalizedMessage());
        } finally {
            QueryManager.closeConnection(connection);
        }
    }
 
Example 4
Source File: BartDBMSUtility.java    From BART with MIT License 6 votes vote down vote up
public static void deleteDB(AccessConfiguration accessConfiguration) {
        String script = "DROP DATABASE " + accessConfiguration.getDatabaseName() + ";\n";
        AccessConfiguration tempAccessConfiguration = getTempAccessConfiguration(accessConfiguration);
        Connection connection = null;
        try {
            if (logger.isDebugEnabled()) logger.debug("Deleting db: " + accessConfiguration);
//            connection = new SimpleDbConnectionFactory().getConnection(tempAccessConfiguration);
            connection = simpleDataSourceDB.getConnection(tempAccessConfiguration);
//            connection = QueryManager.getConnection(tempAccessConfiguration);
            ScriptRunner scriptRunner = getScriptRunner(connection);
            scriptRunner.setAutoCommit(true);
            scriptRunner.setStopOnError(true);
            scriptRunner.runScript(new StringReader(script));
        } catch (Exception daoe) {
            throw new DBMSException("Unable to drop database " + accessConfiguration.getDatabaseName() + ".\n" + tempAccessConfiguration + "\n" + daoe.getLocalizedMessage());
        } finally {
            QueryManager.closeConnection(connection);
        }
    }
 
Example 5
Source File: BaseDataTest.java    From mybatis-typehandlers-postgis with Do What The F*ck You Want To Public License 5 votes vote down vote up
public static void runScript(DataSource ds, String resource) throws IOException, SQLException {
    Connection connection = ds.getConnection();
    try {
        ScriptRunner runner = new ScriptRunner(connection);
        runner.setAutoCommit(true);
        runner.setStopOnError(false);
        runner.setLogWriter(null);
        runner.setErrorLogWriter(null);
        runScript(runner, resource);
    } finally {
        connection.close();
    }
}
 
Example 6
Source File: GossipDataSourceProvider.java    From gossip with MIT License 5 votes vote down vote up
private void executeSQL(Connection connection, Reader reader) throws SQLException {
    ScriptRunner runner = new ScriptRunner(connection);
    runner.setAutoCommit(true);
    runner.setStopOnError(true);

    try {
        runner.runScript(reader);
    } catch (RuntimeSqlException e) {
        throw new SQLException(e); // Force to handle the exception by myself
    }
}
 
Example 7
Source File: MyBatisTestHelper.java    From gossip with MIT License 5 votes vote down vote up
@SneakyThrows
private static void loadInitializeData(Injector injector, Reader reader) {
    DataSource dataSource = injector.getInstance(DataSource.class);

    try (final Connection connection = dataSource.getConnection()) {
        ScriptRunner runner = new ScriptRunner(connection);
        runner.setAutoCommit(true);
        runner.setStopOnError(true);
        runner.runScript(reader);
    } // Auto close connection
}
 
Example 8
Source File: MultipleResultSetTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private static void runReaderScript(Connection conn, SqlSession session, Reader reader) throws Exception {
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.setSendFullScript(true);
  runner.setAutoCommit(true);
  runner.setStopOnError(false);
  runner.runScript(reader);
}
 
Example 9
Source File: BaseDataTest.java    From mybaties with Apache License 2.0 5 votes vote down vote up
public static void runScript(DataSource ds, String resource) throws IOException, SQLException {
  Connection connection = ds.getConnection();
  try {
    ScriptRunner runner = new ScriptRunner(connection);
    runner.setAutoCommit(true);
    runner.setStopOnError(false);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runScript(runner, resource);
  } finally {
    connection.close();
  }
}
 
Example 10
Source File: MultipleResultSetTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private static void runReaderScript(Connection conn, SqlSession session, Reader reader) throws Exception {
  ScriptRunner runner = new ScriptRunner(conn);
  runner.setLogWriter(null);
  runner.setSendFullScript(true);
  runner.setAutoCommit(true);
  runner.setStopOnError(false);
  runner.runScript(reader);
}
 
Example 11
Source File: BaseDataTest.java    From mybatis with Apache License 2.0 5 votes vote down vote up
public static void runScript(DataSource ds, String resource) throws IOException, SQLException {
  Connection connection = ds.getConnection();
  try {
    ScriptRunner runner = new ScriptRunner(connection);
    runner.setAutoCommit(true);
    runner.setStopOnError(false);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runScript(runner, resource);
  } finally {
    connection.close();
  }
}
 
Example 12
Source File: MyBatisPluginTest.java    From HotswapAgent with GNU General Public License v2.0 5 votes vote down vote up
private static void runScript(DataSource ds, String resource) throws IOException, SQLException {
    try (Connection connection = ds.getConnection()) {
        ScriptRunner runner = new ScriptRunner(connection);
        runner.setAutoCommit(true);
        runner.setStopOnError(false);
        runner.setLogWriter(null);
        runner.setErrorLogWriter(null);
        runScript(runner, resource);
    }
}