Search in sources :

Example 11 with SqlSessionFactory

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;
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory)

Example 12 with SqlSessionFactory

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;
}
Also used : SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder)

Example 13 with 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();
}
Also used : SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder)

Example 14 with SqlSessionFactory

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();
    }
}
Also used : Configuration(org.apache.ibatis.session.Configuration) SqlSession(org.apache.ibatis.session.SqlSession) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) Properties(java.util.Properties) Test(org.junit.Test)

Example 15 with SqlSessionFactory

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"));
}
Also used : Configuration(org.apache.ibatis.session.Configuration) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) Properties(java.util.Properties) Test(org.junit.Test)

Aggregations

SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)52 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)42 Reader (java.io.Reader)39 Test (org.junit.Test)30 SqlSession (org.apache.ibatis.session.SqlSession)26 Connection (java.sql.Connection)18 Configuration (org.apache.ibatis.session.Configuration)13 Properties (java.util.Properties)8 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)4 HashMap (java.util.HashMap)3 MappedStatement (org.apache.ibatis.mapping.MappedStatement)3 DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)3 InputStream (java.io.InputStream)2 List (java.util.List)2 DbSqlSessionFactory (org.activiti.engine.impl.db.DbSqlSessionFactory)2 Before (org.junit.Before)2 MovieMapper (com.mapper.MovieMapper)1 Movie (com.po.Movie)1 StringReader (java.io.StringReader)1 Statement (java.sql.Statement)1