public static void FireTriggers(this IQueryContext context, TableEventContext tableEvent)
        {
            var manager = context.Session().Transaction.GetTriggerManager();
            if (manager == null)
                return;

            manager.FireTriggers(context, tableEvent);
        }
Esempio n. 2
0
        public void FireTriggers(IQueryContext context, TableEventContext tableEvent)
        {
            if (!transaction.TableExists(SystemSchema.TriggerTableName))
                return;

            BuildTriggerCache();

            foreach (var trigger in triggerCache) {
                if (trigger.CanInvoke(tableEvent))
                    trigger.Invoke(context, tableEvent);
            }
        }
Esempio n. 3
0
        public static void FireTrigger(this IQueryContext context, TableEventContext tableEvent)
        {
            var eventSource = tableEvent.Table.FullName;
            var eventType = tableEvent.EventType;

            var triggers = context.Session.FindTriggers(eventSource, eventType);

            foreach (var trigger in triggers) {
                try {
                    trigger.Fire(tableEvent);

                    var oldRowId = tableEvent.OldRowId;
                    var newRow = tableEvent.NewRow;

                    var triggerEvent = new TriggerEvent(trigger.TriggerName, eventSource, eventType, oldRowId, newRow);

                    context.RegisterEvent(triggerEvent);
                } catch (Exception) {
                    // TODO: throw a specialized exception
                    throw;
                }
            }
        }
Esempio n. 4
0
        public void Fire(TableEventContext context)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            if (ShouldFire(context)) {

            }
        }
Esempio n. 5
0
        private bool ShouldFire(TableEventContext context)
        {
            if ((TriggerInfo.EventType & context.EventType) == 0)
                return false;

            var tableName = context.Table.TableInfo.TableName;
            return TriggerInfo.TableName == null ||
                   TriggerInfo.TableName.Equals(tableName, true);
        }
Esempio n. 6
0
 private void FireTrigger(IQueryContext context, TableEventContext tableEvent)
 {
     if (TriggerType == TriggerType.Callback) {
         NotifyTriggerEvent(context, tableEvent);
     } else {
         ExecuteProcedure(context);
     }
 }
Esempio n. 7
0
        private void NotifyTriggerEvent(IQueryContext context, TableEventContext tableEvent)
        {
            var tableName = tableEvent.Table.FullName;
            var eventType = tableEvent.EventType;

            var triggerEvent = new TriggerEvent(context.Session, TriggerName, tableName, eventType, tableEvent.OldRowId,
                tableEvent.NewRow);
            context.RegisterEvent(triggerEvent);
        }
Esempio n. 8
0
        public bool CanInvoke(TableEventContext context)
        {
            if ((TriggerInfo.EventType & context.EventType) == 0)
                return false;

            var tableName = context.Table.TableInfo.TableName;
            return TriggerInfo.TableName == null ||
                   TriggerInfo.TableName.Equals(tableName, true);
        }
Esempio n. 9
0
        public void Invoke(IQueryContext context, TableEventContext tableEvent)
        {
            var isBefore = (tableEvent.EventType & TriggerEventType.Before) != 0;

            var transaction = context.Session.Transaction;
            if (transaction is ITableStateHandler) {
                var stateHandler = (ITableStateHandler) transaction;
                var oldState = stateHandler.TableState;
                var newState = new OldNewTableState(tableEvent.Table.FullName, tableEvent.OldRowId.RowNumber, tableEvent.NewRow,
                    isBefore);

                stateHandler.SetTableState(newState);

                try {
                    FireTrigger(context, tableEvent);
                } finally {
                    stateHandler.SetTableState(oldState);
                }
            } else {
                FireTrigger(context, tableEvent);
            }
        }
Esempio n. 10
0
 public TableEventException(TableEventContext tableEvent)
     : this(tableEvent, FormMessage(tableEvent))
 {
 }
Esempio n. 11
0
 private static string FormMessage(TableEventContext tableEvent)
 {
     return String.Format("An error occurred when firing triggers '{0}' on '{1}'.", tableEvent.EventType.AsString(),
         tableEvent.Table.FullName);
 }
Esempio n. 12
0
 public TableEventException(TableEventContext tableEvent, string message, Exception innerException)
     : base(-1, message, innerException)
 {
     TableName = tableEvent.Table.FullName;
     EventType = tableEvent.EventType;
 }
Esempio n. 13
0
 public TableEventException(TableEventContext tableEvent, string message)
     : this(tableEvent, message, null)
 {
 }
Esempio n. 14
0
 public TableEventException(TableEventContext tableEvent, Exception innerException)
     : this(tableEvent, FormMessage(tableEvent), innerException)
 {
 }