1 5 package org.exoplatform.services.communication.forum.hibernate; 6 7 import java.util.List ; 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 24 public class ForumServiceContainerImpl implements ForumServiceContainer { 25 private static String [] 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 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 { 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 owner) throws Exception { 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 owner) throws Exception { 67 ForumServiceImpl service = new ForumServiceImpl(hservice_, indexer_, idService_, 68 eventlisteners_, owner) ; 69 return service ; 70 } 71 72 public List getForumOwners() throws Exception { 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 |