<commit_before>// Copyright 2004-2005 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MonoRail.ActiveRecordSupport.Pagination
{
	using System;
	using System.Collections;

	using Castle.ActiveRecord;
	using Castle.ActiveRecord.Framework;

	using NHibernate;
	using NHibernate.Expression;

	/// <summary>
	/// A paginable criteria.
	/// Mimics the <see cref="ActiveRecordMediator.FindAll"/> interface.
	/// </summary>
	public class ARPaginableCriteria : IARPaginable
	{
		Type targetType;
		ICriterion[] criterions;
		Order[] orders;

		public ARPaginableCriteria(Type targetType, Order[] orders, params ICriterion[] criterions)
		{
			this.targetType = targetType;
			this.orders = orders;
			this.criterions = criterions;
		}

		public ARPaginableCriteria(Type targetType, params ICriterion[] criterions)
			: this(targetType, null, criterions) { }

		public ARPaginableCriteria(Type targetType, params Order[] orders)
			: this(targetType, orders, null) { }

		public IEnumerable GetPageItems(int pageSize, int currentPage)
		{
			ISessionFactoryHolder holder = ActiveRecordMediator.GetSessionFactoryHolder();
			using (ISession session = holder.CreateSession(targetType)) 
			{
				ICriteria c = session.CreateCriteria(targetType);
			
				if (criterions != null)
					foreach (ICriterion cc in criterions)
						c.Add(cc);
			
				if (orders != null)
					foreach (Order order in orders)
						c.AddOrder(order);

				c.SetFirstResult(pageSize * (currentPage-1));
				c.SetMaxResults(pageSize);

				// return GetResultsArray(targetType, c.List(), false);
				return c.List();
			}
		}
	}
}<commit_msg>ARPaginableCriteria was disposing the session got from SessionFactoryHolder.<commit_after>// Copyright 2004-2005 Castle Project - http://www.castleproject.org/
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// 
//     http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace Castle.MonoRail.ActiveRecordSupport.Pagination
{
	using System;
	using System.Collections;

	using Castle.ActiveRecord;
	using Castle.ActiveRecord.Framework;

	using NHibernate;
	using NHibernate.Expression;

	/// <summary>
	/// A paginable criteria.
	/// Mimics the <see cref="ActiveRecordMediator.FindAll"/> interface.
	/// </summary>
	public class ARPaginableCriteria : IARPaginable
	{
		Type targetType;
		ICriterion[] criterions;
		Order[] orders;

		public ARPaginableCriteria(Type targetType, Order[] orders, params ICriterion[] criterions)
		{
			this.targetType = targetType;
			this.orders = orders;
			this.criterions = criterions;
		}

		public ARPaginableCriteria(Type targetType, params ICriterion[] criterions)
			: this(targetType, null, criterions) { }

		public ARPaginableCriteria(Type targetType, params Order[] orders)
			: this(targetType, orders, null) { }

		public IEnumerable GetPageItems(int pageSize, int currentPage)
		{
			ISessionFactoryHolder holder = ActiveRecordMediator.GetSessionFactoryHolder();
			ISession session = holder.CreateSession(targetType);
			try
			{
				ICriteria c = session.CreateCriteria(targetType);
			
				if (criterions != null)
					foreach (ICriterion cc in criterions)
						c.Add(cc);
			
				if (orders != null)
					foreach (Order order in orders)
						c.AddOrder(order);

				c.SetFirstResult(pageSize * (currentPage-1));
				c.SetMaxResults(pageSize);

				// return GetResultsArray(targetType, c.List(), false);
				return c.List();
			}
			finally
			{
				holder.ReleaseSession(session);
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.10167224080267559, 'fraction_numerical': 0.005797101449275362, 'mean_word_length': 3.737064413938754, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5398818', 'n_tokens_mistral': 1489, 'n_tokens_neox': 1269, 'n_words': 395}