1
- using System ;
2
- using System . Collections . Generic ;
3
- using System . Data ;
4
- using System . Linq ;
5
- using NHibernate . Engine ;
6
- using NHibernate . SqlCommand ;
7
- using NHibernate . Type ;
8
-
9
- namespace NHibernate . Param
10
- {
11
- /// <summary>
12
- /// Autogenerated parameter for <see cref="IQuery.SetMaxResults"/>.
13
- /// </summary>
14
- public class QueryTakeParameterSpecification : IParameterSpecification
15
- {
16
- // NOTE: don't use this for HQL take clause
17
- private readonly string [ ] idTrack ;
18
- private readonly string limitParametersNameForThisQuery = "<nhtake" + Guid . NewGuid ( ) . ToString ( "N" ) ; // NH_note: to avoid conflicts using MultiQuery/Future
19
- private readonly IType type = NHibernateUtil . Int32 ;
20
-
21
- public QueryTakeParameterSpecification ( )
22
- {
23
- idTrack = new [ ] { limitParametersNameForThisQuery } ;
24
- }
25
-
26
- #region IParameterSpecification Members
27
-
28
- public void Bind ( IDbCommand command , IList < Parameter > sqlQueryParametersList , QueryParameters queryParameters , ISessionImplementor session )
29
- {
30
- Bind ( command , sqlQueryParametersList , 0 , sqlQueryParametersList , queryParameters , session ) ;
31
- }
32
-
33
- public void Bind ( IDbCommand command , IList < Parameter > multiSqlQueryParametersList , int singleSqlParametersOffset , IList < Parameter > sqlQueryParametersList , QueryParameters queryParameters , ISessionImplementor session )
34
- {
35
- // The QueryTakeParameterSpecification is unique so we can use multiSqlQueryParametersList
36
- var effectiveParameterLocations = multiSqlQueryParametersList . GetEffectiveParameterLocations ( limitParametersNameForThisQuery ) . ToArray ( ) ;
37
- if ( effectiveParameterLocations . Any ( ) )
38
- {
39
- // if the dialect does not support variable limits the parameter may was removed
40
- int value = queryParameters . RowSelection . MaxRows ;
41
- int position = effectiveParameterLocations . Single ( ) ;
42
- type . NullSafeSet ( command , value , position , session ) ;
43
- }
44
- }
45
-
46
- public IType ExpectedType
47
- {
48
- get { return type ; }
49
- set { throw new InvalidOperationException ( ) ; }
50
- }
51
-
52
- public string RenderDisplayInfo ( )
53
- {
54
- return "query-take" ;
55
- }
56
-
57
- public IEnumerable < string > GetIdsForBackTrack ( IMapping sessionFactory )
58
- {
59
- return idTrack ;
60
- }
61
-
62
- #endregion
63
-
64
- public override bool Equals ( object obj )
65
- {
66
- return Equals ( obj as QueryTakeParameterSpecification ) ;
67
- }
68
-
69
- public bool Equals ( QueryTakeParameterSpecification other )
70
- {
71
- if ( ReferenceEquals ( null , other ) )
72
- {
73
- return false ;
74
- }
75
- if ( ReferenceEquals ( this , other ) )
76
- {
77
- return true ;
78
- }
79
- return Equals ( other . limitParametersNameForThisQuery , limitParametersNameForThisQuery ) ;
80
- }
81
-
82
- public override int GetHashCode ( )
83
- {
84
- return limitParametersNameForThisQuery . GetHashCode ( ) ;
85
- }
86
- }
1
+ using System ;
2
+ using System . Collections . Generic ;
3
+ using System . Data ;
4
+ using System . Linq ;
5
+ using NHibernate . Engine ;
6
+ using NHibernate . SqlCommand ;
7
+ using NHibernate . Type ;
8
+
9
+ namespace NHibernate . Param
10
+ {
11
+ /// <summary>
12
+ /// Autogenerated parameter for <see cref="IQuery.SetMaxResults"/>.
13
+ /// </summary>
14
+ public class QueryTakeParameterSpecification : IParameterSpecification
15
+ {
16
+ // NOTE: don't use this for HQL take clause
17
+ private readonly string [ ] idTrack ;
18
+ private readonly string limitParametersNameForThisQuery = "<nhtake" + Guid . NewGuid ( ) . ToString ( "N" ) ; // NH_note: to avoid conflicts using MultiQuery/Future
19
+ private readonly IType type = NHibernateUtil . Int32 ;
20
+
21
+ public QueryTakeParameterSpecification ( )
22
+ {
23
+ idTrack = new [ ] { limitParametersNameForThisQuery } ;
24
+ }
25
+
26
+ #region IParameterSpecification Members
27
+
28
+ public void Bind ( IDbCommand command , IList < Parameter > sqlQueryParametersList , QueryParameters queryParameters , ISessionImplementor session )
29
+ {
30
+ Bind ( command , sqlQueryParametersList , 0 , sqlQueryParametersList , queryParameters , session ) ;
31
+ }
32
+
33
+ public void Bind ( IDbCommand command , IList < Parameter > multiSqlQueryParametersList , int singleSqlParametersOffset , IList < Parameter > sqlQueryParametersList , QueryParameters queryParameters , ISessionImplementor session )
34
+ {
35
+ // The QueryTakeParameterSpecification is unique so we can use multiSqlQueryParametersList
36
+ var effectiveParameterLocations = multiSqlQueryParametersList . GetEffectiveParameterLocations ( limitParametersNameForThisQuery ) . ToArray ( ) ;
37
+ if ( effectiveParameterLocations . Any ( ) )
38
+ {
39
+ // if the dialect does not support variable limits the parameter may was removed
40
+ int value = Loader . Loader . GetLimitUsingDialect ( queryParameters . RowSelection , session . Factory . Dialect ) ?? queryParameters . RowSelection . MaxRows ;
41
+ int position = effectiveParameterLocations . Single ( ) ;
42
+ type . NullSafeSet ( command , value , position , session ) ;
43
+ }
44
+ }
45
+
46
+ public IType ExpectedType
47
+ {
48
+ get { return type ; }
49
+ set { throw new InvalidOperationException ( ) ; }
50
+ }
51
+
52
+ public string RenderDisplayInfo ( )
53
+ {
54
+ return "query-take" ;
55
+ }
56
+
57
+ public IEnumerable < string > GetIdsForBackTrack ( IMapping sessionFactory )
58
+ {
59
+ return idTrack ;
60
+ }
61
+
62
+ #endregion
63
+
64
+ public override bool Equals ( object obj )
65
+ {
66
+ return Equals ( obj as QueryTakeParameterSpecification ) ;
67
+ }
68
+
69
+ public bool Equals ( QueryTakeParameterSpecification other )
70
+ {
71
+ if ( ReferenceEquals ( null , other ) )
72
+ {
73
+ return false ;
74
+ }
75
+ if ( ReferenceEquals ( this , other ) )
76
+ {
77
+ return true ;
78
+ }
79
+ return Equals ( other . limitParametersNameForThisQuery , limitParametersNameForThisQuery ) ;
80
+ }
81
+
82
+ public override int GetHashCode ( )
83
+ {
84
+ return limitParametersNameForThisQuery . GetHashCode ( ) ;
85
+ }
86
+ }
87
87
}
0 commit comments