Home » Modeling » EMF » EMF Query2 questions
EMF Query2 questions [message #672549] |
Sat, 21 May 2011 17:34 |
No real name Messages: 11 Registered: May 2011 |
Junior Member |
|
|
Hello,
i hope you can help me, i have some questions about emf query2, sadly i don't found directly information about it, first the "none-code" questions:
- So far i have seen somewhere, EMF-Query2 will released with the next eclipse relase, is that correct?
- Will Query2 replace Query1, or coexist?
Code-Questions:
At time i am working on a 'project' limted in time, and the question is should i use query1 or query2. At time query1 seem easier to me, for a person who is new in working with EMF, with SELECT(), FROM() and so on. Sadly i don't get query2 to run at time, perhaps you could help me out here. I read some post here about query2 and take a look in "org.eclipse.emf.query2.lilbrarytest", it seem really difficult to me. I thoguht it would be more like: create a index and pass simple the URI's which i want to query and simple make my query statements and execute them with the index. Well, i hope you could help me out, now the code:
public class EMFQuery2 {
private static Index index = null;
public static void main(String[] args) {
index = IndexFactory.getInstance();
index.executeUpdateCommand(new UpdateCommandAdapter() {
@Override
public void execute(final IndexUpdater updater) {
ResourceIndexer indexer = new ResourceIndexer();
indexer.resourceChanged(updater, EcorePackage.eINSTANCE.eResource());
indexer.resourceChanged(updater, WebpagePackage.eINSTANCE.eResource());
ResourceSet rs = new ResourceSetImpl();
loadResources(rs);
EList<Resource> list = rs.getResources();
indexer.resourceChanged(updater, list.toArray(new Resource[list.size()]));
for(Resource r: list) {
r.unload();
}
}
});
// LibraryTransformation.java
if (!Platform.isRunning()) {
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri("..");
}
Injector injector = new QueryStandaloneSetup().createInjectorAndDoEMFRegistration();
XtextResourceSet set = injector.getInstance(XtextResourceSet.class);
set.addLoadOption(XtextResource.OPTION_RESOLVE_ALL, Boolean.TRUE);
URI resourceURI = URI.createURI("platform:/plugin/de.vogella.emf.webpage.usingmodel/selects.query");
URI normalizedURI = set.getURIConverter().normalize(resourceURI);
LazyLinkingResource xtextResource = (LazyLinkingResource)set.getResource(normalizedURI, true);
Model model = (Model) xtextResource.getContents().get(0);
EList<NamedQuery> queryList = model.getNamedQueries();
for (NamedQuery query: queryList) {
ResourceSet rs = new ResourceSetImpl();
Query select = QueryTransformer.transform(query.getQuery());
System.out.println("Queryname: "+ query.getName());
System.out.println("select.toString: "+ select.toString().trim());
QueryProcessor queryProcessor = QueryProcessorFactory.getDefault().createQueryProcessor(index);
// ResultSet result = queryProcessor.execute("from ...", getQueryContext(rs));
ResultSet result = queryProcessor. execute(select, getQueryContext(rs));
System.out.println("size: "+ result.getSize() +"\n\n");
System.out.println(result);
}
}
private static QueryContext getQueryContext(final ResourceSet rs) {
return new QueryContext() {
public URI[] getResourceScope() {
final List<URI> result = new ArrayList<URI>();
index.executeQueryCommand(new QueryCommand() {
public void execute(QueryExecutor queryExecutor) {
ResourceQuery<ResourceDescriptor> resourceQuery = IndexQueryFactory.createResourceQuery();
for (ResourceDescriptor desc : queryExecutor.execute(resourceQuery)) {
result.add(desc.getURI());
}
}
});
return result.toArray(new URI[0]);
}
public ResourceSet getResourceSet() {
return rs;
}
};
}
public static void loadResources(ResourceSet rs) {
// @see load()
WebpagePackage wp = WebpagePackageImpl.init();
EPackage.Registry reg = rs.getPackageRegistry();
reg.put(wp.getNsURI(), wp);
URI loadURI = URI.createFileURI("save.xml");
Resource resource = rs.getResource(loadURI, true);
try {
resource.load(null);
} catch (IOException e) {
System.out.println("EMFQuery2.loadResourcesl()");
e.printStackTrace();
}
}
}
And i don't understand the meaning of index.executeUpdateCommand() [and index.executeQueryCommand()], same for the getQueryContext() method i copied. Did i miss some basics here?
By executing the code i get following Exception:
Exception in thread "main" com.google.inject.internal.ComputationException: com.google.inject.internal.ComputationException: java.lang.NoClassDefFoundError: org/eclipse/xtext/util/TextLocation
But i can't find in which plugin it is located, i have try every *.xtext.* plugin.
Thanks for any help,
littleRathi
|
|
| |
Re: EMF Query2 questions [message #673964 is a reply to message #673591] |
Wed, 25 May 2011 10:25 |
No real name Messages: 11 Registered: May 2011 |
Junior Member |
|
|
Hi Saurav,
no problem, i appreciate that you answer me. The answer to the code question are little bit difficult to me:
d) Is the code so far "correct", i was very unsure about executeUpdateCommand() especially that
i want to use querys with selects, it seem that executeUpdateCommand() should be wrong.
a) do you mean with query command the Index.executeQueryCommand in the method getQueryContext()? With "Though we are not using in anywhere." do you mean that it exist this "feature" but at time not used?
b) It think you mean index.executeUpdateCommand(), your explanation sounds that it is not really neccessary in my code? At time ich use index.resourceChanged(), i am not sure about for what this is necessary. the rest seem clear to me, i load the sources, i want to query and give it to the indexer, then i unload the resource. Is this so far right? Then it would be the way how i can tell the indexer which source it should index and i want to query.
c) Ok, that is a clear statement to me, i need that method. Wow, i read your answer yesterday, but i think i start to understand but now what you mean. In dex index.executeUpdateQuery() at first in my code, i index all resouces i need, and with the getQueryContext() i select which of the resources should be used for the query, (example: i load Resource A, B, C, but i want in the next query only Query resource B, then i can select it with the getQueryContext()?
e)
The installation of Query2 had complications, i think i write it too, perhaps the error lies here:
- First i have do update SWTBot, to 2.0.4.*
- Then i have to deinstall the existing XText plugin, that was confusing, but then it was possible to install Query2?
now the following plugins are installed:
- EMF Model Query SDK 1.4.0.* (could it make problem when it is installed too?)
- EMF Query2 Core Feature 1.0.0.*
- EMF Query2 String Syntax Feature 1.0.0.*
- Query2 Tests 1.0.0.*
- Xpand SDK 1.1.0.*
- include xpand and xtend plugins
f) last question: How stable is the API, do you thing?
So far thanks for help.
Greeting,
littleRathi
[Updated on: Mon, 30 May 2011 12:35] Report message to a moderator
|
|
| |
Re: EMF Query2 questions [message #674259 is a reply to message #674070] |
Thu, 26 May 2011 10:34 |
No real name Messages: 11 Registered: May 2011 |
Junior Member |
|
|
Hi Saurav,
again thx for answering, bu i still have the problem with the exception ^^:
Exception in thread "main" com.google.inject.internal.ComputationException: com.google.inject.internal.ComputationException:
java.lang.NoClassDefFoundError: org/eclipse/xtext/util/TextLocation
I found out by run -> Eclipse Application, that some plugins missing some bundles:
- de.itemis.xtext.antlr
- Missing Constraint: Require-Bundle: org.antlr.generator; bundle-version="3.2.0"
- org.eclipse.xtend.profler
- Missing Constraint: Require-Bundle: orgl.eclipse.emf.mwe.utils; bundle-version="[1.1.0.v*,2.0.0)
- org.eclipse.xtend.typesystem.emf
- Missing Constraint: Require-Bundle: orgl.eclipse.emf.mwe.utils; bundle-version="[1.1.0.v*,2.0.0)
- org.eclipse.xtend.typesystem.xsd
- Missing Constraint: Require-Bundle: orgl.eclipse.emf.mwe.utils; bundle-version="[1.1.0.v*,2.0.0)
- org.eclipse.xtend.util.stdlib
- Missing Constraint: Require-Bundle: orgl.eclipse.emf.mwe.utils; bundle-version="[1.1.0.v*,2.0.0)
Is this problem related to the exception? I only found to old version in my update sites. I think that i need a addition plugin, but not sure
which.
Greeting,
littleRathi
[Updated on: Mon, 30 May 2011 12:35] Report message to a moderator
|
|
| |
Re: EMF Query2 questions [message #674419 is a reply to message #674374] |
Thu, 26 May 2011 20:56 |
No real name Messages: 11 Registered: May 2011 |
Junior Member |
|
|
Hi Saurav,
I thought that, so i try to install Xtext, again but sadly i get a confusing error, well it confuse me, perhaps it's more clear to you:
When i try to install:
Xtext SDK in Version 2.0.0.v201105240502 with Id org.eclipse.xtext.sdk.feature.group
i get following error:
Cannot complete the install because of a conflicting dependency.
Software being installed: Xtext SDK 2.0.0.v201105240502 (org.eclipse.xtext.sdk.feature.group 2.0.0.v201105240502)
Software currently installed: Query2 Tests 1.0.0.201104260527 (org.eclipse.emf.query2.test.feature.feature.group 1.0.0.201104260527)
Only one of the following can be installed at once:
Xtext 1.0.2.v201102150722 (org.eclipse.xtext 1.0.2.v201102150722)
Xtext 1.0.1.v201008251220 (org.eclipse.xtext 1.0.1.v201008251220)
Xtext 2.0.0.v201105240502 (org.eclipse.xtext 2.0.0.v201105240502)
Xtext 2.0.0.v201105170444 (org.eclipse.xtext 2.0.0.v201105170444)
Xtext 1.0.0.v201006170321 (org.eclipse.xtext 1.0.0.v201006170321)
Cannot satisfy dependency:
From: org.eclipse.emf.query2.syntax.test 1.0.0.201104260527
To: bundle org.eclipse.xtext [1.0.0,2.0.0)
Cannot satisfy dependency:
From: Query2 Tests 1.0.0.201104260527 (org.eclipse.emf.query2.test.feature.feature.group 1.0.0.201104260527)
To: org.eclipse.emf.query2.syntax.test [1.0.0.201104260527]
Cannot satisfy dependency:
From: Xtext Runtime 2.0.0.v201105240502 (org.eclipse.xtext.runtime.feature.group 2.0.0.v201105240502)
To: org.eclipse.xtext [2.0.0.v201105240502]
Cannot satisfy dependency:
From: Xtext SDK 2.0.0.v201105240502 (org.eclipse.xtext.sdk.feature.group 2.0.0.v201105240502)
To: org.eclipse.xtext.runtime.feature.group [2.0.0.v201105240502]
I couldn't find any installation of Xtext in eclipse, i don't know where eclipse find the other Version: 1.0.2, 1.0.1, 1.0.0 and 2.0.0.v201105170444.
Greetings,
littleRathi
|
|
| |
Re: EMF Query2 questions [message #674608 is a reply to message #674530] |
Fri, 27 May 2011 14:42 |
No real name Messages: 11 Registered: May 2011 |
Junior Member |
|
|
Hi Saurav,
for testing i have downloaded Xtext 1.0.2 Distribution (Helios). In the first try i used the existing workspace and it doesn't work first, there was a problem with xtext and i installed a new Xtext 2.0, but there was still Problems. Then i try with something in this eclipse and with me preinstalled eclipse. Then i want to write you the problem (suddenly it was the same problem in both eclipse versions! So i "installed" the Xtext 1.0.2 eclipse again, to explain what i have done, but this time, i create a new workspace and only import the two neccessary plugins and then it works with a change by the createURI, i have to delete 'plugin' and use 'resource'. I am so happy. But i have to find out to bring it generally to work in the other eclipse, because the software i work on is only a part and the software exist as eclipse plugins.
a) So here a questions: could it be, that other plug-ins in the workspace can cause trouble? What i don't write here until now is that the editor for .query files doesn't work, only in the last eclipse where everything from EMF Query 2 works is running now. Here the exception, perhaps you know what the problem is. I will setup my working system again because it must work with the workspace that include the other plugins, when i find something i post it here.
0 [main] INFO lipse.emf.mwe.utils.StandaloneSetup - Registering platform uri 'F:\workspaces\mt\workspace3.6'
1735 [main] ERROR clipse.xtext.service.CompoundModule - Type org.eclipse.xtext.parser.antlr.IAntlrParser not present
java.lang.TypeNotPresentException: Type org.eclipse.xtext.parser.antlr.IAntlrParser not present
at sun.reflect.generics.factory.CoreReflectionFactory.makeNamedType(Unknown Source)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Unknown Source)
at sun.reflect.generics.tree.ClassTypeSignature.accept(Unknown Source)
at sun.reflect.generics.reflectiveObjects.WildcardTypeImpl.getUpperBounds(Unknown Source)
at org.eclipse.xtext.service.MethodBasedModule.getFirstTypeParameter(MethodBasedModule.java:106)
at org.eclipse.xtext.service.MethodBasedModule.getKeyType(MethodBasedModule.java:97)
at org.eclipse.xtext.service.MethodBasedModule.configure(MethodBasedModule.java:47)
at org.eclipse.xtext.service.CompoundModule.configure(CompoundModule.java:34)
at org.eclipse.xtext.service.AbstractGenericModule.configure(AbstractGenericModule.java:32)
at org.eclipse.xtext.service.DefaultRuntimeModule.configure(DefaultRuntimeModule.java:74)
at org.eclipse.emf.query2.syntax.AbstractQueryRuntimeModule.configure(AbstractQueryRuntimeModule.java:25)
at com.google.inject.spi.Elements$RecordingBinder.install(Elements.java:223)
at com.google.inject.spi.Elements.getElements(Elements.java:101)
at com.google.inject.InjectorShell$Builder.build(InjectorShell.java:135)
at com.google.inject.InjectorBuilder.build(InjectorBuilder.java:102)
at com.google.inject.Guice.createInjector(Guice.java:92)
at com.google.inject.Guice.createInjector(Guice.java:69)
at com.google.inject.Guice.createInjector(Guice.java:59)
at org.eclipse.emf.query2.syntax.QueryStandaloneSetupGenerated.createInjector(QueryStandaloneSetupGenerated.java:34)
at org.eclipse.emf.query2.syntax.QueryStandaloneSetupGenerated.createInjectorAndDoEMFRegistration(QueryStandaloneSetupGenerated.java:28)
at de.vogella.emf.webpage.usingmodel.EMFQuery2.query(EMFQuery2.java:90)
at de.vogella.emf.webpage.usingmodel.EMFQuery2.main(EMFQuery2.java:59)
Caused by: java.lang.ClassNotFoundException: org.eclipse.xtext.parser.antlr.IAntlrParser
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
... 22 more
b) After the right editor can view now the .query files, but it say me that it have two erros, that it couldn't resolve reference to EClass 'Webpage' and to EStructuralFeature 'rating' but there are both existing in the model. The imports are as following:
import "http ://eclipse.org/modeling/emf/query/1.0.0"
import "http ://webpage/1.0"
So far, thank you for your help .
Greetings,
littleRathi
[ edit1:]
So i try it with the other eclipse version, i updated all plugins, then install EMF Query 2. After that i installed from a itemis update site Xtext Antlr 1.0.1, nearly the same version like in Xtext eclipse. Sadly still same error, perhaps i should deinstall EMF Query 2 and reinstall, could it be a problem, that Antlr was installed after Query 2? So i finish for today ^^.
[ /edit1:]
[Updated on: Fri, 27 May 2011 21:14] Report message to a moderator
|
|
| |
Re: EMF Query2 questions [message #675058 is a reply to message #675043] |
Mon, 30 May 2011 08:18 |
No real name Messages: 11 Registered: May 2011 |
Junior Member |
|
|
Hi saurav,
to get it clear i have at time 2 installations:
a) one how you explain with the Xtext eclipse, in which EMF Query 2 works fine
b) normal eclipse installation i work with, in which EMF Query 2 doesn't work
Until now.
in a) it seem that it updated Xtext to version 2.* (i can't remember that i do it) and it doesn't work anymore. But i try to uninstall in b) the Xtext 2.* version and install the old Xtext 1.* and it works. That was the problem!
Everything works now fine, thanks you for help. That should be firstly.
Greetings
littleRathi
[Updated on: Mon, 30 May 2011 08:20] Report message to a moderator
|
|
| | |
Re: EMF Query2 questions [message #675736 is a reply to message #675673] |
Wed, 01 June 2011 11:05 |
saurav sarkar Messages: 428 Registered: July 2009 |
Senior Member |
|
|
Hi littleRathi,
Suggest you to open a new forum thread.
As this thread is getting lengthier.
Answers to your questions are as follows
(a) ResourceQuery,EObjectQuery and EReferenceQuery are Index queries.They are independent of Query2.
I dont think you need those queries to execute.But if you want you can use it.
These queries are used by Query2 internally.Check IndexQueryService class.
(c) If you want just the URIs you can get it without loading it.Then once you get the URIs you can further load it.
Otherwise query for attributes then Query2 internally loads the resource and shows you the required information.
Let me know if you have any further questions.
Cheers,
Saurav
My Blog http://codifyit.blogspot.com/
Follow me: http://twitter.com/sauravs
|
|
|
Re: EMF Query2 questions [message #687074 is a reply to message #674419] |
Thu, 26 May 2011 21:26 |
Ed Willink Messages: 7679 Registered: July 2009 |
Senior Member |
|
|
Hi
Cannot satisfy dependency:
From: org.eclipse.emf.query2.syntax.test 1.0.0.201104260527
To: bundle org.eclipse.xtext [1.0.0,2.0.0)
means that the version of Query2 requires Xtext 1.0. Other software
requires Xtext 2.0.
Regards
ed Willink
On 26/05/2011 21:56, forums-noreply@eclipse.org wrote:
> Hi Saurav,
>
> I thought that, so i try to install Xtext, again but sadly i get a
> confusing error, well it confuse me, perhaps it's more clear to you:
> When i try to install:
>
> Xtext SDK in Version 2.0.0.v201105240502 with Id
> org.eclipse.xtext.sdk.feature.group
>
> i get following error:
>
> Cannot complete the install because of a conflicting dependency.
> Software being installed: Xtext SDK 2.0.0.v201105240502
> (org.eclipse.xtext.sdk.feature.group 2.0.0.v201105240502)
> Software currently installed: Query2 Tests 1.0.0.201104260527
> (org.eclipse.emf.query2.test.feature.feature.group 1.0.0.201104260527)
> Only one of the following can be installed at once: Xtext
> 1.0.2.v201102150722 (org.eclipse.xtext 1.0.2.v201102150722)
> Xtext 1.0.1.v201008251220 (org.eclipse.xtext 1.0.1.v201008251220)
> Xtext 2.0.0.v201105240502 (org.eclipse.xtext 2.0.0.v201105240502)
> Xtext 2.0.0.v201105170444 (org.eclipse.xtext 2.0.0.v201105170444)
> Xtext 1.0.0.v201006170321 (org.eclipse.xtext 1.0.0.v201006170321)
> Cannot satisfy dependency:
> From: org.eclipse.emf.query2.syntax.test 1.0.0.201104260527
> To: bundle org.eclipse.xtext [1.0.0,2.0.0)
> Cannot satisfy dependency:
> From: Query2 Tests 1.0.0.201104260527
> (org.eclipse.emf.query2.test.feature.feature.group 1.0.0.201104260527)
> To: org.eclipse.emf.query2.syntax.test [1.0.0.201104260527]
> Cannot satisfy dependency:
> From: Xtext Runtime 2.0.0.v201105240502
> (org.eclipse.xtext.runtime.feature.group 2.0.0.v201105240502)
> To: org.eclipse.xtext [2.0.0.v201105240502]
> Cannot satisfy dependency:
> From: Xtext SDK 2.0.0.v201105240502
> (org.eclipse.xtext.sdk.feature.group 2.0.0.v201105240502)
> To: org.eclipse.xtext.runtime.feature.group [2.0.0.v201105240502]
>
>
> I couldn't find any installation of Xtext in eclipse, i don't know
> where eclipse find the other Version: 1.0.2, 1.0.1, 1.0.0 and
> 2.0.0.v201105170444.
>
> Greetings,
> littleRathi
|
|
|
Re: EMF Query2 questions [message #687284 is a reply to message #674419] |
Thu, 26 May 2011 21:26 |
Ed Willink Messages: 7679 Registered: July 2009 |
Senior Member |
|
|
Hi
Cannot satisfy dependency:
From: org.eclipse.emf.query2.syntax.test 1.0.0.201104260527
To: bundle org.eclipse.xtext [1.0.0,2.0.0)
means that the version of Query2 requires Xtext 1.0. Other software
requires Xtext 2.0.
Regards
ed Willink
On 26/05/2011 21:56, forums-noreply@eclipse.org wrote:
> Hi Saurav,
>
> I thought that, so i try to install Xtext, again but sadly i get a
> confusing error, well it confuse me, perhaps it's more clear to you:
> When i try to install:
>
> Xtext SDK in Version 2.0.0.v201105240502 with Id
> org.eclipse.xtext.sdk.feature.group
>
> i get following error:
>
> Cannot complete the install because of a conflicting dependency.
> Software being installed: Xtext SDK 2.0.0.v201105240502
> (org.eclipse.xtext.sdk.feature.group 2.0.0.v201105240502)
> Software currently installed: Query2 Tests 1.0.0.201104260527
> (org.eclipse.emf.query2.test.feature.feature.group 1.0.0.201104260527)
> Only one of the following can be installed at once: Xtext
> 1.0.2.v201102150722 (org.eclipse.xtext 1.0.2.v201102150722)
> Xtext 1.0.1.v201008251220 (org.eclipse.xtext 1.0.1.v201008251220)
> Xtext 2.0.0.v201105240502 (org.eclipse.xtext 2.0.0.v201105240502)
> Xtext 2.0.0.v201105170444 (org.eclipse.xtext 2.0.0.v201105170444)
> Xtext 1.0.0.v201006170321 (org.eclipse.xtext 1.0.0.v201006170321)
> Cannot satisfy dependency:
> From: org.eclipse.emf.query2.syntax.test 1.0.0.201104260527
> To: bundle org.eclipse.xtext [1.0.0,2.0.0)
> Cannot satisfy dependency:
> From: Query2 Tests 1.0.0.201104260527
> (org.eclipse.emf.query2.test.feature.feature.group 1.0.0.201104260527)
> To: org.eclipse.emf.query2.syntax.test [1.0.0.201104260527]
> Cannot satisfy dependency:
> From: Xtext Runtime 2.0.0.v201105240502
> (org.eclipse.xtext.runtime.feature.group 2.0.0.v201105240502)
> To: org.eclipse.xtext [2.0.0.v201105240502]
> Cannot satisfy dependency:
> From: Xtext SDK 2.0.0.v201105240502
> (org.eclipse.xtext.sdk.feature.group 2.0.0.v201105240502)
> To: org.eclipse.xtext.runtime.feature.group [2.0.0.v201105240502]
>
>
> I couldn't find any installation of Xtext in eclipse, i don't know
> where eclipse find the other Version: 1.0.2, 1.0.1, 1.0.0 and
> 2.0.0.v201105170444.
>
> Greetings,
> littleRathi
|
|
|
Goto Forum:
Current Time: Sun Nov 10 18:16:51 GMT 2024
Powered by FUDForum. Page generated in 0.05134 seconds
|