Example usage for org.apache.ibatis.datasource.pooled PooledDataSourceFactory getDataSource

List of usage examples for org.apache.ibatis.datasource.pooled PooledDataSourceFactory getDataSource

Introduction

In this page you can find the example usage for org.apache.ibatis.datasource.pooled PooledDataSourceFactory getDataSource.

Prototype

@Override
    public DataSource getDataSource() 

Source Link

Usage

From source file:com.itfsw.mybatis.generator.plugins.tools.MyBatisGeneratorTool.java

License:Apache License

/**
 * ?SqlSession//from   www  . j a v  a  2  s  .co  m
 * @return
 * @throws IOException
 */
public SqlSession getSqlSession() throws IOException, ClassNotFoundException {
    org.apache.ibatis.session.Configuration config = new org.apache.ibatis.session.Configuration();
    config.setCallSettersOnNulls(true); // nullsetter
    config.setMapUnderscoreToCamelCase(true); // ???

    // mapper
    config.addMappers(targetPackage);
    // ??
    PooledDataSourceFactory dataSourceFactory = new PooledDataSourceFactory();
    dataSourceFactory.setProperties(DBHelper.properties);
    DataSource dataSource = dataSourceFactory.getDataSource();
    JdbcTransactionFactory transactionFactory = new JdbcTransactionFactory();

    Environment environment = new Environment("test", transactionFactory, dataSource);
    config.setEnvironment(environment);
    SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(config);
    return sqlSessionFactory.openSession(true);
}