forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMySqlClientSqlCommandSet.cs
67 lines (57 loc) · 1.78 KB
/
MySqlClientSqlCommandSet.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Data.Common;
using System.Diagnostics;
using System.Reflection;
using NHibernate.Util;
namespace NHibernate.AdoNet
{
public class MySqlClientSqlCommandSet : IDisposable
{
private static readonly System.Type adapterType;
private static readonly Action<object> doInitialise;
private static readonly Action<object, int> batchSizeSetter;
private static readonly Action<object, DbCommand> doAppend;
private static readonly Func<object, int> doExecuteNonQuery;
private static readonly Action<object> doDispose;
private readonly object instance;
private int countOfCommands;
static MySqlClientSqlCommandSet()
{
var sysData = Assembly.Load("MySql.Data");
adapterType = sysData.GetType("MySql.Data.MySqlClient.MySqlDataAdapter");
Debug.Assert(adapterType != null, "Could not find MySqlDataAdapter!");
doInitialise = DelegateHelper.BuildAction(adapterType, "InitializeBatching");
batchSizeSetter = DelegateHelper.BuildPropertySetter<int>(adapterType, "UpdateBatchSize");
doAppend = DelegateHelper.BuildAction<DbCommand>(adapterType, "AddToBatch");
doExecuteNonQuery = DelegateHelper.BuildFunc<int>(adapterType, "ExecuteBatch");
doDispose = DelegateHelper.BuildAction(adapterType, "Dispose");
}
public MySqlClientSqlCommandSet(int batchSize)
{
instance = Activator.CreateInstance(adapterType, true);
doInitialise(instance);
batchSizeSetter(instance, batchSize);
}
public void Append(DbCommand command)
{
doAppend(instance, command);
countOfCommands++;
}
public void Dispose()
{
doDispose(instance);
}
public int ExecuteNonQuery()
{
if (CountOfCommands == 0)
{
return 0;
}
return doExecuteNonQuery(instance);
}
public int CountOfCommands
{
get { return countOfCommands; }
}
}
}