Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF-IncQuery » Statements and Operations in Query Definitions
Statements and Operations in Query Definitions [message #1254923] Mon, 24 February 2014 00:12 Go to next message
Emre T is currently offline Emre TFriend
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 Go to previous messageGo to next message
Abel Hegedus is currently offline Abel HegedusFriend
Messages: 120
Registered: July 2009
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 Go to previous messageGo to next message
Istvan Rath is currently offline Istvan RathFriend
Messages: 58
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 #1269302 is a reply to message #1255187] Tue, 11 March 2014 17:19 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Thanks for the replies. But I thing the Xbase won't be sufficient in my case, since it is only allowed to use simple EDataTypes, as the following error says:

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.

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.

Any further ideas will be appreciated. Thanks!
Re: Statements and Operations in Query Definitions [message #1269825 is a reply to message #1269302] Wed, 12 March 2014 08:24 Go to previous messageGo to next message
Istvan Rath is currently offline Istvan RathFriend
Messages: 58
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.
Re: Statements and Operations in Query Definitions [message #1270190 is a reply to message #1269825] Wed, 12 March 2014 16:36 Go to previous messageGo to next message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hello again.

I see now what these warnings mean and how I can workaround them. Though I am not referencing my own code, there is no way to add @Pure annotations. I guess I am just have to trust them.

For the first error about the EDataType, I don't get it quite what you mean by correspond to EObject. Does it mean, any datatype which is a EObject can't be used there? Because I am trying to work with model elements in check expressions e.g. to get their attribute values etc. By the way, these are variables that appear in the pattern bodies without a problem.

But I am thinking again, that the Xbase expressions in checks() etc. are not really going to meet my needs after all. (But I really hope not) And this might be a pitfall for my work to create getters/notifiers for derived references via EMF-IncQuery.

Now I am getting the following error:

The method instanceOF(Object) is undefined or The method toString() is undefined

When I, again, try to use various model elements in check expressions with the above methods.

Thanks for the further help!



Re: Statements and Operations in Query Definitions [message #1270192 is a reply to message #1270190] Wed, 12 March 2014 16:42 Go to previous messageGo to next message
Istvan Rath is currently offline Istvan RathFriend
Messages: 58
Registered: July 2009
Member
Quote:
For the first error about the EDataType, I don't get it quite what you mean by correspond to EObject. Does it mean, any datatype which is a EObject can't be used there? Because I am trying to work with model elements in check expressions e.g. to get their attribute values etc. By the way, these are variables that appear in the pattern bodies without a problem.

But I am thinking again, that the Xbase expressions in checks() etc. are not really going to meet my needs after all. (But I really hope not) And this might be a pitfall for my work to create getters/notifiers for derived references via EMF-IncQuery.

Now I am getting the following error:

The method instanceOF(Object) is undefined or The method toString() is undefined

When I, again, try to use various model elements in check expressions with the above methods.


Please provide a concrete code example, so that I can help you further.
Re: Statements and Operations in Query Definitions [message #1271165 is a reply to message #1270192] Fri, 14 March 2014 12:08 Go to previous message
Emre T is currently offline Emre TFriend
Messages: 119
Registered: April 2013
Senior Member
Hi Istvan,

I will try to provide a sample code for the issue, but it might take a while, since my priority has changed to another issue. But thanks anyway!

Best regards,
Emre
Previous Topic:Accessing the values of attributes/references in pattern bodies
Next Topic:A pattern definition regarding Inheritance
Goto Forum:
  


Current Time: Mon Jul 06 01:14:24 GMT 2015

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

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