if (log.isDebugEnabled()) log.debug("Start execute query");
//obtain current ODMG transaction
TransactionImpl tx = odmg.getTxManager().getTransaction();
// create PBCapsule
PBCapsule capsule = null;
ManageableCollection result = null;
try
{
capsule = new PBCapsule(odmg.getCurrentPBKey(), tx);
PersistenceBroker broker = capsule.getBroker();
// ask the broker to perfom the query.
// the concrete result type is configurable
if (!(query instanceof ReportQuery))
{
result = broker.getCollectionByQuery(this.getCollectionClass(), query);
performLockingIfRequired(tx, broker, result);
}
else
{
Iterator iter = null;
result = new ManageableArrayList();
iter = broker.getReportQueryIteratorByQuery(query);
try
{
while (iter.hasNext())
{
Object[] res = (Object[]) iter.next();
if (res.length == 1)
{
if (res[0] != null) // skip null values
{
result.ojbAdd(res[0]);
}
}
else
{
// skip null tuples
for (int i = 0; i < res.length; i++)
{
if (res[i] != null)
{
result.ojbAdd(res);
break;
}
}
}
}
}
finally
{
if (iter instanceof OJBIterator)
{
((OJBIterator) iter).releaseDbResources();
}
}
}
// reset iterator to start of list so we can reuse this query
ListIterator it = getBindIterator();
while (it.hasPrevious())
{
it.previous();
}
}
finally
{
if (capsule != null) capsule.destroy();
}
return result;
}