use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class InsertTest method testInsertMapped.
@Test
public void testInsertMapped() throws Exception {
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/keycolumn/MapperConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
InsertMapper mapper = sqlSession.getMapper(InsertMapper.class);
Name name = new Name();
name.setFirstName("Fred");
name.setLastName("Flintstone");
int rows = mapper.insertNameMapped(name);
assertNotNull(name.getId());
assertEquals(1, rows);
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class MultipleIncludeTest method getSqlSessionFactoryXmlConfig.
private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception {
Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/MultipleIncludeMapperConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
configReader.close();
Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection();
initDb(conn);
return sqlSessionFactory;
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class MultipleReverseIncludeTest method getSqlSessionFactoryXmlConfig.
private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception {
Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/MultipleReverseIncludeMapperConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
configReader.close();
Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection();
initDb(conn);
return sqlSessionFactory;
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class NonFullyQualifiedNamespaceTest method testCrossReferenceXmlConfig.
@Test
public void testCrossReferenceXmlConfig() throws Exception {
Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/NonFullyQualifiedNamespaceConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
configReader.close();
Configuration configuration = sqlSessionFactory.getConfiguration();
MappedStatement selectPerson = configuration.getMappedStatement("person namespace.select");
assertEquals("org/apache/ibatis/submitted/xml_external_ref/NonFullyQualifiedNamespacePersonMapper.xml", selectPerson.getResource());
Connection conn = configuration.getEnvironment().getDataSource().getConnection();
initDb(conn);
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
Person person = (Person) sqlSession.selectOne("person namespace.select", 1);
assertEquals((Integer) 1, person.getId());
assertEquals(2, person.getPets().size());
assertEquals((Integer) 2, person.getPets().get(1).getId());
Pet pet = (Pet) sqlSession.selectOne("person namespace.selectPet", 1);
assertEquals(Integer.valueOf(1), pet.getId());
Pet pet2 = (Pet) sqlSession.selectOne("pet namespace.select", 3);
assertEquals((Integer) 3, pet2.getId());
assertEquals((Integer) 2, pet2.getOwner().getId());
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class ParameterMapReferenceTest method getSqlSessionFactoryXmlConfig.
private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception {
Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/ParameterMapReferenceMapperConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
configReader.close();
Connection conn = sqlSessionFactory.getConfiguration().getEnvironment().getDataSource().getConnection();
initDb(conn);
return sqlSessionFactory;
}
Aggregations