/// <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); }
/// <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> /// 重置资源,以便下个事务使用 /// </summary> public void Reset() { taskSource = null; doScopeList.Clear(); objList.Clear(); bulkList.Clear(); bulkTablies.Clear(); exception = null; ExternalSucessed = true; CommandInfo.Reset(); dbSecodeScope = null; IsImmediately = true; }