Search in sources :

Example 11 with MonitorPlugin

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);
        }
    }
}
Also used : Query(org.hibernate.Query) MonitorPlugin(com.xpn.xwiki.monitor.api.MonitorPlugin) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) BaseObject(com.xpn.xwiki.objects.BaseObject) XWikiException(com.xpn.xwiki.XWikiException) InitializationException(org.xwiki.component.phase.InitializationException) MigrationRequiredException(com.xpn.xwiki.store.migration.MigrationRequiredException) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) QueryException(org.xwiki.query.QueryException) UnexpectedException(org.xwiki.store.UnexpectedException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) SQLException(java.sql.SQLException) XWikiException(com.xpn.xwiki.XWikiException) Session(org.hibernate.Session)

Aggregations

XWikiException (com.xpn.xwiki.XWikiException)11 MonitorPlugin (com.xpn.xwiki.monitor.api.MonitorPlugin)11 InitializationException (org.xwiki.component.phase.InitializationException)10 XWikiContext (com.xpn.xwiki.XWikiContext)9 MigrationRequiredException (com.xpn.xwiki.store.migration.MigrationRequiredException)8 SQLException (java.sql.SQLException)8 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)8 Session (org.hibernate.Session)8 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)8 QueryException (org.xwiki.query.QueryException)8 UnexpectedException (org.xwiki.store.UnexpectedException)8 BaseObject (com.xpn.xwiki.objects.BaseObject)6 Query (org.hibernate.Query)6 ArrayList (java.util.ArrayList)4 SessionFactory (org.hibernate.SessionFactory)4 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)3 List (java.util.List)3 DocumentReference (org.xwiki.model.reference.DocumentReference)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2