Derivation is not available in the database
No edit summary
(Updated Edited template to July 12, 2025.)
 
(11 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Derivation is a very good way to remove the need for repeating definitions.
<message>Write the content here to display this box</message>
Derivation is useful to remove the need for repeating definitions.


Suppose you have this model:
Suppose you have this model:
[[File:101.png|none|thumb|417x417px]]


An apartment has Occupants that may have pets of different breeds.
An apartment has occupants that may have pets of different breeds.


Suppose your logic calls for frequent subsets of information maybe like this:
Suppose your logic calls for frequent subsets of information, maybe like this:
[[File:102.png|none|thumb|446x446px]]


3 different derivations on this model:
3 different derivations of this model:
 
* Apartment.TheDogs = self.Occupants.Pets->select(p|p.PetType.Breed='Dog')
Apartment.TheDogs = self.Occupants.Pets->select(p|p.PetType.Breed='Dog')
* Apartment.Grownups = self.Grownups->select(x|x.Age>=18)
 
* Apartment.AreThereDogs = self.TheDogs->size>0
Apartment.Grownups = self.Grownups->select(x|x.Age>=18)
All is well and everyone is happy, until you want to do a search in the database – when the OCL or Linq gets translated to SQL…
 
Apartment.AreThereDogs = self.TheDogs->size>0
 
All is well and everyone is happy.
 
Until you want to do search in the database – when the OCL or Linq gets translated to Sql…


The problem is that the derivations are at the model level and are not available in persistent storage…
The problem is that the derivations are at the model level and are not available in persistent storage…


To remove the need for retyping the same definition again when you want to fetch in PS it would be much better to be able to use the derived association by having it translated into persistent members.
To remove the need for retyping the same definition again when you want to fetch in PS, it would be much better to use the derived association by translating it into persistent members.


This is what we want to do:
This is what we want to do:


<html> <pre class="code">          <span style="background: white; color: blue;">var </span><span style="background: white; color: black;">ocl=</span><span style="background: white; color: #2b91af;">EcoServiceHelper</span><span style="background: white; color: black;">.GetEcoService&lt;</span><span style="background: white; color: #2b91af;">IOclService</span><span style="background: white; color: black;">&gt;(EcoSpace);</span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">exp1 = ocl.ExpandDerivationsInExpression(</span><span style="background: white; color: #a31515;">"Apartment.allinstances.TheDogs-&gt;select(x|x.Name='Benji')"</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">false</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">);</span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">exp2 = ocl.ExpandDerivationsInExpression(</span><span style="background: white; color: #a31515;">"Apartment.allinstances.Grownups-&gt;intersection(Apartment.allinstances.TheDogs.Owner)"</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">false</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">);And the result in exp1 and exp2 are:</span></pre><pre class="code"><span style="background: white; color: black;"><em>exp1=<span style="color: #ff0000;">Apartment.allinstances.Occupants.Pets-&gt;select(p|p.PetType.Breed = 'Dog')-&gt;select(x|x.Name = 'Benji')</span></em></span></pre>  
<html> <pre class="code"><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">ocl=</span><span style="background: white; color: #2b91af;">EcoServiceHelper</span><span style="background: white; color: black;">.GetEcoService&lt;</span><span style="background: white; color: #2b91af;">IOclService</span><span style="background: white; color: black;">&gt;(EcoSpace);</span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">exp1 = ocl.ExpandDerivationsInExpression(</span><span style="background: white; color: #a31515;">"Apartment.allinstances.TheDogs-&gt;select(x|x.Name='Benji')"</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">false</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">);</span><span style="background: white; color: blue;">var </span><span style="background: white; color: black;">exp2 = ocl.ExpandDerivationsInExpression(</span><span style="background: white; color: #a31515;">"Apartment.allinstances.Grownups-&gt;intersection(Apartment.allinstances.TheDogs.Owner)"</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">false</span><span style="background: white; color: black;">, </span><span style="background: white; color: blue;">null</span><span style="background: white; color: black;">);And the result in exp1 and exp2 are:</span></pre><pre class="code"><span style="background: white; color: black;"><em>exp1=<span style="color: #ff0000;">Apartment.allinstances.Occupants.Pets-&gt;select(p|p.PetType.Breed = 'Dog')-&gt;select(x|x.Name = 'Benji')</span></em></span></pre>  
<pre class="code"><span style="background: white; color: black;"><em>exp2=<span style="color: #ff0000;">Apartment.allinstances.Occupants-&gt;select(x|x.Age &gt;= 18)-&gt;intersection(
<pre class="code"><span style="background: white; color: black;"><em>exp2=<span style="color: #ff0000;">Apartment.allinstances.Occupants-&gt;select(x|x.Age &gt;= 18)-&gt;intersection(
                       Apartment.allinstances.Occupants.Pets-&gt;
                       Apartment.allinstances.Occupants.Pets-&gt;
Line 32: Line 29:


</html>
</html>
The MDriven Framework does the expansion for you so that you can keep and maintain as few and small definitions as possible.
This new functionality surfaces here:
* In IOclService:
* In IOclPsService:
* In PSQuery and EcoQuery PS (same); automatically expands derivations PS fetch.
The SearchLogic that Wecpof uses; automatically expands derivations PS fetch.
This is the suggested solution to [//www.capableobjects.com/forums/topic/ocl-derived-properties-and-psquery/ this discussion].
[[Category:Derivations]]
{{Edited|July|12|2025}}

Latest revision as of 05:48, 20 January 2025

This page was created by Alexandra on 2018-11-28. Last edited by Edgar on 2025-01-20.

Derivation is useful to remove the need for repeating definitions.

Suppose you have this model:

101.png

An apartment has occupants that may have pets of different breeds.

Suppose your logic calls for frequent subsets of information, maybe like this:

102.png

3 different derivations of this model:

  • Apartment.TheDogs = self.Occupants.Pets->select(p|p.PetType.Breed='Dog')
  • Apartment.Grownups = self.Grownups->select(x|x.Age>=18)
  • Apartment.AreThereDogs = self.TheDogs->size>0

All is well and everyone is happy, until you want to do a search in the database – when the OCL or Linq gets translated to SQL…

The problem is that the derivations are at the model level and are not available in persistent storage…

To remove the need for retyping the same definition again when you want to fetch in PS, it would be much better to use the derived association by translating it into persistent members.

This is what we want to do:

var ocl=EcoServiceHelper.GetEcoService<IOclService>(EcoSpace);var exp1 = ocl.ExpandDerivationsInExpression("Apartment.allinstances.TheDogs->select(x|x.Name='Benji')", null, false, null);var exp2 = ocl.ExpandDerivationsInExpression("Apartment.allinstances.Grownups->intersection(Apartment.allinstances.TheDogs.Owner)", null, false, null);And the result in exp1 and exp2 are:
exp1=Apartment.allinstances.Occupants.Pets->select(p|p.PetType.Breed = 'Dog')->select(x|x.Name = 'Benji')
exp2=Apartment.allinstances.Occupants->select(x|x.Age >= 18)->intersection(
                      Apartment.allinstances.Occupants.Pets->
                             select(p|p.PetType.Breed = 'Dog').Owner)

The MDriven Framework does the expansion for you so that you can keep and maintain as few and small definitions as possible.

This new functionality surfaces here:

  • In IOclService:
  • In IOclPsService:
  • In PSQuery and EcoQuery PS (same); automatically expands derivations PS fetch.

The SearchLogic that Wecpof uses; automatically expands derivations PS fetch.

This is the suggested solution to this discussion.