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