7
7
using MySqlConnector . Protocol . Serialization ;
8
8
using MySqlConnector . Utilities ;
9
9
10
- #if NET45 || NET461 || NET471 || NETSTANDARD1_3 || NETSTANDARD2_0 || NETSTANDARD2_1 || NETCOREAPP2_1 || NETCOREAPP3_0
11
- namespace System . Data . Common
12
- {
13
- public abstract class DbBatch : IDisposable
14
- {
15
- public DbBatchCommandCollection BatchCommands => DbBatchCommands ;
16
- protected abstract DbBatchCommandCollection DbBatchCommands { get ; }
17
-
18
- #region Execution (mirrors DbCommand)
19
-
20
- public DbDataReader ExecuteReader ( ) => ExecuteDbDataReader ( ) ;
21
- protected abstract DbDataReader ExecuteDbDataReader ( ) ;
22
- public Task < DbDataReader > ExecuteReaderAsync ( CancellationToken cancellationToken = default ) => ExecuteDbDataReaderAsync ( cancellationToken ) ;
23
- protected abstract Task < DbDataReader > ExecuteDbDataReaderAsync ( CancellationToken cancellationToken ) ;
24
-
25
- public abstract int ExecuteNonQuery ( ) ;
26
- public abstract Task < int > ExecuteNonQueryAsync ( CancellationToken cancellationToken = default ) ;
27
-
28
- public abstract object ExecuteScalar ( ) ;
29
- public abstract Task < object > ExecuteScalarAsync ( CancellationToken cancellationToken = default ) ;
30
-
31
- #endregion
32
-
33
- #region Execution properties (mirrors DbCommand)
34
-
35
- public abstract int Timeout { get ; set ; }
36
-
37
- // Delegates to DbConnection
38
- public DbConnection Connection { get ; set ; }
39
- protected abstract DbConnection DbConnection { get ; set ; }
40
-
41
- // Delegates to DbTransaction
42
- public DbTransaction Transaction { get ; set ; }
43
- protected abstract DbTransaction DbTransaction { get ; set ; }
44
-
45
- #endregion
46
-
47
- #region Other methods mirroring DbCommand
48
-
49
- public abstract void Prepare ( ) ;
50
- public abstract Task PrepareAsync ( CancellationToken cancellationToken = default ) ;
51
- public abstract void Cancel ( ) ;
52
-
53
- #endregion
54
-
55
- #region Standard dispose pattern
56
-
57
- public void Dispose ( )
58
- {
59
- Dispose ( true ) ;
60
- GC . SuppressFinalize ( this ) ;
61
- }
62
-
63
- protected virtual void Dispose ( bool disposing ) { }
64
-
65
- #endregion
66
- }
67
- }
68
- #endif
69
-
70
10
namespace MySql . Data . MySqlClient
71
11
{
72
- public sealed class MySqlBatch : DbBatch , ICancellableCommand
12
+ public sealed class MySqlBatch : ICancellableCommand , IDisposable
73
13
{
74
14
public MySqlBatch ( )
75
15
: this ( null , null )
@@ -84,31 +24,20 @@ public MySqlBatch(MySqlConnection connection = null, MySqlTransaction transactio
84
24
m_commandId = ICancellableCommandExtensions . GetNextId ( ) ;
85
25
}
86
26
87
- public new MySqlConnection Connection { get ; set ; }
88
- public new MySqlTransaction Transaction { get ; set ; }
89
- public new MySqlBatchCommandCollection BatchCommands { get ; }
90
-
91
- protected override DbConnection DbConnection
92
- {
93
- get => Connection ;
94
- set => Connection = ( MySqlConnection ) value ;
95
- }
96
-
97
- protected override DbTransaction DbTransaction
98
- {
99
- get => Transaction ;
100
- set => Transaction = ( MySqlTransaction ) value ;
101
- }
27
+ public MySqlConnection Connection { get ; set ; }
28
+ public MySqlTransaction Transaction { get ; set ; }
29
+ public MySqlBatchCommandCollection BatchCommands { get ; }
102
30
103
- protected override DbBatchCommandCollection DbBatchCommands => BatchCommands ;
31
+ public DbDataReader ExecuteReader ( ) => ExecuteDbDataReader ( ) ;
32
+ public Task < DbDataReader > ExecuteReaderAsync ( CancellationToken cancellationToken = default ) => ExecuteDbDataReaderAsync ( cancellationToken ) ;
104
33
105
- protected override DbDataReader ExecuteDbDataReader ( )
34
+ private DbDataReader ExecuteDbDataReader ( )
106
35
{
107
36
( ( ICancellableCommand ) this ) . ResetCommandTimeout ( ) ;
108
37
return ExecuteReaderAsync ( IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
109
38
}
110
39
111
- protected override Task < DbDataReader > ExecuteDbDataReaderAsync ( CancellationToken cancellationToken )
40
+ private Task < DbDataReader > ExecuteDbDataReaderAsync ( CancellationToken cancellationToken )
112
41
{
113
42
( ( ICancellableCommand ) this ) . ResetCommandTimeout ( ) ;
114
43
return ExecuteReaderAsync ( AsyncIOBehavior , cancellationToken ) ;
@@ -128,17 +57,17 @@ private Task<DbDataReader> ExecuteReaderAsync(IOBehavior ioBehavior, Cancellatio
128
57
return CommandExecutor . ExecuteReaderAsync ( BatchCommands , payloadCreator , CommandBehavior . Default , ioBehavior , cancellationToken ) ;
129
58
}
130
59
131
- public override int ExecuteNonQuery ( ) => ExecuteNonQueryAsync ( IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
60
+ public int ExecuteNonQuery ( ) => ExecuteNonQueryAsync ( IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
132
61
133
- public override object ExecuteScalar ( ) => ExecuteScalarAsync ( IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
62
+ public object ExecuteScalar ( ) => ExecuteScalarAsync ( IOBehavior . Synchronous , CancellationToken . None ) . GetAwaiter ( ) . GetResult ( ) ;
134
63
135
- public override Task < int > ExecuteNonQueryAsync ( CancellationToken cancellationToken = default ) => ExecuteNonQueryAsync ( AsyncIOBehavior , cancellationToken ) ;
64
+ public Task < int > ExecuteNonQueryAsync ( CancellationToken cancellationToken = default ) => ExecuteNonQueryAsync ( AsyncIOBehavior , cancellationToken ) ;
136
65
137
- public override Task < object > ExecuteScalarAsync ( CancellationToken cancellationToken = default ) => ExecuteScalarAsync ( AsyncIOBehavior , cancellationToken ) ;
66
+ public Task < object > ExecuteScalarAsync ( CancellationToken cancellationToken = default ) => ExecuteScalarAsync ( AsyncIOBehavior , cancellationToken ) ;
138
67
139
- public override int Timeout { get ; set ; }
68
+ public int Timeout { get ; set ; }
140
69
141
- public override void Prepare ( )
70
+ public void Prepare ( )
142
71
{
143
72
if ( ! NeedsPrepare ( out var exception ) )
144
73
{
@@ -150,20 +79,13 @@ public override void Prepare()
150
79
DoPrepareAsync ( IOBehavior . Synchronous , default ) . GetAwaiter ( ) . GetResult ( ) ;
151
80
}
152
81
153
- public override Task PrepareAsync ( CancellationToken cancellationToken = default ) => PrepareAsync ( AsyncIOBehavior , cancellationToken ) ;
82
+ public Task PrepareAsync ( CancellationToken cancellationToken = default ) => PrepareAsync ( AsyncIOBehavior , cancellationToken ) ;
154
83
155
- public override void Cancel ( ) => Connection ? . Cancel ( this ) ;
84
+ public void Cancel ( ) => Connection ? . Cancel ( this ) ;
156
85
157
- protected override void Dispose ( bool disposing )
86
+ public void Dispose ( )
158
87
{
159
- try
160
- {
161
- m_isDisposed = true ;
162
- }
163
- finally
164
- {
165
- base . Dispose ( disposing ) ;
166
- }
88
+ m_isDisposed = true ;
167
89
}
168
90
169
91
int ICancellableCommand . CommandId => m_commandId ;
0 commit comments