Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » efficient emf query
efficient emf query [message #417952] Mon, 31 March 2008 12:34 Go to next message
Amol is currently offline AmolFriend
Messages: 4
Registered: July 2009
Junior Member
Hi,

I executed the EMF query Library application which consists of the EMF
model (Writer, Book, Borrower, Library etc.)

------------------------:Consider the statement :------------------
"To select the borrowers of the books a particular writer has written"

Writer myWriter = (Writer)value; //assume I get the writer object here
String name = myWriter.getName();

EObjectCondition condition = new EObjectReferenceValueCondition(
new
EObjectTypeRelationCondition(EXTLibraryPackage.eINSTANCE.get Borrower()),
EXTLibraryPackage.eINSTANCE.getBorrower_Borrowed(),
new EObjectReferenceValueCondition(
new EObjectTypeRelationCondition(EXTLibraryPackage.eINSTANCE.get Book()),
EXTLibraryPackage.eINSTANCE.getBook_Author(),
new
EObjectAttributeValueCondition(EXTLibraryPackage.eINSTANCE.g etWriter_Name(),
new StringValue(name)))
);

SELECT statement = new SELECT(
new FROM(chosenOne.eResource().getContents()),
new WHERE(condition));

//chosenOne.eResource().getContents() ---> This is the list of all the
objects
--------------------:This worked fine:---------------

Now, I need to do this.
"To select the list of writers of the books a particular borrower has
borrowed"

Borrower myBorrower = (Borrower)value; //assume I get the borrower object
here

Basically from borrowers I can get the list of books he/she has borrowed.
Getting the writer name of these books will give me the required data.

I want to run the select statement, without passing the entire library
content but only by passing the borrower object.

SELECT statement = new SELECT(
new FROM(myborrower),
new WHERE(condition));

Please help me with what should the condition be, to get the desired list
of writers ?

Thanks and Regards,
-Amol.
Re: efficient emf query [message #417963 is a reply to message #417952] Mon, 31 March 2008 16:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Amol,

Christian is not around and I'm not familiar with this stuff. I'd just
get the borrower's list of books and collect the authors of each such
book into a set and be done with it...


Amol wrote:
> Hi,
>
> I executed the EMF query Library application which consists of the EMF
> model (Writer, Book, Borrower, Library etc.)
>
> ------------------------:Consider the statement :------------------
> "To select the borrowers of the books a particular writer has written"
>
> Writer myWriter = (Writer)value; //assume I get the writer object here
> String name = myWriter.getName();
>
> EObjectCondition condition = new EObjectReferenceValueCondition(
> new
> EObjectTypeRelationCondition(EXTLibraryPackage.eINSTANCE.get Borrower()),
> EXTLibraryPackage.eINSTANCE.getBorrower_Borrowed(),
> new EObjectReferenceValueCondition(
> new
> EObjectTypeRelationCondition(EXTLibraryPackage.eINSTANCE.get Book()),
> EXTLibraryPackage.eINSTANCE.getBook_Author(), new
> EObjectAttributeValueCondition(EXTLibraryPackage.eINSTANCE.g etWriter_Name(),
> new StringValue(name)))
> );
>
> SELECT statement = new SELECT(
> new FROM(chosenOne.eResource().getContents()), new
> WHERE(condition));
>
> //chosenOne.eResource().getContents() ---> This is the list of all the
> objects
> --------------------:This worked fine:---------------
>
> Now, I need to do this.
> "To select the list of writers of the books a particular borrower has
> borrowed"
>
> Borrower myBorrower = (Borrower)value; //assume I get the borrower
> object here
>
> Basically from borrowers I can get the list of books he/she has
> borrowed. Getting the writer name of these books will give me the
> required data.
>
> I want to run the select statement, without passing the entire library
> content but only by passing the borrower object.
>
> SELECT statement = new SELECT(
> new FROM(myborrower), new WHERE(condition));
>
> Please help me with what should the condition be, to get the desired
> list of writers ?
>
> Thanks and Regards,
> -Amol.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: efficient emf query [message #417971 is a reply to message #417963] Tue, 01 April 2008 05:02 Go to previous messageGo to next message
Amol Deshmukh is currently offline Amol DeshmukhFriend
Messages: 1
Registered: July 2009
Junior Member
Thanks for the quick response.

Yes, we can get it that way, but we would be iterating over all the
objects in the Library.
i.e. we will pass all the Library objects in the from clause

Is there any way where we can pass only the borrower object in the FROM
clause, and using only this object the EMF query finds the list of books
and from that list of books, their respective writers.

Basically, I am looking at NOT passing all the Library objects in the FROM
clause.

-Amol.
Re: efficient emf query [message #417980 is a reply to message #417971] Tue, 01 April 2008 11:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Amol,

I'm sure Christian will need to answer it when he's back; I should have
asked for how long he'd be away...

Given you can collect the answer by iterating over the borrowers books
and adding all the authors of those books into a set I'm not sure what's
compelling you to use a query....


Amol Deshmukh wrote:
> Thanks for the quick response.
>
> Yes, we can get it that way, but we would be iterating over all the
> objects in the Library.
> i.e. we will pass all the Library objects in the from clause
>
> Is there any way where we can pass only the borrower object in the
> FROM clause, and using only this object the EMF query finds the list
> of books and from that list of books, their respective writers.
>
> Basically, I am looking at NOT passing all the Library objects in the
> FROM clause.
>
> -Amol.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: efficient emf query [message #417998 is a reply to message #417952] Tue, 01 April 2008 15:28 Go to previous message
Eclipse UserFriend
Originally posted by: cdamus.ca.ibm.com

Hi, Amol,

As Ed indicates in his replies, this isn't actually a case where the
complexity of the query structure appears to bring much value, as a
Borrower directly references its borrowed books, and these reference their
authors.

Note that the EMF Query API doesn't have an analog of SQL's
column-projection capability. Thus, you cannot write a query that will
project the authors of books related to your borrower.

Initializing a FROM clause with your borrower will result in a SELECT
statement that can only return that borrower and/or the objects that it
contains. There is, currently, no provision for queries to crawl the
cross-reference graph, but only the content tree. You might see how far
you can get in implementing this yourself, though, using a custom FROM
clause implementation.

HTH,

Christian


Amol wrote:

> Hi,
>
> I executed the EMF query Library application which consists of the EMF
> model (Writer, Book, Borrower, Library etc.)
>
> ------------------------:Consider the statement :------------------
> "To select the borrowers of the books a particular writer has written"
>
> Writer myWriter = (Writer)value; //assume I get the writer object here
> String name = myWriter.getName();
>
> EObjectCondition condition = new EObjectReferenceValueCondition(
> new
> EObjectTypeRelationCondition(EXTLibraryPackage.eINSTANCE.get Borrower()),
> EXTLibraryPackage.eINSTANCE.getBorrower_Borrowed(),
> new EObjectReferenceValueCondition(
> new
> EObjectTypeRelationCondition(EXTLibraryPackage.eINSTANCE.get Book()),
> EXTLibraryPackage.eINSTANCE.getBook_Author(), new
>
EObjectAttributeValueCondition(EXTLibraryPackage.eINSTANCE.g etWriter_Name(),
> new StringValue(name)))
> );
>
> SELECT statement = new SELECT(
> new FROM(chosenOne.eResource().getContents()),
> new WHERE(condition));
>
> //chosenOne.eResource().getContents() ---> This is the list of all the
> objects
> --------------------:This worked fine:---------------
>
> Now, I need to do this.
> "To select the list of writers of the books a particular borrower has
> borrowed"
>
> Borrower myBorrower = (Borrower)value; //assume I get the borrower object
> here
>
> Basically from borrowers I can get the list of books he/she has borrowed.
> Getting the writer name of these books will give me the required data.
>
> I want to run the select statement, without passing the entire library
> content but only by passing the borrower object.
>
> SELECT statement = new SELECT(
> new FROM(myborrower),
> new WHERE(condition));
>
> Please help me with what should the condition be, to get the desired list
> of writers ?
>
> Thanks and Regards,
> -Amol.
Previous Topic:XML schema import and EEnums
Next Topic:[EMF Transactions] No custom NotificationFilters?
Goto Forum:
  


Current Time: Thu Apr 25 05:24:46 GMT 2024

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

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

Back to the top