Search in sources :

Example 1 with WindowDefinition

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

the class Function method window.

@SuppressWarnings("unchecked")
final QueryPart window(Context<?> ctx) {
    if (windowSpecification != null)
        return DSL.sql("({0})", windowSpecification);
    // shouldn't be referenced from within parentheses (in PostgreSQL)
    if (windowDefinition != null)
        if (POSTGRES == ctx.family())
            return windowDefinition;
        else
            return DSL.sql("({0})", windowDefinition);
    // [#531] Inline window specifications if the WINDOW clause is not supported
    if (windowName != null) {
        if (asList(POSTGRES).contains(ctx.family()))
            return windowName;
        Map<Object, Object> map = (Map<Object, Object>) ctx.data(DATA_LOCALLY_SCOPED_DATA_MAP);
        QueryPartList<WindowDefinition> windows = (QueryPartList<WindowDefinition>) map.get(DATA_WINDOW_DEFINITIONS);
        if (windows != null) {
            for (WindowDefinition window : windows) {
                if (((WindowDefinitionImpl) window).getName().equals(windowName)) {
                    return DSL.sql("({0})", window);
                }
            }
        } else // [#3162] If a window specification is missing from the query's WINDOW clause,
        // jOOQ should just render the window name regardless of the SQL dialect
        {
            return windowName;
        }
    }
    return null;
}
Also used : Map(java.util.Map) WindowDefinition(org.jooq.WindowDefinition)

Example 2 with WindowDefinition

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

the class WindowDefinitionImpl method accept.

@Override
public final void accept(Context<?> ctx) {
    // In the WINDOW clause, always declare window definitions
    if (ctx.declareWindows()) {
        ctx.visit(name).sql(' ').visit(K_AS).sql(" (");
        if (window != null)
            ctx.visit(window);
        ctx.sql(')');
    } else // referencing WINDOW definitions
    if (!NO_SUPPORT_WINDOW_CLAUSE.contains(ctx.dialect())) {
        ctx.visit(name);
    } else // When emulating, just repeat the window specification
    if (window != null) {
        ctx.visit(window);
    } else // Try looking up the window specification from the context
    {
        @SuppressWarnings("unchecked") QueryPartList<WindowDefinition> windows = (QueryPartList<WindowDefinition>) ctx.data(DATA_WINDOW_DEFINITIONS);
        renderContextDefinitionOrName: if (windows != null) {
            windowLoop: for (WindowDefinition w : windows) {
                if (((WindowDefinitionImpl) w).getName().equals(name)) {
                    // Prevent StackOverflowError
                    if (w == this)
                        break windowLoop;
                    ctx.visit(w);
                    break renderContextDefinitionOrName;
                }
            }
        // [#7296] This is an empty window specification if we reach this far
        }
    }
}
Also used : WindowDefinition(org.jooq.WindowDefinition)

Example 3 with WindowDefinition

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

the class DefaultParseContext method parseWindowDefinitions.

private final List<WindowDefinition> parseWindowDefinitions() {
    return parseList(',', c -> {
        Name name = parseIdentifier();
        parseKeyword("AS");
        parse('(');
        WindowDefinition result = name.as(parseWindowSpecificationIf(null, true));
        parse(')');
        return result;
    });
}
Also used : WindowDefinition(org.jooq.WindowDefinition) Name(org.jooq.Name) DSL.systemName(org.jooq.impl.DSL.systemName)

Aggregations

WindowDefinition (org.jooq.WindowDefinition)3 Map (java.util.Map)1 Name (org.jooq.Name)1 DSL.systemName (org.jooq.impl.DSL.systemName)1