From 19287add9d23171ccbd6f7436b1c65a4385dafad Mon Sep 17 00:00:00 2001 From: Timur Shaidullin Date: Tue, 19 Dec 2017 13:39:01 +0300 Subject: [PATCH] [#6913] Added a support for GRANT .. WITH GRANT OPTION --- .../main/java/org/jooq/GrantGrantedStep.java | 54 +++++++++++++++++++ jOOQ/src/main/java/org/jooq/GrantToStep.java | 6 +-- .../main/java/org/jooq/impl/GrantImpl.java | 14 +++++ .../src/main/java/org/jooq/impl/Keywords.java | 1 + 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 jOOQ/src/main/java/org/jooq/GrantGrantedStep.java diff --git a/jOOQ/src/main/java/org/jooq/GrantGrantedStep.java b/jOOQ/src/main/java/org/jooq/GrantGrantedStep.java new file mode 100644 index 0000000000..d7ef3e3e53 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/GrantGrantedStep.java @@ -0,0 +1,54 @@ +/* + * 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; + +import static org.jooq.SQLDialect.FIREBIRD; +import static org.jooq.SQLDialect.HSQLDB; +import static org.jooq.SQLDialect.MYSQL; +import static org.jooq.SQLDialect.POSTGRES; + +/** + * The step of creation GRANT statement that assign user + * or role a grant option. + * + * @author Timur Shaidullin + */ +public interface GrantGrantedStep extends GrantFinalStep{ + @Support({ POSTGRES, MYSQL, HSQLDB, FIREBIRD }) + GrantFinalStep withGrantOption(); +} diff --git a/jOOQ/src/main/java/org/jooq/GrantToStep.java b/jOOQ/src/main/java/org/jooq/GrantToStep.java index 066ebac333..8624456ca1 100644 --- a/jOOQ/src/main/java/org/jooq/GrantToStep.java +++ b/jOOQ/src/main/java/org/jooq/GrantToStep.java @@ -55,17 +55,17 @@ public interface GrantToStep { * Grant a privilege to a user. */ @Support({ H2, POSTGRES }) - GrantFinalStep to(User user); + GrantGrantedStep to(User user); /** * Grant a privilege to a role. */ @Support({ H2, POSTGRES }) - GrantFinalStep to(Role role); + GrantGrantedStep to(Role role); /** * Grant a privilege to PUBLIC. */ @Support({ H2, POSTGRES }) - GrantFinalStep toPublic(); + GrantGrantedStep toPublic(); } diff --git a/jOOQ/src/main/java/org/jooq/impl/GrantImpl.java b/jOOQ/src/main/java/org/jooq/impl/GrantImpl.java index 652bcaaf79..9dd1b1350a 100644 --- a/jOOQ/src/main/java/org/jooq/impl/GrantImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/GrantImpl.java @@ -46,6 +46,7 @@ import static org.jooq.impl.Keywords.K_GRANT; import static org.jooq.impl.Keywords.K_ON; import static org.jooq.impl.Keywords.K_PUBLIC; import static org.jooq.impl.Keywords.K_TO; +import static org.jooq.impl.Keywords.K_WITH_GRANT_OPTION; import java.util.Collection; @@ -53,6 +54,7 @@ import org.jooq.Clause; import org.jooq.Configuration; import org.jooq.Context; import org.jooq.GrantFinalStep; +import org.jooq.GrantGrantedStep; import org.jooq.GrantOnStep; import org.jooq.GrantToStep; import org.jooq.Name; @@ -70,6 +72,7 @@ final class GrantImpl extends AbstractQuery implements // Cascading interface implementations for Select behaviour GrantOnStep, GrantToStep, + GrantGrantedStep, GrantFinalStep { /** @@ -81,6 +84,7 @@ final class GrantImpl extends AbstractQuery implements private Role role; private Table table; private User user; + private boolean withGrantOption; GrantImpl(Configuration configuration, Collection privileges) { super(configuration); @@ -120,6 +124,10 @@ final class GrantImpl extends AbstractQuery implements else ctx.visit(K_PUBLIC); + if (withGrantOption) + ctx.sql(' ') + .visit(K_WITH_GRANT_OPTION); + ctx.end(GRANT_TO); } @@ -164,4 +172,10 @@ final class GrantImpl extends AbstractQuery implements public final GrantImpl toPublic() { return this; } + + @Override + public final GrantImpl withGrantOption() { + withGrantOption = true; + return this; + } } diff --git a/jOOQ/src/main/java/org/jooq/impl/Keywords.java b/jOOQ/src/main/java/org/jooq/impl/Keywords.java index e8174f9329..486f862505 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Keywords.java +++ b/jOOQ/src/main/java/org/jooq/impl/Keywords.java @@ -281,6 +281,7 @@ final class Keywords { static final Keyword K_WITH = keyword("with"); static final Keyword K_WITH_CHECK_OPTION = keyword("with check option"); static final Keyword K_WITH_DATA = keyword("with data"); + static final Keyword K_WITH_GRANT_OPTION = keyword("with grant option"); static final Keyword K_WITH_LOCK = keyword("with lock"); static final Keyword K_WITH_NO_DATA = keyword("with no data"); static final Keyword K_WITH_PRIMARY_KEY = keyword("with primary key");