Question
· Sep 12, 2016

Class change trigger

Hello community,

Is there a way in Caché to trigger some method when any class changes? For example, if I edit any class in any namespace, when I save this class I want some method to be triggered with the class name parameter or any available data about the class.

Concretely, I tried to add a %OnAfterSave() callback to the %Dictionary.ClassDefinition  class, but this method is not triggerred when any class saved as I expected. I am writing a project in Caché and the purpose of my project is to show editing history of the edited classes in the Caché studio.

Thank you in advance for your response.

Discussion (2)0
Log in or sign up to continue

Here are some thoughts:

  • Write Source Control Hook that implemets OnAfterSave method and checks there (or maybe some other entry point). There are several sample source control hook classes, check them out.
  • Use ^rINDEXCLASS global (key - class name in uppercase) - it contains some basic information such as modification time (1st position) and hash (13th position). You can monitor it and if time or hash changes then record the new class version.
  • Use lock table to see what classes are currently being edited
  • Use $$$defClassKeyGet macros (see %Dictionary.ClassDefinition/%Dictionary.CompiledClass definitions, they use these macros a lot) to get info about modification time/hash and the changes themselves
  • %Compiler.UDL.TextServices to get the class text

I would have done it like this:

  • Background process monitors ^rINDEXCLASS global
  • Upon finding changes get the current class code via %Compiler.UDL.TextServices class,  GetTextAsStream method
  • Write this information into your own class (classname, timestamp, user, classtext, diff, previousversion)

Modification of system classes is not a very good idea:

  • They are lost on update
  • User may not have access required to install these changes

That being said, the best solution in my opinion is to setup your critical/production systems in such a way, that developers do not have direct write access to them. Each of the developers have their own environment where they can do whatever and then commit it to source control system. Continuous integration solution (or one developer or a script) then uploads the code (after it passes the tests) to the production server. There are several source control/continuous integration systems available for Caché.

It is a good idea that a change can only be done via source control commit. All other changes simply should not exist.