Search in sources :

Example 1 with CaseValueStep

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

the class ParserImpl method parseFieldCaseIf.

private static final Field<?> parseFieldCaseIf(ParserContext ctx) {
    if (parseKeywordIf(ctx, "CASE")) {
        if (parseKeywordIf(ctx, "WHEN")) {
            CaseConditionStep step = null;
            Field result;
            do {
                Condition condition = parseCondition(ctx);
                parseKeyword(ctx, "THEN");
                Field value = parseField(ctx);
                step = step == null ? when(condition, value) : step.when(condition, value);
            } while (parseKeywordIf(ctx, "WHEN"));
            if (parseKeywordIf(ctx, "ELSE"))
                result = step.otherwise(parseField(ctx));
            else
                result = step;
            parseKeyword(ctx, "END");
            return result;
        } else {
            CaseValueStep init = choose(parseField(ctx));
            CaseWhenStep step = null;
            Field result;
            parseKeyword(ctx, "WHEN");
            do {
                Field when = parseField(ctx);
                parseKeyword(ctx, "THEN");
                Field then = parseField(ctx);
                step = step == null ? init.when(when, then) : step.when(when, then);
            } while (parseKeywordIf(ctx, "WHEN"));
            if (parseKeywordIf(ctx, "ELSE"))
                result = step.otherwise(parseField(ctx));
            else
                result = step;
            parseKeyword(ctx, "END");
            return result;
        }
    }
    return null;
}
Also used : Condition(org.jooq.Condition) TableField(org.jooq.TableField) GroupField(org.jooq.GroupField) Field(org.jooq.Field) SortField(org.jooq.SortField) CaseValueStep(org.jooq.CaseValueStep) CaseWhenStep(org.jooq.CaseWhenStep) CaseConditionStep(org.jooq.CaseConditionStep)

Aggregations

CaseConditionStep (org.jooq.CaseConditionStep)1 CaseValueStep (org.jooq.CaseValueStep)1 CaseWhenStep (org.jooq.CaseWhenStep)1 Condition (org.jooq.Condition)1 Field (org.jooq.Field)1 GroupField (org.jooq.GroupField)1 SortField (org.jooq.SortField)1 TableField (org.jooq.TableField)1