예제 #1
0
        // トランザクションの開始 (UsingTran オブジェクト作成)
        public async Task <UsingTran> UsingTranAsync(IsolationLevel?isolationLevel = null)
        {
            UsingTran t = new UsingTran(this);

            await BeginAsync(isolationLevel);

            return(t);
        }
예제 #2
0
        // トランザクションの開始 (UsingTran オブジェクト作成)
        public UsingTran UsingTran(IsolationLevel?isolationLevel = null)
        {
            UsingTran t = new UsingTran(this);

            Begin(isolationLevel);

            return(t);
        }
예제 #3
0
        public async Task TranAsync(IsolationLevel?isolationLevel, DeadlockRetryConfig?retryConfig, TransactionalTaskAsync task)
        {
            await EnsureOpenAsync();

            if (retryConfig == null)
            {
                retryConfig = this.DeadlockRetryConfig;
            }

            int numRetry = 0;

LABEL_RETRY:
            try
            {
                using (UsingTran u = this.UsingTran(isolationLevel))
                {
                    if (await task())
                    {
                        u.Commit();
                    }
                }
            }
            catch (SqlException sqlex)
            {
                //sqlex._Debug();
                if (sqlex.Number == 1205)
                {
                    // デッドロック発生
                    numRetry++;
                    if (numRetry <= retryConfig.RetryCount)
                    {
                        await Task.Delay(Util.RandSInt31() % retryConfig.RetryAverageInterval);

                        goto LABEL_RETRY;
                    }

                    throw;
                }
                else
                {
                    throw;
                }
            }
        }
예제 #4
0
        public void Tran(IsolationLevel?isolationLevel, DeadlockRetryConfig?retryConfig, TransactionalTask task)
        {
            EnsureOpen();
            if (retryConfig == null)
            {
                retryConfig = this.DeadlockRetryConfig;
            }

            int numRetry = 0;

LABEL_RETRY:
            try
            {
                using (UsingTran u = this.UsingTran(isolationLevel))
                {
                    if (task())
                    {
                        u.Commit();
                    }
                }
            }
            catch (SqlException sqlex)
            {
                if (sqlex.Number == 1205)
                {
                    // デッドロック発生
                    numRetry++;
                    if (numRetry <= retryConfig.RetryCount)
                    {
                        Kernel.SleepThread(Util.RandSInt31() % retryConfig.RetryAverageInterval);

                        goto LABEL_RETRY;
                    }

                    throw;
                }
                else
                {
                    throw;
                }
            }
        }