Search in sources :

Example 1 with CaseConditionStep

use of org.jooq.CaseConditionStep 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)

Example 2 with CaseConditionStep

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

the class DefaultParseContext method parseFieldCaseIf.

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

Aggregations

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