public void ProcessJoins(IRestrictableStatement query) { FromClause fromClause = query.FromClause; var supportRootAlias = !(query is DeleteStatement || query is UpdateStatement); IList <FromElement> fromElements; if (DotNode.UseThetaStyleImplicitJoins) { // for regression testing against output from the old parser... // found it easiest to simply reorder the FromElements here into ascending order // in terms of injecting them into the resulting sql ast in orders relative to those // expected by the old parser; this is definitely another of those "only needed // for regression purposes". The SyntheticAndFactory, then, simply injects them as it // encounters them. fromElements = new List <FromElement>(); var t = fromClause.GetFromElementsTyped(); for (int i = t.Count - 1; i >= 0; i--) { fromElements.Add(t[i]); } } else { fromElements = fromClause.GetFromElementsTyped(); } // Iterate through the alias,JoinSequence pairs and generate SQL token nodes. foreach (FromElement fromElement in fromElements) { JoinSequence join = fromElement.JoinSequence; join.SetSelector(new JoinSequenceSelector(_walker, fromClause, fromElement)); // the delete and update statements created here will never be executed when IsMultiTable is true, // only the where clause will be used by MultiTableUpdateExecutor/MultiTableDeleteExecutor. In that case // we have to use the alias from the persister. AddJoinNodes(query, join, fromElement, supportRootAlias || fromElement.Queryable.IsMultiTable); } }
public void ProcessJoins(QueryNode query) { FromClause fromClause = query.FromClause; IList <IASTNode> fromElements; if (DotNode.UseThetaStyleImplicitJoins) { // for regression testing against output from the old parser... // found it easiest to simply reorder the FromElements here into ascending order // in terms of injecting them into the resulting sql ast in orders relative to those // expected by the old parser; this is definitely another of those "only needed // for regression purposes". The SyntheticAndFactory, then, simply injects them as it // encounters them. fromElements = new List <IASTNode>(); IList <IASTNode> t = fromClause.GetFromElements(); for (int i = t.Count - 1; i >= 0; i--) { fromElements.Add(t[i]); } } else { fromElements = fromClause.GetFromElements(); } // Iterate through the alias,JoinSequence pairs and generate SQL token nodes. foreach (FromElement fromElement in fromElements) { JoinSequence join = fromElement.JoinSequence; join.SetSelector(new JoinSequenceSelector(_walker, fromClause, fromElement)); AddJoinNodes(query, join, fromElement); } }
public void ProcessJoins(IRestrictableStatement query) { FromClause fromClause = query.FromClause; IList <FromElement> fromElements; if (DotNode.UseThetaStyleImplicitJoins) { // for regression testing against output from the old parser... // found it easiest to simply reorder the FromElements here into ascending order // in terms of injecting them into the resulting sql ast in orders relative to those // expected by the old parser; this is definitely another of those "only needed // for regression purposes". The SyntheticAndFactory, then, simply injects them as it // encounters them. fromElements = new List <FromElement>(); var t = fromClause.GetFromElementsTyped(); for (int i = t.Count - 1; i >= 0; i--) { fromElements.Add(t[i]); } } else { fromElements = fromClause.GetFromElementsTyped(); for (var index = fromElements.Count - 1; index >= 0; index--) { var fromElement = fromElements[index]; // We found an implied from element that is used in the WITH clause of another from element, so it need to become part of it's join sequence if (fromElement.IsImplied && fromElement.IsPartOfJoinSequence == null) { var origin = fromElement.Origin; while (origin.IsImplied) { origin = origin.Origin; origin.IsPartOfJoinSequence = false; } if (origin.WithClauseFragment?.Contains(fromElement.TableAlias + ".") == true) { List <FromElement> elements = new List <FromElement>(); while (fromElement.IsImplied) { elements.Add(fromElement); // This from element will be rendered as part of the origins join sequence fromElement.Text = string.Empty; fromElement.IsPartOfJoinSequence = true; fromElement = fromElement.Origin; } for (var i = elements.Count - 1; i >= 0; i--) { origin.JoinSequence.AddJoin(elements[i]); } } } } } // Iterate through the alias,JoinSequence pairs and generate SQL token nodes. foreach (FromElement fromElement in fromElements) { if (fromElement.IsPartOfJoinSequence == true) { continue; } JoinSequence join = fromElement.JoinSequence; join.SetSelector(new JoinSequenceSelector(_walker, fromClause, fromElement)); // the delete and update statements created here will never be executed when IsMultiTable is true, // only the where clause will be used by MultiTableUpdateExecutor/MultiTableDeleteExecutor. In that case // we have to use the alias from the persister. AddJoinNodes(query, join, fromElement); } }