forked from nhibernate/nhibernate-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrder.cs
66 lines (59 loc) · 1.68 KB
/
Order.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
using System.Collections;
using NHibernate.Engine;
namespace NHibernate.Expression
{
/// <summary>
/// Represents an order imposed upon a <see cref="ICriteria"/>
/// result set.
/// </summary>
public class Order
{
private bool _ascending;
private string _propertyName;
/// <summary>
/// Constructor for Order.
/// </summary>
/// <param name="propertyName"></param>
/// <param name="ascending"></param>
public Order( string propertyName, bool ascending )
{
_propertyName = propertyName;
_ascending = ascending;
}
/// <summary>
/// Render the SQL fragment
/// </summary>
/// <param name="sessionFactory"></param>
/// <param name="persistentClass"></param>
/// <param name="alias"></param>
/// <returns></returns>
public string ToSqlString( ISessionFactoryImplementor sessionFactory, System.Type persistentClass, string alias )
{
string[ ] columns = AbstractCriterion.GetColumns( sessionFactory, persistentClass, _propertyName, alias, emptyMap );
if( columns.Length != 1 )
{
throw new HibernateException( "Cannot order by multi-column property: " + _propertyName );
}
return columns[ 0 ] + ( _ascending ? " asc" : " desc" );
}
/// <summary>
/// Ascending order
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static Order Asc( string propertyName )
{
return new Order( propertyName, true );
}
/// <summary>
/// Descending order
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public static Order Desc( string propertyName )
{
return new Order( propertyName, false );
}
private static readonly IDictionary emptyMap = new Hashtable( 0 );
}
}