OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlRevokePrivilege.java
Go to the documentation of this file.
1 package com.mapd.parser.extension.ddl;
2 
3 import static java.util.Objects.requireNonNull;
4 
5 import com.google.gson.annotations.Expose;
6 
7 import org.apache.calcite.sql.SqlCall;
8 import org.apache.calcite.sql.SqlDdl;
9 import org.apache.calcite.sql.SqlIdentifier;
10 import org.apache.calcite.sql.SqlKind;
11 import org.apache.calcite.sql.SqlNode;
12 import org.apache.calcite.sql.SqlNodeList;
13 import org.apache.calcite.sql.SqlOperator;
14 import org.apache.calcite.sql.SqlSpecialOperator;
15 import org.apache.calcite.sql.parser.SqlParserPos;
17 import org.apache.calcite.util.JsonBuilder;
18 import org.apache.calcite.util.Pair;
19 
20 import java.io.*;
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.Map;
24 
25 public class SqlRevokePrivilege extends SqlDdl {
26  private static final SqlOperator OPERATOR =
27  new SqlSpecialOperator("REVOKE_PRIVILEGE", SqlKind.OTHER_DDL);
28  @Expose
29  private String command;
30  @Expose
31  private SqlNodeList privileges;
32  @Expose
33  private String type;
34  @Expose
35  private String target;
36  @Expose
37  private SqlNodeList grantees;
38 
39  public SqlRevokePrivilege(SqlParserPos pos,
40  SqlNodeList privileges,
41  String type,
42  String target,
43  SqlNodeList grantees) {
44  super(OPERATOR, pos);
45  requireNonNull(privileges);
46  this.command = OPERATOR.getName();
47  this.privileges = privileges;
48  this.type = type;
49  this.target = target;
50  this.grantees = grantees;
51  }
52 
53  @Override
54  public List<SqlNode> getOperandList() {
55  return null;
56  }
57 
58  @Override
59  public String toString() {
61  Map<String, Object> map = jsonBuilder.map();
62 
63  if (this.privileges != null) {
64  List<Object> privilege_list = jsonBuilder.list();
65  for (SqlNode privilege : this.privileges) {
66  privilege_list.add(privilege.toString());
67  }
68  map.put("privileges", privilege_list);
69  }
70 
71  map.put("type", this.type);
72  map.put("target", this.target);
73 
74  if (this.grantees != null) {
75  List<Object> grantee_list = jsonBuilder.list();
76  for (SqlNode grantee : this.grantees) {
77  grantee_list.add(grantee.toString());
78  }
79  map.put("grantees", grantee_list);
80  }
81 
82  map.put("command", "REVOKE_PRIVILEGE");
83  Map<String, Object> payload = jsonBuilder.map();
84  payload.put("payload", map);
85  return jsonBuilder.toJsonString(payload);
86  }
87 }
SqlRevokePrivilege(SqlParserPos pos, SqlNodeList privileges, String type, String target, SqlNodeList grantees)