forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLCriterion.cs
60 lines (55 loc) · 1.65 KB
/
SQLCriterion.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
using System.Collections;
using NHibernate.Engine;
using NHibernate.SqlCommand;
using NHibernate.Type;
namespace NHibernate.Expression
{
/// <summary>
/// An <see cref="ICriterion"/> that creates a SQLExpression.
/// The string {alias} will be replaced by the alias of the root entity.
/// </summary>
/// <remarks>
/// This allows for database specific Expressions at the cost of needing to
/// write a correct <see cref="SqlString"/>.
/// </remarks>
public class SQLCriterion : AbstractCriterion
{
private readonly SqlString _sql;
private readonly TypedValue[ ] _typedValues;
public SQLCriterion( SqlString sql, object[ ] values, IType[ ] types )
{
_sql = sql;
_typedValues = new TypedValue[values.Length];
for( int i = 0; i < _typedValues.Length; i++ )
{
_typedValues[ i ] = new TypedValue( types[ i ], values[ i ] );
}
}
/// <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 )
{
return _sql.Replace( "{alias}", alias );
}
/// <summary>
///
/// </summary>
/// <param name="sessionFactory"></param>
/// <param name="persistentClass"></param>
/// <returns></returns>
public override TypedValue[ ] GetTypedValues( ISessionFactoryImplementor sessionFactory, System.Type persistentClass, IDictionary aliasClasses )
{
return _typedValues;
}
/// <summary></summary>
public override string ToString()
{
return _sql.ToString();
}
}
}