[#6913] Added a support for GRANT .. WITH GRANT OPTION

This commit is contained in:
Timur Shaidullin 2017-12-19 13:39:01 +03:00
parent 5bb2d17f9d
commit 19287add9d
4 changed files with 72 additions and 3 deletions

View File

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

View File

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

View File

@ -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<? extends Privilege> 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;
}
}

View File

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