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