Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF Query 2]Parameter in XText query
[EMF Query 2]Parameter in XText query [message #651824] Tue, 01 February 2011 17:46 Go to next message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 636
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Hi,

I would like to have a parameter in the query that I wrote using Xtext.

For instance in my .query file:
smyQueryName:
from XXX as xxx
	in resources{${myVariable}}
	select xxx


I would like to replace ${myVariable} by the URI of the resource

Regards,


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Re: [EMF Query 2]Parameter in XText query [message #651921 is a reply to message #651824] Wed, 02 February 2011 05:04 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
HI Aurelien,

Answers below

Aurelien Pupier wrote on Tue, 01 February 2011 12:46
Hi,

I would like to have a parameter in the query that I wrote using Xtext.

For instance in my .query file:
smyQueryName:
from XXX as xxx
	in resources{${myVariable}}
	select xxx


I would like to replace ${myVariable} by the URI of the resource

Regards,


You can pass parameter to the XText strings.
Please have a look at the org.eclipse.emf.query2.syntax.test.TestTransformation class where you can see a test method named testSelectPar2AsParameter whose query takes paramteres.

We have an API which actually transforms the XText AST to Query2 AST by accepting parameters.

/**
	 * For queries accepting arguments. Each ? in where clause of the query is
	 * replaced with object in Object[] replacableValues ? in query is replaced
	 * in order of element in Object[] replacableValues. User can pass values
	 * has following: transform(query, new Object[] { new Integer(200), new
	 * String(""), new Double(20.0), new Long(20000000000), new Boolean(true) }
	 * );
	 * 
	 * @param query
	 * @param replacableValues
	 * @return {@link Query}
	 */
	public static Query transform(MQLquery query, Object[] replacableValues)


cheers,
Saurav


[SOLVED]Re: [EMF Query 2]Parameter in XText query [message #652133 is a reply to message #651824] Wed, 02 February 2011 18:16 Go to previous message
Aurélien Pupier is currently offline Aurélien PupierFriend
Messages: 636
Registered: July 2009
Location: Grenoble, FRANCE
Senior Member

Nice,
I understand (even if I can't manage to test it for now)

For other: you need to use '?' in the query and use public static Query transform(MQLquery query, Object[] replacableValues)


Aurélien Pupier - Red Hat
Senior Software Engineer in Fuse Tooling team
Previous Topic:[CDO] NPEx when setLayoutConstraint on GMF editors
Next Topic:[EMF Query 2]Strange stacktrace at shutdown
Goto Forum:
  


Current Time: Mon Oct 14 18:48:39 GMT 2019

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

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

Back to the top