User: janaudy 
  Date: 00/05/22 09:58:24

  Modified:    webstore/src/org/jboss/zol/webstore/ejbs/product
                        ProductEntityBean.java
  Log:
  
  
  Revision  Changes    Path
  1.2       +57 -1     
zola/webstore/src/org/jboss/zol/webstore/ejbs/product/ProductEntityBean.java
  
  Index: ProductEntityBean.java
  ===================================================================
  RCS file: 
/products/cvs/ejboss/zola/webstore/src/org/jboss/zol/webstore/ejbs/product/ProductEntityBean.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProductEntityBean.java    2000/05/10 14:36:20     1.1
  +++ ProductEntityBean.java    2000/05/22 16:58:24     1.2
  @@ -16,7 +16,9 @@
   import java.util.Collection;
   import java.util.LinkedList;
   
  -public class ProductEntityBean implements EntityBean {
  +import org.jboss.zol.webstore.ejbs.common.GenericEntityBean;
  +
  +public class ProductEntityBean extends GenericEntityBean implements EntityBean {
     /**
      * ID, pk of this product
      */
  @@ -143,7 +145,50 @@
       
       return _productPK;
     }
  +  
  +  /**
  +    * Find products by category
  +    * @param cat The category
  +    * @return a collection of this products
  +    */
  +   public Collection ejbFindProductsByCategory(String category)
  +     throws ObjectNotFoundException, RemoteException {
  +     log("ejbFindProductsByPrice ("+category+")");
       
  +    PreparedStatement ps = null;
  +    LinkedList list = new LinkedList();
  +
  +    try {
  +      String sql = "SELECT "+ID+" FROM "+TABLE_NAME+" WHERE "+
  +      CATEGORY+" = ?";
  +      log(sql);
  +      log("Connection is: "+connection);
  +      ps = connection.prepareStatement(sql);
  +      log("After prepared statement ...."+connection+" ps:"+ps);
  +      ps.setString(1, category);
  +      ps.executeQuery();
  +      ResultSet rs = ps.getResultSet();
  +      while(rs.next())
  +        list.add(new ProductEntityPK(rs.getString(ID)));
  +      if (list.size() == 0) {
  +        String error = "ejbFindByPrimaryKey: ProductEntityBean (" + category + ") 
not found";
  +        log(error);
  +        throw new ObjectNotFoundException (error);
  +       }
  +    } catch (SQLException sqe) {
  +      log("SQLException:  " + sqe);
  +      throw new EJBException (sqe);
  +    } finally {
  +      try {
  +             ps.close();
  +      } catch (Exception e) {e.printStackTrace();}
  +    }
  +
  +    log("ejbFindByPrimaryKey (" + category + ") found");
  +    
  +    return list;     
  +   }
  +    
     /**
      * Return all products that have their price between low and high
      * @param low
  @@ -249,6 +294,7 @@
       this.category = newCategory;
       log(toString(), "setCategory",
                   new Object[] {newCategory}, null);
  +    this.modified = true;
     }
       
     /**
  @@ -269,6 +315,7 @@
       this.description = newDescription;
       log(toString(), "setDescription",
                   new Object[] {newDescription}, null);        
  +    this.modified = true;
     }
         
     /**
  @@ -289,6 +336,7 @@
       this.price = newPrice;
       log(toString(), "setPrice",
                   new Object[] {new Double(newPrice)}, null);  
  +    this.modified = true;
     }
         
     /**
  @@ -309,6 +357,7 @@
       this.imageURL = newImageURL;
       log(toString(), "setImageURL",
                   new Object[] {newImageURL}, null);           
  +    this.modified = true;
     }
         
     /**
  @@ -450,12 +499,17 @@
                ps.close();
         } catch (Exception e) {e.printStackTrace();}
       }
  +    
  +    this.modified = false;
     }
   
     /**
      * Store callback
      */
     public void ejbStore() throws RemoteException {
  +    if (this.modified == false)
  +      return;
  +      
       log(toString(), "ejbStore",
                   new Object[] {}, null);
                   
  @@ -488,6 +542,8 @@
                ps.close();
         } catch (Exception e) {e.printStackTrace();}
       }
  +    
  +    this.modified = false;
     }
     
     /**
  
  
  

Reply via email to