Skip to main content



      Home
Home » Modeling » EMF » emf model query(confused)
emf model query [message #652513] Fri, 04 February 2011 06:03 Go to next message
Eclipse UserFriend
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 #652516 is a reply to message #652513] Fri, 04 February 2011 06:15 Go to previous messageGo to next message
Eclipse UserFriend
Hi Chuck,

Do you mean model query jars or model query2 jars ?.

cheers,
Saurav
Re: emf model query [message #652517 is a reply to message #652516] Fri, 04 February 2011 06:18 Go to previous messageGo to next message
Eclipse UserFriend
model query jars...
but i don't know wich is the difference beetween the first one e the second version...

thx a million!
Re: emf model query [message #652518 is a reply to message #652513] Fri, 04 February 2011 06:23 Go to previous messageGo to next message
Eclipse UserFriend
Hi Chuck,

Model Query actually loads all the resource in the memory and then performs the query operations hence suffers in terms of scalability.

Whereas Model Query2 uses an index mechanism behind the scenes which allows user to query model data loading resources minimally.It also comes with a XText based SQL like query language and an convinient UI which will help you to query your resources.

Let us know if you need any further information

cheers,
Saurav

[Updated on: Fri, 04 February 2011 06:24] by Moderator

Re: emf model query [message #652520 is a reply to message #652518] Fri, 04 February 2011 06:28 Go to previous messageGo to next message
Eclipse UserFriend
ok...i put query2 jars in plugin and deleted query jars... my goal is to query models programmatically in java .... can you provide me some very simple examples ??
Re: emf model query [message #652521 is a reply to message #652513] Fri, 04 February 2011 06:40 Go to previous messageGo to next message
Eclipse UserFriend
Chuck,

You can programmatically query models using Query2.

Please check the following link for how to setup Query2 and how to execute queries in object format.

http://wiki.eclipse.org/EMF/Query2/DevGuide#Writing_Queries_ in_Object_format.

Also suggest you to use this update site link for the latest jars.

https://hudson.eclipse.org/hudson/job/tycho-query2-nightly/l astSuccessfulBuild/artifact/targetPlatform/

You can also check this forum link where we had discussions couple of days back on the first steps for Query2.

http://www.eclipse.org/forums/index.php?t=msg&th=203789& amp; amp;start=0&S=08ea2661269e7ad29eebbaf92cb1fa03

Let us know if you face any problems while executing the queries.

cheers,
Saurav

[Updated on: Fri, 04 February 2011 06:43] by Moderator

Re: emf model query [message #652564 is a reply to message #652521] Fri, 04 February 2011 09:38 Go to previous messageGo to next message
Eclipse UserFriend
i don't understand how to query models...i' m reading but i would like a sample with xmi or ecore models to query.
Re: emf model query [message #652570 is a reply to message #652513] Fri, 04 February 2011 10:13 Go to previous messageGo to next message
Eclipse UserFriend
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 #652595 is a reply to message #652570] Fri, 04 February 2011 11:27 Go to previous messageGo to next message
Eclipse UserFriend
thx! where i can find source of these examples?i found only class files...
Re: emf model query [message #652603 is a reply to message #652513] Fri, 04 February 2011 11:45 Go to previous messageGo to next message
Eclipse UserFriend
Chuck,,

For that you need to sync the files from CVS.

Our code can be found under /cvsroot/modeling

More details about how to connect to Eclipse CVS

http://wiki.eclipse.org/CVS_Howto

Web browsing can be done through

http://dev.eclipse.org/viewcvs/viewvc.cgi/org.eclipse.emf/or g.eclipse.emf.query/?root=Modeling_Project

cheers,
Saurav
Re: emf model query [message #653308 is a reply to message #652603] Wed, 09 February 2011 05:03 Go to previous messageGo to next message
Eclipse UserFriend
hi, i'm so confused Smile

i downloaded src files of librarytest... but i don't understand how to index files... in librarytest there are some java classes like librarypackage ...how to obtain that from myecore model?
I need a really simple example...sorry for my "dummy" experience... Smile
Re: emf model query [message #653441 is a reply to message #653308] Wed, 09 February 2011 13:45 Go to previous messageGo to next message
Eclipse UserFriend
sorry my problem was genmodel file... i guess ecore is not validated Sad... i will update this 3d ...
Re: emf model query [message #653616 is a reply to message #652513] Thu, 10 February 2011 07:35 Go to previous messageGo to next message
Eclipse UserFriend
I receive this error...
i don't know why...

Caused by: java.lang.NullPointerException
at org.eclipse.emf.query.index.IndexFactory.getDirectoryToDumpI ndices(IndexFactory.java:73)
at org.eclipse.emf.query.index.IndexFactory.getOptions(IndexFac tory.java:66)
at org.eclipse.emf.query.index.IndexFactory.<clinit>(IndexFactory.java:32)
... 1 more
Re: emf model query [message #653698 is a reply to message #653616] Thu, 10 February 2011 13:13 Go to previous messageGo to next message
Eclipse UserFriend
Chuck,

Are you running a test ? if yes are you running it as a Junit Plug-in test ?.

cheers,
Saurav
Re: emf model query [message #655194 is a reply to message #653698] Fri, 18 February 2011 10:45 Go to previous messageGo to next message
Eclipse UserFriend
what do you mean for test? i'm not in junit...i would use model query 2 in java class...execute some query on models and manipulate results... executing library test under junit i receive always size:0 ...i guess depends on registering of metamodel?? Embarrassed Embarrassed
Re: emf model query [message #655352 is a reply to message #652513] Sat, 19 February 2011 13:56 Go to previous message
Eclipse UserFriend
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... °_°
Previous Topic:[EMFCompare] Not working with resources using content types
Next Topic:Teneo source bundles containing plugin.xml
Goto Forum:
  


Current Time: Wed Jul 23 11:04:56 EDT 2025

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

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

Back to the top