移除掉特性分片配置

This commit is contained in:
xuejiaming 2022-07-02 09:11:53 +08:00
parent 5fb2852db4
commit 7f4827b278
12 changed files with 0 additions and 314 deletions

View File

@ -70,7 +70,6 @@ namespace ShardingCore.Bootstrappers
{
var creatEntityMetadataDataSourceBuilder = EntityMetadataDataSourceBuilder<TEntity>.CreateEntityMetadataDataSourceBuilder(entityMetadata);
//配置属性分库信息
EntityMetadataHelper.Configure(creatEntityMetadataDataSourceBuilder);
var dataSourceRoute = CreateVirtualDataSourceRoute(virtualDataSourceRouteType);
if (dataSourceRoute is IEntityMetadataAutoBindInitializer entityMetadataAutoBindInitializer)
{
@ -89,7 +88,6 @@ namespace ShardingCore.Bootstrappers
{
var entityMetadataTableBuilder = EntityMetadataTableBuilder<TEntity>.CreateEntityMetadataTableBuilder(entityMetadata);
//配置属性分表信息
EntityMetadataHelper.Configure(entityMetadataTableBuilder);
var virtualTableRoute = CreateVirtualTableRoute(virtualTableRouteType);
if (virtualTableRoute is IEntityMetadataAutoBindInitializer entityMetadataAutoBindInitializer)

View File

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ShardingCore.Core
{
/*
* @Author: xjm
* @Description:
* @Ver: 1.0
* @Email: 326308290@qq.com
*/
[Obsolete("will remove")]
public interface IShardingDataSource
{
}
}

View File

@ -1,8 +0,0 @@
namespace ShardingCore.Core
{
public interface IShardingEntityType
{
string GetLogicTableName();
bool IsSingleKey { get; }
}
}

View File

@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ShardingCore.Core
{
/*
* @Author: xjm
* @Description:
* @Date: 2021/9/17 13:21:04
* @Ver: 1.0
* @Email: 326308290@qq.com
*/
[Obsolete("will remove")]
public interface IShardingTable
{
}
}

View File

@ -1,18 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace ShardingCore.Core
{
/*
* @Author: xjm
* @Description:
* @Date: 2021/8/21 13:04:38
* @Ver: 1.0
* @Email: 326308290@qq.com
*/
public class ShardingConstant
{
public const string MULTI_ENTITIES_QUERY = "MULTI_ENTITIES_QUERY";
}
}

View File

@ -1,69 +0,0 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace ShardingCore.Core
{
internal class ShardingCreatorHelper
{
private static ConcurrentDictionary<Type, Func<object[], object>> _creator;
private ShardingCreatorHelper() { }
static ShardingCreatorHelper()
{
_creator = new ConcurrentDictionary<Type, Func<object[], object>>();
}
public static object CreateInstance(Type targetType,params object[] args)
{
var creator = _creator.GetOrAdd(targetType,key=> GetActivator(key));
return creator(args);
}
private static Func<object[],object> GetActivator(Type targetType)
{
ConstructorInfo ctor = targetType.GetConstructors().First();
Type type = ctor.DeclaringType;
ParameterInfo[] paramsInfo = ctor.GetParameters();
//create a single param of type object[]
ParameterExpression param =
Expression.Parameter(typeof(object[]), "args");
Expression[] argsExp =
new Expression[paramsInfo.Length];
//pick each arg from the params array
//and create a typed expression of them
for (int i = 0; i < paramsInfo.Length; i++)
{
Expression index = Expression.Constant(i);
Type paramType = paramsInfo[i].ParameterType;
Expression paramAccessorExp =
Expression.ArrayIndex(param, index);
Expression paramCastExp =
Expression.Convert(paramAccessorExp, paramType);
argsExp[i] = paramCastExp;
}
//make a NewExpression that calls the
//ctor with the args we just created
NewExpression newExp = Expression.New(ctor, argsExp);
//create a lambda with the New
//Expression as body and our param object[] as arg
//compile it
var compiled =
Expression.Lambda<Func<object[],object>>(newExp, param).Compile();
return compiled;
}
}
}

View File

@ -1,22 +0,0 @@
using System;
namespace ShardingCore.Core
{
/*
* @Author: xjm
* @Description:
* @Date: Friday, 05 February 2021 12:53:46
* @Email: 326308290@qq.com
*/
/// <summary>
/// 数据源分库规则字段
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class ShardingDataSourceKeyAttribute: Attribute
{
/// <summary>
/// 是否需要在启动的时候创建表
/// </summary>
public ShardingKeyAutoCreateTableEnum AutoCreateDataSourceTableOnStart { get; set; } = ShardingKeyAutoCreateTableEnum.UnKnown;
}
}

View File

@ -1,18 +0,0 @@
using System;
namespace ShardingCore.Core
{
/*
* @Author: xjm
* @Description:
* @Date: Friday, 05 February 2021 12:53:46
* @Email: 326308290@qq.com
*/
/// <summary>
/// 数据源分库额外规则字段
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class ShardingExtraDataSourceKeyAttribute : Attribute
{
}
}

View File

@ -1,18 +0,0 @@
using System;
namespace ShardingCore.Core
{
/*
* @Author: xjm
* @Description:
* @Date: Wednesday, 16 December 2020 11:04:51
* @Email: 326308290@qq.com
*/
/// <summary>
/// 分片额外配置
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class ShardingExtraTableKeyAttribute : Attribute
{
}
}

View File

@ -1,8 +0,0 @@
// namespace ShardingCore.Core
// {
//
// public class ShardingRuntimeOptions
// {
//
// }
// }

View File

@ -1,34 +0,0 @@
using System;
namespace ShardingCore.Core
{
/*
* @Author: xjm
* @Description:
* @Date: Wednesday, 16 December 2020 11:04:51
* @Email: 326308290@qq.com
*/
/// <summary>
/// AbstractVirtualTableRoute 最基础分表规则 需要自己解析如何分表
/// 仅ShardingMode为Custom:以下接口提供自定义分表
/// AbstractShardingKeyObjectEqualVirtualRoute 自定义分表
/// SimpleShardingKeyStringModVirtualRoute 默认对AbstractShardingKeyObjectEqualVirtualRoute的实现,字符串按取模分表
/// 仅ShardingMode非Custom以下接口提供自动按时间分表
/// SimpleShardingDateByDayVirtualRoute 分表
/// </summary>
[AttributeUsage(AttributeTargets.Property, AllowMultiple = true)]
public class ShardingTableKeyAttribute : Attribute
{
public const string DEFAULT_TABLE_SEPARATOR = "_";
/// <summary>
/// 是否需要在启动的时候创建表
/// </summary>
public ShardingKeyAutoCreateTableEnum AutoCreateTableOnStart { get; set; } = ShardingKeyAutoCreateTableEnum.UnKnown;
/// <summary>
/// 分表尾巴前缀
/// </summary>
public string TableSeparator { get; set; } = DEFAULT_TABLE_SEPARATOR;
}
}

View File

@ -1,82 +0,0 @@
using System;
using System.Linq;
using System.Reflection;
using ShardingCore.Core;
using ShardingCore.Core.EntityMetadatas;
namespace ShardingCore.Helpers
{
public class EntityMetadataHelper
{
private EntityMetadataHelper()
{
}
public static void Configure<TEntity>(EntityMetadataTableBuilder<TEntity> builder) where TEntity : class
{
var entityType = typeof(TEntity);
PropertyInfo[] shardingProperties = entityType.GetProperties();
var shardingTableCount = 0;
foreach (var shardingProperty in shardingProperties)
{
var attributes = shardingProperty.GetCustomAttributes(true);
if (attributes.FirstOrDefault(x => x.GetType() == typeof(ShardingTableKeyAttribute)) is ShardingTableKeyAttribute shardingKey)
{
if (shardingTableCount > 1)
throw new NotSupportedException($"{entityType} should use single attribute [{nameof(ShardingTableKeyAttribute)}]");
builder.ShardingProperty(shardingProperty.Name);
var autoCreateTable =
shardingKey.AutoCreateTableOnStart == ShardingKeyAutoCreateTableEnum.UnKnown
? (bool?)null
: (shardingKey.AutoCreateTableOnStart == ShardingKeyAutoCreateTableEnum.Create);
builder.AutoCreateTable(autoCreateTable);
builder.TableSeparator(shardingKey.TableSeparator);
shardingTableCount++;
}
if (attributes.FirstOrDefault(x => x.GetType() == typeof(ShardingExtraTableKeyAttribute)) is
ShardingExtraTableKeyAttribute shardingExtraKey)
{
builder.ShardingExtraProperty(shardingProperty.Name);
}
}
}
public static void Configure<TEntity>(EntityMetadataDataSourceBuilder<TEntity> builder) where TEntity : class
{
var entityType = typeof(TEntity);
PropertyInfo[] shardingProperties = entityType.GetProperties();
var shardingDataSourceCount = 0;
foreach (var shardingProperty in shardingProperties)
{
var attributes = shardingProperty.GetCustomAttributes(true);
if (attributes.FirstOrDefault(x => x.GetType() == typeof(ShardingDataSourceKeyAttribute)) is ShardingDataSourceKeyAttribute shardingDataSourceKey)
{
if (shardingDataSourceCount > 1)
throw new NotSupportedException($"{entityType} should use single attribute [{nameof(ShardingDataSourceKeyAttribute)}]");
builder.ShardingProperty(shardingProperty.Name);
var autoCreateDataSource = shardingDataSourceKey.AutoCreateDataSourceTableOnStart ==
ShardingKeyAutoCreateTableEnum.UnKnown
? (bool?)null
: (shardingDataSourceKey.AutoCreateDataSourceTableOnStart ==
ShardingKeyAutoCreateTableEnum.Create);
builder.AutoCreateDataSource(autoCreateDataSource);
shardingDataSourceCount++;
}
if (attributes.FirstOrDefault(x => x.GetType() == typeof(ShardingExtraDataSourceKeyAttribute)) is
ShardingExtraDataSourceKeyAttribute shardingExtraKey)
{
builder.ShardingExtraProperty(shardingProperty.Name);
}
}
}
}
}