DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
GrantPrivilegesStatement.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Collections.Generic;
19 
20 using Deveel.Data.Security;
22 
23 namespace Deveel.Data.Sql.Statements {
24  [Serializable]
26  public GrantPrivilegesStatement(string grantee, Privileges privilege, ObjectName objName)
27  : this(grantee, privilege, false, objName) {
28  }
29 
30  public GrantPrivilegesStatement(string grantee, Privileges privilege, bool withGrant, ObjectName objName)
31  : this(grantee, privilege, withGrant, objName, null) {
32  }
33 
34  public GrantPrivilegesStatement(string grantee, Privileges privilege, ObjectName objName, IEnumerable<string> columns)
35  : this(grantee, privilege, false, objName, columns) {
36  }
37 
38  public GrantPrivilegesStatement(string grantee, Privileges privilege, bool withGrant, ObjectName objName, IEnumerable<string> columns) {
39  Grantee = grantee;
40  Privilege = privilege;
41  Columns = columns;
42  ObjectName = objName;
43  WithGrant = withGrant;
44  }
45 
47  ObjectName = data.GetValue<ObjectName>("ObjectName");
48  Grantee = data.GetString("Grantee");
49  Privilege = (Privileges) data.GetInt32("Privilege");
50  Columns = data.GetValue<string[]>("Columns");
51  WithGrant = data.GetBoolean("WithGrant");
52  }
53 
54  public IEnumerable<string> Columns { get; private set; }
55 
56  public string Grantee { get; private set; }
57 
58  public Privileges Privilege { get; private set; }
59 
60  public ObjectName ObjectName { get; private set; }
61 
62  public bool WithGrant { get; private set; }
63 
64  protected override void GetData(SerializeData data) {
65  data.SetValue("ObjectName", ObjectName);
66  data.SetValue("Grantee", Grantee);
67  data.SetValue("Privilege", (int)Privilege);
68  data.SetValue("Columns", Columns);
69  data.SetValue("WithGrant", WithGrant);
70  }
71 
73  var objName = context.Query.ResolveObjectName(ObjectName.FullName);
74  return new GrantPrivilegesStatement(Grantee, Privilege, WithGrant, objName, Columns);
75  }
76 
77  protected override void ExecuteStatement(ExecutionContext context) {
78  var obj = context.Request.Query.FindObject(ObjectName);
79  if (obj == null)
80  throw new InvalidOperationException(String.Format("Object '{0}' was not found in the system.", ObjectName));
81 
82  context.Request.Query.GrantTo(Grantee, obj.ObjectType, obj.FullName, Privilege, WithGrant);
83  }
84  }
85 }
GrantPrivilegesStatement(string grantee, Privileges privilege, ObjectName objName)
void SetValue(string key, Type type, object value)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
GrantPrivilegesStatement(string grantee, Privileges privilege, bool withGrant, ObjectName objName)
override void ExecuteStatement(ExecutionContext context)
Represents the foundation class of SQL statements to be executed.
Definition: SqlStatement.cs:32
string FullName
Gets the full reference name formatted.
Definition: ObjectName.cs:114
GrantPrivilegesStatement(string grantee, Privileges privilege, bool withGrant, ObjectName objName, IEnumerable< string > columns)
GrantPrivilegesStatement(string grantee, Privileges privilege, ObjectName objName, IEnumerable< string > columns)