KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > communication > forum > hibernate > ForumServiceContainerImpl


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.services.communication.forum.hibernate;
6
7 import java.util.List JavaDoc ;
8 import net.sf.hibernate.Session;
9 import net.sf.hibernate.Query;
10 import org.exoplatform.services.cache.*;
11 import org.exoplatform.services.communication.forum.ForumEventListener;
12 import org.exoplatform.services.communication.forum.ForumService;
13 import org.exoplatform.services.communication.forum.ForumServiceContainer;
14 import org.exoplatform.services.database.HibernateService;
15 import org.exoplatform.services.idgenerator.IDGeneratorService;
16 import org.exoplatform.commons.utils.ListenerStack;
17 /**
18  * Created by The eXo Platform SARL .
19  * Author : Tuan Nguyen
20  * tuan08@users.sourceforge.net
21  * Date: Jun 14, 2003
22  * Time: 1:12:22 PM
23  */

24 public class ForumServiceContainerImpl implements ForumServiceContainer {
25   private static String JavaDoc[] MAPPING =
26     {
27       "org/exoplatform/services/communication/forum/hibernate/CategoryImpl.hbm.xml" ,
28       "org/exoplatform/services/communication/forum/hibernate/ForumImpl.hbm.xml",
29       "org/exoplatform/services/communication/forum/hibernate/TopicImpl.hbm.xml" ,
30       "org/exoplatform/services/communication/forum/hibernate/PostImpl.hbm.xml",
31       "org/exoplatform/services/communication/forum/hibernate/WatcherImpl.hbm.xml"
32     };
33   
34   public static String JavaDoc queryForumOwners =
35     "select distinct c.owner from org.exoplatform.services.communication.forum.hibernate.CategoryImpl as c" ;
36
37   private HibernateService hservice_ ;
38   private IDGeneratorService idService_ ;
39   private ForumIndexerPluginImpl indexer_ ;
40   private ExoCache forumServices_ ;
41   private ListenerStack eventlisteners_ ;
42   
43   public ForumServiceContainerImpl(HibernateService hservice,
44                                    IDGeneratorService idService,
45                                    CacheService cService,
46                                    ForumIndexerPluginImpl indexer) throws Exception JavaDoc {
47     hservice_ = hservice ;
48     idService_ = idService ;
49     indexer_ = indexer ;
50     eventlisteners_ = new ListenerStack(3) ;
51     hservice.addMappingFiles(MAPPING) ;
52     forumServices_ = cService.getCacheInstance(getClass().getName()) ;
53   }
54
55   public ForumService findForumService(String JavaDoc owner) throws Exception JavaDoc {
56     ForumService service = (ForumService) forumServices_.get(owner) ;
57     if(service == null) {
58       synchronized(forumServices_) {
59         service = createForumService(owner) ;
60         forumServices_.put(owner, service) ;
61       }
62     }
63     return service ;
64   }
65
66   public ForumService createForumService(String JavaDoc owner) throws Exception JavaDoc {
67     ForumServiceImpl service = new ForumServiceImpl(hservice_, indexer_, idService_,
68                                                     eventlisteners_, owner) ;
69     return service ;
70   }
71   
72   public List JavaDoc getForumOwners() throws Exception JavaDoc {
73     Session session = hservice_.openSession();
74     Query q = session.createQuery(queryForumOwners);
75     return q.list() ;
76   }
77   
78   
79   public void addForumEventListener(ForumEventListener listener) {
80     eventlisteners_.add(listener) ;
81   }
82 }
Popular Tags