Exemplo n.º 1
0
 public void ThrowQueryException()
 {
     if (GetErrorCount() > 0)
     {
         if (_recognitionExceptions.Count > 0)
         {
             throw QuerySyntaxException.Convert(_recognitionExceptions[0]);
         }
         else
         {
             throw new QueryException(GetErrorString());
         }
     }
     else
     {
         // all clear
         if (log.IsDebugEnabled)
         {
             log.Debug("throwQueryException() : no errors");
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Performs both filter and non-filter compiling.
        /// </summary>
        /// <param name="replacements">Defined query substitutions.</param>
        /// <param name="shallow">Does this represent a shallow (scalar or entity-id) select?</param>
        /// <param name="collectionRole">the role name of the collection used as the basis for the filter, NULL if this is not a filter.</param>
        private void DoCompile(IDictionary <string, string> replacements, bool shallow, String collectionRole)
        {
            // If the query is already compiled, skip the compilation.
            if (_compiled)
            {
                if (log.IsDebugEnabled)
                {
                    log.Debug("compile() : The query is already compiled, skipping...");
                }
                return;
            }

            // Remember the parameters for the compilation.
            _tokenReplacements = replacements ?? new Dictionary <string, string>(1);

            _shallowQuery = shallow;

            try
            {
                // PHASE 1 : Analyze the HQL AST, and produce an SQL AST.
                var translator = Analyze(collectionRole);

                _sqlAst = translator.SqlStatement;

                // at some point the generate phase needs to be moved out of here,
                // because a single object-level DML might spawn multiple SQL DML
                // command executions.
                //
                // Possible to just move the sql generation for dml stuff, but for
                // consistency-sake probably best to just move responsiblity for
                // the generation phase completely into the delegates
                // (QueryLoader/StatementExecutor) themselves.  Also, not sure why
                // QueryLoader currently even has a dependency on this at all; does
                // it need it?  Ideally like to see the walker itself given to the delegates directly...

                if (_sqlAst.NeedsExecutor)
                {
                    _statementExecutor = BuildAppropriateStatementExecutor(_sqlAst);
                }
                else
                {
                    // PHASE 2 : Generate the SQL.
                    _generator = new HqlSqlGenerator(_sqlAst, _factory);
                    _generator.Generate();

                    _queryLoader = new QueryLoader(this, _factory, _sqlAst.Walker.SelectClause);
                }

                _compiled = true;
            }
            catch (QueryException qe)
            {
                qe.QueryString = _queryIdentifier;
                throw;
            }
            catch (RecognitionException e)
            {
                // we do not actually propogate ANTLRExceptions as a cause, so
                // log it here for diagnostic purposes
                if (log.IsInfoEnabled)
                {
                    log.Info("converted antlr.RecognitionException", e);
                }
                throw QuerySyntaxException.Convert(e, _queryIdentifier);
            }

            _enabledFilters = null;             //only needed during compilation phase...
        }