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
Ejemplo n.º 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;
        }
Ejemplo n.º 2
0
        public static void CreateTrigger(this IUserSession session, TriggerInfo triggerInfo)
        {
            var manager = session.Transaction.GetTriggerManager();
            if (manager == null)
                return;

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

            CreateTrigger(triggerInfo);
            return true;
        }
Ejemplo n.º 4
0
        internal TriggerBody(TriggerInfo triggerInfo)
        {
            if (triggerInfo == null)
                throw new ArgumentNullException("triggerInfo");

            TriggerInfo = triggerInfo;

            statements = new List<SqlStatement>();
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 6
0
        public bool AlterTrigger(TriggerInfo triggerInfo)
        {
            if (!DropTrigger(triggerInfo.TriggerName))
            {
                return(false);
            }

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

            if (manager == null)
            {
                return;
            }

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

            TriggerInfo = triggerInfo;

            statements = new List <SqlStatement>();
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 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");
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 12
0
 void ITriggerManager.CreateTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger((CallbackTriggerInfo)triggerInfo);
 }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 14
0
 public bool AlterTrigger(TriggerInfo triggerInfo)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 15
0
 public bool AlterTrigger(TriggerInfo triggerInfo)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 16
0
 public bool CanFire(TableEvent tableEvent)
 {
     return(TriggerInfo.CanFire(tableEvent));
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 19
0
 void ITriggerManager.CreateTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger((CallbackTriggerInfo) triggerInfo);
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 21
0
        //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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 23
0
 void ITriggerManager.RegisterTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger(triggerInfo);
 }
Ejemplo n.º 24
0
 void ITriggerManager.CreateTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger(triggerInfo);
 }
Ejemplo n.º 25
0
 public void CreateTrigger(TriggerInfo triggerInfo)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 26
0
 void ITriggerManager.CreateTrigger(TriggerInfo triggerInfo)
 {
     CreateTrigger(triggerInfo);
 }