OCL derived properties and PSQuery

CapableObjects Forums SupportForum OCL derived properties and PSQuery

This topic contains 8 replies, has 5 voices, and was last updated by  Admin 4 years, 8 months ago.

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #1960 Score: 0

    Peter Buchmann
    Participant

    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?

    #1962 Score: 0

    PeterMorris
    Participant

    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.

    #1963 Score: 0

    Peter Buchmann
    Participant

    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 OK

    #1966 Score: 0

    lbernas
    Participant

    Hi,

    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?

    #1968 Score: 0

    Admin
    Keymaster

    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

    #1969 Score: 0

    lbernas
    Participant

    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 Bernas

    #1970 Score: 0

    Peter Buchmann
    Participant

    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”

    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?

    #1977 Score: 0

    efim
    Participant

    > 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?

    #2071 Score: 0

    Admin
    Keymaster

    This is now implemented like this: //www.capableobjects.com/2014/11/07/derivation-is-not-available-in-the-database/

Viewing 9 posts - 1 through 9 (of 9 total)

You must be logged in to reply to this topic.

One Response to OCL derived properties and PSQuery

  1. Pingback: Derivation is not available in the database | CapableObjects