Hello,
I think i have found a bug in PrefetchHelper.java, i discovered it when
testing my application which uses resolveToOneRelations() defined in
PrefetchHelper.
In "PrefetchHelper.java" there is a function called
resolveToOneRelations(). Here's a the interesting code:
===============
List oids = new ArrayList(nobjects);
for (int i = 0; i < nobjects; i++) {
DataObject sourceObject = (DataObject) objects.get(i);
DataObject targetObject = (DataObject)
sourceObject.readProperty(relName);
if (targetObject.getPersistenceState() ==
PersistenceState.HOLLOW) {
ObjectId oid = targetObject.getObjectId();
oids.add(oid);
}
}
// this maybe suboptimal, cause it uses an OR .. OR .. OR ..
expression
// instead of IN (..) - to be compatble with compound keys -
// however, it seems to be quite fast as well
SelectQuery sel = QueryUtils.selectQueryForIds(oids);
context.performQuery(sel);
===============
It is possible that "List oids" will be a empty list when it reaches the line:
===============
SelectQuery sel = QueryUtils.selectQueryForIds(oids);
===============
because when a object has already been retrieved once the following line
will return false and no object is added to oids list.
===============
if (targetObject.getPersistenceState() == PersistenceState.HOLLOW) {
===============
"QueryUtils.selectQueryForIds(oids);" will raise a IllegalArgumentException
when the oids list is empty.
===============
IllegalArgumentException("List must contain at least one ObjectId")
===============
I now just catch this "IllegalArgumentException" in my code and ignore it.
But a check in PrefetchHelper would be nice, something like:
===============
if(oids.size()!=0){
SelectQuery sel = QueryUtils.selectQueryForIds(oids);
context.performQuery(sel);
}
===============
Cheers,
Twan Kogels
This archive was generated by hypermail 2.0.0 : Tue Aug 31 2004 - 03:51:25 EDT