001
014
015 package com.liferay.portlet.ratings.service.persistence;
016
017 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020 import com.liferay.portal.kernel.dao.orm.FinderPath;
021 import com.liferay.portal.kernel.dao.orm.Query;
022 import com.liferay.portal.kernel.dao.orm.QueryPos;
023 import com.liferay.portal.kernel.dao.orm.QueryUtil;
024 import com.liferay.portal.kernel.dao.orm.Session;
025 import com.liferay.portal.kernel.exception.SystemException;
026 import com.liferay.portal.kernel.log.Log;
027 import com.liferay.portal.kernel.log.LogFactoryUtil;
028 import com.liferay.portal.kernel.util.GetterUtil;
029 import com.liferay.portal.kernel.util.InstanceFactory;
030 import com.liferay.portal.kernel.util.OrderByComparator;
031 import com.liferay.portal.kernel.util.StringBundler;
032 import com.liferay.portal.kernel.util.StringPool;
033 import com.liferay.portal.kernel.util.StringUtil;
034 import com.liferay.portal.kernel.util.UnmodifiableList;
035 import com.liferay.portal.model.CacheModel;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
038
039 import com.liferay.portlet.ratings.NoSuchStatsException;
040 import com.liferay.portlet.ratings.model.RatingsStats;
041 import com.liferay.portlet.ratings.model.impl.RatingsStatsImpl;
042 import com.liferay.portlet.ratings.model.impl.RatingsStatsModelImpl;
043
044 import java.io.Serializable;
045
046 import java.util.ArrayList;
047 import java.util.Collections;
048 import java.util.List;
049
050
062 public class RatingsStatsPersistenceImpl extends BasePersistenceImpl<RatingsStats>
063 implements RatingsStatsPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = RatingsStatsImpl.class.getName();
070 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
071 ".List1";
072 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List2";
074 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
075 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
076 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
077 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
078 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
081 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
084 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
085 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
086 new String[] { Long.class.getName(), Long.class.getName() },
087 RatingsStatsModelImpl.CLASSNAMEID_COLUMN_BITMASK |
088 RatingsStatsModelImpl.CLASSPK_COLUMN_BITMASK);
089 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
090 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
091 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
092 new String[] { Long.class.getName(), Long.class.getName() });
093
094
103 public RatingsStats findByC_C(long classNameId, long classPK)
104 throws NoSuchStatsException, SystemException {
105 RatingsStats ratingsStats = fetchByC_C(classNameId, classPK);
106
107 if (ratingsStats == null) {
108 StringBundler msg = new StringBundler(6);
109
110 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
111
112 msg.append("classNameId=");
113 msg.append(classNameId);
114
115 msg.append(", classPK=");
116 msg.append(classPK);
117
118 msg.append(StringPool.CLOSE_CURLY_BRACE);
119
120 if (_log.isWarnEnabled()) {
121 _log.warn(msg.toString());
122 }
123
124 throw new NoSuchStatsException(msg.toString());
125 }
126
127 return ratingsStats;
128 }
129
130
138 public RatingsStats fetchByC_C(long classNameId, long classPK)
139 throws SystemException {
140 return fetchByC_C(classNameId, classPK, true);
141 }
142
143
152 public RatingsStats fetchByC_C(long classNameId, long classPK,
153 boolean retrieveFromCache) throws SystemException {
154 Object[] finderArgs = new Object[] { classNameId, classPK };
155
156 Object result = null;
157
158 if (retrieveFromCache) {
159 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
160 finderArgs, this);
161 }
162
163 if (result instanceof RatingsStats) {
164 RatingsStats ratingsStats = (RatingsStats)result;
165
166 if ((classNameId != ratingsStats.getClassNameId()) ||
167 (classPK != ratingsStats.getClassPK())) {
168 result = null;
169 }
170 }
171
172 if (result == null) {
173 StringBundler query = new StringBundler(4);
174
175 query.append(_SQL_SELECT_RATINGSSTATS_WHERE);
176
177 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
178
179 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
180
181 String sql = query.toString();
182
183 Session session = null;
184
185 try {
186 session = openSession();
187
188 Query q = session.createQuery(sql);
189
190 QueryPos qPos = QueryPos.getInstance(q);
191
192 qPos.add(classNameId);
193
194 qPos.add(classPK);
195
196 List<RatingsStats> list = q.list();
197
198 if (list.isEmpty()) {
199 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
200 finderArgs, list);
201 }
202 else {
203 RatingsStats ratingsStats = list.get(0);
204
205 result = ratingsStats;
206
207 cacheResult(ratingsStats);
208
209 if ((ratingsStats.getClassNameId() != classNameId) ||
210 (ratingsStats.getClassPK() != classPK)) {
211 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
212 finderArgs, ratingsStats);
213 }
214 }
215 }
216 catch (Exception e) {
217 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
218 finderArgs);
219
220 throw processException(e);
221 }
222 finally {
223 closeSession(session);
224 }
225 }
226
227 if (result instanceof List<?>) {
228 return null;
229 }
230 else {
231 return (RatingsStats)result;
232 }
233 }
234
235
243 public RatingsStats removeByC_C(long classNameId, long classPK)
244 throws NoSuchStatsException, SystemException {
245 RatingsStats ratingsStats = findByC_C(classNameId, classPK);
246
247 return remove(ratingsStats);
248 }
249
250
258 public int countByC_C(long classNameId, long classPK)
259 throws SystemException {
260 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
261
262 Object[] finderArgs = new Object[] { classNameId, classPK };
263
264 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
265 this);
266
267 if (count == null) {
268 StringBundler query = new StringBundler(3);
269
270 query.append(_SQL_COUNT_RATINGSSTATS_WHERE);
271
272 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
273
274 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
275
276 String sql = query.toString();
277
278 Session session = null;
279
280 try {
281 session = openSession();
282
283 Query q = session.createQuery(sql);
284
285 QueryPos qPos = QueryPos.getInstance(q);
286
287 qPos.add(classNameId);
288
289 qPos.add(classPK);
290
291 count = (Long)q.uniqueResult();
292
293 FinderCacheUtil.putResult(finderPath, finderArgs, count);
294 }
295 catch (Exception e) {
296 FinderCacheUtil.removeResult(finderPath, finderArgs);
297
298 throw processException(e);
299 }
300 finally {
301 closeSession(session);
302 }
303 }
304
305 return count.intValue();
306 }
307
308 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsStats.classNameId = ? AND ";
309 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsStats.classPK = ?";
310
311
316 public void cacheResult(RatingsStats ratingsStats) {
317 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
318 RatingsStatsImpl.class, ratingsStats.getPrimaryKey(), ratingsStats);
319
320 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
321 new Object[] {
322 ratingsStats.getClassNameId(), ratingsStats.getClassPK()
323 }, ratingsStats);
324
325 ratingsStats.resetOriginalValues();
326 }
327
328
333 public void cacheResult(List<RatingsStats> ratingsStatses) {
334 for (RatingsStats ratingsStats : ratingsStatses) {
335 if (EntityCacheUtil.getResult(
336 RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
337 RatingsStatsImpl.class, ratingsStats.getPrimaryKey()) == null) {
338 cacheResult(ratingsStats);
339 }
340 else {
341 ratingsStats.resetOriginalValues();
342 }
343 }
344 }
345
346
353 @Override
354 public void clearCache() {
355 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
356 CacheRegistryUtil.clear(RatingsStatsImpl.class.getName());
357 }
358
359 EntityCacheUtil.clearCache(RatingsStatsImpl.class.getName());
360
361 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
362 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
363 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
364 }
365
366
373 @Override
374 public void clearCache(RatingsStats ratingsStats) {
375 EntityCacheUtil.removeResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
376 RatingsStatsImpl.class, ratingsStats.getPrimaryKey());
377
378 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
379 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
380
381 clearUniqueFindersCache(ratingsStats);
382 }
383
384 @Override
385 public void clearCache(List<RatingsStats> ratingsStatses) {
386 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
387 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
388
389 for (RatingsStats ratingsStats : ratingsStatses) {
390 EntityCacheUtil.removeResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
391 RatingsStatsImpl.class, ratingsStats.getPrimaryKey());
392
393 clearUniqueFindersCache(ratingsStats);
394 }
395 }
396
397 protected void cacheUniqueFindersCache(RatingsStats ratingsStats) {
398 if (ratingsStats.isNew()) {
399 Object[] args = new Object[] {
400 ratingsStats.getClassNameId(), ratingsStats.getClassPK()
401 };
402
403 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
404 Long.valueOf(1));
405 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
406 ratingsStats);
407 }
408 else {
409 RatingsStatsModelImpl ratingsStatsModelImpl = (RatingsStatsModelImpl)ratingsStats;
410
411 if ((ratingsStatsModelImpl.getColumnBitmask() &
412 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
413 Object[] args = new Object[] {
414 ratingsStats.getClassNameId(), ratingsStats.getClassPK()
415 };
416
417 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
418 Long.valueOf(1));
419 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
420 ratingsStats);
421 }
422 }
423 }
424
425 protected void clearUniqueFindersCache(RatingsStats ratingsStats) {
426 RatingsStatsModelImpl ratingsStatsModelImpl = (RatingsStatsModelImpl)ratingsStats;
427
428 Object[] args = new Object[] {
429 ratingsStats.getClassNameId(), ratingsStats.getClassPK()
430 };
431
432 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
433 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
434
435 if ((ratingsStatsModelImpl.getColumnBitmask() &
436 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
437 args = new Object[] {
438 ratingsStatsModelImpl.getOriginalClassNameId(),
439 ratingsStatsModelImpl.getOriginalClassPK()
440 };
441
442 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
443 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
444 }
445 }
446
447
453 public RatingsStats create(long statsId) {
454 RatingsStats ratingsStats = new RatingsStatsImpl();
455
456 ratingsStats.setNew(true);
457 ratingsStats.setPrimaryKey(statsId);
458
459 return ratingsStats;
460 }
461
462
470 public RatingsStats remove(long statsId)
471 throws NoSuchStatsException, SystemException {
472 return remove((Serializable)statsId);
473 }
474
475
483 @Override
484 public RatingsStats remove(Serializable primaryKey)
485 throws NoSuchStatsException, SystemException {
486 Session session = null;
487
488 try {
489 session = openSession();
490
491 RatingsStats ratingsStats = (RatingsStats)session.get(RatingsStatsImpl.class,
492 primaryKey);
493
494 if (ratingsStats == null) {
495 if (_log.isWarnEnabled()) {
496 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
497 }
498
499 throw new NoSuchStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
500 primaryKey);
501 }
502
503 return remove(ratingsStats);
504 }
505 catch (NoSuchStatsException nsee) {
506 throw nsee;
507 }
508 catch (Exception e) {
509 throw processException(e);
510 }
511 finally {
512 closeSession(session);
513 }
514 }
515
516 @Override
517 protected RatingsStats removeImpl(RatingsStats ratingsStats)
518 throws SystemException {
519 ratingsStats = toUnwrappedModel(ratingsStats);
520
521 Session session = null;
522
523 try {
524 session = openSession();
525
526 if (!session.contains(ratingsStats)) {
527 ratingsStats = (RatingsStats)session.get(RatingsStatsImpl.class,
528 ratingsStats.getPrimaryKeyObj());
529 }
530
531 if (ratingsStats != null) {
532 session.delete(ratingsStats);
533 }
534 }
535 catch (Exception e) {
536 throw processException(e);
537 }
538 finally {
539 closeSession(session);
540 }
541
542 if (ratingsStats != null) {
543 clearCache(ratingsStats);
544 }
545
546 return ratingsStats;
547 }
548
549 @Override
550 public RatingsStats updateImpl(
551 com.liferay.portlet.ratings.model.RatingsStats ratingsStats)
552 throws SystemException {
553 ratingsStats = toUnwrappedModel(ratingsStats);
554
555 boolean isNew = ratingsStats.isNew();
556
557 Session session = null;
558
559 try {
560 session = openSession();
561
562 if (ratingsStats.isNew()) {
563 session.save(ratingsStats);
564
565 ratingsStats.setNew(false);
566 }
567 else {
568 session.merge(ratingsStats);
569 }
570 }
571 catch (Exception e) {
572 throw processException(e);
573 }
574 finally {
575 closeSession(session);
576 }
577
578 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
579
580 if (isNew || !RatingsStatsModelImpl.COLUMN_BITMASK_ENABLED) {
581 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
582 }
583
584 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
585 RatingsStatsImpl.class, ratingsStats.getPrimaryKey(), ratingsStats);
586
587 clearUniqueFindersCache(ratingsStats);
588 cacheUniqueFindersCache(ratingsStats);
589
590 return ratingsStats;
591 }
592
593 protected RatingsStats toUnwrappedModel(RatingsStats ratingsStats) {
594 if (ratingsStats instanceof RatingsStatsImpl) {
595 return ratingsStats;
596 }
597
598 RatingsStatsImpl ratingsStatsImpl = new RatingsStatsImpl();
599
600 ratingsStatsImpl.setNew(ratingsStats.isNew());
601 ratingsStatsImpl.setPrimaryKey(ratingsStats.getPrimaryKey());
602
603 ratingsStatsImpl.setStatsId(ratingsStats.getStatsId());
604 ratingsStatsImpl.setClassNameId(ratingsStats.getClassNameId());
605 ratingsStatsImpl.setClassPK(ratingsStats.getClassPK());
606 ratingsStatsImpl.setTotalEntries(ratingsStats.getTotalEntries());
607 ratingsStatsImpl.setTotalScore(ratingsStats.getTotalScore());
608 ratingsStatsImpl.setAverageScore(ratingsStats.getAverageScore());
609
610 return ratingsStatsImpl;
611 }
612
613
621 @Override
622 public RatingsStats findByPrimaryKey(Serializable primaryKey)
623 throws NoSuchStatsException, SystemException {
624 RatingsStats ratingsStats = fetchByPrimaryKey(primaryKey);
625
626 if (ratingsStats == null) {
627 if (_log.isWarnEnabled()) {
628 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
629 }
630
631 throw new NoSuchStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
632 primaryKey);
633 }
634
635 return ratingsStats;
636 }
637
638
646 public RatingsStats findByPrimaryKey(long statsId)
647 throws NoSuchStatsException, SystemException {
648 return findByPrimaryKey((Serializable)statsId);
649 }
650
651
658 @Override
659 public RatingsStats fetchByPrimaryKey(Serializable primaryKey)
660 throws SystemException {
661 RatingsStats ratingsStats = (RatingsStats)EntityCacheUtil.getResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
662 RatingsStatsImpl.class, primaryKey);
663
664 if (ratingsStats == _nullRatingsStats) {
665 return null;
666 }
667
668 if (ratingsStats == null) {
669 Session session = null;
670
671 try {
672 session = openSession();
673
674 ratingsStats = (RatingsStats)session.get(RatingsStatsImpl.class,
675 primaryKey);
676
677 if (ratingsStats != null) {
678 cacheResult(ratingsStats);
679 }
680 else {
681 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
682 RatingsStatsImpl.class, primaryKey, _nullRatingsStats);
683 }
684 }
685 catch (Exception e) {
686 EntityCacheUtil.removeResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
687 RatingsStatsImpl.class, primaryKey);
688
689 throw processException(e);
690 }
691 finally {
692 closeSession(session);
693 }
694 }
695
696 return ratingsStats;
697 }
698
699
706 public RatingsStats fetchByPrimaryKey(long statsId)
707 throws SystemException {
708 return fetchByPrimaryKey((Serializable)statsId);
709 }
710
711
717 public List<RatingsStats> findAll() throws SystemException {
718 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
719 }
720
721
733 public List<RatingsStats> findAll(int start, int end)
734 throws SystemException {
735 return findAll(start, end, null);
736 }
737
738
751 public List<RatingsStats> findAll(int start, int end,
752 OrderByComparator orderByComparator) throws SystemException {
753 boolean pagination = true;
754 FinderPath finderPath = null;
755 Object[] finderArgs = null;
756
757 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
758 (orderByComparator == null)) {
759 pagination = false;
760 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
761 finderArgs = FINDER_ARGS_EMPTY;
762 }
763 else {
764 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
765 finderArgs = new Object[] { start, end, orderByComparator };
766 }
767
768 List<RatingsStats> list = (List<RatingsStats>)FinderCacheUtil.getResult(finderPath,
769 finderArgs, this);
770
771 if (list == null) {
772 StringBundler query = null;
773 String sql = null;
774
775 if (orderByComparator != null) {
776 query = new StringBundler(2 +
777 (orderByComparator.getOrderByFields().length * 3));
778
779 query.append(_SQL_SELECT_RATINGSSTATS);
780
781 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
782 orderByComparator);
783
784 sql = query.toString();
785 }
786 else {
787 sql = _SQL_SELECT_RATINGSSTATS;
788
789 if (pagination) {
790 sql = sql.concat(RatingsStatsModelImpl.ORDER_BY_JPQL);
791 }
792 }
793
794 Session session = null;
795
796 try {
797 session = openSession();
798
799 Query q = session.createQuery(sql);
800
801 if (!pagination) {
802 list = (List<RatingsStats>)QueryUtil.list(q, getDialect(),
803 start, end, false);
804
805 Collections.sort(list);
806
807 list = new UnmodifiableList<RatingsStats>(list);
808 }
809 else {
810 list = (List<RatingsStats>)QueryUtil.list(q, getDialect(),
811 start, end);
812 }
813
814 cacheResult(list);
815
816 FinderCacheUtil.putResult(finderPath, finderArgs, list);
817 }
818 catch (Exception e) {
819 FinderCacheUtil.removeResult(finderPath, finderArgs);
820
821 throw processException(e);
822 }
823 finally {
824 closeSession(session);
825 }
826 }
827
828 return list;
829 }
830
831
836 public void removeAll() throws SystemException {
837 for (RatingsStats ratingsStats : findAll()) {
838 remove(ratingsStats);
839 }
840 }
841
842
848 public int countAll() throws SystemException {
849 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
850 FINDER_ARGS_EMPTY, this);
851
852 if (count == null) {
853 Session session = null;
854
855 try {
856 session = openSession();
857
858 Query q = session.createQuery(_SQL_COUNT_RATINGSSTATS);
859
860 count = (Long)q.uniqueResult();
861
862 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
863 FINDER_ARGS_EMPTY, count);
864 }
865 catch (Exception e) {
866 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
867 FINDER_ARGS_EMPTY);
868
869 throw processException(e);
870 }
871 finally {
872 closeSession(session);
873 }
874 }
875
876 return count.intValue();
877 }
878
879
882 public void afterPropertiesSet() {
883 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
884 com.liferay.portal.util.PropsUtil.get(
885 "value.object.listener.com.liferay.portlet.ratings.model.RatingsStats")));
886
887 if (listenerClassNames.length > 0) {
888 try {
889 List<ModelListener<RatingsStats>> listenersList = new ArrayList<ModelListener<RatingsStats>>();
890
891 for (String listenerClassName : listenerClassNames) {
892 listenersList.add((ModelListener<RatingsStats>)InstanceFactory.newInstance(
893 getClassLoader(), listenerClassName));
894 }
895
896 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
897 }
898 catch (Exception e) {
899 _log.error(e);
900 }
901 }
902 }
903
904 public void destroy() {
905 EntityCacheUtil.removeCache(RatingsStatsImpl.class.getName());
906 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
907 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
908 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
909 }
910
911 private static final String _SQL_SELECT_RATINGSSTATS = "SELECT ratingsStats FROM RatingsStats ratingsStats";
912 private static final String _SQL_SELECT_RATINGSSTATS_WHERE = "SELECT ratingsStats FROM RatingsStats ratingsStats WHERE ";
913 private static final String _SQL_COUNT_RATINGSSTATS = "SELECT COUNT(ratingsStats) FROM RatingsStats ratingsStats";
914 private static final String _SQL_COUNT_RATINGSSTATS_WHERE = "SELECT COUNT(ratingsStats) FROM RatingsStats ratingsStats WHERE ";
915 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsStats.";
916 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsStats exists with the primary key ";
917 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsStats exists with the key {";
918 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
919 private static Log _log = LogFactoryUtil.getLog(RatingsStatsPersistenceImpl.class);
920 private static RatingsStats _nullRatingsStats = new RatingsStatsImpl() {
921 @Override
922 public Object clone() {
923 return this;
924 }
925
926 @Override
927 public CacheModel<RatingsStats> toCacheModel() {
928 return _nullRatingsStatsCacheModel;
929 }
930 };
931
932 private static CacheModel<RatingsStats> _nullRatingsStatsCacheModel = new CacheModel<RatingsStats>() {
933 public RatingsStats toEntityModel() {
934 return _nullRatingsStats;
935 }
936 };
937 }