@Override public Void visitGrant(Grant node, Integer indent) { builder.append("GRANT "); if (node.getPrivileges().isPresent()) { builder.append(node.getPrivileges().get().stream() .collect(joining(", "))); } else { builder.append("ALL PRIVILEGES"); } builder.append(" ON "); if (node.isTable()) { builder.append("TABLE "); } builder.append(node.getTableName()) .append(" TO ") .append(formatPrincipal(node.getGrantee())); if (node.isWithGrantOption()) { builder.append(" WITH GRANT OPTION"); } return null; }
@Override public Void visitRevoke(Revoke node, Integer indent) { builder.append("REVOKE "); if (node.isGrantOptionFor()) { builder.append("GRANT OPTION FOR "); } if (node.getPrivileges().isPresent()) { builder.append(node.getPrivileges().get().stream() .collect(joining(", "))); } else { builder.append("ALL PRIVILEGES"); } builder.append(" ON "); if (node.isTable()) { builder.append("TABLE "); } builder.append(node.getTableName()) .append(" FROM ") .append(formatPrincipal(node.getGrantee())); return null; }
@Override public Void visitRevoke(Revoke node, Integer indent) { builder.append("REVOKE "); if (node.isGrantOptionFor()) { builder.append("GRANT OPTION FOR "); } if (node.getPrivileges().isPresent()) { builder.append(node.getPrivileges().get().stream() .collect(joining(", "))); } else { builder.append("ALL PRIVILEGES"); } builder.append(" ON "); if (node.isTable()) { builder.append("TABLE "); } builder.append(node.getTableName()) .append(" FROM ") .append(formatPrincipal(node.getGrantee())); return null; }
@Override public Void visitGrant(Grant node, Integer indent) { builder.append("GRANT "); if (node.getPrivileges().isPresent()) { builder.append(node.getPrivileges().get().stream() .collect(joining(", "))); } else { builder.append("ALL PRIVILEGES"); } builder.append(" ON "); if (node.isTable()) { builder.append("TABLE "); } builder.append(node.getTableName()) .append(" TO ") .append(formatPrincipal(node.getGrantee())); if (node.isWithGrantOption()) { builder.append(" WITH GRANT OPTION"); } return null; }
private static String formatGrantor(GrantorSpecification grantor) { GrantorSpecification.Type type = grantor.getType(); switch (type) { case CURRENT_ROLE: case CURRENT_USER: return type.name(); case PRINCIPAL: return formatPrincipal(grantor.getPrincipal().get()); default: throw new IllegalArgumentException("Unsupported principal type: " + type); } }
private static String formatGrantor(GrantorSpecification grantor) { GrantorSpecification.Type type = grantor.getType(); switch (type) { case CURRENT_ROLE: case CURRENT_USER: return type.name(); case PRINCIPAL: return formatPrincipal(grantor.getPrincipal().get()); default: throw new IllegalArgumentException("Unsupported principal type: " + type); } }