|
1 | 1 | using System;
|
2 |
| -using System.Text; |
3 |
| -using NHibernate.Criterion; |
4 | 2 | using NHibernate.Engine;
|
5 | 3 | using NHibernate.SqlCommand;
|
6 | 4 |
|
@@ -39,35 +37,47 @@ public Order(string propertyName, bool ascending)
|
39 | 37 | public virtual SqlString ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
|
40 | 38 | {
|
41 | 39 | SqlString[] columns = CriterionUtil.GetColumnNames(propertyName, projection, criteriaQuery, criteria);
|
42 |
| - Type.IType type = projection?.GetTypes(criteria, criteriaQuery)[0] ?? criteriaQuery.GetTypeUsingProjection(criteria, propertyName); |
| 40 | + |
| 41 | + bool[] toLowerColumns = ignoreCase ? FindStringColumns(criteria, criteriaQuery) : null; |
43 | 42 |
|
44 |
| - StringBuilder fragment = new StringBuilder(); |
45 |
| - ISessionFactoryImplementor factory = criteriaQuery.Factory; |
| 43 | + var factory = criteriaQuery.Factory; |
| 44 | + var fragment = new SqlStringBuilder(); |
46 | 45 | for (int i = 0; i < columns.Length; i++)
|
47 | 46 | {
|
48 |
| - bool lower = ignoreCase && IsStringType(type.SqlTypes(factory)[i]); |
| 47 | + bool lower = toLowerColumns?[i] == true; |
49 | 48 |
|
50 | 49 | if (lower)
|
51 | 50 | {
|
52 |
| - fragment.Append(factory.Dialect.LowercaseFunction) |
53 |
| - .Append("("); |
| 51 | + fragment |
| 52 | + .Add(factory.Dialect.LowercaseFunction) |
| 53 | + .Add("("); |
54 | 54 | }
|
55 |
| - fragment.Append(columns[i]); |
| 55 | + |
| 56 | + fragment.Add(columns[i]); |
56 | 57 |
|
57 | 58 | if (lower)
|
58 | 59 | {
|
59 |
| - fragment.Append(")"); |
| 60 | + fragment.Add(")"); |
60 | 61 | }
|
61 | 62 |
|
62 |
| - fragment.Append(ascending ? " asc" : " desc"); |
| 63 | + fragment.Add(ascending ? " asc" : " desc"); |
63 | 64 |
|
64 | 65 | if (i < columns.Length - 1)
|
65 | 66 | {
|
66 |
| - fragment.Append(", "); |
| 67 | + fragment.Add(", "); |
67 | 68 | }
|
68 | 69 | }
|
69 | 70 |
|
70 |
| - return new SqlString(fragment.ToString()); |
| 71 | + return fragment.ToSqlString(); |
| 72 | + } |
| 73 | + |
| 74 | + private bool[] FindStringColumns(ICriteria criteria, ICriteriaQuery criteriaQuery) |
| 75 | + { |
| 76 | + var type = projection == null |
| 77 | + ? criteriaQuery.GetTypeUsingProjection(criteria, propertyName) |
| 78 | + : projection.GetTypes(criteria, criteriaQuery)[0]; |
| 79 | + |
| 80 | + return Array.ConvertAll(type.SqlTypes(criteriaQuery.Factory), t => IsStringType(t)); |
71 | 81 | }
|
72 | 82 |
|
73 | 83 | public override string ToString()
|
|
0 commit comments