Search in sources :

Example 1 with WindowSpecificationOrderByStep

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

the class ParserImpl method parseWindowNameOrSpecification.

private static Object parseWindowNameOrSpecification(ParserContext ctx, boolean orderByAllowed) {
    Object result;
    if (parseIf(ctx, '(')) {
        WindowSpecificationOrderByStep s1 = null;
        WindowSpecificationRowsStep s2 = null;
        WindowSpecificationRowsAndStep s3 = null;
        s1 = parseKeywordIf(ctx, "PARTITION BY") ? partitionBy(parseFields(ctx)) : null;
        s2 = orderByAllowed && parseKeywordIf(ctx, "ORDER BY") ? s1 == null ? orderBy(parseSortSpecification(ctx)) : s1.orderBy(parseSortSpecification(ctx)) : s1;
        boolean rows = orderByAllowed && parseKeywordIf(ctx, "ROWS");
        if (rows || (orderByAllowed && parseKeywordIf(ctx, "RANGE"))) {
            if (parseKeywordIf(ctx, "BETWEEN")) {
                if (parseKeywordIf(ctx, "UNBOUNDED")) {
                    if (parseKeywordIf(ctx, "PRECEDING")) {
                        s3 = s2 == null ? rows ? rowsBetweenUnboundedPreceding() : rangeBetweenUnboundedPreceding() : rows ? s2.rowsBetweenUnboundedPreceding() : s2.rangeBetweenUnboundedPreceding();
                    } else {
                        parseKeyword(ctx, "FOLLOWING");
                        s3 = s2 == null ? rows ? rowsBetweenUnboundedFollowing() : rangeBetweenUnboundedFollowing() : rows ? s2.rowsBetweenUnboundedFollowing() : s2.rangeBetweenUnboundedFollowing();
                    }
                } else if (parseKeywordIf(ctx, "CURRENT ROW")) {
                    s3 = s2 == null ? rows ? rowsBetweenCurrentRow() : rangeBetweenCurrentRow() : rows ? s2.rowsBetweenCurrentRow() : s2.rangeBetweenCurrentRow();
                } else {
                    int number = (int) (long) parseUnsignedInteger(ctx);
                    if (parseKeywordIf(ctx, "PRECEDING")) {
                        s3 = s2 == null ? rows ? rowsBetweenPreceding(number) : rangeBetweenPreceding(number) : rows ? s2.rowsBetweenPreceding(number) : s2.rangeBetweenPreceding(number);
                    } else {
                        parseKeyword(ctx, "FOLLOWING");
                        s3 = s2 == null ? rows ? rowsBetweenFollowing(number) : rangeBetweenFollowing(number) : rows ? s2.rowsBetweenFollowing(number) : s2.rangeBetweenFollowing(number);
                    }
                }
                parseKeyword(ctx, "AND");
                if (parseKeywordIf(ctx, "UNBOUNDED")) {
                    if (parseKeywordIf(ctx, "PRECEDING")) {
                        result = s3.andUnboundedPreceding();
                    } else {
                        parseKeyword(ctx, "FOLLOWING");
                        result = s3.andUnboundedFollowing();
                    }
                } else if (parseKeywordIf(ctx, "CURRENT ROW")) {
                    result = s3.andCurrentRow();
                } else {
                    int number = (int) (long) parseUnsignedInteger(ctx);
                    if (parseKeywordIf(ctx, "PRECEDING")) {
                        result = s3.andPreceding(number);
                    } else {
                        parseKeyword(ctx, "FOLLOWING");
                        result = s3.andFollowing(number);
                    }
                }
            } else {
                if (parseKeywordIf(ctx, "UNBOUNDED")) {
                    if (parseKeywordIf(ctx, "PRECEDING")) {
                        result = s2 == null ? rows ? rowsUnboundedPreceding() : rangeUnboundedPreceding() : rows ? s2.rowsUnboundedPreceding() : s2.rangeUnboundedPreceding();
                    } else {
                        parseKeyword(ctx, "FOLLOWING");
                        result = s2 == null ? rows ? rowsUnboundedFollowing() : rangeUnboundedFollowing() : rows ? s2.rowsUnboundedFollowing() : s2.rangeUnboundedFollowing();
                    }
                } else if (parseKeywordIf(ctx, "CURRENT ROW")) {
                    result = s2 == null ? rows ? rowsCurrentRow() : rangeCurrentRow() : rows ? s2.rowsCurrentRow() : s2.rangeCurrentRow();
                } else {
                    int number = (int) (long) parseUnsignedInteger(ctx);
                    if (parseKeywordIf(ctx, "PRECEDING")) {
                        result = s2 == null ? rows ? rowsPreceding(number) : rangePreceding(number) : rows ? s2.rowsPreceding(number) : s2.rangePreceding(number);
                    } else {
                        parseKeyword(ctx, "FOLLOWING");
                        result = s2 == null ? rows ? rowsFollowing(number) : rangeFollowing(number) : rows ? s2.rowsFollowing(number) : s2.rangeFollowing(number);
                    }
                }
            }
        } else {
            result = s2;
        }
        parse(ctx, ')');
    } else {
        result = name(parseIdentifier(ctx));
    }
    return result;
}
Also used : WindowSpecificationRowsAndStep(org.jooq.WindowSpecificationRowsAndStep) WindowSpecificationRowsStep(org.jooq.WindowSpecificationRowsStep) WindowSpecificationOrderByStep(org.jooq.WindowSpecificationOrderByStep)

Aggregations

WindowSpecificationOrderByStep (org.jooq.WindowSpecificationOrderByStep)1 WindowSpecificationRowsAndStep (org.jooq.WindowSpecificationRowsAndStep)1 WindowSpecificationRowsStep (org.jooq.WindowSpecificationRowsStep)1