Search in sources :

Example 1 with QueryLoader

use of org.hibernate.loader.hql.QueryLoader in project hibernate-orm by hibernate.

the class QueryTranslatorImpl method doCompile.

/**
	 * Performs both filter and non-filter compiling.
	 *
	 * @param replacements   Defined query substitutions.
	 * @param shallow        Does this represent a shallow (scalar or entity-id) select?
	 * @param collectionRole the role name of the collection used as the basis for the filter, NULL if this
	 *                       is not a filter.
	 */
private synchronized void doCompile(Map replacements, boolean shallow, String collectionRole) {
    // If the query is already compiled, skip the compilation.
    if (compiled) {
        LOG.debug("compile() : The query is already compiled, skipping...");
        return;
    }
    // Remember the parameters for the compilation.
    this.tokenReplacements = replacements;
    if (tokenReplacements == null) {
        tokenReplacements = new HashMap();
    }
    this.shallowQuery = shallow;
    try {
        // PHASE 1 : Parse the HQL into an AST.
        final HqlParser parser = parse(true);
        // PHASE 2 : Analyze the HQL AST, and produce an SQL AST.
        final HqlSqlWalker w = analyze(parser, collectionRole);
        sqlAst = (Statement) w.getAST();
        if (sqlAst.needsExecutor()) {
            statementExecutor = buildAppropriateStatementExecutor(w);
        } else {
            // PHASE 3 : Generate the SQL.
            generate((QueryNode) sqlAst);
            queryLoader = new QueryLoader(this, factory, w.getSelectClause());
        }
        compiled = true;
    } catch (QueryException qe) {
        if (qe.getQueryString() == null) {
            throw qe.wrapWithQueryString(hql);
        } else {
            throw qe;
        }
    } catch (RecognitionException e) {
        // we do not actually propagate ANTLRExceptions as a cause, so
        // log it here for diagnostic purposes
        LOG.trace("Converted antlr.RecognitionException", e);
        throw QuerySyntaxException.convert(e, hql);
    } catch (ANTLRException e) {
        // we do not actually propagate ANTLRExceptions as a cause, so
        // log it here for diagnostic purposes
        LOG.trace("Converted antlr.ANTLRException", e);
        throw new QueryException(e.getMessage(), hql);
    } catch (IllegalArgumentException e) {
        // translate this into QueryException
        LOG.trace("Converted IllegalArgumentException", e);
        throw new QueryException(e.getMessage(), hql);
    }
    //only needed during compilation phase...
    this.enabledFilters = null;
}
Also used : ANTLRException(antlr.ANTLRException) QueryException(org.hibernate.QueryException) QueryLoader(org.hibernate.loader.hql.QueryLoader) HashMap(java.util.HashMap) RecognitionException(antlr.RecognitionException)

Aggregations

ANTLRException (antlr.ANTLRException)1 RecognitionException (antlr.RecognitionException)1 HashMap (java.util.HashMap)1 QueryException (org.hibernate.QueryException)1 QueryLoader (org.hibernate.loader.hql.QueryLoader)1