添加部分备注信息
This commit is contained in:
parent
1e715ffa2e
commit
64dc7d90e9
|
@ -21,6 +21,8 @@ namespace Sample.AutoCreateIfPresent
|
|||
|
||||
private readonly ConcurrentDictionary<string, object?> _tails =
|
||||
new ConcurrentDictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
|
||||
// private readonly ConcurrentDictionary<string, ConcurrentDictionary<string, object?>> _tails =
|
||||
// new ConcurrentDictionary<string, ConcurrentDictionary<string, object?>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
private readonly object _lock = new object();
|
||||
private readonly object _initLock = new object();
|
||||
|
|
|
@ -1,12 +1,22 @@
|
|||
using Sample.MySql.DbContexts;
|
||||
using Sample.MySql.Domain.Entities;
|
||||
using ShardingCore.Core.EntityMetadatas;
|
||||
using ShardingCore.Core.RuntimeContexts;
|
||||
using ShardingCore.Core.ServiceProviders;
|
||||
using ShardingCore.Core.VirtualRoutes;
|
||||
using ShardingCore.Core.VirtualRoutes.DataSourceRoutes.Abstractions;
|
||||
using ShardingCore.Helpers;
|
||||
|
||||
namespace Sample.MySql.Shardings
|
||||
{
|
||||
public class SysUserLogByMonthDSRoute:AbstractShardingOperatorVirtualDataSourceRoute<SysUserLogByMonth,DateTime>
|
||||
{
|
||||
private readonly IShardingProvider _shardingProvider;
|
||||
|
||||
public SysUserLogByMonthDSRoute(IShardingProvider shardingProvider)
|
||||
{
|
||||
_shardingProvider = shardingProvider;
|
||||
}
|
||||
public override string ShardingKeyToDataSourceName(object shardingKey)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
@ -37,5 +47,13 @@ namespace Sample.MySql.Shardings
|
|||
//判断过滤查询历史还是现在
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// public override string RouteWithValue(object shardingKey)
|
||||
// {
|
||||
// //计算出数据源名
|
||||
// var dataSourceName = ShardingKeyToDataSourceName(shardingKey);
|
||||
// var shardingRuntimeContext = _shardingProvider.ApplicationServiceProvider.GetRequiredService<IShardingRuntimeContext<DefaultShardingDbContext>>();
|
||||
// DynamicShardingHelper.DynamicAppendDataSource(shardingRuntimeContext,dataSourceName,$"server=127.0.0.1;port=3306;database=db_{dataSourceName};userid=root;password=root;",true,true);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -139,7 +139,8 @@ namespace Sample.MySql
|
|||
{
|
||||
// var logger = sp.ApplicationServiceProvider.GetService<ILogger<Startup>>();
|
||||
// logger.LogInformation(conStr);
|
||||
builder.UseMySql(conStr, new MySqlServerVersion(new Version()));
|
||||
builder.UseMySql(conStr, new MySqlServerVersion(new Version()))
|
||||
.UseLoggerFactory(efLogger);
|
||||
// .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
||||
// .UseLoggerFactory(loggerFactory1)
|
||||
// .EnableSensitiveDataLogging();
|
||||
|
@ -148,7 +149,8 @@ namespace Sample.MySql
|
|||
o.UseShardingTransaction((connection, builder) =>
|
||||
{
|
||||
builder
|
||||
.UseMySql(connection, new MySqlServerVersion(new Version()));
|
||||
.UseMySql(connection, new MySqlServerVersion(new Version()))
|
||||
.UseLoggerFactory(efLogger);
|
||||
// .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
|
||||
// .UseLoggerFactory(loggerFactory1)
|
||||
// .EnableSensitiveDataLogging();
|
||||
|
@ -222,6 +224,7 @@ namespace Sample.MySql
|
|||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
// DynamicShardingHelper.DynamicAppendDataSource();
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
|
@ -236,6 +239,14 @@ namespace Sample.MySql
|
|||
// virtualTableRoute.Append("2021");
|
||||
}
|
||||
app.ApplicationServices.UseAutoTryCompensateTable();
|
||||
|
||||
|
||||
// var shardingRuntimeContext = app.ApplicationServices.GetRequiredService<IShardingRuntimeContext<DefaultShardingDbContext>>();
|
||||
// var virtualDataSource = shardingRuntimeContext.GetVirtualDataSource();
|
||||
// var connectionString = virtualDataSource.GetConnectionString("dataSourceName");
|
||||
// var defaultConnectionString1 = virtualDataSource.GetDefaultDataSource().ConnectionString;
|
||||
// var defaultConnectionString2 = virtualDataSource.GetPhysicDataSource("dataSourceName").ConnectionString;
|
||||
// shardingRuntimeContext.UseAutoTryCompensateTable();
|
||||
// var shardingRuntimeContext = app.ApplicationServices.GetRequiredService<IShardingRuntimeContext>();
|
||||
// var entityMetadataManager = shardingRuntimeContext.GetEntityMetadataManager();
|
||||
// var entityMetadata = entityMetadataManager.TryGet<SysUserMod>();
|
||||
|
|
|
@ -1,12 +1,21 @@
|
|||
namespace ShardingCore
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化配置执行单元
|
||||
/// </summary>
|
||||
public class InitConfigureUnit
|
||||
{
|
||||
/// <summary>
|
||||
/// 初始化配置执行单元
|
||||
/// </summary>
|
||||
public InitConfigureUnit(string dataSourceName)
|
||||
{
|
||||
DataSourceName = dataSourceName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据源
|
||||
/// </summary>
|
||||
public string DataSourceName { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,13 +4,9 @@ using ShardingCore.Sharding.Abstractions;
|
|||
|
||||
namespace ShardingCore.Sharding
|
||||
{
|
||||
/*
|
||||
* @Author: xjm
|
||||
* @Description:
|
||||
* @Date: 2021/9/7 10:32:26
|
||||
* @Ver: 1.0
|
||||
* @Email: 326308290@qq.com
|
||||
*/
|
||||
/// <summary>
|
||||
/// 默认的链接字符串管理器
|
||||
/// </summary>
|
||||
public class DefaultConnectionStringManager : IConnectionStringManager
|
||||
{
|
||||
private readonly IVirtualDataSource _virtualDataSource;
|
||||
|
@ -19,6 +15,11 @@ namespace ShardingCore.Sharding
|
|||
{
|
||||
_virtualDataSource = virtualDataSource;
|
||||
}
|
||||
/// <summary>
|
||||
/// 获取链接字符串根据数据源名称
|
||||
/// </summary>
|
||||
/// <param name="dataSourceName"></param>
|
||||
/// <returns></returns>
|
||||
public string GetConnectionString(string dataSourceName)
|
||||
{
|
||||
if (_virtualDataSource.IsDefault(dataSourceName))
|
||||
|
|
|
@ -35,12 +35,20 @@ namespace ShardingCore.Sharding
|
|||
_queryableRewriteEngine = queryableRewriteEngine;
|
||||
_queryableOptimizeEngine = queryableOptimizeEngine;
|
||||
}
|
||||
/// <summary>
|
||||
/// 创建流式合并上下文
|
||||
/// </summary>
|
||||
/// <param name="mergeQueryCompilerContext"></param>
|
||||
/// <returns></returns>
|
||||
public StreamMergeContext Create(IMergeQueryCompilerContext mergeQueryCompilerContext)
|
||||
{
|
||||
//表达式解析结果
|
||||
var parseResult = _queryableParseEngine.Parse(mergeQueryCompilerContext);
|
||||
|
||||
//表达式重写结果
|
||||
var rewriteResult = _queryableRewriteEngine.GetRewriteQueryable(mergeQueryCompilerContext, parseResult);
|
||||
//表达式优化结果
|
||||
var optimizeResult = _queryableOptimizeEngine.Optimize(mergeQueryCompilerContext, parseResult, rewriteResult);
|
||||
//合并上下文
|
||||
CheckMergeContext(mergeQueryCompilerContext, parseResult, rewriteResult, optimizeResult);
|
||||
return new StreamMergeContext(mergeQueryCompilerContext, parseResult, rewriteResult,optimizeResult);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue