Пример #1
0
        public FromElement CreateEntityJoin(
            string entityClass,
            string tableAlias,
            JoinSequence joinSequence,
            bool fetchFlag,
            bool inFrom,
            EntityType type)
        {
            FromElement elem = CreateJoin(entityClass, tableAlias, joinSequence, type, false);

            elem.Fetch = fetchFlag;

            //if (numberOfTables > 1 && _implied && !elem.UseFromFragment)
            // NH Different behavior: numberOfTables was removed because an
            // implicit join is an implicit join even if it not come from a
            // multi-table entity
            if (_implied && !elem.UseFromFragment)
            {
                if (Log.IsDebugEnabled)
                {
                    Log.Debug("createEntityJoin() : Implied entity join");
                }
                elem.UseFromFragment = true;
            }

            // If this is an implied join in a FROM clause, then use ANSI-style joining, and set the
            // flag on the FromElement that indicates that it was implied in the FROM clause itself.
            if (_implied && inFrom)
            {
                joinSequence.SetUseThetaStyle(false);
                elem.UseFromFragment = true;
                elem.SetImpliedInFromClause(true);
            }
            if (elem.Walker.IsSubQuery)
            {
                // two conditions where we need to transform this to a theta-join syntax:
                //      1) 'elem' is the "root from-element" in correlated subqueries
                //      2) The DotNode.useThetaStyleImplicitJoins has been set to true
                //          and 'elem' represents an implicit join
                if (elem.FromClause != elem.Origin.FromClause || DotNode.UseThetaStyleImplicitJoins)
                {
                    // the "root from-element" in correlated subqueries do need this piece
                    elem.Type = HqlSqlWalker.FROM_FRAGMENT;
                    joinSequence.SetUseThetaStyle(true);
                    elem.UseFromFragment = false;
                }
            }

            return(elem);
        }
		/// <summary>
		/// Generate a join sequence representing the given association type.
		/// </summary>
		/// <param name="implicitJoin">Should implicit joins (theta-style) or explicit joins (ANSI-style) be rendered</param>
		/// <param name="associationType">The type representing the thing to be joined into.</param>
		/// <param name="tableAlias">The table alias to use in qualifing the join conditions</param>
		/// <param name="joinType">The type of join to render (inner, outer, etc)</param>
		/// <param name="columns">The columns making up the condition of the join.</param>
		/// <returns>The generated join sequence.</returns>
		public JoinSequence CreateJoinSequence(bool implicitJoin, IAssociationType associationType, string tableAlias, JoinType joinType, string[] columns) 
		{
			JoinSequence joinSequence = CreateJoinSequence();
			joinSequence.SetUseThetaStyle(implicitJoin);	// Implicit joins use theta style (WHERE pk = fk), explicit joins use JOIN (after from)
			joinSequence.AddJoin( associationType, tableAlias, joinType, columns );
			return joinSequence;
		}
		/// <summary>
		/// Create a join sequence rooted at the given collection.
		/// </summary>
		/// <param name="collPersister">The persister for the collection at which the join should be rooted.</param>
		/// <param name="collectionName">The alias to use for qualifying column references.</param>
		/// <returns>The generated join sequence.</returns>
		public JoinSequence CreateCollectionJoinSequence(IQueryableCollection collPersister, String collectionName)
		{
			JoinSequence joinSequence = CreateJoinSequence();
			joinSequence.SetRoot(collPersister, collectionName);
			joinSequence.SetUseThetaStyle(true);		// TODO: figure out how this should be set.

			///////////////////////////////////////////////////////////////////////////////
			// This was the reason for failures regarding INDEX_OP and subclass joins on
			// theta-join dialects; not sure what behaviour we were trying to emulate ;)
			//		joinSequence = joinSequence.getFromPart();	// Emulate the old addFromOnly behavior.
			return joinSequence;
		}