예제 #1
0
 @SuppressWarnings("unchecked")
 public static List<Category> getAllCategories() {
   try {
     return (List<Category>)
         TransactionProvider.executeInTransactionWithResult(
             new TransactionalActionWithResult() {
               public Object executeInTransaction() throws SQLException {
                 CategoryExample productCategoryExample = new CategoryExample();
                 productCategoryExample.createCriteria().andDeletedEqualTo(0);
                 productCategoryExample.setOrderByClause("name");
                 List<Category> allCategories =
                     DAOManager.getCategoryDAO().selectCategoryByExample(productCategoryExample);
                 return allCategories;
               }
             });
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return new ArrayList<Category>();
   }
 }
예제 #2
0
 @SuppressWarnings("unchecked")
 public static List<Category> getParentCategories(final int id) {
   try {
     return (List<Category>)
         TransactionProvider.executeInTransactionWithResult(
             new TransactionalActionWithResult() {
               public Object executeInTransaction() throws SQLException {
                 List<Category> result = new ArrayList<Category>();
                 CategoryDAO categoryDAO = DAOManager.getCategoryDAO();
                 Category category = categoryDAO.selectCategoryByPrimaryKey(id);
                 result.add(category);
                 while (category.getParentId() != 0) {
                   category = categoryDAO.selectCategoryByPrimaryKey(category.getParentId());
                   result.add(0, category);
                 }
                 return result;
               }
             });
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     return new ArrayList<Category>();
   }
 }