1
|
|
|
2
|
|
#region Apache Notice
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
|
22
|
|
|
23
|
|
|
24
|
|
|
25
|
|
#endregion
|
26
|
|
|
27
|
|
#region Using
|
28
|
|
using System;
|
29
|
|
using System.Data;
|
30
|
|
using System.Collections;
|
31
|
|
using System.Reflection;
|
32
|
|
using System.Xml.Serialization;
|
33
|
|
using System.Text;
|
34
|
|
|
35
|
|
using Castle.DynamicProxy;
|
36
|
|
|
37
|
|
using IBatisNet.Common;
|
38
|
|
using IBatisNet.Common.Utilities.Objects;
|
39
|
|
|
40
|
|
using IBatisNet.Common.Exceptions;
|
41
|
|
|
42
|
|
using log4net;
|
43
|
|
#endregion
|
44
|
|
|
45
|
|
namespace IBatisNet.DataMapper.Commands
|
46
|
|
{
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
|
public class IPreparedCommandProxy : IInterceptor
|
51
|
|
{
|
52
|
|
|
53
|
|
#region Fields
|
54
|
|
private IPreparedCommand _preparedCommand = null;
|
55
|
|
private static ArrayList _passthroughMethods = new ArrayList();
|
56
|
|
private static readonly ILog _logger = LogManager.GetLogger( "IBatisNet.DataMapper.Commands.IPreparedCommand" );
|
57
|
|
|
58
|
|
#endregion
|
59
|
|
|
60
|
|
#region Constructors
|
61
|
|
|
62
|
0
|
static IPreparedCommandProxy()
|
63
|
|
{
|
64
|
|
_passthroughMethods.Add("GetType");
|
65
|
|
_passthroughMethods.Add("ToString");
|
66
|
|
}
|
67
|
|
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
0
|
internal IPreparedCommandProxy(IPreparedCommand preparedCommand)
|
73
|
|
{
|
74
|
|
_preparedCommand = preparedCommand;
|
75
|
|
}
|
76
|
|
#endregion
|
77
|
|
|
78
|
|
#region Methods
|
79
|
|
|
80
|
|
|
81
|
|
|
82
|
|
|
83
|
|
|
84
|
|
|
85
|
0
|
internal static IPreparedCommand NewInstance(IPreparedCommand preparedCommand)
|
86
|
|
{
|
87
|
|
object proxyIPreparedCommand = null;
|
88
|
|
IInterceptor handler = new IPreparedCommandProxy(preparedCommand);
|
89
|
|
|
90
|
|
ProxyGenerator proxyGenerator = new ProxyGenerator();
|
91
|
|
|
92
|
|
proxyIPreparedCommand = proxyGenerator.CreateProxy(typeof(IPreparedCommand), handler, preparedCommand);
|
93
|
|
|
94
|
|
return (IPreparedCommand) proxyIPreparedCommand;
|
95
|
|
}
|
96
|
|
#endregion
|
97
|
|
|
98
|
|
#region IInterceptor Members
|
99
|
|
|
100
|
|
|
101
|
|
|
102
|
|
|
103
|
|
|
104
|
|
|
105
|
|
|
106
|
0
|
public object Intercept(IInvocation invocation, params object[] arguments)
|
107
|
|
{
|
108
|
|
object returnValue = null;
|
109
|
|
|
110
|
|
returnValue = invocation.Method.Invoke( _preparedCommand, arguments);
|
111
|
|
|
112
|
|
if (invocation.Method.Name=="Create")
|
113
|
|
{
|
114
|
|
if (_logger.IsDebugEnabled)
|
115
|
|
{
|
116
|
|
IDbCommand command = (IDbCommand)returnValue;
|
117
|
|
|
118
|
|
_logger.Debug("PreparedStatement : [" + command.CommandText + "]");
|
119
|
|
if (command.Parameters.Count>0)
|
120
|
|
{
|
121
|
|
StringBuilder valueList = new StringBuilder();
|
122
|
|
StringBuilder typeList = new StringBuilder();
|
123
|
|
|
124
|
|
for ( int i = 0; i < command.Parameters.Count; ++i )
|
125
|
|
{
|
126
|
|
IDataParameter sqlParameter = (IDataParameter)command.Parameters[i];
|
127
|
|
if (sqlParameter.Value == System.DBNull.Value)
|
128
|
|
{
|
129
|
|
valueList.Append("null,");
|
130
|
|
typeList.Append("null,");
|
131
|
|
}
|
132
|
|
else
|
133
|
|
{
|
134
|
|
valueList.Append( sqlParameter.Value.ToString() );
|
135
|
|
valueList.Append( "," );
|
136
|
|
typeList.Append( sqlParameter.Value.GetType().ToString() );
|
137
|
|
typeList.Append( "," );
|
138
|
|
}
|
139
|
|
}
|
140
|
|
|
141
|
|
_logger.Debug("Parameters: [" + valueList.ToString().Remove(valueList.ToString().Length-1,1) + "]");
|
142
|
|
_logger.Debug("Types: [" + typeList.ToString().Remove(typeList.ToString().Length-1,1) + "]");
|
143
|
|
}
|
144
|
|
}
|
145
|
|
}
|
146
|
|
|
147
|
|
return returnValue;
|
148
|
|
}
|
149
|
|
|
150
|
|
#endregion
|
151
|
|
}
|
152
|
|
}
|
153
|
|
|