-
Notifications
You must be signed in to change notification settings - Fork 935
/
Copy pathJoinFragment.cs
98 lines (81 loc) · 2.21 KB
/
JoinFragment.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
88
89
90
91
92
93
94
95
96
97
98
using System;
using NHibernate.Util;
namespace NHibernate.SqlCommand
{
/// <summary></summary>
public enum JoinType
{
None = -666,
InnerJoin = 0,
FullJoin = 4,
LeftOuterJoin = 1,
RightOuterJoin = 2,
CrossJoin = 8
}
/// <summary>
/// Represents a SQL <c>JOIN</c>
/// </summary>
public abstract class JoinFragment
{
public abstract void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType);
public abstract void AddJoin(string tableName, string alias, string[] fkColumns, string[] pkColumns, JoinType joinType,
SqlString on);
public abstract void AddCrossJoin(string tableName, string alias);
public abstract void AddJoins(SqlString fromFragment, SqlString whereFragment);
public abstract SqlString ToFromFragmentString { get; }
public abstract SqlString ToWhereFragmentString { get; }
public abstract bool AddCondition(string condition);
public abstract bool AddCondition(SqlString condition);
public abstract void AddFromFragmentString(SqlString fromFragmentString);
public virtual void AddFragment(JoinFragment ojf)
{
AddJoins(ojf.ToFromFragmentString, ojf.ToWhereFragmentString);
}
protected bool AddCondition(SqlStringBuilder buffer, string on)
{
if (StringHelper.IsNotEmpty(on))
{
if (!on.StartsWith(" and", StringComparison.Ordinal))
{
buffer.Add(" and ");
}
buffer.Add(on);
return true;
}
else
{
return false;
}
}
/// <summary>
/// Adds condition to buffer without adding " and " prefix. Existing " and" prefix is removed
/// </summary>
protected void AddBareCondition(SqlStringBuilder buffer, SqlString condition)
{
if (SqlStringHelper.IsEmpty(condition))
return;
buffer.Add(
condition.StartsWithCaseInsensitive(" and ")
? condition.Substring(4)
: condition);
}
protected bool AddCondition(SqlStringBuilder buffer, SqlString on)
{
if (SqlStringHelper.IsNotEmpty(on))
{
if (!on.StartsWithCaseInsensitive(" and"))
{
buffer.Add(" and ");
}
buffer.Add(on);
return true;
}
else
{
return false;
}
}
public bool HasFilterCondition { get; set; }
public bool HasThetaJoins { get; set; }
}
}