forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPropertyExpression.cs
81 lines (70 loc) · 2.53 KB
/
PropertyExpression.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
using System.Collections;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.Util;
namespace NHibernate.Expression
{
/// <summary>
/// Superclass for an <see cref="ICriterion"/> that represents a
/// constraint between two properties (with SQL binary operators).
/// </summary>
public abstract class PropertyExpression : AbstractCriterion
{
private string _lhsPropertyName;
private string _rhsPropertyName;
private static TypedValue[ ] NoTypedValues = new TypedValue[0];
/// <summary>
/// Initialize a new instance of the <see cref="PropertyExpression" /> class
/// that compares two mapped properties.
/// </summary>
/// <param name="lhsPropertyName">The name of the Property to use as the left hand side.</param>
/// <param name="rhsPropertyName">The name of the Property to use as the right hand side.</param>
protected PropertyExpression(string lhsPropertyName, string rhsPropertyName)
{
_lhsPropertyName = lhsPropertyName;
_rhsPropertyName = rhsPropertyName;
}
/// <summary>
///
/// </summary>
/// <param name="factory"></param>
/// <param name="persistentClass"></param>
/// <param name="alias"></param>
/// <returns></returns>
public override SqlString ToSqlString( ISessionFactoryImplementor factory, System.Type persistentClass, string alias, IDictionary aliasClasses )
{
SqlStringBuilder sqlBuilder = new SqlStringBuilder();
string[ ] columnNames = AbstractCriterion.GetColumns( factory, persistentClass, _lhsPropertyName, alias, aliasClasses );
string[ ] otherColumnNames = AbstractCriterion.GetColumns( factory, persistentClass, _rhsPropertyName, alias, aliasClasses );
string result = string.Join(
" and ",
StringHelper.Add( columnNames, Op, otherColumnNames )
);
if( columnNames.Length > 1 )
{
result = StringHelper.OpenParen + result + StringHelper.ClosedParen;
}
return new SqlString( result );
//TODO: get SQL rendering out of this package!
}
/// <summary>
///
/// </summary>
/// <param name="sessionFactory"></param>
/// <param name="persistentClass"></param>
/// <returns></returns>
public override TypedValue[ ] GetTypedValues( ISessionFactoryImplementor sessionFactory, System.Type persistentClass, IDictionary aliasClasses )
{
return NoTypedValues;
}
/// <summary></summary>
public override string ToString()
{
return _lhsPropertyName + Op + _rhsPropertyName;
}
/// <summary>
/// Get the Sql operator to use for the property expression.
/// </summary>
protected abstract string Op { get; }
}
}