query2 problem [message #655662] |
Tue, 22 February 2011 08:49 |
chuck 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() {
// 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 |
|
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 #655674 is a reply to message #655672] |
Tue, 22 February 2011 09:30 |
|
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 #655885 is a reply to message #655686] |
Wed, 23 February 2011 01:40 |
|
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 #656077 is a reply to message #655944] |
Thu, 24 February 2011 04:00 |
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.04288 seconds