emf model query [message #652513] |
Fri, 04 February 2011 06:03  |
Eclipse User |
|
|
|
Hi everybody...i'm a begginer with emf....
i'm trying to use emf model query in java... and i need to query an ecore model...
I put "model query" jars in plugins directory... do you have a sample code to query an ecore model starting from resource?
many thx!
|
|
|
|
|
|
|
|
|
Re: emf model query [message #652570 is a reply to message #652513] |
Fri, 04 February 2011 10:13   |
Eclipse User |
|
|
|
Chuck,
1. Have the model plug-in your target platform.
2. Index the data i.e. the XMI files.
You can use the project builder as indexer if your data is in the workspace or you can manually index the data by loading from your specific file location.
Once data indexed, you can unload your data.Then your queries will be executed against the index.
You may wish to not to use Indexed data rather going directly to loaded resources.Then you need to pass the loaded resource set and URIs of the resources in the resource scope.
3. Execute your queries.
Since you are using Object based format.A Query can be executed like this.
//Form entries
// from clause
FromType employees = new FromType("em", employeeUri, true); //$NON-NLS-1$
FromEntry[] fromEntries = new FromEntry[] { employees };
// select clause
SelectAttrs selectEmployeeName = new SelectAttrs("em", new String[] { "name" }); //$NON-NLS-1$ //$NON-NLS-2$
SelectAlias selectEm = new SelectAlias("em"); //$NON-NLS-1$
SelectEntry[] selectEntries = new SelectEntry[] { selectEm, selectEmployeeName };
// where entries
WhereInt whereYoung = new WhereInt("age", Operation.SMALLER, 40); //$NON-NLS-1$
WhereEntry whereEmYoung = new LocalWhereEntry("em", whereYoung); //$NON-NLS-1$
WhereEntry[] whereEntries = new WhereEntry[] { whereEmYoung };
// the actual query
Query query = new Query(selectEntries, fromEntries, whereEntries);
QueryProcessorFactory.getDefault().createQueryProcessor(inde x).execute(Query, context);
4. You will get an instance of ResultSet which you can use to display your data.
You may want to have a look at the test cases for example
For loaded data example org.eclipse.emf.query2.test.SuiteCompanyQueryTest
For Indexes
BaseSyntheticQueryTests.
Let us know if you are stuck.
cheers,
Saurav
[Updated on: Fri, 04 February 2011 10:14] by Moderator
|
|
|
|
|
|
|
|
|
|
Re: emf model query [message #655352 is a reply to message #652513] |
Sat, 19 February 2011 13:56  |
Eclipse User |
|
|
|
the problem is the path of xmi models... i downloaded code from svn and path of resource is plugin: and in my case is in folder in workspace... °_°
|
|
|
Powered by
FUDForum. Page generated in 0.03765 seconds