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();
}
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();
}
}
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();
}
}
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();
}
}
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();
}
Aggregations