Updates Castle to the latest NHibernate Trunk libs. This required namespace changes...
[castle.git] / ActiveRecord / Castle.ActiveRecord / Framework / Queries / ActiveRecordCriteriaQuery.cs
blobad53befdd99552a9876586408dde8c9102f5e843
1 // Copyright 2004-2008 Castle Project - http://www.castleproject.org/
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
15 namespace Castle.ActiveRecord.Queries
17 using System;
19 using NHibernate;
20 using NHibernate.Criterion;
22 /// <summary>
23 /// Criteria Query
24 /// Note: This query can not be included in a MultiQuery.
25 /// the problem is that NHibernate does not have a real CriteriaQuery class
26 /// </summary>
27 public class ActiveRecordCriteriaQuery : HqlBasedQuery
29 // constructors will set EITHER criterias OR detachedCriteria
30 private readonly ICriterion[] criterias;
31 private readonly DetachedCriteria detachedCriteria;
33 /// <summary>
34 /// Initializes a new instance of the <see cref="ActiveRecordCriteriaQuery"/> class.
35 /// </summary>
36 /// <param name="targetType">The target type.</param>
37 /// <param name="criterias">Criteria applied to the query</param>
38 public ActiveRecordCriteriaQuery(Type targetType, ICriterion[] criterias)
39 : base(targetType, string.Empty, null)
41 this.criterias = criterias;
44 /// <summary>
45 /// Initializes a new instance of the <see cref="ActiveRecordCriteriaQuery"/> class.
46 /// </summary>
47 /// <param name="targetType">The target type.</param>
48 /// <param name="detachedCriteria">Criteria applied to the query</param>
49 public ActiveRecordCriteriaQuery(Type targetType, DetachedCriteria detachedCriteria)
50 : base(targetType, string.Empty, null)
52 this.detachedCriteria = detachedCriteria;
55 /// <summary>
56 /// Executes the query.
57 /// </summary>
58 /// <param name="session">The <c>NHibernate</c>'s <see cref="ISession"/></param>
59 /// <returns><c>ArrayList</c> as an <c>object</c></returns>
60 protected override object InternalExecute(ISession session)
62 if (detachedCriteria != null)
64 ICriteria criteria = detachedCriteria.GetExecutableCriteria(session);
66 return criteria.List();
68 else if (criterias != null)
70 ICriteria criteria = session.CreateCriteria(RootType);
72 CriteriaHelper.AddCriterionToCriteria(criteria, criterias);
74 return criteria.List();
76 else
78 return base.CreateQuery(session).List();