Home » Archived » EMF-IncQuery » Queries for derived features with constrains
Queries for derived features with constrains [message #1243192] |
Mon, 10 February 2014 16:51 |
Emre T 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 |
Zoltan Ujhelyi Messages: 392 Registered: July 2015 |
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 #1243211 is a reply to message #1243192] |
Mon, 10 February 2014 17:23 |
Abel Hegedus Messages: 197 Registered: September 2015 |
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
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 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 |
Emre T Messages: 119 Registered: April 2013 |
Senior Member |
|
|
Hello,
yes, indeed I meant the second question.
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.
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 #1250489 is a reply to message #1244361] |
Wed, 19 February 2014 09:44 |
Emre T 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
|
|
| |
Goto Forum:
Current Time: Wed Sep 25 19:02:13 GMT 2024
Powered by FUDForum. Page generated in 0.03769 seconds
|