Search in sources :

Example 21 with JdbcTransactionFactory

use of org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory in project mybatis-3 by mybatis.

the class SqlxmlTypeHandlerTest method setUp.

@BeforeAll
static void setUp() throws Exception {
    Configuration configuration = new Configuration();
    Environment environment = new Environment("development", new JdbcTransactionFactory(), PgContainer.getUnpooledDataSource());
    configuration.setEnvironment(environment);
    configuration.addMapper(Mapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), "org/apache/ibatis/type/SqlxmlTypeHandlerTest.sql");
}
Also used : Configuration(org.apache.ibatis.session.Configuration) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 22 with JdbcTransactionFactory

use of org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory in project mybatis-3 by mybatis.

the class ResultMapReferenceTest method getSqlSessionFactoryJavaConfig.

private SqlSessionFactory getSqlSessionFactoryJavaConfig() throws Exception {
    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(ResultMapReferencePersonMapper.class);
    configuration.addMapper(ResultMapReferencePetMapper.class);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    initDb(sqlSessionFactory);
    return sqlSessionFactory;
}
Also used : UnpooledDataSource(org.apache.ibatis.datasource.unpooled.UnpooledDataSource) Configuration(org.apache.ibatis.session.Configuration) SqlSessionFactory(org.apache.ibatis.session.SqlSessionFactory) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)

Example 23 with JdbcTransactionFactory

use of org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory in project mybatis-3 by mybatis.

the class BindingTest method setup.

@BeforeAll
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) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 24 with JdbcTransactionFactory

use of org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory in project mybatis-3 by mybatis.

the class NpeExtendsTest method getSqlSessionFactoryWithConstructor.

private static SqlSessionFactory getSqlSessionFactoryWithConstructor() {
    UnpooledDataSourceFactory unpooledDataSourceFactory = new UnpooledDataSourceFactory();
    Properties properties = new Properties();
    properties.setProperty("driver", "org.hsqldb.jdbcDriver");
    properties.setProperty("url", "jdbc:hsqldb:mem:extends_with_constructor");
    properties.setProperty("username", "sa");
    unpooledDataSourceFactory.setProperties(properties);
    Environment environment = new Environment("extends_with_constructor", new JdbcTransactionFactory(), unpooledDataSourceFactory.getDataSource());
    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.addMapper(StudentConstructorMapper.class);
    configuration.addMapper(TeacherMapper.class);
    configuration.getMappedStatementNames();
    configuration.setAutoMappingBehavior(AutoMappingBehavior.NONE);
    return new DefaultSqlSessionFactory(configuration);
}
Also used : Configuration(org.apache.ibatis.session.Configuration) DefaultSqlSessionFactory(org.apache.ibatis.session.defaults.DefaultSqlSessionFactory) UnpooledDataSourceFactory(org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory) Environment(org.apache.ibatis.mapping.Environment) Properties(java.util.Properties) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)

Example 25 with JdbcTransactionFactory

use of org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory in project mybatis-3 by mybatis.

the class MysqlCursorTest method setUp.

@BeforeAll
static void setUp() throws Exception {
    Configuration configuration = new Configuration();
    Environment environment = new Environment("development", new JdbcTransactionFactory(), MysqlContainer.getUnpooledDataSource());
    configuration.setEnvironment(environment);
    configuration.addMapper(Mapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
    BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), "org/apache/ibatis/submitted/cursor_simple/CreateDB.sql");
}
Also used : Configuration(org.apache.ibatis.session.Configuration) Environment(org.apache.ibatis.mapping.Environment) SqlSessionFactoryBuilder(org.apache.ibatis.session.SqlSessionFactoryBuilder) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) BeforeAll(org.junit.jupiter.api.BeforeAll)

Aggregations

Environment (org.apache.ibatis.mapping.Environment)34 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)34 Configuration (org.apache.ibatis.session.Configuration)31 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)28 BeforeAll (org.junit.jupiter.api.BeforeAll)16 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)14 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)12 DataSource (javax.sql.DataSource)7 TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)7 Properties (java.util.Properties)4 Test (org.junit.jupiter.api.Test)3 UnpooledDataSourceFactory (org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory)2 DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 InputStream (java.io.InputStream)1 BaseDataTest (org.apache.ibatis.BaseDataTest)1 CustomLongTypeHandler (org.apache.ibatis.builder.CustomLongTypeHandler)1 CustomObjectWrapperFactory (org.apache.ibatis.builder.CustomObjectWrapperFactory)1 CustomReflectorFactory (org.apache.ibatis.builder.CustomReflectorFactory)1 CustomStringTypeHandler (org.apache.ibatis.builder.CustomStringTypeHandler)1