001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/db/DAOFactory.java,v 1.41 2008/01/21 11:31:34 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.41 $
005: * $Date: 2008/01/21 11:31:34 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Minh Nguyen
039: */
040: package com.mvnforum.db;
041:
042: import net.myvietnam.mvncore.MVNCoreConfig;
043: import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
044:
045: import org.apache.commons.logging.Log;
046: import org.apache.commons.logging.LogFactory;
047:
048: import com.mvnforum.*;
049: import com.mvnforum.db.jdbc.*;
050:
051: /**
052: * Instance that returns the right implementation for the different
053: * DAO implementation such as JDBC or Hibernate.
054: *
055: * @author Minh Nguyen
056: * @version $Revision: 1.41 $
057: */
058: public class DAOFactory {
059:
060: private static Log log = LogFactory.getLog(DAOFactory.class);
061:
062: private DAOFactory() {
063: }
064:
065: private static MemberDAO localMemberDAO = null;
066: private static MemberDAO memberDAO = null;
067: private static MessageFolderDAO messageFolderDAO = null;
068: private static MemberForumDAO memberForumDAO = null;
069: private static MemberGroupDAO memberGroupDAO = null;
070: private static MemberPermissionDAO memberPermissionDAO = null;
071: private static CategoryDAO categoryDAO = null;
072: private static ForumDAO forumDAO = null;
073: private static FavoriteThreadDAO favoriteThreadDAO = null;
074: private static GroupForumDAO groupForumDAO = null;
075: private static GroupPermissionDAO groupPermissionDAO = null;
076: private static GroupsDAO groupsDAO = null;
077: private static AttachmentDAO attachmentDAO = null;
078: private static ThreadDAO threadDAO = null;
079: private static PostDAO postDAO = null;
080: private static RankDAO rankDAO = null;
081: private static WatchDAO watchDAO = null;
082: private static MessageDAO messageDAO = null;
083: private static MessageStatisticsDAO messageStatisticsDAO = null;
084: private static PmAttachmentDAO pmAttachmentDAO = null;
085: private static PmAttachMessageDAO pmAttachMessageDAO = null;
086:
087: public static MemberDAO getMemberDAO() {
088: return memberDAO;
089: }
090:
091: public static MemberDAO getLocalMemberDAO() {
092: return localMemberDAO;
093: }
094:
095: public static MessageFolderDAO getMessageFolderDAO() {
096: return messageFolderDAO;
097: }
098:
099: 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: static {
172:
173: // please note that localMemberDAO should be instantiated first the memberDAO
174: // because the memberDAO can refer to the localMemberDAO
175: localMemberDAO = new MemberDAOImplJDBC();
176:
177: messageFolderDAO = new MessageFolderDAOImplJDBC();
178:
179: memberForumDAO = new MemberForumDAOImplJDBC();
180:
181: memberGroupDAO = new MemberGroupDAOImplJDBC();
182:
183: memberPermissionDAO = new MemberPermissionDAOImplJDBC();
184:
185: categoryDAO = new CategoryDAOImplJDBC();
186:
187: forumDAO = new ForumDAOImplJDBC();
188:
189: favoriteThreadDAO = new FavoriteThreadDAOImplJDBC();
190:
191: groupForumDAO = new GroupForumDAOImplJDBC();
192:
193: groupPermissionDAO = new GroupPermissionDAOImplJDBC();
194:
195: groupsDAO = new GroupsDAOImplJDBC();
196:
197: attachmentDAO = new AttachmentDAOImplJDBC();
198:
199: threadDAO = new ThreadDAOImplJDBC();
200:
201: postDAO = new PostDAOImplJDBC();
202:
203: rankDAO = new RankDAOImplJDBC();
204:
205: watchDAO = new WatchDAOImplJDBC();
206:
207: messageDAO = new MessageDAOImplJDBC();
208:
209: messageStatisticsDAO = new MessageStatisticsDAOImplJDBC();
210:
211: pmAttachmentDAO = new PmAttachmentDAOImplJDBC();
212:
213: pmAttachMessageDAO = new PmAttachMessageDAOImplJDBC();
214:
215: boolean enablePortlet = MvnCoreServiceFactory
216: .getMvnCoreService().getEnvironmentService()
217: .isPortlet();
218:
219: //boolean dontUseCustomizedMemberClass = false;
220: String memberImpl = "";
221:
222: //@todo assert here
223: //assert(MVNForumFactoryConfig.getMemberManagerClassName() != null);
224:
225: if (MVNForumFactoryConfig.getMemberManagerClassName().length() > 0) {// we can be sure is not null
226: memberImpl = MVNForumFactoryConfig
227: .getMemberManagerClassName();
228: } else if (enablePortlet) {
229: memberImpl = Portal.getMemberImplementation(MVNCoreConfig
230: .getPortalType());
231: } else {
232: log
233: .error("Error: not config <member_implementation> properly in mvnforum.xml. Try loading the default implementation for Member.");
234:
235: memberImpl = "com.mvnforum.db.jdbc.MemberDAOImplJDBC";
236: log.info("Try loading default MemberDAO = " + memberImpl);
237: }
238:
239: try {
240: Class c = Class.forName(memberImpl);
241: memberDAO = (MemberDAO) c.newInstance();
242: log.info("memberDAO = " + memberDAO);
243: } catch (Exception e) {
244: log.error("Error returning the DAOFactory.", e);
245: log.warn("Cannot init MemberDAO [" + memberImpl
246: + "], about to use the default implementation.");
247:
248: memberDAO = new MemberDAOImplJDBC();
249: }
250:
251: }
252:
253: }
|