use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class SelectKeyTest method testSelectKey.
@Test
public void testSelectKey() throws Exception {
// this test checks to make sure that we can have select keys with the same
// insert id in different namespaces
String resource = "org/apache/ibatis/submitted/selectkey/MapperConfig.xml";
Reader reader = Resources.getResourceAsReader(resource);
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory sqlMapper = builder.build(reader);
assertNotNull(sqlMapper);
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class DynamicSqlSourceTest method createDynamicSqlSource.
private DynamicSqlSource createDynamicSqlSource(SqlNode... contents) throws IOException, SQLException {
createBlogDataSource();
final String resource = "org/apache/ibatis/builder/MapperConfig.xml";
final Reader reader = Resources.getResourceAsReader(resource);
SqlSessionFactory sqlMapper = new SqlSessionFactoryBuilder().build(reader);
Configuration configuration = sqlMapper.getConfiguration();
MixedSqlNode sqlNode = mixedContents(contents);
return new DynamicSqlSource(configuration, sqlNode);
}
use of org.apache.ibatis.session.SqlSessionFactory in project api-manager by cehome-com.
the class ApplicationConfiguration method newSqlSessionTemplate.
@Bean
public SqlSessionTemplate newSqlSessionTemplate() {
SqlSessionFactoryBean factoryBean = new SqlSessionFactoryBean();
factoryBean.setDataSource(dataSource);
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();
SqlSessionFactory sessionFactory = null;
try {
factoryBean.setMapperLocations(context.getResources(MAPPER_PACKAGE));
sessionFactory = factoryBean.getObject();
return new SqlSessionTemplate(sessionFactory);
} catch (Exception e) {
logger.error("context.getResources error!", e);
} finally {
context.close();
}
return null;
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class CustomCollectionHandlingTest method getSqlSessionFactoryXmlConfig.
private SqlSessionFactory getSqlSessionFactoryXmlConfig(String resource) throws Exception {
Reader configReader = Resources.getResourceAsReader(resource);
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 RefCursorTest method testRefCursor2.
@SuppressWarnings("unchecked")
@Test
public void testRefCursor2() throws IOException {
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/refcursor/MapperConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
OrdersMapper mapper = sqlSession.getMapper(OrdersMapper.class);
Map<String, Object> parameter = new HashMap<String, Object>();
parameter.put("orderId", 1);
mapper.getOrder2(parameter);
assertNotNull(parameter.get("order"));
List<Order> orders = (List<Order>) parameter.get("order");
assertEquals(1, orders.size());
Order order = orders.get(0);
assertEquals(3, order.getDetailLines().size());
} finally {
sqlSession.close();
}
}
Aggregations