Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF-IncQuery » Queries for derived features with constrains
Queries for derived features with constrains [message #1243192] Mon, 10 February 2014 16:51 Go to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello there,

my question regards the querying the derived features of EMF models, but not from its general aspect. I have read your tutorials (old and new ones) and I had read your papers regarding the topic awhile ago. But I couldn't found anything to assure that my conceptional thinking is OK.

As far as I understand, the queries for derived features are not defined in the actual EMF model projects, but in EMF-IncQuery projects as a little bit more complex, annotated query patterns, whit which I am familiar with. That way, the by-EMF-generated "getDerivedFeature"-methods won't have to be actually maintained manually, as a developer should do if the usage of derived features is needed. But I believe that the generated EMF-getters for derived features are still called by the EMF-IncQuery engine in the back-end, right?

The reason why I am asking this, is that I have for every derived feature in my model (conceptually, almost every reference is derived) various OCL constraints, which should be used to validate the instances of my model and they are validated when the corresponding getters of derived features are called. Or simply by right-clicking on the model instance and choosing "Validate". (If derived feature getters are not refactored accordingly after the model code generation, than the validation fails eventually; and I hope that EMF-IncQuery can be very helpful in this manner.)

Long story short, can the OCL constraints on derived features still be exploited if EMF-IncQuery is used to -quasi- implement the getters of derived features? If so, is there anything that has to be taken care of additionally?

Thanks a lot!

Emre
Re: Queries for derived features with constrains [message #1243197 is a reply to message #1243192] Mon, 10 February 2014 16:59 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 222
Registered: July 2009
Senior Member
Hi,

you are right, the EMF-IncQuery runtime calls the derived features referenced in queries. About them the only thing the framework expects is that the referenced features should be "well-behaving": they are deterministic, and provide notifications in case of model changes.

Sadly, as far as I know derived features created by OCL does not provide notifications, making it possible that EMF-IncQuery indexes become invalid.

If you are only interested in queries about a single snapshot, and are willing to manually help the engine to reindex its stuff, you could look at the new run-once query engine (see https://wiki.eclipse.org/EMFIncQuery/UserDocumentation/API/RunOnce), where you could theoretically work with deterministic, but non well-behaving derived features.

I hope this helps for your problem.

Cheers,
Zoltán
Re: Queries for derived features with constrains [message #1243203 is a reply to message #1243197] Mon, 10 February 2014 17:08 Go to previous messageGo to next message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 222
Registered: July 2009
Senior Member
Hi,

sorry, I have probably misunderstood your question, as it was pointed out to me offline. (Thanks to Gábor Bergmann Smile ). I try to address these issues as well.

EMF-IncQuery includes a derived feature generator, that updates the generated EMF code (more specifically, updates the getter), so it will work as expected when using it from any EMF-based tool (including OCL-based validation). In other words, EMF-IncQuery does implement the derived features.

Cheers,
Zoltán
Re: Queries for derived features with constrains [message #1243211 is a reply to message #1243192] Mon, 10 February 2014 17:23 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 105
Registered: July 2009
Senior Member
Hi Emre,

your setup sound quite interesting, I hope you can get it to work!
By the way, have you tried our Validation Framework (https://wiki.eclipse.org/EMFIncQuery/UserDocumentation/Validation) to get incremental evaluation instead of on-demand?

Also, I think Zoltán answered the question "how can I query my model that implements derived features using OCL?", while I understand your question as "how can I make sure the constraints are validated when the getter is called even when the feature is implented as a query?". I will answer the second question, and please correct us, if you meant a third question Smile

First, the query-based derived feature does indeed generate into the getter method (at this point, we plan to move to setting delegates). These getters are called by EMF-IncQuery during initialization, but if you need to put in additional code (to invoke the OCL constraint validation), you can do that. However, in this case, I would suggest the following:
1. Define the pattern and add @QueryBasedFeature annotation
2. After that, the EMF-IncQuery code generator will create the enhanced getter code.
3. Copy the well-behaving feature extensions from the plugin.xml in your query project.
4. Remove the @QueryBasedFeature annotation
5. Add back the well-behaving feature extensions.
6. Extend your getters to call the OCL constraint validation.

Otherwise, the EMF-IncQuery builder may overwrite your modified getter.
Anyway, as long as the code that is generated in the getter is in there, the query-based features will work.

I hope this adds some information and not only confusion Smile We are happy to answer any follow-up questions.
Re: Queries for derived features with constrains [message #1244139 is a reply to message #1243211] Wed, 12 February 2014 00:12 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello,

yes, indeed I meant the second question. Smile

Another option I could choose is to implement the notifiers for my derived references directly in the generated model code which should also call the OCL validations, but since I am also going to need queries for my work and I am familiar with IncQuery, I have found it as the better solution to use EMF-IncQuery for my approach. Only thing I wasn't sure of, whether the queries interact only from the outside with the model instances or also generating the needed getters for the derived references.

So I will try to implement my approach using your tool, and I am hoping that I could get it running accordingly. Also hope that I won't be having a lot of questions, so that you won't get any headaches. Smile

Best regards,
Emre

Edit: I have read your answers again and have noticed, that I still have to implement the notifiers for the derived references myself. Or am I misinterpreting this? my first thought was that these would also be generated by the EMF-IncQuery.

[Updated on: Wed, 12 February 2014 00:27]

Report message to a moderator

Re: Queries for derived features with constrains [message #1244158 is a reply to message #1244139] Wed, 12 February 2014 00:54 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello again,

I guess, I see now, that so the derived features could be accessed by the pattern definitions properly in the first place and that their getters could be re-implemented by the EMF-IncQuery, we should first register the derived features into the WellBehavingDerivedFeatureRegistry. I believe the older approach for this is to use the Derived Feature Handler, which seems to be gone now.

So the basic steps which should be followed are as follows:

1. Register the derived references into the WellBehavingDerivedFeatureRegistry class using register-methods in a seperate project where we also use the getMatcher() etc.
2. Define the patterns for derived references in a IncQuery-Project, which is in the same workspace as the model with derived features to query
3. The notifiers and getters for the derived features will be generated by the EMF-IncQuery
4. Let the query run in a runtime instance of Eclipse to validate the OCL constraints of the derived features eventually

Hope, I am getting it right.

Best regards,
Emre

Re: Queries for derived features with constrains [message #1244361 is a reply to message #1244158] Wed, 12 February 2014 08:06 Go to previous messageGo to next message
Gabor Bergmann is currently offline Gabor BergmannFriend
Messages: 21
Registered: July 2009
Junior Member
Hi Emre,

If you specify your derived feature as an Query-Based Feature (QBF) using EMF-IncQuery (see steps 2-3 above), then step 1 happens automatically - QBF will be recognized as well-behaving.

Manual registration in WellBehavingDerivedFeatureRegistry is probably only needed if you run a stand-alone program (without Eclipse runtime), where the generated extensions to the well-behaving extension point can not automatically take effect.

"I have read your answers again and have noticed, that I still have to implement the notifiers for the derived references myself." - no, these are generated alongside the getter in case of QBF.

HTH,
Gábor
Re: Queries for derived features with constrains [message #1250489 is a reply to message #1244361] Wed, 19 February 2014 09:44 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello again,

so far I have managed to build the queries for derived features. The interestin part was, that I didn't have to extend the derived features in plugin.xml of the IncQuery project myself, but they have been added automatically, when the patterns are annotated with @QueryBasedFeature. Thought first, that I had to do it also manually, but clearly it is not the case?

The notifiers as far as I can see have also been added to the model code of the elements with derived features:

Now there is a new method for e.g. basicGetDerivedFeature(), which has been generated by the EMF IncQuery runtime, and the one method generated by the EMF itself has been refactored to basicGetDerivedFeatureGen(). With it of course the UnsupportedOperationException is gone. This is a very nice relief, since I am now able to concentrate on the model itself and its constraints.

The only thing, I am still not sure about, is when the OCL constraints will be validated. I have registered the queries into the Query Explorer in an Eclipse runtime. Loaded the model to query and the model it is referencing on derived basis as a ResourceSet, filtered my queries with the selected model elements. And eventually let it run. But there is simply no sign of whether the validation succeeds. I can still choose the option "Validate" from the context menu on the model instance, but because of some other reasons, the validation doesn't go through, though I don't get the UnsupportedOperationException for the derieved features, which tells me that the notifiers generated by the EMF IncQuery are indeed working?

Would you have any recommendations regarding this matter?

Thanks again,
Emre
Re: Queries for derived features with constrains [message #1250498 is a reply to message #1250489] Wed, 19 February 2014 09:52 Go to previous message
Zoltan Ujhelyi is currently offline Zoltan UjhelyiFriend
Messages: 222
Registered: July 2009
Senior Member
Hi,

I am not sure when the OCL expressions are checked and/or how the results are displayed, mostly because of my very limited experience with OCL tooling. For testing purposes, I would write some constraint, that should report some trivial violation (even if does not have any meaning), and then try to execute the validation, and look for signs (e.g. problems view) whether the expression is checked.

If this does not work, I would recommend to ask this question from the more qualified members of the OCL forum (http://www.eclipse.org/forums/index.php/f/26/).

Cheers,
Zoltán
Previous Topic:Not representable well-behaving feature
Next Topic:Unique names of derived features?
Goto Forum:
  


Current Time: Sat Dec 20 15:58:06 GMT 2014

Powered by FUDForum. Page generated in 0.02165 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software