Page tree

Versions Compared

Key

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

...

Extend the DatabaseTriggerLoadService class

This new class will be used to dynamically load the specified database triggers.

Akioma.Swat.Server.Startup.DatabaseTriggerLoadService is a SWAT class which implements the IDatabaseTriggerLoadService interface. You will need to extend this class.

The new class will be used to dynamically load the specified database triggers on top of any triggers loaded from SWAT.

You can specify the triggers to load in the LoadTriggers method of the class.

It is recommended to extend the existing SWAT implementation instead of writing a new implementation for the interface, since triggers may also be loaded from SWAT.

...

Code Block
titleCustom Database Trigger Example
collapsetrue
USING Progress.Lang.*.

BLOCK-LEVEL ON ERROR UNDO, THROW.

CLASS Custom.CustomDatabaseTriggerLoadService
  INHERITS Akioma.Swat.Server.Startup.DatabaseTriggerLoadService:	//inherits the existing SWAT implementation

  METHOD PUBLIC OVERRIDE VOID LoadTriggers():
    SUPER:LoadTriggers().	//calls super in case triggers are loaded from SWAT
    
    RUN loadCustomTriggers.p PERSISTENT. // procedure to include custom triggers
  END METHOD.
END CLASS.

...

Override the existing IDatabaseTriggerLoadService service

IDatabaseTriggerLoadService is an interface which is implemented by the DatabaseTriggerLoadService class.

In order to make use of this new classimplementation, we will need to override the default trigger load service in the services.xml file by including the following:


Code Block
titleOverride Default Trigger Load Service
collapsetrue
<ttServiceLoaderRow>
    <Order>0</Order>
    <ServiceTypeName>Akioma.Swat.Server.Startup.IDatabaseTriggerLoadService</ServiceTypeName>
    <ServiceClassName>Custom.CustomDatabaseTriggerLoadService</ServiceClassName>
</ttServiceLoaderRow>

This will specify which class implementation is used for the IDatabaseTriggerLoadService service.


Load the custom triggers

In the above example, we run loadCustomTriggers.p from the LoadTriggers method. A possible implementation of the procedure will look like this:

Code Block
titleloadCustomTriggers.p
collapsetrue
{Custom/Triggers/myCreateTrigger.i}	//here, we just include the desired triggers



Info
titleTrigger
Each trigger can be a separate procedure (.p) - the directory of these triggers needs to be in the PROPATH


Trigger implementation

Inside the trigger itself:

Code Block
titlemyCreateTrigger.i
collapsetrue
ON CREATE OF myTable
DO:
  MESSAGE "Created new record".
END.