Esempio n. 1
0
        public IList <IASTNode> Collect(IASTNode root)
        {
            var traverser = new NodeTraverser(this);

            traverser.TraverseDepthFirst(root);
            return(collectedNodes);
        }
        public IList<IASTNode> LocateQuerySources()
        {
            // Find all the polymorphic query sources
            var nodeTraverser = new NodeTraverser(this);
            nodeTraverser.TraverseDepthFirst(_tree);

            return _nodes;
        }
		public IASTNode Parse()
		{
            // Parse the query string into an HQL AST.
            var lex = new HqlLexer(new CaseInsensitiveStringStream(_hql));
            _tokens = new CommonTokenStream(lex);

		    var parser = new HqlParser(_tokens) {TreeAdaptor = new ASTTreeAdaptor(), Filter = _filter};

		    if (log.IsDebugEnabled)
            {
                log.Debug("parse() - HQL: " + _hql);
            }

            try
            {
                var ast = (IASTNode) parser.statement().Tree;

                var walker = new NodeTraverser(new ConstantConverter(_sfi));
                walker.TraverseDepthFirst(ast);

                return ast;
            }
            finally
            {
                parser.ParseErrorHandler.ThrowQueryException();
            }
		}
Esempio n. 4
0
		private void HandleWithFragment(FromElement fromElement, IASTNode hqlWithNode)
		{
			try
			{
				ITreeNodeStream old = input;
				input = new CommonTreeNodeStream(adaptor, hqlWithNode);

				IASTNode hqlSqlWithNode = (IASTNode) withClause().Tree;
				input = old;

				if (log.IsDebugEnabled)
				{
					log.Debug("handleWithFragment() : " + _printer.ShowAsString(hqlSqlWithNode, "-- with clause --"));
				}
				WithClauseVisitor visitor = new WithClauseVisitor(fromElement);
				NodeTraverser traverser = new NodeTraverser(visitor);
				traverser.TraverseDepthFirst(hqlSqlWithNode);
				FromElement referencedFromElement = visitor.GetReferencedFromElement();
				if (referencedFromElement != fromElement)
				{
					throw new InvalidWithClauseException(
						"with-clause expressions did not reference from-clause element to which the with-clause was associated");
				}
				SqlGenerator sql = new SqlGenerator(_sessionFactoryHelper.Factory, new CommonTreeNodeStream(adaptor, hqlSqlWithNode.GetChild(0)));

				sql.whereExpr();

				var withClauseFragment = new SqlString("(", sql.GetSQL(), ")");
				fromElement.SetWithClauseFragment(visitor.GetJoinAlias(), withClauseFragment);
			}
			catch (SemanticException)
			{
				throw;
			}
			catch (InvalidWithClauseException)
			{
				throw;
			}
			catch (Exception e)
			{
				throw new SemanticException(e.Message);
			}
		}
		private IList<IASTNode> LocateParameters()
		{
			var nodeTraverser = new NodeTraverser(this);
			nodeTraverser.TraverseDepthFirst(_tree);

			return _nodes;
		}
		public IList<IASTNode> Collect(IASTNode root)
		{
			var traverser = new NodeTraverser(this);
			traverser.TraverseDepthFirst(root);
			return collectedNodes;
		}