[jboss-cvs] jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay ...

Shane Bryzak sbryzak at redhat.com
Wed May 2 23:23:12 EDT 2007


  User: sbryzak2
  Date: 07/05/02 23:23:12

  Modified:    examples/seambay/src/org/jboss/seam/example/seambay    
                        AuctionSearchAction.java AuctionService.java
                        Category.java CategoryAction.java
  Log:
  added buy page, cleaned up categories, hierarchical categories
  
  Revision  Changes    Path
  1.11      +23 -8     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.10
  retrieving revision 1.11
  diff -u -b -r1.10 -r1.11
  --- AuctionSearchAction.java	23 Apr 2007 11:31:04 -0000	1.10
  +++ AuctionSearchAction.java	3 May 2007 03:23:12 -0000	1.11
  @@ -33,6 +33,7 @@
      
      private String searchTerm;
      private Category searchCategory;
  +   private boolean titleAndDescription;
      
      @DataModel
      private List<Auction> auctions;
  @@ -45,21 +46,25 @@
      @SuppressWarnings("unchecked")
      public void queryAuctions()
      {
  -      String qry = null;
  +      StringBuilder qry = new StringBuilder();
         
  -      if (searchCategory == null)
  +      qry.append("from Auction a where a.status = 1 and endDate >= #{currentDatetime}");
  +      
  +      if (titleAndDescription)
         {
  -         qry = "from Auction a where lower(title) like #{searchPattern} " +
  -               "and a.status = 1 and a.endDate >= #{currentDatetime}"; 
  +         qry.append(" and (lower(title) like #{searchPattern} or lower(description) like #{searchPattern})");
         }
         else
         {
  -         qry = "from Auction a where lower(title) like #{searchPattern} " +
  -               "and a.category = #{searchCategory} and a.status = 1 " +
  -               "and a.endDate >= #{currentDatetime}";
  +         qry.append(" and lower(title) like #{searchPattern}");
         }
         
  -      auctions = entityManager.createQuery(qry)
  +      if (searchCategory != null)
  +      {
  +         qry.append(" and a.category = #{searchCategory}");
  +      }
  +            
  +      auctions = entityManager.createQuery(qry.toString())
               .setMaxResults(pageSize)
               .setFirstResult( page * pageSize )
               .getResultList();      
  @@ -163,4 +168,14 @@
      {
         this.searchCategory = entityManager.find(Category.class, categoryId);
      }
  +   
  +   public boolean isTitleAndDescription()
  +   {
  +      return titleAndDescription;
  +   }
  +   
  +   public void setTitleAndDescription(boolean value)
  +   {
  +      this.titleAndDescription = value;
  +   }
   }
  
  
  
  1.10      +4 -2      jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionService.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: AuctionService.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/AuctionService.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- AuctionService.java	1 May 2007 01:31:48 -0000	1.9
  +++ AuctionService.java	3 May 2007 03:23:12 -0000	1.10
  @@ -1,5 +1,7 @@
   package org.jboss.seam.example.seambay;
   
  +import java.util.List;
  +
   import javax.ejb.Stateless;
   import javax.jws.WebMethod;
   import javax.jws.WebService;
  @@ -34,9 +36,9 @@
         CategoryAction catAction = (CategoryAction) Component.getInstance(
               CategoryAction.class, true);
         
  -      catAction.loadCategories();
  +      List<Category> categories = catAction.getAllCategories();
         
  -      return catAction.getCategories().toArray(new Category[catAction.getCategories().size()]);
  +      return categories.toArray(new Category[categories.size()]);
      }
      
      @WebMethod
  
  
  
  1.2       +16 -1     jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Category.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Category.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/Category.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -b -r1.1 -r1.2
  --- Category.java	22 Mar 2007 15:02:47 -0000	1.1
  +++ Category.java	3 May 2007 03:23:12 -0000	1.2
  @@ -4,14 +4,17 @@
   
   import javax.persistence.Entity;
   import javax.persistence.Id;
  +import javax.persistence.JoinColumn;
  +import javax.persistence.ManyToOne;
   
   @Entity
   public class Category implements Serializable
   {
  -   private static final long serialVersionUID = 1L;
  +   private static final long serialVersionUID = 411989568594034566L;
      
      private Integer categoryId;
      private String name;
  +   private Category parent;
      
      @Id
      public Integer getCategoryId()
  @@ -33,4 +36,16 @@
      {
         this.name = name;
      }
  +   
  +   @ManyToOne
  +   @JoinColumn(name = "PARENT_CATEGORY_ID")
  +   public Category getParent()
  +   {
  +      return parent;
  +   }
  +   
  +   public void setParent(Category parent)
  +   {
  +      this.parent = parent;
  +   }
   }
  
  
  
  1.3       +60 -2     jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/CategoryAction.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CategoryAction.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/seambay/src/org/jboss/seam/example/seambay/CategoryAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- CategoryAction.java	29 Mar 2007 13:54:59 -0000	1.2
  +++ CategoryAction.java	3 May 2007 03:23:12 -0000	1.3
  @@ -1,5 +1,6 @@
   package org.jboss.seam.example.seambay;
   
  +import java.util.ArrayList;
   import java.util.List;
   
   import javax.persistence.EntityManager;
  @@ -18,11 +19,18 @@
      @Out(required = false)
      private List<Category> categories;
      
  +   @Out(required = false)
  +   private List<Category> leftCategories;
  +   
  +   @Out(required = false)
  +   private List<Category> rightCategories;
  +   
      @SuppressWarnings("unchecked")
      @Factory("categories")
      public void loadCategories()
      {
  -      categories = entityManager.createQuery("from Category order by name")
  +      categories = entityManager.createQuery(
  +            "from Category where parent = null order by name")
                      .getResultList();
      }
      
  @@ -30,4 +38,54 @@
      {
         return categories;
      }
  +   
  +   @SuppressWarnings("unchecked")
  +   public List<Category> getAllCategories()
  +   {
  +      return entityManager.createQuery("from Category").getResultList();
  +   }
  +   
  +   private void loadLeftAndRight()
  +   {
  +      if (categories == null) loadCategories();
  +      
  +      boolean loadLeft = leftCategories == null;
  +      boolean loadRight = rightCategories == null;
  +
  +      if (loadLeft) leftCategories = new ArrayList<Category>();
  +      if (loadRight) rightCategories = new ArrayList<Category>();
  +      
  +      for (int i = 0; i < categories.size(); i++)
  +      {
  +         if (i <= (categories.size() / 2))
  +         {
  +            if (loadLeft) leftCategories.add(categories.get(i));
  +         }
  +         else if (loadRight)
  +         {
  +            rightCategories.add(categories.get(i));
  +         }
  +      }
  +   }
  +   
  +   @Factory("leftCategories")
  +   public void loadLeftCategories()
  +   {
  +      if (leftCategories == null) loadLeftAndRight();
  +   }
  +   
  +   @Factory("rightCategories")
  +   public void loadRightCategories()
  +   {
  +      if (rightCategories == null) loadLeftAndRight();
  +   }
  +   
  +   @SuppressWarnings("unchecked")
  +   public List<Category> getSubCategories(Category parent)
  +   {
  +      return entityManager.createQuery(
  +            "from Category where parent = :parent")
  +            .setParameter("parent", parent)
  +            .getResultList();
  +   }
   }
  
  
  



More information about the jboss-cvs-commits mailing list