Exposes the context of an event fired on a table.
Inheritance: Deveel.Data.Diagnostics.Event
Exemple #1
0
        public void Fire(TableEvent tableEvent, IRequest context)
        {
            var oldState = GetOldState(context);

            try {
                var triggerType = TriggerInfo.TriggerType;
                var tableName = tableEvent.Table.TableInfo.TableName;
                context.Context.OnEvent(new TriggerEvent(triggerType, Name, tableName, tableEvent.EventTime, tableEvent.EventType,
                    tableEvent.OldRowId, tableEvent.NewRow));

                var newState = new OldNewTableState(tableName, tableEvent.OldRowId.RowNumber, tableEvent.NewRow,
                    tableEvent.EventTime == TriggerEventTime.Before);

                SetState(context, newState);

                using (var block = context.CreateBlock()) {
                    FireTrigger(tableEvent, block);
                }
            } catch (TriggerException) {
                throw;
            } catch (Exception ex) {
                throw new TriggerException(String.Format("An unknown error occurred while executing trigger '{0}'.", Name), ex);
            } finally {
                SetState(context, oldState);
            }
        }
Exemple #2
0
        protected override void FireTrigger(TableEvent tableEvent, IBlock context)
        {
            var e = new TriggerEvent(TriggerType.Callback, TriggerInfo.TriggerName, tableEvent.Table.TableInfo.TableName, tableEvent.EventTime, tableEvent.EventType,
                                     tableEvent.OldRowId, tableEvent.NewRow);

            context.Context.RegisterEvent(e);
        }
        public void Fire(TableEvent tableEvent, IRequest context)
        {
            var oldState = GetOldState(context);

            try {
                var triggerType = TriggerInfo.TriggerType;
                var tableName   = tableEvent.Table.TableInfo.TableName;
                context.Context.OnEvent(new TriggerEvent(triggerType, Name, tableName, tableEvent.EventTime, tableEvent.EventType,
                                                         tableEvent.OldRowId, tableEvent.NewRow));

                var newState = new OldNewTableState(tableName, tableEvent.OldRowId.RowNumber, tableEvent.NewRow,
                                                    tableEvent.EventTime == TriggerEventTime.Before);

                SetState(context, newState);

                using (var block = context.CreateBlock()) {
                    FireTrigger(tableEvent, block);
                }
            } catch (TriggerException) {
                throw;
            } catch (Exception ex) {
                throw new TriggerException(String.Format("An unknown error occurred while executing trigger '{0}'.", Name), ex);
            } finally {
                SetState(context, oldState);
            }
        }
 public void FireTriggers(IRequest context, TableEvent tableEvent)
 {
     foreach (var trigger in triggers.Values) {
         if (trigger.CanFire(tableEvent))
             trigger.Fire(tableEvent, context);
     }
 }
Exemple #5
0
        public void Invoke(IQuery context, TableEvent 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);
            }
        }
Exemple #6
0
        protected override void FireTrigger(TableEvent tableEvent, IBlock context)
        {
            var e = new TriggerEvent(TriggerType.Callback, TriggerInfo.TriggerName, tableEvent.Table.TableInfo.TableName, tableEvent.EventTime, tableEvent.EventType,
                tableEvent.OldRowId, tableEvent.NewRow);

            context.Context.RegisterEvent(e);
        }
        public static void FireTriggers(this IQuery context, TableEvent tableEvent)
        {
            var manager = context.Session.Transaction.GetTriggerManager();
            if (manager == null)
                return;

            manager.FireTriggers(context, tableEvent);
        }
Exemple #8
0
 protected override void FireTrigger(TableEvent tableEvent, IBlock context)
 {
     // TODO: Should pass arguments?
     try {
         Body.Execute(new ExecutionContext(context, Body));
     } catch (Exception ex) {
         throw new TriggerException(this, ex);
     }
 }
Exemple #9
0
 protected override void FireTrigger(TableEvent tableEvent, IBlock context)
 {
     // TODO: Should pass arguments?
     try {
         Body.Execute(new ExecutionContext(context, Body));
     } catch (Exception ex) {
         throw new TriggerException(this, ex);
     }
 }
Exemple #10
0
        private void NotifyTriggerEvent(IQuery context, TableEvent tableEvent)
        {
            var tableName = tableEvent.Table.FullName;
            var eventType = tableEvent.EventType;

            var triggerEvent = new TriggerEvent(context.Session, TriggerName, tableName, eventType, tableEvent.OldRowId,
                                                tableEvent.NewRow);
            // TODO: context.RegisterEvent(triggerEvent);
        }
        public bool CanFire(TableEvent tableEvent)
        {
            if (!TableName.Equals(tableEvent.Table.TableInfo.TableName))
            {
                return(false);
            }

            return(MatchesEvent(tableEvent.EventTime, tableEvent.EventType));
        }
Exemple #12
0
 public void FireTriggers(IRequest context, TableEvent tableEvent)
 {
     foreach (var trigger in triggers.Values)
     {
         if (trigger.CanFire(tableEvent))
         {
             trigger.Fire(tableEvent, context);
         }
     }
 }
Exemple #13
0
 private void FireTrigger(IQuery context, TableEvent tableEvent)
 {
     if (TriggerType == TriggerType.Callback)
     {
         NotifyTriggerEvent(context, tableEvent);
     }
     else
     {
         ExecuteProcedure(context);
     }
 }
Exemple #14
0
        public static void FireTriggers(this IQuery context, TableEvent tableEvent)
        {
            var manager = context.Session.Transaction.GetTriggerManager();

            if (manager == null)
            {
                return;
            }

            manager.FireTriggers(context, tableEvent);
        }
Exemple #15
0
        public static void FireTriggers(this IContext context, IRequest request, TableEvent tableEvent)
        {
            var current = context;
            while (current != null) {
                if (current is ITriggerScope) {
                    var scope = (ITriggerScope)current;
                    scope.TriggerManager.FireTriggers(request, tableEvent);
                }

                current = current.Parent;
            }
        }
Exemple #16
0
        public bool CanInvoke(TableEvent context)
        {
            if ((TriggerInfo.EventType & context.EventType) == 0)
            {
                return(false);
            }

            var tableName = context.Table.TableInfo.TableName;

            return(TriggerInfo.TableName == null ||
                   TriggerInfo.TableName.Equals(tableName, true));
        }
Exemple #17
0
        public static void FireTriggers(this IContext context, IRequest request, TableEvent tableEvent)
        {
            var current = context;

            while (current != null)
            {
                if (current is ITriggerScope)
                {
                    var scope = (ITriggerScope)current;
                    scope.TriggerManager.FireTriggers(request, tableEvent);
                }

                current = current.Parent;
            }
        }
Exemple #18
0
        protected override void FireTrigger(TableEvent tableEvent, IBlock context)
        {
            var procedure = context.Access().GetObject(DbObjectType.Routine, ProcedureName) as IProcedure;

            if (procedure == null)
                throw new TriggerException(String.Format("The procedure '{0}' was not found.", ProcedureName));

            var invoke = new Invoke(ProcedureName, Arguments);

            try {
                procedure.Execute(new InvokeContext(invoke, procedure, null, null, context));
            } catch (Exception ex) {
                throw new TriggerException(String.Format("Error while invoking '{0}'.",invoke), ex);
            }
        }
        protected override void FireTrigger(TableEvent tableEvent, IBlock context)
        {
            var procedure = context.Access().GetObject(DbObjectType.Routine, ProcedureName) as IProcedure;

            if (procedure == null)
            {
                throw new TriggerException(String.Format("The procedure '{0}' was not found.", ProcedureName));
            }

            var invoke = new Invoke(ProcedureName, Arguments);

            try {
                procedure.Execute(new InvokeContext(invoke, procedure, null, null, context));
            } catch (Exception ex) {
                throw new TriggerException(String.Format("Error while invoking '{0}'.", invoke), ex);
            }
        }
Exemple #20
0
        public void FireTriggers(IQuery context, TableEvent tableEvent)
        {
            if (!transaction.TableExists(SystemSchema.TriggerTableName))
            {
                return;
            }

            BuildTriggerCache();

            foreach (var trigger in triggerCache)
            {
                if (trigger.CanInvoke(tableEvent))
                {
                    trigger.Invoke(context, tableEvent);
                }
            }
        }
Exemple #21
0
        public void FireTriggers(IRequest context, TableEvent tableEvent)
        {
            if (!transaction.TableExists(TriggerTableName))
            {
                return;
            }

            BuildTriggerCache();

            foreach (var trigger in triggerCache)
            {
                try {
                    if (trigger.CanFire(tableEvent))
                    {
                        trigger.Fire(tableEvent, context);
                    }
                } catch (TriggerException) {
                    throw;
                } catch (Exception ex) {
                    throw new TriggerException(trigger, ex);
                }
            }
        }
Exemple #22
0
        public void FireTriggers(IRequest context, TableEvent tableEvent)
        {
            if (!transaction.TableExists(TriggerTableName))
                return;

            BuildTriggerCache();

            foreach (var trigger in triggerCache) {
                try {
                    if (trigger.CanFire(tableEvent))
                        trigger.Fire(tableEvent, context);
                } catch(TriggerException) {
                    throw;
                } catch (Exception ex) {
                    throw new TriggerException(trigger, ex);
                }
            }
        }
Exemple #23
0
        public void Invoke(IQuery context, TableEvent 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);
            }
        }
Exemple #24
0
 protected abstract void FireTrigger(TableEvent tableEvent, IBlock context);
Exemple #25
0
        public bool CanInvoke(TableEvent context)
        {
            if ((TriggerInfo.EventType & context.EventType) == 0)
                return false;

            var tableName = context.Table.TableInfo.TableName;
            return TriggerInfo.TableName == null ||
                   TriggerInfo.TableName.Equals(tableName, true);
        }
Exemple #26
0
 public bool CanFire(TableEvent tableEvent)
 {
     return TriggerInfo.CanFire(tableEvent);
 }
Exemple #27
0
 public bool CanFire(TableEvent tableEvent)
 {
     return(TriggerInfo.CanFire(tableEvent));
 }
Exemple #28
0
        public bool CanFire(TableEvent tableEvent)
        {
            if (!TableName.Equals(tableEvent.Table.TableInfo.TableName))
                return false;

            return MatchesEvent(tableEvent.EventTime, tableEvent.EventType);
        }
        public void FireTriggers(IQuery context, TableEvent tableEvent)
        {
            if (!transaction.TableExists(SystemSchema.TriggerTableName))
                return;

            BuildTriggerCache();

            foreach (var trigger in triggerCache) {
                if (trigger.CanInvoke(tableEvent))
                    trigger.Invoke(context, tableEvent);
            }
        }
Exemple #30
0
        private void NotifyTriggerEvent(IQuery context, TableEvent tableEvent)
        {
            var tableName = tableEvent.Table.FullName;
            var eventType = tableEvent.EventType;

            var triggerEvent = new TriggerEvent(context.Session, TriggerName, tableName, eventType, tableEvent.OldRowId,
                tableEvent.NewRow);
            // TODO: context.RegisterEvent(triggerEvent);
        }
Exemple #31
0
 protected abstract void FireTrigger(TableEvent tableEvent, IBlock context);
Exemple #32
0
 private void FireTrigger(IQuery context, TableEvent tableEvent)
 {
     if (TriggerType == TriggerType.Callback) {
         NotifyTriggerEvent(context, tableEvent);
     } else {
         ExecuteProcedure(context);
     }
 }