(Created page with "==== Background ==== In OCL you can’t use assignment because MDriven needs to know that OCL-statements can’t change things. You always use EAL to change the objects of you...") |
No edit summary |
||
Line 30: | Line 30: | ||
) | ) | ||
'''Note!''' OnCreate, OnUpdate and OnDelete are hard-coded names, you have to use these function names. | '''Note!''' OnCreate, OnUpdate and OnDelete are hard-coded names, you have to use these function names. | ||
[[Category:Actions]] | |||
[[Category:OCL]] | |||
[[Category:EAL]] |
Revision as of 11:06, 25 July 2017
Background
In OCL you can’t use assignment because MDriven needs to know that OCL-statements can’t change things. You always use EAL to change the objects of your model.
All viewmodel expressions are side effect free and therefore OCL. Only actions and methods work on the object and classes of the model, not the viewmodel expressions, which defines a projection.
Acting on object events
In the default model of the designer, you will find the methods OnCreate() and OnUpdate() with the content from the template below.
If you need a copy of something, for example to log a previous state and therefore don’t want it derived, you can add an OnUpdate() metod on the class.
Note that methods on classes can be “queries” or not. Methods marked as “IsQuery” are OCL, and therefore side-effect free and can be used in other OCL statements.
OnCreate, OnUpdate and OnDelete all has to have IsQuery set to false, thus being EAL methods to act on the model objects.
Template for
- Time stamp all new and updated objects
- Setting an unique identifier on all objects
- Logging deleted objects to an "archive class" holding the Guid of the deleted object
In the method body for OnCreate set this ocl:
CreateTime:=DateTime.Now; self.Guid.newGuid()
In the method body for OnUpdate set this ocl:
self.ChangeTime:=DateTime.Now
In the method body of OnDelete set this ocl:
let deleted = DeletedObj.Create in ( deleted.DeletedGuid := self.Guid )
Note! OnCreate, OnUpdate and OnDelete are hard-coded names, you have to use these function names.