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

net.sf.jsqlparser.util.deparser.GrantDeParser Maven / Gradle / Ivy

Go to download

JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern.

There is a newer version: 5.0
Show newest version
/*-
 * #%L
 * JSQLParser library
 * %%
 * Copyright (C) 2004 - 2020 JSQLParser
 * %%
 * Dual licensed under GNU LGPL 2.1 or Apache License 2.0
 * #L%
 */
package net.sf.jsqlparser.util.deparser;

import java.util.Iterator;

import net.sf.jsqlparser.statement.grant.Grant;

public class GrantDeParser extends AbstractDeParser {

    public GrantDeParser(StringBuilder buffer) {
        super(buffer);
    }

    @Override
    public void deParse(Grant grant) {
        buffer.append("GRANT ");
        if (grant.getRole() != null) {
            buffer.append(grant.getRole());
        } else {
            for (Iterator iter = grant.getPrivileges().iterator(); iter.hasNext();) {
                String privilege = iter.next();
                buffer.append(privilege);
                if (iter.hasNext()) {
                    buffer.append(", ");
                }
            }
            buffer.append(" ON ");
            buffer.append(grant.getObjectName());
        }
        buffer.append(" TO ");
        for (Iterator iter = grant.getUsers().iterator(); iter.hasNext();) {
            String user = iter.next();
            buffer.append(user);
            if (iter.hasNext()) {
                buffer.append(", ");
            }
        }
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy