public IQueryTranslator[] CreateQueryTranslators(string queryString, string collectionRole, bool shallow, IDictionary<string, IFilter> filters, ISessionFactoryImplementor factory) { var ast = new HqlParseEngine(queryString, collectionRole != null, factory).Parse(); return CreateQueryTranslators(ast, queryString, collectionRole, shallow, filters, factory); }
public IQueryTranslator[] CreateQueryTranslators(string queryString, string collectionRole, bool shallow, IDictionary <string, IFilter> filters, ISessionFactoryImplementor factory) { var ast = new HqlParseEngine(queryString, collectionRole != null, factory).Parse(); return(CreateQueryTranslators(ast, queryString, collectionRole, shallow, filters, factory)); }
private HqlParseEngine Parse(bool isFilter) { if (_parser == null) { _parser = new HqlParseEngine(_hql, isFilter, _factory); _parser.Parse(); } return(_parser); }
private HqlSqlTranslator Analyze(HqlParseEngine parser, string collectionRole) { var translator = new HqlSqlTranslator(parser.Ast, parser.Tokens, this, _factory, tokenReplacements, collectionRole); translator.Translate(); return(translator); }
/// <summary> /// Creates a new AST-based query translator. /// </summary> /// <param name="queryIdentifier">The query-identifier (used in stats collection)</param> /// <param name="queryExpression">The hql query to translate</param> /// <param name="enabledFilters">Currently enabled filters</param> /// <param name="factory">The session factory constructing this translator instance.</param> public QueryTranslatorImpl( string queryIdentifier, IQueryExpression queryExpression, IDictionary<string, IFilter> enabledFilters, ISessionFactoryImplementor factory) { _queryIdentifier = queryIdentifier; _hql = queryExpression.ToString(); _compiled = false; _shallowQuery = false; _enabledFilters = enabledFilters; _factory = factory; _parser = new HqlParseEngine(queryExpression.Translate(factory), factory); }
/// <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 : Parse the HQL into an AST. HqlParseEngine parser = Parse(true); // PHASE 2 : Analyze the HQL AST, and produce an SQL AST. var translator = Analyze(parser, 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 3 : Generate the SQL. _generator = new HqlSqlGenerator(sqlAst, parser.Tokens, _factory); _generator.Generate(); _queryLoader = new QueryLoader(this, _factory, sqlAst.Walker.SelectClause); } _compiled = true; } catch (QueryException qe) { qe.QueryString = _hql; 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, _hql); } _enabledFilters = null; //only needed during compilation phase... }
private HqlParseEngine Parse(bool isFilter) { if (_parser == null) { _parser = new HqlParseEngine(_hql, isFilter, _factory); _parser.Parse(); } return _parser; }
private HqlSqlTranslator Analyze(HqlParseEngine parser, string collectionRole) { var translator = new HqlSqlTranslator(parser.Ast, parser.Tokens, this, _factory, tokenReplacements, collectionRole); translator.Translate(); return translator; }