Search in sources :

Example 31 with SqlSessionFactory

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

the class ExternalRefidResolutionTest method testExternalRefAfterSelectKey.

@Test
public void testExternalRefAfterSelectKey() throws Exception {
    String resource = "org/apache/ibatis/submitted/refid_resolution/ExternalMapperConfig.xml";
    Reader reader = Resources.getResourceAsReader(resource);
    SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
    SqlSessionFactory sqlSessionFactory = builder.build(reader);
    reader.close();
    sqlSessionFactory.getConfiguration().getMappedStatementNames();
}
Also used : SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) Test(org.junit.Test)

Example 32 with SqlSessionFactory

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

the class DefaultResultHandlerTypeTest method testSelectList.

@Test
public void testSelectList() throws Exception {
    String xmlConfig = "org/apache/ibatis/submitted/result_handler_type/MapperConfig.xml";
    SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        List<Person> list = sqlSession.selectList("org.apache.ibatis.submitted.result_handler_type.PersonMapper.doSelect");
        assertEquals(list.size(), 2);
        assertEquals("java.util.LinkedList", list.getClass().getCanonicalName());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Test(org.junit.Test)

Example 33 with SqlSessionFactory

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

the class DefaultResultHandlerTypeTest method testSelectMap.

@Test
public void testSelectMap() throws Exception {
    String xmlConfig = "org/apache/ibatis/submitted/result_handler_type/MapperConfig.xml";
    SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        Map<Integer, Person> map = sqlSession.selectMap("org.apache.ibatis.submitted.result_handler_type.PersonMapper.doSelect", "id");
        assertEquals(map.size(), 2);
        assertEquals("java.util.LinkedHashMap", map.getClass().getCanonicalName());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Test(org.junit.Test)

Example 34 with SqlSessionFactory

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

the class DefaultResultHandlerTypeTest method testSelectMapAnnotation.

@Test
public void testSelectMapAnnotation() throws Exception {
    String xmlConfig = "org/apache/ibatis/submitted/result_handler_type/MapperConfig.xml";
    SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
    SqlSession sqlSession = sqlSessionFactory.openSession();
    try {
        PersonMapper mapper = sqlSession.getMapper(PersonMapper.class);
        Map<Integer, Person> map = mapper.selectAsMap();
        assertEquals(map.size(), 2);
        assertEquals("java.util.LinkedHashMap", map.getClass().getCanonicalName());
    } finally {
        sqlSession.close();
    }
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Test(org.junit.Test)

Example 35 with SqlSessionFactory

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

the class FolderMapperTest method testFindWithChildren.

@Test
public void testFindWithChildren() throws Exception {
    Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:association_nested", "SA", "");
    Statement stmt = conn.createStatement();
    stmt.execute("create table folder (id int, name varchar(100), parent_id int)");
    stmt.execute("insert into folder (id, name) values(1, 'Root')");
    stmt.execute("insert into folder values(2, 'Folder 1', 1)");
    stmt.execute("insert into folder values(3, 'Folder 2', 1)");
    stmt.execute("insert into folder values(4, 'Folder 2_1', 3)");
    stmt.execute("insert into folder values(5, 'Folder 2_2', 3)");
    /**
     * Root/
     *    Folder 1/
     *    Folder 2/
     *      Folder 2_1
     *      Folder 2_2
     */
    String resource = "org/apache/ibatis/submitted/association_nested/mybatis-config.xml";
    InputStream inputStream = Resources.getResourceAsStream(resource);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
    SqlSession session = sqlSessionFactory.openSession();
    FolderMapper postMapper = session.getMapper(FolderMapper.class);
    List<FolderFlatTree> folders = postMapper.findWithSubFolders("Root");
    Assert.assertEquals(3, folders.size());
    session.close();
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Statement(java.sql.Statement) InputStream(java.io.InputStream) Connection(java.sql.Connection) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) Test(org.junit.Test)

Aggregations

SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)53 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)42 Reader (java.io.Reader)39 Test (org.junit.Test)30 SqlSession (org.apache.ibatis.session.SqlSession)26 Connection (java.sql.Connection)18 Configuration (org.apache.ibatis.session.Configuration)13 Properties (java.util.Properties)8 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)4 HashMap (java.util.HashMap)3 MappedStatement (org.apache.ibatis.mapping.MappedStatement)3 DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)3 InputStream (java.io.InputStream)2 List (java.util.List)2 DbSqlSessionFactory (org.activiti.engine.impl.db.DbSqlSessionFactory)2 Before (org.junit.Before)2 MovieMapper (com.mapper.MovieMapper)1 Movie (com.po.Movie)1 StringReader (java.io.StringReader)1 Statement (java.sql.Statement)1