Home » Archived » EMF-IncQuery » Statements and Operations in Query Definitions
Statements and Operations in Query Definitions [message #1254923] |
Mon, 24 February 2014 00:12 |
Emre T Messages: 119 Registered: April 2013 |
Senior Member |
|
|
Hello there,
hope everythings going well.
I have two questions in my mind and think you could help me:
1. Are there any constructs similar to Java statements such as if-else or iterations, that can be used in query definitions?
2. I know, that the attributes or references of EMF model elements can be iterated/exploited, once these models are imported. But what about operations? I can't seem to find a way to use defined operations to use their results in queries.
If the questions are vague, I can definitely provide some exact examples.
Thanks a lot!
[Updated on: Mon, 24 February 2014 00:13] Report message to a moderator
|
|
|
Re: Statements and Operations in Query Definitions [message #1254957 is a reply to message #1254923] |
Mon, 24 February 2014 01:03 |
Abel Hegedus Messages: 197 Registered: September 2015 |
Senior Member |
|
|
Hi,
only short answers for me, and maybe others will offer more details:
1. You can define multiple bodies for a single pattern with the "or" construct (see point 3). Also, you can use recursive pattern calls (but be careful, see our FAQ). However, in most iterative cases, what you really need is transitive closure.
2. Think of operations as derived features which are never-ever well-behaving, therefore you cannot index their value and cannot perform incremental query evaluation. In this sense, operations are not part of the model structure, in most cases (as far as I can see), they are written for utility purposes similar to queries.
It is important to realize, that you don't have to do everything solely through patterns. In fact, you shouldn't. We strived to design the programming API of EMF-IncQuery in a way to make it easy to integrate it into any application code and focus its functionality to the real essentials, "providing incremental evaluation of model queries". For use cases like "if-else" and "iterations", the API is perfectly suitable by providing methods like hasMatch() and forEachMatch().
Cheers.
|
|
|
Re: Statements and Operations in Query Definitions [message #1255187 is a reply to message #1254923] |
Mon, 24 February 2014 07:05 |
Istvan Rath Messages: 59 Registered: July 2009 |
Member |
|
|
Hi,
while I generally agree with Ábel's remarks, for the sake of completeness here are two additional notes:
Quote:1. Are there any constructs similar to Java statements such as if-else or iterations, that can be used in query definitions?
Yes, you can use XBase inside the check expressions, as long as you write pure Xbase (side effect free and only depending on model elements referred to in the pattern body).
For an example, see http://incquery.net/incquery/new/examples/school#Step_4_-_check_conditions
Quote:2. I know, that the attributes or references of EMF model elements can be iterated/exploited, once these models are imported. But what about operations? I can't seem to find a way to use defined operations to use their results in queries.
You can include calls to these operations inside check expressions, as long as they are pure in the sense above.
Note that the EIQ editor has rather limited way of detecting that you are not writing pure Xbase, this feature is under development at the moment. So for the moment, you have to make sure by checking for pureness yourself - if the code is not pure, the pattern matching can give you incorrect result updates as the model is changing.
HTH
Istvan
|
|
| |
Re: Statements and Operations in Query Definitions [message #1269825 is a reply to message #1269302] |
Wed, 12 March 2014 08:24 |
Istvan Rath Messages: 59 Registered: July 2009 |
Member |
|
|
Quote:Only simple EDataTypes are allowed in check() and eval() expressions.
And I need to be able to evaluate conditions on more complex types, which I import from other models.
Any custom EDataType should work. The only rule is that all variables that are referred to inside a check/eval expression need to be "scalar", i.e. cannot correspont to EObjects. (And, obviously, all such variables need to appear inside the pattern body too.)
Quote:Another thing is that I am having problems when I try to use these so called non-pure method calls, with the following error:
There is a potentially problematic java call in the check()/eval()
expression. Custom java calls without @Pure annotations considered
unsafe in IncQuery. The possible erroneous call is the following:
[org.emftext.language.java.annotations.AnnotationAttributeSetting.getAttribute].
Even the toString() method seems to be non-pure in that matter.
There is a potentially problematic java call in the check()/eval()
expression. Custom java calls without @Pure annotations considered
unsafe in IncQuery. The possible erroneous
call is the following: [java.lang.Object.toString].
I was hoping to get the String-values of various attributes or references. It seems that there is no workaround for this.
These messages are not errors, just warnings. (At least they should be. If not, drop us a bugzilla.)
Which means, you *can* use them, as long as you are sure that they are indeed pure. The warning message just notifies you that IncQuery did not see a @Pure Java annotation on the function, so there is a chance things might go wrong here.
Pure means that the return value is deterministically calculated using the input values, and only the input values. Additionally, evaluating pure functions cannot have side effects, i.e. their evaluation must be idempotent. If you are sure your external code satisfies this, you can ignore the warning message. If you wrote the code yourself, you should add the @Pure annotation and then the warning will go away.
|
|
| | | |
Goto Forum:
Current Time: Thu Sep 26 00:23:22 GMT 2024
Powered by FUDForum. Page generated in 0.04962 seconds
|