Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

...

...

SCHEMA MyExpressSchema;
    ENTITY MyEntity;
        attr1 : STRING;
    END_ENTITY;
END_SCHEMA;
 
TRIGGER_SCHEMA MyTriggerSchema FOR MyExpressSchema;
    DECLARE target_model INSTANCE OF MyExpressSchema;
 
---------------------------------------------------------------------------
-- the system recognized events is proposed to define as INTEGER XPX pseudo constants
-- then we can expand range of trigger events without enhancing grammar
-- declaration can be assumed as something like:
---------------------------------------------------------------------------
trigger_source = ENUMERATION OF(
        XPX_Create_Entity,      -- raised after entity is created
        XPX_Delete_Entity,      -- raised before an entity is deleted
        XPX_Read_Entity,        -- any attribute is accessed
        XPX_Write_Entity,       -- any attribute is modified
 
        XPX_Pre_Set_Attribute,      -- raised before specified attribute is assigned (do we need PRE/POST?)
        XPX_Post_Set_Attribute,     -- raised after specified attribute is assigned (do we need PRE/POST?)
        XPX_Pre_Unset_Attribute,    -- raised before an attribute is set to UNSET
        XPX_Post_Unset_Attribute,   -- raised after an attribute is set to UNSET
        XPX_Read_Attribute,         -- any attribute is accessed
 
        XPX_Create_Model,       -- raised after model is created
        XPX_Delete_Model,       -- raised before model is deleted
        XPX_Read_Model,         -- raised if any data in model accessed (pre)
        XPX_Write_Model,        -- raised if any data in model written (pre)
 
        XPX_Commit_Write_Transaction,       -- raised just before write transaction committed (what about tx levels?)
        XPX_Abort_Write_Transaction,        -- raised just before write transaction aborted(what about tx levels?)
 
    );
 
---------------------------------------------------------------------------
-- An event is handeled as a system entity ala XPXEXCEPTION
---------------------------------------------------------------------------

	ENTITY XPXEVENT;
		xpxEventType 	: INTEGER;
		xpxEventTarget 	: GENERIC_ENTITY;
		xpxEventTime	: _DATETIME;
		xpxEventSource	: GENERIC_ENTITY;	-- the schema/function active when event was raised
		xpxEventUser	: GENERIC_ENTITY;	-- user logged in when event was raised
		<... more ...>
	END_ENTITY;
 
---------------------------------------------------------------------------
-- we use the DECLARE keyword to connect events to handlers
-- Pattern: DECLARE trigger_function TRIGGER_FUNCTION(trigger_source) FOR (target);
---------------------------------------------------------------------------
    DECLARE EntityTrigger       TRIGGER_FUNCTION(XPX_Create_Entity)     FOR MyEntity;
    DECLARE AttributeTrigger    TRIGGER_FUNCTION(XPX_Pre_SetAttribute)  FOR MyEntity.MyAttribute;
    DECLARE ModelTrigger        TRIGGER_FUNCTION(XPX_Create_Model)      FOR target_model;
 
     
    TRIGGER_FUNCTION EntityTrigger(theEntity: GENERIC_ENTITY) : GENERIC;
        RETURN(?);
    END_TRIGGER_FUNCTION;
 
    TRIGGER_FUNCTION AttributeTrigger(theEntity: GENERIC_ENTITY) : GENERIC; -- look in DECLARE TRIGGER declarartion to identify attribute
        RETURN(?);
    END_TRIGGER_FUNCTION;
 
    TRIGGER_FUNCTION ModelTrigger(theModel: GENERIC_ENTITY) : GENERIC; -- theModel will refer to SDAI_MODEL instance
        RETURN(?);
    END_TRIGGER_FUNCTION;
     
     
---------------------------------------------------------------------------
-- so for possibility to user defined events
-- firstly the events need to be enumerated somehow. Not trivial as they are cross-schema and cross-model
-- could be kept in a trigger schema, meaning both raise and catch must be done within that schema.
-- anyway, if identified as integer constants we may declare them as such:
---------------------------------------------------------------------------
    CONSTANT
        somethingCreatedEvent : INTEGER := 1001;
        somethingDeletedEvent : INTEGER := 1002;
    END_CONSTANT;
     
-- to raise events - easy way out is to use same technique as for XPX exception:       
    PROCEDURE ThrowAnEvent(arg : GENERIC);
        xpxRaiseEvent(eventType,eventTarget,.....);
    EBD_PROCEDURE;
     
 
-- to catch events is like catching trigger events, so we use same declaration
-- Pattern: DECLARE eventHandler TRIGGER(eventType) FOR target; -- target is a model I think...
     
    DECLARE EventHandler TRIGGER_FUNCTION(somethingCreatedEvent) FOR target_model;
    DECLARE EventHandler TRIGGER_FUNCTION(somethingDeletedEvent) FOR target_model;
     
    TRIGGER_FUNCTION EventHandler(event : GENERIC_ENTITY) : GENERIC;
    LOCAL
        myEventType : INTEGER;
    END_LOCAL;
        myEventType := event.XPXEventType;
        RETURN(?); 
    END_TRIGGER_FUNCTION;
     
END_TRIGGER_SCHEMA;

 

  • Some alternates:.
Code Block
Proposed:
    DECLARE EventHandler TRIGGER_FUNCTION(somethingCreatedEvent) FOR target_model;
 
Alt:
    DECLARE EventHandler(somethingDeletedEvent) TRIGGER_FUNCTION FOR target_model;
    DECLARE TRIGGER_FUNCTION EventHandler(somethingCreatedEvent) FOR target_model;

Q&A:

What is aim to introduce the stuff?

...

Note

Comments wanted!

Since we are about to enable EEX TEX in the EDM it is importrant that any missing or non optimal functionality are noted and corrected. Comments can be posted here or sent to Arne T.

...