Example #1
0
 /// <summary>
 /// Get the aliased columns of the owning entity which are to 
 /// be used in the join
 /// </summary>
 public static string[] GetAliasedLHSColumnNames(
     IAssociationType type,
     string alias,
     int property,
     int begin,
     IOuterJoinLoadable lhsPersister,
     IMapping mapping
     )
 {
     if (type.UseLHSPrimaryKey)
     {
         return StringHelper.Qualify(alias, lhsPersister.IdentifierColumnNames);
     }
     else
     {
         string propertyName = type.LHSPropertyName;
         if (propertyName == null)
         {
             return ArrayHelper.Slice(
                 lhsPersister.ToColumns(alias, property),
                 begin,
                 type.GetColumnSpan(mapping)
                 );
         }
         else
         {
             return ((IPropertyMapping) lhsPersister).ToColumns(alias, propertyName); //bad cast
         }
     }
 }
Example #2
0
        /// <summary>
        /// For an entity class, add to a list of associations to be fetched by outerjoin
        /// </summary>
        /// <param name="persister"></param>
        /// <param name="alias"></param>
        /// <param name="associations"></param>
        /// <param name="visitedPersisters"></param>
        /// <param name="path"></param>
        /// <param name="currentDepth"></param>
        /// <param name="factory"></param>
        private void WalkClassTree(
            IOuterJoinLoadable persister,
            string alias,
            IList associations,
            ISet visitedPersisters,
            string path,
            int currentDepth,
            ISessionFactoryImplementor factory)
        {
            int n = persister.CountSubclassProperties();

            for (int i = 0; i < n; i++)
            {
                IType type = persister.GetSubclassPropertyType(i);
                if (type.IsAssociationType)
                {
                    WalkAssociationTree(
                        ( IAssociationType )type,
                        persister,
                        i,
                        alias,
                        associations,
                        visitedPersisters,
                        path,
                        currentDepth,
                        factory
                        );
                }
                else if (type.IsComponentType)
                {
                    WalkComponentTree(
                        ( IAbstractComponentType )type,
                        i,
                        persister.GetSubclassPropertyColumnNames(i),
                        persister.ToColumns(alias, i),
                        persister,
                        alias,
                        associations,
                        visitedPersisters,
                        SubPath(path, persister.GetSubclassPropertyName(i)),
                        currentDepth,
                        factory
                        );
                }
            }
        }
Example #3
0
        private void WalkAssociationTree(
            IAssociationType associationType,
            IOuterJoinLoadable persister,
            int propertyNumber,
            string alias,
            IList associations,
            ISet visitedPersisters,
            string path,
            int currentDepth,
            ISessionFactoryImplementor factory)
        {
            string[] aliasedForeignKeyColumns = GetAliasedForeignKeyColumns(persister, alias, associationType, persister.ToColumns(alias, propertyNumber));
            string[] foreignKeyColumns        = GetForeignKeyColumns(persister, associationType, persister.GetSubclassPropertyColumnNames(propertyNumber));

            if (IsJoinedFetchAlwaysDisabled(persister, associationType, propertyNumber))
            {
                return;
            }

            string   subpath  = SubPath(path, persister.GetSubclassPropertyName(propertyNumber));
            JoinType joinType = GetJoinType(
                associationType,
                persister.EnableJoinedFetch(propertyNumber),
                subpath,
                persister.GetSubclassPropertyTableName(propertyNumber),
                foreignKeyColumns,
                factory
                );

            if (joinType != JoinType.None)
            {
                WalkAssociationTree(
                    associationType,
                    aliasedForeignKeyColumns,
                    persister,
                    alias,
                    associations,
                    visitedPersisters,
                    subpath,
                    currentDepth,
                    joinType,
                    factory
                    );
            }
        }
		/// <summary>
		/// For an entity class, add to a list of associations to be fetched by outerjoin
		/// </summary>
		/// <param name="persister"></param>
		/// <param name="alias"></param>
		/// <param name="associations"></param>
		/// <param name="visitedPersisters"></param>
		/// <param name="path"></param>
		/// <param name="currentDepth"></param>
		/// <param name="factory"></param>
		private void WalkClassTree( 
			IOuterJoinLoadable persister, 
			string alias, 
			IList associations, 
			ISet visitedPersisters, 
			string path,
			int currentDepth,
			ISessionFactoryImplementor factory )
		{
			int n = persister.CountSubclassProperties();
			for( int i = 0; i < n; i++ )
			{
				IType type = persister.GetSubclassPropertyType( i );
				if( type.IsAssociationType )
				{
					WalkAssociationTree(
						( IAssociationType ) type,
						persister,
						i,
						alias,
						associations,
						visitedPersisters,
						path,
						currentDepth,
						factory
						);

				}
				else if( type.IsComponentType )
				{
					WalkComponentTree(
						( IAbstractComponentType ) type,
						i,
						persister.GetSubclassPropertyColumnNames( i ),
						persister.ToColumns( alias, i ),
						persister,
						alias,
						associations,
						visitedPersisters,
						SubPath( path, persister.GetSubclassPropertyName( i ) ),
						currentDepth,
						factory
						);
				}
			}
		}
		private void WalkAssociationTree(
			IAssociationType associationType,
			IOuterJoinLoadable persister,
			int propertyNumber,
			string alias,
			IList associations,
			ISet visitedPersisters,
			string path,
			int currentDepth,
			ISessionFactoryImplementor factory )
		{
			string[] aliasedForeignKeyColumns = GetAliasedForeignKeyColumns( persister, alias, associationType, persister.ToColumns( alias, propertyNumber ) );
			string[] foreignKeyColumns = GetForeignKeyColumns( persister, associationType, persister.GetSubclassPropertyColumnNames( propertyNumber ) );

			if ( IsJoinedFetchAlwaysDisabled( persister, associationType, propertyNumber ) )
			{
				return;
			}
			
			string subpath = SubPath( path, persister.GetSubclassPropertyName( propertyNumber ) );
			JoinType joinType = GetJoinType(
				associationType,
				persister.EnableJoinedFetch( propertyNumber ),
				subpath,
				persister.GetSubclassPropertyTableName( propertyNumber ),
				foreignKeyColumns,
				factory
				);

			if ( joinType != JoinType.None )
			{
				WalkAssociationTree( 
					associationType, 
					aliasedForeignKeyColumns, 
					persister, 
					alias, 
					associations, 
					visitedPersisters, 
					subpath, 
					currentDepth,
					joinType,
					factory
					);
			}
		}