Example usage for org.apache.ibatis.jdbc ScriptRunner setErrorLogWriter

List of usage examples for org.apache.ibatis.jdbc ScriptRunner setErrorLogWriter

Introduction

In this page you can find the example usage for org.apache.ibatis.jdbc ScriptRunner setErrorLogWriter.

Prototype

public void setErrorLogWriter(PrintWriter errorLogWriter) 

Source Link

Usage

From source file:com.collective.messages.persistence.dao.BaseDataTestCase.java

License:Apache License

public static void runScript(DataSource ds, String resource) throws IOException, SQLException {
    Connection connection = ds.getConnection();
    try {//from   w w w . j ava  2s.c om
        ScriptRunner runner = new ScriptRunner(connection);
        runner.setAutoCommit(true);
        runner.setStopOnError(false);
        runner.setLogWriter(null);
        runner.setErrorLogWriter(null);
        runScript(runner, resource);
    } finally {
        connection.close();
    }
}

From source file:com.daemon.SearchTermTest.java

License:Open Source License

@BeforeClass
public static void prepareDatabase() throws SQLException {
    try {/* w  w  w .ja  v  a 2s  .  c  om*/
        transactor = new Transactor();
        connection = DriverManager.getConnection(transactor.getDbUrl());

        // Prepare database
        Reader reader = Resources.getResourceAsReader("DaemonDump.sql");

        ScriptRunner sr = new ScriptRunner(connection);

        sr.setDelimiter(";");
        sr.setLogWriter(null);
        sr.setErrorLogWriter(null);
        sr.runScript(reader);

        connection.commit();
        reader.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (SQLException sqle) {
        sqle.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        connection.close();
    }
}

From source file:com.daemon.TransactorTest.java

License:Open Source License

@BeforeClass
public static void beforeClass() {
    try {/*from w w w  . j  ava2 s  .c o m*/
        _dbPath = Transactor.DATABASE_PROPERTY_PATH;
        URL url = Resources.getResourceURL("database.properties");
        Transactor.DATABASE_PROPERTY_PATH = URLDecoder.decode(url.getFile(), "UTF-8");
        _trans = new Transactor();
        _trans.connect();

        // Prepare database
        Reader reader = Resources.getResourceAsReader("DaemonDump.sql");

        ScriptRunner sr = new ScriptRunner(_trans.getConnection());

        sr.setDelimiter(";");
        sr.setLogWriter(null);
        sr.setErrorLogWriter(null);
        sr.runScript(reader);

        _trans.getConnection().commit();
        reader.close();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (SQLException sqle) {
        sqle.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.persinity.common.db.SimpleRelDb.java

License:Apache License

private void configure(final ScriptRunner scriptRunner) {
    // All statements are separated by "/" (put on new line as is the Oracle script style)
    scriptRunner.setDelimiter("/");
    scriptRunner.setFullLineDelimiter(true);

    // Abort on error, as once deviated, subsequent stmts may lead the DB to unpredictable state
    scriptRunner.setStopOnError(true);//from  w  w w  .  j  ava 2s.c  o  m

    // Do not auto commit, leave that to the RelDb user
    scriptRunner.setAutoCommit(false);

    // Log script feedback
    // Aways set log writer otherwise it will dump on System.out
    scriptRunner.setLogWriter(new PrintWriter(new Log4jOutputStream(log.getLogger(), Level.DEBUG)));
    scriptRunner.setErrorLogWriter(new PrintWriter(new Log4jOutputStream(log.getLogger(), Level.ERROR)));
}

From source file:com.restservice.serviceLogic.test.IntegrationTest.java

License:Open Source License

@BeforeClass
public static void resetDatabase() {
    properties = new File(System.getProperty("user.home") + "/database_test.properties");
    // Check if properties file exists. Tests don't start if it doesn't.
    if (!properties.isFile()) {
        fail("No test database properties file found at: " + properties.getPath());
    }//from w w w .  ja v  a  2  s .  c  o m

    FileInputStream fis = null;

    try {
        // initialize transactor and services with this file
        transactor = new Transactor(properties.getPath());
        queryService = new QueryService(properties.getPath());
        resultService = new ResultService(properties.getPath());

        Properties props = new Properties();
        fis = new FileInputStream(properties.getPath());
        props.load(fis);
        if (!props.containsKey("database.name")) {
            fail("Please add a database.name setting to your local database.properties file");
        }

        Class.forName(props.getProperty("javabase.jdbc.driver"));

        String dbUrl = props.getProperty("javabase.jdbc.url") + "?user="
                + props.getProperty("javabase.jdbc.username") + "&password="
                + props.getProperty("javabase.jdbc.password");

        Path path = Paths.get("src/test/resources/Dump.sql");
        Path newPath = Paths.get("src/test/resources/LocalDump.sql");
        Charset charset = StandardCharsets.UTF_8;

        String content = new String(Files.readAllBytes(path), charset);

        content = content.replaceAll("resttest", props.getProperty("database.name"));
        Files.write(newPath, content.getBytes(charset));

        Reader reader = Resources.getResourceAsReader("LocalDump.sql");

        Connection connection = DriverManager.getConnection(dbUrl);

        ScriptRunner sr = new ScriptRunner(connection);

        sr.setDelimiter(";");
        sr.setLogWriter(null);
        sr.setErrorLogWriter(null);
        sr.runScript(reader);

        connection.commit();
        reader.close();
    } catch (SQLException sqle) {
        sqle.printStackTrace();
        fail("fail");
    } catch (Exception e) {
        fail(e.getMessage());
    } finally {
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}

From source file:org.b3mn.poem.data.defaults.DataDefaults.java

License:Open Source License

public static void all() {
    try {/* ww w  . j a  va  2 s.c  o  m*/
        //-- Check if already initialized
        Identity rootowner = Identity.instance("ownership");
        if (rootowner == null) {
            //-- Reset DB
            Reader reader = Resources.getResourceAsReader("org/b3mn/poem/tests/myibitis-config.xml");
            SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
            reader.close();

            SqlSession session = sqlSessionFactory.openSession();
            Connection conn = session.getConnection();
            reader = Resources.getResourceAsReader("org/b3mn/poem/defaults/test_reset_mysql_db_schema.sql");
            ScriptRunner runner = new ScriptRunner(conn);
            runner.setErrorLogWriter(null);
            runner.runScript(reader);
            reader.close();

            reader = Resources.getResourceAsReader("org/b3mn/poem/defaults/test_data.sql");
            runner = new ScriptRunner(conn);
            runner.setErrorLogWriter(null);
            runner.runScript(reader);
            reader.close();

            session.close();

            //-- Add test model/template
            String title = "Job #1";
            String type = "http://b3mn.org/stencilset/reporting#";
            String summary = "";
            User user = new User("public");

            URL testfile = DataDefaults.class.getResource("/data/newmodelhandler/test1_svg.xml");
            File file = new File(testfile.toURI());
            String svg = FileUtils.readFileToString(file, "UTF-8");

            testfile = DataDefaults.class.getResource("/data/newmodelhandler/test1_content_json.txt");
            file = new File(testfile.toURI());
            String data = FileUtils.readFileToString(file, "UTF-8");

            Identity.newModel(user.getIdentity(), title, type, summary, svg, data);
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    /*      createIdentities();
          createInterations();
          createSettings();
          createStructures();*/
}

From source file:org.mybatis.scripting.freemarker.CustomizedDataContextTest.java

License:Apache License

@BeforeAll
public static void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");

    JDBCDataSource dataSource = new JDBCDataSource();
    dataSource.setUrl("jdbc:hsqldb:mem:db4");
    dataSource.setUser("sa");
    dataSource.setPassword("");

    try (Connection conn = dataSource.getConnection()) {
        try (Reader reader = Resources.getResourceAsReader("org/mybatis/scripting/freemarker/create-db.sql")) {
            ScriptRunner runner = new ScriptRunner(conn);
            runner.setLogWriter(null);/*from   w w w. j a  v  a 2 s .  co  m*/
            runner.setErrorLogWriter(null);
            runner.runScript(reader);
            conn.commit();
        }
    }

    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("development", transactionFactory, dataSource);

    // You can call configuration.setDefaultScriptingLanguage(FreeMarkerLanguageDriver.class)
    // after this to use FreeMarker driver by default.
    Configuration configuration = new Configuration(environment);

    configuration.addMapper(CustomizedDataContextMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}

From source file:org.mybatis.scripting.freemarker.FreeMarkerInAnnotationsTest.java

License:Apache License

@BeforeAll
public static void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");

    JDBCDataSource dataSource = new JDBCDataSource();
    dataSource.setUrl("jdbc:hsqldb:mem:db1");
    dataSource.setUser("sa");
    dataSource.setPassword("");

    try (Connection conn = dataSource.getConnection()) {
        try (Reader reader = Resources.getResourceAsReader("org/mybatis/scripting/freemarker/create-db.sql")) {
            ScriptRunner runner = new ScriptRunner(conn);
            runner.setLogWriter(null);//from w  ww . j av  a  2  s .  c  om
            runner.setErrorLogWriter(null);
            runner.runScript(reader);
            conn.commit();
        }
    }

    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("development", transactionFactory, dataSource);

    // You can call configuration.setDefaultScriptingLanguage(FreeMarkerLanguageDriver.class)
    // after this to use FreeMarker driver by default.
    Configuration configuration = new Configuration(environment);

    configuration.addMapper(NameMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}

From source file:org.mybatis.scripting.freemarker.FreeMarkerInXmlTest.java

License:Apache License

@BeforeAll
public static void setUp() throws Exception {
    Connection conn = null;/*  www.  ja  v a2  s  .  co  m*/

    try {
        Class.forName("org.hsqldb.jdbcDriver");
        conn = DriverManager.getConnection("jdbc:hsqldb:mem:db2", "sa", "");

        Reader reader = Resources.getResourceAsReader("org/mybatis/scripting/freemarker/create-db.sql");

        ScriptRunner runner = new ScriptRunner(conn);
        runner.setLogWriter(null);
        runner.setErrorLogWriter(null);
        runner.runScript(reader);
        conn.commit();
        reader.close();

        reader = Resources.getResourceAsReader("org/mybatis/scripting/freemarker/mapper-config.xml");
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        reader.close();
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}

From source file:org.mybatis.scripting.freemarker.PreparedParamsTest.java

License:Apache License

@BeforeAll
public static void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");

    JDBCDataSource dataSource = new JDBCDataSource();
    dataSource.setUrl("jdbc:hsqldb:mem:db3");
    dataSource.setUser("sa");
    dataSource.setPassword("");

    try (Connection conn = dataSource.getConnection()) {
        try (Reader reader = Resources.getResourceAsReader("org/mybatis/scripting/freemarker/create-db.sql")) {
            ScriptRunner runner = new ScriptRunner(conn);
            runner.setLogWriter(null);/* w ww . j  a  v a 2 s. com*/
            runner.setErrorLogWriter(null);
            runner.runScript(reader);
            conn.commit();
        }
    }

    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("development", transactionFactory, dataSource);

    // You can call configuration.setDefaultScriptingLanguage(FreeMarkerLanguageDriver.class)
    // after this to use FreeMarker driver by default.
    Configuration configuration = new Configuration(environment);

    configuration.addMapper(PreparedParamsMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}