forked from yxkhuijie/ick
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectionPoolManager.cpp
More file actions
97 lines (80 loc) · 2.02 KB
/
ConnectionPoolManager.cpp
File metadata and controls
97 lines (80 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "ConnectionPoolManager.h"
ConnectionPoolManager* ConnectionPoolManager::instance = new ConnectionPoolManager();
ConnectionPoolManager::ConnectionPoolManager(void)
{
startup();
}
ConnectionPoolManager::~ConnectionPoolManager(void)
{
}
// 单例实现
ConnectionPoolManager* ConnectionPoolManager::getInstance()
{
return instance;
}
// 初始化所有的连接池
void ConnectionPoolManager::startup()
{
}
Connection* ConnectionPoolManager::getConnection(string poolName)
{
Connection* conn = NULL;
if(pools.size()>0 && (pools.find(poolName) != pools.end()))
{
conn = this->getPool(poolName)->getConnection();
}
else
{
// System.out.println("Error:Can't find this connecion pool ->"+poolName);
}
return conn;
}
// 关闭,回收连接
void ConnectionPoolManager::close(string poolName,Connection* conn)
{
ConnectionPool* pool = getPool(poolName);
if(pool != NULL)
{
//pool.releaseConn(conn);
}
//catch (SQLException e)
//{
// System.out.println("连接池已经销毁");
// e.printStackTrace();
//}
}
// 清空连接池
void ConnectionPoolManager::destroy(string poolName)
{
ConnectionPool* pool = getPool(poolName);
if(pool != NULL)
{
// pool.destroy();
}
}
// 获得连接池
ConnectionPool* ConnectionPoolManager::getPool(string poolName)
{
ConnectionPool* pool = NULL;
if(pools.size() > 0)
{
map<string,ConnectionPool*>::iterator it = pools.find(poolName);
if(it != pools.end())
{
pool = it->second;
}
}
return pool;
}
void ConnectionPoolManager::addPool(string poolName, ConnectionPool* pool)
{
if(pools.find(poolName) == pools.end())
{
pools[poolName] = pool;
//throw "Connection pool named '" + poolName + "' added success, occured in ConnectionPoolManager::addPool";
}
else
{
throw "\nConnection pool named '" + poolName + "' has been existed, error in ConnectionPoolManager::addPool().";
}
}