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

Static Public Member Functions

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

Detailed Description

Definition at line 26 of file QueryExtensions.cs.

Member Function Documentation

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

Definition at line 31 of file QueryExtensions.cs.

31  {
32  var tablesInPlan = viewInfo.QueryPlan.DiscoverTableNames();
33  foreach (var tableName in tablesInPlan) {
34  if (!context.UserCanSelectFromTable(tableName))
35  throw new InvalidAccessException(context.UserName(), tableName);
36  }
37 
38  if (context.ViewExists(viewInfo.ViewName)) {
39  if (!replaceIfExists)
40  throw new InvalidOperationException(
41  String.Format("The view {0} already exists and the REPLCE clause was not specified.", viewInfo.ViewName));
42 
43  context.DropObject(DbObjectType.View, viewInfo.ViewName);
44  }
45 
46  context.CreateObject(viewInfo);
47 
48  // The initial grants for a view is to give the user who created it
49  // full access.
50  using (var systemContext = context.Direct()) {
51  systemContext.GrantToUserOnTable(viewInfo.ViewName, context.UserName(), Privileges.TableAll);
52  }
53  }
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.QueryExtensions.DefineView ( this IQuery  context,
ObjectName  viewName,
IQueryPlanNode  queryPlan,
bool  replaceIfExists 
)
inlinestatic

Definition at line 55 of file QueryExtensions.cs.

55  {
56  // We have to execute the plan to get the TableInfo that represents the
57  // result of the view execution.
58  var table = queryPlan.Evaluate(context);
59  var tableInfo = table.TableInfo.Alias(viewName);
60 
61  var viewInfo = new ViewInfo(tableInfo, null, queryPlan);
62  context.DefineView(viewInfo, replaceIfExists);
63  }
ITable Evaluate(IRequest context)
static void Deveel.Data.Sql.Views.QueryExtensions.DropView ( this IQuery  context,
ObjectName  viewName 
)
inlinestatic

Definition at line 65 of file QueryExtensions.cs.

65  {
66  DropView(context, viewName, false);
67  }
static void DropView(this IQuery context, ObjectName viewName)
static void Deveel.Data.Sql.Views.QueryExtensions.DropView ( this IQuery  context,
ObjectName  viewName,
bool  ifExists 
)
inlinestatic

Definition at line 69 of file QueryExtensions.cs.

69  {
70  context.DropViews(new[] { viewName }, ifExists);
71  }
static void Deveel.Data.Sql.Views.QueryExtensions.DropViews ( this IQuery  context,
IEnumerable< ObjectName viewNames 
)
inlinestatic

Definition at line 73 of file QueryExtensions.cs.

73  {
74  DropViews(context, viewNames, false);
75  }
static void DropViews(this IQuery context, IEnumerable< ObjectName > viewNames)
static void Deveel.Data.Sql.Views.QueryExtensions.DropViews ( this IQuery  context,
IEnumerable< ObjectName viewNames,
bool  onlyIfExists 
)
inlinestatic

Definition at line 77 of file QueryExtensions.cs.

77  {
78  var viewNameList = viewNames.ToList();
79  foreach (var tableName in viewNameList) {
80  if (!context.UserCanDropObject(DbObjectType.View, tableName))
81  throw new MissingPrivilegesException(context.UserName(), tableName, Privileges.Drop);
82  }
83 
84  // If the 'only if exists' flag is false, we need to check tables to drop
85  // exist first.
86  if (!onlyIfExists) {
87  // For each table to drop.
88  foreach (var viewName in viewNameList) {
89  // If view doesn't exist, throw an error
90  if (!context.ViewExists(viewName)) {
91  throw new ObjectNotFoundException(viewName, String.Format("The view '{0}' does not exist and cannot be dropped.", viewName));
92  }
93  }
94  }
95 
96  foreach (var viewName in viewNameList) {
97  // Does the table already exist?
98  if (context.ViewExists(viewName)) {
99  // Drop table in the transaction
100  context.DropObject(DbObjectType.Table, viewName);
101 
102  // Revoke all the grants on the table
103  context.RevokeAllGrantsOnView(viewName);
104  }
105  }
106  }
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.QueryExtensions.GetView ( this IQuery  context,
ObjectName  viewName 
)
inlinestatic

Definition at line 108 of file QueryExtensions.cs.

108  {
109  return context.GetObject(DbObjectType.View, viewName, AccessType.Read) as View;
110  }
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.QueryExtensions.GetViewQueryPlan ( this IQuery  context,
ObjectName  viewName 
)
inlinestatic

Definition at line 112 of file QueryExtensions.cs.

112  {
113  var view = context.GetView(viewName);
114  return view == null ? null : view.QueryPlan;
115  }
static bool Deveel.Data.Sql.Views.QueryExtensions.ViewExists ( this IQuery  context,
ObjectName  viewName 
)
inlinestatic

Definition at line 27 of file QueryExtensions.cs.

27  {
28  return context.ObjectExists(DbObjectType.View, viewName);
29  }
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: