001
014
015 package com.liferay.portlet.ratings.service.persistence.impl;
016
017 import aQute.bnd.annotation.ProviderType;
018
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.log.Log;
028 import com.liferay.portal.kernel.log.LogFactoryUtil;
029 import com.liferay.portal.kernel.util.OrderByComparator;
030 import com.liferay.portal.kernel.util.StringBundler;
031 import com.liferay.portal.kernel.util.StringPool;
032 import com.liferay.portal.model.CacheModel;
033 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
034
035 import com.liferay.portlet.ratings.NoSuchStatsException;
036 import com.liferay.portlet.ratings.model.RatingsStats;
037 import com.liferay.portlet.ratings.model.impl.RatingsStatsImpl;
038 import com.liferay.portlet.ratings.model.impl.RatingsStatsModelImpl;
039 import com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence;
040
041 import java.io.Serializable;
042
043 import java.util.Collections;
044 import java.util.HashMap;
045 import java.util.HashSet;
046 import java.util.Iterator;
047 import java.util.List;
048 import java.util.Map;
049 import java.util.Set;
050
051
063 @ProviderType
064 public class RatingsStatsPersistenceImpl extends BasePersistenceImpl<RatingsStats>
065 implements RatingsStatsPersistence {
066
071 public static final String FINDER_CLASS_NAME_ENTITY = RatingsStatsImpl.class.getName();
072 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
073 ".List1";
074 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075 ".List2";
076 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
077 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
078 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
079 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
080 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
081 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
082 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
083 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
084 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
085 public static final FinderPath FINDER_PATH_FETCH_BY_C_C = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
086 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, RatingsStatsImpl.class,
087 FINDER_CLASS_NAME_ENTITY, "fetchByC_C",
088 new String[] { Long.class.getName(), Long.class.getName() },
089 RatingsStatsModelImpl.CLASSNAMEID_COLUMN_BITMASK |
090 RatingsStatsModelImpl.CLASSPK_COLUMN_BITMASK);
091 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
092 RatingsStatsModelImpl.FINDER_CACHE_ENABLED, Long.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
094 new String[] { Long.class.getName(), Long.class.getName() });
095
096
104 @Override
105 public RatingsStats findByC_C(long classNameId, long classPK)
106 throws NoSuchStatsException {
107 RatingsStats ratingsStats = fetchByC_C(classNameId, classPK);
108
109 if (ratingsStats == null) {
110 StringBundler msg = new StringBundler(6);
111
112 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
113
114 msg.append("classNameId=");
115 msg.append(classNameId);
116
117 msg.append(", classPK=");
118 msg.append(classPK);
119
120 msg.append(StringPool.CLOSE_CURLY_BRACE);
121
122 if (_log.isWarnEnabled()) {
123 _log.warn(msg.toString());
124 }
125
126 throw new NoSuchStatsException(msg.toString());
127 }
128
129 return ratingsStats;
130 }
131
132
139 @Override
140 public RatingsStats fetchByC_C(long classNameId, long classPK) {
141 return fetchByC_C(classNameId, classPK, true);
142 }
143
144
152 @Override
153 public RatingsStats fetchByC_C(long classNameId, long classPK,
154 boolean retrieveFromCache) {
155 Object[] finderArgs = new Object[] { classNameId, classPK };
156
157 Object result = null;
158
159 if (retrieveFromCache) {
160 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C,
161 finderArgs, this);
162 }
163
164 if (result instanceof RatingsStats) {
165 RatingsStats ratingsStats = (RatingsStats)result;
166
167 if ((classNameId != ratingsStats.getClassNameId()) ||
168 (classPK != ratingsStats.getClassPK())) {
169 result = null;
170 }
171 }
172
173 if (result == null) {
174 StringBundler query = new StringBundler(4);
175
176 query.append(_SQL_SELECT_RATINGSSTATS_WHERE);
177
178 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
179
180 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
181
182 String sql = query.toString();
183
184 Session session = null;
185
186 try {
187 session = openSession();
188
189 Query q = session.createQuery(sql);
190
191 QueryPos qPos = QueryPos.getInstance(q);
192
193 qPos.add(classNameId);
194
195 qPos.add(classPK);
196
197 List<RatingsStats> list = q.list();
198
199 if (list.isEmpty()) {
200 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
201 finderArgs, list);
202 }
203 else {
204 RatingsStats ratingsStats = list.get(0);
205
206 result = ratingsStats;
207
208 cacheResult(ratingsStats);
209
210 if ((ratingsStats.getClassNameId() != classNameId) ||
211 (ratingsStats.getClassPK() != classPK)) {
212 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
213 finderArgs, ratingsStats);
214 }
215 }
216 }
217 catch (Exception e) {
218 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C,
219 finderArgs);
220
221 throw processException(e);
222 }
223 finally {
224 closeSession(session);
225 }
226 }
227
228 if (result instanceof List<?>) {
229 return null;
230 }
231 else {
232 return (RatingsStats)result;
233 }
234 }
235
236
243 @Override
244 public RatingsStats removeByC_C(long classNameId, long classPK)
245 throws NoSuchStatsException {
246 RatingsStats ratingsStats = findByC_C(classNameId, classPK);
247
248 return remove(ratingsStats);
249 }
250
251
258 @Override
259 public int countByC_C(long classNameId, long classPK) {
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 public RatingsStatsPersistenceImpl() {
312 setModelClass(RatingsStats.class);
313 }
314
315
320 @Override
321 public void cacheResult(RatingsStats ratingsStats) {
322 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
323 RatingsStatsImpl.class, ratingsStats.getPrimaryKey(), ratingsStats);
324
325 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C,
326 new Object[] {
327 ratingsStats.getClassNameId(), ratingsStats.getClassPK()
328 }, ratingsStats);
329
330 ratingsStats.resetOriginalValues();
331 }
332
333
338 @Override
339 public void cacheResult(List<RatingsStats> ratingsStatses) {
340 for (RatingsStats ratingsStats : ratingsStatses) {
341 if (EntityCacheUtil.getResult(
342 RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
343 RatingsStatsImpl.class, ratingsStats.getPrimaryKey()) == null) {
344 cacheResult(ratingsStats);
345 }
346 else {
347 ratingsStats.resetOriginalValues();
348 }
349 }
350 }
351
352
359 @Override
360 public void clearCache() {
361 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
362 CacheRegistryUtil.clear(RatingsStatsImpl.class.getName());
363 }
364
365 EntityCacheUtil.clearCache(RatingsStatsImpl.class);
366
367 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
368 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
369 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
370 }
371
372
379 @Override
380 public void clearCache(RatingsStats ratingsStats) {
381 EntityCacheUtil.removeResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
382 RatingsStatsImpl.class, ratingsStats.getPrimaryKey());
383
384 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
385 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
386
387 clearUniqueFindersCache(ratingsStats);
388 }
389
390 @Override
391 public void clearCache(List<RatingsStats> ratingsStatses) {
392 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
393 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
394
395 for (RatingsStats ratingsStats : ratingsStatses) {
396 EntityCacheUtil.removeResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
397 RatingsStatsImpl.class, ratingsStats.getPrimaryKey());
398
399 clearUniqueFindersCache(ratingsStats);
400 }
401 }
402
403 protected void cacheUniqueFindersCache(RatingsStats ratingsStats) {
404 if (ratingsStats.isNew()) {
405 Object[] args = new Object[] {
406 ratingsStats.getClassNameId(), ratingsStats.getClassPK()
407 };
408
409 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
410 Long.valueOf(1));
411 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
412 ratingsStats);
413 }
414 else {
415 RatingsStatsModelImpl ratingsStatsModelImpl = (RatingsStatsModelImpl)ratingsStats;
416
417 if ((ratingsStatsModelImpl.getColumnBitmask() &
418 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
419 Object[] args = new Object[] {
420 ratingsStats.getClassNameId(), ratingsStats.getClassPK()
421 };
422
423 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, args,
424 Long.valueOf(1));
425 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C, args,
426 ratingsStats);
427 }
428 }
429 }
430
431 protected void clearUniqueFindersCache(RatingsStats ratingsStats) {
432 RatingsStatsModelImpl ratingsStatsModelImpl = (RatingsStatsModelImpl)ratingsStats;
433
434 Object[] args = new Object[] {
435 ratingsStats.getClassNameId(), ratingsStats.getClassPK()
436 };
437
438 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
439 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
440
441 if ((ratingsStatsModelImpl.getColumnBitmask() &
442 FINDER_PATH_FETCH_BY_C_C.getColumnBitmask()) != 0) {
443 args = new Object[] {
444 ratingsStatsModelImpl.getOriginalClassNameId(),
445 ratingsStatsModelImpl.getOriginalClassPK()
446 };
447
448 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
449 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C, args);
450 }
451 }
452
453
459 @Override
460 public RatingsStats create(long statsId) {
461 RatingsStats ratingsStats = new RatingsStatsImpl();
462
463 ratingsStats.setNew(true);
464 ratingsStats.setPrimaryKey(statsId);
465
466 return ratingsStats;
467 }
468
469
476 @Override
477 public RatingsStats remove(long statsId) throws NoSuchStatsException {
478 return remove((Serializable)statsId);
479 }
480
481
488 @Override
489 public RatingsStats remove(Serializable primaryKey)
490 throws NoSuchStatsException {
491 Session session = null;
492
493 try {
494 session = openSession();
495
496 RatingsStats ratingsStats = (RatingsStats)session.get(RatingsStatsImpl.class,
497 primaryKey);
498
499 if (ratingsStats == null) {
500 if (_log.isWarnEnabled()) {
501 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
502 }
503
504 throw new NoSuchStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
505 primaryKey);
506 }
507
508 return remove(ratingsStats);
509 }
510 catch (NoSuchStatsException nsee) {
511 throw nsee;
512 }
513 catch (Exception e) {
514 throw processException(e);
515 }
516 finally {
517 closeSession(session);
518 }
519 }
520
521 @Override
522 protected RatingsStats removeImpl(RatingsStats ratingsStats) {
523 ratingsStats = toUnwrappedModel(ratingsStats);
524
525 Session session = null;
526
527 try {
528 session = openSession();
529
530 if (!session.contains(ratingsStats)) {
531 ratingsStats = (RatingsStats)session.get(RatingsStatsImpl.class,
532 ratingsStats.getPrimaryKeyObj());
533 }
534
535 if (ratingsStats != null) {
536 session.delete(ratingsStats);
537 }
538 }
539 catch (Exception e) {
540 throw processException(e);
541 }
542 finally {
543 closeSession(session);
544 }
545
546 if (ratingsStats != null) {
547 clearCache(ratingsStats);
548 }
549
550 return ratingsStats;
551 }
552
553 @Override
554 public RatingsStats updateImpl(
555 com.liferay.portlet.ratings.model.RatingsStats ratingsStats) {
556 ratingsStats = toUnwrappedModel(ratingsStats);
557
558 boolean isNew = ratingsStats.isNew();
559
560 Session session = null;
561
562 try {
563 session = openSession();
564
565 if (ratingsStats.isNew()) {
566 session.save(ratingsStats);
567
568 ratingsStats.setNew(false);
569 }
570 else {
571 session.merge(ratingsStats);
572 }
573 }
574 catch (Exception e) {
575 throw processException(e);
576 }
577 finally {
578 closeSession(session);
579 }
580
581 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
582
583 if (isNew || !RatingsStatsModelImpl.COLUMN_BITMASK_ENABLED) {
584 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
585 }
586
587 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
588 RatingsStatsImpl.class, ratingsStats.getPrimaryKey(), ratingsStats,
589 false);
590
591 clearUniqueFindersCache(ratingsStats);
592 cacheUniqueFindersCache(ratingsStats);
593
594 ratingsStats.resetOriginalValues();
595
596 return ratingsStats;
597 }
598
599 protected RatingsStats toUnwrappedModel(RatingsStats ratingsStats) {
600 if (ratingsStats instanceof RatingsStatsImpl) {
601 return ratingsStats;
602 }
603
604 RatingsStatsImpl ratingsStatsImpl = new RatingsStatsImpl();
605
606 ratingsStatsImpl.setNew(ratingsStats.isNew());
607 ratingsStatsImpl.setPrimaryKey(ratingsStats.getPrimaryKey());
608
609 ratingsStatsImpl.setStatsId(ratingsStats.getStatsId());
610 ratingsStatsImpl.setClassNameId(ratingsStats.getClassNameId());
611 ratingsStatsImpl.setClassPK(ratingsStats.getClassPK());
612 ratingsStatsImpl.setTotalEntries(ratingsStats.getTotalEntries());
613 ratingsStatsImpl.setTotalScore(ratingsStats.getTotalScore());
614 ratingsStatsImpl.setAverageScore(ratingsStats.getAverageScore());
615
616 return ratingsStatsImpl;
617 }
618
619
626 @Override
627 public RatingsStats findByPrimaryKey(Serializable primaryKey)
628 throws NoSuchStatsException {
629 RatingsStats ratingsStats = fetchByPrimaryKey(primaryKey);
630
631 if (ratingsStats == null) {
632 if (_log.isWarnEnabled()) {
633 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
634 }
635
636 throw new NoSuchStatsException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
637 primaryKey);
638 }
639
640 return ratingsStats;
641 }
642
643
650 @Override
651 public RatingsStats findByPrimaryKey(long statsId)
652 throws NoSuchStatsException {
653 return findByPrimaryKey((Serializable)statsId);
654 }
655
656
662 @Override
663 public RatingsStats fetchByPrimaryKey(Serializable primaryKey) {
664 RatingsStats ratingsStats = (RatingsStats)EntityCacheUtil.getResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
665 RatingsStatsImpl.class, primaryKey);
666
667 if (ratingsStats == _nullRatingsStats) {
668 return null;
669 }
670
671 if (ratingsStats == null) {
672 Session session = null;
673
674 try {
675 session = openSession();
676
677 ratingsStats = (RatingsStats)session.get(RatingsStatsImpl.class,
678 primaryKey);
679
680 if (ratingsStats != null) {
681 cacheResult(ratingsStats);
682 }
683 else {
684 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
685 RatingsStatsImpl.class, primaryKey, _nullRatingsStats);
686 }
687 }
688 catch (Exception e) {
689 EntityCacheUtil.removeResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
690 RatingsStatsImpl.class, primaryKey);
691
692 throw processException(e);
693 }
694 finally {
695 closeSession(session);
696 }
697 }
698
699 return ratingsStats;
700 }
701
702
708 @Override
709 public RatingsStats fetchByPrimaryKey(long statsId) {
710 return fetchByPrimaryKey((Serializable)statsId);
711 }
712
713 @Override
714 public Map<Serializable, RatingsStats> fetchByPrimaryKeys(
715 Set<Serializable> primaryKeys) {
716 if (primaryKeys.isEmpty()) {
717 return Collections.emptyMap();
718 }
719
720 Map<Serializable, RatingsStats> map = new HashMap<Serializable, RatingsStats>();
721
722 if (primaryKeys.size() == 1) {
723 Iterator<Serializable> iterator = primaryKeys.iterator();
724
725 Serializable primaryKey = iterator.next();
726
727 RatingsStats ratingsStats = fetchByPrimaryKey(primaryKey);
728
729 if (ratingsStats != null) {
730 map.put(primaryKey, ratingsStats);
731 }
732
733 return map;
734 }
735
736 Set<Serializable> uncachedPrimaryKeys = null;
737
738 for (Serializable primaryKey : primaryKeys) {
739 RatingsStats ratingsStats = (RatingsStats)EntityCacheUtil.getResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
740 RatingsStatsImpl.class, primaryKey);
741
742 if (ratingsStats == null) {
743 if (uncachedPrimaryKeys == null) {
744 uncachedPrimaryKeys = new HashSet<Serializable>();
745 }
746
747 uncachedPrimaryKeys.add(primaryKey);
748 }
749 else {
750 map.put(primaryKey, ratingsStats);
751 }
752 }
753
754 if (uncachedPrimaryKeys == null) {
755 return map;
756 }
757
758 StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
759 1);
760
761 query.append(_SQL_SELECT_RATINGSSTATS_WHERE_PKS_IN);
762
763 for (Serializable primaryKey : uncachedPrimaryKeys) {
764 query.append(String.valueOf(primaryKey));
765
766 query.append(StringPool.COMMA);
767 }
768
769 query.setIndex(query.index() - 1);
770
771 query.append(StringPool.CLOSE_PARENTHESIS);
772
773 String sql = query.toString();
774
775 Session session = null;
776
777 try {
778 session = openSession();
779
780 Query q = session.createQuery(sql);
781
782 for (RatingsStats ratingsStats : (List<RatingsStats>)q.list()) {
783 map.put(ratingsStats.getPrimaryKeyObj(), ratingsStats);
784
785 cacheResult(ratingsStats);
786
787 uncachedPrimaryKeys.remove(ratingsStats.getPrimaryKeyObj());
788 }
789
790 for (Serializable primaryKey : uncachedPrimaryKeys) {
791 EntityCacheUtil.putResult(RatingsStatsModelImpl.ENTITY_CACHE_ENABLED,
792 RatingsStatsImpl.class, primaryKey, _nullRatingsStats);
793 }
794 }
795 catch (Exception e) {
796 throw processException(e);
797 }
798 finally {
799 closeSession(session);
800 }
801
802 return map;
803 }
804
805
810 @Override
811 public List<RatingsStats> findAll() {
812 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
813 }
814
815
826 @Override
827 public List<RatingsStats> findAll(int start, int end) {
828 return findAll(start, end, null);
829 }
830
831
843 @Override
844 public List<RatingsStats> findAll(int start, int end,
845 OrderByComparator<RatingsStats> orderByComparator) {
846 boolean pagination = true;
847 FinderPath finderPath = null;
848 Object[] finderArgs = null;
849
850 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
851 (orderByComparator == null)) {
852 pagination = false;
853 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
854 finderArgs = FINDER_ARGS_EMPTY;
855 }
856 else {
857 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
858 finderArgs = new Object[] { start, end, orderByComparator };
859 }
860
861 List<RatingsStats> list = (List<RatingsStats>)FinderCacheUtil.getResult(finderPath,
862 finderArgs, this);
863
864 if (list == null) {
865 StringBundler query = null;
866 String sql = null;
867
868 if (orderByComparator != null) {
869 query = new StringBundler(2 +
870 (orderByComparator.getOrderByFields().length * 3));
871
872 query.append(_SQL_SELECT_RATINGSSTATS);
873
874 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
875 orderByComparator);
876
877 sql = query.toString();
878 }
879 else {
880 sql = _SQL_SELECT_RATINGSSTATS;
881
882 if (pagination) {
883 sql = sql.concat(RatingsStatsModelImpl.ORDER_BY_JPQL);
884 }
885 }
886
887 Session session = null;
888
889 try {
890 session = openSession();
891
892 Query q = session.createQuery(sql);
893
894 if (!pagination) {
895 list = (List<RatingsStats>)QueryUtil.list(q, getDialect(),
896 start, end, false);
897
898 Collections.sort(list);
899
900 list = Collections.unmodifiableList(list);
901 }
902 else {
903 list = (List<RatingsStats>)QueryUtil.list(q, getDialect(),
904 start, end);
905 }
906
907 cacheResult(list);
908
909 FinderCacheUtil.putResult(finderPath, finderArgs, list);
910 }
911 catch (Exception e) {
912 FinderCacheUtil.removeResult(finderPath, finderArgs);
913
914 throw processException(e);
915 }
916 finally {
917 closeSession(session);
918 }
919 }
920
921 return list;
922 }
923
924
928 @Override
929 public void removeAll() {
930 for (RatingsStats ratingsStats : findAll()) {
931 remove(ratingsStats);
932 }
933 }
934
935
940 @Override
941 public int countAll() {
942 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
943 FINDER_ARGS_EMPTY, this);
944
945 if (count == null) {
946 Session session = null;
947
948 try {
949 session = openSession();
950
951 Query q = session.createQuery(_SQL_COUNT_RATINGSSTATS);
952
953 count = (Long)q.uniqueResult();
954
955 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
956 FINDER_ARGS_EMPTY, count);
957 }
958 catch (Exception e) {
959 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
960 FINDER_ARGS_EMPTY);
961
962 throw processException(e);
963 }
964 finally {
965 closeSession(session);
966 }
967 }
968
969 return count.intValue();
970 }
971
972
975 public void afterPropertiesSet() {
976 }
977
978 public void destroy() {
979 EntityCacheUtil.removeCache(RatingsStatsImpl.class.getName());
980 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
981 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
982 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
983 }
984
985 private static final String _SQL_SELECT_RATINGSSTATS = "SELECT ratingsStats FROM RatingsStats ratingsStats";
986 private static final String _SQL_SELECT_RATINGSSTATS_WHERE_PKS_IN = "SELECT ratingsStats FROM RatingsStats ratingsStats WHERE statsId IN (";
987 private static final String _SQL_SELECT_RATINGSSTATS_WHERE = "SELECT ratingsStats FROM RatingsStats ratingsStats WHERE ";
988 private static final String _SQL_COUNT_RATINGSSTATS = "SELECT COUNT(ratingsStats) FROM RatingsStats ratingsStats";
989 private static final String _SQL_COUNT_RATINGSSTATS_WHERE = "SELECT COUNT(ratingsStats) FROM RatingsStats ratingsStats WHERE ";
990 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsStats.";
991 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsStats exists with the primary key ";
992 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsStats exists with the key {";
993 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
994 private static final Log _log = LogFactoryUtil.getLog(RatingsStatsPersistenceImpl.class);
995 private static final RatingsStats _nullRatingsStats = new RatingsStatsImpl() {
996 @Override
997 public Object clone() {
998 return this;
999 }
1000
1001 @Override
1002 public CacheModel<RatingsStats> toCacheModel() {
1003 return _nullRatingsStatsCacheModel;
1004 }
1005 };
1006
1007 private static final CacheModel<RatingsStats> _nullRatingsStatsCacheModel = new CacheModel<RatingsStats>() {
1008 @Override
1009 public RatingsStats toEntityModel() {
1010 return _nullRatingsStats;
1011 }
1012 };
1013 }