OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlGrantPrivilege.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.SqlDdl;
8 import org.apache.calcite.sql.SqlIdentifier;
9 import org.apache.calcite.sql.SqlKind;
10 import org.apache.calcite.sql.SqlNode;
11 import org.apache.calcite.sql.SqlNodeList;
12 import org.apache.calcite.sql.SqlOperator;
13 import org.apache.calcite.sql.SqlSpecialOperator;
14 import org.apache.calcite.sql.parser.Span;
15 import org.apache.calcite.sql.parser.SqlParserPos;
17 
18 import java.util.List;
19 import java.util.Map;
20 import java.util.Objects;
21 
22 public class SqlGrantPrivilege extends SqlDdl {
23  private static final SqlOperator OPERATOR =
24  new SqlSpecialOperator("GRANT_PRIVILEGE", SqlKind.OTHER_DDL);
25  @Expose
26  private String command;
27  @Expose
28  private SqlNodeList privileges;
29  @Expose
30  private String type;
31  @Expose
32  private String target;
33  @Expose
34  private SqlNodeList grantees;
35 
36  public SqlGrantPrivilege(SqlParserPos pos,
37  SqlNodeList privileges,
38  String type,
39  String target,
40  SqlNodeList grantees) {
41  super(OPERATOR, pos);
42  requireNonNull(privileges);
43  this.command = OPERATOR.getName();
44  this.privileges = privileges;
45  this.type = type;
46  this.target = target;
47  this.grantees = grantees;
48  }
49 
50  @Override
51  public List<SqlNode> getOperandList() {
52  return null;
53  }
54 
55  @Override
56  public String toString() {
58  Map<String, Object> map = jsonBuilder.map();
59 
60  if (this.privileges != null) {
61  List<Object> privilege_list = jsonBuilder.list();
62  for (SqlNode privilege : this.privileges) {
63  // privilege are string literals,
64  // so may need to be later striped of the quotes that get added
65  privilege_list.add(privilege.toString());
66  }
67  map.put("privileges", privilege_list);
68  }
69 
70  map.put("type", this.type);
71  map.put("target", this.target);
72 
73  if (this.grantees != null) {
74  List<Object> grantee_list = jsonBuilder.list();
75  for (SqlNode grantee : this.grantees) {
76  grantee_list.add(grantee.toString());
77  }
78  map.put("grantees", grantee_list);
79  }
80 
81  map.put("command", "GRANT_PRIVILEGE");
82  Map<String, Object> payload = jsonBuilder.map();
83  payload.put("payload", map);
84  return jsonBuilder.toJsonString(payload);
85  }
86 }
SqlGrantPrivilege(SqlParserPos pos, SqlNodeList privileges, String type, String target, SqlNodeList grantees)