KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > db > DAOFactory


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/db/DAOFactory.java,v 1.27 2006/04/14 17:05:26 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.27 $
5  * $Date: 2006/04/14 17:05:26 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Minh Nguyen
39  */

40 package com.mvnforum.db;
41
42 import com.mvnforum.*;
43 import com.mvnforum.db.jdbc.*;
44 import net.myvietnam.mvncore.MVNCoreConfig;
45 import org.apache.commons.logging.Log;
46 import org.apache.commons.logging.LogFactory;
47
48 /**
49  * Instance that returns the right implementation for the different
50  * DAO implementation such as JDBC or Hibernate.
51  *
52  * @author Minh Nguyen
53  * @version $Revision: 1.27 $
54  */

55 public class DAOFactory {
56
57     private static Log log = LogFactory.getLog(DAOFactory.class);
58
59     private DAOFactory() {}
60
61     private static MemberDAO localMemberDAO = null;
62     private static MemberDAO memberDAO = null;
63     private static MessageFolderDAO messageFolderDAO = null;
64     private static MemberForumDAO memberForumDAO = null;
65     private static MemberGroupDAO memberGroupDAO = null;
66     private static MemberPermissionDAO memberPermissionDAO = null;
67     private static CategoryDAO categoryDAO = null;
68     private static ForumDAO forumDAO = null;
69     private static FavoriteThreadDAO favoriteThreadDAO = null;
70     private static GroupForumDAO groupForumDAO = null;
71     private static GroupPermissionDAO groupPermissionDAO = null;
72     private static GroupsDAO groupsDAO = null;
73     private static AttachmentDAO attachmentDAO = null;
74     private static ThreadDAO threadDAO = null;
75     private static PostDAO postDAO = null;
76     private static RankDAO rankDAO = null;
77     private static WatchDAO watchDAO = null;
78     private static MessageDAO messageDAO = null;
79     private static MessageStatisticsDAO messageStatisticsDAO = null;
80     private static PmAttachmentDAO pmAttachmentDAO = null;
81     private static PmAttachMessageDAO pmAttachMessageDAO = null;
82
83     private static CompanyDAO companyDAO = null;
84     private static MemberTutorDAO memberTutorDAO = null;
85     private static MemberCompanyDAO memberCompanyDAO = null;
86
87     public static MemberDAO getMemberDAO() {
88         return memberDAO;
89     }
90
91     public static MemberDAO getLocalMemberDAO() {
92         return localMemberDAO;
93     }
94
95     public static MessageFolderDAO getMessageFolderDAO() {
96         return messageFolderDAO;
97     }
98
99     public static MemberForumDAO getMemberForumDAO() {
100         return memberForumDAO;
101     }
102
103     public static MemberGroupDAO getMemberGroupDAO() {
104         return memberGroupDAO;
105     }
106
107     public static MemberPermissionDAO getMemberPermissionDAO() {
108         return memberPermissionDAO;
109     }
110
111     public static CategoryDAO getCategoryDAO() {
112         return categoryDAO;
113     }
114
115     public static ForumDAO getForumDAO() {
116         return forumDAO;
117     }
118
119     public static FavoriteThreadDAO getFavoriteThreadDAO() {
120         return favoriteThreadDAO;
121     }
122
123     public static GroupForumDAO getGroupForumDAO() {
124         return groupForumDAO;
125     }
126
127     public static GroupPermissionDAO getGroupPermissionDAO() {
128         return groupPermissionDAO;
129     }
130
131     public static GroupsDAO getGroupsDAO() {
132         return groupsDAO;
133     }
134
135     public static AttachmentDAO getAttachmentDAO() {
136         return attachmentDAO;
137     }
138
139     public static ThreadDAO getThreadDAO() {
140         return threadDAO;
141     }
142
143     public static PostDAO getPostDAO() {
144         return postDAO;
145     }
146
147     public static RankDAO getRankDAO() {
148         return rankDAO;
149     }
150
151     public static WatchDAO getWatchDAO() {
152         return watchDAO;
153     }
154
155     public static MessageDAO getMessageDAO() {
156         return messageDAO;
157     }
158
159     public static MessageStatisticsDAO getMessageStatisticsDAO() {
160         return messageStatisticsDAO;
161     }
162
163     public static PmAttachmentDAO getPmAttachmentDAO() {
164         return pmAttachmentDAO;
165     }
166
167     public static PmAttachMessageDAO getPmAttachMessageDAO() {
168         return pmAttachMessageDAO;
169     }
170
171     public static CompanyDAO getCompanyDAO() {
172         return companyDAO;
173     }
174
175     public static MemberCompanyDAO getMemberCompanyDAO() {
176         return memberCompanyDAO;
177     }
178
179     public static MemberTutorDAO getMemberTutorDAO() {
180         return memberTutorDAO;
181     }
182
183     static {
184         boolean enablePortlet = MVNForumConfig.getEnablePortlet();
185
186         //boolean dontUseCustomizedMemberClass = false;
187
String JavaDoc memberImpl = "";
188
189         //@todo assert here
190
//assert(MVNForumFactoryConfig.getMemberManagerClassName() != null);
191

192         if (MVNForumFactoryConfig.getMemberManagerClassName().length() > 0) {// we can be sure is not null
193
memberImpl = MVNForumFactoryConfig.getMemberManagerClassName();
194         } else if (enablePortlet) {
195             memberImpl = Portal.getMemberImplementation(MVNCoreConfig.getPortalType());
196         } else {
197             log.error("Error: not config <member_implementation> properly in mvnforum.xml. Try loading the default implementation for Member.");
198
199             memberImpl = "com.mvnforum.db.jdbc.MemberDAOImplJDBC";
200             log.info("Try loading default MemberDAO = " + memberImpl);
201         }
202
203         try {
204             Class JavaDoc c = Class.forName(memberImpl);
205             memberDAO = (MemberDAO) c.newInstance();
206             log.info("memberDAO = " + memberDAO);
207         } catch (Exception JavaDoc e) {
208             log.error("Error returning the DAOFactory.", e);
209             log.warn("Cannot init MemberDAO, about to use the default implementation.");
210
211             memberDAO = new MemberDAOImplJDBC();
212         }
213
214         localMemberDAO = new MemberDAOImplJDBC();
215
216         messageFolderDAO = new MessageFolderDAOImplJDBC();
217
218         memberForumDAO = new MemberForumDAOImplJDBC();
219
220         memberGroupDAO = new MemberGroupDAOImplJDBC();
221
222         memberPermissionDAO = new MemberPermissionDAOImplJDBC();
223
224         categoryDAO = new CategoryDAOImplJDBC();
225
226         forumDAO = new ForumDAOImplJDBC();
227
228         favoriteThreadDAO = new FavoriteThreadDAOImplJDBC();
229
230         groupForumDAO = new GroupForumDAOImplJDBC();
231
232         groupPermissionDAO = new GroupPermissionDAOImplJDBC();
233
234         groupsDAO = new GroupsDAOImplJDBC();
235
236         attachmentDAO = new AttachmentDAOImplJDBC();
237
238         threadDAO = new ThreadDAOImplJDBC();
239
240         postDAO = new PostDAOImplJDBC();
241
242         rankDAO = new RankDAOImplJDBC();
243
244         watchDAO = new WatchDAOImplJDBC();
245
246         messageDAO = new MessageDAOImplJDBC();
247
248         messageStatisticsDAO = new MessageStatisticsDAOImplJDBC();
249
250         pmAttachmentDAO = new PmAttachmentDAOImplJDBC();
251
252         pmAttachMessageDAO = new PmAttachMessageDAOImplJDBC();
253
254         memberTutorDAO = new MemberTutorDAOImplJDBC();
255
256         companyDAO = new CompanyDAOImplJDBC();
257
258         memberCompanyDAO = new MemberCompanyDAOImplJDBC();
259
260     }
261
262 }
263
Popular Tags