Search in sources :

Example 6 with QueryPartInternal

use of org.jooq.QueryPartInternal in project jOOQ by jOOQ.

the class AbstractContext method visit.

// ------------------------------------------------------------------------
// VisitListener API
// ------------------------------------------------------------------------
@Override
public final C visit(QueryPart part) {
    if (part != null) {
        // Issue start clause events
        // -----------------------------------------------------------------
        Clause[] clauses = Tools.isNotEmpty(visitListenersStart) ? clause(part) : null;
        if (clauses != null)
            for (int i = 0; i < clauses.length; i++) start(clauses[i]);
        // Perform the actual visiting, or recurse into the replacement
        // -----------------------------------------------------------------
        QueryPart replacement = start(part);
        if (replacement != null) {
            QueryPartInternal internal = (QueryPartInternal) scopeMapping(replacement);
            // We're declaring fields, but "part" does not declare fields
            if (declareFields() && !internal.declaresFields()) {
                boolean aliases = declareAliases();
                declareFields(false);
                visit0(internal);
                declareFields(true);
                declareAliases(aliases);
            } else // We're declaring tables, but "part" does not declare tables
            if (declareTables() && !internal.declaresTables()) {
                boolean aliases = declareAliases();
                declareTables(false);
                visit0(internal);
                declareTables(true);
                declareAliases(aliases);
            } else // We're declaring windows, but "part" does not declare windows
            if (declareWindows() && !internal.declaresWindows()) {
                declareWindows(false);
                visit0(internal);
                declareWindows(true);
            } else // We're declaring cte, but "part" does not declare cte
            if (declareCTE() && !internal.declaresCTE()) {
                declareCTE(false);
                visit0(internal);
                declareCTE(true);
            } else if (!castModeOverride && castMode() != CastMode.DEFAULT && !internal.generatesCast()) {
                CastMode previous = castMode();
                castMode(CastMode.DEFAULT);
                visit0(internal);
                castMode(previous);
            } else // We're not declaring, or "part" can declare
            {
                visit0(internal);
            }
        }
        end(replacement);
        // -----------------------------------------------------------------
        if (clauses != null)
            for (int i = clauses.length - 1; i >= 0; i--) end(clauses[i]);
    }
    return (C) this;
}
Also used : QueryPartInternal(org.jooq.QueryPartInternal) QueryPart(org.jooq.QueryPart) Clause(org.jooq.Clause) CastMode(org.jooq.RenderContext.CastMode) ParamCastMode(org.jooq.conf.ParamCastMode)

Aggregations

QueryPartInternal (org.jooq.QueryPartInternal)6 ArrayList (java.util.ArrayList)3 Condition (org.jooq.Condition)3 CastMode (org.jooq.RenderContext.CastMode)2 ParamCastMode (org.jooq.conf.ParamCastMode)2 Arrays.asList (java.util.Arrays.asList)1 BitSet (java.util.BitSet)1 List (java.util.List)1 Clause (org.jooq.Clause)1 Comparator (org.jooq.Comparator)1 Field (org.jooq.Field)1 QueryPart (org.jooq.QueryPart)1 Row (org.jooq.Row)1 SQLDialect (org.jooq.SQLDialect)1 DSL.falseCondition (org.jooq.impl.DSL.falseCondition)1 DSL.trueCondition (org.jooq.impl.DSL.trueCondition)1 EMPTY_QUERYPART (org.jooq.impl.Tools.EMPTY_QUERYPART)1