1 16 17 package org.javabb.transaction; 18 19 import java.util.List ; 20 21 import org.javabb.dao.entity.ICategoryDAO; 22 import org.javabb.vh.Stats; 23 import org.javabb.vo.Category; 24 25 30 public class CategoryTransaction extends Transaction { 31 35 private ICategoryDAO categoryDAO; 36 37 private ForumTransaction forumTransaction; 38 39 42 public void setCategoryDAO(ICategoryDAO categoryDAO) { 43 this.categoryDAO = categoryDAO; 44 } 45 46 49 public void setForumTransaction(ForumTransaction forumTransaction) { 50 this.forumTransaction = forumTransaction; 51 } 52 53 57 public CategoryTransaction() throws Exception { 58 } 59 60 65 public List listCategory() throws Exception { 66 List lst = categoryDAO.findAll(new int[] { ICategoryDAO.SORTING_POSITION }); 67 return lst; 68 } 69 70 73 public List findAll() { 74 return categoryDAO.findAll(new int[] { ICategoryDAO.NAME }); 75 } 76 77 public void deleteCategory(Category cat){ 78 categoryDAO.deleteCategory(cat); 79 } 80 81 86 public Category loadCategory(Long idCat){ 87 return categoryDAO.load(idCat); 88 } 89 90 96 public Category obtainCategory(Category category) throws Exception { 97 category = categoryDAO.load(category.getId()); 98 List forumByCats = forumTransaction.findAll(category); 99 category.setForuns(forumByCats); 100 return category; 101 } 102 103 106 public long countAllPosts() { 107 return categoryDAO.countAllPosts(); 108 } 109 110 113 public long countAllUsers() { 114 return categoryDAO.countAllUsers(); 115 } 116 117 120 public long countAllTopics() { 121 return categoryDAO.countAllTopics(); 122 } 123 124 127 public Stats lastRegisteredUser() { 128 return categoryDAO.getStatistics(); 129 } 130 131 public void updateCategory(Long catId, Category cat){ 132 Category category = categoryDAO.load(catId); 133 category.setNameCategory(cat.getNameCategory()); 134 } 135 136 public void insertCategory(Category cat){ 137 Category lastCategory = categoryDAO.getLastCattegoryByOrder(); 138 cat.setCatOrder(lastCategory == null ? new Integer (1) : lastCategory.getCatOrder()); 139 categoryDAO.insertCategory(cat); 140 } 141 142 } 143 | Popular Tags |