use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class SerializeCircularTest method createSession.
private SqlSession createSession(boolean anAggressiveLazyLoading) throws Exception {
String xmlConfig = anAggressiveLazyLoading ? "org/apache/ibatis/submitted/serializecircular/MapperConfigWithAggressiveLazyLoading.xml" : "org/apache/ibatis/submitted/serializecircular/MapperConfigWithoutAggressiveLazyLoading.xml";
SqlSessionFactory sqlSessionFactory = getSqlSessionFactoryXmlConfig(xmlConfig);
SqlSession sqlSession = sqlSessionFactory.openSession();
return sqlSession;
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class ReverseIncludeTest method getSqlSessionFactoryXmlConfig.
private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception {
Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/ReverseIncludeMapperConfig.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 ShortNameTest method getConfiguration.
private Configuration getConfiguration() throws IOException {
Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/MapperConfig.xml");
SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
configReader.close();
return sqlSessionFactory.getConfiguration();
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class AnnotationMapperTest method applyPropertyValueOnAnnotationMapper.
@Test
public void applyPropertyValueOnAnnotationMapper() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
props.setProperty("ping.sql", "SELECT 'Hi' FROM INFORMATION_SCHEMA.SYSTEM_USERS");
props.setProperty("cache.name", "custom");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
configuration.addMapper(AnnotationMapper.class);
SupportClasses.CustomCache cache = SupportClasses.Utils.unwrap(configuration.getCache(AnnotationMapper.class.getName()));
Assert.assertThat(cache.getName(), Is.is("custom"));
SqlSession sqlSession = factory.openSession();
try {
AnnotationMapper mapper = sqlSession.getMapper(AnnotationMapper.class);
Assert.assertThat(mapper.ping(), Is.is("Hi"));
} finally {
sqlSession.close();
}
}
use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.
the class ConfigurationTest method applyDefaultValueOnXmlConfiguration.
@Test
public void applyDefaultValueOnXmlConfiguration() throws IOException {
Properties props = new Properties();
props.setProperty(PropertyParser.KEY_ENABLE_DEFAULT_VALUE, "true");
Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/global_variables_defaults/mybatis-config.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, props);
Configuration configuration = factory.getConfiguration();
Assert.assertThat(configuration.getJdbcTypeForNull(), Is.is(JdbcType.NULL));
Assert.assertThat(((UnpooledDataSource) configuration.getEnvironment().getDataSource()).getUrl(), Is.is("jdbc:hsqldb:mem:global_variables_defaults"));
Assert.assertThat(configuration.getDatabaseId(), Is.is("hsql"));
Assert.assertThat(((SupportClasses.CustomObjectFactory) configuration.getObjectFactory()).getProperties().getProperty("name"), Is.is("default"));
}
Aggregations