/*
* Copyright 2004 Clinton Begin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ibatis.common.jdbc;
import com.ibatis.common.beans.ClassInfo;
import com.ibatis.common.resources.Resources;
import com.ibatis.common.logging.LogFactory;
import com.ibatis.common.logging.Log;
import javax.sql.DataSource;
import java.io.PrintWriter;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.sql.*;
import java.util.*;
/**
* This is a simple, synchronous, thread-safe database connection pool. <p/>
* REQUIRED PROPERTIES ------------------- JDBC.Driver JDBC.ConnectionURL
* JDBC.Username JDBC.Password <p/> Pool.MaximumActiveConnections
* Pool.MaximumIdleConnections Pool.MaximumCheckoutTime Pool.TimeToWait
* Pool.PingQuery Pool.PingEnabled Pool.PingConnectionsOlderThan
* Pool.PingConnectionsNotUsedFor Pool.QuietMode
*/
public class SimpleDataSource implements DataSource {
private static final Log log = LogFactory.getLog(SimpleDataSource.class);
// Required Properties
private static final String PROP_JDBC_DRIVER = "JDBC.Driver";
private static final String PROP_JDBC_URL = "JDBC.ConnectionURL";
private static final String PROP_JDBC_USERNAME = "JDBC.Username";
private static final String PROP_JDBC_PASSWORD = "JDBC.Password";
private static final String PROP_JDBC_DEFAULT_AUTOCOMMIT = "JDBC.DefaultAutoCommit";
// Optional Properties
private static final String PROP_POOL_MAX_ACTIVE_CONN = "Pool.MaximumActiveConnections";
private static final String PROP_POOL_MAX_IDLE_CONN = "Pool.MaximumIdleConnections";
private static final String PROP_POOL_MAX_CHECKOUT_TIME = "Pool.MaximumCheckoutTime";
private static final String PROP_POOL_TIME_TO_WAIT = "Pool.TimeToWait";
private static final String PROP_POOL_PING_QUERY = "Pool.PingQuery";
private static final String PROP_POOL_PING_CONN_OLDER_THAN = "Pool.PingConnectionsOlderThan";
private static final String PROP_POOL_PING_ENABLED = "Pool.PingEnabled";
private static final String PROP_POOL_PING_CONN_NOT_USED_FOR = "Pool.PingConnectionsNotUsedFor";
private int expectedConnectionTypeCode;
// Additional Driver Properties prefix
private static final String ADD_DRIVER_PROPS_PREFIX = "Driver.";
private static final int ADD_DRIVER_PROPS_PREFIX_LENGTH = ADD_DRIVER_PROPS_PREFIX
.length();
// ----- BEGIN: FIELDS LOCKED BY POOL_LOCK -----
//
private final Object POOL_LOCK = new Object();
private final Thread POOL_Thread = new Thread();
// 空闲的连接池列表,内部对象为SimplePooledConnection实例化对象
private List idleConnections = new ArrayList();
// 活动的连接池列表,内部对象为SimplePooledConnection实例化对象
private List activeConnections = new ArrayList();
// 请求连接的总数
private long requestCount = 0;
// 累计请求时间
private long accumulatedRequestTime = 0;
// 累计检查时间
private long accumulatedCheckoutTime = 0;
// 统计超时并被被回收的 SimplePooledConnection实例化对象的个数
private long claimedOverdueConnectionCount = 0;
// 统计超时并被被回收的 SimplePooledConnection实例化对象的时间
private long accumulatedCheckoutTimeOfOverdueConnections = 0;
// 累积为回收SimplePooledConnection实例化对象而等待的时间
private long accumulatedWaitTime = 0;
// 累积为回收SimplePooledConnection实例化对象而等待的次数
private long hadToWaitCount = 0;
// 空闲池中SimplePooledConnection实例化对象无效的次数
private long badConnectionCount = 0;
// ----- END: FIELDS LOCKED BY POOL_LOCK -----
// ----- BEGIN: PROPERTY FIELDS FOR CONFIGURATION -----
// 数据库属性配置信息
private String jdbcDriver;
private String jdbcUrl;
private String jdbcUsername;
private String jdbcPassword;
private boolean jdbcDefaultAutoCommit;
private Properties driverProps;
private boolean useDriverProps;
//活动连接池的最大容量
private int poolMaximumActiveConnections;
//空闲连接池的最大容量
private int poolMaximumIdleConnections;
//连接池的检查时间
private int poolMaximumCheckoutTime;
//连接池的等待时间
private int poolTimeToWait;
private String poolPingQuery;
private boolean poolPingEnabled;
private int poolPingConnectionsOlderThan;
private int poolPingConnectionsNotUsedFor;
// ----- END: PROPERTY FIELDS FOR CONFIGURATION -----
/**
* Constructor to allow passing in a map of properties for configuration
*
* @param props -
* the configuration parameters
*/
public SimpleDataSource(Map props) {
initialize(props);
}
private void initialize(Map props) {
try {
String prop_pool_ping_query = null;
if (props == null) {
throw new RuntimeException(
"SimpleDataSource: The properties map passed to the initializer was null.");
}
if (!(props.containsKey(PROP_JDBC_DRIVER)
&& props.containsKey(PROP_JDBC_URL)
&& props.containsKey(PROP_JDBC_USERNAME) && props
.containsKey(PROP_JDBC_PASSWORD))) {
throw new RuntimeException(
"SimpleDataSource: Some properties were not set.");
} else {
jdbcDriver = (String) props.get(PROP_JDBC_DRIVER);
jdbcUrl = (String) props.get(PROP_JDBC_URL);
jdbcUsername = (String) props.get(PROP_JDBC_USERNAME);
jdbcPassword = (String) props.get(PROP_JDBC_PASSWORD);
poolMaximumActiveConnections = props
.containsKey(PROP_POOL_MAX_ACTIVE_CONN) ? Integer
.parseInt((String) props.get(PROP_POOL_MAX_ACTIVE_CONN))
: 10;
poolMaximumIdleConnections = props
.containsKey(PROP_POOL_MAX_IDLE_CONN) ? Integer
.parseInt((String) props.get(PROP_POOL_MAX_IDLE_CONN))
: 5;
poolMaximumCheckoutTime = props
.containsKey(PROP_POOL_MAX_CHECKOUT_TIME) ? Integer
.parseInt((String) props
.get(PROP_POOL_MAX_CHECKOUT_TIME)) : 20000;
poolTimeToWait = props.containsKey(PROP_POOL_TIME_TO_WAIT) ? Integer
.parseInt((String) props.get(PROP_POOL_TIME_TO_WAIT))
: 20000;
poolPingEnabled = props.containsKey(PROP_POOL_PING_ENABLED)
&& Boolean.valueOf(
(String) props.get(PROP_POOL_PING_ENABLED))
.booleanValue();
prop_pool_ping_query = (String) props.get(PROP_POOL_PING_QUERY);
poolPingQuery = props.containsKey(PROP_POOL_PING_QUERY) ? prop_pool_ping_query
: "NO PING QUERY SET";
poolPingConnectionsOlderThan = props
.containsKey(PROP_POOL_PING_CONN_OLDER_THAN) ? Integer
.parseInt((String) props
.get(PROP_POOL_PING_CONN_OLDER_THAN)) : 0;
poolPingConnectionsNotUsedFor = props
.containsKey(PROP_POOL_PING_CONN_NOT_USED_FOR) ? Integer
.parseInt((String) props
.get(PROP_POOL_PING_CONN_NOT_USED_FOR))
: 0;
jdbcDefaultAutoCommit = props
.containsKey(PROP_JDBC_DEFAULT_AUTOCOMMIT)
&& Boolean.valueOf(
(String) props
.get(PROP_JDBC_DEFAULT_AUTOCOMMIT))
.booleanValue();
useDriverProps = false;
Iterator propIter = props.keySet().iterator();
driverProps = new Properties();
driverProps.put("user", jdbcUsername);
driverProps.put("p
没有合适的资源?快使用搜索试试~ 我知道了~
资源详情
资源评论
资源推荐
收起资源包目录
ibatis框架源码剖析光盘资料 (909个子文件)
SqlMapExecutorDelegate.class 20KB
ResultMap.class 19KB
SimpleDataSource.class 18KB
CallableStatementResultSet.class 17KB
SqlExecutor.class 17KB
MappedStatement.class 15KB
SqlMapConfiguration.class 14KB
ClassInfo.class 13KB
MappedStatementConfig.class 11KB
HibernateDaoTemplate.class 11KB
XmlDaoManagerBuilder.class 11KB
DynamicSql.class 10KB
SimpleDataSource$SimplePooledConnection.class 9KB
SqlMapSessionImpl.class 9KB
DomProbe.class 8KB
SqlMapClientImpl.class 8KB
InlineParameterMapParser.class 8KB
ResultMapConfig.class 8KB
Order.class 8KB
Order.class 8KB
Target.class 8KB
SqlMapDaoTemplate.class 7KB
CacheModel.class 7KB
ComplexBeanProbe.class 7KB
ParameterMap.class 7KB
XMLSqlSource.class 7KB
AutoResultMap.class 6KB
TypeHandlerFactory.class 6KB
PaginatedDataList.class 6KB
ScriptRunner.class 6KB
IterateContext.class 6KB
ResultGetterImpl.class 6KB
ConditionalTagHandler.class 6KB
SqlStatementParser.class 6KB
SessionScope.class 6KB
AccountBean.class 6KB
JavaBeanDataExchange.class 6KB
ParameterSetterImpl.class 6KB
NodeletParser.class 6KB
XmlParserState.class 6KB
NodeletParser.class 5KB
OrderBean.class 5KB
CachingStatement.class 5KB
SqlMapConfigParser.class 5KB
Resources.class 5KB
PaginatedArrayList.class 5KB
SqlMapParser.class 5KB
CatalogBean.class 5KB
ParameterMapConfig.class 5KB
SqlTagContext.class 5KB
SqlExecutor$Batch.class 5KB
DbcpConfiguration.class 5KB
ComplexDataExchange.class 5KB
IterateTagHandler.class 5KB
StandardDaoManager.class 5KB
ParameterMapping.class 4KB
BaseProbe.class 4KB
SqlMapParser$14.class 4KB
DaoContext.class 4KB
Project.class 4KB
DomDataExchange.class 4KB
SqlTag.class 4KB
StatementScope.class 4KB
SqlMapParser$16.class 4KB
RowHandlerCallback.class 4KB
GenericProbe.class 4KB
JdbcDaoTransactionManager.class 4KB
PreparedStatementLogProxy.class 4KB
ListDataExchange.class 4KB
Account.class 4KB
Account.class 4KB
CartBean.class 4KB
SimpleDynamicSql.class 4KB
TransactionManager.class 4KB
BaseLogProxy.class 4KB
SqlMapConfigParser$7.class 4KB
ConfigParser.class 4KB
CacheModelConfig.class 4KB
Cart.class 4KB
Cart.class 4KB
ConnectionLogProxy.class 4KB
UnknownTypeHandler.class 4KB
JtaTransaction.class 4KB
XmlList.class 3KB
SqlMapParser$11.class 3KB
Item.class 3KB
Item.class 3KB
SqlMapConfigParser$3.class 3KB
EnhancedLazyResultLoader$EnhancedLazyResultLoaderImpl.class 3KB
JtaDaoTransaction.class 3KB
StatementLogProxy.class 3KB
LazyResultLoader.class 3KB
C3p0Configuration.class 3KB
MapDataExchange.class 3KB
SqlMapConfigParser$9.class 3KB
ResultMapping.class 3KB
SqlMapParser$13.class 3KB
MemoryCacheController.class 3KB
ResultSetLogProxy.class 3KB
ResultLoader.class 3KB
共 909 条
- 1
- 2
- 3
- 4
- 5
- 6
- 10
014379200
- 粉丝: 1
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 海尔H42E10 6i981BTA DH1PY600000 MBOOT usb.bin 程序.zip
- 网盘的功能实现之数据库搭建笔记
- 软件工程与软件测试阶段作业三.doc
- 软件工程中的人工智能辅助设计研究.pptx
- 海尔智能电视刷机数据 H42E07 机编DH1QR000H07 务必确认机编一致 强制刷机 整机USB升级主程序
- 4444444444444444444
- 基于PHP实现响应式创业园区管委会网站.zip
- 安卓手机用作电脑网络摄像头的工具文件
- 海尔智能电视刷机数据 H32E10 机编DH1QX000805 务必确认机编一致 强制刷机 整机USB升级主程序
- ComfyUI AI老照片修复上色工作流
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0