1
|
|
#region Copyright
|
2
|
|
|
3
|
|
|
4
|
|
|
5
|
|
|
6
|
|
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
|
16
|
|
|
17
|
|
#endregion
|
18
|
|
|
19
|
|
using System;
|
20
|
|
using System.Collections;
|
21
|
|
|
22
|
|
namespace Seasar.Dao.Node
|
23
|
|
{
|
24
|
|
public class ParenBindVariableNode : AbstractNode
|
25
|
|
{
|
26
|
|
private string bindName;
|
27
|
|
private string expression;
|
28
|
|
|
29
|
18
|
public ParenBindVariableNode(string expression)
|
30
|
|
{
|
31
|
18
|
this.bindName = expression;
|
32
|
18
|
this.expression = "self.GetArg('" + expression + "')";
|
33
|
|
}
|
34
|
|
|
35
|
0
|
public string Expression
|
36
|
|
{
|
37
|
|
get { return expression; }
|
38
|
|
}
|
39
|
|
|
40
|
5
|
public override void Accept(ICommandContext ctx)
|
41
|
|
{
|
42
|
5
|
object var = InvokeExpression(expression, ctx);
|
43
|
5
|
if(var != null)
|
44
|
|
{
|
45
|
5
|
IList list = var as IList;
|
46
|
5
|
Array array = new object[list.Count];
|
47
|
5
|
list.CopyTo(array, 0);
|
48
|
5
|
BindArray(ctx, array);
|
49
|
|
}
|
50
|
0
|
else if(var == null)
|
51
|
|
{
|
52
|
|
return;
|
53
|
|
}
|
54
|
|
else if(var.GetType().IsArray)
|
55
|
|
{
|
56
|
|
BindArray(ctx, var);
|
57
|
|
}
|
58
|
|
else
|
59
|
|
{
|
60
|
|
ctx.AddSql(var, var.GetType(), bindName);
|
61
|
|
}
|
62
|
|
}
|
63
|
|
|
64
|
5
|
private void BindArray(ICommandContext ctx, object arrayArg)
|
65
|
|
{
|
66
|
5
|
object[] array = arrayArg as object[];
|
67
|
5
|
int length = array.Length;
|
68
|
0
|
if(length == 0) return;
|
69
|
5
|
Type type = null;
|
70
|
23
|
for(int i = 0; i < length; ++i)
|
71
|
|
{
|
72
|
18
|
object o = array[i];
|
73
|
18
|
if(o != null) type = o.GetType();
|
74
|
|
}
|
75
|
5
|
ctx.AddSql("(");
|
76
|
5
|
ctx.AddSql(array[0], type, bindName + 1);
|
77
|
18
|
for(int i = 1; i < length; ++i)
|
78
|
|
{
|
79
|
13
|
ctx.AppendSql(array[i], type, bindName + (i + 1));
|
80
|
|
}
|
81
|
5
|
ctx.AddSql(")");
|
82
|
|
}
|
83
|
|
|
84
|
|
}
|
85
|
|
}
|
86
|
|
|