Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » query2 problem
query2 problem [message #655662] Tue, 22 February 2011 08:49 Go to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
hi everyone...i downloaded code from svn of library example ....but query result it's always 0...

i changed path of models,,metamodels and query and I guess paths are right...

the code flow is that:

@RunWith(Suite.class)
@Suite.SuiteClasses( { LibraryTransformation.class,
IndexQueryCountTest.class
})
public class LibraryTestSuite extends QueryTestCase {

}

=====LibraryTransformation=======
@BeforeClass
public static void setup() {
if (!Platform.isRunning()) {
new org.eclipse.emf.mwe.utils.StandaloneSetup().setPlatformUri(".. "); //$NON-NLS-1$
}

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/org.eclipse.emf.query2.librarytest/data/lib .query "); //$NON-NLS-1$
URI resourceURI = URI.createURI("./data/lib2.query");
URI normalized = set.getURIConverter().normalize(resourceURI);
LazyLinkingResource xtextResource = (LazyLinkingResource) set.getResource(normalized, true);
model = (Model) xtextResource.getContents().get(0);
}
@Test
public void transform() {

for (NamedQuery query : model.getNamedQueries()) {

final ResourceSet rs = new ResourceSetImpl();

Query transform = QueryTransformer.transform(query.getQuery());
System.out.println("\n" + query.getName() + "\n----------------------------------"); //$NON-NLS-1$ //$NON-NLS-2$
System.out.println(transform.toString().trim());

long start = System.nanoTime();
try{
ResultSet execute = QueryProcessorFactory.getDefault().createQueryProcessor(getD efaultIndexStore()).execute(transform, getQueryContextWithEmptyRS());
long end = System.nanoTime();

System.out.println(execute);
System.out.println("Size: " + execute.getSize()); //$NON-NLS-1$
long time = end - start;
System.out.println("QueryTime: " + time + "ns (" + (time / 1000000000f) + "s)"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}catch (Exception e) {
// TODO: handle exception
System.out.println("Error:"+e.getMessage());
}

}

}
private QueryContext getQueryContext(final ResourceSet rs) {
return new QueryContext() {

public URI[] getResourceScope() {
final List<URI> result = new ArrayList<URI>();
getDefaultIndexStore().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;
}

};
=========query file =========

import "http://eclipse.org/modeling/emf/query/1.0.0"
AllBooks : from Library as b select b
========query test case for indexing=====

public class QueryTestCase extends Assert {

private static final Index DEFAULT_INDEX = IndexFactory.getInstance();

private static class Counter {
int i = 0;

void inc() {
i++;
}

int getCount() {
return i;
}
}

static {

System.out.println("Start indexing"); //$NON-NLS-1$
final Counter c = new Counter();
DEFAULT_INDEX.executeUpdateCommand(new UpdateCommandAdapter() {



@Override
public void execute(final IndexUpdater updater) {
final ResourceIndexer indexer = new ResourceIndexer();
try {
indexer.resourceChanged(updater, EcorePackage.eINSTANCE.eResource());
indexer.resourceChanged(updater, LibraryPackage.eINSTANCE.eResource());
final ResourceSet rs = new ResourceSetImpl();
Parser parser = new Parser();
// load the resources
parser.loadResources(rs);
EList<Resource> resources = rs.getResources();
System.out.println("------->files indexed:"+resources.size()+"-last:"+resources.get(resources.size()-1).getURI());
indexer.resourceChanged(updater, resources.toArray(new Resource[0]));

// unload the resources
// for (Iterator iterator = resources.iterator(); iterator.hasNext()Wink {
// Resource resource = (Resource) iterator.next();
// resource.unload();
// }
} catch (Exception e) {
// Put your logging here
System.out.println(e.getMessage());
}
}
});

System.out.println("\nIndexing finished. Indexed " + c.getCount() + " files"); //$NON-NLS-1$ //$NON-NLS-2$
}

public static Index getDefaultIndexStore() {
return DEFAULT_INDEX;
}

@Before
public void beforeTestMethod() throws Exception {

}

@After
public void afterTestMethod() throws Exception {

}
}
==============================
the sysout of indexed files give me 300 and more files... but query always 0 size...
°_°
Re: query2 problem [message #655671 is a reply to message #655662] Tue, 22 February 2011 09:26 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

Hi Chuck,

Check 1 should be to see if indexes are present plus indexes contains the type for which you are making a search.

Can you check if index contains the type for which you are making a search.

Are you running these tests as Junit plugin tests ?
OR
Are running the query using Query Editor in runtime workbench ?



Regards,
Ashwani Kr Sharma

[Updated on: Tue, 22 February 2011 09:30]

Report message to a moderator

Re: query2 problem [message #655672 is a reply to message #655671] Tue, 22 February 2011 09:29 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
i'm running i junits...the same example on line!... i only change query to understand how it works...
Re: query2 problem [message #655674 is a reply to message #655672] Tue, 22 February 2011 09:30 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

I also saw that there is change in one line here:
//URI resourceURI = URI.createURI(" platform:/plugin/org.eclipse.emf.query2.librarytest/data/lib .query "); //$NON-NLS-1$
               URI resourceURI = URI.createURI("./data/lib2.query");


Is your .query file getting picket correctly ? May be you can try:
URI resourceURI = URI.createURI(" platform:/resource/org.eclipse.emf.query2.librarytest/data/lib .query "); //$NON-NLS-1$


Regards,
Ashwani Kr Sharma
Re: query2 problem [message #655675 is a reply to message #655674] Tue, 22 February 2011 09:39 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
this line it's correct because queries are printed correctly...
Re: query2 problem [message #655677 is a reply to message #655675] Tue, 22 February 2011 09:40 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

Hi,

Can you send your TestCase to ashw.kumar@gmail.com.
I will check it.

Regards,
Ashwani Kr Sharma
Re: query2 problem [message #655686 is a reply to message #655677] Tue, 22 February 2011 10:06 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
i guess there is a lack of @... Smile
Re: query2 problem [message #655758 is a reply to message #655677] Tue, 22 February 2011 15:02 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

Hi,

It is ashw.kumar @ gmail.com

Regards,
Ashwani Kr Sharma
Re: query2 problem [message #655885 is a reply to message #655686] Wed, 23 February 2011 01:40 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

Hi,

The indexes were not happening properly. You have change the URI in Parser to "./data/". The resources were getting indexed but the EObjects were not loaded in these resources.

I reverted the Parser to original implementation. I was accessing all the resources as "platform:/plugin/".

Also, run the JUnit as Junit plugin test.
All queries will return results now.

Regards,
Ashwani Kr Sharma
Re: query2 problem [message #655944 is a reply to message #655662] Wed, 23 February 2011 13:16 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
ok but i need to use query2 outside from junit and for this reason I tried to change path of models ...
Re: query2 problem [message #656077 is a reply to message #655944] Thu, 24 February 2011 04:00 Go to previous messageGo to next message
Ashwani Kr Sharma is currently offline Ashwani Kr SharmaFriend
Messages: 119
Registered: July 2009
Location: Bangalore, India
Senior Member

Hi,

The librarytests runs in central builds where i run them as plugin junit tests. Hence, i have made the work like this.
If you want to work them as plain junit, make following changes:

In LibraryTransformation and Parser classes change all uri's from platform:/plugin/ to platform:/resource/ .

Now, it should work for you. I have checked and it works.

Regards,
Ashwani Kr Sharma
Re: query2 problem [message #656201 is a reply to message #656077] Thu, 24 February 2011 14:41 Go to previous message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
i updated the plugin but i receive:
resource with path .... not found .." but i checked path and it's correct...i think the problem is in plugin...
Previous Topic:[CDO] migrate data from one repository to another
Next Topic:Altering XMLResource to create inter-EObject links bottom-up
Goto Forum:
  


Current Time: Sun Oct 20 13:56:40 GMT 2019

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

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

Back to the top