Search in sources :

Example 1 with UnpooledDataSourceFactory

use of org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory in project mybatis-3 by mybatis.

the class EnumWithOgnlTest method testConfiguration.

@Test
public void testConfiguration() {
    UnpooledDataSourceFactory dataSourceFactory = new UnpooledDataSourceFactory();
    Properties dataSourceProperties = new Properties();
    dataSourceProperties.put("driver", "org.hsqldb.jdbcDriver");
    dataSourceProperties.put("url", "jdbc:hsqldb:mem:xml_references");
    dataSourceProperties.put("username", "sa");
    dataSourceFactory.setProperties(dataSourceProperties);
    Environment environment = new Environment("test", new JdbcTransactionFactory(), dataSourceFactory.getDataSource());
    Configuration configuration = new Configuration();
    configuration.setEnvironment(environment);
    configuration.getTypeAliasRegistry().registerAlias(Person.class);
    configuration.addMapper(PersonMapper.class);
    configuration.addMapper(PersonMapper2.class);
    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) Test(org.junit.Test)

Example 2 with UnpooledDataSourceFactory

use of org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory 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

Properties (java.util.Properties)2 UnpooledDataSourceFactory (org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory)2 Environment (org.apache.ibatis.mapping.Environment)2 Configuration (org.apache.ibatis.session.Configuration)2 DefaultSqlSessionFactory (org.apache.ibatis.session.defaults.DefaultSqlSessionFactory)2 JdbcTransactionFactory (org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory)2 Test (org.junit.Test)1