源码一:PooledDataSourceFactory 继承自UnpooledDataSourceFactory
package org.apache.ibatis.datasource.pooled;
import org.apache.ibatis.datasource.unpooled.UnpooledDataSourceFactory;
/**
* @author Clinton Begin
*/
public class PooledDataSourceFactory extends UnpooledDataSourceFactory {
public PooledDataSourceFactory() {
this.dataSource = new PooledDataSource();
}
}
源码二:UnpooledDataSourceFactory 实现了DataSourceFactory 接口
package org.apache.ibatis.datasource.unpooled;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.ibatis.datasource.DataSourceException;
import org.apache.ibatis.datasource.DataSourceFactory;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.reflection.SystemMetaObject;
/**
* @author Clinton Begin
*/
public class UnpooledDataSourceFactory implements DataSourceFactory {
private static final String DRIVER_PROPERTY_PREFIX = "driver.";
private static final int DRIVER_PROPERTY_PREFIX_LENGTH = DRIVER_PROPERTY_PREFIX.length();
protected DataSource dataSource;
public UnpooledDataSourceFactory() {
this.dataSource = new UnpooledDataSource();
}
@Override
public void setProperties(Properties properties) {
Properties driverProperties = new Properties();
MetaObject metaDataSource = SystemMetaObject.forObject(dataSource);
for (Object key : properties.keySet()) {
String propertyName = (String) key;
if (propertyName.startsWith(DRIVER_PROPERTY_PREFIX)) {
String value = properties.getProperty(propertyName);
driverProperties.setProperty(propertyName.substring(DRIVER_PROPERTY_PREFIX_LENGTH), value);
} else if (metaDataSource.hasSetter(propertyName)) {
String value = (String) properties.get(propertyName);
Object convertedValue = convertValue(metaDataSource, propertyName, value);
metaDataSource.setValue(propertyName, convertedValue);
} else {
throw new DataSourceException("Unknown DataSource property: " + propertyName);
}
}
if (driverProperties.size() > 0) {
metaDataSource.setValue("driverProperties", driverProperties);
}
}
@Override
public DataSource getDataSource() {
return dataSource;
}
private Object convertValue(MetaObject metaDataSource, String propertyName, String value) {
Object convertedValue = value;
Class<?> targetType = metaDataSource.getSetterType(propertyName);
if (targetType == Integer.class || targetType == int.class) {
convertedValue = Integer.valueOf(value);
} else if (targetType == Long.class || targetType == long.class) {
convertedValue = Long.valueOf(value);
} else if (targetType == Boolean.class || targetType == boolean.class) {
convertedValue = Boolean.valueOf(value);
}
return convertedValue;
}
}
相关推荐
MyBatis源码分析.pdf
Mybatis源码分析主要分三部分: 1.使用案例讲解 2.Mybatis中用的所有设计模式讲解 3.源码分析
阿里巴巴P7架构师纯手工打造MyBatis源码——1小时解密底层源码.txt 需要更多往期录播资料可以联系我
5套完整springboot+mybatis源码下载只供学习之用,一套登录,一套权限,一套博客,一套.....
适合学习mybatis源码的各位同学,搜集不易,多多支持
一本小小的MyBatis源码分析书,内容详细介绍MyBatis源码!对于初中级java开发工程师是必备的!
阅读mybatis源码所记笔记。 基本: 1.数据源获取 2.mapper的sql语句获取 3.怎么去获得到的resultSet 重点: 1.orm是什么:体现于resultSet的数据库类型和java类型的转换 2.mybatis的一级缓存原理(简单的ifelse判断...
mybatis的源码分析视频,有详细的视频和文档。 视频地址亲测有效。失效了,请联系我。
mybatis源码包mybatis源码包mybatis源码包mybatis源码包
给大家分享一套课程,Java架构师之源码分析专题SpringBoot2.x、Spring5、SpringMVC、Mybatis源码分析,希望对大家学习有帮助。
Mybatis源码分析
mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码mybatis核心源码...
mybatis中文文档和mybatis源码
MyBatis源码解析
刚开始学习mybatis的童鞋们注意了,查看mybatis源码,深入了解mybatis很有用哦
Spring整合Mybatis源码解析
mybatis源码阅读 配置 配置都在配置类 映射代理 映射器代理 3.3.1版本后ExecutorType为简单,重复使用批量插入可以正确返回生成主键 密钥生成器 useGeneratedKeys为true使用Jdbc3KeyGenerator selectKey节点使用...
mybatis源码
Spring boot Mybatis源码,只是单纯的分享给有需要的人使用,俗话说的好,万事开头难,当迈开了第一步,就相当于打开了一扇门,发现了新大陆,所以我们要持之以恒,才能取得成功,让我们一起努力,为心中最美好的...