Search in sources :

Example 1 with AlterSequenceStep

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

the class DefaultParseContext method parseAlterSequence.

private final DDLQuery parseAlterSequence() {
    boolean ifExists = parseKeywordIf("IF EXISTS");
    Sequence<?> sequenceName = parseSequenceName();
    AlterSequenceStep s = ifExists ? dsl.alterSequenceIfExists(sequenceName) : dsl.alterSequence(sequenceName);
    if (parseKeywordIf("RENAME")) {
        parseKeyword("AS", "TO");
        return s.renameTo(parseSequenceName());
    } else if (parseKeywordIf("OWNER TO") && parseUser() != null) {
        return IGNORE;
    } else {
        boolean found = false;
        boolean restart = false;
        boolean startWith = false;
        boolean incrementBy = false;
        boolean minvalue = false;
        boolean maxvalue = false;
        boolean cycle = false;
        boolean cache = false;
        AlterSequenceFlagsStep s1 = s;
        while (true) {
            Field<Long> field;
            if (!startWith && (startWith |= (field = parseSequenceStartWithIf()) != null))
                s1 = s1.startWith(field);
            else if (!incrementBy && (incrementBy |= (field = parseSequenceIncrementByIf()) != null))
                s1 = s1.incrementBy(field);
            else if (!minvalue && (minvalue |= (field = parseSequenceMinvalueIf()) != null))
                s1 = s1.minvalue(field);
            else if (!minvalue && (minvalue |= parseSequenceNoMinvalueIf()))
                s1 = s1.noMinvalue();
            else if (!maxvalue && (maxvalue |= (field = parseSequenceMaxvalueIf()) != null))
                s1 = s1.maxvalue(field);
            else if (!maxvalue && (maxvalue |= parseSequenceNoMaxvalueIf()))
                s1 = s1.noMaxvalue();
            else if (!cycle && (cycle |= parseKeywordIf("CYCLE")))
                s1 = s1.cycle();
            else if (!cycle && (cycle |= parseSequenceNoCycleIf()))
                s1 = s1.noCycle();
            else if (!cache && (cache |= (field = parseSequenceCacheIf()) != null))
                s1 = s1.cache(field);
            else if (!cache && (cache |= parseSequenceNoCacheIf()))
                s1 = s1.noCache();
            else if (!restart && (restart |= parseKeywordIf("RESTART"))) {
                if (parseKeywordIf("WITH"))
                    s1 = s1.restartWith(parseUnsignedIntegerOrBindVariable());
                else
                    s1 = s1.restart();
            } else
                break;
            found = true;
        }
        if (!found)
            throw expected("CACHE", "CYCLE", "INCREMENT BY", "MAXVALUE", "MINVALUE", "NO CACHE", "NO CYCLE", "NO MAXVALUE", "NO MINVALUE", "OWNER TO", "RENAME TO", "RESTART", "START WITH");
        return s1;
    }
}
Also used : GroupField(org.jooq.GroupField) TableField(org.jooq.TableField) Field(org.jooq.Field) SortField(org.jooq.SortField) SelectField(org.jooq.SelectField) AlterSequenceStep(org.jooq.AlterSequenceStep) AlterSequenceFlagsStep(org.jooq.AlterSequenceFlagsStep)

Aggregations

AlterSequenceFlagsStep (org.jooq.AlterSequenceFlagsStep)1 AlterSequenceStep (org.jooq.AlterSequenceStep)1 Field (org.jooq.Field)1 GroupField (org.jooq.GroupField)1 SelectField (org.jooq.SelectField)1 SortField (org.jooq.SortField)1 TableField (org.jooq.TableField)1