Search in sources :

Example 26 with Environment

use of org.apache.ibatis.mapping.Environment 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)

Aggregations

Environment (org.apache.ibatis.mapping.Environment)26 Configuration (org.apache.ibatis.session.Configuration)19 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)18 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)14 Connection (java.sql.Connection)10 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)10 TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)10 DataSource (javax.sql.DataSource)8 BeforeClass (org.junit.BeforeClass)6 Properties (java.util.Properties)5 SQLException (java.sql.SQLException)3 DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)3 Transaction (org.apache.ibatis.transaction.Transaction)3 Test (org.junit.Test)3 InputStream (java.io.InputStream)2 Reader (java.io.Reader)2 UnpooledDataSourceFactory (org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory)2 Executor (org.apache.ibatis.executor.Executor)2 ManagedTransactionFactory (org.apache.ibatis.transaction.managed.ManagedTransactionFactory)2 InputStreamReader (java.io.InputStreamReader)1