设为首页 加入收藏

TOP

通向架构师的道路(第二十天)万能框架spring(二)maven结合spring与ibatis(二)
2018-03-14 09:00:25 】 浏览:848
Tags:通向 架构 师的 道路 第二十 万能 框架 spring maven 结合 ibatis
*/ public class IBatis3SQLSessionFactoryBean implements FactoryBean<SqlSessionFactory>, InitializingBean{ rivate String configLocation; private DataSource dataSource; private SqlSessionFactory sqlSessionFactory; private boolean useTransactionAwareDataSource = true; private String environmentId = "development"; public String getConfigLocation() { return configLocation; } public void setConfigLocation(String configLocation) { this.configLocation = configLocation; } public DataSource getDataSource() { return dataSource; } public void setDataSource(DataSource dataSource) { this.dataSource = dataSource; } public SqlSessionFactory getSqlSessionFactory() { return sqlSessionFactory; } public void setSqlSessionFactory(SqlSessionFactory sqlSessionFactory) { this.sqlSessionFactory = sqlSessionFactory; } public boolean isUseTransactionAwareDataSource() { return useTransactionAwareDataSource; } public void setUseTransactionAwareDataSource( boolean useTransactionAwareDataSource) { this.useTransactionAwareDataSource = useTransactionAwareDataSource; } public String getEnvironmentId() { return environmentId; } public void setEnvironmentId(String environmentId) { this.environmentId = environmentId; } public SqlSessionFactory getObject() throws Exception { return this.sqlSessionFactory; } public Class<SqlSessionFactory> getObjectType() { return SqlSessionFactory.class; } public boolean isSingleton() { return true; } public void afterPropertiesSet() throws Exception { this.sqlSessionFactory = this.buildSqlSessionFactory(configLocation); } protected SqlSessionFactory buildSqlSessionFactory(String configLocation) throws IOException { if (configLocation == null) { throw new IllegalArgumentException( "configLocation entry is required"); } DataSource dataSourceToUse = this.dataSource; if (this.useTransactionAwareDataSource && !(this.dataSource instanceof TransactionAwareDataSourceProxy)) { dataSourceToUse = new TransactionAwareDataSourceProxy(this.dataSource); } Environment environment = new Environment(environmentId, new IBatisTransactionFactory(dataSourceToUse), dataSourceToUse); Reader reader = Resources.getResourceAsReader(configLocation); XMLConfigBuilder parser = new XMLConfigBuilder(reader, null, null); Configuration config = parser.parse(); config.setEnvironment(environment); return new DefaultSqlSessionFactory(config); } }

org.sky.ssi.ibatis.IBatisDAOSupport

package org.sky.ssi.ibatis;

import javax.annotation.Resource;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;


/**

 * Base class for all DAO class. The subclass extends this class to get

 * <p>

 * DAO implementation proxy.

 *

 * @author lifetragedy

 *

 * @param <T>

 */

public class IBatisDAOSupport<T> {

 

    protected Logger log = Logger.getLogger(this.getClass());

    @Resource

    private SqlSess
首页 上一页 1 2 3 4 5 6 下一页 尾页 2/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇使用 partclone 备份磁盘分区 下一篇使用foremost恢复已删除文件

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目