Skip to content

Commit 04c9ee2

Browse files
committed
NH-4008 - Use FirebirdClient ClearPool without reflection.
1 parent f4e4186 commit 04c9ee2

File tree

1 file changed

+5
-20
lines changed

1 file changed

+5
-20
lines changed

src/NHibernate.Driver.FirebirdClient/Driver/FirebirdClientDriver.cs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
using System.Data;
44
using System.Data.Common;
55
using System.Linq;
6-
using System.Reflection;
76
using System.Text.RegularExpressions;
7+
using FirebirdSql.Data.FirebirdClient;
88
using NHibernate.Dialect;
99
using NHibernate.SqlCommand;
1010
using NHibernate.SqlTypes;
@@ -40,12 +40,12 @@ public override string NamedPrefix
4040

4141
public override DbConnection CreateConnection()
4242
{
43-
return new FirebirdSql.Data.FirebirdClient.FbConnection();
43+
return new FbConnection();
4444
}
4545

4646
public override DbCommand CreateCommand()
4747
{
48-
return new FirebirdSql.Data.FirebirdClient.FbCommand();
48+
return new FbCommand();
4949
}
5050

5151

@@ -105,39 +105,24 @@ private string GetFbTypeFromDbType(DbType dbType)
105105
return _fbDialect.GetCastTypeName(new SqlType(dbType));
106106
}
107107

108-
private static volatile MethodInfo _clearPool;
109-
private static volatile MethodInfo _clearAllPools;
110-
111108
/// <summary>
112109
/// Clears the connection pool.
113110
/// </summary>
114111
/// <param name="connectionString">The connection string of connections for which to clear the pool.
115112
/// <c>null</c> for clearing them all.</param>
116113
public void ClearPool(string connectionString)
117114
{
118-
// In case of concurrent threads, may initialize many times. We do not care.
119-
// Members are volatile for avoiding it gets used while its constructor is not yet ended.
120-
if (_clearPool == null || _clearAllPools == null)
121-
{
122-
using (var clearConnection = CreateConnection())
123-
{
124-
var connectionType = clearConnection.GetType();
125-
_clearPool = connectionType.GetMethod("ClearPool") ?? throw new InvalidOperationException("Unable to resolve ClearPool method.");
126-
_clearAllPools = connectionType.GetMethod("ClearAllPools") ?? throw new InvalidOperationException("Unable to resolve ClearAllPools method.");
127-
}
128-
}
129-
130115
if (connectionString != null)
131116
{
132117
using (var clearConnection = CreateConnection())
133118
{
134119
clearConnection.ConnectionString = connectionString;
135-
_clearPool.Invoke(null, new object[] {clearConnection});
120+
FbConnection.ClearPool((FbConnection)clearConnection);
136121
}
137122
return;
138123
}
139124

140-
_clearAllPools.Invoke(null, new object[0]);
125+
FbConnection.ClearAllPools();
141126
}
142127
}
143128
}

0 commit comments

Comments
 (0)