Defines the information about a trigger on a table of the database, such as the event on which is fired and the procedure to execute.
Inheritance: IObjectInfo
Exemple #1
0
        /// <summary>
        /// Constructs a trigger with the given information.
        /// </summary>
        /// <param name="triggerInfo">The object defining the information
        /// of this trigger.</param>
        /// <exception cref="ArgumentNullException">
        /// If the provided <paramref name="triggerInfo"/> is <c>null</c>.
        /// </exception>
        public Trigger(TriggerInfo triggerInfo)
        {
            if (triggerInfo == null)
                throw new ArgumentNullException("triggerInfo");

            TriggerInfo = triggerInfo;
        }
        public static void CreateTrigger(this IUserSession session, TriggerInfo triggerInfo)
        {
            var manager = session.Transaction.GetTriggerManager();
            if (manager == null)
                return;

            manager.CreateTrigger(triggerInfo);
        }
Exemple #3
0
        public bool AlterTrigger(TriggerInfo triggerInfo)
        {
            if (!DropTrigger(triggerInfo.TriggerName))
                return false;

            CreateTrigger(triggerInfo);
            return true;
        }
Exemple #4
0
        internal TriggerBody(TriggerInfo triggerInfo)
        {
            if (triggerInfo == null)
                throw new ArgumentNullException("triggerInfo");

            TriggerInfo = triggerInfo;

            statements = new List<SqlStatement>();
        }
Exemple #5
0
        /// <summary>
        /// Constructs a trigger with the given information.
        /// </summary>
        /// <param name="triggerInfo">The object defining the information
        /// of this trigger.</param>
        /// <exception cref="ArgumentNullException">
        /// If the provided <paramref name="triggerInfo"/> is <c>null</c>.
        /// </exception>
        public Trigger(TriggerInfo triggerInfo)
        {
            if (triggerInfo == null)
            {
                throw new ArgumentNullException("triggerInfo");
            }

            TriggerInfo = triggerInfo;
        }
Exemple #6
0
        public bool AlterTrigger(TriggerInfo triggerInfo)
        {
            if (!DropTrigger(triggerInfo.TriggerName))
            {
                return(false);
            }

            CreateTrigger(triggerInfo);
            return(true);
        }
        public static void CreateTrigger(this ISession session, TriggerInfo triggerInfo)
        {
            var manager = session.Transaction.GetTriggerManager();

            if (manager == null)
            {
                return;
            }

            manager.CreateTrigger(triggerInfo);
        }
Exemple #8
0
        internal TriggerBody(TriggerInfo triggerInfo)
        {
            if (triggerInfo == null)
            {
                throw new ArgumentNullException("triggerInfo");
            }

            TriggerInfo = triggerInfo;

            statements = new List <SqlStatement>();
        }
Exemple #9
0
        public static void DeclareTrigger(this IContext context, TriggerInfo triggerInfo)
        {
            var current = context;
            while (current != null) {
                if (current is ITriggerScope) {
                    var scope = (ITriggerScope) current;
                    scope.TriggerManager.CreateTrigger(triggerInfo);
                    return;
                }

                current = current.Parent;
            }

            throw new InvalidOperationException("No trigger scope found in context");
        }
Exemple #10
0
        public static void DeclareTrigger(this IContext context, TriggerInfo triggerInfo)
        {
            var current = context;

            while (current != null)
            {
                if (current is ITriggerScope)
                {
                    var scope = (ITriggerScope)current;
                    scope.TriggerManager.CreateTrigger(triggerInfo);
                    return;
                }

                current = current.Parent;
            }

            throw new InvalidOperationException("No trigger scope found in context");
        }
Exemple #11
0
        public void CreateTrigger(TriggerInfo triggerInfo)
        {
            if (!transaction.TableExists(SystemSchema.TriggerTableName))
            {
                return;
            }

            try {
                var args    = new TriggerArgument(triggerInfo.Arguments.ToArray());
                var binArgs = SerializeArguments(args);

                var schema        = triggerInfo.TriggerName.ParentName;
                var name          = triggerInfo.TriggerName.Name;
                var type          = (int)triggerInfo.TriggerType;
                var onTable       = triggerInfo.TableName == null ? null : triggerInfo.TableName.FullName;
                var procedureName = triggerInfo.ProcedureName != null ? triggerInfo.ProcedureName.FullName : null;

                var action = (int)triggerInfo.EventType;

                // TODO: if the trigger has a body, create a special procedure and set the name

                // Insert the entry into the trigger table,
                var table = transaction.GetMutableTable(SystemSchema.TriggerTableName);
                var row   = table.NewRow();
                row.SetValue(0, DataObject.String(schema));
                row.SetValue(1, DataObject.String(name));
                row.SetValue(2, DataObject.Integer(type));
                row.SetValue(3, DataObject.String(onTable));
                row.SetValue(4, DataObject.Integer(action));
                row.SetValue(5, DataObject.String(procedureName));
                row.SetValue(6, DataObject.Binary(binArgs));
                table.AddRow(row);

                InvalidateTriggerCache();

                transaction.Registry.RegisterEvent(new ObjectCreatedEvent(triggerInfo.TriggerName, DbObjectType.Trigger));

                tableModified = true;
            } catch (Exception) {
                // TODO: use a specialized exception
                throw;
            }
        }
Exemple #12
0
 void ITriggerManager.CreateTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger((CallbackTriggerInfo)triggerInfo);
 }
Exemple #13
0
        public void CreateTrigger(TriggerInfo triggerInfo)
        {
            if (!transaction.TableExists(SystemSchema.TriggerTableName))
                return;

            try {
                var args = triggerInfo.Arguments.ToArray();
                var binArgs = SqlExpression.Serialize(args);

                var schema = triggerInfo.TriggerName.ParentName;
                var name = triggerInfo.TriggerName.Name;
                var type = (int) triggerInfo.TriggerType;
                var onTable = triggerInfo.TableName == null ? null : triggerInfo.TableName.FullName;
                var procedureName = triggerInfo.ProcedureName != null ? triggerInfo.ProcedureName.FullName : null;

                var action = (int) triggerInfo.EventType;

                // TODO: if the trigger has a body, create a special procedure and set the name

                // Insert the entry into the trigger table,
                var table = transaction.GetMutableTable(SystemSchema.TriggerTableName);
                var row = table.NewRow();
                row.SetValue(0, DataObject.String(schema));
                row.SetValue(1, DataObject.String(name));
                row.SetValue(2, DataObject.Integer(type));
                row.SetValue(3, DataObject.String(onTable));
                row.SetValue(4, DataObject.Integer(action));
                row.SetValue(5, DataObject.String(procedureName));
                row.SetValue(6, DataObject.Binary(binArgs));
                table.AddRow(row);

                InvalidateTriggerCache();

                transaction.Registry.RegisterEvent(new ObjectCreatedEvent(triggerInfo.TriggerName, DbObjectType.Trigger));

                tableModified = true;
            } catch (Exception) {
                // TODO: use a specialized exception
                throw;
            }
        }
Exemple #14
0
 public bool AlterTrigger(TriggerInfo triggerInfo)
 {
     throw new NotImplementedException();
 }
Exemple #15
0
 public bool AlterTrigger(TriggerInfo triggerInfo)
 {
     throw new NotImplementedException();
 }
Exemple #16
0
 public bool CanFire(TableEvent tableEvent)
 {
     return(TriggerInfo.CanFire(tableEvent));
 }
Exemple #17
0
 void ITriggerManager.RegisterTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger(triggerInfo);
 }
 //public static void FireTrigger(this IQueryContext context, TableEventContext tableEvent) {
 //    var tableName = tableEvent.Table.FullName;
 //    var eventType = tableEvent.EventType;
 //    try {
 //        var triggers = context.Session.FindTriggers(tableName, eventType);
 //        foreach (var trigger in triggers) {
 //            try {
 //                trigger.Invoke(tableEvent);
 //                var oldRowId = tableEvent.OldRowId;
 //                var newRow = tableEvent.NewRow;
 //                context.FireTrigger(trigger.TriggerName, tableName, eventType, oldRowId, newRow);
 //            } catch (Exception ex) {
 //                context.RegisterTriggerError(trigger, ex);
 //            }
 //        }
 //    } catch (TableEventException ex) {
 //        context.RegisterError(ex);
 //        throw;
 //    } catch (Exception ex) {
 //        context.RegisterTableEventError(tableEvent, ex);
 //        throw new TableEventException(tableEvent, ex);
 //    }
 //}
 //private static void RegisterTriggerError(this IQueryContext context, Trigger trigger, Exception error) {
 //    context.RegisterError(new TriggerException(trigger, error));
 //}
 //private static void RegisterTableEventError(this IQueryContext context, TableEventContext @event, Exception error) {
 //    context.RegisterError(new TableEventException(@event, error));
 //}
 public static void CreateTrigger(this IQueryContext context, TriggerInfo triggerInfo)
 {
     context.Session().CreateTrigger(triggerInfo);
 }
 void ITriggerManager.CreateTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger((CallbackTriggerInfo) triggerInfo);
 }
Exemple #20
0
        public void CreateTrigger(TriggerInfo triggerInfo)
        {
            if (!transaction.TableExists(TriggerTableName))
            {
                return;
            }

            var schema  = triggerInfo.TriggerName.ParentName;
            var name    = triggerInfo.TriggerName.Name;
            var onTable = triggerInfo.TableName.FullName;

            var time   = (int)triggerInfo.EventTime;
            var action = (int)triggerInfo.EventType;

            int type;

            if (triggerInfo is ProcedureTriggerInfo)
            {
                type = ProcedureType;
            }
            else if (triggerInfo is PlSqlTriggerInfo)
            {
                type = PlSqlType;
            }
            else
            {
                throw new ArgumentException("The specified trigger info is invalid.");
            }

            // Insert the entry into the trigger table,
            var table = transaction.GetMutableTable(TriggerTableName);
            var row   = table.NewRow();

            row.SetValue(0, Field.String(schema));
            row.SetValue(1, Field.String(name));
            row.SetValue(2, Field.Integer(type));
            row.SetValue(3, Field.String(onTable));
            row.SetValue(4, Field.Integer(time));
            row.SetValue(5, Field.Integer(action));

            if (type == ProcedureType)
            {
                var procInfo = (ProcedureTriggerInfo)triggerInfo;

                var args    = new TriggerArgument(procInfo.Arguments);
                var binArgs = SerializeArguments(args);

                var procedureName = procInfo.ProcedureName.FullName;
                row.SetValue(6, Field.String(procedureName));
                row.SetValue(7, Field.Binary(binArgs));
            }
            else if (type == PlSqlType)
            {
                var plsqlInfo = (PlSqlTriggerInfo)triggerInfo;
                var body      = Field.Binary(SqlBinary.ToBinary(plsqlInfo.Body));
                row.SetValue(8, body);
            }

            row.SetValue(9, Field.TinyInt((byte)triggerInfo.Status));

            table.AddRow(row);

            InvalidateTriggerCache();

            transaction.OnObjectCreated(DbObjectType.Trigger, triggerInfo.TriggerName);

            tableModified = true;
        }
        //public static void FireTrigger(this IQueryContext context, TableEventContext tableEvent) {
        //	var tableName = tableEvent.Table.FullName;
        //	var eventType = tableEvent.EventType;

        //	try {
        //		var triggers = context.Session.FindTriggers(tableName, eventType);

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

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

        //				context.FireTrigger(trigger.TriggerName, tableName, eventType, oldRowId, newRow);
        //			} catch (Exception ex) {
        //				context.RegisterTriggerError(trigger, ex);
        //			}
        //		}
        //	} catch (TableEventException ex) {
        //		context.RegisterError(ex);
        //		throw;
        //	} catch (Exception ex) {
        //		context.RegisterTableEventError(tableEvent, ex);
        //		throw new TableEventException(tableEvent, ex);
        //	}
        //}

        //private static void RegisterTriggerError(this IQueryContext context, Trigger trigger, Exception error) {
        //	context.RegisterError(new TriggerException(trigger, error));
        //}

        //private static void RegisterTableEventError(this IQueryContext context, TableEventContext @event, Exception error) {
        //	context.RegisterError(new TableEventException(@event, error));
        //}

        public static void CreateTrigger(this IQueryContext context, TriggerInfo triggerInfo)
        {
            context.Session().CreateTrigger(triggerInfo);
        }
Exemple #22
0
        public void CreateTrigger(TriggerInfo triggerInfo)
        {
            if (!transaction.TableExists(TriggerTableName))
                return;

            var schema = triggerInfo.TriggerName.ParentName;
            var name = triggerInfo.TriggerName.Name;
            var onTable = triggerInfo.TableName.FullName;

            var time = (int) triggerInfo.EventTime;
            var action = (int) triggerInfo.EventType;

            int type;
            if (triggerInfo is ProcedureTriggerInfo) {
                type = ProcedureType;
            } else if (triggerInfo is PlSqlTriggerInfo) {
                type = PlSqlType;
            } else {
                throw new ArgumentException("The specified trigger info is invalid.");
            }

            // Insert the entry into the trigger table,
            var table = transaction.GetMutableTable(TriggerTableName);
            var row = table.NewRow();
            row.SetValue(0, Field.String(schema));
            row.SetValue(1, Field.String(name));
            row.SetValue(2, Field.Integer(type));
            row.SetValue(3, Field.String(onTable));
            row.SetValue(4, Field.Integer(time));
            row.SetValue(5, Field.Integer(action));

            if (type == ProcedureType) {
                var procInfo = (ProcedureTriggerInfo) triggerInfo;

                var args = new TriggerArgument(procInfo.Arguments);
                var binArgs = SerializeArguments(args);

                var procedureName = procInfo.ProcedureName.FullName;
                row.SetValue(6, Field.String(procedureName));
                row.SetValue(7, Field.Binary(binArgs));
            } else if (type == PlSqlType) {
                var plsqlInfo = (PlSqlTriggerInfo) triggerInfo;
                var body = Field.Binary(SqlBinary.ToBinary(plsqlInfo.Body));
                row.SetValue(8, body);
            }

            row.SetValue(9, Field.TinyInt((byte) triggerInfo.Status));

            table.AddRow(row);

            InvalidateTriggerCache();

            transaction.OnObjectCreated(DbObjectType.Trigger, triggerInfo.TriggerName);

            tableModified = true;
        }
 void ITriggerManager.RegisterTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger(triggerInfo);
 }
Exemple #24
0
 void ITriggerManager.CreateTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger(triggerInfo);
 }
Exemple #25
0
 public void CreateTrigger(TriggerInfo triggerInfo)
 {
     throw new NotImplementedException();
 }
Exemple #26
0
 void ITriggerManager.CreateTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger(triggerInfo);
 }