Derivation is not available in the database

Derivation is a very good way to remove the need for repeating definitions.

Suppose you have this model:

image

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

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

image

3 different derivations on 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 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 be able to use the derived association by having it translated 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:

/// <summary>
/// If an ocl expression use derived members and if those derived members are in turn implmented with ocl this call can expand
/// the derivations and return an expanded expression that does not make use of derivations.
/// This is useful when wanting to re-use code from in memory ocl in PS-ocl that cannot resolve derivations.
/// </summary>
string ExpandDerivationsInExpression(string expression, IClassifier context, bool reRaise, 
IExternalVariableList variableList);

In IOclPsService:

/// <summary>
/// Same as Execute - but this allows for expansion of derived members - using ExpandDerivationsInExpression
/// </summary>
IObjectList ExpandDerivationsThenExecute(IElement root, IExternalVariableList variableList, 
string expression, int maxAnswers, int offset);

In PSQuery and EcoQuery PS (same); automatically expands derivations PS fetch.

SearchLogic that Wecpof uses;  automatically expands derivations PS fetch.

This is the suggested solution to this discussion

This entry was posted in CO-Unique, Declarative, OCL. Bookmark the permalink.

One Response to Derivation is not available in the database

  1. Peter Buchmann says:

    This is great. Really great!! Thank you.

Leave a Reply

Your email address will not be published. Required fields are marked *

*