[#7087] Add support for SET SCHEMA and SET CATALOG

This commit is contained in:
lukaseder 2018-01-23 12:40:29 +01:00
parent f017fdce8f
commit 72da87c42a
6 changed files with 304 additions and 0 deletions

View File

@ -8432,6 +8432,58 @@ public interface DSLContext extends Scope , AutoCloseable {
*/
Queries ddl(Collection<? extends Table<?>> 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
// -------------------------------------------------------------------------

View File

@ -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
// -------------------------------------------------------------------------

View File

@ -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));

View File

@ -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");

View File

@ -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;
}
}

View File

@ -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;
}
}