[jOOQ/jOOQ#7752] Support ALTER SEQUENCE flags in DDL interpreter

Note: The RESTART clause has no effect.
This commit is contained in:
Knut Wannheden 2019-11-20 15:45:46 +01:00
parent 060c18b3ba
commit 9aeb540011
3 changed files with 80 additions and 41 deletions

View File

@ -140,9 +140,18 @@ final class AlterSequenceImpl<T extends Number> extends AbstractRowCountQuery im
this.ifExists = ifExists;
}
final Sequence<?> $sequence() { return sequence; }
final boolean $ifExists() { return ifExists; }
final Sequence<?> $renameTo() { return renameTo; }
final Sequence<?> $sequence() { return sequence; }
final boolean $ifExists() { return ifExists; }
final Sequence<?> $renameTo() { return renameTo; }
final Field<? extends Number> $startWith() { return startWith; }
final Field<? extends Number> $incrementBy() { return incrementBy; }
final Field<? extends Number> $minvalue() { return minvalue; }
final boolean $noMinvalue() { return noMinvalue; }
final Field<? extends Number> $maxvalue() { return maxvalue; }
final boolean $noMaxvalue() { return noMaxvalue; }
final Boolean $cycle() { return cycle; }
final Field<? extends Number> $cache() { return cache; }
final boolean $noCache() { return noCache; }
// ------------------------------------------------------------------------
// XXX: DSL API

View File

@ -98,18 +98,18 @@ final class CreateSequenceImpl extends AbstractRowCountQuery implements
private static final Set<SQLDialect> OMIT_NO_MINVALUE = SQLDialect.supportedBy(FIREBIRD);
private static final Set<SQLDialect> OMIT_NO_MAXVALUE = SQLDialect.supportedBy(FIREBIRD);
private final Sequence<?> sequence;
private final boolean ifNotExists;
private Field<?> startWith;
private Field<?> incrementBy;
private Field<?> minvalue;
private boolean noMinvalue;
private Field<?> maxvalue;
private boolean noMaxvalue;
private boolean cycle;
private boolean noCycle;
private Field<?> cache;
private boolean noCache;
private final Sequence<?> sequence;
private final boolean ifNotExists;
private Field<? extends Number> startWith;
private Field<? extends Number> incrementBy;
private Field<? extends Number> minvalue;
private boolean noMinvalue;
private Field<? extends Number> maxvalue;
private boolean noMaxvalue;
private boolean cycle;
private boolean noCycle;
private Field<? extends Number> cache;
private boolean noCache;
CreateSequenceImpl(Configuration configuration, Sequence<?> sequence, boolean ifNotExists) {
super(configuration);
@ -118,18 +118,18 @@ final class CreateSequenceImpl extends AbstractRowCountQuery implements
this.ifNotExists = ifNotExists;
}
final Sequence<?> $sequence() { return sequence; }
final boolean $ifNotExists() { return ifNotExists; }
final Field<?> $startWith() { return startWith; }
final Field<?> $incrementBy() { return incrementBy; }
final Field<?> $minvalue() { return minvalue; }
final boolean $noMinvalue() { return noMinvalue; }
final Field<?> $maxvalue() { return maxvalue; }
final boolean $noMaxvalue() { return noMaxvalue; }
final boolean $cycle() { return cycle; }
final boolean $noCycle() { return noCycle; }
final Field<?> $cache() { return cache; }
final boolean $noCache() { return noCache; }
final Sequence<?> $sequence() { return sequence; }
final boolean $ifNotExists() { return ifNotExists; }
final Field<? extends Number> $startWith() { return startWith; }
final Field<? extends Number> $incrementBy() { return incrementBy; }
final Field<? extends Number> $minvalue() { return minvalue; }
final boolean $noMinvalue() { return noMinvalue; }
final Field<? extends Number> $maxvalue() { return maxvalue; }
final boolean $noMaxvalue() { return noMaxvalue; }
final boolean $cycle() { return cycle; }
final boolean $noCycle() { return noCycle; }
final Field<? extends Number> $cache() { return cache; }
final boolean $noCache() { return noCache; }
// ------------------------------------------------------------------------
// XXX: Sequence API

View File

@ -724,8 +724,37 @@ final class DDLInterpreter {
existing.name = (UnqualifiedName) renameTo.getUnqualifiedName();
}
else
throw unsupportedQuery(query);
else {
Field<? extends Number> startWith = query.$startWith();
if (startWith != null)
existing.startWith = startWith;
Field<? extends Number> incrementBy = query.$incrementBy();
if (incrementBy != null)
existing.incrementBy = incrementBy;
Field<? extends Number> minvalue = query.$minvalue();
if (minvalue != null)
existing.minValue = minvalue;
else if (query.$noMinvalue())
existing.minValue = null;
Field<? extends Number> maxvalue = query.$maxvalue();
if (maxvalue != null)
existing.maxValue = maxvalue;
else if (query.$noMaxvalue())
existing.maxValue = null;
Boolean cycle = query.$cycle();
if (cycle != null)
existing.cycle = cycle;
Field<? extends Number> cache = query.$cache();
if (cache != null)
existing.cache = cache;
else if (query.$noCache())
existing.cache = null;
}
}
private final void accept0(DropSequenceImpl query) {
@ -1388,13 +1417,13 @@ final class DDLInterpreter {
@SuppressWarnings("unused")
private static final class MutableSequence extends MutableNamed {
MutableSchema schema;
Field<?> startWith;
Field<?> incrementBy;
Field<?> minValue;
Field<?> maxValue;
boolean cycle;
Field<?> cache;
MutableSchema schema;
Field<? extends Number> startWith;
Field<? extends Number> incrementBy;
Field<? extends Number> minValue;
Field<? extends Number> maxValue;
boolean cycle;
Field<? extends Number> cache;
MutableSequence(UnqualifiedName name, MutableSchema schema) {
super(name);
@ -1404,13 +1433,14 @@ final class DDLInterpreter {
}
private final class InterpretedSequence extends SequenceImpl<Long> {
@SuppressWarnings("unchecked")
InterpretedSequence(Schema schema) {
super(MutableSequence.this.name, schema, BIGINT, false,
(Field<Long>) startWith, (Field<Long>) incrementBy, (Field<Long>) minValue, (Field<Long>) maxValue, cycle, (Field<Long>) cache);
// [#7752] TODO: Pass additional flags like START WITH to
// SequenceImpl when this is ready.
startWith != null ? startWith.coerce(Long.class) : null,
incrementBy != null ? incrementBy.coerce(Long.class) : null,
minValue != null ? minValue.coerce(Long.class) : null,
maxValue != null ? maxValue.coerce(Long.class) : null,
cycle,
cache != null ? cache.coerce(Long.class) : null);
}
}
}