1
1
using System ;
2
2
using System . Data . Common ;
3
3
using System . Diagnostics ;
4
- using System . Reflection ;
4
+ using MySql . Data . MySqlClient ;
5
5
using NHibernate . Util ;
6
6
7
7
namespace NHibernate . AdoNet
8
8
{
9
9
public class MySqlClientSqlCommandSet : IDisposable
10
10
{
11
11
private static readonly System . Type adapterType ;
12
- private static readonly Action < object > doInitialise ;
13
- private static readonly Action < object , int > batchSizeSetter ;
14
- private static readonly Action < object , DbCommand > doAppend ;
15
- private static readonly Func < object , int > doExecuteNonQuery ;
16
- private static readonly Action < object > doDispose ;
12
+ private static readonly Action < MySqlDataAdapter > doInitialise ;
13
+ private static readonly Action < MySqlDataAdapter , DbCommand > doAppend ;
14
+ private static readonly Func < MySqlDataAdapter , int > doExecuteNonQuery ;
17
15
18
- private readonly object instance ;
16
+ private readonly MySqlDataAdapter instance ;
19
17
private int countOfCommands ;
20
18
21
19
static MySqlClientSqlCommandSet ( )
22
20
{
23
- var sysData = Assembly . Load ( "MySql.Data" ) ;
24
- adapterType = sysData . GetType ( "MySql.Data.MySqlClient.MySqlDataAdapter" ) ;
21
+ adapterType = typeof ( MySqlDataAdapter ) ;
25
22
Debug . Assert ( adapterType != null , "Could not find MySqlDataAdapter!" ) ;
26
23
27
24
doInitialise = DelegateHelper . BuildAction ( adapterType , "InitializeBatching" ) ;
28
- batchSizeSetter = DelegateHelper . BuildPropertySetter < int > ( adapterType , "UpdateBatchSize" ) ;
29
25
doAppend = DelegateHelper . BuildAction < DbCommand > ( adapterType , "AddToBatch" ) ;
30
26
doExecuteNonQuery = DelegateHelper . BuildFunc < int > ( adapterType , "ExecuteBatch" ) ;
31
- doDispose = DelegateHelper . BuildAction ( adapterType , "Dispose" ) ;
32
27
}
33
28
34
29
public MySqlClientSqlCommandSet ( int batchSize )
35
30
{
36
- instance = Activator . CreateInstance ( adapterType , true ) ;
31
+ instance = new MySqlDataAdapter ( ) ;
32
+ instance = ( MySqlDataAdapter ) Activator . CreateInstance ( adapterType , true ) ;
37
33
doInitialise ( instance ) ;
38
- batchSizeSetter ( instance , batchSize ) ;
34
+ instance . UpdateBatchSize = batchSize ;
39
35
}
40
36
41
37
public void Append ( DbCommand command )
@@ -46,7 +42,7 @@ public void Append(DbCommand command)
46
42
47
43
public void Dispose ( )
48
44
{
49
- doDispose ( instance ) ;
45
+ instance . Dispose ( ) ;
50
46
}
51
47
52
48
public int ExecuteNonQuery ( )
0 commit comments