forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNamedParameterSpecification.cs
101 lines (88 loc) · 3.07 KB
/
NamedParameterSpecification.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
99
100
101
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using NHibernate.Engine;
using NHibernate.SqlCommand;
namespace NHibernate.Param
{
/// <summary>
/// Parameter bind specification for an explicit named parameter.
/// </summary>
public partial class NamedParameterSpecification : AbstractExplicitParameterSpecification
{
private const string NamedParameterIdTemplate = "<nnh{0}_span{1}>";
private readonly string name;
/// <summary>
/// Constructs a named parameter bind specification.
/// </summary>
/// <param name="sourceLine">sourceLine</param>
/// <param name="sourceColumn">sourceColumn</param>
/// <param name="name">The named parameter name.</param>
public NamedParameterSpecification(int sourceLine, int sourceColumn, string name) : base(sourceLine, sourceColumn)
{
this.name = name;
}
/// <summary>
/// The user parameter name.
/// </summary>
public string Name
{
get { return name; }
}
public override string RenderDisplayInfo()
{
const string format = "name={0}, expectedType={1}";
return ExpectedType != null ? string.Format(format, name, ExpectedType) : string.Format(format, name, "Unknow");
}
public override IEnumerable<string> GetIdsForBackTrack(IMapping sessionFactory)
{
int paremeterSpan = GetParemeterSpan(sessionFactory);
for (int i = 0; i < paremeterSpan; i++)
{
yield return string.Format(NamedParameterIdTemplate, name, i);
}
}
public override void Bind(DbCommand command, IList<Parameter> sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session)
{
Bind(command, sqlQueryParametersList, 0, sqlQueryParametersList, queryParameters, session);
}
public override void Bind(DbCommand command, IList<Parameter> multiSqlQueryParametersList, int singleSqlParametersOffset, IList<Parameter> sqlQueryParametersList, QueryParameters queryParameters, ISessionImplementor session)
{
TypedValue typedValue = queryParameters.NamedParameters[name];
string backTrackId = GetIdsForBackTrack(session.Factory).First(); // just the first because IType suppose the oders in certain sequence
foreach (int position in sqlQueryParametersList.GetEffectiveParameterLocations(backTrackId))
{
ExpectedType.NullSafeSet(command, GetPagingValue(typedValue.Value, session.Factory.Dialect, queryParameters), position + singleSqlParametersOffset, session);
}
}
public override int GetSkipValue(QueryParameters queryParameters)
{
return (int)queryParameters.NamedParameters[name].Value;
}
public override void SetEffectiveType(QueryParameters queryParameters)
{
ExpectedType = queryParameters.NamedParameters[name].Type;
}
public override bool Equals(object obj)
{
return Equals(obj as NamedParameterSpecification);
}
public bool Equals(NamedParameterSpecification other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return Equals(other.name, name);
}
public override int GetHashCode()
{
return name.GetHashCode() ^ 211;
}
}
}