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

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

Introduction

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

Prototype

public void setLogWriter(PrintWriter logWriter) 

Source Link

Usage

From source file:examples.joins.JoinMapperTest.java

License:Apache License

@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);//  w  ww.j av a  2s.  c  o m
    InputStream is = getClass().getResourceAsStream("/examples/joins/CreateJoinDB.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }

    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(JoinMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}

From source file:examples.paging.LimitAndOffsetTest.java

License:Apache License

@BeforeEach
public void setup() throws Exception {
    Class.forName(JDBC_DRIVER);//from ww  w. j ava  2s  . com
    InputStream is = getClass().getResourceAsStream("/examples/animal/data/CreateAnimalData.sql");
    try (Connection connection = DriverManager.getConnection(JDBC_URL, "sa", "")) {
        ScriptRunner sr = new ScriptRunner(connection);
        sr.setLogWriter(null);
        sr.runScript(new InputStreamReader(is));
    }

    UnpooledDataSource ds = new UnpooledDataSource(JDBC_DRIVER, JDBC_URL, "sa", "");
    Environment environment = new Environment("test", new JdbcTransactionFactory(), ds);
    Configuration config = new Configuration(environment);
    config.addMapper(LimitAndOffsetMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
}

From source file:optional.OptionalTest.java

License:Apache License

@BeforeClass
public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("optional/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();/*from   w w  w.  j  av a  2 s  .c  om*/

    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("optional/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
}

From source file:org.alfresco.repo.transfer.fsr.SchemaBootstrap.java

License:Open Source License

protected void executeSript(Resource resourceScript) {
    BufferedReader reader = null;
    try {//  www .ja  v  a2 s  .co m
        // run the creation script with autocommit true and stop on error.
        ScriptRunner runner = new ScriptRunner(dataSource.getConnection());
        runner.setLogWriter(null);
        runner.setAutoCommit(true);
        runner.setStopOnError(true);
        reader = new BufferedReader(new InputStreamReader(resourceScript.getInputStream(), "UTF-8"));
        runner.runScript(reader);
    } catch (SQLException sql) {
        throw new AlfrescoRuntimeException("Creation script " + creationScript + " failed!", sql);
    } catch (IOException io) {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {
            }
        }
        throw new AlfrescoRuntimeException("Creation script " + creationScript + " could not optain reader!!");
    }
}

From source file:org.apache.mybatis.basetest.BaseTest.java

License:Apache License

@BeforeClass
public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/mybatis/basetest/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();/* ww w.  j  a va2s .  c om*/

    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();

    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/mybatis/basetest/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();

    session.close();
}

From source file:org.fdmtech.mybatis.jdbc.TestJdbc.java

License:Apache License

private SqlSessionFactory createFactory() throws Exception {
    Reader reader = Resources.getResourceAsReader("mybatis-config.xml");
    SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();/*  w  w  w  .ja va 2  s  .  c o m*/
    SqlSession session = factory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("CreateDB_1.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
    return factory;
}

From source file:org.mybatis.cdi.ManagerProducers.java

License:Apache License

private SqlSessionFactory createSessionManager(int n) throws IOException {
    Reader reader = Resources.getResourceAsReader("org/mybatis/cdi/mybatis-config_" + n + ".xml");
    SqlSessionFactory manager = new SqlSessionFactoryBuilder().build(reader);
    reader.close();//  w  w w.  java2 s. com

    SqlSession session = manager.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/mybatis/cdi/CreateDB_" + n + ".sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();

    return manager;
}

From source file:org.mybatis.cdi.ManagerProducers.java

License:Apache License

private SqlSessionFactory createSessionManagerJTA() throws IOException {
    Reader reader = Resources.getResourceAsReader("org/mybatis/cdi/mybatis-config_jta.xml");
    SqlSessionFactory manager = new SqlSessionFactoryBuilder().build(reader);
    reader.close();//from  ww  w  .j  a  v  a  2s  . com

    SqlSession session = manager.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/mybatis/cdi/CreateDB_JTA.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();

    return manager;
}

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);
            runner.setErrorLogWriter(null);
            runner.runScript(reader);/* w w w.j av a  2  s. co  m*/
            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);
            runner.setErrorLogWriter(null);
            runner.runScript(reader);//w  w  w. java2s  .c o m
            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);
}