DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Static Public Member Functions | List of all members
Deveel.Data.Sql.Views.QueryContextExtensions Class Reference

Static Public Member Functions

static bool ViewExists (this IQueryContext context, ObjectName viewName)
 
static void DefineView (this IQueryContext context, ViewInfo viewInfo, bool replaceIfExists)
 
static void DefineView (this IQueryContext context, ObjectName viewName, IQueryPlanNode queryPlan, bool replaceIfExists)
 
static void DropView (this IQueryContext context, ObjectName viewName)
 
static void DropView (this IQueryContext context, ObjectName viewName, bool ifExists)
 
static void DropViews (this IQueryContext context, IEnumerable< ObjectName > viewNames)
 
static void DropViews (this IQueryContext context, IEnumerable< ObjectName > viewNames, bool onlyIfExists)
 
static View GetView (this IQueryContext context, ObjectName viewName)
 
static IQueryPlanNode GetViewQueryPlan (this IQueryContext context, ObjectName viewName)
 

Detailed Description

Definition at line 10 of file QueryContext.Views.cs.

Member Function Documentation

static void Deveel.Data.Sql.Views.QueryContextExtensions.DefineView ( this IQueryContext  context,
ViewInfo  viewInfo,
bool  replaceIfExists 
)
inlinestatic

Definition at line 15 of file QueryContext.Views.cs.

15  {
16  var tablesInPlan = viewInfo.QueryPlan.DiscoverTableNames();
17  foreach (var tableName in tablesInPlan) {
18  if (!context.UserCanSelectFromTable(tableName))
19  throw new InvalidAccessException(context.UserName(), tableName);
20  }
21 
22  if (context.ViewExists(viewInfo.ViewName)) {
23  if (!replaceIfExists)
24  throw new InvalidOperationException(
25  String.Format("The view {0} already exists and the REPLCE clause was not specified.", viewInfo.ViewName));
26 
27  context.DropObject(DbObjectType.View, viewInfo.ViewName);
28  }
29 
30  context.CreateObject(viewInfo);
31 
32  // The initial grants for a view is to give the user who created it
33  // full access.
34  using (var systemContext = context.ForSystemUser()) {
35  systemContext.GrantToUserOnTable(viewInfo.ViewName, context.UserName(), Privileges.TableAll);
36  }
37  }
A long string in the system.
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
static void Deveel.Data.Sql.Views.QueryContextExtensions.DefineView ( this IQueryContext  context,
ObjectName  viewName,
IQueryPlanNode  queryPlan,
bool  replaceIfExists 
)
inlinestatic

Definition at line 39 of file QueryContext.Views.cs.

39  {
40  // We have to execute the plan to get the TableInfo that represents the
41  // result of the view execution.
42  var table = queryPlan.Evaluate(context);
43  var tableInfo = table.TableInfo.Alias(viewName);
44 
45  var viewInfo = new ViewInfo(tableInfo, null, queryPlan);
46  context.DefineView(viewInfo, replaceIfExists);
47  }
ITable Evaluate(IRequest context)
static void Deveel.Data.Sql.Views.QueryContextExtensions.DropView ( this IQueryContext  context,
ObjectName  viewName 
)
inlinestatic

Definition at line 49 of file QueryContext.Views.cs.

49  {
50  DropView(context, viewName, false);
51  }
static void DropView(this IQueryContext context, ObjectName viewName)
static void Deveel.Data.Sql.Views.QueryContextExtensions.DropView ( this IQueryContext  context,
ObjectName  viewName,
bool  ifExists 
)
inlinestatic

Definition at line 53 of file QueryContext.Views.cs.

53  {
54  context.DropViews(new[] { viewName }, ifExists);
55  }
static void Deveel.Data.Sql.Views.QueryContextExtensions.DropViews ( this IQueryContext  context,
IEnumerable< ObjectName viewNames 
)
inlinestatic

Definition at line 57 of file QueryContext.Views.cs.

57  {
58  DropViews(context, viewNames, false);
59  }
static void DropViews(this IQueryContext context, IEnumerable< ObjectName > viewNames)
static void Deveel.Data.Sql.Views.QueryContextExtensions.DropViews ( this IQueryContext  context,
IEnumerable< ObjectName viewNames,
bool  onlyIfExists 
)
inlinestatic

Definition at line 61 of file QueryContext.Views.cs.

61  {
62  var viewNameList = viewNames.ToList();
63  foreach (var tableName in viewNameList) {
64  if (!context.UserCanDropObject(DbObjectType.View, tableName))
65  throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Drop);
66  }
67 
68  // If the 'only if exists' flag is false, we need to check tables to drop
69  // exist first.
70  if (!onlyIfExists) {
71  // For each table to drop.
72  foreach (var viewName in viewNameList) {
73  // If view doesn't exist, throw an error
74  if (!context.ViewExists(viewName)) {
75  throw new ObjectNotFoundException(viewName, String.Format("The view '{0}' does not exist and cannot be dropped.", viewName));
76  }
77  }
78  }
79 
80  foreach (var viewName in viewNameList) {
81  // Does the table already exist?
82  if (context.ViewExists(viewName)) {
83  // Drop table in the transaction
84  context.DropObject(DbObjectType.Table, viewName);
85 
86  // Revoke all the grants on the table
87  context.RevokeAllGrantsOnView(viewName);
88  }
89  }
90  }
A long string in the system.
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
static View Deveel.Data.Sql.Views.QueryContextExtensions.GetView ( this IQueryContext  context,
ObjectName  viewName 
)
inlinestatic

Definition at line 92 of file QueryContext.Views.cs.

92  {
93  return context.GetObject(DbObjectType.View, viewName, AccessType.Read) as View;
94  }
A VIEW object obtained by a source query.
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
static IQueryPlanNode Deveel.Data.Sql.Views.QueryContextExtensions.GetViewQueryPlan ( this IQueryContext  context,
ObjectName  viewName 
)
inlinestatic

Definition at line 96 of file QueryContext.Views.cs.

96  {
97  var view = context.GetView(viewName);
98  return view == null ? null : view.QueryPlan;
99  }
static bool Deveel.Data.Sql.Views.QueryContextExtensions.ViewExists ( this IQueryContext  context,
ObjectName  viewName 
)
inlinestatic

Definition at line 11 of file QueryContext.Views.cs.

11  {
12  return context.ObjectExists(DbObjectType.View, viewName);
13  }
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27

The documentation for this class was generated from the following file: