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.NoSuchEntryException;
040 import com.liferay.portlet.ratings.model.RatingsEntry;
041 import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
042 import com.liferay.portlet.ratings.model.impl.RatingsEntryModelImpl;
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 RatingsEntryPersistenceImpl extends BasePersistenceImpl<RatingsEntry>
063 implements RatingsEntryPersistence {
064
069 public static final String FINDER_CLASS_NAME_ENTITY = RatingsEntryImpl.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(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
075 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.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(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
078 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
079 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
080 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
081 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
083 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
084 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
085 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
086 new String[] {
087 Long.class.getName(), Long.class.getName(),
088
089 Integer.class.getName(), Integer.class.getName(),
090 OrderByComparator.class.getName()
091 });
092 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
093 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
094 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
095 new String[] { Long.class.getName(), Long.class.getName() },
096 RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
097 RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK);
098 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
099 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
100 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
101 new String[] { Long.class.getName(), Long.class.getName() });
102
103
111 public List<RatingsEntry> findByC_C(long classNameId, long classPK)
112 throws SystemException {
113 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
114 QueryUtil.ALL_POS, null);
115 }
116
117
131 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
132 int start, int end) throws SystemException {
133 return findByC_C(classNameId, classPK, start, end, null);
134 }
135
136
151 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
152 int start, int end, OrderByComparator orderByComparator)
153 throws SystemException {
154 boolean pagination = true;
155 FinderPath finderPath = null;
156 Object[] finderArgs = null;
157
158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159 (orderByComparator == null)) {
160 pagination = false;
161 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
162 finderArgs = new Object[] { classNameId, classPK };
163 }
164 else {
165 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
166 finderArgs = new Object[] {
167 classNameId, classPK,
168
169 start, end, orderByComparator
170 };
171 }
172
173 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
174 finderArgs, this);
175
176 if ((list != null) && !list.isEmpty()) {
177 for (RatingsEntry ratingsEntry : list) {
178 if ((classNameId != ratingsEntry.getClassNameId()) ||
179 (classPK != ratingsEntry.getClassPK())) {
180 list = null;
181
182 break;
183 }
184 }
185 }
186
187 if (list == null) {
188 StringBundler query = null;
189
190 if (orderByComparator != null) {
191 query = new StringBundler(4 +
192 (orderByComparator.getOrderByFields().length * 3));
193 }
194 else {
195 query = new StringBundler(4);
196 }
197
198 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
199
200 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
201
202 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
203
204 if (orderByComparator != null) {
205 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
206 orderByComparator);
207 }
208 else
209 if (pagination) {
210 query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
211 }
212
213 String sql = query.toString();
214
215 Session session = null;
216
217 try {
218 session = openSession();
219
220 Query q = session.createQuery(sql);
221
222 QueryPos qPos = QueryPos.getInstance(q);
223
224 qPos.add(classNameId);
225
226 qPos.add(classPK);
227
228 if (!pagination) {
229 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
230 start, end, false);
231
232 Collections.sort(list);
233
234 list = new UnmodifiableList<RatingsEntry>(list);
235 }
236 else {
237 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
238 start, end);
239 }
240
241 cacheResult(list);
242
243 FinderCacheUtil.putResult(finderPath, finderArgs, list);
244 }
245 catch (Exception e) {
246 FinderCacheUtil.removeResult(finderPath, finderArgs);
247
248 throw processException(e);
249 }
250 finally {
251 closeSession(session);
252 }
253 }
254
255 return list;
256 }
257
258
268 public RatingsEntry findByC_C_First(long classNameId, long classPK,
269 OrderByComparator orderByComparator)
270 throws NoSuchEntryException, SystemException {
271 RatingsEntry ratingsEntry = fetchByC_C_First(classNameId, classPK,
272 orderByComparator);
273
274 if (ratingsEntry != null) {
275 return ratingsEntry;
276 }
277
278 StringBundler msg = new StringBundler(6);
279
280 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
281
282 msg.append("classNameId=");
283 msg.append(classNameId);
284
285 msg.append(", classPK=");
286 msg.append(classPK);
287
288 msg.append(StringPool.CLOSE_CURLY_BRACE);
289
290 throw new NoSuchEntryException(msg.toString());
291 }
292
293
302 public RatingsEntry fetchByC_C_First(long classNameId, long classPK,
303 OrderByComparator orderByComparator) throws SystemException {
304 List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
305 orderByComparator);
306
307 if (!list.isEmpty()) {
308 return list.get(0);
309 }
310
311 return null;
312 }
313
314
324 public RatingsEntry findByC_C_Last(long classNameId, long classPK,
325 OrderByComparator orderByComparator)
326 throws NoSuchEntryException, SystemException {
327 RatingsEntry ratingsEntry = fetchByC_C_Last(classNameId, classPK,
328 orderByComparator);
329
330 if (ratingsEntry != null) {
331 return ratingsEntry;
332 }
333
334 StringBundler msg = new StringBundler(6);
335
336 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337
338 msg.append("classNameId=");
339 msg.append(classNameId);
340
341 msg.append(", classPK=");
342 msg.append(classPK);
343
344 msg.append(StringPool.CLOSE_CURLY_BRACE);
345
346 throw new NoSuchEntryException(msg.toString());
347 }
348
349
358 public RatingsEntry fetchByC_C_Last(long classNameId, long classPK,
359 OrderByComparator orderByComparator) throws SystemException {
360 int count = countByC_C(classNameId, classPK);
361
362 List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
363 count, orderByComparator);
364
365 if (!list.isEmpty()) {
366 return list.get(0);
367 }
368
369 return null;
370 }
371
372
383 public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
384 long classPK, OrderByComparator orderByComparator)
385 throws NoSuchEntryException, SystemException {
386 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
387
388 Session session = null;
389
390 try {
391 session = openSession();
392
393 RatingsEntry[] array = new RatingsEntryImpl[3];
394
395 array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
396 classPK, orderByComparator, true);
397
398 array[1] = ratingsEntry;
399
400 array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
401 classPK, orderByComparator, false);
402
403 return array;
404 }
405 catch (Exception e) {
406 throw processException(e);
407 }
408 finally {
409 closeSession(session);
410 }
411 }
412
413 protected RatingsEntry getByC_C_PrevAndNext(Session session,
414 RatingsEntry ratingsEntry, long classNameId, long classPK,
415 OrderByComparator orderByComparator, boolean previous) {
416 StringBundler query = null;
417
418 if (orderByComparator != null) {
419 query = new StringBundler(6 +
420 (orderByComparator.getOrderByFields().length * 6));
421 }
422 else {
423 query = new StringBundler(3);
424 }
425
426 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
427
428 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
429
430 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
431
432 if (orderByComparator != null) {
433 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
434
435 if (orderByConditionFields.length > 0) {
436 query.append(WHERE_AND);
437 }
438
439 for (int i = 0; i < orderByConditionFields.length; i++) {
440 query.append(_ORDER_BY_ENTITY_ALIAS);
441 query.append(orderByConditionFields[i]);
442
443 if ((i + 1) < orderByConditionFields.length) {
444 if (orderByComparator.isAscending() ^ previous) {
445 query.append(WHERE_GREATER_THAN_HAS_NEXT);
446 }
447 else {
448 query.append(WHERE_LESSER_THAN_HAS_NEXT);
449 }
450 }
451 else {
452 if (orderByComparator.isAscending() ^ previous) {
453 query.append(WHERE_GREATER_THAN);
454 }
455 else {
456 query.append(WHERE_LESSER_THAN);
457 }
458 }
459 }
460
461 query.append(ORDER_BY_CLAUSE);
462
463 String[] orderByFields = orderByComparator.getOrderByFields();
464
465 for (int i = 0; i < orderByFields.length; i++) {
466 query.append(_ORDER_BY_ENTITY_ALIAS);
467 query.append(orderByFields[i]);
468
469 if ((i + 1) < orderByFields.length) {
470 if (orderByComparator.isAscending() ^ previous) {
471 query.append(ORDER_BY_ASC_HAS_NEXT);
472 }
473 else {
474 query.append(ORDER_BY_DESC_HAS_NEXT);
475 }
476 }
477 else {
478 if (orderByComparator.isAscending() ^ previous) {
479 query.append(ORDER_BY_ASC);
480 }
481 else {
482 query.append(ORDER_BY_DESC);
483 }
484 }
485 }
486 }
487 else {
488 query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
489 }
490
491 String sql = query.toString();
492
493 Query q = session.createQuery(sql);
494
495 q.setFirstResult(0);
496 q.setMaxResults(2);
497
498 QueryPos qPos = QueryPos.getInstance(q);
499
500 qPos.add(classNameId);
501
502 qPos.add(classPK);
503
504 if (orderByComparator != null) {
505 Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
506
507 for (Object value : values) {
508 qPos.add(value);
509 }
510 }
511
512 List<RatingsEntry> list = q.list();
513
514 if (list.size() == 2) {
515 return list.get(1);
516 }
517 else {
518 return null;
519 }
520 }
521
522
529 public void removeByC_C(long classNameId, long classPK)
530 throws SystemException {
531 for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK,
532 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
533 remove(ratingsEntry);
534 }
535 }
536
537
545 public int countByC_C(long classNameId, long classPK)
546 throws SystemException {
547 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
548
549 Object[] finderArgs = new Object[] { classNameId, classPK };
550
551 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
552 this);
553
554 if (count == null) {
555 StringBundler query = new StringBundler(3);
556
557 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
558
559 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
560
561 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
562
563 String sql = query.toString();
564
565 Session session = null;
566
567 try {
568 session = openSession();
569
570 Query q = session.createQuery(sql);
571
572 QueryPos qPos = QueryPos.getInstance(q);
573
574 qPos.add(classNameId);
575
576 qPos.add(classPK);
577
578 count = (Long)q.uniqueResult();
579
580 FinderCacheUtil.putResult(finderPath, finderArgs, count);
581 }
582 catch (Exception e) {
583 FinderCacheUtil.removeResult(finderPath, finderArgs);
584
585 throw processException(e);
586 }
587 finally {
588 closeSession(session);
589 }
590 }
591
592 return count.intValue();
593 }
594
595 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
596 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
597 public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
598 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
599 FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C",
600 new String[] {
601 Long.class.getName(), Long.class.getName(), Long.class.getName()
602 },
603 RatingsEntryModelImpl.USERID_COLUMN_BITMASK |
604 RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
605 RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK);
606 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
607 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
608 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
609 new String[] {
610 Long.class.getName(), Long.class.getName(), Long.class.getName()
611 });
612
613
623 public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
624 throws NoSuchEntryException, SystemException {
625 RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
626
627 if (ratingsEntry == null) {
628 StringBundler msg = new StringBundler(8);
629
630 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
631
632 msg.append("userId=");
633 msg.append(userId);
634
635 msg.append(", classNameId=");
636 msg.append(classNameId);
637
638 msg.append(", classPK=");
639 msg.append(classPK);
640
641 msg.append(StringPool.CLOSE_CURLY_BRACE);
642
643 if (_log.isWarnEnabled()) {
644 _log.warn(msg.toString());
645 }
646
647 throw new NoSuchEntryException(msg.toString());
648 }
649
650 return ratingsEntry;
651 }
652
653
662 public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
663 throws SystemException {
664 return fetchByU_C_C(userId, classNameId, classPK, true);
665 }
666
667
677 public RatingsEntry fetchByU_C_C(long userId, long classNameId,
678 long classPK, boolean retrieveFromCache) throws SystemException {
679 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
680
681 Object result = null;
682
683 if (retrieveFromCache) {
684 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
685 finderArgs, this);
686 }
687
688 if (result instanceof RatingsEntry) {
689 RatingsEntry ratingsEntry = (RatingsEntry)result;
690
691 if ((userId != ratingsEntry.getUserId()) ||
692 (classNameId != ratingsEntry.getClassNameId()) ||
693 (classPK != ratingsEntry.getClassPK())) {
694 result = null;
695 }
696 }
697
698 if (result == null) {
699 StringBundler query = new StringBundler(5);
700
701 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
702
703 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
704
705 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
706
707 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
708
709 String sql = query.toString();
710
711 Session session = null;
712
713 try {
714 session = openSession();
715
716 Query q = session.createQuery(sql);
717
718 QueryPos qPos = QueryPos.getInstance(q);
719
720 qPos.add(userId);
721
722 qPos.add(classNameId);
723
724 qPos.add(classPK);
725
726 List<RatingsEntry> list = q.list();
727
728 if (list.isEmpty()) {
729 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
730 finderArgs, list);
731 }
732 else {
733 RatingsEntry ratingsEntry = list.get(0);
734
735 result = ratingsEntry;
736
737 cacheResult(ratingsEntry);
738
739 if ((ratingsEntry.getUserId() != userId) ||
740 (ratingsEntry.getClassNameId() != classNameId) ||
741 (ratingsEntry.getClassPK() != classPK)) {
742 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
743 finderArgs, ratingsEntry);
744 }
745 }
746 }
747 catch (Exception e) {
748 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
749 finderArgs);
750
751 throw processException(e);
752 }
753 finally {
754 closeSession(session);
755 }
756 }
757
758 if (result instanceof List<?>) {
759 return null;
760 }
761 else {
762 return (RatingsEntry)result;
763 }
764 }
765
766
775 public RatingsEntry removeByU_C_C(long userId, long classNameId,
776 long classPK) throws NoSuchEntryException, SystemException {
777 RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
778
779 return remove(ratingsEntry);
780 }
781
782
791 public int countByU_C_C(long userId, long classNameId, long classPK)
792 throws SystemException {
793 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
794
795 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
796
797 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
798 this);
799
800 if (count == null) {
801 StringBundler query = new StringBundler(4);
802
803 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
804
805 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
806
807 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
808
809 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
810
811 String sql = query.toString();
812
813 Session session = null;
814
815 try {
816 session = openSession();
817
818 Query q = session.createQuery(sql);
819
820 QueryPos qPos = QueryPos.getInstance(q);
821
822 qPos.add(userId);
823
824 qPos.add(classNameId);
825
826 qPos.add(classPK);
827
828 count = (Long)q.uniqueResult();
829
830 FinderCacheUtil.putResult(finderPath, finderArgs, count);
831 }
832 catch (Exception e) {
833 FinderCacheUtil.removeResult(finderPath, finderArgs);
834
835 throw processException(e);
836 }
837 finally {
838 closeSession(session);
839 }
840 }
841
842 return count.intValue();
843 }
844
845 private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
846 private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
847 private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
848 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
849 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
850 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
851 new String[] {
852 Long.class.getName(), Long.class.getName(),
853 Double.class.getName(),
854
855 Integer.class.getName(), Integer.class.getName(),
856 OrderByComparator.class.getName()
857 });
858 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
859 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
860 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
861 new String[] {
862 Long.class.getName(), Long.class.getName(),
863 Double.class.getName()
864 },
865 RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
866 RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK |
867 RatingsEntryModelImpl.SCORE_COLUMN_BITMASK);
868 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
869 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
870 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
871 new String[] {
872 Long.class.getName(), Long.class.getName(),
873 Double.class.getName()
874 });
875
876
885 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
886 double score) throws SystemException {
887 return findByC_C_S(classNameId, classPK, score, QueryUtil.ALL_POS,
888 QueryUtil.ALL_POS, null);
889 }
890
891
906 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
907 double score, int start, int end) throws SystemException {
908 return findByC_C_S(classNameId, classPK, score, start, end, null);
909 }
910
911
927 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
928 double score, int start, int end, OrderByComparator orderByComparator)
929 throws SystemException {
930 boolean pagination = true;
931 FinderPath finderPath = null;
932 Object[] finderArgs = null;
933
934 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
935 (orderByComparator == null)) {
936 pagination = false;
937 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
938 finderArgs = new Object[] { classNameId, classPK, score };
939 }
940 else {
941 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
942 finderArgs = new Object[] {
943 classNameId, classPK, score,
944
945 start, end, orderByComparator
946 };
947 }
948
949 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
950 finderArgs, this);
951
952 if ((list != null) && !list.isEmpty()) {
953 for (RatingsEntry ratingsEntry : list) {
954 if ((classNameId != ratingsEntry.getClassNameId()) ||
955 (classPK != ratingsEntry.getClassPK()) ||
956 (score != ratingsEntry.getScore())) {
957 list = null;
958
959 break;
960 }
961 }
962 }
963
964 if (list == null) {
965 StringBundler query = null;
966
967 if (orderByComparator != null) {
968 query = new StringBundler(5 +
969 (orderByComparator.getOrderByFields().length * 3));
970 }
971 else {
972 query = new StringBundler(5);
973 }
974
975 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
976
977 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
978
979 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
980
981 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
982
983 if (orderByComparator != null) {
984 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
985 orderByComparator);
986 }
987 else
988 if (pagination) {
989 query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
990 }
991
992 String sql = query.toString();
993
994 Session session = null;
995
996 try {
997 session = openSession();
998
999 Query q = session.createQuery(sql);
1000
1001 QueryPos qPos = QueryPos.getInstance(q);
1002
1003 qPos.add(classNameId);
1004
1005 qPos.add(classPK);
1006
1007 qPos.add(score);
1008
1009 if (!pagination) {
1010 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1011 start, end, false);
1012
1013 Collections.sort(list);
1014
1015 list = new UnmodifiableList<RatingsEntry>(list);
1016 }
1017 else {
1018 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1019 start, end);
1020 }
1021
1022 cacheResult(list);
1023
1024 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1025 }
1026 catch (Exception e) {
1027 FinderCacheUtil.removeResult(finderPath, finderArgs);
1028
1029 throw processException(e);
1030 }
1031 finally {
1032 closeSession(session);
1033 }
1034 }
1035
1036 return list;
1037 }
1038
1039
1050 public RatingsEntry findByC_C_S_First(long classNameId, long classPK,
1051 double score, OrderByComparator orderByComparator)
1052 throws NoSuchEntryException, SystemException {
1053 RatingsEntry ratingsEntry = fetchByC_C_S_First(classNameId, classPK,
1054 score, orderByComparator);
1055
1056 if (ratingsEntry != null) {
1057 return ratingsEntry;
1058 }
1059
1060 StringBundler msg = new StringBundler(8);
1061
1062 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1063
1064 msg.append("classNameId=");
1065 msg.append(classNameId);
1066
1067 msg.append(", classPK=");
1068 msg.append(classPK);
1069
1070 msg.append(", score=");
1071 msg.append(score);
1072
1073 msg.append(StringPool.CLOSE_CURLY_BRACE);
1074
1075 throw new NoSuchEntryException(msg.toString());
1076 }
1077
1078
1088 public RatingsEntry fetchByC_C_S_First(long classNameId, long classPK,
1089 double score, OrderByComparator orderByComparator)
1090 throws SystemException {
1091 List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score, 0,
1092 1, orderByComparator);
1093
1094 if (!list.isEmpty()) {
1095 return list.get(0);
1096 }
1097
1098 return null;
1099 }
1100
1101
1112 public RatingsEntry findByC_C_S_Last(long classNameId, long classPK,
1113 double score, OrderByComparator orderByComparator)
1114 throws NoSuchEntryException, SystemException {
1115 RatingsEntry ratingsEntry = fetchByC_C_S_Last(classNameId, classPK,
1116 score, orderByComparator);
1117
1118 if (ratingsEntry != null) {
1119 return ratingsEntry;
1120 }
1121
1122 StringBundler msg = new StringBundler(8);
1123
1124 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1125
1126 msg.append("classNameId=");
1127 msg.append(classNameId);
1128
1129 msg.append(", classPK=");
1130 msg.append(classPK);
1131
1132 msg.append(", score=");
1133 msg.append(score);
1134
1135 msg.append(StringPool.CLOSE_CURLY_BRACE);
1136
1137 throw new NoSuchEntryException(msg.toString());
1138 }
1139
1140
1150 public RatingsEntry fetchByC_C_S_Last(long classNameId, long classPK,
1151 double score, OrderByComparator orderByComparator)
1152 throws SystemException {
1153 int count = countByC_C_S(classNameId, classPK, score);
1154
1155 List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score,
1156 count - 1, count, orderByComparator);
1157
1158 if (!list.isEmpty()) {
1159 return list.get(0);
1160 }
1161
1162 return null;
1163 }
1164
1165
1177 public RatingsEntry[] findByC_C_S_PrevAndNext(long entryId,
1178 long classNameId, long classPK, double score,
1179 OrderByComparator orderByComparator)
1180 throws NoSuchEntryException, SystemException {
1181 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
1182
1183 Session session = null;
1184
1185 try {
1186 session = openSession();
1187
1188 RatingsEntry[] array = new RatingsEntryImpl[3];
1189
1190 array[0] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1191 classNameId, classPK, score, orderByComparator, true);
1192
1193 array[1] = ratingsEntry;
1194
1195 array[2] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1196 classNameId, classPK, score, orderByComparator, false);
1197
1198 return array;
1199 }
1200 catch (Exception e) {
1201 throw processException(e);
1202 }
1203 finally {
1204 closeSession(session);
1205 }
1206 }
1207
1208 protected RatingsEntry getByC_C_S_PrevAndNext(Session session,
1209 RatingsEntry ratingsEntry, long classNameId, long classPK,
1210 double score, OrderByComparator orderByComparator, boolean previous) {
1211 StringBundler query = null;
1212
1213 if (orderByComparator != null) {
1214 query = new StringBundler(6 +
1215 (orderByComparator.getOrderByFields().length * 6));
1216 }
1217 else {
1218 query = new StringBundler(3);
1219 }
1220
1221 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1222
1223 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1224
1225 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1226
1227 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1228
1229 if (orderByComparator != null) {
1230 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1231
1232 if (orderByConditionFields.length > 0) {
1233 query.append(WHERE_AND);
1234 }
1235
1236 for (int i = 0; i < orderByConditionFields.length; i++) {
1237 query.append(_ORDER_BY_ENTITY_ALIAS);
1238 query.append(orderByConditionFields[i]);
1239
1240 if ((i + 1) < orderByConditionFields.length) {
1241 if (orderByComparator.isAscending() ^ previous) {
1242 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1243 }
1244 else {
1245 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1246 }
1247 }
1248 else {
1249 if (orderByComparator.isAscending() ^ previous) {
1250 query.append(WHERE_GREATER_THAN);
1251 }
1252 else {
1253 query.append(WHERE_LESSER_THAN);
1254 }
1255 }
1256 }
1257
1258 query.append(ORDER_BY_CLAUSE);
1259
1260 String[] orderByFields = orderByComparator.getOrderByFields();
1261
1262 for (int i = 0; i < orderByFields.length; i++) {
1263 query.append(_ORDER_BY_ENTITY_ALIAS);
1264 query.append(orderByFields[i]);
1265
1266 if ((i + 1) < orderByFields.length) {
1267 if (orderByComparator.isAscending() ^ previous) {
1268 query.append(ORDER_BY_ASC_HAS_NEXT);
1269 }
1270 else {
1271 query.append(ORDER_BY_DESC_HAS_NEXT);
1272 }
1273 }
1274 else {
1275 if (orderByComparator.isAscending() ^ previous) {
1276 query.append(ORDER_BY_ASC);
1277 }
1278 else {
1279 query.append(ORDER_BY_DESC);
1280 }
1281 }
1282 }
1283 }
1284 else {
1285 query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
1286 }
1287
1288 String sql = query.toString();
1289
1290 Query q = session.createQuery(sql);
1291
1292 q.setFirstResult(0);
1293 q.setMaxResults(2);
1294
1295 QueryPos qPos = QueryPos.getInstance(q);
1296
1297 qPos.add(classNameId);
1298
1299 qPos.add(classPK);
1300
1301 qPos.add(score);
1302
1303 if (orderByComparator != null) {
1304 Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
1305
1306 for (Object value : values) {
1307 qPos.add(value);
1308 }
1309 }
1310
1311 List<RatingsEntry> list = q.list();
1312
1313 if (list.size() == 2) {
1314 return list.get(1);
1315 }
1316 else {
1317 return null;
1318 }
1319 }
1320
1321
1329 public void removeByC_C_S(long classNameId, long classPK, double score)
1330 throws SystemException {
1331 for (RatingsEntry ratingsEntry : findByC_C_S(classNameId, classPK,
1332 score, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1333 remove(ratingsEntry);
1334 }
1335 }
1336
1337
1346 public int countByC_C_S(long classNameId, long classPK, double score)
1347 throws SystemException {
1348 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
1349
1350 Object[] finderArgs = new Object[] { classNameId, classPK, score };
1351
1352 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1353 this);
1354
1355 if (count == null) {
1356 StringBundler query = new StringBundler(4);
1357
1358 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1359
1360 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1361
1362 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1363
1364 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1365
1366 String sql = query.toString();
1367
1368 Session session = null;
1369
1370 try {
1371 session = openSession();
1372
1373 Query q = session.createQuery(sql);
1374
1375 QueryPos qPos = QueryPos.getInstance(q);
1376
1377 qPos.add(classNameId);
1378
1379 qPos.add(classPK);
1380
1381 qPos.add(score);
1382
1383 count = (Long)q.uniqueResult();
1384
1385 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1386 }
1387 catch (Exception e) {
1388 FinderCacheUtil.removeResult(finderPath, finderArgs);
1389
1390 throw processException(e);
1391 }
1392 finally {
1393 closeSession(session);
1394 }
1395 }
1396
1397 return count.intValue();
1398 }
1399
1400 private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1401 private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "ratingsEntry.classPK = ? AND ";
1402 private static final String _FINDER_COLUMN_C_C_S_SCORE_2 = "ratingsEntry.score = ?";
1403
1404
1409 public void cacheResult(RatingsEntry ratingsEntry) {
1410 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1411 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
1412
1413 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1414 new Object[] {
1415 ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
1416 ratingsEntry.getClassPK()
1417 }, ratingsEntry);
1418
1419 ratingsEntry.resetOriginalValues();
1420 }
1421
1422
1427 public void cacheResult(List<RatingsEntry> ratingsEntries) {
1428 for (RatingsEntry ratingsEntry : ratingsEntries) {
1429 if (EntityCacheUtil.getResult(
1430 RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1431 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey()) == null) {
1432 cacheResult(ratingsEntry);
1433 }
1434 else {
1435 ratingsEntry.resetOriginalValues();
1436 }
1437 }
1438 }
1439
1440
1447 @Override
1448 public void clearCache() {
1449 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1450 CacheRegistryUtil.clear(RatingsEntryImpl.class.getName());
1451 }
1452
1453 EntityCacheUtil.clearCache(RatingsEntryImpl.class.getName());
1454
1455 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1456 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1457 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1458 }
1459
1460
1467 @Override
1468 public void clearCache(RatingsEntry ratingsEntry) {
1469 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1470 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
1471
1472 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1473 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1474
1475 clearUniqueFindersCache(ratingsEntry);
1476 }
1477
1478 @Override
1479 public void clearCache(List<RatingsEntry> ratingsEntries) {
1480 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1481 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1482
1483 for (RatingsEntry ratingsEntry : ratingsEntries) {
1484 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1485 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
1486
1487 clearUniqueFindersCache(ratingsEntry);
1488 }
1489 }
1490
1491 protected void cacheUniqueFindersCache(RatingsEntry ratingsEntry) {
1492 if (ratingsEntry.isNew()) {
1493 Object[] args = new Object[] {
1494 ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
1495 ratingsEntry.getClassPK()
1496 };
1497
1498 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C, args,
1499 Long.valueOf(1));
1500 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C, args,
1501 ratingsEntry);
1502 }
1503 else {
1504 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
1505
1506 if ((ratingsEntryModelImpl.getColumnBitmask() &
1507 FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
1508 Object[] args = new Object[] {
1509 ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
1510 ratingsEntry.getClassPK()
1511 };
1512
1513 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C, args,
1514 Long.valueOf(1));
1515 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C, args,
1516 ratingsEntry);
1517 }
1518 }
1519 }
1520
1521 protected void clearUniqueFindersCache(RatingsEntry ratingsEntry) {
1522 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
1523
1524 Object[] args = new Object[] {
1525 ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
1526 ratingsEntry.getClassPK()
1527 };
1528
1529 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1530 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
1531
1532 if ((ratingsEntryModelImpl.getColumnBitmask() &
1533 FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
1534 args = new Object[] {
1535 ratingsEntryModelImpl.getOriginalUserId(),
1536 ratingsEntryModelImpl.getOriginalClassNameId(),
1537 ratingsEntryModelImpl.getOriginalClassPK()
1538 };
1539
1540 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1541 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
1542 }
1543 }
1544
1545
1551 public RatingsEntry create(long entryId) {
1552 RatingsEntry ratingsEntry = new RatingsEntryImpl();
1553
1554 ratingsEntry.setNew(true);
1555 ratingsEntry.setPrimaryKey(entryId);
1556
1557 return ratingsEntry;
1558 }
1559
1560
1568 public RatingsEntry remove(long entryId)
1569 throws NoSuchEntryException, SystemException {
1570 return remove((Serializable)entryId);
1571 }
1572
1573
1581 @Override
1582 public RatingsEntry remove(Serializable primaryKey)
1583 throws NoSuchEntryException, SystemException {
1584 Session session = null;
1585
1586 try {
1587 session = openSession();
1588
1589 RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
1590 primaryKey);
1591
1592 if (ratingsEntry == null) {
1593 if (_log.isWarnEnabled()) {
1594 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1595 }
1596
1597 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1598 primaryKey);
1599 }
1600
1601 return remove(ratingsEntry);
1602 }
1603 catch (NoSuchEntryException nsee) {
1604 throw nsee;
1605 }
1606 catch (Exception e) {
1607 throw processException(e);
1608 }
1609 finally {
1610 closeSession(session);
1611 }
1612 }
1613
1614 @Override
1615 protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
1616 throws SystemException {
1617 ratingsEntry = toUnwrappedModel(ratingsEntry);
1618
1619 Session session = null;
1620
1621 try {
1622 session = openSession();
1623
1624 if (!session.contains(ratingsEntry)) {
1625 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
1626 ratingsEntry.getPrimaryKeyObj());
1627 }
1628
1629 if (ratingsEntry != null) {
1630 session.delete(ratingsEntry);
1631 }
1632 }
1633 catch (Exception e) {
1634 throw processException(e);
1635 }
1636 finally {
1637 closeSession(session);
1638 }
1639
1640 if (ratingsEntry != null) {
1641 clearCache(ratingsEntry);
1642 }
1643
1644 return ratingsEntry;
1645 }
1646
1647 @Override
1648 public RatingsEntry updateImpl(
1649 com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry)
1650 throws SystemException {
1651 ratingsEntry = toUnwrappedModel(ratingsEntry);
1652
1653 boolean isNew = ratingsEntry.isNew();
1654
1655 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
1656
1657 Session session = null;
1658
1659 try {
1660 session = openSession();
1661
1662 if (ratingsEntry.isNew()) {
1663 session.save(ratingsEntry);
1664
1665 ratingsEntry.setNew(false);
1666 }
1667 else {
1668 session.merge(ratingsEntry);
1669 }
1670 }
1671 catch (Exception e) {
1672 throw processException(e);
1673 }
1674 finally {
1675 closeSession(session);
1676 }
1677
1678 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1679
1680 if (isNew || !RatingsEntryModelImpl.COLUMN_BITMASK_ENABLED) {
1681 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1682 }
1683
1684 else {
1685 if ((ratingsEntryModelImpl.getColumnBitmask() &
1686 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1687 Object[] args = new Object[] {
1688 ratingsEntryModelImpl.getOriginalClassNameId(),
1689 ratingsEntryModelImpl.getOriginalClassPK()
1690 };
1691
1692 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1693 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1694 args);
1695
1696 args = new Object[] {
1697 ratingsEntryModelImpl.getClassNameId(),
1698 ratingsEntryModelImpl.getClassPK()
1699 };
1700
1701 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1702 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1703 args);
1704 }
1705
1706 if ((ratingsEntryModelImpl.getColumnBitmask() &
1707 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
1708 Object[] args = new Object[] {
1709 ratingsEntryModelImpl.getOriginalClassNameId(),
1710 ratingsEntryModelImpl.getOriginalClassPK(),
1711 ratingsEntryModelImpl.getOriginalScore()
1712 };
1713
1714 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1715 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1716 args);
1717
1718 args = new Object[] {
1719 ratingsEntryModelImpl.getClassNameId(),
1720 ratingsEntryModelImpl.getClassPK(),
1721 ratingsEntryModelImpl.getScore()
1722 };
1723
1724 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1725 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1726 args);
1727 }
1728 }
1729
1730 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1731 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
1732
1733 clearUniqueFindersCache(ratingsEntry);
1734 cacheUniqueFindersCache(ratingsEntry);
1735
1736 return ratingsEntry;
1737 }
1738
1739 protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
1740 if (ratingsEntry instanceof RatingsEntryImpl) {
1741 return ratingsEntry;
1742 }
1743
1744 RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
1745
1746 ratingsEntryImpl.setNew(ratingsEntry.isNew());
1747 ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
1748
1749 ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
1750 ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
1751 ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
1752 ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
1753 ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
1754 ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
1755 ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
1756 ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
1757 ratingsEntryImpl.setScore(ratingsEntry.getScore());
1758
1759 return ratingsEntryImpl;
1760 }
1761
1762
1770 @Override
1771 public RatingsEntry findByPrimaryKey(Serializable primaryKey)
1772 throws NoSuchEntryException, SystemException {
1773 RatingsEntry ratingsEntry = fetchByPrimaryKey(primaryKey);
1774
1775 if (ratingsEntry == null) {
1776 if (_log.isWarnEnabled()) {
1777 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1778 }
1779
1780 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1781 primaryKey);
1782 }
1783
1784 return ratingsEntry;
1785 }
1786
1787
1795 public RatingsEntry findByPrimaryKey(long entryId)
1796 throws NoSuchEntryException, SystemException {
1797 return findByPrimaryKey((Serializable)entryId);
1798 }
1799
1800
1807 @Override
1808 public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
1809 throws SystemException {
1810 RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1811 RatingsEntryImpl.class, primaryKey);
1812
1813 if (ratingsEntry == _nullRatingsEntry) {
1814 return null;
1815 }
1816
1817 if (ratingsEntry == null) {
1818 Session session = null;
1819
1820 try {
1821 session = openSession();
1822
1823 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
1824 primaryKey);
1825
1826 if (ratingsEntry != null) {
1827 cacheResult(ratingsEntry);
1828 }
1829 else {
1830 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1831 RatingsEntryImpl.class, primaryKey, _nullRatingsEntry);
1832 }
1833 }
1834 catch (Exception e) {
1835 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1836 RatingsEntryImpl.class, primaryKey);
1837
1838 throw processException(e);
1839 }
1840 finally {
1841 closeSession(session);
1842 }
1843 }
1844
1845 return ratingsEntry;
1846 }
1847
1848
1855 public RatingsEntry fetchByPrimaryKey(long entryId)
1856 throws SystemException {
1857 return fetchByPrimaryKey((Serializable)entryId);
1858 }
1859
1860
1866 public List<RatingsEntry> findAll() throws SystemException {
1867 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1868 }
1869
1870
1882 public List<RatingsEntry> findAll(int start, int end)
1883 throws SystemException {
1884 return findAll(start, end, null);
1885 }
1886
1887
1900 public List<RatingsEntry> findAll(int start, int end,
1901 OrderByComparator orderByComparator) throws SystemException {
1902 boolean pagination = true;
1903 FinderPath finderPath = null;
1904 Object[] finderArgs = null;
1905
1906 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1907 (orderByComparator == null)) {
1908 pagination = false;
1909 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1910 finderArgs = FINDER_ARGS_EMPTY;
1911 }
1912 else {
1913 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1914 finderArgs = new Object[] { start, end, orderByComparator };
1915 }
1916
1917 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1918 finderArgs, this);
1919
1920 if (list == null) {
1921 StringBundler query = null;
1922 String sql = null;
1923
1924 if (orderByComparator != null) {
1925 query = new StringBundler(2 +
1926 (orderByComparator.getOrderByFields().length * 3));
1927
1928 query.append(_SQL_SELECT_RATINGSENTRY);
1929
1930 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1931 orderByComparator);
1932
1933 sql = query.toString();
1934 }
1935 else {
1936 sql = _SQL_SELECT_RATINGSENTRY;
1937
1938 if (pagination) {
1939 sql = sql.concat(RatingsEntryModelImpl.ORDER_BY_JPQL);
1940 }
1941 }
1942
1943 Session session = null;
1944
1945 try {
1946 session = openSession();
1947
1948 Query q = session.createQuery(sql);
1949
1950 if (!pagination) {
1951 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1952 start, end, false);
1953
1954 Collections.sort(list);
1955
1956 list = new UnmodifiableList<RatingsEntry>(list);
1957 }
1958 else {
1959 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1960 start, end);
1961 }
1962
1963 cacheResult(list);
1964
1965 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1966 }
1967 catch (Exception e) {
1968 FinderCacheUtil.removeResult(finderPath, finderArgs);
1969
1970 throw processException(e);
1971 }
1972 finally {
1973 closeSession(session);
1974 }
1975 }
1976
1977 return list;
1978 }
1979
1980
1985 public void removeAll() throws SystemException {
1986 for (RatingsEntry ratingsEntry : findAll()) {
1987 remove(ratingsEntry);
1988 }
1989 }
1990
1991
1997 public int countAll() throws SystemException {
1998 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1999 FINDER_ARGS_EMPTY, this);
2000
2001 if (count == null) {
2002 Session session = null;
2003
2004 try {
2005 session = openSession();
2006
2007 Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
2008
2009 count = (Long)q.uniqueResult();
2010
2011 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2012 FINDER_ARGS_EMPTY, count);
2013 }
2014 catch (Exception e) {
2015 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2016 FINDER_ARGS_EMPTY);
2017
2018 throw processException(e);
2019 }
2020 finally {
2021 closeSession(session);
2022 }
2023 }
2024
2025 return count.intValue();
2026 }
2027
2028
2031 public void afterPropertiesSet() {
2032 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2033 com.liferay.portal.util.PropsUtil.get(
2034 "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
2035
2036 if (listenerClassNames.length > 0) {
2037 try {
2038 List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
2039
2040 for (String listenerClassName : listenerClassNames) {
2041 listenersList.add((ModelListener<RatingsEntry>)InstanceFactory.newInstance(
2042 getClassLoader(), listenerClassName));
2043 }
2044
2045 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2046 }
2047 catch (Exception e) {
2048 _log.error(e);
2049 }
2050 }
2051 }
2052
2053 public void destroy() {
2054 EntityCacheUtil.removeCache(RatingsEntryImpl.class.getName());
2055 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2056 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2057 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2058 }
2059
2060 private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
2061 private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
2062 private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
2063 private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
2064 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
2065 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
2066 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
2067 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2068 private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
2069 private static RatingsEntry _nullRatingsEntry = new RatingsEntryImpl() {
2070 @Override
2071 public Object clone() {
2072 return this;
2073 }
2074
2075 @Override
2076 public CacheModel<RatingsEntry> toCacheModel() {
2077 return _nullRatingsEntryCacheModel;
2078 }
2079 };
2080
2081 private static CacheModel<RatingsEntry> _nullRatingsEntryCacheModel = new CacheModel<RatingsEntry>() {
2082 public RatingsEntry toEntityModel() {
2083 return _nullRatingsEntry;
2084 }
2085 };
2086 }