Search in sources :

Example 6 with DefaultSqlSessionFactory

use of org.apache.ibatis.session.defaults.DefaultSqlSessionFactory 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)

Example 7 with DefaultSqlSessionFactory

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

the class ProviderTest method shouldUseDefaultId.

@Test
public void shouldUseDefaultId() throws Exception {
    Reader reader = Resources.getResourceAsReader("org/apache/ibatis/submitted/multidb/MultiDbConfig.xml");
    DefaultSqlSessionFactory sqlSessionFactory = (DefaultSqlSessionFactory) new SqlSessionFactoryBuilder().build(reader);
    Configuration c = sqlSessionFactory.getConfiguration();
    assertEquals("hsql", 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)

Aggregations

DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)7 Configuration (org.apache.ibatis.session.Configuration)5 Test (org.junit.Test)5 Reader (java.io.Reader)3 Properties (java.util.Properties)3 Environment (org.apache.ibatis.mapping.Environment)3 BaseDataTest (org.apache.ibatis.BaseDataTest)2 UnpooledDataSourceFactory (org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory)2 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)2 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)2 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 SQLException (java.sql.SQLException)1 ActivitiException (org.activiti.engine.ActivitiException)1 ProcessEngineConfiguration (org.activiti.engine.ProcessEngineConfiguration)1 AuthorMapperWithMultipleHandlers (org.apache.ibatis.domain.blog.mappers.AuthorMapperWithMultipleHandlers)1 AuthorMapperWithRowBounds (org.apache.ibatis.domain.blog.mappers.AuthorMapperWithRowBounds)1 DefaultResultHandler (org.apache.ibatis.executor.result.DefaultResultHandler)1