Search in sources :

Example 46 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project mybatis-3 by mybatis.

the class SimpleObjectTest method setUp.

@Before
public void setUp() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/bringrags/mybatis-config.xml");
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
    sqlSession = sqlSessionFactory.openSession();
    Connection conn = sqlSession.getConnection();
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(new StringReader("DROP TABLE IF EXISTS SimpleObject;"));
    runner.runScript(new StringReader("DROP TABLE IF EXISTS SimpleChildObject;"));
    runner.runScript(new StringReader("CREATE TABLE SimpleObject (id VARCHAR(5) NOT NULL);"));
    runner.runScript(new StringReader("CREATE TABLE SimpleChildObject (id VARCHAR(5) NOT NULL, simple_object_id VARCHAR(5) NOT NULL);"));
    runner.runScript(new StringReader("INSERT INTO SimpleObject (id) values ('10000');"));
    runner.runScript(new StringReader("INSERT INTO SimpleChildObject (id, simple_object_id) values ('20000', '10000');"));
    reader.close();
    simpleChildObjectMapper = (SimpleChildObjectMapper) sqlSession.getMapper(SimpleChildObjectMapper.class);
}
Also used : SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Connection(java.sql.Connection) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) Before(org.junit.Before)

Example 47 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project mybatis-3 by mybatis.

the class CglibNPELazyTest method initDatabase.

@BeforeClass
public static void initDatabase() throws Exception {
    Connection conn = null;
    try {
        Class.forName("org.hsqldb.jdbcDriver");
        conn = DriverManager.getConnection("jdbc:hsqldb:mem:cglib_lazy_error", "sa", "");
        Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cglib_lazy_error/CreateDB.sql");
        ScriptRunner runner = new ScriptRunner(conn);
        runner.setLogWriter(null);
        runner.setErrorLogWriter(null);
        runner.runScript(reader);
        conn.commit();
        reader.close();
        reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/cglib_lazy_error/ibatisConfigLazy.xml");
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        sqlSessionFactory.getConfiguration().setLazyLoadingEnabled(true);
        sqlSessionFactory.getConfiguration().setAggressiveLazyLoading(false);
        reader.close();
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

Example 48 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project mybatis-3 by mybatis.

the class NestedResultHandlerMultipleAssociationTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_multiple_association/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nestedresulthandler_multiple_association/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

Example 49 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project mybatis-3 by mybatis.

the class QuotedColumnNamesTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    Connection conn = null;
    try {
        Class.forName("org.hsqldb.jdbcDriver");
        conn = DriverManager.getConnection("jdbc:hsqldb:mem:gname", "sa", "");
        Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/quotedcolumnnames/CreateDB.sql");
        ScriptRunner runner = new ScriptRunner(conn);
        runner.setLogWriter(null);
        runner.setErrorLogWriter(null);
        runner.runScript(reader);
        conn.commit();
        reader.close();
        reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/quotedcolumnnames/MapperConfig.xml");
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        reader.close();
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

Example 50 with ScriptRunner

use of org.apache.ibatis.jdbc.ScriptRunner in project mybatis-3 by mybatis.

the class ResulthandlerTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/result_handler/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
    sqlSessionFactory.getConfiguration().addMapper(Mapper.class);
    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/result_handler/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

Aggregations

ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)130 Reader (java.io.Reader)126 Connection (java.sql.Connection)114 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)109 BeforeClass (org.junit.BeforeClass)91 SqlSession (org.apache.ibatis.session.SqlSession)69 Before (org.junit.Before)17 PrintWriter (java.io.PrintWriter)8 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)4 Configuration (org.apache.ibatis.session.Configuration)2 StringReader (java.io.StringReader)1 Charset (java.nio.charset.Charset)1 Properties (java.util.Properties)1 NullWriter (org.apache.commons.io.output.NullWriter)1 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)1 Environment (org.apache.ibatis.mapping.Environment)1 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)1 Test (org.junit.Test)1