CapableObjects › Forums › SupportForum › OCL derived properties and PSQuery
This topic contains 8 replies, has 5 voices, and was last updated by Admin 7 years, 9 months ago.
-
AuthorPosts
-
We sometimes have the requirement to use OCL derived properties in queries. We now came to the issue that we need a derived property in a PSQuery. This always ends up in the discussion how we implement this without doubling code.
But we thought that MDriven could maybe convert the OCL of the derived property into a expression that could be part of a PSQuery.
Could this be possible?
I’ve not taken part in discussing this subject for some time, but I suppose if you checked all dirty objects at the point of UpdateDatabase you could evaluate the value of derived attributes that have a custom tag identifying another attribute to stuff the value into before saving.
It’d mean that the object in question would have to be dirty.
It seems I wasn’t able to explain my question properly. So another try:
Just imagine we have two persistend date attributes StartDate and EndDate and a derived Attribute called IsActual that checks that the current date is between StartDate and EndDate.Then we can use the Attribute IsActual in MemQueries (or OCL queries) but not in PSQuerries and OCLPS queries because it is derived.
When you have a MemQuery using this Attribute and convert it into a PSQuery, you have to resolve the OCL of the derived property manually into a Expression. This is code doubling because you need the code twice, first in OCL and also as a method returning the Expression (just assume this as a solution).
I assume that CO could be possible to transform the OCL Expression string into a Expression that could be used in a PSQuery so that following would pe possible:
var data = EcoSpace.PSQuery<class1>().Where(x=>x.IsActual).ToList(); // works like other attributes, would be best
or maybe
var data = EcoSpace.PSQuery<class1>().Where(x=>Eco.Linq.TransformToExpression(x,”IsActual”)).ToList(); // Would also be OKHi,
We have had similar problems,as I guess most people using MDriven have at some point.
It would be a nice extension to auto convert OCL to its equivalent PS-supported expression, I don’t think it would be easy to do autoconversion on a framework level if you want all possible derivations supported. Maybe one possibility would be to add a tag “SupportsPS” or similar to OCL derived properties, and then, provided that their derivation OCL supports PS-evaluation, the “conversion” would basically be a simple replace operation.
We have not used this approach, and of course has limitations. But maybe would be enough for where it is needed?
We can probably do some tests to see how it turns out on a strategy like this
“If anything in the expression is derived, replace with its definition, repeat until nothing is derived in expression”PS expressions will then possibly work or repeat the error on the expanded expression
A bit off topic, but we have an “OCL fetcher” for Bold that conceptually works according to the mentioned principle. It doesn’t translate queries, but traverse the expression finding out which members to ensure. You have to tag code derived members with a prefetch expression, but provided all code derived stuff has prefetch expression defined, you can pass any OCL to it and ensure the accessed objects are loaded. Contact me if you think it could be of help, either when translating OCL -> OCLPS queries, or perhaps porting the fetcher to MDriven.
Regards,
Linus BernasWe can probably do some tests to see how it turns out on a strategy like this
“If anything in the expression is derived, replace with its definition, repeat until nothing is derived in expression”Sounds good and should be sufficient. I wouldn’t expect more complex OCL expressions to work. Everything that e.g. contains a “let”, a “if” or a “allInstances” can’t be translated into PS. But normal expressions, why not?
> We can probably do some tests to see how it turns out on a strategy like this
“If anything in the expression is derived, replace with its definition, repeat until nothing is derived in expression”… or until anything is code-derived?
This is now implemented like this: //www.capableobjects.com/2014/11/07/derivation-is-not-available-in-the-database/
-
AuthorPosts
You must be logged in to reply to this topic.