Search in sources :

Example 86 with SqlSessionFactoryBuilder

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

the class BindingTest method setup.

@BeforeClass
public static void setup() throws Exception {
    DataSource dataSource = BaseDataTest.createBlogDataSource();
    BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DDL);
    BaseDataTest.runScript(dataSource, BaseDataTest.BLOG_DATA);
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.setLazyLoadingEnabled(true);
    // to test legacy style reference (#{0} #{1})
    configuration.setUseActualParamName(false);
    configuration.getTypeAliasRegistry().registerAlias(Blog.class);
    configuration.getTypeAliasRegistry().registerAlias(Post.class);
    configuration.getTypeAliasRegistry().registerAlias(Author.class);
    configuration.addMapper(BoundBlogMapper.class);
    configuration.addMapper(BoundAuthorMapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) DataSource(javax.sql.DataSource) BeforeClass(org.junit.BeforeClass)

Example 87 with SqlSessionFactoryBuilder

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

the class CommonPropertyDeferLoadError method initDatabase.

@BeforeClass
public static void initDatabase() throws Exception {
    Connection conn = null;
    try {
        Class.forName("org.hsqldb.jdbcDriver");
        conn = DriverManager.getConnection("jdbc:hsqldb:mem:deferload_common_property", "sa", "");
        Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/deferload_common_property/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/deferload_common_property/ibatisConfig.xml");
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/deferload_common_property/lazyLoadIbatisConfig.xml");
        lazyLoadSqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
        reader.close();
    } finally {
        if (conn != null) {
            conn.close();
        }
    }
}
Also used : 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 88 with SqlSessionFactoryBuilder

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

the class DmlMapperReturnTypesTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create a SqlSessionFactory
    Reader reader = Resources.getResourceAsReader(XML);
    try {
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
    } finally {
        reader.close();
    }
    // populate in-memory database
    SqlSession session = sqlSessionFactory.openSession();
    try {
        Connection conn = session.getConnection();
        reader = Resources.getResourceAsReader(SQL);
        try {
            ScriptRunner runner = new ScriptRunner(conn);
            runner.setLogWriter(null);
            runner.runScript(reader);
        } finally {
            reader.close();
        }
    } finally {
        session.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)

Example 89 with SqlSessionFactoryBuilder

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

the class BatchKeysTest method setUp.

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

Example 90 with SqlSessionFactoryBuilder

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

the class BatchTest method setUp.

@BeforeClass
public static void setUp() throws Exception {
    // create an SqlSessionFactory
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/batch_test/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/batch_test/CreateDB.sql");
    ScriptRunner runner = new ScriptRunner(conn);
    runner.setLogWriter(null);
    runner.runScript(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) 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