Quoting Rickard Öberg <[email protected]>:
On 2010-05-10 17.47, Stanislav Muhametsin wrote:
The test is this:
public void script15()
throws EntityFinderException
{
Male person = templateFor( Male.class );
// should return Ann and Joe Doe
Iterable<EntityReference> entities = entityFinder.findEntities(
Person.class.getName(),
isNull( person.wife() ),
NO_SORTING, NO_FIRST_RESULT, NO_MAX_RESULTS
);
assertNames( entities, ANN, JOE );
}
The test finds all people, who have their wife-association null. It
assumes that it should return two values: Ann and Joe Doe. Looking at
data models, the entity representing Ann Doe is of Female-type, and thus
doesn't even have wife-association. So, how can "is null" query match
something that doesn't even exist? At least I think that in order to be
null, something must exist first.
The query is for any entity implementing Person, which includes
Female/Ann. If the query asks for a property that doesn't even exist
in the Ann instance, then Ann should be included, because it doesn't
match the query requirement isNull(). So IMO the query/test is
correct.
Hmm? Something SHOULD be included in query result, because it does NOT
match the query requirement? Sounds quirky to me. Or was that a typo?
What is your opinion/explanation on this? Should there be separate
"exists"-expression in queries? Or "is null" really should match
non-existing things too?
I would say yes, isNull should match even non-existing things. If
you compare to reality and ask all available Person instances (some
of which are Male and some of which are Female), then it does make
sense that all Females would be included. If you wanted to ask for
Male that does not have Wife, then that is what the query would be.
I guess this is a trickier issue of having ideas in our heads to
formalize in programming languages and Qi4j specifically. Strictly
formally speaking, "isNull" should match everything that 1. exists and
2. is null. Then there can be "isNullOrNotExist" which matches
everything that either exists and is null, or doesn't exist.
Of course, I guess in practical life, having both "isNull" and
"isNullOrNotExist" wouldn't be feasible. Probably the method you
described by making Male as return type for query would be same as
formal "isNull". Luckily the fix for these kinds of queries didn't
cause whole re-write of SQLIndexing. ;)
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev