queryString.append(getBlogEntryWhereClause(ignoreDoc, year, month, day, tag));
queryString.append(" ");
queryString.append("order by doc2.CREATED_ON desc");
SQLQuery query = getSession().createSQLQuery(queryString.toString());
bindBlogEntryWhereClause(query, startDir, ignoreDoc, year, month, day, tag);
query.setComment("Finding all blogEntry documents recursively in dir: " + startDir.getName());
query.addEntity(WikiDocument.class);
query.addScalar("COMMENT_COUNT", Hibernate.LONG);
query.setFirstResult( pager.getQueryFirstResult() );
query.setMaxResults( pager.getQueryMaxResults() );
query.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] aliases) {
BlogEntry be = new BlogEntry();
be.setEntryDocument( (WikiDocument)result[0]);
blogEntryMap.put(be.getEntryDocument().getId(), be); // Put in map so we can attach comment count later
return be;
}
public List transformList(List list) { return list; }
}
);
List<BlogEntry> result = (List<BlogEntry>)query.list();
if (countComments && result.size() > 0) {
// The risk here is that pager.getQueryMaxResults() is too large for the IN() operator of some DBs...
StringBuilder commentQueryString = new StringBuilder();
commentQueryString.append("select doc.NODE_ID as DOC_ID, count(c1.NODE_ID) as COMMENT_COUNT").append(" ");
commentQueryString.append("from WIKI_DOCUMENT doc").append(" ");
commentQueryString.append("left outer join WIKI_NODE c1 on doc.NODE_ID = c1.PARENT_NODE_ID").append(" ");
commentQueryString.append("where doc.NODE_ID in (:blogEntriesIds)").append(" ");
commentQueryString.append("group by doc.NODE_ID");
SQLQuery commentQuery = getSession().createSQLQuery(commentQueryString.toString());
commentQuery.setComment("Finding comment count for blog entries");
commentQuery.addScalar("DOC_ID");
commentQuery.addScalar("COMMENT_COUNT");
commentQuery.setParameterList("blogEntriesIds", blogEntryMap.keySet());
commentQuery.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] aliases) {
BlogEntry be = blogEntryMap.get( ((BigInteger)result[0]).longValue() );
be.setCommentCount( ((BigInteger)result[1]).longValue() );
return null;
}
public List transformList(List list) { return list; }
}
);
commentQuery.list();
}
return result;
}