public
class ItemManager { private ItemDao itemDao; publicvoid setItemDao(ItemDao itemDao){ this.itemDao = itemDao;} public Bid loadItemById(Long id){ itemDao.loadItemById(id); } publicCollection listAllItems(){ return itemDao.findAll(); } public Bid placeBid(Item item, User bidder, MonetaryAmount bidAmount, Bid currentMaxBid, Bid currentMinBid)throws BusinessException { if(currentMaxBid != null && currentMaxBid.getAmount().compareTo(bidAmount) > 0){ throw new BusinessException("Bid too low."); } // Auction is active if( !state.equals(ItemState.ACTIVE)) throw new BusinessException("Auction is not active yet."); // Auction still valid if( item.getEndDate().before(newDate())) throw new BusinessException("Can't place new bid, auction already ended."); // Create new Bid Bid newBid = new Bid(bidAmount, item, bidder); // Place bid for this Item item.getBids().add(newBid); itemDao.update(item); // 调用DAO完成持久化操作 return newBid; } }
|