Search in sources :

Example 61 with SqlSessionFactoryBuilder

use of org.apache.ibatis.session.SqlSessionFactoryBuilder 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 62 with SqlSessionFactoryBuilder

use of org.apache.ibatis.session.SqlSessionFactoryBuilder in project mybatis-3 by mybatis.

the class NestedQueryCacheTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/nested_query_cache/MapperConfig.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
    createBlogDataSource();
}
Also used : Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) BeforeClass(org.junit.BeforeClass)

Example 63 with SqlSessionFactoryBuilder

use of org.apache.ibatis.session.SqlSessionFactoryBuilder 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 64 with SqlSessionFactoryBuilder

use of org.apache.ibatis.session.SqlSessionFactoryBuilder 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 65 with SqlSessionFactoryBuilder

use of org.apache.ibatis.session.SqlSessionFactoryBuilder in project mybatis-3 by mybatis.

the class RefCursorTest method testRefCursor1.

@SuppressWarnings("unchecked")
@Test
public void testRefCursor1() throws IOException {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/refcursor/MapperConfig.xml");
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
        Map<String, Object> parameter = new HashMap<String, Object>();
        parameter.put("orderId", 1);
        mapper.getOrder1(parameter);
        assertNotNull(parameter.get("order"));
        List<Order> orders = (List<Order>) parameter.get("order");
        assertEquals(1, orders.size());
        Order order = orders.get(0);
        assertEquals(3, order.getDetailLines().size());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) HashMap(java.util.HashMap) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) List(java.util.List) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) Test(org.junit.Test)

Aggregations

SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)175 Reader (java.io.Reader)159 Connection (java.sql.Connection)134 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)109 BeforeClass (org.junit.BeforeClass)98 SqlSession (org.apache.ibatis.session.SqlSession)85 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)42 Configuration (org.apache.ibatis.session.Configuration)30 Test (org.junit.Test)30 Before (org.junit.Before)18 Environment (org.apache.ibatis.mapping.Environment)14 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)14 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)10 Properties (java.util.Properties)9 PrintWriter (java.io.PrintWriter)6 InputStream (java.io.InputStream)3 DataSource (javax.sql.DataSource)3 BaseDataTest (org.apache.ibatis.BaseDataTest)3 MappedStatement (org.apache.ibatis.mapping.MappedStatement)3 DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)3