diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 82ef4315b6..b6104edd6e 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -8432,6 +8432,58 @@ public interface DSLContext extends Scope , AutoCloseable { */ Queries ddl(Collection> tables, DDLFlag... flags); + // ------------------------------------------------------------------------- + // XXX Session Statements + // ------------------------------------------------------------------------- + + + + + + + + + + + + + + + + + + + + + + + + + + + + /** + * Set the current schema to a new value. + * + * @see DSL#schema(Name) + */ + @Support({ H2, POSTGRES} ) + Query setSchema(String schema); + + /** + * Set the current schema to a new value. + * + * @see DSL#schema(Name) + */ + @Support({ H2, POSTGRES} ) + Query setSchema(Name schema); + + /** + * Set the current schema to a new value. + */ + @Support({ H2, POSTGRES} ) + Query setSchema(Schema schema); + // ------------------------------------------------------------------------- // XXX DDL Statements // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 85bf9d9681..f18be5917a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -6578,6 +6578,70 @@ public class DSL { return constraint().check(condition); } + // ------------------------------------------------------------------------- + // XXX Session Statements + // ------------------------------------------------------------------------- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /** + * Set the current schema to a new value. + * + * @see DSL#schema(Name) + */ + @Support({ H2, POSTGRES} ) + public static Query setSchema(String schema) { + return using(new DefaultConfiguration()).setSchema(schema); + } + + /** + * Set the current schema to a new value. + * + * @see DSL#schema(Name) + */ + @Support({ H2, POSTGRES} ) + public static Query setSchema(Name schema) { + return using(new DefaultConfiguration()).setSchema(schema); + } + + /** + * Set the current schema to a new value. + */ + @Support({ H2, POSTGRES} ) + public static Query setSchema(Schema schema) { + return using(new DefaultConfiguration()).setSchema(schema); + } + // ------------------------------------------------------------------------- // XXX DDL Statements // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index 07836f36fa..4e1e3c65ca 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -40,6 +40,7 @@ package org.jooq.impl; import static org.jooq.conf.ParamType.INLINED; import static org.jooq.conf.ParamType.NAMED; import static org.jooq.conf.ParamType.NAMED_OR_INLINED; +import static org.jooq.impl.DSL.catalog; import static org.jooq.impl.DSL.condition; import static org.jooq.impl.DSL.count; import static org.jooq.impl.DSL.field; @@ -2855,6 +2856,40 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri // XXX DDL Statements // ------------------------------------------------------------------------- + + + + + + + + + + + + + + + + + + + + @Override + public Query setSchema(String schema) { + return setSchema(name(schema)); + } + + @Override + public Query setSchema(Name schema) { + return setSchema(schema(schema)); + } + + @Override + public Query setSchema(Schema schema) { + return new SetSchema(configuration(), schema); + } + @Override public CommentOnIsStep commentOnTable(String tableName) { return commentOnTable(name(tableName)); diff --git a/jOOQ/src/main/java/org/jooq/impl/Keywords.java b/jOOQ/src/main/java/org/jooq/impl/Keywords.java index 75ebfa445f..eb373141b7 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Keywords.java +++ b/jOOQ/src/main/java/org/jooq/impl/Keywords.java @@ -73,6 +73,7 @@ final class Keywords { static final Keyword K_CASCADE = keyword("cascade"); static final Keyword K_CASE = keyword("case"); static final Keyword K_CAST = keyword("cast"); + static final Keyword K_CATALOG = keyword("catalog"); static final Keyword K_CHANGE_COLUMN = keyword("change column"); static final Keyword K_CHECK = keyword("check"); static final Keyword K_COALESCE = keyword("coalesce"); @@ -234,6 +235,7 @@ final class Keywords { static final Keyword K_ROWS_FROM = keyword("rows from"); static final Keyword K_ROWS_ONLY = keyword("rows only"); static final Keyword K_ROWS_WITH_TIES = keyword("rows with ties"); + static final Keyword K_SCHEMA = keyword("schema"); static final Keyword K_SCN = keyword("scn"); static final Keyword K_SELECT = keyword("select"); static final Keyword K_SEPARATOR = keyword("separator"); diff --git a/jOOQ/src/main/java/org/jooq/impl/SetCatalog.java b/jOOQ/src/main/java/org/jooq/impl/SetCatalog.java new file mode 100644 index 0000000000..252d7d270f --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/SetCatalog.java @@ -0,0 +1,75 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.impl.Keywords.K_CATALOG; +import static org.jooq.impl.Keywords.K_SET; + +import org.jooq.Catalog; +import org.jooq.Clause; +import org.jooq.Configuration; +import org.jooq.Context; + +/** + * @author Lukas Eder + */ +final class SetCatalog extends AbstractQuery { + + private static final long serialVersionUID = -3996953205762741746L; + private final Catalog catalog; + + SetCatalog(Configuration configuration, Catalog catalog) { + super(configuration); + + this.catalog = catalog; + } + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + default: + ctx.visit(K_SET).sql(' ').visit(K_CATALOG).sql(' ').visit(catalog); + break; + } + } + + @Override + public final Clause[] clauses(Context ctx) { + return null; + } +} diff --git a/jOOQ/src/main/java/org/jooq/impl/SetSchema.java b/jOOQ/src/main/java/org/jooq/impl/SetSchema.java new file mode 100644 index 0000000000..f021f6d907 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/SetSchema.java @@ -0,0 +1,76 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Other licenses: + * ----------------------------------------------------------------------------- + * Commercial licenses for this work are available. These replace the above + * ASL 2.0 and offer limited warranties, support, maintenance, and commercial + * database integrations. + * + * For more information, please visit: http://www.jooq.org/licenses + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + * + */ +package org.jooq.impl; + +import static org.jooq.impl.Keywords.K_SCHEMA; +import static org.jooq.impl.Keywords.K_SET; + +import org.jooq.Clause; +import org.jooq.Configuration; +import org.jooq.Context; +import org.jooq.Schema; + +/** + * @author Lukas Eder + */ +final class SetSchema extends AbstractQuery { + + private static final long serialVersionUID = -3996953205762741746L; + private final Schema schema; + + SetSchema(Configuration configuration, Schema schema) { + super(configuration); + + this.schema = schema; + } + + @Override + public final void accept(Context ctx) { + switch (ctx.family()) { + case H2: + default: + ctx.visit(K_SET).sql(' ').visit(K_SCHEMA).sql(' ').visit(schema); + break; + } + } + + @Override + public final Clause[] clauses(Context ctx) { + return null; + } +}