Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [EMF Query 2] Trouble with the import line in *.query file
[EMF Query 2] Trouble with the import line in *.query file [message #718884] Thu, 25 August 2011 14:51 Go to next message
Fer Missing name is currently offline Fer Missing nameFriend
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 #718900 is a reply to message #718884] Thu, 25 August 2011 15:24 Go to previous messageGo to next message
Fer Missing name is currently offline Fer Missing nameFriend
Messages: 24
Registered: September 2009
Junior Member
Hello all,

I solved the problem by setting both imports:

import "http://www.engineering.org/vsd/v10"
import "platform:/resource/engineering.query/model/engineering.ecore"


Is there a better way?

Best Regards,

Fernando
Re: [EMF Query 2] Trouble with the import line in *.query file [message #718996 is a reply to message #718900] Thu, 25 August 2011 18:13 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
Hi Fer,

Is you model part of the target platform ?

cheers,
Saurav


Re: [EMF Query 2] Trouble with the import line in *.query file [message #718997 is a reply to message #718996] Thu, 25 August 2011 18:20 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
Ok i presume the model is in your workspace after looking at your import ecore URI.
Query2 editor does not work out of the box until your model is installed in the target platform.

We already have a bug here

https://bugs.eclipse.org/bugs/show_bug.cgi?id=333722

Let me know on any further questions related to Query2.

cheers,
Saurav


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 Go to previous message
Fer Missing name is currently offline Fer Missing nameFriend
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

Previous Topic:Metadata utilization
Next Topic:Constructing generic objects
Goto Forum:
  


Current Time: Fri Apr 26 13:18:25 GMT 2024

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

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

Back to the top