[jboss-cvs] jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay ...
Shane Bryzak
sbryzak at redhat.com
Tue Aug 21 00:42:31 EDT 2007
User: sbryzak2
Date: 07/08/21 00:42:31
Modified: examples/seambay/src/org/jboss/seam/example/seambay
AuctionSearchAction.java
Log:
Fixed search categories, added more sample data
Revision Changes Path
1.12 +41 -7 jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionSearchAction.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AuctionSearchAction.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionSearchAction.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- AuctionSearchAction.java 3 May 2007 03:23:12 -0000 1.11
+++ AuctionSearchAction.java 21 Aug 2007 04:42:31 -0000 1.12
@@ -5,8 +5,10 @@
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import java.util.Map.Entry;
import javax.persistence.EntityManager;
@@ -61,7 +63,7 @@
if (searchCategory != null)
{
- qry.append(" and a.category = #{searchCategory}");
+ qry.append(" and a.category in (#{subCategories})");
}
auctions = entityManager.createQuery(qry.toString())
@@ -71,12 +73,21 @@
searchCategories.clear();
- for (Object[] result : (List<Object[]>) entityManager.createQuery(
- "select a.category.categoryId, count(a) from Auction a " +
+ StringBuilder catQuery = new StringBuilder();
+ catQuery.append("select a.category.categoryId, count(a) from Auction a " +
"where lower(a.title) like #{searchPattern} " +
- "and a.endDate >= #{currentDatetime} and a.status = 1 " +
- "group by a.category.categoryId")
- .getResultList())
+ "and a.endDate >= #{currentDatetime} and a.status = 1 ");
+
+ if (searchCategory != null)
+ {
+ catQuery.append("and a.category in (#{subCategories}) ");
+ }
+
+ catQuery.append("group by a.category.categoryId");
+
+
+ for (Object[] result : (List<Object[]>) entityManager.createQuery(
+ catQuery.toString()).getResultList())
{
searchCategories.put(entityManager.find(Category.class, result[0]), (Long) result[1]);
}
@@ -143,7 +154,30 @@
queryAuctions();
}
- @Factory(value="searchCategory", scope=ScopeType.EVENT)
+ @Factory(value="subCategories", scope=ScopeType.EVENT)
+ public Set<Category> getSubCategories()
+ {
+ Set<Category> categories = new HashSet<Category>();
+ categories.add(searchCategory);
+ addSubCategories(searchCategory, categories);
+ return categories;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void addSubCategories(Category parent, Set<Category> categories)
+ {
+ List<Category> children = entityManager.createQuery(
+ "from Category where parent = :parent")
+ .setParameter("parent", parent)
+ .getResultList();
+
+ for (Category child : children)
+ {
+ categories.add(child);
+ addSubCategories(child, categories);
+ }
+ }
+
public Category getSearchCategory()
{
return searchCategory;
More information about the jboss-cvs-commits
mailing list