From 9ffd882d2f7f85eeb1ba6538de9efbeeacae1c2b Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Fri, 17 Jul 2020 12:57:28 +0200 Subject: [PATCH] [jOOQ/jOOQ#10418] GrantOnStep.on(String) and RevokeOnStep.on(String) should wrap String argument in Name --- jOOQ/src/main/java/org/jooq/DSLContext.java | 148 +++++---- .../main/java/org/jooq/GrantFinalStep.java | 29 +- jOOQ/src/main/java/org/jooq/GrantOnStep.java | 67 ++-- jOOQ/src/main/java/org/jooq/GrantToStep.java | 59 ++-- .../org/jooq/GrantWithGrantOptionStep.java | 45 +-- .../main/java/org/jooq/RevokeFinalStep.java | 29 +- .../main/java/org/jooq/RevokeFromStep.java | 59 ++-- jOOQ/src/main/java/org/jooq/RevokeOnStep.java | 67 ++-- jOOQ/src/main/java/org/jooq/impl/DSL.java | 294 ++++++------------ .../java/org/jooq/impl/DefaultDSLContext.java | 96 +++--- .../main/java/org/jooq/impl/GrantImpl.java | 214 +++++++------ .../main/java/org/jooq/impl/RevokeImpl.java | 178 ++++++----- 12 files changed, 650 insertions(+), 635 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/DSLContext.java b/jOOQ/src/main/java/org/jooq/DSLContext.java index 80ccff657e..196eb68953 100644 --- a/jOOQ/src/main/java/org/jooq/DSLContext.java +++ b/jOOQ/src/main/java/org/jooq/DSLContext.java @@ -9758,6 +9758,87 @@ public interface DSLContext extends Scope , AutoCloseable { @Support({ CUBRID, FIREBIRD, H2, HSQLDB, MARIADB, POSTGRES }) DropSequenceFinalStep dropSequenceIfExists(Sequence sequence); + /** + * The GRANT statement. + * + * @see DSL#grant(Privilege) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + GrantOnStep grant(Privilege privileges); + + /** + * The GRANT statement. + * + * @see DSL#grant(Privilege...) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + GrantOnStep grant(Privilege... privileges); + + /** + * The GRANT statement. + * + * @see DSL#grant(Collection) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + GrantOnStep grant(Collection privileges); + + /** + * The REVOKE statement. + * + * @see DSL#revoke(Privilege) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + RevokeOnStep revoke(Privilege privileges); + + /** + * The REVOKE statement. + * + * @see DSL#revoke(Privilege...) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + RevokeOnStep revoke(Privilege... privileges); + + /** + * The REVOKE statement. + * + * @see DSL#revoke(Collection) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + RevokeOnStep revoke(Collection privileges); + + /** + * The REVOKE GRANT OPTION FOR statement. + * + * @see DSL#revokeGrantOptionFor(Privilege) + */ + @NotNull + @Support({ HSQLDB, POSTGRES }) + RevokeOnStep revokeGrantOptionFor(Privilege privileges); + + /** + * The REVOKE GRANT OPTION FOR statement. + * + * @see DSL#revokeGrantOptionFor(Privilege...) + */ + @NotNull + @Support({ HSQLDB, POSTGRES }) + RevokeOnStep revokeGrantOptionFor(Privilege... privileges); + + /** + * The REVOKE GRANT OPTION FOR statement. + * + * @see DSL#revokeGrantOptionFor(Collection) + */ + @NotNull + @Support({ HSQLDB, POSTGRES }) + RevokeOnStep revokeGrantOptionFor(Collection privileges); + /** @@ -11264,73 +11345,6 @@ public interface DSLContext extends Scope , AutoCloseable { @Support TruncateIdentityStep truncateTable(Table table); - // ------------------------------------------------------------------------- - // XXX Access control - // ------------------------------------------------------------------------- - - /** - * Grant a privilege on a table to user or role. - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - GrantOnStep grant(Privilege privilege); - - /** - * Grant privileges on a table to user or role. - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - GrantOnStep grant(Privilege... privileges); - - /** - * Grant privileges on a table to user or role. - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - GrantOnStep grant(Collection privileges); - - /** - * Revoke a privilege on table from user or role. - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - RevokeOnStep revoke(Privilege privilege); - - /** - * Revoke privileges on table from user or role. - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - RevokeOnStep revoke(Privilege... privileges); - - /** - * Revoke privileges on table from user or role. - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - RevokeOnStep revoke(Collection privileges); - - /** - * Revoke grant option for a privilege on a table from user or role. - */ - @NotNull - @Support({ HSQLDB, POSTGRES }) - RevokeOnStep revokeGrantOptionFor(Privilege privilege); - - /** - * Revoke grant option for some privileges on a table from user or role. - */ - @NotNull - @Support({ HSQLDB, POSTGRES }) - RevokeOnStep revokeGrantOptionFor(Privilege... privileges); - - /** - * Revoke grant option for some privileges on a table from user or role. - */ - @NotNull - @Support({ HSQLDB, POSTGRES }) - RevokeOnStep revokeGrantOptionFor(Collection privileges); - // ------------------------------------------------------------------------- // XXX Other queries for identites and sequences // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/GrantFinalStep.java b/jOOQ/src/main/java/org/jooq/GrantFinalStep.java index 7b3f1c90bb..6a49819a41 100644 --- a/jOOQ/src/main/java/org/jooq/GrantFinalStep.java +++ b/jOOQ/src/main/java/org/jooq/GrantFinalStep.java @@ -37,12 +37,33 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + +import org.jetbrains.annotations.*; /** - * The final step in the creation of a REVOKE statement. - * - * @author Timur Shaidullin - * @author Lukas Eder + * A step in the construction of the GRANT statement. + *

+ *

Referencing XYZ*Step types directly from client code

+ *

+ * It is usually not recommended to reference any XYZ*Step types + * directly from client code, or assign them to local variables. When writing + * dynamic SQL, creating a statement's components dynamically, and passing them + * to the DSL API statically is usually a better choice. See the manual's + * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. + *

+ * Drawbacks of referencing the XYZ*Step types directly: + *

    + *
  • They're operating on mutable implementations (as of jOOQ 3.x)
  • + *
  • They're less composable and not easy to get right when dynamic SQL gets + * complex
  • + *
  • They're less readable
  • + *
  • They might have binary incompatible changes between minor releases
  • + *
*/ +@SuppressWarnings({ "unused" }) public interface GrantFinalStep extends DDLQuery { } diff --git a/jOOQ/src/main/java/org/jooq/GrantOnStep.java b/jOOQ/src/main/java/org/jooq/GrantOnStep.java index 283bcb7aec..7416b85a51 100644 --- a/jOOQ/src/main/java/org/jooq/GrantOnStep.java +++ b/jOOQ/src/main/java/org/jooq/GrantOnStep.java @@ -37,55 +37,54 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + import org.jetbrains.annotations.*; - -// ... -// ... -// ... -import static org.jooq.SQLDialect.DERBY; -import static org.jooq.SQLDialect.H2; -import static org.jooq.SQLDialect.HSQLDB; -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... - /** - * The step in the creation of a GRANT statement where the - * ON clause can be added. - * - * @author Timur Shaidullin - * @author Lukas Eder + * A step in the construction of the GRANT statement. + *

+ *

Referencing XYZ*Step types directly from client code

+ *

+ * It is usually not recommended to reference any XYZ*Step types + * directly from client code, or assign them to local variables. When writing + * dynamic SQL, creating a statement's components dynamically, and passing them + * to the DSL API statically is usually a better choice. See the manual's + * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. + *

+ * Drawbacks of referencing the XYZ*Step types directly: + *

    + *
  • They're operating on mutable implementations (as of jOOQ 3.x)
  • + *
  • They're less composable and not easy to get right when dynamic SQL gets + * complex
  • + *
  • They're less readable
  • + *
  • They might have binary incompatible changes between minor releases
  • + *
*/ +@SuppressWarnings({ "unused" }) public interface GrantOnStep { /** - * Grant a privilege on a table. + * Add the ON clause to the GRANT statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - GrantToStep on(Table table); + @NotNull + GrantToStep on(String on); /** - * Grant a privilege on a table. + * Add the ON clause to the GRANT statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - GrantToStep on(Name table); + @NotNull + GrantToStep on(Name on); /** - * Grant a privilege on a table. - *

- * NOTE: When inserting plain SQL into jOOQ objects, you must - * guarantee syntax integrity. You may also create the possibility of - * malicious SQL injection. Be sure to properly use bind variables and/or - * escape literals when concatenated into SQL clauses! + * Add the ON clause to the GRANT statement. */ - @PlainSQL - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - GrantToStep on(String table); + @NotNull + GrantToStep on(Table on); } diff --git a/jOOQ/src/main/java/org/jooq/GrantToStep.java b/jOOQ/src/main/java/org/jooq/GrantToStep.java index fae2bb2e89..767e401cab 100644 --- a/jOOQ/src/main/java/org/jooq/GrantToStep.java +++ b/jOOQ/src/main/java/org/jooq/GrantToStep.java @@ -37,49 +37,54 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + import org.jetbrains.annotations.*; - -// ... -// ... -// ... -import static org.jooq.SQLDialect.DERBY; -import static org.jooq.SQLDialect.H2; -import static org.jooq.SQLDialect.HSQLDB; -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... - /** - * The step in the creation of a GRANT statement where the - * TO clause can be added. - * - * @author Timur Shaidullin - * @author Lukas Eder + * A step in the construction of the GRANT statement. + *

+ *

Referencing XYZ*Step types directly from client code

+ *

+ * It is usually not recommended to reference any XYZ*Step types + * directly from client code, or assign them to local variables. When writing + * dynamic SQL, creating a statement's components dynamically, and passing them + * to the DSL API statically is usually a better choice. See the manual's + * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. + *

+ * Drawbacks of referencing the XYZ*Step types directly: + *

    + *
  • They're operating on mutable implementations (as of jOOQ 3.x)
  • + *
  • They're less composable and not easy to get right when dynamic SQL gets + * complex
  • + *
  • They're less readable
  • + *
  • They might have binary incompatible changes between minor releases
  • + *
*/ +@SuppressWarnings({ "unused" }) public interface GrantToStep { /** - * Grant a privilege to a user. + * Add the TO clause to the GRANT statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - GrantWithGrantOptionStep to(User user); + @NotNull + GrantWithGrantOptionStep to(User to); /** - * Grant a privilege to a role. + * Add the TO clause to the GRANT statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - GrantWithGrantOptionStep to(Role role); + @NotNull + GrantWithGrantOptionStep to(Role to); /** - * Grant a privilege to PUBLIC. + * Add the TO PUBLIC clause to the GRANT statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @NotNull GrantWithGrantOptionStep toPublic(); } diff --git a/jOOQ/src/main/java/org/jooq/GrantWithGrantOptionStep.java b/jOOQ/src/main/java/org/jooq/GrantWithGrantOptionStep.java index f157b4d813..772f770ab8 100644 --- a/jOOQ/src/main/java/org/jooq/GrantWithGrantOptionStep.java +++ b/jOOQ/src/main/java/org/jooq/GrantWithGrantOptionStep.java @@ -37,31 +37,40 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + import org.jetbrains.annotations.*; - -// ... -// ... -import static org.jooq.SQLDialect.HSQLDB; -import static org.jooq.SQLDialect.MARIADB; -// ... -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 + * A step in the construction of the GRANT statement. + *

+ *

Referencing XYZ*Step types directly from client code

+ *

+ * It is usually not recommended to reference any XYZ*Step types + * directly from client code, or assign them to local variables. When writing + * dynamic SQL, creating a statement's components dynamically, and passing them + * to the DSL API statically is usually a better choice. See the manual's + * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. + *

+ * Drawbacks of referencing the XYZ*Step types directly: + *

    + *
  • They're operating on mutable implementations (as of jOOQ 3.x)
  • + *
  • They're less composable and not easy to get right when dynamic SQL gets + * complex
  • + *
  • They're less readable
  • + *
  • They might have binary incompatible changes between minor releases
  • + *
*/ -public interface GrantWithGrantOptionStep extends GrantFinalStep{ +@SuppressWarnings({ "unused" }) +public interface GrantWithGrantOptionStep extends GrantFinalStep { /** - * Add the WITH GRANT OPTION clause. + * Add the WITH GRANT OPTION clause to the GRANT statement. */ - @NotNull @Support({ HSQLDB, MARIADB, MYSQL, POSTGRES }) + @NotNull GrantFinalStep withGrantOption(); } diff --git a/jOOQ/src/main/java/org/jooq/RevokeFinalStep.java b/jOOQ/src/main/java/org/jooq/RevokeFinalStep.java index 8919fbb950..1a31805415 100644 --- a/jOOQ/src/main/java/org/jooq/RevokeFinalStep.java +++ b/jOOQ/src/main/java/org/jooq/RevokeFinalStep.java @@ -37,12 +37,33 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + +import org.jetbrains.annotations.*; /** - * The final step in the creation of a REVOKE statement. - * - * @author Timur Shaidullin - * @author Lukas Eder + * A step in the construction of the REVOKE statement. + *

+ *

Referencing XYZ*Step types directly from client code

+ *

+ * It is usually not recommended to reference any XYZ*Step types + * directly from client code, or assign them to local variables. When writing + * dynamic SQL, creating a statement's components dynamically, and passing them + * to the DSL API statically is usually a better choice. See the manual's + * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. + *

+ * Drawbacks of referencing the XYZ*Step types directly: + *

    + *
  • They're operating on mutable implementations (as of jOOQ 3.x)
  • + *
  • They're less composable and not easy to get right when dynamic SQL gets + * complex
  • + *
  • They're less readable
  • + *
  • They might have binary incompatible changes between minor releases
  • + *
*/ +@SuppressWarnings({ "unused" }) public interface RevokeFinalStep extends DDLQuery { } diff --git a/jOOQ/src/main/java/org/jooq/RevokeFromStep.java b/jOOQ/src/main/java/org/jooq/RevokeFromStep.java index 9984696d02..bb90245ea2 100644 --- a/jOOQ/src/main/java/org/jooq/RevokeFromStep.java +++ b/jOOQ/src/main/java/org/jooq/RevokeFromStep.java @@ -37,49 +37,54 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + import org.jetbrains.annotations.*; - -// ... -// ... -// ... -import static org.jooq.SQLDialect.DERBY; -import static org.jooq.SQLDialect.H2; -import static org.jooq.SQLDialect.HSQLDB; -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... - /** - * The step in the creation of a REVOKE statement where the - * FROM clause can be added. - * - * @author Timur Shaidullin - * @author Lukas Eder + * A step in the construction of the REVOKE statement. + *

+ *

Referencing XYZ*Step types directly from client code

+ *

+ * It is usually not recommended to reference any XYZ*Step types + * directly from client code, or assign them to local variables. When writing + * dynamic SQL, creating a statement's components dynamically, and passing them + * to the DSL API statically is usually a better choice. See the manual's + * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. + *

+ * Drawbacks of referencing the XYZ*Step types directly: + *

    + *
  • They're operating on mutable implementations (as of jOOQ 3.x)
  • + *
  • They're less composable and not easy to get right when dynamic SQL gets + * complex
  • + *
  • They're less readable
  • + *
  • They might have binary incompatible changes between minor releases
  • + *
*/ +@SuppressWarnings({ "unused" }) public interface RevokeFromStep { /** - * Revoke a privilege from a user. + * Add the FROM clause to the REVOKE statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - RevokeFinalStep from(User user); + @NotNull + RevokeFinalStep from(User from); /** - * Revoke a privilege from a role. + * Add the FROM clause to the REVOKE statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - RevokeFinalStep from(Role role); + @NotNull + RevokeFinalStep from(Role from); /** - * Revoke a privilege from PUBLIC. + * Add the FROM PUBLIC clause to the REVOKE statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + @NotNull RevokeFinalStep fromPublic(); } diff --git a/jOOQ/src/main/java/org/jooq/RevokeOnStep.java b/jOOQ/src/main/java/org/jooq/RevokeOnStep.java index e5af142033..3d4bd0988d 100644 --- a/jOOQ/src/main/java/org/jooq/RevokeOnStep.java +++ b/jOOQ/src/main/java/org/jooq/RevokeOnStep.java @@ -37,55 +37,54 @@ */ package org.jooq; +import static org.jooq.SQLDialect.*; + +import java.util.*; + import org.jetbrains.annotations.*; - -// ... -// ... -// ... -import static org.jooq.SQLDialect.DERBY; -import static org.jooq.SQLDialect.H2; -import static org.jooq.SQLDialect.HSQLDB; -import static org.jooq.SQLDialect.MARIADB; -// ... -import static org.jooq.SQLDialect.MYSQL; -// ... -import static org.jooq.SQLDialect.POSTGRES; -// ... - /** - * The step in the creation of a REVOKE statement where the - * ON clause can be added. - * - * @author Timur Shaidullin - * @author Lukas Eder + * A step in the construction of the REVOKE statement. + *

+ *

Referencing XYZ*Step types directly from client code

+ *

+ * It is usually not recommended to reference any XYZ*Step types + * directly from client code, or assign them to local variables. When writing + * dynamic SQL, creating a statement's components dynamically, and passing them + * to the DSL API statically is usually a better choice. See the manual's + * section about dynamic SQL for details: https://www.jooq.org/doc/latest/manual/sql-building/dynamic-sql. + *

+ * Drawbacks of referencing the XYZ*Step types directly: + *

    + *
  • They're operating on mutable implementations (as of jOOQ 3.x)
  • + *
  • They're less composable and not easy to get right when dynamic SQL gets + * complex
  • + *
  • They're less readable
  • + *
  • They might have binary incompatible changes between minor releases
  • + *
*/ +@SuppressWarnings({ "unused" }) public interface RevokeOnStep { /** - * Revoke a privilege on a table. + * Add the ON clause to the REVOKE statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - RevokeFromStep on(Table table); + @NotNull + RevokeFromStep on(String on); /** - * Revoke a privilege on a table. + * Add the ON clause to the REVOKE statement. */ - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - RevokeFromStep on(Name table); + @NotNull + RevokeFromStep on(Name on); /** - * Revoke a privilege on a table. - *

- * NOTE: When inserting plain SQL into jOOQ objects, you must - * guarantee syntax integrity. You may also create the possibility of - * malicious SQL injection. Be sure to properly use bind variables and/or - * escape literals when concatenated into SQL clauses! + * Add the ON clause to the REVOKE statement. */ - @PlainSQL - @NotNull @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - RevokeFromStep on(String table); + @NotNull + RevokeFromStep on(Table on); } diff --git a/jOOQ/src/main/java/org/jooq/impl/DSL.java b/jOOQ/src/main/java/org/jooq/impl/DSL.java index d7deb74421..b1c0374d4f 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DSL.java +++ b/jOOQ/src/main/java/org/jooq/impl/DSL.java @@ -205,7 +205,6 @@ import org.jooq.False; import org.jooq.Field; import org.jooq.FieldOrRow; // ... -import org.jooq.GrantOnStep; import org.jooq.GroupConcatOrderByStep; import org.jooq.GroupConcatSeparatorStep; import org.jooq.GroupField; @@ -318,7 +317,6 @@ import org.jooq.RecordType; // ... import org.jooq.Result; import org.jooq.ResultQuery; -import org.jooq.RevokeOnStep; import org.jooq.Role; import org.jooq.Row; import org.jooq.Row1; @@ -7871,6 +7869,105 @@ public class DSL { return dsl().dropSequenceIfExists(sequence); } + /** + * The GRANT statement. + * + * @see DSLContext#grant(Privilege) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + public static org.jooq.GrantOnStep grant(Privilege privileges) { + return dsl().grant(privileges); + } + + /** + * The GRANT statement. + * + * @see DSLContext#grant(Privilege...) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + public static org.jooq.GrantOnStep grant(Privilege... privileges) { + return dsl().grant(privileges); + } + + /** + * The GRANT statement. + * + * @see DSLContext#grant(Collection) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + public static org.jooq.GrantOnStep grant(Collection privileges) { + return dsl().grant(privileges); + } + + /** + * The REVOKE statement. + * + * @see DSLContext#revoke(Privilege) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + public static org.jooq.RevokeOnStep revoke(Privilege privileges) { + return dsl().revoke(privileges); + } + + /** + * The REVOKE statement. + * + * @see DSLContext#revoke(Privilege...) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + public static org.jooq.RevokeOnStep revoke(Privilege... privileges) { + return dsl().revoke(privileges); + } + + /** + * The REVOKE statement. + * + * @see DSLContext#revoke(Collection) + */ + @NotNull + @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) + public static org.jooq.RevokeOnStep revoke(Collection privileges) { + return dsl().revoke(privileges); + } + + /** + * The REVOKE GRANT OPTION FOR statement. + * + * @see DSLContext#revokeGrantOptionFor(Privilege) + */ + @NotNull + @Support({ HSQLDB, POSTGRES }) + public static org.jooq.RevokeOnStep revokeGrantOptionFor(Privilege privileges) { + return dsl().revokeGrantOptionFor(privileges); + } + + /** + * The REVOKE GRANT OPTION FOR statement. + * + * @see DSLContext#revokeGrantOptionFor(Privilege...) + */ + @NotNull + @Support({ HSQLDB, POSTGRES }) + public static org.jooq.RevokeOnStep revokeGrantOptionFor(Privilege... privileges) { + return dsl().revokeGrantOptionFor(privileges); + } + + /** + * The REVOKE GRANT OPTION FOR statement. + * + * @see DSLContext#revokeGrantOptionFor(Collection) + */ + @NotNull + @Support({ HSQLDB, POSTGRES }) + public static org.jooq.RevokeOnStep revokeGrantOptionFor(Collection privileges) { + return dsl().revokeGrantOptionFor(privileges); + } + /** @@ -9544,199 +9641,6 @@ public class DSL { return new QuantifiedSelectImpl<>(Quantifier.ANY, fields); } - // ------------------------------------------------------------------------- - // XXX Access control - // ------------------------------------------------------------------------- - - /** - * Grant a privilege on table to user or role. - * - *

- * Example:

-     * import static org.jooq.impl.DSL.*;
-     *
-     * grant(privilege)
-     *   .on(table)
-     *   .to(user)
-     *   .execute();
-     *
-     * grant(privilege)
-     *   .on(table)
-     *   .to(role)
-     *   .execute();
-     * 
- * - * - * @see #grant(Collection) - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - public static GrantOnStep grant(Privilege privilege) { - return dsl().grant(privilege); - } - - /** - * Grant privileges on table to user or role. - * - *

- * Example:

-     * import static org.jooq.impl.DSL.*;
-     *
-     * grant(privilege)
-     *   .on(table)
-     *   .to(user)
-     *   .execute();
-     *
-     * grant(privilege)
-     *   .on(table)
-     *   .to(role)
-     *   .execute();
-     * 
- * - * - * @see #grant(Collection) - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - public static GrantOnStep grant(Privilege... privileges) { - return dsl().grant(privileges); - } - - /** - * Grant privileges on table to user or role. - * - *

- * Example:

-     * import static org.jooq.impl.DSL.*;
-     *
-     * grant(privileges)
-     *   .on(table)
-     *   .to(user)
-     *   .execute();
-     *
-     * grant(privileges)
-     *   .on(table)
-     *   .to(role)
-     *   .execute();
-     * 
- *

- * - * @see #grant(Privilege...) - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - public static GrantOnStep grant(Collection privileges) { - return dsl().grant(privileges); - } - - /** - * Revoke a privilege on table from user or role. - * - *

- * Example:

-     * import static org.jooq.impl.DSL.*;
-     *
-     * revoke(privilege)
-     *   .on(table)
-     *   .from(user)
-     *   .execute();
-     *
-     * revoke(privilege)
-     *   .on(table)
-     *   .from(role)
-     *   .execute();
-     * 
- *

- * - * @see #revoke(Collection) - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - public static RevokeOnStep revoke(Privilege privilege) { - return dsl().revoke(privilege); - } - - /** - * Revoke privileges on table from user or role. - * - *

- * Example:

-     * import static org.jooq.impl.DSL.*;
-     *
-     * revoke(privilege)
-     *   .on(table)
-     *   .from(user)
-     *   .execute();
-     *
-     * revoke(privilege)
-     *   .on(table)
-     *   .from(role)
-     *   .execute();
-     * 
- *

- * - * @see #revoke(Collection) - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - public static RevokeOnStep revoke(Privilege... privileges) { - return dsl().revoke(privileges); - } - - /** - * Revoke privileges on table from user or role. - * - *

- * Example:

-     * import static org.jooq.impl.DSL.*;
-     *
-     * revoke(privileges)
-     *   .on(table)
-     *   .from(user)
-     *   .execute();
-     *
-     * revoke(privileges)
-     *   .on(table)
-     *   .from(role)
-     *   .execute();
-     * 
- *

- * - * @see #revoke(Privilege...) - */ - @NotNull - @Support({ DERBY, H2, HSQLDB, MARIADB, MYSQL, POSTGRES }) - public static RevokeOnStep revoke(Collection privileges) { - return dsl().revoke(privileges); - } - - /** - * Revoke grant option for a privilege on a table from user or role. - */ - @NotNull - @Support({ HSQLDB, POSTGRES }) - public static RevokeOnStep revokeGrantOptionFor(Privilege privilege) { - return dsl().revoke(privilege); - } - - /** - * Revoke grant option for some privileges on a table from user or role. - */ - @NotNull - @Support({ HSQLDB, POSTGRES }) - public static RevokeOnStep revokeGrantOptionFor(Privilege... privileges) { - return dsl().revoke(privileges); - } - - /** - * Revoke grant option for some privileges on a table from user or role. - */ - @NotNull - @Support({ HSQLDB, POSTGRES }) - public static RevokeOnStep revokeGrantOptionFor(Collection privileges) { - return dsl().revoke(privileges); - } - // ------------------------------------------------------------------------- // XXX Other objects // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java index e0746a3a3a..72aba6ffe2 100644 --- a/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java +++ b/jOOQ/src/main/java/org/jooq/impl/DefaultDSLContext.java @@ -133,7 +133,6 @@ import org.jooq.ExecuteContext; import org.jooq.ExecuteListener; import org.jooq.Explain; import org.jooq.Field; -import org.jooq.GrantOnStep; import org.jooq.Index; import org.jooq.InsertQuery; import org.jooq.InsertSetStep; @@ -222,7 +221,6 @@ import org.jooq.RenderContext; import org.jooq.Result; import org.jooq.ResultQuery; import org.jooq.Results; -import org.jooq.RevokeOnStep; import org.jooq.RowCountQuery; import org.jooq.SQL; import org.jooq.SQLDialect; @@ -3244,6 +3242,51 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new DropSequenceImpl(configuration(), sequence, true); } + @Override + public org.jooq.GrantOnStep grant(Privilege privileges) { + return new GrantImpl(configuration(), Arrays.asList(privileges)); + } + + @Override + public org.jooq.GrantOnStep grant(Privilege... privileges) { + return new GrantImpl(configuration(), Arrays.asList(privileges)); + } + + @Override + public org.jooq.GrantOnStep grant(Collection privileges) { + return new GrantImpl(configuration(), privileges); + } + + @Override + public org.jooq.RevokeOnStep revoke(Privilege privileges) { + return new RevokeImpl(configuration(), Arrays.asList(privileges), false); + } + + @Override + public org.jooq.RevokeOnStep revoke(Privilege... privileges) { + return new RevokeImpl(configuration(), Arrays.asList(privileges), false); + } + + @Override + public org.jooq.RevokeOnStep revoke(Collection privileges) { + return new RevokeImpl(configuration(), privileges, false); + } + + @Override + public org.jooq.RevokeOnStep revokeGrantOptionFor(Privilege privileges) { + return new RevokeImpl(configuration(), Arrays.asList(privileges), true); + } + + @Override + public org.jooq.RevokeOnStep revokeGrantOptionFor(Privilege... privileges) { + return new RevokeImpl(configuration(), Arrays.asList(privileges), true); + } + + @Override + public org.jooq.RevokeOnStep revokeGrantOptionFor(Collection privileges) { + return new RevokeImpl(configuration(), privileges, true); + } + @Override @@ -4026,55 +4069,6 @@ public class DefaultDSLContext extends AbstractScope implements DSLContext, Seri return new TruncateImpl<>(configuration(), table); } - // ------------------------------------------------------------------------- - // XXX Access control - // ------------------------------------------------------------------------- - - @Override - public GrantOnStep grant(Privilege privilege) { - return grant(Arrays.asList(privilege)); - } - - @Override - public GrantOnStep grant(Privilege... privileges) { - return grant(Arrays.asList(privileges)); - } - - @Override - public GrantOnStep grant(Collection privileges) { - return new GrantImpl(configuration(), privileges); - } - - @Override - public RevokeOnStep revoke(Privilege privilege) { - return revoke(Arrays.asList(privilege)); - } - - @Override - public RevokeOnStep revoke(Privilege... privileges) { - return revoke(Arrays.asList(privileges)); - } - - @Override - public RevokeOnStep revoke(Collection privileges) { - return new RevokeImpl(configuration(), privileges); - } - - @Override - public RevokeOnStep revokeGrantOptionFor(Privilege privilege) { - return revokeGrantOptionFor(Arrays.asList(privilege)); - } - - @Override - public RevokeOnStep revokeGrantOptionFor(Privilege... privileges) { - return revokeGrantOptionFor(Arrays.asList(privileges)); - } - - @Override - public RevokeOnStep revokeGrantOptionFor(Collection privileges) { - return new RevokeImpl(configuration(), privileges, true); - } - // ------------------------------------------------------------------------- // XXX Other queries for identites and sequences // ------------------------------------------------------------------------- diff --git a/jOOQ/src/main/java/org/jooq/impl/GrantImpl.java b/jOOQ/src/main/java/org/jooq/impl/GrantImpl.java index 91e0b702ab..decc1398ee 100644 --- a/jOOQ/src/main/java/org/jooq/impl/GrantImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/GrantImpl.java @@ -37,90 +37,151 @@ */ package org.jooq.impl; -import static org.jooq.Clause.GRANT; -import static org.jooq.Clause.GRANT_ON; -import static org.jooq.Clause.GRANT_PRIVILEGE; -import static org.jooq.Clause.GRANT_TO; -import static org.jooq.impl.DSL.table; -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 static org.jooq.impl.QueryPartCollectionView.wrap; +import static org.jooq.impl.DSL.*; +import static org.jooq.impl.Keywords.*; +import static org.jooq.impl.Names.*; +import static org.jooq.impl.SQLDataType.*; +import static org.jooq.impl.Tools.BooleanDataKey.*; +import static org.jooq.SQLDialect.*; -import java.util.Collection; +import org.jooq.*; +import org.jooq.impl.*; -import org.jooq.Clause; -import org.jooq.Configuration; -import org.jooq.Context; -import org.jooq.GrantOnStep; -import org.jooq.GrantToStep; -import org.jooq.GrantWithGrantOptionStep; -import org.jooq.Name; -import org.jooq.Privilege; -import org.jooq.Role; -import org.jooq.Table; -import org.jooq.User; +import java.util.*; /** - * Grant privilege or privileges on a table to user or role. - * - * @author Timur Shaidullin + * The GRANT statement. */ -final class GrantImpl extends AbstractRowCountQuery implements - - // Cascading interface implementations for Select behaviour +@SuppressWarnings({ "hiding", "rawtypes", "unchecked", "unused" }) +final class GrantImpl +extends + AbstractRowCountQuery +implements GrantOnStep, GrantToStep, - GrantWithGrantOptionStep { + GrantWithGrantOptionStep, + GrantFinalStep +{ + + private static final long serialVersionUID = 1L; - /** - * Generated UID - */ - private static final long serialVersionUID = -6509384254822040545L; - private static final Clause[] CLAUSE = { GRANT }; private final Collection privileges; - private Role role; - private Table table; - private User user; - private boolean withGrantOption; + private Table on; + private Role to; + private Boolean toPublic; + private Boolean withGrantOption; + + GrantImpl( + Configuration configuration, + Collection privileges + ) { + this( + configuration, + privileges, + null, + null, + null, + null + ); + } - GrantImpl(Configuration configuration, Collection privileges) { + GrantImpl( + Configuration configuration, + Collection privileges, + Table on, + Role to, + Boolean toPublic, + Boolean withGrantOption + ) { super(configuration); this.privileges = privileges; + this.on = on; + this.to = to; + this.toPublic = toPublic; + this.withGrantOption = withGrantOption; } - // ------------------------------------------------------------------------ + final Collection $privileges() { return privileges; } + final Table $on() { return on; } + final Role $to() { return to; } + final Boolean $toPublic() { return toPublic; } + final Boolean $withGrantOption() { return withGrantOption; } + + // ------------------------------------------------------------------------- + // XXX: DSL API + // ------------------------------------------------------------------------- + + @Override + public final GrantImpl on(String on) { + return on(DSL.table(DSL.name(on))); + } + + @Override + public final GrantImpl on(Name on) { + return on(DSL.table(on)); + } + + @Override + public final GrantImpl on(Table on) { + this.on = on; + return this; + } + + @Override + public final GrantImpl to(User to) { + return to(DSL.role(to.getName())); + } + + @Override + public final GrantImpl to(Role to) { + this.to = to; + return this; + } + + @Override + public final GrantImpl toPublic() { + this.toPublic = true; + return this; + } + + @Override + public final GrantImpl withGrantOption() { + this.withGrantOption = true; + return this; + } + + // ------------------------------------------------------------------------- // XXX: QueryPart API - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- + + + + private static final Clause[] CLAUSE = { Clause.GRANT }; @Override public final void accept(Context ctx) { - ctx.start(GRANT_PRIVILEGE) + ctx.start(Clause.GRANT_PRIVILEGE) .visit(K_GRANT).sql(' ') - .visit(wrap(privileges).indentSize(0)) - .end(GRANT_PRIVILEGE).sql(' ') - .start(GRANT_ON) + .visit(QueryPartCollectionView.wrap(privileges).indentSize(0)) + .end(Clause.GRANT_PRIVILEGE).sql(' ') + .start(Clause.GRANT_ON) .visit(K_ON).sql(' ') - .visit(table) - .end(GRANT_ON).sql(' ') - .start(GRANT_TO) + .visit(on) + .end(Clause.GRANT_ON).sql(' ') + .start(Clause.GRANT_TO) .visit(K_TO).sql(' '); - if (user != null) - ctx.visit(user); - else if (role != null) - ctx.visit(role); - else + if (to != null) + ctx.visit(to); + else if (Boolean.TRUE.equals(toPublic)) ctx.visit(K_PUBLIC); - if (withGrantOption) + if (Boolean.TRUE.equals(withGrantOption)) ctx.sql(' ') .visit(K_WITH_GRANT_OPTION); - ctx.end(GRANT_TO); + ctx.end(Clause.GRANT_TO); } @Override @@ -128,46 +189,5 @@ final class GrantImpl extends AbstractRowCountQuery implements return CLAUSE; } - // ------------------------------------------------------------------------ - // XXX: GrantImpl API - // ------------------------------------------------------------------------ - @Override - public final GrantImpl on(Table t) { - this.table = t; - return this; - } - - @Override - public final GrantImpl on(Name t) { - return on(table(t)); - } - - @Override - public final GrantImpl on(String t) { - return on(table(t)); - } - - @Override - public final GrantImpl to(User u) { - this.user = u; - return this; - } - - @Override - public final GrantImpl to(Role r) { - this.role = r; - return this; - } - - @Override - 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/RevokeImpl.java b/jOOQ/src/main/java/org/jooq/impl/RevokeImpl.java index 88e0f8bd4a..2e8bc73791 100644 --- a/jOOQ/src/main/java/org/jooq/impl/RevokeImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/RevokeImpl.java @@ -37,19 +37,13 @@ */ package org.jooq.impl; -import static org.jooq.Clause.REVOKE; -import static org.jooq.Clause.REVOKE_FROM; -import static org.jooq.Clause.REVOKE_ON; -import static org.jooq.Clause.REVOKE_PRIVILEGE; import static org.jooq.SQLDialect.HSQLDB; -import static org.jooq.impl.DSL.table; import static org.jooq.impl.Keywords.K_FROM; import static org.jooq.impl.Keywords.K_GRANT_OPTION_FOR; import static org.jooq.impl.Keywords.K_ON; import static org.jooq.impl.Keywords.K_PUBLIC; import static org.jooq.impl.Keywords.K_RESTRICT; import static org.jooq.impl.Keywords.K_REVOKE; -import static org.jooq.impl.QueryPartCollectionView.wrap; import java.util.Collection; @@ -66,71 +60,136 @@ import org.jooq.Table; import org.jooq.User; /** - * Revoke privilege or privileges on a table from user or role. - * - * @author Timur Shaidullin + * The REVOKE GRANT OPTION FOR statement. */ -final class RevokeImpl extends AbstractRowCountQuery implements - - // Cascading interface implementations for Select behaviour +@SuppressWarnings({ "hiding", "rawtypes", "unchecked", "unused" }) +final class RevokeImpl +extends + AbstractRowCountQuery +implements RevokeOnStep, RevokeFromStep, - RevokeFinalStep { + RevokeFinalStep +{ + + private static final long serialVersionUID = 1L; - /** - * Generated UID - */ - private static final long serialVersionUID = -5777612075774539326L; - private static final Clause[] CLAUSE = { REVOKE }; private final Collection privileges; - private Role role; - private Table table; - private User user; - private final boolean grantOptionFor; + private final boolean revokeGrantOptionFor; + private Table on; + private Role from; + private Boolean fromPublic; - RevokeImpl(Configuration configuration, Collection privileges, boolean grantOptionFor) { + RevokeImpl( + Configuration configuration, + Collection privileges, + boolean revokeGrantOptionFor + ) { + this( + configuration, + privileges, + revokeGrantOptionFor, + null, + null, + null + ); + } + + RevokeImpl( + Configuration configuration, + Collection privileges, + boolean revokeGrantOptionFor, + Table on, + Role from, + Boolean fromPublic + ) { super(configuration); + this.privileges = privileges; - this.grantOptionFor = grantOptionFor; + this.revokeGrantOptionFor = revokeGrantOptionFor; + this.on = on; + this.from = from; + this.fromPublic = fromPublic; } - RevokeImpl(Configuration configuration, Collection privileges) { - this(configuration, privileges, false); + final Collection $privileges() { return privileges; } + final boolean $revokeGrantOptionFor() { return revokeGrantOptionFor; } + final Table $on() { return on; } + final Role $from() { return from; } + final Boolean $fromPublic() { return fromPublic; } + + // ------------------------------------------------------------------------- + // XXX: DSL API + // ------------------------------------------------------------------------- + + @Override + public final RevokeImpl on(String on) { + return on(DSL.table(DSL.name(on))); } - // ------------------------------------------------------------------------ + @Override + public final RevokeImpl on(Name on) { + return on(DSL.table(on)); + } + + @Override + public final RevokeImpl on(Table on) { + this.on = on; + return this; + } + + @Override + public final RevokeImpl from(User from) { + return from(DSL.role(from.getName())); + } + + @Override + public final RevokeImpl from(Role from) { + this.from = from; + return this; + } + + @Override + public final RevokeImpl fromPublic() { + this.fromPublic = true; + return this; + } + + // ------------------------------------------------------------------------- // XXX: QueryPart API - // ------------------------------------------------------------------------ + // ------------------------------------------------------------------------- + + + + private static final Clause[] CLAUSE = { Clause.REVOKE }; @Override public final void accept(Context ctx) { - ctx.start(REVOKE_PRIVILEGE) + ctx.start(Clause.REVOKE_PRIVILEGE) .visit(K_REVOKE).sql(' '); - if (grantOptionFor) + if (revokeGrantOptionFor) ctx.visit(K_GRANT_OPTION_FOR) .sql(' '); - ctx.visit(wrap(privileges).indentSize(0)) - .end(REVOKE_PRIVILEGE).sql(' ') - .start(REVOKE_ON) + ctx.visit(QueryPartCollectionView.wrap(privileges).indentSize(0)) + .end(Clause.REVOKE_PRIVILEGE).sql(' ') + .start(Clause.REVOKE_ON) .visit(K_ON).sql(' ') - .visit(table) - .end(REVOKE_ON).sql(' ') - .start(REVOKE_FROM) + .visit(on) + .end(Clause.REVOKE_ON).sql(' ') + .start(Clause.REVOKE_FROM) .visit(K_FROM).sql(' '); - if (user != null) - ctx.visit(user); - else if (role != null) - ctx.visit(role); - else + if (from != null) + ctx.visit(from); + else if (Boolean.TRUE.equals(fromPublic)) ctx.visit(K_PUBLIC); if (ctx.family() == HSQLDB) ctx.sql(' ').visit(K_RESTRICT); - ctx.end(REVOKE_FROM); + ctx.end(Clause.REVOKE_FROM); } @Override @@ -138,40 +197,5 @@ final class RevokeImpl extends AbstractRowCountQuery implements return CLAUSE; } - // ------------------------------------------------------------------------ - // XXX: RevokeImpl API - // ------------------------------------------------------------------------ - @Override - public final RevokeImpl on(Table t) { - this.table = t; - return this; - } - - @Override - public final RevokeImpl on(Name t) { - return on(table(t)); - } - - @Override - public final RevokeImpl on(String t) { - return on(table(t)); - } - - @Override - public final RevokeImpl from(User u) { - this.user = u; - return this; - } - - @Override - public final RevokeImpl from(Role r) { - this.role = r; - return this; - } - - @Override - public final RevokeImpl fromPublic() { - return this; - } }