@Override public List<Product> searchByCategory( Integer category, int pageNumber, int pageSize, boolean cascade) throws Exception { List<Product> find = null; if (category == null) { find = productDao.find(pageNumber, pageSize, null, null, null, null, null, null, null, false); } else { find = productDao.find( pageNumber, pageSize, null, null, new String[] {"category"}, new Object[] {category}, null, null, null, false); } if (cascade && find != null) { for (Product product : find) { Article article = articleDao.findById(product.getParentId()); BeanUtils.copyProperties(product, article); } } return find; }
@Override public Product get(String id, boolean cascade) throws Exception { Product product = productDao.findById(id); if (cascade) { Article article = articleDao.findById(product.getParentId()); BeanUtils.copyProperties(product, article); } return product; }
@Override public boolean delete(String id) { Product findById = null; try { findById = productDao.findById(id); } catch (Exception e) { e.printStackTrace(); } if (findById == null) return false; try { productDao.delete(findById); Article article = articleDao.findById(findById.getParentId()); articleDao.delete(article); } catch (Exception e) { e.printStackTrace(); return false; } return true; }