[jboss-cvs] jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao ...
Christian Bauer
christian at hibernate.org
Thu Nov 15 07:53:32 EST 2007
User: cbauer
Date: 07/11/15 07:53:32
Modified: examples/wiki/src/main/org/jboss/seam/wiki/core/dao
TagDAO.java
Log:
Fixed duplicate results in tag display
Revision Changes Path
1.2 +21 -8 jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/TagDAO.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: TagDAO.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/wiki/src/main/org/jboss/seam/wiki/core/dao/TagDAO.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -b -r1.1 -r1.2
--- TagDAO.java 1 Oct 2007 19:08:05 -0000 1.1
+++ TagDAO.java 15 Nov 2007 12:53:32 -0000 1.2
@@ -6,10 +6,9 @@
import org.jboss.seam.annotations.In;
import org.jboss.seam.log.Log;
import org.jboss.seam.wiki.core.model.Node;
-import org.jboss.seam.wiki.core.model.Document;
-import org.jboss.seam.wiki.plugin.tags.TagsAggregator;
import org.hibernate.Session;
import org.hibernate.Query;
+import org.hibernate.transform.ResultTransformer;
import javax.persistence.EntityManager;
import java.util.List;
@@ -51,13 +50,11 @@
return tagsSortedByCount;
}
- public List<Node> findNodes(Node startNode, Node ignoreNode, String tag) {
+ public List<Node> findNodes(Node startNode, Node ignoreNode, final String tag) {
StringBuilder queryString = new StringBuilder();
- queryString.append("select n1");
-
- queryString.append(" ");
+ queryString.append("select distinct n1").append(" ");
queryString.append("from ").append(startNode.getTreeSuperclassEntityName()).append(" n1, ");
queryString.append(startNode.getTreeSuperclassEntityName()).append(" n2 ");
queryString.append("where n1.nsThread = :thread and n2.nsThread = :thread").append(" ");
@@ -87,9 +84,26 @@
if (tag != null && tag.length()>0) {
nestedSetQuery.setParameter("tag", "%" + tag + "%");
+ // These nodes have the tag _as a substring_ in their comma-separated tags list, we need to find
+ // the real tags, narrowing down the list of nodes by checking each node again.
+ nestedSetQuery.setResultTransformer(
+ new ResultTransformer() {
+ public Object transformTuple(Object[] result, String[] aliases) {
+ Node node = (Node)result[0];
+ if (node.isTagged(tag)) return node;
+ return null;
+ }
+ public List transformList(List list) {
+ List listWithoutNulls = new ArrayList();
+ for (Object o : list) if (o != null) listWithoutNulls.add(o);
+ return listWithoutNulls;
+ }
+ }
+ );
}
return nestedSetQuery.list();
+
}
private Session getSession() {
@@ -123,9 +137,8 @@
TagCount tagCount = (TagCount) o;
- if (!tag.equals(tagCount.tag)) return false;
+ return tag.equals(tagCount.tag);
- return true;
}
public int hashCode() {
More information about the jboss-cvs-commits
mailing list