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