Search in sources :

Example 1 with AlterSequenceFlagsStep

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

Example 2 with AlterSequenceFlagsStep

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

the class Diff method appendSequences.

private final DiffResult appendSequences(DiffResult result, List<? extends Sequence<?>> l1, List<? extends Sequence<?>> l2) {
    return append(result, l1, l2, null, (r, s) -> r.queries.add(ddl.createSequence(s)), dropSequence(), (r, s1, s2) -> {
        AlterSequenceFlagsStep stmt = null;
        AlterSequenceFlagsStep stmt0 = ctx.alterSequence(s1);
        if (s2.getStartWith() != null && !s2.getStartWith().equals(s1.getStartWith()))
            stmt = defaultIfNull(stmt, stmt0).startWith(s2.getStartWith());
        else if (s2.getStartWith() == null && s1.getStartWith() != null)
            stmt = defaultIfNull(stmt, stmt0).startWith(1);
        if (s2.getIncrementBy() != null && !s2.getIncrementBy().equals(s1.getIncrementBy()))
            stmt = defaultIfNull(stmt, stmt0).incrementBy(s2.getIncrementBy());
        else if (s2.getIncrementBy() == null && s1.getIncrementBy() != null)
            stmt = defaultIfNull(stmt, stmt0).incrementBy(1);
        if (s2.getMinvalue() != null && !s2.getMinvalue().equals(s1.getMinvalue()))
            stmt = defaultIfNull(stmt, stmt0).minvalue(s2.getMinvalue());
        else if (s2.getMinvalue() == null && s1.getMinvalue() != null)
            stmt = defaultIfNull(stmt, stmt0).noMinvalue();
        if (s2.getMaxvalue() != null && !s2.getMaxvalue().equals(s1.getMaxvalue()))
            stmt = defaultIfNull(stmt, stmt0).maxvalue(s2.getMaxvalue());
        else if (s2.getMaxvalue() == null && s1.getMaxvalue() != null)
            stmt = defaultIfNull(stmt, stmt0).noMaxvalue();
        if (s2.getCache() != null && !s2.getCache().equals(s1.getCache()))
            stmt = defaultIfNull(stmt, stmt0).cache(s2.getCache());
        else if (s2.getCache() == null && s1.getCache() != null)
            stmt = defaultIfNull(stmt, stmt0).noCache();
        if (s2.getCycle() && !s1.getCycle())
            stmt = defaultIfNull(stmt, stmt0).cycle();
        else if (!s2.getCycle() && s1.getCycle())
            stmt = defaultIfNull(stmt, stmt0).noCycle();
        if (stmt != null)
            r.queries.add(stmt);
    });
}
Also used : AlterSequenceFlagsStep(org.jooq.AlterSequenceFlagsStep)

Aggregations

AlterSequenceFlagsStep (org.jooq.AlterSequenceFlagsStep)2 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