Search in sources :

Example 6 with JdbcTransactionFactory

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

the class ReverseIncludeTest 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(ReverseIncludePersonMapper.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 7 with JdbcTransactionFactory

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

the class SameIdTest 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(SameIdPersonMapper.class);
    configuration.addMapper(SameIdPetMapper.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 8 with JdbcTransactionFactory

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

the class AutoMappingUnknownColumnBehaviorTest method setup.

@BeforeClass
public static void setup() throws Exception {
    DataSource dataSource = BaseDataTest.createBlogDataSource();
    TransactionFactory transactionFactory = new JdbcTransactionFactory();
    Environment environment = new Environment("Production", transactionFactory, dataSource);
    Configuration configuration = new Configuration(environment);
    configuration.addMapper(Mapper.class);
    sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration);
}
Also used : TransactionFactory(org.apache.ibatis.transaction.TransactionFactory) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) Environment(org.apache.ibatis.mapping.Environment) JdbcTransactionFactory(org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory) DataSource(javax.sql.DataSource) BeforeClass(org.junit.BeforeClass)

Example 9 with JdbcTransactionFactory

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

the class ManyAnnoTest method testGetMessageForEmptyDatabase.

@Test
public void testGetMessageForEmptyDatabase() throws Exception {
    final Environment environment = new Environment("test", new JdbcTransactionFactory(), BaseDataTest.createBlogDataSource());
    final Configuration config = new Configuration(environment);
    config.addMapper(PostMapper.class);
    final SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(config);
    final SqlSession session = factory.openSession();
    PostMapper mapper = session.getMapper(PostMapper.class);
    List<AnnoPost> posts = mapper.getPosts(101);
    assertEquals(3, posts.size());
    assertEquals(3, posts.get(0).getTags().size());
    assertEquals(1, posts.get(1).getTags().size());
    assertEquals(0, posts.get(2).getTags().size());
    session.close();
}
Also used : Configuration(org.apache.ibatis.session.Configuration) SqlSession(org.apache.ibatis.session.SqlSession) 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) BaseDataTest(org.apache.ibatis.BaseDataTest) Test(org.junit.Test)

Example 10 with JdbcTransactionFactory

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

the class NpeExtendsTest method getSqlSessionFactoryWithConstructor.

private 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)

Aggregations

Environment (org.apache.ibatis.mapping.Environment)18 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)18 Configuration (org.apache.ibatis.session.Configuration)16 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)14 Connection (java.sql.Connection)10 UnpooledDataSource (org.apache.ibatis.datasource.unpooled.UnpooledDataSource)10 BeforeClass (org.junit.BeforeClass)6 DataSource (javax.sql.DataSource)5 TransactionFactory (org.apache.ibatis.transaction.TransactionFactory)5 Properties (java.util.Properties)2 UnpooledDataSourceFactory (org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory)2 DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)2 Test (org.junit.Test)2 Reader (java.io.Reader)1 BaseDataTest (org.apache.ibatis.BaseDataTest)1 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)1 SqlSession (org.apache.ibatis.session.SqlSession)1 SqlSessionFactory (org.apache.ibatis.session.SqlSessionFactory)1