All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.prestosql.sql.tree.Revoke Maven / Gradle / Ivy

There is a newer version: 350
Show newest version
/*
 * 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.
 */
package io.prestosql.sql.tree;

import com.google.common.collect.ImmutableList;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static com.google.common.base.MoreObjects.toStringHelper;
import static java.util.Objects.requireNonNull;

public class Revoke
        extends Statement
{
    private final boolean grantOptionFor;
    private final Optional> privileges; // missing means ALL PRIVILEGES
    private final boolean table;
    private final QualifiedName tableName;
    private final PrincipalSpecification grantee;

    public Revoke(boolean grantOptionFor, Optional> privileges, boolean table, QualifiedName tableName, PrincipalSpecification grantee)
    {
        this(Optional.empty(), grantOptionFor, privileges, table, tableName, grantee);
    }

    public Revoke(NodeLocation location, boolean grantOptionFor, Optional> privileges, boolean table, QualifiedName tableName, PrincipalSpecification grantee)
    {
        this(Optional.of(location), grantOptionFor, privileges, table, tableName, grantee);
    }

    private Revoke(Optional location, boolean grantOptionFor, Optional> privileges, boolean table, QualifiedName tableName, PrincipalSpecification grantee)
    {
        super(location);
        this.grantOptionFor = grantOptionFor;
        requireNonNull(privileges, "privileges is null");
        this.privileges = privileges.map(ImmutableList::copyOf);
        this.table = table;
        this.tableName = requireNonNull(tableName, "tableName is null");
        this.grantee = requireNonNull(grantee, "grantee is null");
    }

    public boolean isGrantOptionFor()
    {
        return grantOptionFor;
    }

    public Optional> getPrivileges()
    {
        return privileges;
    }

    public boolean isTable()
    {
        return table;
    }

    public QualifiedName getTableName()
    {
        return tableName;
    }

    public PrincipalSpecification getGrantee()
    {
        return grantee;
    }

    @Override
    public  R accept(AstVisitor visitor, C context)
    {
        return visitor.visitRevoke(this, context);
    }

    @Override
    public List getChildren()
    {
        return ImmutableList.of();
    }

    @Override
    public int hashCode()
    {
        return Objects.hash(grantOptionFor, privileges, table, tableName, grantee);
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj) {
            return true;
        }
        if (obj == null || getClass() != obj.getClass()) {
            return false;
        }
        Revoke o = (Revoke) obj;
        return Objects.equals(grantOptionFor, o.grantOptionFor) &&
                Objects.equals(privileges, o.privileges) &&
                Objects.equals(table, o.table) &&
                Objects.equals(tableName, o.tableName) &&
                Objects.equals(grantee, o.grantee);
    }

    @Override
    public String toString()
    {
        return toStringHelper(this)
                .add("grantOptionFor", grantOptionFor)
                .add("privileges", privileges)
                .add("table", table)
                .add("tableName", tableName)
                .add("grantee", grantee)
                .toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy