use of org.olat.core.commons.services.mark.MarkResourceStat in project openolat by klemens.
the class MarkManagerImpl method getStats.
@Override
public List<MarkResourceStat> getStats(OLATResourceable ores, List<String> subPaths, Identity identity) {
if (subPaths == null || subPaths.isEmpty()) {
// these stats are optimized
if (identity == null) {
return getStats(ores);
} else {
return getStats(ores, identity);
}
} else {
StringBuilder sb = new StringBuilder();
sb.append("select count(mark.resSubPath), mark.resSubPath from ").append(MarkImpl.class.getName()).append(" mark where ").append("mark.resId=:resId and mark.resName=:resName and mark.resSubPath in (:resSubPath)");
if (identity != null) {
sb.append(" and mark.creator=:creator");
}
sb.append(" group by mark.resSubPath");
TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).setParameter("resSubPath", subPaths);
if (identity != null) {
query.setParameter("creator", identity);
}
List<Object[]> rawStats = query.getResultList();
List<MarkResourceStat> stats = new ArrayList<MarkResourceStat>(rawStats.size());
for (Object[] rawStat : rawStats) {
stats.add(new MarkResourceStat(ores, (String) rawStat[1], ((Number) rawStat[0]).intValue()));
}
return stats;
}
}
use of org.olat.core.commons.services.mark.MarkResourceStat in project openolat by klemens.
the class MarkManagerImpl method getStats.
private List<MarkResourceStat> getStats(OLATResourceable ores) {
StringBuilder sb = new StringBuilder();
sb.append("select count(mark.resSubPath), mark.resSubPath from ").append(MarkImpl.class.getName()).append(" mark where ").append("mark.resId=:resId and mark.resName=:resName").append(" group by mark.resSubPath");
List<Object[]> rawStats = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resName", ores.getResourceableTypeName()).setParameter("resId", ores.getResourceableId()).getResultList();
List<MarkResourceStat> stats = new ArrayList<MarkResourceStat>(rawStats.size());
for (Object[] rawStat : rawStats) {
stats.add(new MarkResourceStat(ores, (String) rawStat[1], ((Number) rawStat[0]).intValue()));
}
return stats;
}
Aggregations