Home » Modeling » EMF » efficient emf query
efficient emf query [message #417952] |
Mon, 31 March 2008 12:34 |
Amol 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 |
Ed Merks 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 #417998 is a reply to message #417952] |
Tue, 01 April 2008 15:28 |
Eclipse User |
|
|
|
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.
|
|
|
Goto Forum:
Current Time: Thu Apr 25 05:24:46 GMT 2024
Powered by FUDForum. Page generated in 0.03347 seconds
|