<commit_before>using System;
using System.Collections;
using NHibernate.Collection;
using NHibernate.Engine;
using NHibernate.Persister;
using NHibernate.SqlCommand;
using NHibernate.Type;
using NHibernate.Util;

namespace NHibernate.Loader
{
	/// <summary></summary>
	public abstract class AbstractEntityLoader : OuterJoinLoader
	{
		private readonly IOuterJoinLoadable persister;
		private ICollectionPersister collectionPersister;
		private int collectionOwner;
		private string alias;
		private string[] aliases;

		/// <summary>
		/// 
		/// </summary>
		/// <param name="persister"></param>
		/// <param name="factory"></param>
		public AbstractEntityLoader( IOuterJoinLoadable persister, ISessionFactoryImplementor factory ) : base( factory.Dialect )
		{
			this.persister = persister;
			alias = GenerateRootAlias( persister.ClassName );
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="associations"></param>
		/// <param name="condition"></param>
		/// <param name="factory"></param>
		protected void RenderStatement( IList associations, SqlString condition, ISessionFactoryImplementor factory )
		{
			InitStatementString( associations, condition, string.Empty, factory );
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="spaces"></param>
		protected void AddAllToPropertySpaces( object[] spaces )
		{
			for ( int i = 0; i < spaces.Length; i++ )
			{
				AddToPropertySpaces( spaces[ i ] );
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="space"></param>
		protected virtual void AddToPropertySpaces( object space )
		{
			throw new NotSupportedException( "only criteria queries need to autoflush" );
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="associations"></param>
		protected void InitClassPersisters( IList associations )
		{
			int joins = CountClassPersisters( associations );

			collectionOwner = -1;	// if no collection found
			classPersisters = new ILoadable[ joins + 1 ];
			SetOwners( new int[ joins + 1 ] );
			aliases = new string[ joins + 1 ];
			LockModeArray = CreateLockModeArray( joins + 1, LockMode.None );
			int i = 0;
			foreach( OuterJoinableAssociation oj in associations )
			{
				object subpersister = oj.Joinable;
				if ( subpersister is ILoadable )
				{
					classPersisters[ i ] = (ILoadable) subpersister;
					Owners[ i ] = ToOwner( oj, joins, oj.IsOneToOne );
					aliases[ i ] = oj.Subalias;
					if ( oj.JoinType == JoinType.InnerJoin )
					{
						AddAllToPropertySpaces( classPersisters[ i ].PropertySpaces );
					}
					i++;
				}
				else 
				{
					IQueryableCollection collPersister = (IQueryableCollection) subpersister;
					// TODO: ?? suppress initialization of collections with a where condition
					if ( oj.JoinType == JoinType.LeftOuterJoin )
					{
						collectionPersister = collPersister;
						collectionOwner = ToOwner( oj, joins, true );
					}
					else
					{
						AddToPropertySpaces( collPersister.CollectionSpace ) ;
					}

					if ( collPersister.IsOneToMany )
					{
						classPersisters[ i ] = (ILoadable) collPersister.ElementPersister;
						aliases[ i ] = oj.Subalias;
						i++;
					}
				}
			}
			classPersisters[ joins ] = persister;
			Owners[ joins ] = -1;
			aliases[ joins ] = alias;

			if ( ArrayHelper.IsAllNegative( Owners ) )
			{
				SetOwners( null );
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="associations"></param>
		/// <param name="condition"></param>
		/// <param name="orderBy"></param>
		/// <param name="factory"></param>
		protected void InitStatementString( IList associations, SqlString condition, string orderBy, ISessionFactoryImplementor factory )
		{
			int joins = CountClassPersisters( associations );

			Suffixes = GenerateSuffixes( joins + 1 );

			JoinFragment ojf = MergeOuterJoins( associations );

			SqlString = new SqlSelectBuilder( factory )
				.SetSelectClause( 
					persister.SelectFragment( alias, Suffixes[ joins ] ) +
					SelectString( associations, factory )
				)
				.SetFromClause( 
					persister.FromTableFragment( alias ).Append( 
					persister.FromJoinFragment( alias, true, true ) )
				)
				.AddWhereClause( condition )
				.SetOuterJoins( 
					ojf.ToFromFragmentString,
					ojf.ToWhereFragmentString
				)
				.AddWhereClause( GetWhereFragment() )
				.SetOrderByClause( orderBy )
				.ToSqlString();<commit_msg>Modified code a little bit to make it easier to set breakpoints.<commit_after>using System;
using System.Collections;
using NHibernate.Collection;
using NHibernate.Engine;
using NHibernate.Persister;
using NHibernate.SqlCommand;
using NHibernate.Type;
using NHibernate.Util;

namespace NHibernate.Loader
{
	/// <summary></summary>
	public abstract class AbstractEntityLoader : OuterJoinLoader
	{
		private readonly IOuterJoinLoadable persister;
		private ICollectionPersister collectionPersister;
		private int collectionOwner;
		private string alias;
		private string[] aliases;

		/// <summary>
		/// 
		/// </summary>
		/// <param name="persister"></param>
		/// <param name="factory"></param>
		public AbstractEntityLoader( IOuterJoinLoadable persister, ISessionFactoryImplementor factory ) : base( factory.Dialect )
		{
			this.persister = persister;
			alias = GenerateRootAlias( persister.ClassName );
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="associations"></param>
		/// <param name="condition"></param>
		/// <param name="factory"></param>
		protected void RenderStatement( IList associations, SqlString condition, ISessionFactoryImplementor factory )
		{
			InitStatementString( associations, condition, string.Empty, factory );
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="spaces"></param>
		protected void AddAllToPropertySpaces( object[] spaces )
		{
			for ( int i = 0; i < spaces.Length; i++ )
			{
				AddToPropertySpaces( spaces[ i ] );
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="space"></param>
		protected virtual void AddToPropertySpaces( object space )
		{
			throw new NotSupportedException( "only criteria queries need to autoflush" );
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="associations"></param>
		protected void InitClassPersisters( IList associations )
		{
			int joins = CountClassPersisters( associations );

			collectionOwner = -1;	// if no collection found
			classPersisters = new ILoadable[ joins + 1 ];
			SetOwners( new int[ joins + 1 ] );
			aliases = new string[ joins + 1 ];
			LockModeArray = CreateLockModeArray( joins + 1, LockMode.None );
			int i = 0;
			foreach( OuterJoinableAssociation oj in associations )
			{
				object subpersister = oj.Joinable;
				if ( subpersister is ILoadable )
				{
					classPersisters[ i ] = (ILoadable) subpersister;
					Owners[ i ] = ToOwner( oj, joins, oj.IsOneToOne );
					aliases[ i ] = oj.Subalias;
					if ( oj.JoinType == JoinType.InnerJoin )
					{
						AddAllToPropertySpaces( classPersisters[ i ].PropertySpaces );
					}
					i++;
				}
				else 
				{
					IQueryableCollection collPersister = (IQueryableCollection) subpersister;
					// TODO: ?? suppress initialization of collections with a where condition
					if ( oj.JoinType == JoinType.LeftOuterJoin )
					{
						collectionPersister = collPersister;
						collectionOwner = ToOwner( oj, joins, true );
					}
					else
					{
						AddToPropertySpaces( collPersister.CollectionSpace ) ;
					}

					if ( collPersister.IsOneToMany )
					{
						classPersisters[ i ] = (ILoadable) collPersister.ElementPersister;
						aliases[ i ] = oj.Subalias;
						i++;
					}
				}
			}
			classPersisters[ joins ] = persister;
			Owners[ joins ] = -1;
			aliases[ joins ] = alias;

			if ( ArrayHelper.IsAllNegative( Owners ) )
			{
				SetOwners( null );
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="associations"></param>
		/// <param name="condition"></param>
		/// <param name="orderBy"></param>
		/// <param name="factory"></param>
		protected void InitStatementString( IList associations, SqlString condition, string orderBy, ISessionFactoryImplementor factory )
		{
			int joins = CountClassPersisters( associations );

			Suffixes = GenerateSuffixes( joins + 1 );

			JoinFragment ojf = MergeOuterJoins( associations );

			SqlSelectBuilder builder = new SqlSelectBuilder( factory );
			builder.SetSelectClause( 
					persister.SelectFragment( alias, Suffixes[ joins ] ) +
					SelectString( associations, factory )
				);
			builder.SetFromClause( 
					persister.FromTableFragment( alias ).Append( 
					persister.FromJoinFragment( alias, true, true ) )
				);
			builder.AddWhereClause( condition );
			builder.SetOuterJoins( 
					ojf.ToFromFragmentString,
					ojf.ToWhereFragmentString
				);
			builder.AddWhereClause( GetWhereFragment() );
			builder.SetOrderByClause( orderBy );
				
			this.SqlString = builder.ToSqlString();
{'fraction_non_alphanumeric': 0.1242530161235765, 'fraction_numerical': 0.0020295410982072385, 'mean_word_length': 3.0894421392346705, 'pattern_counts': {'":': 0, '<': 81, '<?xml version=': 0, '>': 79, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '925157', 'n_tokens_mistral': 3359, 'n_tokens_neox': 2663, 'n_words': 628}