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 Seasar.Dao.Context;
|
21
|
|
using Seasar.Dao.Parser;
|
22
|
|
using Seasar.Extension.ADO;
|
23
|
|
|
24
|
|
namespace Seasar.Dao.Impl
|
25
|
|
{
|
26
|
|
public abstract class AbstractDynamicCommand : AbstractSqlCommand
|
27
|
|
{
|
28
|
|
private INode rootNode;
|
29
|
|
private string[] argNames = new string[0];
|
30
|
|
private Type[] argTypes = new Type[0];
|
31
|
|
|
32
|
50
|
public AbstractDynamicCommand(IDataSource dataSource, ICommandFactory commandFactory)
|
33
|
|
: base(dataSource, commandFactory)
|
34
|
|
{
|
35
|
|
}
|
36
|
|
|
37
|
|
public override string Sql
|
38
|
|
{
|
39
|
50
|
set
|
40
|
|
{
|
41
|
50
|
base.Sql = value;
|
42
|
50
|
rootNode = new SqlParserImpl(value).Parse();
|
43
|
|
}
|
44
|
0
|
get
|
45
|
|
{
|
46
|
|
return base.Sql;
|
47
|
|
}
|
48
|
|
}
|
49
|
|
|
50
|
|
public string[] ArgNames
|
51
|
|
{
|
52
|
0
|
get { return argNames; }
|
53
|
50
|
set { argNames = value; }
|
54
|
|
}
|
55
|
|
|
56
|
|
public Type[] ArgTypes
|
57
|
|
{
|
58
|
0
|
get { return argTypes; }
|
59
|
49
|
set { argTypes = value; }
|
60
|
|
}
|
61
|
|
|
62
|
11
|
protected ICommandContext Apply(object[] args)
|
63
|
|
{
|
64
|
11
|
ICommandContext ctx = CreateCommandContext(args);
|
65
|
11
|
rootNode.Accept(ctx);
|
66
|
11
|
return ctx;
|
67
|
|
}
|
68
|
|
|
69
|
11
|
protected ICommandContext CreateCommandContext(object[] args)
|
70
|
|
{
|
71
|
11
|
ICommandContext ctx = GetCommandContext();
|
72
|
11
|
if(args != null)
|
73
|
|
{
|
74
|
21
|
for(int i = 0; i < args.Length; ++i)
|
75
|
|
{
|
76
|
10
|
Type argType = null;
|
77
|
10
|
if(args[i] != null)
|
78
|
|
{
|
79
|
10
|
if(i < argTypes.Length)
|
80
|
9
|
argType = argTypes[i];
|
81
|
1
|
else if (args[i] != null)
|
82
|
1
|
argType = args[i].GetType();
|
83
|
|
}
|
84
|
10
|
if(i < argNames.Length)
|
85
|
10
|
ctx.AddArg(argNames[i], args[i], argType);
|
86
|
|
else
|
87
|
0
|
ctx.AddArg("$" + (i + 1), args[i], argType);
|
88
|
|
}
|
89
|
|
}
|
90
|
11
|
return ctx;
|
91
|
|
}
|
92
|
|
|
93
|
11
|
private ICommandContext GetCommandContext()
|
94
|
|
{
|
95
|
11
|
return new CommandContextImpl();
|
96
|
|
}
|
97
|
|
}
|
98
|
|
}
|
99
|
|
|