use of com.xpn.xwiki.monitor.api.MonitorPlugin in project xwiki-platform by xwiki.
the class XWikiHibernateStore method searchGenericInternal.
/**
* @since 2.2M1
*/
private <T> List<T> searchGenericInternal(String sql, int nb, int start, List<?> parameterValues, XWikiContext context) throws XWikiException {
boolean bTransaction = false;
MonitorPlugin monitor = Util.getMonitorPlugin(context);
try {
// Start monitoring timer
if (monitor != null) {
monitor.startTimer(HINT, sql);
}
checkHibernate(context);
bTransaction = beginTransaction(false, context);
Session session = getSession(context);
Query query = session.createQuery(filterSQL(sql));
injectParameterListToQuery(0, query, parameterValues);
if (start != 0) {
query.setFirstResult(start);
}
if (nb != 0) {
query.setMaxResults(nb);
}
Iterator it = query.list().iterator();
List list = new ArrayList<>();
while (it.hasNext()) {
list.add(it.next());
}
return list;
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_SEARCH, "Exception while searching documents with SQL [{0}]", e, new Object[] { sql });
} finally {
try {
if (bTransaction) {
endTransaction(context, false, false);
}
} catch (Exception e) {
}
// End monitoring timer
if (monitor != null) {
monitor.endTimer(HINT);
}
}
}
Aggregations