From 84449e57f325999936eca908e1a8525dc6d30966 Mon Sep 17 00:00:00 2001 From: 28810 <28810@YEXIANGQIN> Date: Fri, 15 Feb 2019 13:53:10 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=B2=E6=AD=A2=E5=90=8C=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E8=A2=ABIFreeSql=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=A4=9A=E6=AC=A1=EF=BC=8C=E5=8F=91=E7=94=9F=E8=BF=9E=E6=8E=A5?= =?UTF-8?q?=E6=B1=A0=E6=BA=A2=E5=87=BAbug=EF=BC=88ado.net=E8=BF=9E?= =?UTF-8?q?=E6=8E=A5=E6=B1=A0=E5=8E=9F=E7=90=86=EF=BC=8C=E5=87=8F=E5=B0=91?= =?UTF-8?q?=E8=A7=A3=E9=87=8A=E6=88=90=E6=9C=AC=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FreeSql/MySql/MySqlAdo/MySqlConnectionPool.cs | 6 ++++-- FreeSql/Oracle/OracleAdo/OracleConnectionPool.cs | 6 ++++-- .../PostgreSQL/PostgreSQLAdo/PostgreSQLConnectionPool.cs | 6 ++++-- FreeSql/SqlServer/SqlServerAdo/SqlServerConnectionPool.cs | 6 ++++-- FreeSql/Sqlite/SqliteAdo/SqliteConnectionPool.cs | 6 ++++-- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/FreeSql/MySql/MySqlAdo/MySqlConnectionPool.cs b/FreeSql/MySql/MySqlAdo/MySqlConnectionPool.cs index 50196cfd..a0f69578 100644 --- a/FreeSql/MySql/MySqlAdo/MySqlConnectionPool.cs +++ b/FreeSql/MySql/MySqlAdo/MySqlConnectionPool.cs @@ -1,6 +1,7 @@ using MySql.Data.MySqlClient; using SafeObjectPool; using System; +using System.Collections.Concurrent; using System.Data; using System.Data.Common; using System.Text.RegularExpressions; @@ -43,6 +44,7 @@ namespace FreeSql.MySql { public bool IsThrowGetTimeoutException { get; set; } = true; public int CheckAvailableInterval { get; set; } = 5; + static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); private string _connectionString; public string ConnectionString { get => _connectionString; @@ -51,7 +53,8 @@ namespace FreeSql.MySql { var poolsizePatern = @"Max\s*pool\s*size\s*=\s*(\d+)"; Match m = Regex.Match(connStr, poolsizePatern, RegexOptions.IgnoreCase); if (m.Success == false || int.TryParse(m.Groups[1].Value, out var poolsize) == false || poolsize <= 0) poolsize = 100; - PoolSize = poolsize + 1; + var connStrIncr = dicConnStrIncr.AddOrUpdate(connStr, 1, (oldkey, oldval) => oldval + 1); + PoolSize = poolsize + connStrIncr; _connectionString = m.Success ? Regex.Replace(connStr, poolsizePatern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) : $"{connStr};Max pool size={PoolSize}"; @@ -62,7 +65,6 @@ namespace FreeSql.MySql { } } - public bool OnCheckAvailable(Object obj) { if ((obj.Value as MySqlConnection).Ping() == false) obj.Value.Open(); return (obj.Value as MySqlConnection).Ping(); diff --git a/FreeSql/Oracle/OracleAdo/OracleConnectionPool.cs b/FreeSql/Oracle/OracleAdo/OracleConnectionPool.cs index cc0321d5..ae16d021 100644 --- a/FreeSql/Oracle/OracleAdo/OracleConnectionPool.cs +++ b/FreeSql/Oracle/OracleAdo/OracleConnectionPool.cs @@ -1,6 +1,7 @@ using Oracle.ManagedDataAccess.Client; using SafeObjectPool; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Data.Common; @@ -58,6 +59,7 @@ namespace FreeSql.Oracle { public bool IsThrowGetTimeoutException { get; set; } = true; public int CheckAvailableInterval { get; set; } = 5; + static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); private string _connectionString; public string ConnectionString { get => _connectionString; @@ -66,7 +68,8 @@ namespace FreeSql.Oracle { var poolsizePatern = @"Max\s*pool\s*size\s*=\s*(\d+)"; Match m = Regex.Match(connStr, poolsizePatern, RegexOptions.IgnoreCase); if (m.Success == false || int.TryParse(m.Groups[1].Value, out var poolsize) == false || poolsize <= 0) poolsize = 100; - PoolSize = poolsize + 1; + var connStrIncr = dicConnStrIncr.AddOrUpdate(connStr, 1, (oldkey, oldval) => oldval + 1); + PoolSize = poolsize + connStrIncr; _connectionString = m.Success ? Regex.Replace(connStr, poolsizePatern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) : $"{connStr};Max pool size={PoolSize}"; @@ -77,7 +80,6 @@ namespace FreeSql.Oracle { } } - public bool OnCheckAvailable(Object obj) { if (obj.Value.State == ConnectionState.Closed) obj.Value.Open(); var cmd = obj.Value.CreateCommand(); diff --git a/FreeSql/PostgreSQL/PostgreSQLAdo/PostgreSQLConnectionPool.cs b/FreeSql/PostgreSQL/PostgreSQLAdo/PostgreSQLConnectionPool.cs index afa5cbfb..c0e1d7fd 100644 --- a/FreeSql/PostgreSQL/PostgreSQLAdo/PostgreSQLConnectionPool.cs +++ b/FreeSql/PostgreSQL/PostgreSQLAdo/PostgreSQLConnectionPool.cs @@ -1,6 +1,7 @@ using Npgsql; using SafeObjectPool; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Data.Common; @@ -53,6 +54,7 @@ namespace FreeSql.PostgreSQL { public bool IsThrowGetTimeoutException { get; set; } = true; public int CheckAvailableInterval { get; set; } = 5; + static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); private string _connectionString; public string ConnectionString { get => _connectionString; @@ -61,7 +63,8 @@ namespace FreeSql.PostgreSQL { var poolsizePatern = @"Maximum\s*pool\s*size\s*=\s*(\d+)"; Match m = Regex.Match(connStr, poolsizePatern, RegexOptions.IgnoreCase); if (m.Success == false || int.TryParse(m.Groups[1].Value, out var poolsize) == false || poolsize <= 0) poolsize = 100; - PoolSize = poolsize + 1; + var connStrIncr = dicConnStrIncr.AddOrUpdate(connStr, 1, (oldkey, oldval) => oldval + 1); + PoolSize = poolsize + connStrIncr; _connectionString = m.Success ? Regex.Replace(connStr, poolsizePatern, $"Maximum pool size={PoolSize}", RegexOptions.IgnoreCase) : $"{connStr};Maximum pool size={PoolSize}"; @@ -72,7 +75,6 @@ namespace FreeSql.PostgreSQL { } } - public bool OnCheckAvailable(Object obj) { if (obj.Value.State == ConnectionState.Closed) obj.Value.Open(); var cmd = obj.Value.CreateCommand(); diff --git a/FreeSql/SqlServer/SqlServerAdo/SqlServerConnectionPool.cs b/FreeSql/SqlServer/SqlServerAdo/SqlServerConnectionPool.cs index cdd74202..f49d191f 100644 --- a/FreeSql/SqlServer/SqlServerAdo/SqlServerConnectionPool.cs +++ b/FreeSql/SqlServer/SqlServerAdo/SqlServerConnectionPool.cs @@ -1,5 +1,6 @@ using SafeObjectPool; using System; +using System.Collections.Concurrent; using System.Data; using System.Data.Common; using System.Data.SqlClient; @@ -47,6 +48,7 @@ namespace FreeSql.SqlServer { public bool IsThrowGetTimeoutException { get; set; } = true; public int CheckAvailableInterval { get; set; } = 5; + static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); private string _connectionString; public string ConnectionString { get => _connectionString; @@ -55,7 +57,8 @@ namespace FreeSql.SqlServer { var poolsizePatern = @"Max\s*pool\s*size\s*=\s*(\d+)"; Match m = Regex.Match(connStr, poolsizePatern, RegexOptions.IgnoreCase); if (m.Success == false || int.TryParse(m.Groups[1].Value, out var poolsize) == false || poolsize <= 0) poolsize = 100; - PoolSize = poolsize + 1; + var connStrIncr = dicConnStrIncr.AddOrUpdate(connStr, 1, (oldkey, oldval) => oldval + 1); + PoolSize = poolsize + connStrIncr; _connectionString = m.Success ? Regex.Replace(connStr, poolsizePatern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) : $"{connStr};Max pool size={PoolSize}"; @@ -66,7 +69,6 @@ namespace FreeSql.SqlServer { } } - public bool OnCheckAvailable(Object obj) { if (obj.Value.State == ConnectionState.Closed) obj.Value.Open(); var cmd = obj.Value.CreateCommand(); diff --git a/FreeSql/Sqlite/SqliteAdo/SqliteConnectionPool.cs b/FreeSql/Sqlite/SqliteAdo/SqliteConnectionPool.cs index 55f82a93..1612fbfb 100644 --- a/FreeSql/Sqlite/SqliteAdo/SqliteConnectionPool.cs +++ b/FreeSql/Sqlite/SqliteAdo/SqliteConnectionPool.cs @@ -1,5 +1,6 @@ using SafeObjectPool; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Data; using System.Data.Common; @@ -49,6 +50,7 @@ namespace FreeSql.Sqlite { public int CheckAvailableInterval { get; set; } = 5; public string[] Attaches = new string[0]; + static ConcurrentDictionary dicConnStrIncr = new ConcurrentDictionary(StringComparer.CurrentCultureIgnoreCase); private string _connectionString; public string ConnectionString { get => _connectionString; @@ -57,7 +59,8 @@ namespace FreeSql.Sqlite { var poolsizePatern = @"Max\s*pool\s*size\s*=\s*(\d+)"; Match m = Regex.Match(connStr, poolsizePatern, RegexOptions.IgnoreCase); if (m.Success == false || int.TryParse(m.Groups[1].Value, out var poolsize) == false || poolsize <= 0) poolsize = 100; - PoolSize = poolsize + 1; + var connStrIncr = dicConnStrIncr.AddOrUpdate(connStr, 1, (oldkey, oldval) => oldval + 1); + PoolSize = poolsize + connStrIncr; _connectionString = m.Success ? Regex.Replace(connStr, poolsizePatern, $"Max pool size={PoolSize}", RegexOptions.IgnoreCase) : $"{connStr};Max pool size={PoolSize}"; @@ -74,7 +77,6 @@ namespace FreeSql.Sqlite { } } - public bool OnCheckAvailable(Object obj) { if ((obj.Value as SQLiteConnection).Ping() == false) obj.Value.OpenAndAttach(Attaches); return (obj.Value as SQLiteConnection).Ping();