-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoTransaction.cs
More file actions
34 lines (26 loc) · 876 Bytes
/
AutoTransaction.cs
File metadata and controls
34 lines (26 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using System.Data.Common;
using System.Transactions;
namespace StilettoSQL.Query;
public sealed class AutoTransaction : IDisposable {
internal DbConnection? Connection;
internal DbTransaction? transact;
internal int commandsCount = 0;
public AutoTransaction() {
if (StProfile.CurrentTransaction_.Value != null) {
throw new Exception("recursive transactions not supported");
}
// регистрируем себя.
StProfile.CurrentTransaction_.Value = this;
}
async public Task CommitAsync() {
if (transact == null) {
throw new Exception("no connetions during transaction");
}
await transact.CommitAsync();
}
public void Dispose() {
transact?.Dispose();
Connection?.Dispose();
StProfile.CurrentTransaction_.Value = null;
}
}