boolean bConj = false;
for (int i = parentList.size() - 1; i >= 0; --i)
{
Accessor parent = (Accessor)parentList.get(i);
InstanceList resultList = (InstanceList)parent.getValue("results");
if (resultList == null || resultList.size() == 0)
{
return setEmptyResult(reader);
}
Object assoc = assocList.get(i);
if (assoc != null && !(assoc instanceof Pair))
{
assoc = new Pair(assoc);
}
Instance parentInstance = resultList.getInstance(0);
Metaclass parentMetaclass = parentInstance.getMetaclass();
// Check for attributes without persistence mappings
if (i == 0)
{
Metaclass containerMetaclass = parentMetaclass;
for (Pair pair = (Pair)assoc; pair != null; pair = pair.getNext())
{
Attribute attribute = containerMetaclass.findAttribute((Symbol)pair.getHead());
if (attribute == null)
{
break;
}
attribute.checkReadAccess(m_context.getPrivilegeSet());
if (!attribute.isPersistent() &&
!attribute.getType().isPrimitive() &&
event == null &&
((Metaclass)attribute.getType()).findEvent("read", 6)
.findAction("main").getDeclarator().getBase() == null)
{
if (parentList.size() > 1)
{
throw new InvalidQueryException("err.persistence.multipleParentsWithoutPersistence",
new Object[]{classSym, assoc, parentMetaclass.getName()});
}
if (where != null || bookmark != null || orderBy != null)
{
throw new InvalidQueryException("err.persistence.whereWithoutPersistence",
new Object[]{classSym, assoc, parentMetaclass.getName()});
}
resultList = new InstanceArrayList();
collectAssociatedInstances((Pair)assoc, parentInstance, resultList);
int nOffset = (offset == null) ? 0 : offset.intValue();
int nCount = (count == null) ? -1 : count.intValue();
if (nOffset < 0)
{
nOffset = 0;
}
if (nCount < 0 || nCount > resultList.size() - nOffset)
{
nCount = resultList.size() - nOffset;
if (nCount < 0)
{
nCount = 0;
}
}
if (nOffset > 0 || resultList.size() > nCount)
{
InstanceList list = new InstanceArrayList(nCount);
for (int k = 0; k < nCount; ++k)
{
list.add(resultList.getInstance(k + nOffset), InstanceList.REPLACE | InstanceList.DIRECT);
}
resultList = list;
}
if (next != null && !next.booleanValue())
{
resultList.reverse();
}
for (int k = 0; k < nCount; ++k)
{
resultList.getInstance(k).invoke("load", attributes);
}
reader.setValue("results", resultList);
return resultList;
}
if (attribute.getType().isPrimitive())
{
break;
}
containerMetaclass = (Metaclass)attribute.getType();
}
}
assoc = new Pair(Symbol.ATAT, new Pair(parentMetaclass.getSymbol(), assoc));
Pair cond = Pair.binary(Symbol.EQ, assoc, parentInstance.getOID());
if (bConj)
{
where = new Pair(cond, where);
}
else if (where != null)
{
where = new Pair(cond, new Pair(where));
bConj = true;
}
else
{
where = cond;
}
}
if (bConj)
{
where = new Pair(Symbol.AND, where);
}
}
// Handle the bookmark
boolean bNext = true;
if (next != null && orderBy != null)
{
bNext = next.booleanValue();
if (!bNext)
{
// Flip sort order
Pair pair = orderBy;
Pair last = orderBy = null;
for (; pair != null; pair = pair.getNext())
{
Pair head = (Pair)pair.getHead();
Pair item = new Pair(new Pair(head.getHead(),
Boolean.valueOf(!((Boolean)head.getTail()).booleanValue())));
if (last == null)
{
orderBy = item;
}
else
{
last.setTail(item);
}
last = item;
}
}
// The bookmark has the following format: (value1 ... valueN)
// If values are missing, then the start or the end of the recordset is
// retrieved, depending on the value of next (inclusive is ignored in this case)
if (bookmark != null)
{
where = addBookmarkToWhere(where, orderBy, bookmark, inclusive);
}
}
// This takes care of the bookmark attributes access rights
metaclass.checkOrderByAccess(orderBy, m_context.getPrivilegeSet());
attributes = Pair.nconc(security, attributes);
InstanceList resultList;
if (event != null)
{
setValue(event, "attributes", argArray, attributes);
setValue(event, "where", argArray, where);
setValue(event, "orderBy", argArray, orderBy);
resultList = (InstanceList)event.invoke(argArray, m_context.getMachine());
}
else
{
resultList = (InstanceList)metaclass.invoke("read",
new Object[]{attributes, where, orderBy, count, offset, xlock});
}
if (!bNext)
{
resultList.reverse();
}
reader.setValue("results", resultList);
if (key != null)