Beispiel #1
0
        private QueryModelVisitor(VisitorParameters visitorParameters, bool root, QueryModel queryModel)
        {
            VisitorParameters = visitorParameters;
            Model             = queryModel;

            _hqlTree = new IntermediateHqlTree(root);
        }
Beispiel #2
0
 public SelectClauseVisitor(System.Type inputType, VisitorParameters parameters, IEnumerable <Expression> groupByKeys)
 {
     _inputParameter = Expression.Parameter(inputType, "input");
     _parameters     = parameters;
     _hqlVisitor     = new HqlGeneratorExpressionTreeVisitor(_parameters);
     _hqlNodes       = new HashSet <Expression>(groupByKeys);
 }
Beispiel #3
0
 private QueryModelVisitor(VisitorParameters visitorParameters, bool root, QueryModel queryModel,
                           NhLinqExpressionReturnType?rootReturnType)
 {
     VisitorParameters = visitorParameters;
     Model             = queryModel;
     _rootReturnType   = root ? rootReturnType : null;
     _hqlTree          = new IntermediateHqlTree(root);
 }
		public IASTNode Translate(ISessionFactoryImplementor sessionFactory)
		{
			var requiredHqlParameters = new List<NamedParameterDescriptor>();
			var querySourceNamer = new QuerySourceNamer();
			var queryModel = NhRelinqQueryParser.Parse(_expression);
			var visitorParameters = new VisitorParameters(sessionFactory, _constantToParameterMap, requiredHqlParameters, querySourceNamer);

			ExpressionToHqlTranslationResults = QueryModelVisitor.GenerateHqlQuery(queryModel, visitorParameters, true);

			ParameterDescriptors = requiredHqlParameters.AsReadOnly();
			
			return ExpressionToHqlTranslationResults.Statement.AstNode;
		}
		public static ExpressionToHqlTranslationResults GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, bool root)
		{
			NestedSelectRewriter.ReWrite(queryModel, parameters.SessionFactory);

			// Remove unnecessary body operators
			RemoveUnnecessaryBodyOperators.ReWrite(queryModel);

			// Merge aggregating result operators (distinct, count, sum etc) into the select clause
			MergeAggregatingResultsRewriter.ReWrite(queryModel);
			
			// Swap out non-aggregating group-bys
			NonAggregatingGroupByRewriter.ReWrite(queryModel);

			// Rewrite aggregate group-by statements
			AggregatingGroupByRewriter.ReWrite(queryModel);

			// Rewrite aggregating group-joins
			AggregatingGroupJoinRewriter.ReWrite(queryModel);

			// Rewrite non-aggregating group-joins
			NonAggregatingGroupJoinRewriter.ReWrite(queryModel);

			SubQueryFromClauseFlattener.ReWrite(queryModel);

			// Rewrite left-joins
			LeftJoinRewriter.ReWrite(queryModel);

			// Rewrite paging
			PagingRewriter.ReWrite(queryModel);

			// Flatten pointless subqueries
			QueryReferenceExpressionFlattener.ReWrite(queryModel);

			// Add joins for references
			AddJoinsReWriter.ReWrite(queryModel, parameters.SessionFactory);

			// Move OrderBy clauses to end
			MoveOrderByToEndRewriter.ReWrite(queryModel);

			// rewrite any operators that should be applied on the outer query
			// by flattening out the sub-queries that they are located in
			var result = ResultOperatorRewriter.Rewrite(queryModel);

			// Identify and name query sources
			QuerySourceIdentifier.Visit(parameters.QuerySourceNamer, queryModel);

			var visitor = new QueryModelVisitor(parameters, root, queryModel) { RewrittenOperatorResult = result };
			visitor.Visit();

			return visitor._hqlTree.GetTranslation();
		}
			public QueryModelVisitorBase CreateVisitor(VisitorParameters parameters)
			{
				return new CustomVisitor();
			}
Beispiel #7
0
 public static HqlTreeNode Visit(Expression expression, VisitorParameters parameters)
 {
     return(new HqlGeneratorExpressionVisitor(parameters).VisitExpression(expression));
 }
		public SelectClauseHqlNominator(VisitorParameters parameters)
		{
			_functionRegistry = parameters.SessionFactory.Settings.LinqToHqlGeneratorsRegistry;
		}
		public HqlGeneratorExpressionTreeVisitor(VisitorParameters parameters)
		{
			_functionRegistry = parameters.SessionFactory.Settings.LinqToHqlGeneratorsRegistry;
			_parameters = parameters;
		}
Beispiel #10
0
 public SelectClauseVisitor(System.Type inputType, VisitorParameters parameters)
 {
     _inputParameter = Expression.Parameter(inputType, "input");
     _parameters     = parameters;
     _hqlVisitor     = new HqlGeneratorExpressionTreeVisitor(_parameters);
 }
Beispiel #11
0
 public HqlGeneratorExpressionVisitor(VisitorParameters parameters)
 {
     _functionRegistry           = parameters.SessionFactory.Settings.LinqToHqlGeneratorsRegistry;
     _parameters                 = parameters;
     _nullableExpressionDetector = new NullableExpressionDetector(_parameters.SessionFactory, _functionRegistry);
 }
        public HqlGeneratorExpressionTreeVisitor(VisitorParameters parameters)
        {
            _parameters = parameters;
			_hqlTreeBuilder = new HqlTreeBuilder();
        }
		public EqualityHqlGenerator(VisitorParameters parameters)
		{
			_parameters = parameters;
			_hqlTreeBuilder = new HqlTreeBuilder();
		}
Beispiel #14
0
        public static ExpressionToHqlTranslationResults GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, bool root)
        {
            // Remove unnecessary body operators
            RemoveUnnecessaryBodyOperators.ReWrite(queryModel);

            // Merge aggregating result operators (distinct, count, sum etc) into the select clause
            MergeAggregatingResultsRewriter.ReWrite(queryModel);

            // Rewrite aggregate group-by statements
            AggregatingGroupByRewriter.ReWrite(queryModel);

            // Swap out non-aggregating group-bys
            NonAggregatingGroupByRewriter.ReWrite(queryModel);

            // Rewrite aggregating group-joins
            AggregatingGroupJoinRewriter.ReWrite(queryModel);

            // Rewrite non-aggregating group-joins
            NonAggregatingGroupJoinRewriter.ReWrite(queryModel);

            // Flatten pointless subqueries
            QueryReferenceExpressionFlattener.ReWrite(queryModel);

            // Add left joins for references
            AddLeftJoinsReWriter.ReWrite(queryModel, parameters.SessionFactory);

            var visitor = new QueryModelVisitor(parameters, root, queryModel);

            visitor.Visit();

            return(visitor._hqlTree.GetTranslation());
        }
 public SelectClauseVisitor(System.Type inputType, VisitorParameters parameters)
 {
     functionRegistry = parameters.SessionFactory.Settings.LinqToHqlGeneratorsRegistry;
     _inputParameter  = Expression.Parameter(inputType, "input");
     _parameters      = parameters;
 }
Beispiel #16
0
        public static HqlTreeNode Visit(Expression expression, VisitorParameters parameters)
        {
            var visitor = new HqlGeneratorExpressionTreeVisitor(parameters);

            return(visitor.VisitExpression(expression));
        }
		public SelectClauseVisitor(System.Type inputType, VisitorParameters parameters)
		{
			_inputParameter = Expression.Parameter(inputType, "input");
			_parameters = parameters;
			_hqlVisitor = new HqlGeneratorExpressionTreeVisitor(_parameters);
		}
Beispiel #18
0
 public HqlGeneratorExpressionTreeVisitor(VisitorParameters parameters)
 {
     functionRegistry = parameters.SessionFactory.Settings.LinqToHqlGeneratorsRegistry;
     _parameters      = parameters;
     _hqlTreeBuilder  = new HqlTreeBuilder();
 }
Beispiel #19
0
 public EqualityHqlGenerator(VisitorParameters parameters)
 {
     _parameters     = parameters;
     _hqlTreeBuilder = new HqlTreeBuilder();
 }
Beispiel #20
0
 public SelectClauseVisitor(System.Type inputType, VisitorParameters parameters)
 {
 	functionRegistry = parameters.SessionFactory.Settings.LinqToHqlGeneratorsRegistry;
 	_inputParameter = Expression.Parameter(inputType, "input");
     _parameters = parameters;
 }
		public static HqlTreeNode Visit(Expression expression, VisitorParameters parameters)
		{
			return new HqlGeneratorExpressionTreeVisitor(parameters).VisitExpression(expression);
		}
        public HqlGeneratorExpressionTreeVisitor(VisitorParameters parameters)
        {
					functionRegistry = parameters.SessionFactory.Settings.LinqToHqlGeneratorsRegistry;
        	_parameters = parameters;
			_hqlTreeBuilder = new HqlTreeBuilder();
        }
 public SelectClauseHqlNominator(VisitorParameters parameters)
 {
     _functionRegistry = parameters.SessionFactory.Settings.LinqToHqlGeneratorsRegistry;
 }
 public SelectClauseVisitor(System.Type inputType, VisitorParameters parameters)
 {
     _inputParameter = Expression.Parameter(inputType, "input");
     _parameters = parameters;
 }
        public static ExpressionToHqlTranslationResults GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, bool root,
                                                                         NhLinqExpressionReturnType?rootReturnType)
        {
            // Expand conditionals in subquery FROM clauses into multiple subqueries
            if (root)
            {
                // This expander works recursively
                SubQueryConditionalExpander.ReWrite(queryModel);
            }

            NestedSelectRewriter.ReWrite(queryModel, parameters.SessionFactory);

            // Remove unnecessary body operators
            RemoveUnnecessaryBodyOperators.ReWrite(queryModel);

            // Merge aggregating result operators (distinct, count, sum etc) into the select clause
            MergeAggregatingResultsRewriter.ReWrite(queryModel);

            // Swap out non-aggregating group-bys
            NonAggregatingGroupByRewriter.ReWrite(queryModel);

            // Rewrite aggregate group-by statements
            AggregatingGroupByRewriter.ReWrite(queryModel);

            // Rewrite aggregating group-joins
            AggregatingGroupJoinRewriter.ReWrite(queryModel);

            // Rewrite non-aggregating group-joins
            NonAggregatingGroupJoinRewriter.ReWrite(queryModel);

            SubQueryFromClauseFlattener.ReWrite(queryModel);

            // Rewrite left-joins
            LeftJoinRewriter.ReWrite(queryModel);

            // Rewrite paging
            PagingRewriter.ReWrite(queryModel);

            // Flatten pointless subqueries
            QueryReferenceExpressionFlattener.ReWrite(queryModel);

            // Flatten array index access to query references
            ArrayIndexExpressionFlattener.ReWrite(queryModel);

            // Add joins for references
            AddJoinsReWriter.ReWrite(queryModel, parameters);

            // Expand coalesced and conditional joins to their logical equivalents
            ConditionalQueryReferenceExpander.ReWrite(queryModel);

            // Move OrderBy clauses to end
            MoveOrderByToEndRewriter.ReWrite(queryModel);

            // Give a rewriter provided by the session factory a chance to
            // rewrite the query.
            var rewriterFactory = parameters.SessionFactory.Settings.QueryModelRewriterFactory;

            if (rewriterFactory != null)
            {
                var customVisitor = rewriterFactory.CreateVisitor(parameters);
                if (customVisitor != null)
                {
                    customVisitor.VisitQueryModel(queryModel);
                }
            }

            // rewrite any operators that should be applied on the outer query
            // by flattening out the sub-queries that they are located in
            var result = ResultOperatorRewriter.Rewrite(queryModel);

            // Identify and name query sources
            QuerySourceIdentifier.Visit(parameters.QuerySourceNamer, queryModel);

            var visitor = new QueryModelVisitor(parameters, root, queryModel, rootReturnType)
            {
                RewrittenOperatorResult = result,
            };

            visitor.Visit();

            return(visitor._hqlTree.GetTranslation());
        }
		private QueryModelVisitor(VisitorParameters visitorParameters, bool root, QueryModel queryModel)
		{
			VisitorParameters = visitorParameters;
			Model = queryModel;
			_hqlTree = new IntermediateHqlTree(root);
		}
        public static ExpressionToHqlTranslationResults GenerateHqlQuery(QueryModel queryModel, VisitorParameters parameters, bool root)
        {
            NestedSelectRewriter.ReWrite(queryModel, parameters.SessionFactory);

            // Remove unnecessary body operators
            RemoveUnnecessaryBodyOperators.ReWrite(queryModel);

            // Merge aggregating result operators (distinct, count, sum etc) into the select clause
            MergeAggregatingResultsRewriter.ReWrite(queryModel);

            // Swap out non-aggregating group-bys
            NonAggregatingGroupByRewriter.ReWrite(queryModel);

            // Rewrite aggregate group-by statements
            AggregatingGroupByRewriter.ReWrite(queryModel);

            // Rewrite aggregating group-joins
            AggregatingGroupJoinRewriter.ReWrite(queryModel);

            // Rewrite non-aggregating group-joins
            NonAggregatingGroupJoinRewriter.ReWrite(queryModel);

            SubQueryFromClauseFlattener.ReWrite(queryModel);

            // Rewrite left-joins
            LeftJoinRewriter.ReWrite(queryModel);

            // Rewrite paging
            PagingRewriter.ReWrite(queryModel);

            // Flatten pointless subqueries
            QueryReferenceExpressionFlattener.ReWrite(queryModel);

            // Add joins for references
            AddJoinsReWriter.ReWrite(queryModel, parameters.SessionFactory);

            // Move OrderBy clauses to end
            MoveOrderByToEndRewriter.ReWrite(queryModel);

            // rewrite any operators that should be applied on the outer query
            // by flattening out the sub-queries that they are located in
            var result = ResultOperatorRewriter.Rewrite(queryModel);

            // Identify and name query sources
            QuerySourceIdentifier.Visit(parameters.QuerySourceNamer, queryModel);

            var visitor = new QueryModelVisitor(parameters, root, queryModel)
            {
                RewrittenOperatorResult = result
            };

            visitor.Visit();

            return(visitor._hqlTree.GetTranslation());
        }
 public SelectClauseVisitor(System.Type inputType, VisitorParameters parameters)
 {
     _inputParameter = Expression.Parameter(inputType, "input");
     _parameters     = parameters;
 }
Beispiel #29
0
 public HqlGeneratorExpressionVisitor(VisitorParameters parameters)
 {
     _functionRegistry = parameters.SessionFactory.Settings.LinqToHqlGeneratorsRegistry;
     _parameters       = parameters;
 }
		public static void ReWrite(QueryModel queryModel, VisitorParameters parameters)
		{
			var visitor = new AddJoinsReWriter(parameters.SessionFactory, queryModel);
			visitor.VisitQueryModel(queryModel);
		}