|
4 | 4 |
|
5 | 5 | using System;
|
6 | 6 | using System.ComponentModel;
|
7 |
| -using System.Data; |
8 | 7 | using System.Data.Common;
|
9 |
| -using System.Diagnostics; |
10 | 8 | using Microsoft.Data.Common;
|
11 | 9 |
|
12 | 10 | namespace Microsoft.Data.SqlClient
|
13 | 11 | {
|
14 | 12 | /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/SqlTransaction/*' />
|
15 |
| - public sealed class SqlTransaction : DbTransaction |
| 13 | + public sealed partial class SqlTransaction : DbTransaction |
16 | 14 | {
|
17 |
| - private static readonly SqlDiagnosticListener s_diagnosticListener = new SqlDiagnosticListener(SqlClientDiagnosticListenerExtensions.DiagnosticListenerName); |
18 |
| - private static int _objectTypeCount; // EventSource Counter |
19 |
| - internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); |
20 |
| - internal readonly IsolationLevel _isolationLevel = IsolationLevel.ReadCommitted; |
21 |
| - |
22 |
| - private SqlInternalTransaction _internalTransaction; |
23 |
| - private SqlConnection _connection; |
24 |
| - |
25 |
| - private bool _isFromAPI; |
26 |
| - |
27 |
| - internal SqlTransaction(SqlInternalConnection internalConnection, SqlConnection con, |
28 |
| - IsolationLevel iso, SqlInternalTransaction internalTransaction) |
29 |
| - { |
30 |
| - _isolationLevel = iso; |
31 |
| - _connection = con; |
32 |
| - |
33 |
| - if (internalTransaction == null) |
34 |
| - { |
35 |
| - _internalTransaction = new SqlInternalTransaction(internalConnection, TransactionType.LocalFromAPI, this); |
36 |
| - } |
37 |
| - else |
38 |
| - { |
39 |
| - Debug.Assert(internalConnection.CurrentTransaction == internalTransaction, "Unexpected Parser.CurrentTransaction state!"); |
40 |
| - _internalTransaction = internalTransaction; |
41 |
| - _internalTransaction.InitParent(this); |
42 |
| - } |
43 |
| - } |
44 |
| - |
45 |
| - //////////////////////////////////////////////////////////////////////////////////////// |
46 |
| - // PROPERTIES |
47 |
| - //////////////////////////////////////////////////////////////////////////////////////// |
48 |
| - |
49 |
| - /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Connection/*' /> |
50 |
| - new public SqlConnection Connection |
51 |
| - { |
52 |
| - get |
53 |
| - { |
54 |
| - if (IsZombied) |
55 |
| - { |
56 |
| - return null; |
57 |
| - } |
58 |
| - else |
59 |
| - { |
60 |
| - return _connection; |
61 |
| - } |
62 |
| - } |
63 |
| - } |
64 |
| - |
65 |
| - /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/DbConnection/*' /> |
66 |
| - override protected DbConnection DbConnection |
67 |
| - { |
68 |
| - get |
69 |
| - { |
70 |
| - return Connection; |
71 |
| - } |
72 |
| - } |
73 |
| - |
74 |
| - internal SqlInternalTransaction InternalTransaction |
75 |
| - { |
76 |
| - get |
77 |
| - { |
78 |
| - return _internalTransaction; |
79 |
| - } |
80 |
| - } |
81 |
| - |
82 |
| - /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/IsolationLevel/*' /> |
83 |
| - override public IsolationLevel IsolationLevel |
84 |
| - { |
85 |
| - get |
86 |
| - { |
87 |
| - ZombieCheck(); |
88 |
| - return _isolationLevel; |
89 |
| - } |
90 |
| - } |
91 |
| - |
92 |
| - private bool Is2005PartialZombie |
93 |
| - { |
94 |
| - get |
95 |
| - { |
96 |
| - return (null != _internalTransaction && _internalTransaction.IsCompleted); |
97 |
| - } |
98 |
| - } |
99 |
| - |
100 |
| - internal bool IsZombied |
101 |
| - { |
102 |
| - get |
103 |
| - { |
104 |
| - return (null == _internalTransaction || _internalTransaction.IsCompleted); |
105 |
| - } |
106 |
| - } |
107 |
| - |
108 |
| - internal int ObjectID |
109 |
| - { |
110 |
| - get |
111 |
| - { |
112 |
| - return _objectID; |
113 |
| - } |
114 |
| - } |
115 |
| - |
116 |
| - internal SqlStatistics Statistics |
117 |
| - { |
118 |
| - get |
119 |
| - { |
120 |
| - if (null != _connection) |
121 |
| - { |
122 |
| - if (_connection.StatisticsEnabled) |
123 |
| - { |
124 |
| - return _connection.Statistics; |
125 |
| - } |
126 |
| - } |
127 |
| - return null; |
128 |
| - } |
129 |
| - } |
| 15 | + private static readonly SqlDiagnosticListener s_diagnosticListener = new(SqlClientDiagnosticListenerExtensions.DiagnosticListenerName); |
130 | 16 |
|
131 | 17 | ////////////////////////////////////////////////////////////////////////////////////////
|
132 | 18 | // PUBLIC METHODS
|
133 | 19 | ////////////////////////////////////////////////////////////////////////////////////////
|
134 | 20 |
|
135 | 21 | /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Commit/*' />
|
136 |
| - override public void Commit() |
| 22 | + public override void Commit() |
137 | 23 | {
|
138 | 24 | using (DiagnosticTransactionScope diagnosticScope = s_diagnosticListener.CreateTransactionCommitScope(_isolationLevel, _connection, InternalTransaction))
|
139 | 25 | {
|
@@ -191,7 +77,7 @@ protected override void Dispose(bool disposing)
|
191 | 77 | }
|
192 | 78 |
|
193 | 79 | /// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Rollback2/*' />
|
194 |
| - override public void Rollback() |
| 80 | + public override void Rollback() |
195 | 81 | {
|
196 | 82 | using (DiagnosticTransactionScope diagnosticScope = s_diagnosticListener.CreateTransactionRollbackScope(_isolationLevel, _connection, InternalTransaction, null))
|
197 | 83 | {
|
@@ -284,45 +170,5 @@ public void Save(string savePointName)
|
284 | 170 | }
|
285 | 171 | }
|
286 | 172 | }
|
287 |
| - |
288 |
| - //////////////////////////////////////////////////////////////////////////////////////// |
289 |
| - // INTERNAL METHODS |
290 |
| - //////////////////////////////////////////////////////////////////////////////////////// |
291 |
| - |
292 |
| - internal void Zombie() |
293 |
| - { |
294 |
| - // For 2005, we have to defer "zombification" until |
295 |
| - // we get past the users' next rollback, else we'll |
296 |
| - // throw an exception there that is a breaking change. |
297 |
| - // Of course, if the connection is already closed, |
298 |
| - // then we're free to zombify... |
299 |
| - SqlInternalConnection internalConnection = (_connection.InnerConnection as SqlInternalConnection); |
300 |
| - if (null != internalConnection && !_isFromAPI) |
301 |
| - { |
302 |
| - SqlClientEventSource.Log.TryAdvancedTraceEvent("SqlTransaction.Zombie | ADV | Object Id {0} 2005 deferred zombie", ObjectID); |
303 |
| - } |
304 |
| - else |
305 |
| - { |
306 |
| - _internalTransaction = null; // pre-2005 zombification |
307 |
| - } |
308 |
| - } |
309 |
| - |
310 |
| - //////////////////////////////////////////////////////////////////////////////////////// |
311 |
| - // PRIVATE METHODS |
312 |
| - //////////////////////////////////////////////////////////////////////////////////////// |
313 |
| - |
314 |
| - private void ZombieCheck() |
315 |
| - { |
316 |
| - // If this transaction has been completed, throw exception since it is unusable. |
317 |
| - if (IsZombied) |
318 |
| - { |
319 |
| - if (Is2005PartialZombie) |
320 |
| - { |
321 |
| - _internalTransaction = null; // 2005 zombification |
322 |
| - } |
323 |
| - |
324 |
| - throw ADP.TransactionZombied(this); |
325 |
| - } |
326 |
| - } |
327 | 173 | }
|
328 | 174 | }
|
0 commit comments