getSession(true).getNamedQuery("forums")
.setParameter("parentDir", forumsDirectory)
.setComment("Finding all forums")
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
forumInfoMap.put(
(Long) result[0],
new ForumInfo( (WikiDirectory)result[1])
);
return null;
}
public List transformList(List list) { return list; }
}
)
.list();
// Find topic and replies count (topics are just wiki documents in the forum directories)
getSession(true).getNamedQuery("forumTopicReplyCount")
.setParameter("parentDirId", forumsDirectory.getId())
.setParameter("readAccessLevel", currentAccessLevel)
.setComment("Finding topic and replies count for all forums")
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
if (forumInfoMap.containsKey((Long)result[0])) {
ForumInfo info = forumInfoMap.get( (Long)result[0] );
info.setTotalNumOfTopics((Long)result[1]);
info.setTotalNumOfPosts(info.getTotalNumOfTopics());
if (result[2] != null) {
info.setTotalNumOfPosts(info.getTotalNumOfPosts() + (Long)result[2]);
}
}
return null;
}
public List transformList(List list) { return list; }
}
)
.list();
// Append last topic WikiDocument (faster if we do it with a MySQL specific LIMIT subselect)
List<Object[]> forumsAndLastTopics = getSession(true).getNamedQuery("forumLastTopic")
.setParameter("parentDirId", forumsDirectory.getId())
.setParameter("readAccessLevel", currentAccessLevel)
.setComment("Finding last topics for all forums")
.list();
for (Object[] lastTopicRow : forumsAndLastTopics) {
if (forumInfoMap.containsKey((Long)lastTopicRow[0])) {
WikiDocument lastTopic = wikiNodeDAO.findWikiDocument( (Long)lastTopicRow[1] );
forumInfoMap.get( (Long)lastTopicRow[0] ).setLastTopic( lastTopic );
}
}
// Append last reply WikiComment
for (final Long forumId : forumInfoMap.keySet()) {
getSession(true).getNamedQuery("forumLastReply")
.setParameter("parentDirId", forumId)
.setParameter("readAccessLevel", currentAccessLevel)
.setComment("Finding last replies for forum : " + forumId)
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
forumInfoMap.get(forumId).setLastComment( (WikiComment)result[0] );
return null;
}
public List transformList(List list) { return list; }