forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCastProjection.cs
68 lines (59 loc) · 1.7 KB
/
CastProjection.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
namespace NHibernate.Criterion
{
using System;
using Engine;
using SqlCommand;
using SqlTypes;
using Type;
using Util;
/// <summary>
/// Casting a value from one type to another, at the database
/// level
/// </summary>
[Serializable]
public class CastProjection : SimpleProjection
{
private readonly IType type;
private readonly IProjection projection;
public CastProjection(IType type, IProjection projection)
{
this.type = type;
this.projection = projection;
}
public override bool IsAggregate
{
get { return false; }
}
public override SqlString ToSqlString(ICriteria criteria, int position, ICriteriaQuery criteriaQuery)
{
ISessionFactoryImplementor factory = criteriaQuery.Factory;
SqlType[] sqlTypeCodes = type.SqlTypes(factory);
if (sqlTypeCodes.Length != 1)
{
throw new QueryException("invalid Hibernate type for CastProjection");
}
string sqlType = factory.Dialect.GetCastTypeName(sqlTypeCodes[0]);
var val = CriterionUtil.GetColumnNameAsSqlStringPart(projection, criteriaQuery, criteria);
return new SqlString("cast( ", val, " as ", sqlType, ") as ", GetColumnAlias(position));
}
public override IType[] GetTypes(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return new IType[]{ type };
}
public override NHibernate.Engine.TypedValue[] GetTypedValues(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return projection.GetTypedValues(criteria, criteriaQuery);
}
public override bool IsGrouped
{
get
{
return projection.IsGrouped;
}
}
public override SqlString ToGroupSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
{
return projection.ToGroupSqlString(criteria, criteriaQuery);
}
}
}