Skip to content
Snippets Groups Projects
Commit d8fb31f7 authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

[debug] Add progress steps for queries

parent 9a21a75e
No related branches found
No related tags found
No related merge requests found
......@@ -41,6 +41,7 @@
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;
import org.xwiki.context.Execution;
import org.xwiki.job.event.status.JobProgressManager;
import org.xwiki.query.Query;
import org.xwiki.query.QueryException;
import org.xwiki.query.QueryExecutor;
......@@ -88,6 +89,9 @@ public class HqlQueryExecutor implements QueryExecutor, Initializable
@Inject
private ContextualAuthorizationManager authorization;
@Inject
private JobProgressManager progress;
private volatile Set<String> allowedNamedQueries;
@Override
......@@ -117,7 +121,7 @@ private Set<String> getAllowedNamedQueries()
}
}
}
return this.allowedNamedQueries;
}
......@@ -153,6 +157,8 @@ public <T> List<T> execute(final Query query) throws QueryException
String oldDatabase = getContext().getWikiId();
try {
this.progress.startStep(query, "query.hql.progress.execute", "Execute HQL query [{}]", query);
if (query.getWiki() != null) {
getContext().setWikiId(query.getWiki());
}
......@@ -178,6 +184,8 @@ public List<T> doInHibernate(Session session)
throw new QueryException("Exception while executing query", query, e);
} finally {
getContext().setWikiId(oldDatabase);
this.progress.endStep(query);
}
}
......
......@@ -103,7 +103,7 @@ public class DefaultQuery implements SecureQuery
/**
* field for {@link #getExecuter()}.
*/
private QueryExecutor executer;
private transient QueryExecutor executer;
/**
* Create a Query.
......@@ -294,4 +294,10 @@ protected QueryExecutor getExecuter()
{
return this.executer;
}
@Override
public String toString()
{
return getStatement();
}
}
......@@ -30,6 +30,7 @@
import org.xwiki.component.annotation.Component;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.job.event.status.JobProgressManager;
import org.xwiki.model.EntityType;
import org.xwiki.model.ModelContext;
import org.xwiki.model.reference.EntityReference;
......@@ -56,6 +57,9 @@ public class XWQLQueryExecutor implements QueryExecutor
@Inject
private ModelContext context;
@Inject
private JobProgressManager progress;
public QueryManager getQueryManager() throws ComponentLookupException
{
// We can't inject QueryManager because of cyclic dependency.
......@@ -78,6 +82,8 @@ public <T> List<T> execute(Query query) throws QueryException
Query nativeQuery;
try {
this.progress.startStep(query, "query.xwql.progress.execute", "Execute XWQL query [{}]", query);
if (query.getWiki() != null) {
if (currentEntityReference.getType() == EntityType.WIKI) {
this.context.setCurrentEntityReference(new WikiReference(query.getWiki()));
......@@ -124,6 +130,8 @@ public <T> List<T> execute(Query query) throws QueryException
+ this.translator.getOutputLanguage() + "] language", query, e);
} finally {
this.context.setCurrentEntityReference(currentEntityReference);
this.progress.endStep(query);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment