Commit 2085c719 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

fetching list of reactions is faster

parent 793a72d4
......@@ -4,8 +4,10 @@ import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
......@@ -141,14 +143,17 @@ public class ReactionDao extends BaseDao<Reaction> {
participantClause = " and element.id in :participant_ids ";
}
String queryString = "select reaction, node, line from " + this.getClazz().getSimpleName() + " reaction "
+ "inner join reaction.nodes node "
+ "inner join node.element element "
+ "inner join node.line line "
+ "where reaction.model in :maps "
+ idClause
+ participantClause
+ removableAndStatemant();
Query<?> query = getSession()
.createQuery("select reaction from " + this.getClazz().getSimpleName() + " reaction "
+ "inner join reaction.nodes node inner join node.element element "
+ "where reaction.model in :maps "
+ idClause
+ participantClause
+ removableAndStatemant()
+ " group by reaction")
.createQuery(queryString)
.setParameter("maps", maps);
if (ids.size() > 0) {
query.setParameter("ids", ids);
......@@ -157,7 +162,14 @@ public class ReactionDao extends BaseDao<Reaction> {
query.setParameter("participant_ids", participantIds);
}
return genericListToReactionList(query.list());
Set<Reaction> result = new LinkedHashSet<>();
for (Object object : query.list()) {
Object[] row = (Object[]) object;
result.add((Reaction) row[0]);
}
return new ArrayList<>(result);
}
@SuppressWarnings("unchecked")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment