1
19
20 package com.liferay.portlet.ratings.service.impl;
21
22 import com.liferay.portal.PortalException;
23 import com.liferay.portal.SystemException;
24 import com.liferay.portal.kernel.log.Log;
25 import com.liferay.portal.kernel.log.LogFactoryUtil;
26 import com.liferay.portal.util.PortalUtil;
27 import com.liferay.portlet.ratings.NoSuchStatsException;
28 import com.liferay.portlet.ratings.model.RatingsStats;
29 import com.liferay.portlet.ratings.service.base.RatingsStatsLocalServiceBaseImpl;
30
31
38 public class RatingsStatsLocalServiceImpl
39 extends RatingsStatsLocalServiceBaseImpl {
40
41 public void deleteStats(String className, long classPK)
42 throws SystemException {
43
44 long classNameId = PortalUtil.getClassNameId(className);
45
46 try {
47 ratingsStatsPersistence.removeByC_C(classNameId, classPK);
48 }
49 catch (NoSuchStatsException nsse) {
50 _log.warn(nsse);
51 }
52
53 ratingsEntryPersistence.removeByC_C(classNameId, classPK);
54 }
55
56 public RatingsStats getStats(long statsId)
57 throws PortalException, SystemException {
58
59 return ratingsStatsPersistence.findByPrimaryKey(statsId);
60 }
61
62 public RatingsStats getStats(String className, long classPK)
63 throws SystemException {
64
65 long classNameId = PortalUtil.getClassNameId(className);
66
67 RatingsStats stats = ratingsStatsPersistence.fetchByC_C(
68 classNameId, classPK);
69
70 if (stats == null) {
71 long statsId = counterLocalService.increment();
72
73 stats = ratingsStatsPersistence.create(statsId);
74
75 stats.setClassNameId(classNameId);
76 stats.setClassPK(classPK);
77 stats.setTotalEntries(0);
78 stats.setTotalScore(0.0);
79 stats.setAverageScore(0.0);
80
81 ratingsStatsPersistence.update(stats, false);
82 }
83
84 return stats;
85 }
86
87 private static Log _log =
88 LogFactoryUtil.getLog(RatingsStatsLocalServiceImpl.class);
89
90 }