KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > services > portal > log > impl > PortalLogServiceImpl


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.portal.log.impl;
6
7 import java.util.LinkedList JavaDoc;
8 import org.exoplatform.commons.utils.PageList;
9 import org.exoplatform.container.monitor.ActionData;
10 import org.exoplatform.services.database.DBObjectPageList;
11 import org.exoplatform.services.database.HibernateService;
12 import org.exoplatform.services.database.ObjectQuery;
13 import org.exoplatform.services.idgenerator.IDGeneratorService;
14 import org.exoplatform.services.portal.log.PortalLogService;
15 import org.exoplatform.services.portal.log.Query;
16 import org.exoplatform.services.portal.log.SessionLogData;
17 import com.thoughtworks.xstream.XStream;
18 import com.thoughtworks.xstream.io.xml.XppDriver;
19 /**
20  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
21  * @since Dec 2, 2004
22  * @version $Id$
23  */

24 public class PortalLogServiceImpl implements PortalLogService {
25   static private XStream xstream_ ;
26   static private String JavaDoc[] MAPPING =
27   { "org/exoplatform/services/portal/log/impl/SessionLogDataDescriptionImpl.hbm.xml",
28     "org/exoplatform/services/portal/log/impl/SessionLogDataImpl.hbm.xml" } ;
29   
30   private HibernateService hservice_ ;
31   private IDGeneratorService idService_ ;
32   
33   public PortalLogServiceImpl(HibernateService hservice, IDGeneratorService idService) {
34     hservice.addMappingFiles(MAPPING) ;
35     hservice_ = hservice ;
36     idService_ = idService ;
37   }
38   
39   public SessionLogData getSessionLogData(String JavaDoc id) throws Exception JavaDoc {
40     return (SessionLogData)hservice_.findOne(SessionLogDataImpl.class, id) ;
41   }
42
43   public void saveSessionLogData(SessionLogData data) throws Exception JavaDoc {
44     SessionLogDataImpl impl = (SessionLogDataImpl) data ;
45     if(impl.getId() == null) impl.setId(idService_.generateStringID(impl)) ;
46     hservice_.create(impl) ;
47   }
48
49   public PageList getSessionLogDatas(Query query) throws Exception JavaDoc {
50     ObjectQuery oq = new ObjectQuery(SessionLogDataDescriptionImpl.class);
51     oq.addLIKE("sessionOwner", query.getSessionOwner()) ;
52     oq.addLIKE("remoteUser", query.getRemoteUser()) ;
53     oq.addLIKE("IPAddress", query.getIPAddress()) ;
54     oq.addLIKE("clientName", query.getClientType()) ;
55     oq.addGT("accessTime", query.getFromDate()) ;
56     oq.addLT("accessTime", query.getToDate()) ;
57     if(query.getError() > 0) {
58       oq.addGT("errorCount", Integer.toString(0)) ;
59     }
60     return new DBObjectPageList(hservice_, oq) ;
61   }
62   
63   static public XStream getXStreamInstance() {
64     if (xstream_ == null ) {
65       xstream_ = new XStream(new XppDriver());
66       xstream_.alias("action-data", ActionData.class);
67       xstream_.alias("session-data", LinkedList JavaDoc.class);
68     }
69     return xstream_ ;
70   }
71 }
72
Popular Tags