Skip to content

Commit

Permalink
[#9437] Emulate ALTER SEQUENCE ... NO CACHE for PostgreSQL
Browse files Browse the repository at this point in the history
PostgreSQL only understands the `CACHE` clause and `CACHE 1` effectively
means `NO CACHE`.
  • Loading branch information
knutwannheden committed Nov 20, 2019
1 parent cbcd506 commit 2229e4f
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions jOOQ/src/main/java/org/jooq/impl/AlterSequenceImpl.java
Expand Up @@ -43,6 +43,8 @@
import static org.jooq.Clause.ALTER_SEQUENCE_SEQUENCE;
// ...
// ...
// ...
// ...
import static org.jooq.SQLDialect.CUBRID;
// ...
import static org.jooq.SQLDialect.DERBY;
Expand All @@ -52,6 +54,7 @@
// ...
import static org.jooq.SQLDialect.MARIADB;
// ...
import static org.jooq.SQLDialect.POSTGRES;
// ...
// ...
import static org.jooq.impl.Keywords.K_ALTER;
Expand Down Expand Up @@ -105,6 +108,7 @@ final class AlterSequenceImpl<T extends Number> extends AbstractRowCountQuery im
private static final Set<SQLDialect> NO_SUPPORT_IF_EXISTS = SQLDialect.supportedBy(CUBRID, DERBY, FIREBIRD);
private static final Set<SQLDialect> NO_SEPARATOR = SQLDialect.supportedBy(CUBRID, MARIADB);
private static final Set<SQLDialect> NO_SUPPORT_CACHE = SQLDialect.supportedBy(DERBY, FIREBIRD, HSQLDB);
private static final Set<SQLDialect> EMULATE_NO_CACHE = SQLDialect.supportedBy(POSTGRES);



Expand Down Expand Up @@ -275,7 +279,7 @@ public AlterSequenceFlagsStep noCache() {
// ------------------------------------------------------------------------

private final boolean supportsIfExists(Context<?> ctx) {
return !NO_SUPPORT_IF_EXISTS.contains(ctx.family());
return !NO_SUPPORT_IF_EXISTS.contains(ctx.dialect());

This comment has been minimized.

Copy link
@lukaseder

lukaseder Nov 20, 2019

Member

I have a feeling, you have this itch to fix this thoroughly throughout the codebase ;-) Go for it, I won't keep you from doing it...

This comment has been minimized.

Copy link
@knutwannheden

knutwannheden Nov 20, 2019

Author Contributor

I just might 😄

}

@Override
Expand Down Expand Up @@ -400,7 +404,7 @@ private final void accept1(Context<?> ctx) {
else {
ctx.start(ALTER_SEQUENCE_RESTART);

String noSeparator = NO_SEPARATOR.contains(ctx.family()) ? "" : " ";
String noSeparator = NO_SEPARATOR.contains(ctx.dialect()) ? "" : " ";

if (incrementBy != null) {
ctx.sql(' ').visit(K_INCREMENT_BY)
Expand Down Expand Up @@ -439,12 +443,14 @@ else if (restartWith != null) {
.sql(' ').visit(restartWith);
}

if (!NO_SUPPORT_CACHE.contains(ctx.family()))
if (!NO_SUPPORT_CACHE.contains(ctx.dialect()))
if (cache != null)
ctx.sql(' ').visit(K_CACHE).sql(' ').visit(cache);
else if (noCache)
// TODO: Postgres requires CACHE 1 here
ctx.sql(' ').visit(K_NO).sql(noSeparator).visit(K_CACHE);
if (EMULATE_NO_CACHE.contains(ctx.dialect()))
ctx.sql(' ').visit(K_CACHE).sql(' ').sql(1);
else
ctx.sql(' ').visit(K_NO).sql(noSeparator).visit(K_CACHE);

if (Boolean.TRUE.equals(cycle))
ctx.sql(' ').visit(K_CYCLE);
Expand Down

0 comments on commit 2229e4f

Please sign in to comment.