2
2
using System . Data ;
3
3
using System . Diagnostics ;
4
4
using System . Reflection ;
5
+ using NHibernate . Util ;
5
6
6
7
namespace NHibernate . AdoNet
7
8
{
8
- using Action = System . Action ;
9
-
10
9
public class MySqlClientSqlCommandSet : IDisposable
11
10
{
12
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 , IDbCommand > doAppend ;
15
+ private static readonly Func < object , int > doExecuteNonQuery ;
16
+ private static readonly Action < object > doDispose ;
17
+
13
18
private readonly object instance ;
14
- private readonly Action doInitialise ;
15
- private readonly Action < int > batchSizeSetter ;
16
- private readonly Func < IDbCommand , int > doAppend ;
17
- private readonly Func < int > doExecuteNonQuery ;
18
- private readonly Action doDispose ;
19
19
private int countOfCommands ;
20
20
21
21
static MySqlClientSqlCommandSet ( )
22
22
{
23
23
var sysData = Assembly . Load ( "MySql.Data" ) ;
24
24
adapterType = sysData . GetType ( "MySql.Data.MySqlClient.MySqlDataAdapter" ) ;
25
25
Debug . Assert ( adapterType != null , "Could not find MySqlDataAdapter!" ) ;
26
+
27
+ doInitialise = DelegateHelper . BuildAction ( adapterType , "InitializeBatching" ) ;
28
+ batchSizeSetter = DelegateHelper . BuildPropertySetter < int > ( adapterType , "UpdateBatchSize" ) ;
29
+ doAppend = DelegateHelper . BuildAction < IDbCommand > ( adapterType , "AddToBatch" ) ;
30
+ doExecuteNonQuery = DelegateHelper . BuildFunc < int > ( adapterType , "ExecuteBatch" ) ;
31
+ doDispose = DelegateHelper . BuildAction ( adapterType , "Dispose" ) ;
26
32
}
27
33
28
34
public MySqlClientSqlCommandSet ( int batchSize )
29
35
{
30
36
instance = Activator . CreateInstance ( adapterType , true ) ;
31
- doInitialise = ( Action ) Delegate . CreateDelegate ( typeof ( Action ) , instance , "InitializeBatching" ) ;
32
- batchSizeSetter = ( Action < int > ) Delegate . CreateDelegate ( typeof ( Action < int > ) , instance , "set_UpdateBatchSize" ) ;
33
- doAppend = ( Func < IDbCommand , int > ) Delegate . CreateDelegate ( typeof ( Func < IDbCommand , int > ) , instance , "AddToBatch" ) ;
34
- doExecuteNonQuery = ( Func < int > ) Delegate . CreateDelegate ( typeof ( Func < int > ) , instance , "ExecuteBatch" ) ;
35
- doDispose = ( Action ) Delegate . CreateDelegate ( typeof ( Action ) , instance , "Dispose" ) ;
36
-
37
- Initialise ( batchSize ) ;
38
- }
39
-
40
- private void Initialise ( int batchSize )
41
- {
42
- doInitialise ( ) ;
43
- batchSizeSetter ( batchSize ) ;
37
+ doInitialise ( instance ) ;
38
+ batchSizeSetter ( instance , batchSize ) ;
44
39
}
45
40
46
41
public void Append ( IDbCommand command )
47
42
{
48
- doAppend ( command ) ;
43
+ doAppend ( instance , command ) ;
49
44
countOfCommands ++ ;
50
45
}
51
46
52
47
public void Dispose ( )
53
48
{
54
- doDispose ( ) ;
49
+ doDispose ( instance ) ;
55
50
}
56
51
57
52
public int ExecuteNonQuery ( )
@@ -63,7 +58,7 @@ public int ExecuteNonQuery()
63
58
return 0 ;
64
59
}
65
60
66
- return doExecuteNonQuery ( ) ;
61
+ return doExecuteNonQuery ( instance ) ;
67
62
}
68
63
catch ( Exception exception )
69
64
{
@@ -73,10 +68,7 @@ public int ExecuteNonQuery()
73
68
74
69
public int CountOfCommands
75
70
{
76
- get
77
- {
78
- return countOfCommands ;
79
- }
71
+ get { return countOfCommands ; }
80
72
}
81
73
}
82
74
}
0 commit comments