Search in sources :

Example 26 with SqlSessionFactoryBuilder

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

the class AutodiscoverTest method setup.

@BeforeClass
public static void setup() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/autodiscover/MapperConfig.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
}
Also used : Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) BeforeClass(org.junit.BeforeClass)

Example 27 with SqlSessionFactoryBuilder

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

the class AwfulTableTest method setUp.

@Before
public void setUp() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Connection conn = DriverManager.getConnection("jdbc:hsqldb:mem:attest", "sa", "");
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/awful_table/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    conn.commit();
    reader.close();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/awful_table/MapperConfig.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
}
Also used : Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) Before(org.junit.Before)

Example 28 with SqlSessionFactoryBuilder

use of org.apache.ibatis.session.SqlSessionFactoryBuilder 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 29 with SqlSessionFactoryBuilder

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

the class XmlExternalRefTest method getSqlSessionFactoryJavaConfig.

private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
    Class.forName("org.hsqldb.jdbcDriver");
    Connection c = DriverManager.getConnection("jdbc:hsqldb:mem:xmlextref", "sa", "");
    initDb(c);
    Configuration configuration = new Configuration();
    Environment environment = new Environment("development", new JdbcTransactionFactory(), new UnpooledDataSource("org.hsqldb.jdbcDriver", "jdbc:hsqldb:mem:xmlextref", null));
    configuration.setEnvironment(environment);
    configuration.addMapper(PersonMapper.class);
    configuration.addMapper(PetMapper.class);
    return new SqlSessionFactoryBuilder().build(configuration);
}
Also used : UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) Configuration(org.apache.ibatis.session.Configuration) Connection(java.sql.Connection) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)

Example 30 with SqlSessionFactoryBuilder

use of org.apache.ibatis.session.SqlSessionFactoryBuilder 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)

Aggregations

SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)175 Reader (java.io.Reader)159 Connection (java.sql.Connection)134 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)109 BeforeClass (org.junit.BeforeClass)98 SqlSession (org.apache.ibatis.session.SqlSession)85 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)42 Configuration (org.apache.ibatis.session.Configuration)30 Test (org.junit.Test)30 Before (org.junit.Before)18 Environment (org.apache.ibatis.mapping.Environment)14 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)14 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)10 Properties (java.util.Properties)9 PrintWriter (java.io.PrintWriter)6 InputStream (java.io.InputStream)3 DataSource (javax.sql.DataSource)3 BaseDataTest (org.apache.ibatis.BaseDataTest)3 MappedStatement (org.apache.ibatis.mapping.MappedStatement)3 DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)3