DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
QueryContextExtensions.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 
19 using Deveel.Data.Diagnostics;
21 
22 namespace Deveel.Data.Sql.Triggers {
23  public static class QueryContextExtensions {
24  public static void FireTriggers(this IQueryContext context, TableEventContext tableEvent) {
25  var manager = context.Session().Transaction.GetTriggerManager();
26  if (manager == null)
27  return;
28 
29  manager.FireTriggers(context, tableEvent);
30  }
31 
32  //public static void FireTrigger(this IQueryContext context, TableEventContext tableEvent) {
33  // var tableName = tableEvent.Table.FullName;
34  // var eventType = tableEvent.EventType;
35 
36  // try {
37  // var triggers = context.Session.FindTriggers(tableName, eventType);
38 
39  // foreach (var trigger in triggers) {
40  // try {
41  // trigger.Invoke(tableEvent);
42 
43  // var oldRowId = tableEvent.OldRowId;
44  // var newRow = tableEvent.NewRow;
45 
46  // context.FireTrigger(trigger.TriggerName, tableName, eventType, oldRowId, newRow);
47  // } catch (Exception ex) {
48  // context.RegisterTriggerError(trigger, ex);
49  // }
50  // }
51  // } catch (TableEventException ex) {
52  // context.RegisterError(ex);
53  // throw;
54  // } catch (Exception ex) {
55  // context.RegisterTableEventError(tableEvent, ex);
56  // throw new TableEventException(tableEvent, ex);
57  // }
58  //}
59 
60  //private static void RegisterTriggerError(this IQueryContext context, Trigger trigger, Exception error) {
61  // context.RegisterError(new TriggerException(trigger, error));
62  //}
63 
64  //private static void RegisterTableEventError(this IQueryContext context, TableEventContext @event, Exception error) {
65  // context.RegisterError(new TableEventException(@event, error));
66  //}
67 
68  public static void CreateTrigger(this IQueryContext context, TriggerInfo triggerInfo) {
69  context.Session().CreateTrigger(triggerInfo);
70  }
71 
72  public static void CreateCallbackTrigger(this IQueryContext context, ObjectName triggerName, TriggerEventType eventType) {
73  context.CreateTrigger(new TriggerInfo(triggerName, eventType));
74  }
75 
76  public static bool TriggerExists(this IQueryContext context, ObjectName triggerName) {
77  return context.Session().TriggerExists(triggerName);
78  }
79  }
80 }
Defines the information about a trigger on a table of the database, such as the event on which is fir...
Definition: TriggerInfo.cs:29
TriggerEventType
The different types of high layer trigger events.
static void CreateCallbackTrigger(this IQueryContext context, ObjectName triggerName, TriggerEventType eventType)
Provides a context for executing queries, accessing the system resources and evaluation context...
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static bool TriggerExists(this IQueryContext context, ObjectName triggerName)
static void CreateTrigger(this IQueryContext context, TriggerInfo triggerInfo)
static void FireTriggers(this IQueryContext context, TableEventContext tableEvent)