forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConditionalFragment.cs
87 lines (78 loc) · 1.7 KB
/
ConditionalFragment.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using NHibernate.Util;
namespace NHibernate.SqlCommand
{
/// <summary></summary>
public class ConditionalFragment
{
private string tableAlias;
private string[] lhs;
private object[] rhs;
private string op = "=";
/// <summary>
/// Sets the op
/// </summary>
/// <param name="op">The op to set</param>
public ConditionalFragment SetOp(string op)
{
this.op = op;
return this;
}
/// <summary>
///
/// </summary>
/// <param name="tableAlias"></param>
/// <returns></returns>
public ConditionalFragment SetTableAlias(string tableAlias)
{
this.tableAlias = tableAlias;
return this;
}
/// <summary>
///
/// </summary>
/// <param name="lhs"></param>
/// <param name="rhs"></param>
/// <returns></returns>
public ConditionalFragment SetCondition(string[] lhs, string[] rhs)
{
this.lhs = lhs;
this.rhs = rhs;
return this;
}
public ConditionalFragment SetCondition(string[] lhs, Parameter[] rhs)
{
this.lhs = lhs;
this.rhs = rhs;
return this;
}
/// <summary>
///
/// </summary>
/// <param name="lhs"></param>
/// <param name="rhs"></param>
/// <returns></returns>
public ConditionalFragment SetCondition(string[] lhs, string rhs)
{
this.lhs = lhs;
this.rhs = ArrayHelper.Fill(rhs, lhs.Length);
return this;
}
/// <summary></summary>
public SqlString ToSqlStringFragment()
{
SqlStringBuilder buf = new SqlStringBuilder(lhs.Length * 4);
string prefix = tableAlias + StringHelper.Dot;
for (int i = 0; i < lhs.Length; i++)
{
buf.Add(prefix)
.Add(lhs[i] + op);
buf.AddObject(rhs[i]);
if (i < lhs.Length - 1)
{
buf.Add(" and ");
}
}
return buf.ToSqlString();
}
}
}