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 @Override
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 @Override
133 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
134 int start, int end) throws SystemException {
135 return findByC_C(classNameId, classPK, start, end, null);
136 }
137
138
153 @Override
154 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
155 int start, int end, OrderByComparator orderByComparator)
156 throws SystemException {
157 boolean pagination = true;
158 FinderPath finderPath = null;
159 Object[] finderArgs = null;
160
161 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
162 (orderByComparator == null)) {
163 pagination = false;
164 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
165 finderArgs = new Object[] { classNameId, classPK };
166 }
167 else {
168 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
169 finderArgs = new Object[] {
170 classNameId, classPK,
171
172 start, end, orderByComparator
173 };
174 }
175
176 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
177 finderArgs, this);
178
179 if ((list != null) && !list.isEmpty()) {
180 for (RatingsEntry ratingsEntry : list) {
181 if ((classNameId != ratingsEntry.getClassNameId()) ||
182 (classPK != ratingsEntry.getClassPK())) {
183 list = null;
184
185 break;
186 }
187 }
188 }
189
190 if (list == null) {
191 StringBundler query = null;
192
193 if (orderByComparator != null) {
194 query = new StringBundler(4 +
195 (orderByComparator.getOrderByFields().length * 3));
196 }
197 else {
198 query = new StringBundler(4);
199 }
200
201 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
202
203 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
204
205 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
206
207 if (orderByComparator != null) {
208 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
209 orderByComparator);
210 }
211 else
212 if (pagination) {
213 query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
214 }
215
216 String sql = query.toString();
217
218 Session session = null;
219
220 try {
221 session = openSession();
222
223 Query q = session.createQuery(sql);
224
225 QueryPos qPos = QueryPos.getInstance(q);
226
227 qPos.add(classNameId);
228
229 qPos.add(classPK);
230
231 if (!pagination) {
232 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
233 start, end, false);
234
235 Collections.sort(list);
236
237 list = new UnmodifiableList<RatingsEntry>(list);
238 }
239 else {
240 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
241 start, end);
242 }
243
244 cacheResult(list);
245
246 FinderCacheUtil.putResult(finderPath, finderArgs, list);
247 }
248 catch (Exception e) {
249 FinderCacheUtil.removeResult(finderPath, finderArgs);
250
251 throw processException(e);
252 }
253 finally {
254 closeSession(session);
255 }
256 }
257
258 return list;
259 }
260
261
271 @Override
272 public RatingsEntry findByC_C_First(long classNameId, long classPK,
273 OrderByComparator orderByComparator)
274 throws NoSuchEntryException, SystemException {
275 RatingsEntry ratingsEntry = fetchByC_C_First(classNameId, classPK,
276 orderByComparator);
277
278 if (ratingsEntry != null) {
279 return ratingsEntry;
280 }
281
282 StringBundler msg = new StringBundler(6);
283
284 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
285
286 msg.append("classNameId=");
287 msg.append(classNameId);
288
289 msg.append(", classPK=");
290 msg.append(classPK);
291
292 msg.append(StringPool.CLOSE_CURLY_BRACE);
293
294 throw new NoSuchEntryException(msg.toString());
295 }
296
297
306 @Override
307 public RatingsEntry fetchByC_C_First(long classNameId, long classPK,
308 OrderByComparator orderByComparator) throws SystemException {
309 List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
310 orderByComparator);
311
312 if (!list.isEmpty()) {
313 return list.get(0);
314 }
315
316 return null;
317 }
318
319
329 @Override
330 public RatingsEntry findByC_C_Last(long classNameId, long classPK,
331 OrderByComparator orderByComparator)
332 throws NoSuchEntryException, SystemException {
333 RatingsEntry ratingsEntry = fetchByC_C_Last(classNameId, classPK,
334 orderByComparator);
335
336 if (ratingsEntry != null) {
337 return ratingsEntry;
338 }
339
340 StringBundler msg = new StringBundler(6);
341
342 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
343
344 msg.append("classNameId=");
345 msg.append(classNameId);
346
347 msg.append(", classPK=");
348 msg.append(classPK);
349
350 msg.append(StringPool.CLOSE_CURLY_BRACE);
351
352 throw new NoSuchEntryException(msg.toString());
353 }
354
355
364 @Override
365 public RatingsEntry fetchByC_C_Last(long classNameId, long classPK,
366 OrderByComparator orderByComparator) throws SystemException {
367 int count = countByC_C(classNameId, classPK);
368
369 if (count == 0) {
370 return null;
371 }
372
373 List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
374 count, orderByComparator);
375
376 if (!list.isEmpty()) {
377 return list.get(0);
378 }
379
380 return null;
381 }
382
383
394 @Override
395 public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
396 long classPK, OrderByComparator orderByComparator)
397 throws NoSuchEntryException, SystemException {
398 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
399
400 Session session = null;
401
402 try {
403 session = openSession();
404
405 RatingsEntry[] array = new RatingsEntryImpl[3];
406
407 array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
408 classPK, orderByComparator, true);
409
410 array[1] = ratingsEntry;
411
412 array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
413 classPK, orderByComparator, false);
414
415 return array;
416 }
417 catch (Exception e) {
418 throw processException(e);
419 }
420 finally {
421 closeSession(session);
422 }
423 }
424
425 protected RatingsEntry getByC_C_PrevAndNext(Session session,
426 RatingsEntry ratingsEntry, long classNameId, long classPK,
427 OrderByComparator orderByComparator, boolean previous) {
428 StringBundler query = null;
429
430 if (orderByComparator != null) {
431 query = new StringBundler(6 +
432 (orderByComparator.getOrderByFields().length * 6));
433 }
434 else {
435 query = new StringBundler(3);
436 }
437
438 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
439
440 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
441
442 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
443
444 if (orderByComparator != null) {
445 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
446
447 if (orderByConditionFields.length > 0) {
448 query.append(WHERE_AND);
449 }
450
451 for (int i = 0; i < orderByConditionFields.length; i++) {
452 query.append(_ORDER_BY_ENTITY_ALIAS);
453 query.append(orderByConditionFields[i]);
454
455 if ((i + 1) < orderByConditionFields.length) {
456 if (orderByComparator.isAscending() ^ previous) {
457 query.append(WHERE_GREATER_THAN_HAS_NEXT);
458 }
459 else {
460 query.append(WHERE_LESSER_THAN_HAS_NEXT);
461 }
462 }
463 else {
464 if (orderByComparator.isAscending() ^ previous) {
465 query.append(WHERE_GREATER_THAN);
466 }
467 else {
468 query.append(WHERE_LESSER_THAN);
469 }
470 }
471 }
472
473 query.append(ORDER_BY_CLAUSE);
474
475 String[] orderByFields = orderByComparator.getOrderByFields();
476
477 for (int i = 0; i < orderByFields.length; i++) {
478 query.append(_ORDER_BY_ENTITY_ALIAS);
479 query.append(orderByFields[i]);
480
481 if ((i + 1) < orderByFields.length) {
482 if (orderByComparator.isAscending() ^ previous) {
483 query.append(ORDER_BY_ASC_HAS_NEXT);
484 }
485 else {
486 query.append(ORDER_BY_DESC_HAS_NEXT);
487 }
488 }
489 else {
490 if (orderByComparator.isAscending() ^ previous) {
491 query.append(ORDER_BY_ASC);
492 }
493 else {
494 query.append(ORDER_BY_DESC);
495 }
496 }
497 }
498 }
499 else {
500 query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
501 }
502
503 String sql = query.toString();
504
505 Query q = session.createQuery(sql);
506
507 q.setFirstResult(0);
508 q.setMaxResults(2);
509
510 QueryPos qPos = QueryPos.getInstance(q);
511
512 qPos.add(classNameId);
513
514 qPos.add(classPK);
515
516 if (orderByComparator != null) {
517 Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
518
519 for (Object value : values) {
520 qPos.add(value);
521 }
522 }
523
524 List<RatingsEntry> list = q.list();
525
526 if (list.size() == 2) {
527 return list.get(1);
528 }
529 else {
530 return null;
531 }
532 }
533
534
541 @Override
542 public void removeByC_C(long classNameId, long classPK)
543 throws SystemException {
544 for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK,
545 QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
546 remove(ratingsEntry);
547 }
548 }
549
550
558 @Override
559 public int countByC_C(long classNameId, long classPK)
560 throws SystemException {
561 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
562
563 Object[] finderArgs = new Object[] { classNameId, classPK };
564
565 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
566 this);
567
568 if (count == null) {
569 StringBundler query = new StringBundler(3);
570
571 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
572
573 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
574
575 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
576
577 String sql = query.toString();
578
579 Session session = null;
580
581 try {
582 session = openSession();
583
584 Query q = session.createQuery(sql);
585
586 QueryPos qPos = QueryPos.getInstance(q);
587
588 qPos.add(classNameId);
589
590 qPos.add(classPK);
591
592 count = (Long)q.uniqueResult();
593
594 FinderCacheUtil.putResult(finderPath, finderArgs, count);
595 }
596 catch (Exception e) {
597 FinderCacheUtil.removeResult(finderPath, finderArgs);
598
599 throw processException(e);
600 }
601 finally {
602 closeSession(session);
603 }
604 }
605
606 return count.intValue();
607 }
608
609 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
610 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
611 public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
612 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
613 FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C",
614 new String[] {
615 Long.class.getName(), Long.class.getName(), Long.class.getName()
616 },
617 RatingsEntryModelImpl.USERID_COLUMN_BITMASK |
618 RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
619 RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK);
620 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
621 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
622 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
623 new String[] {
624 Long.class.getName(), Long.class.getName(), Long.class.getName()
625 });
626
627
637 @Override
638 public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
639 throws NoSuchEntryException, SystemException {
640 RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
641
642 if (ratingsEntry == null) {
643 StringBundler msg = new StringBundler(8);
644
645 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
646
647 msg.append("userId=");
648 msg.append(userId);
649
650 msg.append(", classNameId=");
651 msg.append(classNameId);
652
653 msg.append(", classPK=");
654 msg.append(classPK);
655
656 msg.append(StringPool.CLOSE_CURLY_BRACE);
657
658 if (_log.isWarnEnabled()) {
659 _log.warn(msg.toString());
660 }
661
662 throw new NoSuchEntryException(msg.toString());
663 }
664
665 return ratingsEntry;
666 }
667
668
677 @Override
678 public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
679 throws SystemException {
680 return fetchByU_C_C(userId, classNameId, classPK, true);
681 }
682
683
693 @Override
694 public RatingsEntry fetchByU_C_C(long userId, long classNameId,
695 long classPK, boolean retrieveFromCache) throws SystemException {
696 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
697
698 Object result = null;
699
700 if (retrieveFromCache) {
701 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
702 finderArgs, this);
703 }
704
705 if (result instanceof RatingsEntry) {
706 RatingsEntry ratingsEntry = (RatingsEntry)result;
707
708 if ((userId != ratingsEntry.getUserId()) ||
709 (classNameId != ratingsEntry.getClassNameId()) ||
710 (classPK != ratingsEntry.getClassPK())) {
711 result = null;
712 }
713 }
714
715 if (result == null) {
716 StringBundler query = new StringBundler(5);
717
718 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
719
720 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
721
722 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
723
724 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
725
726 String sql = query.toString();
727
728 Session session = null;
729
730 try {
731 session = openSession();
732
733 Query q = session.createQuery(sql);
734
735 QueryPos qPos = QueryPos.getInstance(q);
736
737 qPos.add(userId);
738
739 qPos.add(classNameId);
740
741 qPos.add(classPK);
742
743 List<RatingsEntry> list = q.list();
744
745 if (list.isEmpty()) {
746 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
747 finderArgs, list);
748 }
749 else {
750 RatingsEntry ratingsEntry = list.get(0);
751
752 result = ratingsEntry;
753
754 cacheResult(ratingsEntry);
755
756 if ((ratingsEntry.getUserId() != userId) ||
757 (ratingsEntry.getClassNameId() != classNameId) ||
758 (ratingsEntry.getClassPK() != classPK)) {
759 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
760 finderArgs, ratingsEntry);
761 }
762 }
763 }
764 catch (Exception e) {
765 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
766 finderArgs);
767
768 throw processException(e);
769 }
770 finally {
771 closeSession(session);
772 }
773 }
774
775 if (result instanceof List<?>) {
776 return null;
777 }
778 else {
779 return (RatingsEntry)result;
780 }
781 }
782
783
792 @Override
793 public RatingsEntry removeByU_C_C(long userId, long classNameId,
794 long classPK) throws NoSuchEntryException, SystemException {
795 RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
796
797 return remove(ratingsEntry);
798 }
799
800
809 @Override
810 public int countByU_C_C(long userId, long classNameId, long classPK)
811 throws SystemException {
812 FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
813
814 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
815
816 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
817 this);
818
819 if (count == null) {
820 StringBundler query = new StringBundler(4);
821
822 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
823
824 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
825
826 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
827
828 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
829
830 String sql = query.toString();
831
832 Session session = null;
833
834 try {
835 session = openSession();
836
837 Query q = session.createQuery(sql);
838
839 QueryPos qPos = QueryPos.getInstance(q);
840
841 qPos.add(userId);
842
843 qPos.add(classNameId);
844
845 qPos.add(classPK);
846
847 count = (Long)q.uniqueResult();
848
849 FinderCacheUtil.putResult(finderPath, finderArgs, count);
850 }
851 catch (Exception e) {
852 FinderCacheUtil.removeResult(finderPath, finderArgs);
853
854 throw processException(e);
855 }
856 finally {
857 closeSession(session);
858 }
859 }
860
861 return count.intValue();
862 }
863
864 private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
865 private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
866 private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
867 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
868 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
869 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
870 new String[] {
871 Long.class.getName(), Long.class.getName(),
872 Double.class.getName(),
873
874 Integer.class.getName(), Integer.class.getName(),
875 OrderByComparator.class.getName()
876 });
877 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
878 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
879 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
880 new String[] {
881 Long.class.getName(), Long.class.getName(),
882 Double.class.getName()
883 },
884 RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
885 RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK |
886 RatingsEntryModelImpl.SCORE_COLUMN_BITMASK);
887 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
888 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
889 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
890 new String[] {
891 Long.class.getName(), Long.class.getName(),
892 Double.class.getName()
893 });
894
895
904 @Override
905 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
906 double score) throws SystemException {
907 return findByC_C_S(classNameId, classPK, score, QueryUtil.ALL_POS,
908 QueryUtil.ALL_POS, null);
909 }
910
911
926 @Override
927 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
928 double score, int start, int end) throws SystemException {
929 return findByC_C_S(classNameId, classPK, score, start, end, null);
930 }
931
932
948 @Override
949 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
950 double score, int start, int end, OrderByComparator orderByComparator)
951 throws SystemException {
952 boolean pagination = true;
953 FinderPath finderPath = null;
954 Object[] finderArgs = null;
955
956 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
957 (orderByComparator == null)) {
958 pagination = false;
959 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
960 finderArgs = new Object[] { classNameId, classPK, score };
961 }
962 else {
963 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
964 finderArgs = new Object[] {
965 classNameId, classPK, score,
966
967 start, end, orderByComparator
968 };
969 }
970
971 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
972 finderArgs, this);
973
974 if ((list != null) && !list.isEmpty()) {
975 for (RatingsEntry ratingsEntry : list) {
976 if ((classNameId != ratingsEntry.getClassNameId()) ||
977 (classPK != ratingsEntry.getClassPK()) ||
978 (score != ratingsEntry.getScore())) {
979 list = null;
980
981 break;
982 }
983 }
984 }
985
986 if (list == null) {
987 StringBundler query = null;
988
989 if (orderByComparator != null) {
990 query = new StringBundler(5 +
991 (orderByComparator.getOrderByFields().length * 3));
992 }
993 else {
994 query = new StringBundler(5);
995 }
996
997 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
998
999 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1000
1001 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1002
1003 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1004
1005 if (orderByComparator != null) {
1006 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1007 orderByComparator);
1008 }
1009 else
1010 if (pagination) {
1011 query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
1012 }
1013
1014 String sql = query.toString();
1015
1016 Session session = null;
1017
1018 try {
1019 session = openSession();
1020
1021 Query q = session.createQuery(sql);
1022
1023 QueryPos qPos = QueryPos.getInstance(q);
1024
1025 qPos.add(classNameId);
1026
1027 qPos.add(classPK);
1028
1029 qPos.add(score);
1030
1031 if (!pagination) {
1032 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1033 start, end, false);
1034
1035 Collections.sort(list);
1036
1037 list = new UnmodifiableList<RatingsEntry>(list);
1038 }
1039 else {
1040 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1041 start, end);
1042 }
1043
1044 cacheResult(list);
1045
1046 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1047 }
1048 catch (Exception e) {
1049 FinderCacheUtil.removeResult(finderPath, finderArgs);
1050
1051 throw processException(e);
1052 }
1053 finally {
1054 closeSession(session);
1055 }
1056 }
1057
1058 return list;
1059 }
1060
1061
1072 @Override
1073 public RatingsEntry findByC_C_S_First(long classNameId, long classPK,
1074 double score, OrderByComparator orderByComparator)
1075 throws NoSuchEntryException, SystemException {
1076 RatingsEntry ratingsEntry = fetchByC_C_S_First(classNameId, classPK,
1077 score, orderByComparator);
1078
1079 if (ratingsEntry != null) {
1080 return ratingsEntry;
1081 }
1082
1083 StringBundler msg = new StringBundler(8);
1084
1085 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1086
1087 msg.append("classNameId=");
1088 msg.append(classNameId);
1089
1090 msg.append(", classPK=");
1091 msg.append(classPK);
1092
1093 msg.append(", score=");
1094 msg.append(score);
1095
1096 msg.append(StringPool.CLOSE_CURLY_BRACE);
1097
1098 throw new NoSuchEntryException(msg.toString());
1099 }
1100
1101
1111 @Override
1112 public RatingsEntry fetchByC_C_S_First(long classNameId, long classPK,
1113 double score, OrderByComparator orderByComparator)
1114 throws SystemException {
1115 List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score, 0,
1116 1, orderByComparator);
1117
1118 if (!list.isEmpty()) {
1119 return list.get(0);
1120 }
1121
1122 return null;
1123 }
1124
1125
1136 @Override
1137 public RatingsEntry findByC_C_S_Last(long classNameId, long classPK,
1138 double score, OrderByComparator orderByComparator)
1139 throws NoSuchEntryException, SystemException {
1140 RatingsEntry ratingsEntry = fetchByC_C_S_Last(classNameId, classPK,
1141 score, orderByComparator);
1142
1143 if (ratingsEntry != null) {
1144 return ratingsEntry;
1145 }
1146
1147 StringBundler msg = new StringBundler(8);
1148
1149 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1150
1151 msg.append("classNameId=");
1152 msg.append(classNameId);
1153
1154 msg.append(", classPK=");
1155 msg.append(classPK);
1156
1157 msg.append(", score=");
1158 msg.append(score);
1159
1160 msg.append(StringPool.CLOSE_CURLY_BRACE);
1161
1162 throw new NoSuchEntryException(msg.toString());
1163 }
1164
1165
1175 @Override
1176 public RatingsEntry fetchByC_C_S_Last(long classNameId, long classPK,
1177 double score, OrderByComparator orderByComparator)
1178 throws SystemException {
1179 int count = countByC_C_S(classNameId, classPK, score);
1180
1181 if (count == 0) {
1182 return null;
1183 }
1184
1185 List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score,
1186 count - 1, count, orderByComparator);
1187
1188 if (!list.isEmpty()) {
1189 return list.get(0);
1190 }
1191
1192 return null;
1193 }
1194
1195
1207 @Override
1208 public RatingsEntry[] findByC_C_S_PrevAndNext(long entryId,
1209 long classNameId, long classPK, double score,
1210 OrderByComparator orderByComparator)
1211 throws NoSuchEntryException, SystemException {
1212 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
1213
1214 Session session = null;
1215
1216 try {
1217 session = openSession();
1218
1219 RatingsEntry[] array = new RatingsEntryImpl[3];
1220
1221 array[0] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1222 classNameId, classPK, score, orderByComparator, true);
1223
1224 array[1] = ratingsEntry;
1225
1226 array[2] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1227 classNameId, classPK, score, orderByComparator, false);
1228
1229 return array;
1230 }
1231 catch (Exception e) {
1232 throw processException(e);
1233 }
1234 finally {
1235 closeSession(session);
1236 }
1237 }
1238
1239 protected RatingsEntry getByC_C_S_PrevAndNext(Session session,
1240 RatingsEntry ratingsEntry, long classNameId, long classPK,
1241 double score, OrderByComparator orderByComparator, boolean previous) {
1242 StringBundler query = null;
1243
1244 if (orderByComparator != null) {
1245 query = new StringBundler(6 +
1246 (orderByComparator.getOrderByFields().length * 6));
1247 }
1248 else {
1249 query = new StringBundler(3);
1250 }
1251
1252 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1253
1254 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1255
1256 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1257
1258 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1259
1260 if (orderByComparator != null) {
1261 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1262
1263 if (orderByConditionFields.length > 0) {
1264 query.append(WHERE_AND);
1265 }
1266
1267 for (int i = 0; i < orderByConditionFields.length; i++) {
1268 query.append(_ORDER_BY_ENTITY_ALIAS);
1269 query.append(orderByConditionFields[i]);
1270
1271 if ((i + 1) < orderByConditionFields.length) {
1272 if (orderByComparator.isAscending() ^ previous) {
1273 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1274 }
1275 else {
1276 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1277 }
1278 }
1279 else {
1280 if (orderByComparator.isAscending() ^ previous) {
1281 query.append(WHERE_GREATER_THAN);
1282 }
1283 else {
1284 query.append(WHERE_LESSER_THAN);
1285 }
1286 }
1287 }
1288
1289 query.append(ORDER_BY_CLAUSE);
1290
1291 String[] orderByFields = orderByComparator.getOrderByFields();
1292
1293 for (int i = 0; i < orderByFields.length; i++) {
1294 query.append(_ORDER_BY_ENTITY_ALIAS);
1295 query.append(orderByFields[i]);
1296
1297 if ((i + 1) < orderByFields.length) {
1298 if (orderByComparator.isAscending() ^ previous) {
1299 query.append(ORDER_BY_ASC_HAS_NEXT);
1300 }
1301 else {
1302 query.append(ORDER_BY_DESC_HAS_NEXT);
1303 }
1304 }
1305 else {
1306 if (orderByComparator.isAscending() ^ previous) {
1307 query.append(ORDER_BY_ASC);
1308 }
1309 else {
1310 query.append(ORDER_BY_DESC);
1311 }
1312 }
1313 }
1314 }
1315 else {
1316 query.append(RatingsEntryModelImpl.ORDER_BY_JPQL);
1317 }
1318
1319 String sql = query.toString();
1320
1321 Query q = session.createQuery(sql);
1322
1323 q.setFirstResult(0);
1324 q.setMaxResults(2);
1325
1326 QueryPos qPos = QueryPos.getInstance(q);
1327
1328 qPos.add(classNameId);
1329
1330 qPos.add(classPK);
1331
1332 qPos.add(score);
1333
1334 if (orderByComparator != null) {
1335 Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
1336
1337 for (Object value : values) {
1338 qPos.add(value);
1339 }
1340 }
1341
1342 List<RatingsEntry> list = q.list();
1343
1344 if (list.size() == 2) {
1345 return list.get(1);
1346 }
1347 else {
1348 return null;
1349 }
1350 }
1351
1352
1360 @Override
1361 public void removeByC_C_S(long classNameId, long classPK, double score)
1362 throws SystemException {
1363 for (RatingsEntry ratingsEntry : findByC_C_S(classNameId, classPK,
1364 score, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1365 remove(ratingsEntry);
1366 }
1367 }
1368
1369
1378 @Override
1379 public int countByC_C_S(long classNameId, long classPK, double score)
1380 throws SystemException {
1381 FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
1382
1383 Object[] finderArgs = new Object[] { classNameId, classPK, score };
1384
1385 Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1386 this);
1387
1388 if (count == null) {
1389 StringBundler query = new StringBundler(4);
1390
1391 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1392
1393 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1394
1395 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1396
1397 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1398
1399 String sql = query.toString();
1400
1401 Session session = null;
1402
1403 try {
1404 session = openSession();
1405
1406 Query q = session.createQuery(sql);
1407
1408 QueryPos qPos = QueryPos.getInstance(q);
1409
1410 qPos.add(classNameId);
1411
1412 qPos.add(classPK);
1413
1414 qPos.add(score);
1415
1416 count = (Long)q.uniqueResult();
1417
1418 FinderCacheUtil.putResult(finderPath, finderArgs, count);
1419 }
1420 catch (Exception e) {
1421 FinderCacheUtil.removeResult(finderPath, finderArgs);
1422
1423 throw processException(e);
1424 }
1425 finally {
1426 closeSession(session);
1427 }
1428 }
1429
1430 return count.intValue();
1431 }
1432
1433 private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1434 private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "ratingsEntry.classPK = ? AND ";
1435 private static final String _FINDER_COLUMN_C_C_S_SCORE_2 = "ratingsEntry.score = ?";
1436
1437 public RatingsEntryPersistenceImpl() {
1438 setModelClass(RatingsEntry.class);
1439 }
1440
1441
1446 @Override
1447 public void cacheResult(RatingsEntry ratingsEntry) {
1448 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1449 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
1450
1451 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1452 new Object[] {
1453 ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
1454 ratingsEntry.getClassPK()
1455 }, ratingsEntry);
1456
1457 ratingsEntry.resetOriginalValues();
1458 }
1459
1460
1465 @Override
1466 public void cacheResult(List<RatingsEntry> ratingsEntries) {
1467 for (RatingsEntry ratingsEntry : ratingsEntries) {
1468 if (EntityCacheUtil.getResult(
1469 RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1470 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey()) == null) {
1471 cacheResult(ratingsEntry);
1472 }
1473 else {
1474 ratingsEntry.resetOriginalValues();
1475 }
1476 }
1477 }
1478
1479
1486 @Override
1487 public void clearCache() {
1488 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
1489 CacheRegistryUtil.clear(RatingsEntryImpl.class.getName());
1490 }
1491
1492 EntityCacheUtil.clearCache(RatingsEntryImpl.class.getName());
1493
1494 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
1495 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1496 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1497 }
1498
1499
1506 @Override
1507 public void clearCache(RatingsEntry ratingsEntry) {
1508 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1509 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
1510
1511 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1512 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1513
1514 clearUniqueFindersCache(ratingsEntry);
1515 }
1516
1517 @Override
1518 public void clearCache(List<RatingsEntry> ratingsEntries) {
1519 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1520 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1521
1522 for (RatingsEntry ratingsEntry : ratingsEntries) {
1523 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1524 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
1525
1526 clearUniqueFindersCache(ratingsEntry);
1527 }
1528 }
1529
1530 protected void cacheUniqueFindersCache(RatingsEntry ratingsEntry) {
1531 if (ratingsEntry.isNew()) {
1532 Object[] args = new Object[] {
1533 ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
1534 ratingsEntry.getClassPK()
1535 };
1536
1537 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C, args,
1538 Long.valueOf(1));
1539 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C, args,
1540 ratingsEntry);
1541 }
1542 else {
1543 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
1544
1545 if ((ratingsEntryModelImpl.getColumnBitmask() &
1546 FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
1547 Object[] args = new Object[] {
1548 ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
1549 ratingsEntry.getClassPK()
1550 };
1551
1552 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C, args,
1553 Long.valueOf(1));
1554 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C, args,
1555 ratingsEntry);
1556 }
1557 }
1558 }
1559
1560 protected void clearUniqueFindersCache(RatingsEntry ratingsEntry) {
1561 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
1562
1563 Object[] args = new Object[] {
1564 ratingsEntry.getUserId(), ratingsEntry.getClassNameId(),
1565 ratingsEntry.getClassPK()
1566 };
1567
1568 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1569 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
1570
1571 if ((ratingsEntryModelImpl.getColumnBitmask() &
1572 FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
1573 args = new Object[] {
1574 ratingsEntryModelImpl.getOriginalUserId(),
1575 ratingsEntryModelImpl.getOriginalClassNameId(),
1576 ratingsEntryModelImpl.getOriginalClassPK()
1577 };
1578
1579 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
1580 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
1581 }
1582 }
1583
1584
1590 @Override
1591 public RatingsEntry create(long entryId) {
1592 RatingsEntry ratingsEntry = new RatingsEntryImpl();
1593
1594 ratingsEntry.setNew(true);
1595 ratingsEntry.setPrimaryKey(entryId);
1596
1597 return ratingsEntry;
1598 }
1599
1600
1608 @Override
1609 public RatingsEntry remove(long entryId)
1610 throws NoSuchEntryException, SystemException {
1611 return remove((Serializable)entryId);
1612 }
1613
1614
1622 @Override
1623 public RatingsEntry remove(Serializable primaryKey)
1624 throws NoSuchEntryException, SystemException {
1625 Session session = null;
1626
1627 try {
1628 session = openSession();
1629
1630 RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
1631 primaryKey);
1632
1633 if (ratingsEntry == null) {
1634 if (_log.isWarnEnabled()) {
1635 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1636 }
1637
1638 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1639 primaryKey);
1640 }
1641
1642 return remove(ratingsEntry);
1643 }
1644 catch (NoSuchEntryException nsee) {
1645 throw nsee;
1646 }
1647 catch (Exception e) {
1648 throw processException(e);
1649 }
1650 finally {
1651 closeSession(session);
1652 }
1653 }
1654
1655 @Override
1656 protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
1657 throws SystemException {
1658 ratingsEntry = toUnwrappedModel(ratingsEntry);
1659
1660 Session session = null;
1661
1662 try {
1663 session = openSession();
1664
1665 if (!session.contains(ratingsEntry)) {
1666 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
1667 ratingsEntry.getPrimaryKeyObj());
1668 }
1669
1670 if (ratingsEntry != null) {
1671 session.delete(ratingsEntry);
1672 }
1673 }
1674 catch (Exception e) {
1675 throw processException(e);
1676 }
1677 finally {
1678 closeSession(session);
1679 }
1680
1681 if (ratingsEntry != null) {
1682 clearCache(ratingsEntry);
1683 }
1684
1685 return ratingsEntry;
1686 }
1687
1688 @Override
1689 public RatingsEntry updateImpl(
1690 com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry)
1691 throws SystemException {
1692 ratingsEntry = toUnwrappedModel(ratingsEntry);
1693
1694 boolean isNew = ratingsEntry.isNew();
1695
1696 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
1697
1698 Session session = null;
1699
1700 try {
1701 session = openSession();
1702
1703 if (ratingsEntry.isNew()) {
1704 session.save(ratingsEntry);
1705
1706 ratingsEntry.setNew(false);
1707 }
1708 else {
1709 session.merge(ratingsEntry);
1710 }
1711 }
1712 catch (Exception e) {
1713 throw processException(e);
1714 }
1715 finally {
1716 closeSession(session);
1717 }
1718
1719 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1720
1721 if (isNew || !RatingsEntryModelImpl.COLUMN_BITMASK_ENABLED) {
1722 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1723 }
1724
1725 else {
1726 if ((ratingsEntryModelImpl.getColumnBitmask() &
1727 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
1728 Object[] args = new Object[] {
1729 ratingsEntryModelImpl.getOriginalClassNameId(),
1730 ratingsEntryModelImpl.getOriginalClassPK()
1731 };
1732
1733 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1734 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1735 args);
1736
1737 args = new Object[] {
1738 ratingsEntryModelImpl.getClassNameId(),
1739 ratingsEntryModelImpl.getClassPK()
1740 };
1741
1742 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
1743 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
1744 args);
1745 }
1746
1747 if ((ratingsEntryModelImpl.getColumnBitmask() &
1748 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
1749 Object[] args = new Object[] {
1750 ratingsEntryModelImpl.getOriginalClassNameId(),
1751 ratingsEntryModelImpl.getOriginalClassPK(),
1752 ratingsEntryModelImpl.getOriginalScore()
1753 };
1754
1755 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1756 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1757 args);
1758
1759 args = new Object[] {
1760 ratingsEntryModelImpl.getClassNameId(),
1761 ratingsEntryModelImpl.getClassPK(),
1762 ratingsEntryModelImpl.getScore()
1763 };
1764
1765 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
1766 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
1767 args);
1768 }
1769 }
1770
1771 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1772 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
1773
1774 clearUniqueFindersCache(ratingsEntry);
1775 cacheUniqueFindersCache(ratingsEntry);
1776
1777 return ratingsEntry;
1778 }
1779
1780 protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
1781 if (ratingsEntry instanceof RatingsEntryImpl) {
1782 return ratingsEntry;
1783 }
1784
1785 RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
1786
1787 ratingsEntryImpl.setNew(ratingsEntry.isNew());
1788 ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
1789
1790 ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
1791 ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
1792 ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
1793 ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
1794 ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
1795 ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
1796 ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
1797 ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
1798 ratingsEntryImpl.setScore(ratingsEntry.getScore());
1799
1800 return ratingsEntryImpl;
1801 }
1802
1803
1811 @Override
1812 public RatingsEntry findByPrimaryKey(Serializable primaryKey)
1813 throws NoSuchEntryException, SystemException {
1814 RatingsEntry ratingsEntry = fetchByPrimaryKey(primaryKey);
1815
1816 if (ratingsEntry == null) {
1817 if (_log.isWarnEnabled()) {
1818 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1819 }
1820
1821 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1822 primaryKey);
1823 }
1824
1825 return ratingsEntry;
1826 }
1827
1828
1836 @Override
1837 public RatingsEntry findByPrimaryKey(long entryId)
1838 throws NoSuchEntryException, SystemException {
1839 return findByPrimaryKey((Serializable)entryId);
1840 }
1841
1842
1849 @Override
1850 public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
1851 throws SystemException {
1852 RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1853 RatingsEntryImpl.class, primaryKey);
1854
1855 if (ratingsEntry == _nullRatingsEntry) {
1856 return null;
1857 }
1858
1859 if (ratingsEntry == null) {
1860 Session session = null;
1861
1862 try {
1863 session = openSession();
1864
1865 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
1866 primaryKey);
1867
1868 if (ratingsEntry != null) {
1869 cacheResult(ratingsEntry);
1870 }
1871 else {
1872 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1873 RatingsEntryImpl.class, primaryKey, _nullRatingsEntry);
1874 }
1875 }
1876 catch (Exception e) {
1877 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
1878 RatingsEntryImpl.class, primaryKey);
1879
1880 throw processException(e);
1881 }
1882 finally {
1883 closeSession(session);
1884 }
1885 }
1886
1887 return ratingsEntry;
1888 }
1889
1890
1897 @Override
1898 public RatingsEntry fetchByPrimaryKey(long entryId)
1899 throws SystemException {
1900 return fetchByPrimaryKey((Serializable)entryId);
1901 }
1902
1903
1909 @Override
1910 public List<RatingsEntry> findAll() throws SystemException {
1911 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1912 }
1913
1914
1926 @Override
1927 public List<RatingsEntry> findAll(int start, int end)
1928 throws SystemException {
1929 return findAll(start, end, null);
1930 }
1931
1932
1945 @Override
1946 public List<RatingsEntry> findAll(int start, int end,
1947 OrderByComparator orderByComparator) throws SystemException {
1948 boolean pagination = true;
1949 FinderPath finderPath = null;
1950 Object[] finderArgs = null;
1951
1952 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1953 (orderByComparator == null)) {
1954 pagination = false;
1955 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1956 finderArgs = FINDER_ARGS_EMPTY;
1957 }
1958 else {
1959 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1960 finderArgs = new Object[] { start, end, orderByComparator };
1961 }
1962
1963 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1964 finderArgs, this);
1965
1966 if (list == null) {
1967 StringBundler query = null;
1968 String sql = null;
1969
1970 if (orderByComparator != null) {
1971 query = new StringBundler(2 +
1972 (orderByComparator.getOrderByFields().length * 3));
1973
1974 query.append(_SQL_SELECT_RATINGSENTRY);
1975
1976 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1977 orderByComparator);
1978
1979 sql = query.toString();
1980 }
1981 else {
1982 sql = _SQL_SELECT_RATINGSENTRY;
1983
1984 if (pagination) {
1985 sql = sql.concat(RatingsEntryModelImpl.ORDER_BY_JPQL);
1986 }
1987 }
1988
1989 Session session = null;
1990
1991 try {
1992 session = openSession();
1993
1994 Query q = session.createQuery(sql);
1995
1996 if (!pagination) {
1997 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1998 start, end, false);
1999
2000 Collections.sort(list);
2001
2002 list = new UnmodifiableList<RatingsEntry>(list);
2003 }
2004 else {
2005 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
2006 start, end);
2007 }
2008
2009 cacheResult(list);
2010
2011 FinderCacheUtil.putResult(finderPath, finderArgs, list);
2012 }
2013 catch (Exception e) {
2014 FinderCacheUtil.removeResult(finderPath, finderArgs);
2015
2016 throw processException(e);
2017 }
2018 finally {
2019 closeSession(session);
2020 }
2021 }
2022
2023 return list;
2024 }
2025
2026
2031 @Override
2032 public void removeAll() throws SystemException {
2033 for (RatingsEntry ratingsEntry : findAll()) {
2034 remove(ratingsEntry);
2035 }
2036 }
2037
2038
2044 @Override
2045 public int countAll() throws SystemException {
2046 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
2047 FINDER_ARGS_EMPTY, this);
2048
2049 if (count == null) {
2050 Session session = null;
2051
2052 try {
2053 session = openSession();
2054
2055 Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
2056
2057 count = (Long)q.uniqueResult();
2058
2059 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
2060 FINDER_ARGS_EMPTY, count);
2061 }
2062 catch (Exception e) {
2063 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
2064 FINDER_ARGS_EMPTY);
2065
2066 throw processException(e);
2067 }
2068 finally {
2069 closeSession(session);
2070 }
2071 }
2072
2073 return count.intValue();
2074 }
2075
2076
2079 public void afterPropertiesSet() {
2080 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
2081 com.liferay.portal.util.PropsUtil.get(
2082 "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
2083
2084 if (listenerClassNames.length > 0) {
2085 try {
2086 List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
2087
2088 for (String listenerClassName : listenerClassNames) {
2089 listenersList.add((ModelListener<RatingsEntry>)InstanceFactory.newInstance(
2090 getClassLoader(), listenerClassName));
2091 }
2092
2093 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2094 }
2095 catch (Exception e) {
2096 _log.error(e);
2097 }
2098 }
2099 }
2100
2101 public void destroy() {
2102 EntityCacheUtil.removeCache(RatingsEntryImpl.class.getName());
2103 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2104 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2105 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2106 }
2107
2108 private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
2109 private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
2110 private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
2111 private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
2112 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
2113 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
2114 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
2115 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
2116 private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
2117 private static RatingsEntry _nullRatingsEntry = new RatingsEntryImpl() {
2118 @Override
2119 public Object clone() {
2120 return this;
2121 }
2122
2123 @Override
2124 public CacheModel<RatingsEntry> toCacheModel() {
2125 return _nullRatingsEntryCacheModel;
2126 }
2127 };
2128
2129 private static CacheModel<RatingsEntry> _nullRatingsEntryCacheModel = new CacheModel<RatingsEntry>() {
2130 @Override
2131 public RatingsEntry toEntityModel() {
2132 return _nullRatingsEntry;
2133 }
2134 };
2135 }