⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookcontrollerbean.java~1~

📁 一个java
💻 JAVA~1~
📖 第 1 页 / 共 2 页
字号:
            books =bookHome.findByCondition(condition);
            if (books.isEmpty())
                throw new ObjectNotFoundException();
        } catch (Exception ex) {
             throw new ObjectNotFoundException();
        }

        ArrayList bookValues = new ArrayList();

        Iterator i = books.iterator();
        while (i.hasNext()) {
            Book book = (Book)i.next();
            BookDetails bookValue=book.getDetails();
            bookValues.add(bookValue);
        }
        return bookValues;

      }//getRecommendedBooks

    public ArrayList getBargainBooks() throws ObjectNotFoundException
     {

        System.out.println("BookControllerBean getBargainBooks");

        Collection books;

        try
        {
            //特价书的条件:出版日期一年以前&评定等级为1以下&库存数量在25以上(初始库存数量为50)
            //rank: 1 一般 2 较好 3 好 4 特好
            java.util.Date utilDate=new java.util.Date();
            java.sql.Date date=new java.sql.Date(utilDate.getTime()-365*(1000 * 60 * 60 * 24));
            String condition="publishDate <="+"'"+DateHelper.format(date,"yyyy-MM-dd HH:mm:ss")+"'"+
                             " and rank<=1 and stockNum<=25";
            books =bookHome.findByCondition(condition);
            if (books.isEmpty())
                throw new ObjectNotFoundException();
        } catch (Exception ex) {
             throw new ObjectNotFoundException();
        }

        ArrayList bookValues = new ArrayList();

        Iterator i = books.iterator();
        while (i.hasNext()) {
            Book book = (Book)i.next();
            BookDetails bookValue=book.getDetails();
            bookValues.add(bookValue);
        }
        return bookValues;
      }//getBargainBooks

      public ArrayList getNewBooks() throws ObjectNotFoundException
      {

         System.out.println("BookControllerBean getNewBooks");

         Collection books;

         try
         {
             //新书的条件:出版日期在近一个月内
             java.util.Date utilDate=new java.util.Date();
             java.sql.Date date=new java.sql.Date(utilDate.getTime()-30*(1000 * 60 * 60 * 24));
             String condition="publishDate >="+"'"+DateHelper.format(date,"yyyy-MM-dd HH:mm:ss")+"'";

             books =bookHome.findByCondition(condition);
             if (books.isEmpty())
                 throw new ObjectNotFoundException();
         } catch (Exception ex) {
              throw new ObjectNotFoundException();
         }

         ArrayList bookValues = new ArrayList();

         Iterator i = books.iterator();
         while (i.hasNext()) {
             Book book = (Book)i.next();
             BookDetails bookValue=book.getDetails();
             bookValues.add(bookValue);
         }
         return bookValues;

       }//getNewBooks

       //缺货
       public ArrayList getBooksInShort() throws ObjectNotFoundException
          {

             System.out.println("BookControllerBean getBooksInShort");

             Collection books;

             try
             {
                 //库存数量为负值时,即为缺货
                 String condition="stockNum < 0";

                 books =bookHome.findByCondition(condition);
                 if (books.isEmpty())
                     throw new ObjectNotFoundException();
             } catch (Exception ex) {
                  throw new ObjectNotFoundException();
             }

             ArrayList bookValues = new ArrayList();

             Iterator i = books.iterator();
             while (i.hasNext()) {
                 Book book = (Book)i.next();
                 BookDetails bookValue=book.getDetails();
                 bookValues.add(bookValue);
             }
             return bookValues;

           }//getBooksInShort
    //须进图书
    public ArrayList getBooksNeeded() throws ObjectNotFoundException
          {

             System.out.println("BookControllerBean getBooksNeeded");

             Collection books;

             try
             {
                 //库存数量少于10,即须进货
                 String condition="stockNum < 10";

                 books =bookHome.findByCondition(condition);
                 if (books.isEmpty())
                     throw new ObjectNotFoundException();
             } catch (Exception ex) {
                  throw new ObjectNotFoundException();
             }

             ArrayList bookValues = new ArrayList();

             Iterator i = books.iterator();
             while (i.hasNext()) {
                 Book book = (Book)i.next();
                 BookDetails bookValue=book.getDetails();
                 bookValues.add(bookValue);
             }
             return bookValues;

           }//getBooksNeeded
      public BookDetails getBookValue(String bookId)
        {
          System.out.println("bookControllerBean getbookValue");
          try
               {
                   book = bookHome.findByPrimaryKey(bookId);
                   this.bookID = bookId;
               } catch (Exception ex)
               {
                   return null;
               }
               return book.getDetails();
        }//getBookValue

        public ArrayList getTopTenPreMonth() throws ObjectNotFoundException
          {

             System.out.println("BookControllerBean getTopTenPreMonth");

             Collection books;

             try
             {
                 //按上月销售数量降序排列
                 String condition="order by preMonthSaleNum desc";

                 books =bookHome.findTopTen(condition);
                 if (books.isEmpty())
                     throw new ObjectNotFoundException();
             } catch (Exception ex) {
                  throw new ObjectNotFoundException();
             }

             ArrayList bookValues = new ArrayList();

             Iterator i = books.iterator();
             while (i.hasNext()) {
                 Book book = (Book)i.next();
                 BookDetails bookValue=book.getDetails();
                 bookValues.add(bookValue);
             }
             return bookValues;

           }//getTopTenPreMonth

           public ArrayList getTopTenSaleNum() throws ObjectNotFoundException
               {

                  System.out.println("BookControllerBean getTopTenSaleNum");

                  Collection books;

                  try
                  {
                      //按上月销售数量降序排列
                      String condition="order by SaleNum desc";

                      books =bookHome.findTopTen(condition);
                      if (books.isEmpty())
                          throw new ObjectNotFoundException();
                  } catch (Exception ex) {
                       throw new ObjectNotFoundException();
                  }

                  ArrayList bookValues = new ArrayList();

                  Iterator i = books.iterator();
                  while (i.hasNext()) {
                      Book book = (Book)i.next();
                      BookDetails bookValue=book.getDetails();
                      bookValues.add(bookValue);
                  }
                  return bookValues;

                }//getTopTenSaleNum





/******************************ejb methods*********************************/

  public void ejbCreate() throws CreateException {
    System.out.println("BookControllerBean ejbCreate");

        try {
            //创建下一层的引导接口
            bookHome=EJBGetter.getBookHome();

        } catch (Exception ex) {
             System.out.println("BookControllerBean catch");
             throw new EJBException("ejbCreate: " +
                 ex.getMessage());
        }

        book = null;
        bookID = null;
  }//ejbCreate

  public void ejbRemove() {
    /**@todo Complete this method*/
  }
  public void ejbActivate() {
    /**@todo Complete this method*/
  }
  public void ejbPassivate() {
    /**@todo Complete this method*/
  }
  public void setSessionContext(SessionContext sessionContext) {
    this.sessionContext = sessionContext;
  }
  /******************************util methods****************************/
  private boolean isBookExist(String bookId) {

        // If a business method has been invoked with
        // a different BookId, then update the
        // BookId and Book variables.
        // Return null if the Book is not found.

        System.out.println("BookControllerBean isBookExist");

        if (bookId.equals(this.bookID) == false)
        {
            try
            {
                book = bookHome.findByPrimaryKey(bookId);
                this.bookID = bookId;
            } catch (Exception ex)
            {
                return false;
            }
        } // if
        return true;

    }
 // isBookExist

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -