[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.tools.emf] Complex EMF Query for a "Simple Query"

Hello,

I am playing around with EMF Query currently. I wanted to write a simple query based on the Extended Library Model.

SELECT Authors
FROM Library
WHERE COUNT(Authors.Books) > 10

I ended up writing a query like this. Would like to know if there is a simpler way of doing this.

EObjectCondition adaptedCondition = new EObjectCondition(){
@Override
public boolean isSatisfied(EObject object) {
if (object.eClass().equals(EXTLibraryPackage.eINSTANCE.getWriter())) {
if (((EList)object.eGet(EXTLibraryPackage.eINSTANCE.getWriter_Books())).size()
10)
				return true;
		}
		return false;
	}
};

EObjectCondition contextCondition = new EObjectTypeRelationCondition(
		EXTLibraryPackage.eINSTANCE.getWriter());

EObjectCondition valueCondition = new EObjectReferenceValueCondition(
		EXTLibraryPackage.eINSTANCE.getBook_Author(),
		adaptedCondition);

EObjectCondition masterCondition = new EObjectReferenceValueCondition(
contextCondition,
EXTLibraryPackage.eINSTANCE.getWriter_Books(), valueCondition);

What I find funny is the fact that, I started with Writer as the context (because this is what I want to return). Then I get the Books of the Writer, then the Writer of the Books, then the Books of the writer again. Arrrrg.... Has to be a better way.


Thanks in advance,

Nirmal