Exposes the context of an event fired on a table.
상속: Deveel.Data.Diagnostics.Event
예제 #1
0
파일: Trigger.cs 프로젝트: deveel/deveeldb
        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);
            }
        }
예제 #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);
        }
예제 #3
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);
            }
        }
예제 #4
0
 public void FireTriggers(IRequest context, TableEvent tableEvent)
 {
     foreach (var trigger in triggers.Values) {
         if (trigger.CanFire(tableEvent))
             trigger.Fire(tableEvent, context);
     }
 }
예제 #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);
            }
        }
예제 #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);
        }
예제 #7
0
        public static void FireTriggers(this IQuery context, TableEvent tableEvent)
        {
            var manager = context.Session.Transaction.GetTriggerManager();
            if (manager == null)
                return;

            manager.FireTriggers(context, tableEvent);
        }
예제 #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);
     }
 }
예제 #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);
     }
 }
예제 #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);
        }
예제 #11
0
        public bool CanFire(TableEvent tableEvent)
        {
            if (!TableName.Equals(tableEvent.Table.TableInfo.TableName))
            {
                return(false);
            }

            return(MatchesEvent(tableEvent.EventTime, tableEvent.EventType));
        }
예제 #12
0
 public void FireTriggers(IRequest context, TableEvent tableEvent)
 {
     foreach (var trigger in triggers.Values)
     {
         if (trigger.CanFire(tableEvent))
         {
             trigger.Fire(tableEvent, context);
         }
     }
 }
예제 #13
0
 private void FireTrigger(IQuery context, TableEvent tableEvent)
 {
     if (TriggerType == TriggerType.Callback)
     {
         NotifyTriggerEvent(context, tableEvent);
     }
     else
     {
         ExecuteProcedure(context);
     }
 }
예제 #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);
        }
예제 #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;
            }
        }
예제 #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));
        }
예제 #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;
            }
        }
예제 #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);
            }
        }
예제 #19
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);
            }
        }
예제 #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);
                }
            }
        }
예제 #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);
                }
            }
        }
예제 #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);
                }
            }
        }
예제 #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);
            }
        }
예제 #24
0
 protected abstract void FireTrigger(TableEvent tableEvent, IBlock context);
예제 #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);
        }
예제 #26
0
파일: Trigger.cs 프로젝트: deveel/deveeldb
 public bool CanFire(TableEvent tableEvent)
 {
     return TriggerInfo.CanFire(tableEvent);
 }
예제 #27
0
 public bool CanFire(TableEvent tableEvent)
 {
     return(TriggerInfo.CanFire(tableEvent));
 }
예제 #28
0
        public bool CanFire(TableEvent tableEvent)
        {
            if (!TableName.Equals(tableEvent.Table.TableInfo.TableName))
                return false;

            return MatchesEvent(tableEvent.EventTime, tableEvent.EventType);
        }
예제 #29
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);
            }
        }
예제 #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);
        }
예제 #31
0
파일: Trigger.cs 프로젝트: deveel/deveeldb
 protected abstract void FireTrigger(TableEvent tableEvent, IBlock context);
예제 #32
0
 private void FireTrigger(IQuery context, TableEvent tableEvent)
 {
     if (TriggerType == TriggerType.Callback) {
         NotifyTriggerEvent(context, tableEvent);
     } else {
         ExecuteProcedure(context);
     }
 }