Search in sources :

Example 16 with SqlSessionFactoryBuilder

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

the class ProviderTest method shouldUseProvider.

@Test
public void shouldUseProvider() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/ProviderConfig.xml");
    DefaultSqlSessionFactory sqlSessionFactory = (DefaultSqlSessionFactory) new SqlSessionFactoryBuilder().build(reader);
    Configuration c = sqlSessionFactory.getConfiguration();
    assertEquals("translated", c.getDatabaseId());
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultSqlSessionFactory(org.apache.ibatis.session.defaults.DefaultSqlSessionFactory) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) Test(org.junit.Test)

Example 17 with SqlSessionFactoryBuilder

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

the class MultipleResultTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multiple_resultsets/mybatis-config.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 18 with SqlSessionFactoryBuilder

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

the class MultipleResultSetTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multipleresultsetswithassociation/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
    // populate in-memory database
    // Could not get the table creation, procedure creation, and data population to work from the same script.
    // Once it was in three scripts, all seemed well.
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multipleresultsetswithassociation/CreateDB1.sql");
    runReaderScript(conn, session, reader);
    reader.close();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multipleresultsetswithassociation/CreateDB2.sql");
    runReaderScript(conn, session, reader);
    reader.close();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multipleresultsetswithassociation/CreateDB3.sql");
    runReaderScript(conn, session, reader);
    reader.close();
    session.close();
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) BeforeClass(org.junit.BeforeClass)

Example 19 with SqlSessionFactoryBuilder

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

the class NamedConstructorArgsTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/named_constructor_args/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
    Configuration configuration = sqlSessionFactory.getConfiguration();
    configuration.setUseActualParamName(false);
    configuration.addMapper(Mapper.class);
    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/named_constructor_args/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(reader);
    reader.close();
    session.close();
}
Also used : Configuration(org.apache.ibatis.session.Configuration) SqlSession(org.apache.ibatis.session.SqlSession) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

Example 20 with SqlSessionFactoryBuilder

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

the class PermissionsTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/permissions/mybatis-config.xml");
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    reader.close();
    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    Connection conn = session.getConnection();
    reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/permissions/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.setErrorLogWriter(null);
    runner.runScript(reader);
    conn.commit();
    conn.close();
    reader.close();
}
Also used : SqlSession(org.apache.ibatis.session.SqlSession) Connection(java.sql.Connection) Reader(java.io.Reader) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) ScriptRunner(org.apache.ibatis.jdbc.ScriptRunner) BeforeClass(org.junit.BeforeClass)

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