[EMF Query 2] Trouble with the import line in *.query file [message #718884] |
Thu, 25 August 2011 14:51 |
Fer Missing name Messages: 24 Registered: September 2009 |
Junior Member |
|
|
Hello all,
I am using Query2 to do queries on my model. I have development my own bundle using the ''org.eclipse.emf.query2.librarytest'' as example.
The librarytest works fine, but with my model I have the following trouble; in the *.query file I would like to replace the
import "http://eclipse.org/modeling/emf/query/1.0.0" line with the nsURI of my model, i.e. import "http://www.engineering.org/v10" But the nsURI is not recognized by the import dropdown. If I put the ecore
import "platform:/resource/engineering.query/model/engineering.ecore" works fine and all EClass of my model appears.
How I can use the nsURI instead of ecore in the import line?
Where the "http://eclipse.org/modeling/emf/query/1.0.0" nsURI is registered in the librarytest example?
Thanks in advance.
Best Regards,
Fernando
[Updated on: Thu, 25 August 2011 14:52] Report message to a moderator
|
|
|
|
|
|
Re: [EMF Query 2] Trouble with the import line in *.query file [message #777041 is a reply to message #718997] |
Mon, 09 January 2012 17:56 |
Fer Missing name Messages: 24 Registered: September 2009 |
Junior Member |
|
|
Dear Saurav,
I am running EMF Query2 with my model, but it is too slow (30 seconds per query with three Resources). My XMI files weight about 10MB. Am I indexing correctly? Please, see my code below:
public class QueryImpl implements QueryInterface{
private static final Index DEFAULT_INDEX = IndexFactory.getInstance();
private static Model model;
public QueryImpl() {
super();
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.createFileURI("C:/eclipse workspace/workspace_trunk/project.query.test/data/test.query");
URI normalized = set.getURIConverter().normalize(resourceURI);
LazyLinkingResource xtextResource = (LazyLinkingResource) set.getResource(normalized, true);
model = (Model) xtextResource.getContents().get(0);
}
@Override
public void dataExtraction(){
try {
final Resource rs1 = //get the resource from the XMI file
final Resource rs2 = //get the resource from the XMI file
final Resource rs3 = //get the resource from the XMI file
//Indexing
final Counter c = new Counter();
DEFAULT_INDEX.executeUpdateCommand(new UpdateCommandAdapter() {
@Override
public void execute(final IndexUpdater updater) {
final ResourceIndexer indexer = new ResourceIndexer();
final ResourceSet rs = new ResourceSetImpl();
rs.getResources().add(rs1);
rs.getResources().add(rs2);
rs.getResources().add(rs3);
EList<Resource> resources = rs.getResources();
indexer.resourceChanged(updater,resources.toArray(new Resource[resources.size()]));
//unload the resources
for (Iterator<Resource> iterator = resources.iterator(); iterator.hasNext();) {
c.inc();
Resource resource = (Resource) iterator.next();
resource.unload();
}
}
});
//Iterate over the queries
for (NamedQuery query : model.getNamedQueries()) {
final ResourceSet rs = new ResourceSetImpl();
Query transform = QueryTransformer.transform(query.getQuery());
long start = System.nanoTime();
ResultSet execute = QueryProcessorFactory.getDefault().createQueryProcessor(getDefaultIndexStore()).execute(transform, getQueryContext(rs));
long end = System.nanoTime();
long time = end-start;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.getMessage();
}
}
private QueryContext getQueryContext(final ResourceSet rs) {
return new QueryContext() {
@Override
public URI[] getResourceScope() {
final List<URI> result = new ArrayList<URI>();
getDefaultIndexStore().executeQueryCommand(new QueryCommand() {
@Override
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]);
}
@Override
public ResourceSet getResourceSet() {
return rs;
}
};
}
private static class Counter {
int i = 0;
void inc() {
i++;
}
int getCount() {
return i;
}
}
public static Index getDefaultIndexStore() {
return DEFAULT_INDEX;
}
Am I doing something wrong?
Thank you very much for your help.
Best Regards,
Fer
[Updated on: Mon, 09 January 2012 18:09] Report message to a moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03379 seconds