forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupedProjection.cs
84 lines (70 loc) · 2.32 KB
/
GroupedProjection.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
using System;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.Type;
namespace NHibernate.Criterion
{
[Serializable]
public class GroupedProjection : IProjection
{
private readonly IProjection projection;
private SqlString renderedProjection;
public GroupedProjection(IProjection projection)
{
this.projection = projection;
}
public virtual SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery)
{
return renderedProjection = projection.ToSqlString(criteria, position, criteriaQuery);
}
public virtual SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
if (projection is IPropertyProjection propertyProjection)
return new SqlString(string.Join(", ", criteriaQuery.GetColumns(criteria, propertyProjection.PropertyName)));
//This is kind of a hack. The hack is based on the fact that ToGroupSqlString always called after ToSqlString.
return SqlStringHelper.RemoveAsAliasesFromSql(renderedProjection);
}
public virtual IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return projection.GetTypes(criteria, criteriaQuery);
}
public virtual IType[] GetTypes(String alias, ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return this.projection.GetTypes(alias, criteria, criteriaQuery);
}
public string[] GetColumnAliases(int position, ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return projection.GetColumnAliases(position, criteria, criteriaQuery);
}
public string[] GetColumnAliases(string alias, int position, ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return null;
}
public virtual string[] Aliases
{
get { return Array.Empty<string>(); }
}
public virtual bool IsGrouped
{
get { return true; }
}
public bool IsAggregate
{
get { return projection.IsAggregate; }
}
/// <summary>
/// Gets the typed values for parameters in this projection
/// </summary>
/// <param name="criteria">The criteria.</param>
/// <param name="criteriaQuery">The criteria query.</param>
/// <returns></returns>
public TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return projection.GetTypedValues(criteria, criteriaQuery);
}
public override string ToString()
{
return projection.ToString();
}
}
}