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 mybatis-3 by mybatis.
the class RefCursorTest method testRefCursor1.
@SuppressWarnings("unchecked")
@Test
public void testRefCursor1() 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.getOrder1(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();
}
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class RefidResolutionTest method testIncludes.
@Test(expected = PersistenceException.class)
public void testIncludes() throws Exception {
String resource = "org/apache/ibatis/submitted/refid_resolution/MapperConfig.xml";
Reader reader = Resources.getResourceAsReader(resource);
SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
SqlSessionFactory sqlSessionFactory = builder.build(reader);
sqlSessionFactory.getConfiguration().getMappedStatementNames();
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class DefaultResultHandlerTypeTest 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 FooMapperTest method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() {
try {
final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsReader(SQL_MAP_CONFIG));
session = factory.openSession();
Connection conn = session.getConnection();
ScriptRunner runner = new ScriptRunner(conn);
runner.setLogWriter(null);
runner.setErrorLogWriter(null);
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/null_associations/create-schema-mysql.sql");
runner.runScript(reader);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Aggregations