OmniSciDB  6686921089
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SqlGrantRole.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 import org.apache.calcite.util.JsonBuilder;
18 
19 import java.util.List;
20 import java.util.Map;
21 import java.util.Objects;
22 
23 public class SqlGrantRole extends SqlDdl {
24  private static final SqlOperator OPERATOR =
25  new SqlSpecialOperator("GRANT_ROLE", SqlKind.OTHER_DDL);
26  @Expose
27  private String command;
28  @Expose
29  private SqlNodeList roles;
30  @Expose
31  private SqlNodeList grantees;
32 
33  public SqlGrantRole(SqlParserPos pos, SqlNodeList roles, SqlNodeList grantees) {
34  super(OPERATOR, pos);
35  requireNonNull(roles);
36  this.command = OPERATOR.getName();
37  this.roles = roles;
38  this.grantees = grantees;
39  }
40 
41  @Override
42  public List<SqlNode> getOperandList() {
43  return null;
44  }
45 
46  @Override
47  public String toString() {
49  Map<String, Object> map = jsonBuilder.map();
50 
51  if (this.roles != null) {
52  List<Object> roles_list = jsonBuilder.list();
53  for (SqlNode role : this.roles) {
54  roles_list.add(role.toString());
55  }
56  map.put("roles", roles_list);
57  }
58 
59  if (this.grantees != null) {
60  List<Object> grantee_list = jsonBuilder.list();
61  for (SqlNode grantee : this.grantees) {
62  grantee_list.add(grantee.toString());
63  }
64  map.put("grantees", grantee_list);
65  }
66 
67  map.put("command", "GRANT_ROLE");
68  Map<String, Object> payload = jsonBuilder.map();
69  payload.put("payload", map);
70  return jsonBuilder.toJsonString(payload);
71  }
72 }
SqlGrantRole(SqlParserPos pos, SqlNodeList roles, SqlNodeList grantees)