public void Process(FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree, string sourceAlias, bool userInnerJoin = false) { var join = tree.TreeBuilder.Dot( tree.TreeBuilder.Ident(sourceAlias), tree.TreeBuilder.Ident(resultOperator.RelationMember.Name)); string alias = queryModelVisitor.Model.GetNewName("_"); if (userInnerJoin) { tree.AddFromClause(tree.TreeBuilder.FetchJoin(join, tree.TreeBuilder.Alias(alias))); } else { tree.AddFromClause(tree.TreeBuilder.LeftFetchJoin(join, tree.TreeBuilder.Alias(alias))); } tree.AddDistinctRootOperator(); foreach (var innerFetch in resultOperator.InnerFetchRequests) { if (innerFetch is InnerFetchOneRequest || innerFetch is InnerFetchManyRequest) { Process(innerFetch, queryModelVisitor, tree, alias, true); } else { Process(innerFetch, queryModelVisitor, tree, alias); } } }
public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel) { _hqlTree.AddFromClause(_hqlTree.TreeBuilder.Range( HqlGeneratorExpressionTreeVisitor.Visit(fromClause.FromExpression, VisitorParameters), _hqlTree.TreeBuilder.Alias(fromClause.ItemName))); base.VisitMainFromClause(fromClause, queryModel); }
public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel) { _hqlTree.AddFromClause(_hqlTree.TreeBuilder.Range( HqlGeneratorExpressionTreeVisitor.Visit(fromClause.FromExpression, VisitorParameters), _hqlTree.TreeBuilder.Alias(fromClause.ItemName))); // apply any result operators that were rewritten if (RewrittenOperatorResult != null) { CurrentEvaluationType = RewrittenOperatorResult.EvaluationType; foreach (ResultOperatorBase rewrittenOperator in RewrittenOperatorResult.RewrittenOperators) { this.VisitResultOperator(rewrittenOperator, queryModel, -1); } } base.VisitMainFromClause(fromClause, queryModel); }
public override void VisitMainFromClause(MainFromClause fromClause, QueryModel queryModel) { var querySourceName = VisitorParameters.QuerySourceNamer.GetName(fromClause); var hqlExpressionTree = HqlGeneratorExpressionVisitor.Visit(fromClause.FromExpression, VisitorParameters); _hqlTree.AddFromClause(_hqlTree.TreeBuilder.Range(hqlExpressionTree, _hqlTree.TreeBuilder.Alias(querySourceName))); // apply any result operators that were rewritten if (RewrittenOperatorResult != null) { CurrentEvaluationType = RewrittenOperatorResult.EvaluationType; foreach (ResultOperatorBase rewrittenOperator in RewrittenOperatorResult.RewrittenOperators) { VisitResultOperator(rewrittenOperator, queryModel, -1); } } base.VisitMainFromClause(fromClause, queryModel); }
private void Process(FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree, HqlDot memberPath, IType propType) { if (resultOperator is FetchOneRequest) { if (propType == null) { var metadata = queryModelVisitor.VisitorParameters.SessionFactory .GetClassMetadata(resultOperator.RelationMember.ReflectedType); propType = metadata?.GetPropertyType(resultOperator.RelationMember.Name); } if (propType != null && !propType.IsAssociationType) { tree.AddFromLastChildClause(tree.TreeBuilder.Fetch()); tree.AddFromLastChildClause(memberPath); ComponentType componentType = null; foreach (var innerFetch in resultOperator.InnerFetchRequests) { if (componentType == null) { componentType = propType as ComponentType; if (componentType == null) { throw new InvalidOperationException( $"Property {innerFetch.RelationMember.Name} cannot be fetched from a non component type property {resultOperator.RelationMember.Name}."); } } var subTypeIndex = componentType.GetPropertyIndex(innerFetch.RelationMember.Name); memberPath = tree.TreeBuilder.Dot( memberPath, tree.TreeBuilder.Ident(innerFetch.RelationMember.Name)); Process(innerFetch, queryModelVisitor, tree, memberPath, componentType.Subtypes[subTypeIndex]); } return; } } var alias = queryModelVisitor.Model.GetNewName("_"); tree.AddFromClause(tree.TreeBuilder.LeftFetchJoin(memberPath, tree.TreeBuilder.Alias(alias))); tree.AddDistinctRootOperator(); foreach (var innerFetch in resultOperator.InnerFetchRequests) { Process(innerFetch, queryModelVisitor, tree, alias); } }
public void Process(FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree, string sourceAlias) { var join = tree.TreeBuilder.Dot( tree.TreeBuilder.Ident(sourceAlias), tree.TreeBuilder.Ident(resultOperator.RelationMember.Name)); string alias = queryModelVisitor.Model.GetNewName("_"); tree.AddFromClause(tree.TreeBuilder.LeftFetchJoin(join, tree.TreeBuilder.Alias(alias))); tree.AddDistinctRootOperator(); foreach (var innerFetch in resultOperator.InnerFetchRequests) { Process(innerFetch, queryModelVisitor, tree, alias); } }
private void Process( FetchRequestBase resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree, HqlDot memberPath, HqlTreeNode currentNode, IType propType) { string alias = null; if (resultOperator is FetchOneRequest) { if (propType == null) { var metadata = queryModelVisitor.VisitorParameters.SessionFactory .GetClassMetadata(resultOperator.RelationMember.ReflectedType); propType = metadata?.GetPropertyType(resultOperator.RelationMember.Name); } if (propType != null && !propType.IsAssociationType) { if (currentNode == null) { currentNode = tree.GetFromRangeClause() ?? throw new InvalidOperationException($"Property {resultOperator.RelationMember.Name} cannot be fetched for this type of query."); } currentNode.AddChild(tree.TreeBuilder.Fetch()); currentNode.AddChild(memberPath); ComponentType componentType = null; foreach (var innerFetch in resultOperator.InnerFetchRequests) { if (componentType == null) { componentType = propType as ComponentType; if (componentType == null) { throw new InvalidOperationException( $"Property {innerFetch.RelationMember.Name} cannot be fetched from a non component type property {resultOperator.RelationMember.Name}."); } } var subTypeIndex = componentType.GetPropertyIndex(innerFetch.RelationMember.Name); memberPath = tree.TreeBuilder.Dot( memberPath, tree.TreeBuilder.Ident(innerFetch.RelationMember.Name)); Process(innerFetch, queryModelVisitor, tree, memberPath, currentNode, componentType.Subtypes[subTypeIndex]); } return; } var relatedJoin = queryModelVisitor.RelatedJoinFetchRequests.FirstOrDefault(o => o.Value == resultOperator).Key; if (relatedJoin != null) { alias = queryModelVisitor.VisitorParameters.QuerySourceNamer.GetName(relatedJoin); } } if (alias == null) { alias = queryModelVisitor.Model.GetNewName("_"); currentNode = tree.TreeBuilder.LeftFetchJoin(memberPath, tree.TreeBuilder.Alias(alias)); tree.AddFromClause(currentNode); } tree.AddDistinctRootOperator(); foreach (var innerFetch in resultOperator.InnerFetchRequests) { Process(innerFetch, queryModelVisitor, tree, currentNode, alias); } }