Deveel.Data.Sql.Statements.CreateTriggerStatement.ExecuteStatement C# (CSharp) Method

ExecuteStatement() protected method

protected ExecuteStatement ( ExecutionContext context ) : void
context ExecutionContext
return void
        protected override void ExecuteStatement(ExecutionContext context)
        {
            //if (!context.User.CanCreateInSchema(TriggerName.ParentName))
            //	throw new SecurityException(String.Format("The user '{0}' cannot create in schema '{1}'.", context.User.Name, TriggerName.ParentName));

            if (!context.DirectAccess.TableExists(TableName))
                throw new ObjectNotFoundException(TableName);

            // TODO: Discover the accessed objects in the Body and verifies the user has the rights

            if (context.DirectAccess.ObjectExists(DbObjectType.Trigger, TriggerName)) {
                if (!ReplaceIfExists)
                    throw new StatementException(String.Format("A trigger named '{0}' already exists.", TriggerName));

                context.DirectAccess.DropObject(DbObjectType.Trigger, TriggerName);
            }

            var triggerInfo = new PlSqlTriggerInfo(TriggerName, TableName, EventTime, EventType, Body);

            if (Status != TriggerStatus.Unknown)
                triggerInfo.Status = Status;

            context.DirectAccess.CreateObject(triggerInfo);
            context.DirectAccess.GrantOn(DbObjectType.Trigger, TableName, context.User.Name, PrivilegeSets.SchemaAll, true);
        }