Skip to content

Commit

Permalink
[#6913] Added a support for GRANT .. WITH GRANT OPTION
Browse files Browse the repository at this point in the history
  • Loading branch information
timur-sh committed Dec 19, 2017
1 parent 5bb2d17 commit 19287ad
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 3 deletions.
54 changes: 54 additions & 0 deletions 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 <code>GRANT</code> statement that assign user
* or role a grant option.
*
* @author Timur Shaidullin
*/
public interface GrantGrantedStep extends GrantFinalStep{
@Support({ POSTGRES, MYSQL, HSQLDB, FIREBIRD })
GrantFinalStep withGrantOption();
}
6 changes: 3 additions & 3 deletions jOOQ/src/main/java/org/jooq/GrantToStep.java
Expand Up @@ -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 <code>PUBLIC</code>.
*/
@Support({ H2, POSTGRES })
GrantFinalStep toPublic();
GrantGrantedStep toPublic();
}
14 changes: 14 additions & 0 deletions jOOQ/src/main/java/org/jooq/impl/GrantImpl.java
Expand Up @@ -46,13 +46,15 @@
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;

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;
Expand All @@ -70,6 +72,7 @@ final class GrantImpl extends AbstractQuery implements
// Cascading interface implementations for Select behaviour
GrantOnStep,
GrantToStep,
GrantGrantedStep,
GrantFinalStep {

/**
Expand All @@ -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<? extends Privilege> privileges) {
super(configuration);
Expand Down Expand Up @@ -120,6 +124,10 @@ else if (role != null)
else
ctx.visit(K_PUBLIC);

if (withGrantOption)
ctx.sql(' ')
.visit(K_WITH_GRANT_OPTION);

ctx.end(GRANT_TO);
}

Expand Down Expand Up @@ -164,4 +172,10 @@ public final GrantImpl to(Role r) {
public final GrantImpl toPublic() {
return this;
}

@Override
public final GrantImpl withGrantOption() {
withGrantOption = true;
return this;
}
}
1 change: 1 addition & 0 deletions jOOQ/src/main/java/org/jooq/impl/Keywords.java
Expand Up @@ -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");
Expand Down

0 comments on commit 19287ad

Please sign in to comment.