From ec1768245b295182f45bcc205d9f482497887a93 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 18 Dec 2019 11:36:31 +0100 Subject: [PATCH] [jOOQ/jOOQ#8528] Interpret SetSchema --- .../java/org/jooq/impl/DDLInterpreter.java | 24 ++++++++++++++++++- .../main/java/org/jooq/impl/SetSchema.java | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/DDLInterpreter.java b/jOOQ/src/main/java/org/jooq/impl/DDLInterpreter.java index d65e1af00e..290241b7e4 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DDLInterpreter.java +++ b/jOOQ/src/main/java/org/jooq/impl/DDLInterpreter.java @@ -112,6 +112,7 @@ final class DDLInterpreter { private final Map catalogs = new LinkedHashMap<>(); private final MutableCatalog defaultCatalog; private final MutableSchema defaultSchema; + private MutableSchema currentSchema; // Caches private final Map interpretedCatalogs = new HashMap<>(); @@ -197,6 +198,12 @@ final class DDLInterpreter { else if (query instanceof CommentOnImpl) accept0((CommentOnImpl) query); + // TODO: Add support for catalogs + // else if (query instanceof SetCatalog) + // accept0((SetCatalog) query); + else if (query instanceof SetSchema) + accept0((SetSchema) query); + // The interpreter cannot handle DML statements. We're ignoring these for now. else if (query instanceof Select) ; @@ -936,6 +943,14 @@ final class DDLInterpreter { throw unsupportedQuery(query); } + private final void accept0(SetSchema query) { + MutableSchema schema = getSchema(query.$schema()); + if (schema == null) + throw schemaNotExists(query.$schema()); + + currentSchema = schema; + } + // ------------------------------------------------------------------------- // Exceptions // ------------------------------------------------------------------------- @@ -1059,7 +1074,7 @@ final class DDLInterpreter { private final MutableSchema getSchema(Schema input, boolean create) { if (input == null) - return getInterpreterSearchPathSchema(create); + return currentSchema(create); MutableCatalog catalog = defaultCatalog; if (input.getCatalog() != null) { @@ -1079,6 +1094,13 @@ final class DDLInterpreter { return schema; } + private final MutableSchema currentSchema(boolean create) { + if (currentSchema == null) + currentSchema = getInterpreterSearchPathSchema(create); + + return currentSchema; + } + private final MutableSchema getInterpreterSearchPathSchema(boolean create) { List searchPath = configuration.settings().getInterpreterSearchPath(); diff --git a/jOOQ/src/main/java/org/jooq/impl/SetSchema.java b/jOOQ/src/main/java/org/jooq/impl/SetSchema.java index 816a81d3b1..0fa371dfd4 100644 --- a/jOOQ/src/main/java/org/jooq/impl/SetSchema.java +++ b/jOOQ/src/main/java/org/jooq/impl/SetSchema.java @@ -64,6 +64,8 @@ final class SetSchema extends AbstractRowCountQuery { this.schema = schema; } + final Schema $schema() { return schema; } + @Override public final void accept(Context ctx) { switch (ctx.family()) {