Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community Forums[Acceleo 3] Calling MTL queries from java code
https://www.eclipse.org/forums/index.php/mv/msg/175371/558740/#msg_558740
Is there some kind of helper similar to Xtend's XtendFacade which would
allow executing MTL queries defined in a MTL template file from Java
code ? Both standalone and under Eclipse.
-----
The planned API only allows for clients to call Acceleo Templates, not
Queries; though I believe you should be able to mimic it in order to
call queries as well. Take a look at AcceleoService#doGenerate to see
how it's done ... don't hesitate to raise enhancement requests on the
bugzilla is the API isn't opened enough for you to call queries instead
of Templates :) .
-----
Laurent Goubet
Obeo
Cedric Vidal wrote:
> Hi Guys,
>
> Is there some kind of helper similar to Xtend's XtendFacade which would
> allow executing MTL queries defined in a MTL template file from Java
> code ? Both standalone and under Eclipse.
>
> Kind regards,
>
> C]]>Laurent Goubet2010-09-14T14:25:38-00:00Re: [Acceleo 3] Calling MTL queries from java code
https://www.eclipse.org/forums/index.php/mv/msg/175371/559058/#msg_559058
Thanx for your quick answer :)
I've had a look at AcceleoService and thanx to your explanation, I've
managed to execute a MTL query programmatically. Actually, it was pretty
easy as the syntax of MTL queries is actually directly parsed into OCL
Expressions and directly accessible in the MTL Ecore Metamodel.
So all I had to do was to mimic the doEvaluate method of AcceleoEngine
and transform the Query's OCL expression into an OCL Query and evaluate it.
But I had to fork AcceleoService and AcceleoEngine. The original code is
pretty dependent on the fact that files are being generated which is not
relevant when executing queries (and AcceleoService is a final class ;) ).
What's more, I have an issue with the cleaning up after execution. I
stopped there as I didn't have the time to investigate that problem.
Regarding the API, it would indead be great if Acceleo 3 supported that
use case. According to me, it's very important to be able to leverage
the set of MTL queries you've written into Java code. It allows creating
libraries of queries that you can reuse both in MTL templates and Java code.
Regarding how the API could look like, I guess the following additional
methods in AcceleoService could do the job (mine look alike):
public Object doQuery(Module module, String queryName, EObject model,
Monitor monitor);
public Object doQuery(Query query, EObject model, Monitor monitor);
Thanks for the follow-up, could you raise an enhancement request on the
bugzilla with the code you wrote (as a patch or directly in the
comments) regarding these "doQuery" methods? That'll allow me to know
exactly the needed use case and quickly get the grasp of what changes
are needed :).
Laurent Goubet
Obeo
C]]>Laurent Goubet2010-09-15T13:17:08-00:00Re: [Acceleo 3] Calling MTL queries from java code
https://www.eclipse.org/forums/index.php/mv/msg/175371/559078/#msg_559078
by friday. I'll keep you posted.