Search in sources :

Example 1 with SqlSession

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

the class AncestorRefTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/ancestor_ref/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/ancestor_ref/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 2 with SqlSession

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

the class ArrayResultTypeTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/array_result_type/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/array_result_type/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 3 with SqlSession

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

the class AssociationTypeTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/associationtype/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/associationtype/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 4 with SqlSession

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

the class SimpleListParameterTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/simplelistparameter/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/simplelistparameter/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 5 with SqlSession

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

the class StringListTest method shouldGetAUser.

@Test
public void shouldGetAUser() {
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        Mapper mapper = sqlSession.getMapper(Mapper.class);
        List<User> users = mapper.getUsersAndGroups(1);
        Assert.assertEquals(1, users.size());
        Assert.assertEquals(2, users.get(0).getGroups().size());
        Assert.assertEquals(2, users.get(0).getRoles().size());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Test(org.junit.Test)

Aggregations

SqlSession (org.apache.ibatis.session.SqlSession)2117 Test (org.junit.jupiter.api.Test)1845 BaseDataTest (org.apache.ibatis.BaseDataTest)593 Test (org.junit.Test)127 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)104 Reader (java.io.Reader)97 User (com.github.pagehelper.model.User)87 ArrayList (java.util.ArrayList)84 UserMapper (com.github.pagehelper.mapper.UserMapper)75 Connection (java.sql.Connection)68 FirstName (mbg.test.common.FirstName)60 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)60 HashMap (java.util.HashMap)59 BeforeClass (org.junit.BeforeClass)56 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)54 RowBounds (org.apache.ibatis.session.RowBounds)36 Map (java.util.Map)34 Date (java.util.Date)33 List (java.util.List)24 AwfulTableMapper (mbg.test.mb3.generated.dsql.mapper.AwfulTableMapper)23