[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/forum ...
Christian Bauer
christian at hibernate.org
Tue Dec 25 08:06:30 EST 2007
User: cbauer
Date: 07/12/25 08:06:30
Modified: examples/wiki/src/main/org/jboss/seam/wiki/plugin/forum
ForumQueries.hbm.xml ForumDAO.java
Log:
Forum topic list didn't sort topics by latest comment date, fallback to native SQL query
Revision Changes Path
1.3 +56 -16 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/forum/ForumQueries.hbm.xml
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ForumQueries.hbm.xml
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/forum/ForumQueries.hbm.xml,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ForumQueries.hbm.xml 19 Dec 2007 04:29:25 -0000 1.2
+++ ForumQueries.hbm.xml 25 Dec 2007 13:06:30 -0000 1.3
@@ -131,21 +131,62 @@
]]></query>
- <!-- Somewhat ugly workarounds for the missing case...when support in HQL select clause -->
- <query name="forumTopics"><![CDATA[
- select
- t.id,
- t,
- locate('forumStickyPosting', t.headerMacrosString, 1)
+ <!-- TODO: HQL doesn't support CASE...WHEN -->
+ <!-- TODO: We could optimize this a little if we'd also retrieve the CREATED_BY_USER_ID guy but
+ we'll hit the 2nd level cache anyway or we load them in batches... -->
+ <sql-query name="forumTopics">
+ <return class="org.jboss.seam.wiki.core.model.WikiDocument"/>
+ <return-scalar column="STICKY" type="integer"/>
+ <return-scalar column="LAST_POST" type="timestamp"/>
+ <![CDATA[
+ select distinct
+ doc2.NODE_ID as NODE_ID,
+ doc2.OBJ_VERSION as OBJ_VERSION,
+ doc2.AREA_NR as AREA_NR,
+ doc2.NAME as NAME,
+ doc2.WIKINAME as WIKINAME,
+ doc2.CREATED_ON as CREATED_ON,
+ doc2.CREATED_BY_USER_ID as CREATED_BY_USER_ID,
+ doc2.LAST_MODIFIED_ON as LAST_MODIFIED_ON,
+ doc2.LAST_MODIFIED_BY_USER_ID as LAST_MODIFIED_BY_USER_ID,
+ doc2.WRITE_ACCESS_LEVEL as WRITE_ACCESS_LEVEL,
+ doc2.READ_ACCESS_LEVEL as READ_ACCESS_LEVEL,
+ doc2.WRITE_PROTECTED as WRITE_PROTECTED,
+ doc2.PARENT_NODE_ID as PARENT_NODE_ID,
+
+ doc1.FILE_REVISION as FILE_REVISION,
+
+ doc0.NAME_AS_TITLE as NAME_AS_TITLE,
+ doc0.ENABLE_COMMENTS as ENABLE_COMMENTS,
+ doc0.ENABLE_COMMENT_FORM as ENABLE_COMMENT_FORM,
+ doc0.ENABLE_COMMENTS_ON_FEEDS as ENABLE_COMMENTS_ON_FEEDS,
+ doc0.HEADER as HEADER,
+ doc0.HEADER_MACROS as HEADER_MACROS,
+ doc0.CONTENT_MACROS as CONTENT_MACROS,
+ doc0.FOOTER as FOOTER,
+ doc0.FOOTER_MACROS as FOOTER_MACROS,
+
+ case when (doc0.HEADER_MACROS like '%forumStickyPosting%') then 1 else 0 end as STICKY,
+ case
+ when
+ (select max(c3.CREATED_ON) from WIKI_COMMENT c2 inner join WIKI_NODE c3 on c2.NODE_ID = c3.NODE_ID where c2.NS_THREAD in
+ (select c4.NS_THREAD from WIKI_COMMENT c4 inner join WIKI_NODE c5 on c4.NODE_ID = c5.NODE_ID where c5.PARENT_NODE_ID = doc0.NODE_ID)
+ ) is null
+ then doc2.CREATED_ON
+ else
+ (select max(c3.CREATED_ON) from WIKI_COMMENT c2 inner join WIKI_NODE c3 on c2.NODE_ID = c3.NODE_ID where c2.NS_THREAD in
+ (select c4.NS_THREAD from WIKI_COMMENT c4 inner join WIKI_NODE c5 on c4.NODE_ID = c5.NODE_ID where c5.PARENT_NODE_ID = doc0.NODE_ID)
+ )
+ end as LAST_POST
from
- WikiDirectory f,
- WikiDocument t join fetch t.createdBy u join fetch u.profile up
+ WIKI_DOCUMENT doc0 inner join WIKI_FILE doc1 on doc0.NODE_ID=doc1.NODE_ID inner join WIKI_NODE doc2 on doc0.NODE_ID=doc2.NODE_ID,
+ WIKI_COMMENT c0 inner join WIKI_NODE c1 on c0.NODE_ID = c1.NODE_ID
where
- f = :forum
- and t.parent = f
- and (t.headerMacrosString like '%forumPosting%' or t.headerMacrosString like '%forumStickyPosting%')
- order by case locate('forumStickyPosting', t.headerMacrosString, 1) when '0' then '0' else '1' end desc, t.createdOn desc
- ]]></query>
+ doc2.PARENT_NODE_ID= :parentNodeId
+ and (doc0.HEADER_MACROS like '%forumPosting%' or doc0.HEADER_MACROS like '%forumStickyPosting%')
+ order
+ by STICKY desc, LAST_POST desc
+ ]]></sql-query>
<query name="forumTopicsReplies"><![CDATA[
select
@@ -155,7 +196,7 @@
from
WikiDocument t,
WikiComment c,
- WikiComment c2 join fetch c2.createdBy u join fetch u.profile up
+ WikiComment c2 join fetch c2.createdBy u
where
t.id in (:topicIds)
and c.nodeInfo.nsThread in (select c3.nodeInfo.nsThread from WikiComment c3 where c3.parent = t)
@@ -170,8 +211,7 @@
c2.areaNumber, c2.name, c2.wikiname, c2.createdBy, c2.createdOn, c2.lastModifiedBy, c2.lastModifiedOn, c2.readAccessLevel, c2.writeAccessLevel, c2.writeProtected,
c2.subject, c2.fromUserName, c2.fromUserEmail, c2.fromUserHomepage, c2.useWikiText,
- u.id, u.version, u.firstname, u.lastname, u.username, u.passwordHash, u.email, u.activated, u.activationCode, u.createdOn, u.lastLoginOn, u.memberHome, u.profile,
- up.id, up.version, up.createdOn, up.bio, up.website, up.location, up.occupation, up.signature, up.imageContentType
+ u.id, u.version, u.firstname, u.lastname, u.username, u.passwordHash, u.email, u.activated, u.activationCode, u.createdOn, u.lastLoginOn, u.memberHome, u.profile
]]></query>
1.3 +19 -5 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/forum/ForumDAO.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ForumDAO.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/plugin/forum/ForumDAO.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- ForumDAO.java 19 Dec 2007 04:29:25 -0000 1.2
+++ ForumDAO.java 25 Dec 2007 13:06:30 -0000 1.3
@@ -35,6 +35,7 @@
getSession(true).getNamedQuery("forums")
.setParameter("parentDir", forumsDirectory)
+ .setComment("Finding all forums")
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
@@ -52,6 +53,8 @@
// Find topic count (topics are just wiki documents in the forum directories)
getSession(true).getNamedQuery("forumTopicCount")
.setParameter("parentDir", forumsDirectory)
+ .setComment("Finding topic count for all forums")
+ .setCacheable(true)
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
@@ -70,6 +73,8 @@
// Add reply count to topic count to get total num of posts
getSession(true).getNamedQuery("forumReplyCount")
.setParameter("parentDir", forumsDirectory)
+ .setComment("Finding reply count for all forums")
+ .setCacheable(true)
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
@@ -89,6 +94,7 @@
// Append last topic WikiDocument
getSession(true).getNamedQuery("forumLastTopic")
.setParameter("parentDir", forumsDirectory)
+ .setComment("Finding last topics for all forums")
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
@@ -104,6 +110,7 @@
// Append last reply WikiComment
getSession(true).getNamedQuery("forumLastReply")
.setParameter("parentDir", forumsDirectory)
+ .setComment("Finding last replies for all forums")
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
@@ -134,6 +141,8 @@
getSession(true).getNamedQuery(unreadTopicsQuery)
.setParameter("parentDir", directory)
.setParameter("lastLoginDate", lastLoginDate)
+ .setComment("Finding unread topics")
+ .setCacheable(true)
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] objects, String[] strings) {
@@ -148,6 +157,8 @@
getSession(true).getNamedQuery(unreadRepliesQuery)
.setParameter("parentDir", directory)
.setParameter("lastLoginDate", lastLoginDate)
+ .setComment("Finding unread replies")
+ .setCacheable(true)
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] objects, String[] strings) {
@@ -165,7 +176,8 @@
public Long findTopicCount(WikiDirectory forum) {
ScrollableResults cursor =
getSession(true).getNamedQuery("forumTopics")
- .setParameter("forum", forum)
+ .setParameter("parentNodeId", forum.getId())
+ .setComment("Counting forum topics")
.scroll();
cursor.last();
Long count = cursor.getRowNumber() + 1l;
@@ -178,15 +190,16 @@
final Map<Long, TopicInfo> topicInfoMap = new LinkedHashMap<Long, TopicInfo>();
getSession(true).getNamedQuery("forumTopics")
- .setParameter("forum", forum)
+ .setParameter("parentNodeId", forum.getId())
+ .setComment("Retrieving forum topics")
.setFirstResult(new Long(firstResult).intValue())
.setMaxResults(new Long(maxResults).intValue())
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
topicInfoMap.put(
- (Long) result[0],
- new TopicInfo( (WikiDocument)result[1], (Integer)result[2])
+ ((WikiDocument)result[0]).getId(),
+ new TopicInfo( (WikiDocument)result[0], (Integer)result[1])
);
return null;
}
@@ -196,6 +209,7 @@
.list();
getSession(true).getNamedQuery("forumTopicsReplies")
.setParameterList("topicIds", topicInfoMap.keySet())
+ .setComment("Retrieving forum topic replies")
.setResultTransformer(
new ResultTransformer() {
public Object transformTuple(Object[] result, String[] strings) {
More information about the jboss-cvs-commits
mailing list