Hey,
In our project we came across a query situation that I think will be
quite common, so I updated the QueryExpressions API to allow it. The
case is as follows:
You have one Entity, e.g. "PetEntity" which has an Association to a
Person. Person, in turn, has a name Property, but it is not available
directly from the Person interface as it is in an internal state
interface only. It was not possible to query for "all pets whose owner
is named 'Foo'", which is a big problem, and something that we needed to
do quite often in my project.
So, I added a variation of templateFor in QueryExpressions which takes
both a mixin type and an object to start from. Here's an example from
IterableQueryTest on how you could use it:
QueryBuilder<PetEntity> qb = qbf.newQueryBuilder(PetEntity.class);
Pet.PetState pet = templateFor(Pet.PetState.class);
Nameable petOwner = templateFor(Nameable.class, pet.owner().get());
qb.where(eq(petOwner.name(), "Jack Doe"));
--
The key is that pet.owner() returns a Person, but I want to check the
name() property from Nameable, so I need to convert the Person to a
Nameable (this is a terrible example though since Person happens to
extend Nameable though, but the idea is the same). The new templateFor()
method allows me to do this.
I've already tried it in my own project, and it works even for the RDF
query engine.
/Rickard
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev