From 72781596bdaf16ee5a5fd74f0af1c31c2a0b3117 Mon Sep 17 00:00:00 2001
From: 28810 <28810@YEXIANGQIN>
Date: Fri, 20 Mar 2020 20:32:49 +0800
Subject: [PATCH] =?UTF-8?q?-=20=E7=A7=BB=E9=99=A4=20In=E5=A4=9A=E8=A1=A8?=
=?UTF-8?q?=E8=A1=A8=E8=BE=BE=E5=BC=8F=E5=87=BD=E6=95=B0=E8=A7=A3=E6=9E=90?=
=?UTF-8?q?=20#243=EF=BC=9B=20-=20=E8=B0=83=E6=95=B4=20SafeObjectPool=20?=
=?UTF-8?q?=E6=BA=90=E7=A0=81=E7=A7=BB=E5=85=A5=E9=A1=B9=E7=9B=AE=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Examples/dbcontext_01/Program.cs | 2 +-
FreeSql.DbContext/UnitOfWork/UnitOfWork.cs | 2 +-
.../Extensions/FreeSqlGlobalExpressionCall.cs | 92 +--
FreeSql/FreeSql.csproj | 9 +-
FreeSql/FreeSql.xml | 253 ++++++--
FreeSql/FreeUtil.cs | 2 +-
FreeSql/Interface/IAdo.cs | 2 +-
.../CommonProvider/AdoProvider/AdoProvider.cs | 2 +-
.../AdoProvider/AdoProviderAsync.cs | 2 +-
.../AdoProvider/AdoProviderTransaction.cs | 2 +-
.../AdoProvider/DbConnectionPool.cs | 2 +-
.../Internal/CommonProvider/InsertProvider.cs | 2 +-
.../CommonProvider/InsertProviderAsync.cs | 2 +-
FreeSql/Internal/CommonUtils.cs | 2 +-
FreeSql/Internal/ObjectPool/DefaultPolicy.cs | 74 +++
FreeSql/Internal/ObjectPool/IObjectPool.cs | 63 ++
FreeSql/Internal/ObjectPool/IPolicy.cs | 99 ++++
FreeSql/Internal/ObjectPool/Object.cs | 93 +++
FreeSql/Internal/ObjectPool/ObjectPool.cs | 547 ++++++++++++++++++
.../Curd/MsAccessInsert.cs | 2 +-
.../MsAccessAdo/MsAccessAdo.cs | 2 +-
.../MsAccessAdo/MsAccessConnectionPool.cs | 2 +-
.../MySqlAdo/MySqlAdo.cs | 2 +-
.../MySqlAdo/MySqlConnectionPool.cs | 2 +-
.../Dameng/OdbcDamengAdo/OdbcDamengAdo.cs | 2 +-
.../OdbcDamengAdo/OdbcDamengConnectionPool.cs | 2 +-
.../Default/Curd/OdbcInsert.cs | 2 +-
.../Default/OdbcAdo/OdbcAdo.cs | 2 +-
.../Default/OdbcAdo/OdbcConnectionPool.cs | 2 +-
.../MySql/Curd/OdbcMySqlInsert.cs | 2 +-
.../MySql/OdbcMySqlAdo/OdbcMySqlAdo.cs | 2 +-
.../OdbcMySqlAdo/OdbcMySqlConnectionPool.cs | 2 +-
.../Oracle/OdbcOracleAdo/OdbcOracleAdo.cs | 2 +-
.../OdbcOracleAdo/OdbcOracleConnectionPool.cs | 2 +-
.../OdbcPostgreSQLAdo/OdbcPostgreSQLAdo.cs | 2 +-
.../OdbcPostgreSQLConnectionPool.cs | 2 +-
.../SqlServer/Curd/OdbcSqlServerInsert.cs | 2 +-
.../OdbcSqlServerAdo/OdbcSqlServerAdo.cs | 2 +-
.../OdbcSqlServerConnectionPool.cs | 2 +-
.../OracleAdo/OracleAdo.cs | 2 +-
.../OracleAdo/OracleConnectionPool.cs | 2 +-
.../PostgreSQLAdo/PostgreSQLAdo.cs | 2 +-
.../PostgreSQLAdo/PostgreSQLConnectionPool.cs | 2 +-
.../PostgreSQLDbFirst.cs | 2 +-
.../Curd/SqlServerInsert.cs | 2 +-
.../SqlServerAdo/SqlServerAdo.cs | 2 +-
.../SqlServerAdo/SqlServerConnectionPool.cs | 2 +-
.../SqliteAdo/SqliteAdo.cs | 2 +-
.../SqliteAdo/SqliteConnectionPool.cs | 2 +-
49 files changed, 1138 insertions(+), 174 deletions(-)
create mode 100644 FreeSql/Internal/ObjectPool/DefaultPolicy.cs
create mode 100644 FreeSql/Internal/ObjectPool/IObjectPool.cs
create mode 100644 FreeSql/Internal/ObjectPool/IPolicy.cs
create mode 100644 FreeSql/Internal/ObjectPool/Object.cs
create mode 100644 FreeSql/Internal/ObjectPool/ObjectPool.cs
diff --git a/Examples/dbcontext_01/Program.cs b/Examples/dbcontext_01/Program.cs
index 0aa6a2a1..6f7b9727 100644
--- a/Examples/dbcontext_01/Program.cs
+++ b/Examples/dbcontext_01/Program.cs
@@ -40,7 +40,7 @@ namespace dbcontext_01
static IFreeSql fsql;
public static void Main(string[] args)
{
- var asse = typeof(SafeObjectPool.ObjectPool<>).Assembly;
+ var asse = typeof(FreeSql.Internal.ObjectPool.ObjectPool<>).Assembly;
fsql = new FreeSql.FreeSqlBuilder()
.UseConnectionString(FreeSql.DataType.Sqlite, @"Data Source=|DataDirectory|\dd2.db;Pooling=true;Max Pool Size=10")
diff --git a/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs b/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs
index a05b8ba6..4e0aa3de 100644
--- a/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs
+++ b/FreeSql.DbContext/UnitOfWork/UnitOfWork.cs
@@ -1,4 +1,4 @@
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
diff --git a/FreeSql/Extensions/FreeSqlGlobalExpressionCall.cs b/FreeSql/Extensions/FreeSqlGlobalExpressionCall.cs
index 2ad04f7d..67faf87a 100644
--- a/FreeSql/Extensions/FreeSqlGlobalExpressionCall.cs
+++ b/FreeSql/Extensions/FreeSqlGlobalExpressionCall.cs
@@ -1,16 +1,5 @@
-using FreeSql;
-using FreeSql.DataAnnotations;
+using FreeSql.DataAnnotations;
using System;
-using System.Collections;
-using System.Collections.Concurrent;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Data;
-using System.Drawing;
-using System.Linq;
-using System.Linq.Expressions;
-using System.Reflection;
-using System.Text;
using System.Threading;
[ExpressionCall]
@@ -50,83 +39,4 @@ public static class FreeSqlGlobalExpressionCall
expContext.Value.Result = $"{expContext.Value.ParsedContent["that"]} >= {expContext.Value.ParsedContent["start"]} and {expContext.Value.ParsedContent["that"]} < {expContext.Value.ParsedContent["end"]}";
return false;
}
-
-#if netcoreapp
- ///
- /// C#:从元组集合中查找 exp1, exp2 是否存在
- /// SQL:
- /// exp1 = that[0].Item1 and exp2 = that[0].Item2 OR
- /// exp1 = that[1].Item1 and exp2 = that[1].Item2 OR
- /// ...
- /// 注意:当 that 为 null 或 empty 时,返回 1=0
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static bool Contains([RawValue] this IEnumerable<(T1, T2)> that, T1 exp1, T2 exp2)
- {
- if (expContext.IsValueCreated == false || expContext.Value == null || expContext.Value.ParsedContent == null)
- return that?.Any(a => a.Item1.Equals(exp1) && a.Item2.Equals(exp2)) == true;
- if (that?.Any() != true)
- {
- expContext.Value.Result = "1=0";
- return false;
- }
- var sb = new StringBuilder();
- var idx = 0;
- foreach (var item in that)
- {
- if (idx++ > 0) sb.Append(" OR \r\n");
- sb
- .Append(expContext.Value.ParsedContent["exp1"]).Append(" = ").Append(expContext.Value.FormatSql(FreeSql.Internal.Utils.GetDataReaderValue(typeof(T1), item.Item1)))
- .Append(" AND ")
- .Append(expContext.Value.ParsedContent["exp2"]).Append(" = ").Append(expContext.Value.FormatSql(FreeSql.Internal.Utils.GetDataReaderValue(typeof(T2), item.Item2)));
- }
- expContext.Value.Result = sb.ToString();
- return true;
- }
- ///
- /// C#:从元组集合中查找 exp1, exp2, exp2 是否存在
- /// SQL:
- /// exp1 = that[0].Item1 and exp2 = that[0].Item2 and exp3 = that[0].Item3 OR
- /// exp1 = that[1].Item1 and exp2 = that[1].Item2 and exp3 = that[1].Item3 OR
- /// ...
- /// 注意:当 that 为 null 或 empty 时,返回 1=0
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static bool Contains([RawValue] this IEnumerable<(T1, T2, T3)> that, T1 exp1, T2 exp2, T3 exp3)
- {
- if (expContext.IsValueCreated == false || expContext.Value == null || expContext.Value.ParsedContent == null)
- return that.Any(a => a.Item1.Equals(exp1) && a.Item2.Equals(exp2) && a.Item3.Equals(exp3));
- if (that.Any() == false)
- {
- expContext.Value.Result = "1=0";
- return false;
- }
- var sb = new StringBuilder();
- var idx = 0;
- foreach (var item in that)
- {
- if (idx++ > 0) sb.Append(" OR \r\n");
- sb
- .Append(expContext.Value.ParsedContent["exp1"]).Append(" = ").Append(expContext.Value.FormatSql(FreeSql.Internal.Utils.GetDataReaderValue(typeof(T1), item.Item1)))
- .Append(" AND ")
- .Append(expContext.Value.ParsedContent["exp2"]).Append(" = ").Append(expContext.Value.FormatSql(FreeSql.Internal.Utils.GetDataReaderValue(typeof(T2), item.Item2)))
- .Append(" AND ")
- .Append(expContext.Value.ParsedContent["exp3"]).Append(" = ").Append(expContext.Value.FormatSql(FreeSql.Internal.Utils.GetDataReaderValue(typeof(T3), item.Item3)));
- }
- expContext.Value.Result = sb.ToString();
- return true;
- }
-#endif
}
\ No newline at end of file
diff --git a/FreeSql/FreeSql.csproj b/FreeSql/FreeSql.csproj
index 51229c77..c8887594 100644
--- a/FreeSql/FreeSql.csproj
+++ b/FreeSql/FreeSql.csproj
@@ -1,7 +1,7 @@
- netstandard2.0;netcoreapp31;netcoreapp30;netcoreapp22;netcoreapp21;net45;net40
+ netstandard2.0;net45;net40
1.3.0-preview10
true
YeXiangQin
@@ -30,13 +30,6 @@
3
-
-
-
-
-
- netcoreapp
-
net40
diff --git a/FreeSql/FreeSql.xml b/FreeSql/FreeSql.xml
index 96d40ff9..cbd67953 100644
--- a/FreeSql/FreeSql.xml
+++ b/FreeSql/FreeSql.xml
@@ -2900,6 +2900,225 @@
中间表,多对多
+
+
+ 是否可用
+
+
+
+
+ 不可用错误
+
+
+
+
+ 不可用时间
+
+
+
+
+ 将对象池设置为不可用,后续 Get/GetAsync 均会报错,同时启动后台定时检查服务恢复可用
+
+
+ 由【可用】变成【不可用】时返回true,否则返回false
+
+
+
+ 统计对象池中的对象
+
+
+
+
+ 统计对象池中的对象(完整)
+
+
+
+
+ 获取资源
+
+ 超时
+
+
+
+
+ 获取资源
+
+
+
+
+
+ 使用完毕后,归还资源
+
+ 对象
+ 是否重新创建
+
+
+
+ 名称
+
+
+
+
+ 池容量
+
+
+
+
+ 默认获取超时设置
+
+
+
+
+ 空闲时间,获取时若超出,则重新创建
+
+
+
+
+ 异步获取排队队列大小,小于等于0不生效
+
+
+
+
+ 获取超时后,是否抛出异常
+
+
+
+
+ 后台定时检查可用性间隔秒数
+
+
+
+
+ 对象池的对象被创建时
+
+ 返回被创建的对象
+
+
+
+ 销毁对象
+
+ 资源对象
+
+
+
+ 从对象池获取对象超时的时候触发,通过该方法统计
+
+
+
+
+ 从对象池获取对象成功的时候触发,通过该方法统计或初始化对象
+
+ 资源对象
+
+
+
+ 从对象池获取对象成功的时候触发,通过该方法统计或初始化对象
+
+ 资源对象
+
+
+
+ 归还对象给对象池的时候触发
+
+ 资源对象
+
+
+
+ 检查可用性
+
+ 资源对象
+
+
+
+
+ 事件:可用时触发
+
+
+
+
+ 事件:不可用时触发
+
+
+
+
+ 所属对象池
+
+
+
+
+ 在对象池中的唯一标识
+
+
+
+
+ 资源对象
+
+
+
+
+ 被获取的总次数
+
+
+
+ 最后获取时的时间
+
+
+
+ 最后归还时的时间
+
+
+
+
+ 创建时间
+
+
+
+
+ 最后获取时的线程id
+
+
+
+
+ 最后归还时的线程id
+
+
+
+
+ 重置 Value 值
+
+
+
+
+ 对象池管理类
+
+ 对象类型
+
+
+
+ 后台定时检查可用性
+
+
+
+
+
+ 创建对象池
+
+ 池大小
+ 池内对象的创建委托
+ 获取池内对象成功后,进行使用前操作
+
+
+
+ 创建对象池
+
+ 策略
+
+
+
+ 获取可用资源,或创建资源
+
+
+
不进行任何处理
@@ -2970,40 +3189,6 @@
-
-
- C#:从元组集合中查找 exp1, exp2 是否存在
- SQL:
- exp1 = that[0].Item1 and exp2 = that[0].Item2 OR
- exp1 = that[1].Item1 and exp2 = that[1].Item2 OR
- ...
- 注意:当 that 为 null 或 empty 时,返回 1=0
-
-
-
-
-
-
-
-
-
-
- C#:从元组集合中查找 exp1, exp2, exp2 是否存在
- SQL:
- exp1 = that[0].Item1 and exp2 = that[0].Item2 and exp3 = that[0].Item3 OR
- exp1 = that[1].Item1 and exp2 = that[1].Item2 and exp3 = that[1].Item3 OR
- ...
- 注意:当 that 为 null 或 empty 时,返回 1=0
-
-
-
-
-
-
-
-
-
-
测量两个经纬度的距离,返回单位:米
diff --git a/FreeSql/FreeUtil.cs b/FreeSql/FreeUtil.cs
index 145b8243..37e928c9 100644
--- a/FreeSql/FreeUtil.cs
+++ b/FreeSql/FreeUtil.cs
@@ -1,4 +1,4 @@
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections.Concurrent;
using System.Data.Common;
diff --git a/FreeSql/Interface/IAdo.cs b/FreeSql/Interface/IAdo.cs
index 3d93860d..d5ec0a8c 100644
--- a/FreeSql/Interface/IAdo.cs
+++ b/FreeSql/Interface/IAdo.cs
@@ -1,6 +1,6 @@
using FreeSql.DatabaseModel;
using FreeSql.Internal.Model;
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections.Generic;
using System.Data;
diff --git a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProvider.cs b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProvider.cs
index 2f2facd5..07d785ca 100644
--- a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProvider.cs
+++ b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProvider.cs
@@ -1,4 +1,4 @@
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
diff --git a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderAsync.cs b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderAsync.cs
index bc8b96b6..356222af 100644
--- a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderAsync.cs
+++ b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderAsync.cs
@@ -1,5 +1,5 @@
using FreeSql.Internal.Model;
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections.Generic;
using System.Data;
diff --git a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderTransaction.cs b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderTransaction.cs
index 60133ed4..cd7356a5 100644
--- a/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderTransaction.cs
+++ b/FreeSql/Internal/CommonProvider/AdoProvider/AdoProviderTransaction.cs
@@ -1,4 +1,4 @@
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
diff --git a/FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs b/FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs
index d3be116e..e667b19f 100644
--- a/FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs
+++ b/FreeSql/Internal/CommonProvider/AdoProvider/DbConnectionPool.cs
@@ -1,4 +1,4 @@
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections.Generic;
using System.Data;
diff --git a/FreeSql/Internal/CommonProvider/InsertProvider.cs b/FreeSql/Internal/CommonProvider/InsertProvider.cs
index 3a15daab..d673a2af 100644
--- a/FreeSql/Internal/CommonProvider/InsertProvider.cs
+++ b/FreeSql/Internal/CommonProvider/InsertProvider.cs
@@ -1,6 +1,6 @@
using FreeSql.Internal.Model;
using FreeSql.Extensions.EntityUtil;
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections.Generic;
using System.Data;
diff --git a/FreeSql/Internal/CommonProvider/InsertProviderAsync.cs b/FreeSql/Internal/CommonProvider/InsertProviderAsync.cs
index 0f6d77d1..ddd24bf9 100644
--- a/FreeSql/Internal/CommonProvider/InsertProviderAsync.cs
+++ b/FreeSql/Internal/CommonProvider/InsertProviderAsync.cs
@@ -1,5 +1,5 @@
using FreeSql.Internal.Model;
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections.Generic;
using System.Data;
diff --git a/FreeSql/Internal/CommonUtils.cs b/FreeSql/Internal/CommonUtils.cs
index cbab8e0a..14a5e3a6 100644
--- a/FreeSql/Internal/CommonUtils.cs
+++ b/FreeSql/Internal/CommonUtils.cs
@@ -2,7 +2,7 @@
using FreeSql.DatabaseModel;
using FreeSql.Extensions.EntityUtil;
using FreeSql.Internal.Model;
-using SafeObjectPool;
+using FreeSql.Internal.ObjectPool;
using System;
using System.Collections;
using System.Collections.Concurrent;
diff --git a/FreeSql/Internal/ObjectPool/DefaultPolicy.cs b/FreeSql/Internal/ObjectPool/DefaultPolicy.cs
new file mode 100644
index 00000000..5541c579
--- /dev/null
+++ b/FreeSql/Internal/ObjectPool/DefaultPolicy.cs
@@ -0,0 +1,74 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace FreeSql.Internal.ObjectPool
+{
+
+ public class DefaultPolicy : IPolicy
+ {
+
+ public string Name { get; set; } = typeof(DefaultPolicy).GetType().FullName;
+ public int PoolSize { get; set; } = 1000;
+ public TimeSpan SyncGetTimeout { get; set; } = TimeSpan.FromSeconds(10);
+ public TimeSpan IdleTimeout { get; set; } = TimeSpan.FromSeconds(50);
+ public int AsyncGetCapacity { get; set; } = 10000;
+ public bool IsThrowGetTimeoutException { get; set; } = true;
+ public int CheckAvailableInterval { get; set; } = 5;
+
+ public Func CreateObject;
+ public Action