* @throws PersistenceException On error
*/
public Iterator executeSelect(String sql, int maxResults)
throws PersistenceException
{
TransactionGuard tg = new TransactionGuard(this);
try
{
SQLTemplate temp = new SQLTemplate();
temp.setDefaultTemplate(sql);
if (maxResults > 0)
{
temp.setFetchLimit(maxResults);
}
DataMap dataMap = getDataContext().getEntityResolver().getDataMaps().iterator().next();
temp.setRoot(dataMap);
Collection result = getDataContext().performQuery(temp);
return new CayenneIterator(result.iterator());
}
catch (Exception e)
{
tg.doCatch();
throw createLoggedException(e);
}
finally
{
tg.doFinally();
}
}