工厂方法模式
Mybatis提供了两个javax.sql.DateSource接口实现,为PooledDataSource和UnpooledDataSource,分别使用PooledDataSourceFactory和UnpooledDataSourceFactory创建
UnpooledDataSource
每次UnpooledDataSource.getConnection()
会创建一个新的链接
PooledDataSource
PooledDataSource管理PooledConnection对象,PooledConnection封装了真正的Connection对象(通过UnpooledDataSource创建)以及该对象的代理对象(JDK动态代理)。
PooledConnection,invoke()会对close()方法实现代理,将连接放入连接池而不是真正的关掉,poolState管理所有的连接状态