/// <summary> /// 事务一次提交 /// timeOut【指定操作的调用的外部服务或者方法执行的超时时间】:分布式事务提交,二次提交依赖外部条件,二次提交时一定要注意外部事务提交或者应用执行的时间 /// 如果外部事务执行时间过长,会导致本事务的连接线程占用过长,会出现数据库连接泄露的情况出现(尤其是在分布式事务中,一定需要调整好外部服务的调用时间)。 /// timeOut默认情况下可以不用设置,建议根据业务实际情况设置此值. /// </summary> public dbscope FirstSubmit(out bool noneError, out string errorMessage, int?timeOut = null) { dbscope db = new dbscope(); noneError = true; IsImmediately = false; errorMessage = string.Empty; dbSecodeScope = new DistributedTransaction(_targetdb); dbSecodeScope.DistributedEventException += (sender) => { isNoneException = false; exception = (Exception)sender; CommonDealException(); }; dbSecodeScope.SetListQuery = doScopeList; //处理bulkList dbSecodeScope.BulkTablies = this.bulkTablies; dbSecodeScope.SetbulkList = this.bulkList; CommandInfo = dbSecodeScope.ComamInfo; noneError = dbSecodeScope.BeginTransaction(); if (!noneError) { errorMessage = exception.Message; } if (timeOut.HasValue) { taskSource = new TaskCompletionSource <bool>(); RegisetiOverTime(taskSource, timeOut.Value); } return(this); }
/// <summary> /// 事务一次提交 /// timeOut【指定操作的调用的外部服务或者方法执行的超时时间】:分布式事务提交,二次提交依赖外部条件,二次提交时一定要注意外部事务提交或者应用执行的时间 /// 如果外部事务执行时间过长,会导致本事务的连接线程占用过长,会出现数据库连接泄露的情况出现(尤其是在分布式事务中,一定需要调整好外部服务的调用时间)。 /// timeOut默认情况下可以不用设置,建议根据业务实际情况设置此值. /// </summary> public dbscope FirstSubmit(int?timeOut = null) { IsImmediately = false; dbSecodeScope = new DistributedTransaction(); dbSecodeScope.DistributedEventException += (sender) => { isNoneException = false; exception = (Exception)sender; CommonDealException(); }; dbSecodeScope.SetListQuery = doScopeList; //处理bulkList dbSecodeScope.BulkTablies = this.bulkTablies; dbSecodeScope.SetbulkList = this.bulkList; CommandInfo = dbSecodeScope.ComamInfo; dbSecodeScope.BeginTransaction(); if (timeOut.HasValue) { taskSource = new TaskCompletionSource <bool>(); RegisetiOverTime(taskSource, timeOut.Value); } return(this); }
internal static bool GetSubmit(List <BaseQuery> list, ScopeCommandInfo scopecommandInfo, out Exception Ex, List <BulkCopyModel> bulkModels, List <DataTable> bulkTablies, string targetdb) { bool bl = true; Ex = null; if ((list == null || list.Count == 0) && (bulkModels == null || bulkModels.Count == 0)) { bl = true; } else { try { var pty = dc.conn(targetdb); var index = 0; list.ForEach(p => { if (p.excutParBag == null) { string error = "错误:core-excutParBag为null.事务语句索引:请检查业务执行语句." + index.ToSafeString(); LogService.Default.Fatal(error); throw new Exception(error); } p.Convert(targetdb); index++; }); if (bulkModels != null && bulkModels.Count > 0) { bulkTablies = bulkModels.ConvertBulkTable(targetdb); } if (scopecommandInfo == null) { scopecommandInfo = default(ScopeCommandInfo); } BaseQuery q = null; if (list != null && list.Count > 0) { q = list.ConvertOneQuery(); scopecommandInfo.Parameters = q.Parameters; scopecommandInfo.SqlCommand = q.CommandText; } List <BaseQuery> ql = null; if (q != null) { ql = new List <BaseQuery>() { q }; } bl = ModelOpretion.ExecuteBacheNonQuery(ql, out Ex, bulkTablies, targetdb); } catch (Exception ex) { bl = false; Ex = ex; LogService.Default.Fatal("处理事务语句时出现异常:" + ex.Message); } } return(bl); }
internal static bool Submit(this List <BaseQuery> list, ScopeCommandInfo scopecommandInfo, out Exception Ex, List <BulkCopyModel> bulkModels, List <DataTable> bulkTablies, string targetdb) { Ex = null; return(GetSubmit(list, scopecommandInfo, out Ex, bulkModels, bulkTablies, targetdb)); }