// トランザクションの開始 (UsingTran オブジェクト作成) public UsingTran UsingTran(IsolationLevel iso = IsolationLevel.Unspecified) { UsingTran t = new UsingTran(this); Begin(iso); return(t); }
public async Task TranAsync(IsolationLevel iso, DeadlockRetryConfig retry_config, TransactionalTaskAsync task) { await EnsureOpenAsync(); if (retry_config == null) { retry_config = this.DeadlockRetryConfig; } int num_retry = 0; LABEL_RETRY: try { using (UsingTran u = this.UsingTran(iso)) { if (await task()) { u.Commit(); } } } catch (SqlException sqlex) { if (sqlex.Number == 1205) { // デッドロック発生 num_retry++; if (num_retry <= retry_config.RetryCount) { await Task.Delay(Secure.Rand31i() % retry_config.RetryAverageInterval); goto LABEL_RETRY; } throw; } else { throw; } } }
public void Tran(IsolationLevel iso, DeadlockRetryConfig retry_config, TransactionalTask task) { EnsureOpen(); if (retry_config == null) { retry_config = this.DeadlockRetryConfig; } int num_retry = 0; LABEL_RETRY: try { using (UsingTran u = this.UsingTran(iso)) { if (task()) { u.Commit(); } } } catch (SqlException sqlex) { if (sqlex.Number == 1205) { // デッドロック発生 num_retry++; if (num_retry <= retry_config.RetryCount) { Kernel.SleepThread(Secure.Rand31i() % retry_config.RetryAverageInterval); goto LABEL_RETRY; } throw; } else { throw; } } }