query2 problem [message #655662] |
Tue, 22 February 2011 03:49  |
Eclipse User |
|
|
|
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 #656201 is a reply to message #656077] |
Thu, 24 February 2011 09:41  |
Eclipse User |
|
|
|
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...
|
|
|
Powered by
FUDForum. Page generated in 0.05192 seconds