001
014
015 package com.liferay.portlet.ratings.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.ratings.NoSuchStatsException;
044 import com.liferay.portlet.ratings.model.RatingsStats;
045 import com.liferay.portlet.ratings.model.impl.RatingsStatsImpl;
046 import com.liferay.portlet.ratings.model.impl.RatingsStatsModelImpl;
047
048 import java.io.Serializable;
049
050 import java.util.ArrayList;
051 import java.util.Collections;
052 import java.util.List;
053
054
066 public class RatingsStatsPersistenceImpl extends BasePersistenceImpl<RatingsStats>
067 implements RatingsStatsPersistence {
068
073 public static final String FINDER_CLASS_NAME_ENTITY = RatingsStatsImpl.class.getName();
074 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List1";
076 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077 ".List2";
078 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
079 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
080 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
081 new String[] { Long.class.getName(), Long.class.getName() },
082 RatingsStatsModelImpl.CLASSNAMEID_COLUMN_BITMASK |
083 RatingsStatsModelImpl.CLASSPK_COLUMN_BITMASK);
084 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
085 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
086 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
087 new String[] { Long.class.getName(), Long.class.getName() });
088 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
089 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
090 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
091 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
092 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
094 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
095 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
096 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
097
098
103 public void cacheResult(RatingsStats ratingsStats) {
104 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
105 RatingsStatsImpl.class, ratingsStats.getPrimaryKey(), ratingsStats);
106
107 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
108 new Object[] {
109 Long.valueOf(ratingsStats.getClassNameId()),
110 Long.valueOf(ratingsStats.getClassPK())
111 }, ratingsStats);
112
113 ratingsStats.resetOriginalValues();
114 }
115
116
121 public void cacheResult(List<RatingsStats> ratingsStatses) {
122 for (RatingsStats ratingsStats : ratingsStatses) {
123 if (EntityCacheUtil.getResult(
124 RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
125 RatingsStatsImpl.class, ratingsStats.getPrimaryKey()) == null) {
126 cacheResult(ratingsStats);
127 }
128 else {
129 ratingsStats.resetOriginalValues();
130 }
131 }
132 }
133
134
141 @Override
142 public void clearCache() {
143 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
144 CacheRegistryUtil.clear(RatingsStatsImpl.class.getName());
145 }
146
147 EntityCacheUtil.clearCache(RatingsStatsImpl.class.getName());
148
149 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
150 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
151 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
152 }
153
154
161 @Override
162 public void clearCache(RatingsStats ratingsStats) {
163 EntityCacheUtil.removeResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
164 RatingsStatsImpl.class, ratingsStats.getPrimaryKey());
165
166 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
167 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
168
169 clearUniqueFindersCache(ratingsStats);
170 }
171
172 @Override
173 public void clearCache(List<RatingsStats> ratingsStatses) {
174 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
175 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
176
177 for (RatingsStats ratingsStats : ratingsStatses) {
178 EntityCacheUtil.removeResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
179 RatingsStatsImpl.class, ratingsStats.getPrimaryKey());
180
181 clearUniqueFindersCache(ratingsStats);
182 }
183 }
184
185 protected void cacheUniqueFindersCache(RatingsStats ratingsStats) {
186 if (ratingsStats.isNew()) {
187 Object[] args = new Object[] {
188 Long.valueOf(ratingsStats.getClassNameId()),
189 Long.valueOf(ratingsStats.getClassPK())
190 };
191
192 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
193 Long.valueOf(1));
194 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
195 ratingsStats);
196 }
197 else {
198 RatingsStatsModelImpl ratingsStatsModelImpl = (RatingsStatsModelImpl)ratingsStats;
199
200 if ((ratingsStatsModelImpl.getColumnBitmask() &
201 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
202 Object[] args = new Object[] {
203 Long.valueOf(ratingsStats.getClassNameId()),
204 Long.valueOf(ratingsStats.getClassPK())
205 };
206
207 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
208 Long.valueOf(1));
209 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
210 ratingsStats);
211 }
212 }
213 }
214
215 protected void clearUniqueFindersCache(RatingsStats ratingsStats) {
216 RatingsStatsModelImpl ratingsStatsModelImpl = (RatingsStatsModelImpl)ratingsStats;
217
218 Object[] args = new Object[] {
219 Long.valueOf(ratingsStats.getClassNameId()),
220 Long.valueOf(ratingsStats.getClassPK())
221 };
222
223 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
224 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
225
226 if ((ratingsStatsModelImpl.getColumnBitmask() &
227 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
228 args = new Object[] {
229 Long.valueOf(ratingsStatsModelImpl.getOriginalClassNameId()),
230 Long.valueOf(ratingsStatsModelImpl.getOriginalClassPK())
231 };
232
233 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
234 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
235 }
236 }
237
238
244 public RatingsStats create(long statsId) {
245 RatingsStats ratingsStats = new RatingsStatsImpl();
246
247 ratingsStats.setNew(true);
248 ratingsStats.setPrimaryKey(statsId);
249
250 return ratingsStats;
251 }
252
253
261 public RatingsStats remove(long statsId)
262 throws NoSuchStatsException, SystemException {
263 return remove(Long.valueOf(statsId));
264 }
265
266
274 @Override
275 public RatingsStats remove(Serializable primaryKey)
276 throws NoSuchStatsException, SystemException {
277 Session session = null;
278
279 try {
280 session = openSession();
281
282 RatingsStats ratingsStats = (RatingsStats)session.get(RatingsStatsImpl.class,
283 primaryKey);
284
285 if (ratingsStats == null) {
286 if (_log.isWarnEnabled()) {
287 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
288 }
289
290 throw new NoSuchStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
291 primaryKey);
292 }
293
294 return remove(ratingsStats);
295 }
296 catch (NoSuchStatsException nsee) {
297 throw nsee;
298 }
299 catch (Exception e) {
300 throw processException(e);
301 }
302 finally {
303 closeSession(session);
304 }
305 }
306
307 @Override
308 protected RatingsStats removeImpl(RatingsStats ratingsStats)
309 throws SystemException {
310 ratingsStats = toUnwrappedModel(ratingsStats);
311
312 Session session = null;
313
314 try {
315 session = openSession();
316
317 BatchSessionUtil.delete(session, ratingsStats);
318 }
319 catch (Exception e) {
320 throw processException(e);
321 }
322 finally {
323 closeSession(session);
324 }
325
326 clearCache(ratingsStats);
327
328 return ratingsStats;
329 }
330
331 @Override
332 public RatingsStats updateImpl(
333 com.liferay.portlet.ratings.model.RatingsStats ratingsStats,
334 boolean merge) throws SystemException {
335 ratingsStats = toUnwrappedModel(ratingsStats);
336
337 boolean isNew = ratingsStats.isNew();
338
339 Session session = null;
340
341 try {
342 session = openSession();
343
344 BatchSessionUtil.update(session, ratingsStats, merge);
345
346 ratingsStats.setNew(false);
347 }
348 catch (Exception e) {
349 throw processException(e);
350 }
351 finally {
352 closeSession(session);
353 }
354
355 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
356
357 if (isNew || !RatingsStatsModelImpl.COLUMN_BITMASK_ENABLED) {
358 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
359 }
360
361 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
362 RatingsStatsImpl.class, ratingsStats.getPrimaryKey(), ratingsStats);
363
364 clearUniqueFindersCache(ratingsStats);
365 cacheUniqueFindersCache(ratingsStats);
366
367 return ratingsStats;
368 }
369
370 protected RatingsStats toUnwrappedModel(RatingsStats ratingsStats) {
371 if (ratingsStats instanceof RatingsStatsImpl) {
372 return ratingsStats;
373 }
374
375 RatingsStatsImpl ratingsStatsImpl = new RatingsStatsImpl();
376
377 ratingsStatsImpl.setNew(ratingsStats.isNew());
378 ratingsStatsImpl.setPrimaryKey(ratingsStats.getPrimaryKey());
379
380 ratingsStatsImpl.setStatsId(ratingsStats.getStatsId());
381 ratingsStatsImpl.setClassNameId(ratingsStats.getClassNameId());
382 ratingsStatsImpl.setClassPK(ratingsStats.getClassPK());
383 ratingsStatsImpl.setTotalEntries(ratingsStats.getTotalEntries());
384 ratingsStatsImpl.setTotalScore(ratingsStats.getTotalScore());
385 ratingsStatsImpl.setAverageScore(ratingsStats.getAverageScore());
386
387 return ratingsStatsImpl;
388 }
389
390
398 @Override
399 public RatingsStats findByPrimaryKey(Serializable primaryKey)
400 throws NoSuchModelException, SystemException {
401 return findByPrimaryKey(((Long)primaryKey).longValue());
402 }
403
404
412 public RatingsStats findByPrimaryKey(long statsId)
413 throws NoSuchStatsException, SystemException {
414 RatingsStats ratingsStats = fetchByPrimaryKey(statsId);
415
416 if (ratingsStats == null) {
417 if (_log.isWarnEnabled()) {
418 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + statsId);
419 }
420
421 throw new NoSuchStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
422 statsId);
423 }
424
425 return ratingsStats;
426 }
427
428
435 @Override
436 public RatingsStats fetchByPrimaryKey(Serializable primaryKey)
437 throws SystemException {
438 return fetchByPrimaryKey(((Long)primaryKey).longValue());
439 }
440
441
448 public RatingsStats fetchByPrimaryKey(long statsId)
449 throws SystemException {
450 RatingsStats ratingsStats = (RatingsStats)EntityCacheUtil.getResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
451 RatingsStatsImpl.class, statsId);
452
453 if (ratingsStats == _nullRatingsStats) {
454 return null;
455 }
456
457 if (ratingsStats == null) {
458 Session session = null;
459
460 boolean hasException = false;
461
462 try {
463 session = openSession();
464
465 ratingsStats = (RatingsStats)session.get(RatingsStatsImpl.class,
466 Long.valueOf(statsId));
467 }
468 catch (Exception e) {
469 hasException = true;
470
471 throw processException(e);
472 }
473 finally {
474 if (ratingsStats != null) {
475 cacheResult(ratingsStats);
476 }
477 else if (!hasException) {
478 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
479 RatingsStatsImpl.class, statsId, _nullRatingsStats);
480 }
481
482 closeSession(session);
483 }
484 }
485
486 return ratingsStats;
487 }
488
489
498 public RatingsStats findByC_C(long classNameId, long classPK)
499 throws NoSuchStatsException, SystemException {
500 RatingsStats ratingsStats = fetchByC_C(classNameId, classPK);
501
502 if (ratingsStats == null) {
503 StringBundler msg = new StringBundler(6);
504
505 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
506
507 msg.append("classNameId=");
508 msg.append(classNameId);
509
510 msg.append(", classPK=");
511 msg.append(classPK);
512
513 msg.append(StringPool.CLOSE_CURLY_BRACE);
514
515 if (_log.isWarnEnabled()) {
516 _log.warn(msg.toString());
517 }
518
519 throw new NoSuchStatsException(msg.toString());
520 }
521
522 return ratingsStats;
523 }
524
525
533 public RatingsStats fetchByC_C(long classNameId, long classPK)
534 throws SystemException {
535 return fetchByC_C(classNameId, classPK, true);
536 }
537
538
547 public RatingsStats fetchByC_C(long classNameId, long classPK,
548 boolean retrieveFromCache) throws SystemException {
549 Object[] finderArgs = new Object[] { classNameId, classPK };
550
551 Object result = null;
552
553 if (retrieveFromCache) {
554 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
555 finderArgs, this);
556 }
557
558 if (result instanceof RatingsStats) {
559 RatingsStats ratingsStats = (RatingsStats)result;
560
561 if ((classNameId != ratingsStats.getClassNameId()) ||
562 (classPK != ratingsStats.getClassPK())) {
563 result = null;
564 }
565 }
566
567 if (result == null) {
568 StringBundler query = new StringBundler(3);
569
570 query.append(_SQL_SELECT_RATINGSSTATS_WHERE);
571
572 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
573
574 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
575
576 String sql = query.toString();
577
578 Session session = null;
579
580 try {
581 session = openSession();
582
583 Query q = session.createQuery(sql);
584
585 QueryPos qPos = QueryPos.getInstance(q);
586
587 qPos.add(classNameId);
588
589 qPos.add(classPK);
590
591 List<RatingsStats> list = q.list();
592
593 result = list;
594
595 RatingsStats ratingsStats = null;
596
597 if (list.isEmpty()) {
598 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
599 finderArgs, list);
600 }
601 else {
602 ratingsStats = list.get(0);
603
604 cacheResult(ratingsStats);
605
606 if ((ratingsStats.getClassNameId() != classNameId) ||
607 (ratingsStats.getClassPK() != classPK)) {
608 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
609 finderArgs, ratingsStats);
610 }
611 }
612
613 return ratingsStats;
614 }
615 catch (Exception e) {
616 throw processException(e);
617 }
618 finally {
619 if (result == null) {
620 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
621 finderArgs);
622 }
623
624 closeSession(session);
625 }
626 }
627 else {
628 if (result instanceof List<?>) {
629 return null;
630 }
631 else {
632 return (RatingsStats)result;
633 }
634 }
635 }
636
637
643 public List<RatingsStats> findAll() throws SystemException {
644 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
645 }
646
647
659 public List<RatingsStats> findAll(int start, int end)
660 throws SystemException {
661 return findAll(start, end, null);
662 }
663
664
677 public List<RatingsStats> findAll(int start, int end,
678 OrderByComparator orderByComparator) throws SystemException {
679 FinderPath finderPath = null;
680 Object[] finderArgs = new Object[] { start, end, orderByComparator };
681
682 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
683 (orderByComparator == null)) {
684 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
685 finderArgs = FINDER_ARGS_EMPTY;
686 }
687 else {
688 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
689 finderArgs = new Object[] { start, end, orderByComparator };
690 }
691
692 List<RatingsStats> list = (List<RatingsStats>)FinderCacheUtil.getResult(finderPath,
693 finderArgs, this);
694
695 if (list == null) {
696 StringBundler query = null;
697 String sql = null;
698
699 if (orderByComparator != null) {
700 query = new StringBundler(2 +
701 (orderByComparator.getOrderByFields().length * 3));
702
703 query.append(_SQL_SELECT_RATINGSSTATS);
704
705 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
706 orderByComparator);
707
708 sql = query.toString();
709 }
710 else {
711 sql = _SQL_SELECT_RATINGSSTATS;
712 }
713
714 Session session = null;
715
716 try {
717 session = openSession();
718
719 Query q = session.createQuery(sql);
720
721 if (orderByComparator == null) {
722 list = (List<RatingsStats>)QueryUtil.list(q, getDialect(),
723 start, end, false);
724
725 Collections.sort(list);
726 }
727 else {
728 list = (List<RatingsStats>)QueryUtil.list(q, getDialect(),
729 start, end);
730 }
731 }
732 catch (Exception e) {
733 throw processException(e);
734 }
735 finally {
736 if (list == null) {
737 FinderCacheUtil.removeResult(finderPath, finderArgs);
738 }
739 else {
740 cacheResult(list);
741
742 FinderCacheUtil.putResult(finderPath, finderArgs, list);
743 }
744
745 closeSession(session);
746 }
747 }
748
749 return list;
750 }
751
752
760 public RatingsStats removeByC_C(long classNameId, long classPK)
761 throws NoSuchStatsException, SystemException {
762 RatingsStats ratingsStats = findByC_C(classNameId, classPK);
763
764 return remove(ratingsStats);
765 }
766
767
772 public void removeAll() throws SystemException {
773 for (RatingsStats ratingsStats : findAll()) {
774 remove(ratingsStats);
775 }
776 }
777
778
786 public int countByC_C(long classNameId, long classPK)
787 throws SystemException {
788 Object[] finderArgs = new Object[] { classNameId, classPK };
789
790 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
791 finderArgs, this);
792
793 if (count == null) {
794 StringBundler query = new StringBundler(3);
795
796 query.append(_SQL_COUNT_RATINGSSTATS_WHERE);
797
798 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
799
800 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
801
802 String sql = query.toString();
803
804 Session session = null;
805
806 try {
807 session = openSession();
808
809 Query q = session.createQuery(sql);
810
811 QueryPos qPos = QueryPos.getInstance(q);
812
813 qPos.add(classNameId);
814
815 qPos.add(classPK);
816
817 count = (Long)q.uniqueResult();
818 }
819 catch (Exception e) {
820 throw processException(e);
821 }
822 finally {
823 if (count == null) {
824 count = Long.valueOf(0);
825 }
826
827 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
828 count);
829
830 closeSession(session);
831 }
832 }
833
834 return count.intValue();
835 }
836
837
843 public int countAll() throws SystemException {
844 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
845 FINDER_ARGS_EMPTY, this);
846
847 if (count == null) {
848 Session session = null;
849
850 try {
851 session = openSession();
852
853 Query q = session.createQuery(_SQL_COUNT_RATINGSSTATS);
854
855 count = (Long)q.uniqueResult();
856 }
857 catch (Exception e) {
858 throw processException(e);
859 }
860 finally {
861 if (count == null) {
862 count = Long.valueOf(0);
863 }
864
865 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
866 FINDER_ARGS_EMPTY, count);
867
868 closeSession(session);
869 }
870 }
871
872 return count.intValue();
873 }
874
875
878 public void afterPropertiesSet() {
879 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
880 com.liferay.portal.util.PropsUtil.get(
881 "value.object.listener.com.liferay.portlet.ratings.model.RatingsStats")));
882
883 if (listenerClassNames.length > 0) {
884 try {
885 List<ModelListener<RatingsStats>> listenersList = new ArrayList<ModelListener<RatingsStats>>();
886
887 for (String listenerClassName : listenerClassNames) {
888 Class<?> clazz = getClass();
889
890 listenersList.add((ModelListener<RatingsStats>)InstanceFactory.newInstance(
891 clazz.getClassLoader(), listenerClassName));
892 }
893
894 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
895 }
896 catch (Exception e) {
897 _log.error(e);
898 }
899 }
900 }
901
902 public void destroy() {
903 EntityCacheUtil.removeCache(RatingsStatsImpl.class.getName());
904 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
905 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
906 }
907
908 @BeanReference(type = RatingsEntryPersistence.class)
909 protected RatingsEntryPersistence ratingsEntryPersistence;
910 @BeanReference(type = RatingsStatsPersistence.class)
911 protected RatingsStatsPersistence ratingsStatsPersistence;
912 @BeanReference(type = ResourcePersistence.class)
913 protected ResourcePersistence resourcePersistence;
914 @BeanReference(type = UserPersistence.class)
915 protected UserPersistence userPersistence;
916 private static final String _SQL_SELECT_RATINGSSTATS = "SELECT ratingsStats FROM RatingsStats ratingsStats";
917 private static final String _SQL_SELECT_RATINGSSTATS_WHERE = "SELECT ratingsStats FROM RatingsStats ratingsStats WHERE ";
918 private static final String _SQL_COUNT_RATINGSSTATS = "SELECT COUNT(ratingsStats) FROM RatingsStats ratingsStats";
919 private static final String _SQL_COUNT_RATINGSSTATS_WHERE = "SELECT COUNT(ratingsStats) FROM RatingsStats ratingsStats WHERE ";
920 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsStats.classNameId = ? AND ";
921 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsStats.classPK = ?";
922 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsStats.";
923 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsStats exists with the primary key ";
924 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsStats exists with the key {";
925 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
926 private static Log _log = LogFactoryUtil.getLog(RatingsStatsPersistenceImpl.class);
927 private static RatingsStats _nullRatingsStats = new RatingsStatsImpl() {
928 @Override
929 public Object clone() {
930 return this;
931 }
932
933 @Override
934 public CacheModel<RatingsStats> toCacheModel() {
935 return _nullRatingsStatsCacheModel;
936 }
937 };
938
939 private static CacheModel<RatingsStats> _nullRatingsStatsCacheModel = new CacheModel<RatingsStats>() {
940 public RatingsStats toEntityModel() {
941 return _nullRatingsStats;
942 }
943 };
944 }