Search in sources :

Example 6 with SqlSessionFactory

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

Example 7 with SqlSessionFactory

use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.

the class XmlExternalRefTest method testMappedStatementCache.

@Test
public void testMappedStatementCache() throws Exception {
    Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/MapperConfig.xml");
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configReader);
    configReader.close();
    Configuration configuration = sqlSessionFactory.getConfiguration();
    configuration.getMappedStatementNames();
    MappedStatement selectPetStatement = configuration.getMappedStatement("org.apache.ibatis.submitted.xml_external_ref.PetMapper.select");
    MappedStatement selectPersonStatement = configuration.getMappedStatement("org.apache.ibatis.submitted.xml_external_ref.PersonMapper.select");
    Cache cache = selectPetStatement.getCache();
    assertEquals("org.apache.ibatis.submitted.xml_external_ref.PetMapper", cache.getId());
    assertSame(cache, selectPersonStatement.getCache());
}
Also used : Configuration(org.apache.ibatis.session.Configuration) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) MappedStatement(org.apache.ibatis.mapping.MappedStatement) Cache(org.apache.ibatis.cache.Cache) Test(org.junit.Test)

Example 8 with SqlSessionFactory

use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.

the class XmlExternalRefTest method getSqlSessionFactoryXmlConfig.

private SqlSessionFactory getSqlSessionFactoryXmlConfig() throws Exception {
    Reader configReader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_external_ref/MapperConfig.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 9 with SqlSessionFactory

use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.

the class EnumWithOgnlTest method testMixedConfiguration.

@Test
public void testMixedConfiguration() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/xml_references/ibatisConfig.xml");
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    sqlSessionFactory.getConfiguration().addMapper(PersonMapper2.class);
}
Also used : DefaultSqlSessionFactory(org.apache.ibatis.session.defaults.DefaultSqlSessionFactory) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) Test(org.junit.Test)

Example 10 with SqlSessionFactory

use of org.apache.ibatis.session.SqlSessionFactory in project mybatis-3 by mybatis.

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

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