Example #1
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
                    );
            }
        }
Example #2
0
        /// <summary>
        /// For a component, add to a list of associations to be fetched by outerjoin
        /// </summary>
        /// <param name="componentType"></param>
        /// <param name="propertyNumber"></param>
        /// <param name="cols"></param>
        /// <param name="persister"></param>
        /// <param name="alias"></param>
        /// <param name="associations"></param>
        /// <param name="visitedPersisters"></param>
        /// <param name="aliasedCols"></param>
        /// <param name="path"></param>
        /// <param name="currentDepth"></param>
        /// <param name="factory"></param>
        private void WalkComponentTree(
            IAbstractComponentType componentType,
            int propertyNumber,
            string[] cols,
            string[] aliasedCols,
            IOuterJoinLoadable persister,
            string alias,
            IList associations,
            ISet visitedPersisters,
            string path,
            int currentDepth,
            ISessionFactoryImplementor factory)
        {
            IType[]  types         = componentType.Subtypes;
            string[] propertyNames = componentType.PropertyNames;
            int      begin         = 0;

            for (int i = 0; i < types.Length; i++)
            {
                int      length       = types[i].GetColumnSpan(factory);
                string[] range        = ArrayHelper.Slice(cols, begin, length);
                string[] aliasedRange = ArrayHelper.Slice(aliasedCols, begin, length);

                if (types[i].IsAssociationType)
                {
                    IAssociationType associationType = ( IAssociationType )types[i];

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

                    string[] aliasedFkColumns = GetAliasedForeignKeyColumns(persister, alias, associationType, aliasedRange);
                    string[] fkColumns        = GetForeignKeyColumns(persister, associationType, range);
                    string   subpath          = SubPath(path, propertyNames[i]);
                    JoinType joinType         = GetJoinType(
                        associationType,
                        componentType.EnableJoinedFetch(i),
                        subpath,
                        persister.GetSubclassPropertyTableName(propertyNumber),
                        fkColumns,
                        factory
                        );

                    if (joinType != JoinType.None)
                    {
                        WalkAssociationTree(
                            associationType,
                            aliasedFkColumns,
                            persister,
                            alias,
                            associations,
                            visitedPersisters,
                            subpath,
                            currentDepth,
                            joinType,
                            factory
                            );
                    }
                }
                else if (types[i].IsComponentType)
                {
                    string subpath = SubPath(path, propertyNames[i]);

                    WalkComponentTree(
                        ( IAbstractComponentType )types[i],
                        propertyNumber,
                        range,
                        aliasedRange,
                        persister,
                        alias,
                        associations,
                        visitedPersisters,
                        subpath,
                        currentDepth,
                        factory
                        );
                }
                begin += length;
            }
        }
		/// <summary>
		/// For a component, add to a list of associations to be fetched by outerjoin
		/// </summary>
		/// <param name="componentType"></param>
		/// <param name="propertyNumber"></param>
		/// <param name="cols"></param>
		/// <param name="persister"></param>
		/// <param name="alias"></param>
		/// <param name="associations"></param>
		/// <param name="visitedPersisters"></param>
		/// <param name="aliasedCols"></param>
		/// <param name="path"></param>
		/// <param name="currentDepth"></param>
		/// <param name="factory"></param>
		private void WalkComponentTree(
			IAbstractComponentType componentType,
			int propertyNumber,
			string[ ] cols,
			string[ ] aliasedCols,
			IOuterJoinLoadable persister,
			string alias,
			IList associations,
			ISet visitedPersisters,
			string path,
			int currentDepth,
			ISessionFactoryImplementor factory )
		{
			IType[ ] types = componentType.Subtypes;
			string[ ] propertyNames = componentType.PropertyNames;
			int begin = 0;
			for( int i = 0; i < types.Length; i++ )
			{
				int length = types[ i ].GetColumnSpan( factory );
				string[ ] range = ArrayHelper.Slice( cols, begin, length );
				string[ ] aliasedRange = ArrayHelper.Slice( aliasedCols, begin, length );

				if( types[ i ].IsAssociationType )
				{
					IAssociationType associationType = ( IAssociationType ) types[ i ];

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

					string[] aliasedFkColumns = GetAliasedForeignKeyColumns( persister, alias, associationType, aliasedRange );
					string[] fkColumns = GetForeignKeyColumns( persister, associationType, range );
					string subpath = SubPath( path, propertyNames[ i ] );
					JoinType joinType = GetJoinType(
						associationType,
						componentType.EnableJoinedFetch( i ),
						subpath,
						persister.GetSubclassPropertyTableName( propertyNumber ),
						fkColumns,
						factory
						);

					if ( joinType != JoinType.None )
					{
						WalkAssociationTree(
							associationType,
							aliasedFkColumns,
							persister,
							alias,
							associations,
							visitedPersisters,
							subpath,
							currentDepth,
							joinType,
							factory
							);
					}
				}
				else if( types[ i ].IsComponentType )
				{
					string subpath = SubPath( path, propertyNames[ i ] );

					WalkComponentTree( 
						( IAbstractComponentType ) types[ i ], 
						propertyNumber, 
						range, 
						aliasedRange, 
						persister, 
						alias, 
						associations, 
						visitedPersisters, 
						subpath, 
						currentDepth,
						factory
						);
				}
				begin += length;
			}
		}
Example #4
0
 public static string GetLHSTableName(
     IAssociationType type,
     int property,
     IOuterJoinLoadable lhsPersister
     )
 {
     if (type.UseLHSPrimaryKey)
     {
         return lhsPersister.TableName;
     }
     else
     {
         string propertyName = type.LHSPropertyName;
         if (propertyName == null)
         {
             //if there is no property-ref, assume the join
             //is to the subclass table (ie. the table of the
             //subclass that the association belongs to)
             return lhsPersister.GetSubclassPropertyTableName(property);
         }
         else
         {
             //handle a property-ref
             string propertyRefTable = lhsPersister.GetPropertyTableName(propertyName);
             if (propertyRefTable == null)
             {
                 //it is possible that the tree-walking in OuterJoinLoader can get to
                 //an association defined by a subclass, in which case the property-ref
                 //might refer to a property defined on a subclass of the current class
                 //in this case, the table name is not known - this temporary solution
                 //assumes that the property-ref refers to a property of the subclass
                 //table that the association belongs to (a reasonable guess)
                 //TODO: fix this, add: IOuterJoinLoadable.getSubclassPropertyTableName(string propertyName)
                 propertyRefTable = lhsPersister.GetSubclassPropertyTableName(property);
             }
             return propertyRefTable;
         }
     }
 }
		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
					);
			}
		}