예제 #1
0
        public static List <int> ExecuteShardingNonQuery(IList <Statement> statements)
        {
            if (statements == null || statements.Count == 0)
            {
                return(null);
            }

            var funcs = new List <Func <Int32> >();

            for (Int32 i = 0; i < statements.Count; i++)
            {
                Statement statement = statements[i];
                funcs.Add(() =>
                {
                    try
                    {
                        LogManager.Logger.StartTracing();
                        return(DatabaseBridge.Instance.ExecuteNonQuery(statement));
                    }
                    finally
                    {
                        LogManager.Logger.StopTracing();
                    }
                });
            }

            return(ExecuteParallelHelper.ParallelExcuter(funcs, CheckSameShard(statements)));
        }
예제 #2
0
        /// <summary>
        /// 表结构均相同, 只有一个数据库,将一个表分为多个名称不同的表
        /// </summary>
        /// <param name="statements"></param>
        /// <returns></returns>
        public static DataTable ExecuteShardTable(IList <Statement> statements)
        {
            if (statements == null || statements.Count == 0)
            {
                return(null);
            }

            var excuter = new List <Func <IDataReader> >();

            for (Int32 i = 0; i < statements.Count; i++)
            {
                Statement statement = statements[i];
                excuter.Add(() =>
                {
                    try
                    {
                        LogManager.Logger.StartTracing();
                        return(DatabaseBridge.Instance.ExecuteReader(statement));
                    }
                    finally
                    {
                        LogManager.Logger.StopTracing();
                    }
                });
            }

            var result = ExecuteParallelHelper.ParallelExcuter(excuter, CheckSameShard(statements));

            return(MergeDataReader(result));
        }
예제 #3
0
        private static IList <T> MergeListOfSingleField <T>(IList <IDataReader> dataReaders, Boolean isSameShard)
        {
            if (dataReaders == null || dataReaders.Count == 0)
            {
                return(null);
            }

            var result = new List <T>();
            var funcs  = new List <Func <IList <T> > >();

            for (Int32 i = 0; i < dataReaders.Count; i++)
            {
                var dataReader = dataReaders[i];
                funcs.Add(() =>
                {
                    try
                    {
                        LogManager.Logger.StartTracing();
                        var list = new List <T>();
                        using (dataReader)
                        {
                            OrmUtil.FillBySingleFied(dataReader, list);
                        }
                        return(list);
                    }
                    finally
                    {
                        LogManager.Logger.StopTracing();
                    }
                });
            }

            var temp = ExecuteParallelHelper.ParallelExcuter(funcs, isSameShard);

            if (temp.Count > 0)
            {
                foreach (var item in temp)
                {
                    result.AddRange(item);
                }
            }

            return(result);
        }
예제 #4
0
        private static IList <T> MergeFirst <T>(IList <IDataReader> dataReaders, SqlTable sqlTable, Boolean isSameShard)
        {
            if (dataReaders == null || dataReaders.Count == 0)
            {
                return(null);
            }

            if (sqlTable == null || sqlTable.ColumnList == null || sqlTable.ColumnList.Count == 0)
            {
                return(null);
            }

            var funcs = new List <Func <T> >();

            for (Int32 i = 0; i < dataReaders.Count; i++)
            {
                var dataReader = dataReaders[i];
                funcs.Add(() =>
                {
                    try
                    {
                        LogManager.Logger.StartTracing();
                        T item = default(T);
                        using (dataReader)
                        {
                            OrmUtil.FillFirstByName(dataReader, sqlTable.ColumnList, ref item);
                        }
                        return(item);
                    }
                    finally
                    {
                        LogManager.Logger.StopTracing();
                    }
                });
            }

            var result = ExecuteParallelHelper.ParallelExcuter(funcs, isSameShard);

            return(result);
        }
예제 #5
0
        public static IList <IDataReader> GetShardingDataReaderList(IList <Statement> statements)
        {
            var dataReaders = new List <Func <IDataReader> >();

            for (Int32 i = 0; i < statements.Count; i++)
            {
                Statement statement = statements[i];
                dataReaders.Add(() =>
                {
                    try
                    {
                        LogManager.Logger.StartTracing();
                        return(DatabaseBridge.Instance.ExecuteReader(statement));
                    }
                    finally
                    {
                        LogManager.Logger.StopTracing();
                    }
                });
            }

            return(ExecuteParallelHelper.ParallelExcuter(dataReaders, CheckSameShard(statements)));
        }