Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » emf model query(confused)
emf model query [message #652513] Fri, 04 February 2011 11:03 Go to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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 11:15 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
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 11:18 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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 11:23 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
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 11:24]

Report message to a moderator

Re: emf model query [message #652520 is a reply to message #652518] Fri, 04 February 2011 11:28 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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 11:40 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
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 11:43]

Report message to a moderator

Re: emf model query [message #652564 is a reply to message #652521] Fri, 04 February 2011 14:38 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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 15:13 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
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 15:14]

Report message to a moderator

Re: emf model query [message #652595 is a reply to message #652570] Fri, 04 February 2011 16:27 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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 16:45 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
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 10:03 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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 18:45 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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 12:35 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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 18:13 Go to previous messageGo to next message
saurav sarkar is currently offline saurav sarkarFriend
Messages: 428
Registered: July 2009
Senior Member
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 15:45 Go to previous messageGo to next message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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 18:56 Go to previous message
chuck  is currently offline chuck Friend
Messages: 160
Registered: July 2010
Senior Member
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: Fri Apr 19 04:46:55 GMT 2024

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

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

Back to the top