Ejemplo n.º 1
0
        public static void DataBaseSharding(this IDataBaseSharding dataBaseSharding, int id = MatchedID.All, string tableIndex = null)
        {
            if (dataBaseSharding == null)
            {
                return;
            }
            var shardingValues            = dataBaseSharding.GetShardingColumnValues();
            var fatabaseShardingAttribute = dataBaseSharding.GetDataBaseShardingAttribute(id);

            if (fatabaseShardingAttribute == null)
            {
                return;
            }
            var       algorithm     = fatabaseShardingAttribute.ShardingAlgorithm;
            var       shardingTotal = fatabaseShardingAttribute.ShardingMaxCount;
            ISharding sharding      = Activator.CreateInstance(Type.GetType(algorithm)) as ISharding;

            dataBaseSharding.__DataBaseIndex__ = sharding.SharingByObject(shardingValues, shardingTotal);
        }
Ejemplo n.º 2
0
        public static void TableSharding(this ITableSharding tableSharding, int id = MatchedID.All, string tableIndex = null)
        {
            if (tableSharding == null)
            {
                return;
            }
            var shardingValues         = tableSharding.GetShardingColumnValues();
            var tableShardingAttribute = tableSharding.GetTableShardingAttribute(id);

            if (tableShardingAttribute == null)
            {
                return;
            }
            var       algorithm          = tableShardingAttribute.ShardingAlgorithm;
            var       shardingTotal      = tableShardingAttribute.ShardingTotalCount;
            ISharding sharding           = Activator.CreateInstance(Type.GetType(algorithm)) as ISharding;
            var       tableIndexSharding = sharding.SharingByObject(shardingValues, shardingTotal);

            if (!string.IsNullOrEmpty(tableIndexSharding))
            {
                tableSharding.__TableIndex__ = tableIndexSharding;
            }
        }