use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class DuplicateResourceTest method shouldDemonstrateDuplicateResourceIssue.
@Test
public void shouldDemonstrateDuplicateResourceIssue() throws Exception {
final String resource = "org/apache/ibatis/submitted/duplicate_resource_loaded/Config.xml";
final Reader reader = Resources.getResourceAsReader(resource);
final SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
final SqlSessionFactory factory = builder.build(reader);
final SqlSession sqlSession = factory.openSession();
try {
final Mapper mapper = sqlSession.getMapper(Mapper.class);
final List<Map<String, Object>> list = mapper.selectAllBlogs();
Assert.assertEquals(2, list.size());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class CustomCollectionHandlingTest method testSelectListWithNestedSelect.
/**
* Custom collections with nested select.
*
* @throws Exception
*/
@Test
public void testSelectListWithNestedSelect() throws Exception {
String xmlConfig = "org/apache/ibatis/submitted/custom_collection_handling/MapperConfig.xml";
SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
List<Person> list = sqlSession.selectList("org.apache.ibatis.submitted.custom_collection_handling.PersonMapper.findWithSelect");
assertEquals(2, list.size());
assertEquals(2, list.get(0).getContacts().size());
assertEquals(1, list.get(1).getContacts().size());
assertEquals("3 Wall Street", list.get(0).getContacts().get(1).getAddress());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class CustomCollectionHandlingTest method testSelectListWithNestedResultMap.
/**
* Custom collections with nested resultMap.
*
* @throws Exception
*/
@Test
public void testSelectListWithNestedResultMap() throws Exception {
String xmlConfig = "org/apache/ibatis/submitted/custom_collection_handling/MapperConfig.xml";
SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
List<Person> list = sqlSession.selectList("org.apache.ibatis.submitted.custom_collection_handling.PersonMapper.findWithResultMap");
assertEquals(2, list.size());
assertEquals(2, list.get(0).getContacts().size());
assertEquals(1, list.get(1).getContacts().size());
assertEquals("3 Wall Street", list.get(0).getContacts().get(1).getAddress());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class NpeExtendsTest method testSelectNoName.
@Test
public void testSelectNoName() {
SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryWithConstructor();
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
StudentConstructorMapper studentConstructorMapper = sqlSession.getMapper(StudentConstructorMapper.class);
StudentConstructor testStudent = studentConstructorMapper.selectNoNameById(1);
assertEquals(1, testStudent.getConstructors().size());
assertTrue(testStudent.getConstructors().contains(StudentConstructor.Constructor.ID));
assertNull(testStudent.getName());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class NpeExtendsTest method testSelectWithTeacher.
@Test
public void testSelectWithTeacher() {
SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryWithConstructor();
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
StudentConstructorMapper studentConstructorMapper = sqlSession.getMapper(StudentConstructorMapper.class);
StudentConstructor testStudent = studentConstructorMapper.selectWithTeacherById(1);
assertEquals(1, testStudent.getConstructors().size());
assertTrue(testStudent.getConstructors().contains(StudentConstructor.Constructor.ID_NAME));
} finally {
sqlSession.close();
}
}
Aggregations