KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javabb > transaction > CategoryTransaction


1 /*
2  * Copyright 2004 JavaFree.org
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.javabb.transaction;
18
19 import java.util.List JavaDoc;
20
21 import org.javabb.dao.entity.ICategoryDAO;
22 import org.javabb.vh.Stats;
23 import org.javabb.vo.Category;
24
25 /**
26  * $Id: CategoryTransaction.java,v 1.18.8.2 2006/04/17 17:46:49 daltoncamargo Exp $
27  * @author Dalton Camargo - <a HREF="mailto:dalton@javabb.org">dalton@javabb.org </a> <br>
28  * @author Ronald Tetsuo Miura
29  */

30 public class CategoryTransaction extends Transaction {
31     /**
32      * Sobrepõe o atributo dao definido na superclasse Este atributo está sobreposto para poder
33      * adquirir os métodos específicos desta entidade
34      */

35     private ICategoryDAO categoryDAO;
36
37     private ForumTransaction forumTransaction;
38
39     /**
40      * @param categoryDAO the new categoryDAO value
41      */

42     public void setCategoryDAO(ICategoryDAO categoryDAO) {
43         this.categoryDAO = categoryDAO;
44     }
45
46     /**
47      * @param forumTransaction the new forumTransaction value
48      */

49     public void setForumTransaction(ForumTransaction forumTransaction) {
50         this.forumTransaction = forumTransaction;
51     }
52
53     /**
54      * Construtor redefinindo o dao da Superclasse
55      * @throws Exception
56      */

57     public CategoryTransaction() throws Exception JavaDoc {
58     }
59
60     /**
61      * Busca todas categorias de foruns
62      * @return Categorias e seus foruns
63      * @throws Exception
64      */

65     public List JavaDoc listCategory() throws Exception JavaDoc {
66         List JavaDoc lst = categoryDAO.findAll(new int[] { ICategoryDAO.SORTING_POSITION });
67         return lst;
68     }
69
70     /**
71      * @return result
72      */

73     public List JavaDoc findAll() {
74         return categoryDAO.findAll(new int[] { ICategoryDAO.NAME });
75     }
76     
77     public void deleteCategory(Category cat){
78         categoryDAO.deleteCategory(cat);
79     }
80
81     /**
82      * Carrega uma determinada categoria
83      * @param idCat
84      * @return
85      */

86     public Category loadCategory(Long JavaDoc idCat){
87         return categoryDAO.load(idCat);
88     }
89     
90     /**
91      * Carrega uma determinada categoria
92      * @param category
93      * @return Categoria e seus foruns devidamente configurados
94      * @throws Exception
95      */

96     public Category obtainCategory(Category category) throws Exception JavaDoc {
97         category = categoryDAO.load(category.getId());
98         List JavaDoc forumByCats = forumTransaction.findAll(category);
99         category.setForuns(forumByCats);
100         return category;
101     }
102
103     /**
104      * @return post count
105      */

106     public long countAllPosts() {
107         return categoryDAO.countAllPosts();
108     }
109
110     /**
111      * @return user count
112      */

113     public long countAllUsers() {
114         return categoryDAO.countAllUsers();
115     }
116
117     /**
118      * @return topic count
119      */

120     public long countAllTopics() {
121         return categoryDAO.countAllTopics();
122     }
123
124     /**
125      * @return
126      */

127     public Stats lastRegisteredUser() {
128         return categoryDAO.getStatistics();
129     }
130
131     public void updateCategory(Long JavaDoc 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 JavaDoc(1) : lastCategory.getCatOrder());
139         categoryDAO.insertCategory(cat);
140      }
141     
142 }
143
Popular Tags