Skip to content

Commit d49d488

Browse files
committed
Move pool clearing methods
1 parent 5a0b1e8 commit d49d488

File tree

2 files changed

+36
-40
lines changed

2 files changed

+36
-40
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionFactory.cs

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,48 +18,11 @@ namespace Microsoft.Data.ProviderBase
1818
{
1919
internal abstract class DbConnectionFactory
2020
{
21-
public void ClearAllPools()
22-
{
23-
using (TryEventScope.Create(nameof(SqlConnectionFactory)))
24-
{
25-
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
26-
foreach (KeyValuePair<DbConnectionPoolKey, DbConnectionPoolGroup> entry in connectionPoolGroups)
27-
{
28-
DbConnectionPoolGroup poolGroup = entry.Value;
29-
if (poolGroup != null)
30-
{
31-
poolGroup.Clear();
32-
}
33-
}
34-
}
35-
}
21+
3622

37-
public void ClearPool(DbConnection connection)
38-
{
39-
ADP.CheckArgumentNull(connection, nameof(connection));
40-
using (TryEventScope.Create("<prov.DbConnectionFactory.ClearPool|API> {0}", GetObjectId(connection)))
41-
{
42-
DbConnectionPoolGroup poolGroup = GetConnectionPoolGroup(connection);
43-
if (poolGroup != null)
44-
{
45-
poolGroup.Clear();
46-
}
47-
}
48-
}
23+
4924

50-
public void ClearPool(DbConnectionPoolKey key)
51-
{
52-
Debug.Assert(key != null, "key cannot be null");
53-
ADP.CheckArgumentNull(key.ConnectionString, $"{nameof(key)}.{nameof(key.ConnectionString)}");
54-
using (TryEventScope.Create("<prov.DbConnectionFactory.ClearPool|API> connectionString"))
55-
{
56-
Dictionary<DbConnectionPoolKey, DbConnectionPoolGroup> connectionPoolGroups = _connectionPoolGroups;
57-
if (connectionPoolGroups.TryGetValue(key, out DbConnectionPoolGroup poolGroup))
58-
{
59-
poolGroup.Clear();
60-
}
61-
}
62-
}
25+
6326

6427
internal abstract DbConnectionPoolProviderInfo CreateConnectionPoolProviderInfo(
6528
DbConnectionOptions connectionOptions);

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,39 @@ private SqlConnectionFactory()
7373

7474
#endregion
7575

76+
#region Public Methods
77+
78+
internal void ClearAllPools()
79+
{
80+
using TryEventScope scope = TryEventScope.Create(nameof(SqlConnectionFactory));
81+
foreach ((DbConnectionPoolKey _, DbConnectionPoolGroup group) in _connectionPoolGroups)
82+
{
83+
group?.Clear();
84+
}
85+
}
86+
87+
internal void ClearPool(DbConnection connection)
88+
{
89+
ADP.CheckArgumentNull(connection, nameof(connection));
90+
91+
using TryEventScope scope = TryEventScope.Create("<prov.SqlConnectionFactory.ClearPool|API> {0}", GetObjectId(connection));
92+
DbConnectionPoolGroup poolGroup = GetConnectionPoolGroup(connection);
93+
poolGroup?.Clear();
94+
}
95+
96+
internal void ClearPool(DbConnectionPoolKey key)
97+
{
98+
ADP.CheckArgumentNull(key.ConnectionString, $"{nameof(key)}.{nameof(key.ConnectionString)}");
99+
100+
using TryEventScope scope = TryEventScope.Create("<prov.SqlConnectionFactory.ClearPool|API> connectionString");
101+
if (_connectionPoolGroups.TryGetValue(key, out DbConnectionPoolGroup poolGroup))
102+
{
103+
poolGroup?.Clear();
104+
}
105+
}
106+
107+
#endregion
108+
76109
protected override DbConnectionInternal CreateConnection(
77110
DbConnectionOptions options,
78111
DbConnectionPoolKey poolKey,

0 commit comments

Comments
 (0)