*/
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 |