From 8d0a0c617bff124bc2bb740fac4312a7b3bf0ffd Mon Sep 17 00:00:00 2001 From: Timur Shaidullin Date: Sun, 26 Nov 2017 22:58:55 +0300 Subject: [PATCH] [#6839] The Role type for GRANT statement --- jOOQ/src/main/java/org/jooq/Clause.java | 1 + jOOQ/src/main/java/org/jooq/Role.java | 48 +++++++++++ jOOQ/src/main/java/org/jooq/impl/DSL.java | 17 ++++ .../src/main/java/org/jooq/impl/RoleImpl.java | 81 +++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 jOOQ/src/main/java/org/jooq/Role.java create mode 100644 jOOQ/src/main/java/org/jooq/impl/RoleImpl.java diff --git a/jOOQ/src/main/java/org/jooq/Clause.java b/jOOQ/src/main/java/org/jooq/Clause.java index 3c0f5885a8..0a8f511ffe 100644 --- a/jOOQ/src/main/java/org/jooq/Clause.java +++ b/jOOQ/src/main/java/org/jooq/Clause.java @@ -47,6 +47,7 @@ public enum Clause { // ------------------------------------------------------------------------- USER, + ROLE, // ------------------------------------------------------------------------- // Clauses used in a any type of statement to model constraint references diff --git a/jOOQ/src/main/java/org/jooq/Role.java b/jOOQ/src/main/java/org/jooq/Role.java new file mode 100644 index 0000000000..6dad8dc3e5 --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/Role.java @@ -0,0 +1,48 @@ +/* + * 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; + +/** + * The Role to be used by GRANT statement + * + * @author Timur Shaidullin + */ +public interface Role extends QueryPart { + + /** + * The name of role + */ + public String getName(); +} diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index 618ef9a2db..10bf77f455 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -251,6 +251,7 @@ import org.jooq.RecordHandler; import org.jooq.RecordType; import org.jooq.Result; import org.jooq.ResultQuery; +import org.jooq.Role; import org.jooq.Row1; import org.jooq.Row10; import org.jooq.Row11; @@ -7873,6 +7874,22 @@ public class DSL { return new UserImpl(name); } + /** + * Create a new role reference + * + * @see #role(Name) + */ + public static Role role(String name) { + return role(name(name)); + } + + /** + * Create a new role reference + */ + public static Role role(Name name) { + return new RoleImpl(name); + } + // ------------------------------------------------------------------------- // XXX Conversion of objects into tables // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/RoleImpl.java b/jOOQ/src/main/java/org/jooq/impl/RoleImpl.java new file mode 100644 index 0000000000..d1165f5d9f --- /dev/null +++ b/jOOQ/src/main/java/org/jooq/impl/RoleImpl.java @@ -0,0 +1,81 @@ +/* + * 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 org.jooq.*; + +import static org.jooq.Clause.ROLE; + +/** + * A common implementation of the Role type + * + * @author Timur Shaidullin + */ +final class RoleImpl extends AbstractQueryPart implements Role { + + /** + * Generated UID + */ + private static final long serialVersionUID = -1169436492818811877L; + private static final Clause[] CLAUSES = { ROLE }; + private final Name name; + + RoleImpl(Name name) { + this.name = name; + } + + // ------------------------------------------------------------------------ + // XXX: QueryPart API + // ------------------------------------------------------------------------ + + @Override + public final void accept(Context ctx) { + ctx.visit(name); + } + + @Override + public final Clause[] clauses(Context ctx) { + return CLAUSES; + } + + // ------------------------------------------------------------------------ + // XXX: Role API + // ------------------------------------------------------------------------ + + @Override + public final String getName() { + return name.last(); + } +}