001
014
015 package com.liferay.portlet.ratings.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.annotation.BeanReference;
019 import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022 import com.liferay.portal.kernel.dao.orm.FinderPath;
023 import com.liferay.portal.kernel.dao.orm.Query;
024 import com.liferay.portal.kernel.dao.orm.QueryPos;
025 import com.liferay.portal.kernel.dao.orm.QueryUtil;
026 import com.liferay.portal.kernel.dao.orm.Session;
027 import com.liferay.portal.kernel.exception.SystemException;
028 import com.liferay.portal.kernel.log.Log;
029 import com.liferay.portal.kernel.log.LogFactoryUtil;
030 import com.liferay.portal.kernel.util.GetterUtil;
031 import com.liferay.portal.kernel.util.InstanceFactory;
032 import com.liferay.portal.kernel.util.OrderByComparator;
033 import com.liferay.portal.kernel.util.StringBundler;
034 import com.liferay.portal.kernel.util.StringPool;
035 import com.liferay.portal.kernel.util.StringUtil;
036 import com.liferay.portal.model.ModelListener;
037 import com.liferay.portal.service.persistence.BatchSessionUtil;
038 import com.liferay.portal.service.persistence.ResourcePersistence;
039 import com.liferay.portal.service.persistence.UserPersistence;
040 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041
042 import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
043 import com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence;
044 import com.liferay.portlet.ratings.NoSuchEntryException;
045 import com.liferay.portlet.ratings.model.RatingsEntry;
046 import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
047 import com.liferay.portlet.ratings.model.impl.RatingsEntryModelImpl;
048 import com.liferay.portlet.social.service.persistence.SocialEquityLogPersistence;
049
050 import java.io.Serializable;
051
052 import java.util.ArrayList;
053 import java.util.Collections;
054 import java.util.List;
055
056
072 public class RatingsEntryPersistenceImpl extends BasePersistenceImpl<RatingsEntry>
073 implements RatingsEntryPersistence {
074 public static final String FINDER_CLASS_NAME_ENTITY = RatingsEntryImpl.class.getName();
075 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
076 ".List";
077 public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
078 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
079 "findByC_C",
080 new String[] {
081 Long.class.getName(), Long.class.getName(),
082
083 "java.lang.Integer", "java.lang.Integer",
084 "com.liferay.portal.kernel.util.OrderByComparator"
085 });
086 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
087 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088 "countByC_C",
089 new String[] { Long.class.getName(), Long.class.getName() });
090 public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
091 RatingsEntryModelImpl.FINDER_CACHE_ENABLED,
092 FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C",
093 new String[] {
094 Long.class.getName(), Long.class.getName(), Long.class.getName()
095 });
096 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
097 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
098 "countByU_C_C",
099 new String[] {
100 Long.class.getName(), Long.class.getName(), Long.class.getName()
101 });
102 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
103 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104 "findAll", new String[0]);
105 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
106 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
107 "countAll", new String[0]);
108
109
114 public void cacheResult(RatingsEntry ratingsEntry) {
115 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
116 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
117
118 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
119 new Object[] {
120 new Long(ratingsEntry.getUserId()),
121 new Long(ratingsEntry.getClassNameId()),
122 new Long(ratingsEntry.getClassPK())
123 }, ratingsEntry);
124 }
125
126
131 public void cacheResult(List<RatingsEntry> ratingsEntries) {
132 for (RatingsEntry ratingsEntry : ratingsEntries) {
133 if (EntityCacheUtil.getResult(
134 RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
135 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(),
136 this) == null) {
137 cacheResult(ratingsEntry);
138 }
139 }
140 }
141
142
149 public void clearCache() {
150 CacheRegistryUtil.clear(RatingsEntryImpl.class.getName());
151 EntityCacheUtil.clearCache(RatingsEntryImpl.class.getName());
152 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
153 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
154 }
155
156
163 public void clearCache(RatingsEntry ratingsEntry) {
164 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
165 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
166
167 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
168 new Object[] {
169 new Long(ratingsEntry.getUserId()),
170 new Long(ratingsEntry.getClassNameId()),
171 new Long(ratingsEntry.getClassPK())
172 });
173 }
174
175
181 public RatingsEntry create(long entryId) {
182 RatingsEntry ratingsEntry = new RatingsEntryImpl();
183
184 ratingsEntry.setNew(true);
185 ratingsEntry.setPrimaryKey(entryId);
186
187 return ratingsEntry;
188 }
189
190
198 public RatingsEntry remove(Serializable primaryKey)
199 throws NoSuchModelException, SystemException {
200 return remove(((Long)primaryKey).longValue());
201 }
202
203
211 public RatingsEntry remove(long entryId)
212 throws NoSuchEntryException, SystemException {
213 Session session = null;
214
215 try {
216 session = openSession();
217
218 RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
219 new Long(entryId));
220
221 if (ratingsEntry == null) {
222 if (_log.isWarnEnabled()) {
223 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
224 }
225
226 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
227 entryId);
228 }
229
230 return remove(ratingsEntry);
231 }
232 catch (NoSuchEntryException nsee) {
233 throw nsee;
234 }
235 catch (Exception e) {
236 throw processException(e);
237 }
238 finally {
239 closeSession(session);
240 }
241 }
242
243 protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
244 throws SystemException {
245 ratingsEntry = toUnwrappedModel(ratingsEntry);
246
247 Session session = null;
248
249 try {
250 session = openSession();
251
252 if (ratingsEntry.isCachedModel() || BatchSessionUtil.isEnabled()) {
253 Object staleObject = session.get(RatingsEntryImpl.class,
254 ratingsEntry.getPrimaryKeyObj());
255
256 if (staleObject != null) {
257 session.evict(staleObject);
258 }
259 }
260
261 session.delete(ratingsEntry);
262
263 session.flush();
264 }
265 catch (Exception e) {
266 throw processException(e);
267 }
268 finally {
269 closeSession(session);
270 }
271
272 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
273
274 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
275
276 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
277 new Object[] {
278 new Long(ratingsEntryModelImpl.getOriginalUserId()),
279 new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
280 new Long(ratingsEntryModelImpl.getOriginalClassPK())
281 });
282
283 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
284 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
285
286 return ratingsEntry;
287 }
288
289 public RatingsEntry updateImpl(
290 com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
291 boolean merge) throws SystemException {
292 ratingsEntry = toUnwrappedModel(ratingsEntry);
293
294 boolean isNew = ratingsEntry.isNew();
295
296 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
297
298 Session session = null;
299
300 try {
301 session = openSession();
302
303 BatchSessionUtil.update(session, ratingsEntry, merge);
304
305 ratingsEntry.setNew(false);
306 }
307 catch (Exception e) {
308 throw processException(e);
309 }
310 finally {
311 closeSession(session);
312 }
313
314 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
315
316 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
317 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
318
319 if (!isNew &&
320 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
321 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
322 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
323 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
324 new Object[] {
325 new Long(ratingsEntryModelImpl.getOriginalUserId()),
326 new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
327 new Long(ratingsEntryModelImpl.getOriginalClassPK())
328 });
329 }
330
331 if (isNew ||
332 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
333 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
334 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
335 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
336 new Object[] {
337 new Long(ratingsEntry.getUserId()),
338 new Long(ratingsEntry.getClassNameId()),
339 new Long(ratingsEntry.getClassPK())
340 }, ratingsEntry);
341 }
342
343 return ratingsEntry;
344 }
345
346 protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
347 if (ratingsEntry instanceof RatingsEntryImpl) {
348 return ratingsEntry;
349 }
350
351 RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
352
353 ratingsEntryImpl.setNew(ratingsEntry.isNew());
354 ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
355
356 ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
357 ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
358 ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
359 ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
360 ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
361 ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
362 ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
363 ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
364 ratingsEntryImpl.setScore(ratingsEntry.getScore());
365
366 return ratingsEntryImpl;
367 }
368
369
377 public RatingsEntry findByPrimaryKey(Serializable primaryKey)
378 throws NoSuchModelException, SystemException {
379 return findByPrimaryKey(((Long)primaryKey).longValue());
380 }
381
382
390 public RatingsEntry findByPrimaryKey(long entryId)
391 throws NoSuchEntryException, SystemException {
392 RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
393
394 if (ratingsEntry == null) {
395 if (_log.isWarnEnabled()) {
396 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
397 }
398
399 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
400 entryId);
401 }
402
403 return ratingsEntry;
404 }
405
406
413 public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
414 throws SystemException {
415 return fetchByPrimaryKey(((Long)primaryKey).longValue());
416 }
417
418
425 public RatingsEntry fetchByPrimaryKey(long entryId)
426 throws SystemException {
427 RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
428 RatingsEntryImpl.class, entryId, this);
429
430 if (ratingsEntry == null) {
431 Session session = null;
432
433 try {
434 session = openSession();
435
436 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
437 new Long(entryId));
438 }
439 catch (Exception e) {
440 throw processException(e);
441 }
442 finally {
443 if (ratingsEntry != null) {
444 cacheResult(ratingsEntry);
445 }
446
447 closeSession(session);
448 }
449 }
450
451 return ratingsEntry;
452 }
453
454
462 public List<RatingsEntry> findByC_C(long classNameId, long classPK)
463 throws SystemException {
464 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
465 QueryUtil.ALL_POS, null);
466 }
467
468
482 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
483 int start, int end) throws SystemException {
484 return findByC_C(classNameId, classPK, start, end, null);
485 }
486
487
502 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
503 int start, int end, OrderByComparator orderByComparator)
504 throws SystemException {
505 Object[] finderArgs = new Object[] {
506 classNameId, classPK,
507
508 String.valueOf(start), String.valueOf(end),
509 String.valueOf(orderByComparator)
510 };
511
512 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
513 finderArgs, this);
514
515 if (list == null) {
516 Session session = null;
517
518 try {
519 session = openSession();
520
521 StringBundler query = null;
522
523 if (orderByComparator != null) {
524 query = new StringBundler(4 +
525 (orderByComparator.getOrderByFields().length * 3));
526 }
527 else {
528 query = new StringBundler(3);
529 }
530
531 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
532
533 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
534
535 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
536
537 if (orderByComparator != null) {
538 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
539 orderByComparator);
540 }
541
542 String sql = query.toString();
543
544 Query q = session.createQuery(sql);
545
546 QueryPos qPos = QueryPos.getInstance(q);
547
548 qPos.add(classNameId);
549
550 qPos.add(classPK);
551
552 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
553 start, end);
554 }
555 catch (Exception e) {
556 throw processException(e);
557 }
558 finally {
559 if (list == null) {
560 list = new ArrayList<RatingsEntry>();
561 }
562
563 cacheResult(list);
564
565 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
566 list);
567
568 closeSession(session);
569 }
570 }
571
572 return list;
573 }
574
575
589 public RatingsEntry findByC_C_First(long classNameId, long classPK,
590 OrderByComparator orderByComparator)
591 throws NoSuchEntryException, SystemException {
592 List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
593 orderByComparator);
594
595 if (list.isEmpty()) {
596 StringBundler msg = new StringBundler(6);
597
598 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
599
600 msg.append("classNameId=");
601 msg.append(classNameId);
602
603 msg.append(", classPK=");
604 msg.append(classPK);
605
606 msg.append(StringPool.CLOSE_CURLY_BRACE);
607
608 throw new NoSuchEntryException(msg.toString());
609 }
610 else {
611 return list.get(0);
612 }
613 }
614
615
629 public RatingsEntry findByC_C_Last(long classNameId, long classPK,
630 OrderByComparator orderByComparator)
631 throws NoSuchEntryException, SystemException {
632 int count = countByC_C(classNameId, classPK);
633
634 List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
635 count, orderByComparator);
636
637 if (list.isEmpty()) {
638 StringBundler msg = new StringBundler(6);
639
640 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
641
642 msg.append("classNameId=");
643 msg.append(classNameId);
644
645 msg.append(", classPK=");
646 msg.append(classPK);
647
648 msg.append(StringPool.CLOSE_CURLY_BRACE);
649
650 throw new NoSuchEntryException(msg.toString());
651 }
652 else {
653 return list.get(0);
654 }
655 }
656
657
672 public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
673 long classPK, OrderByComparator orderByComparator)
674 throws NoSuchEntryException, SystemException {
675 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
676
677 Session session = null;
678
679 try {
680 session = openSession();
681
682 RatingsEntry[] array = new RatingsEntryImpl[3];
683
684 array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
685 classPK, orderByComparator, true);
686
687 array[1] = ratingsEntry;
688
689 array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
690 classPK, orderByComparator, false);
691
692 return array;
693 }
694 catch (Exception e) {
695 throw processException(e);
696 }
697 finally {
698 closeSession(session);
699 }
700 }
701
702 protected RatingsEntry getByC_C_PrevAndNext(Session session,
703 RatingsEntry ratingsEntry, long classNameId, long classPK,
704 OrderByComparator orderByComparator, boolean previous) {
705 StringBundler query = null;
706
707 if (orderByComparator != null) {
708 query = new StringBundler(6 +
709 (orderByComparator.getOrderByFields().length * 6));
710 }
711 else {
712 query = new StringBundler(3);
713 }
714
715 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
716
717 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
718
719 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
720
721 if (orderByComparator != null) {
722 String[] orderByFields = orderByComparator.getOrderByFields();
723
724 if (orderByFields.length > 0) {
725 query.append(WHERE_AND);
726 }
727
728 for (int i = 0; i < orderByFields.length; i++) {
729 query.append(_ORDER_BY_ENTITY_ALIAS);
730 query.append(orderByFields[i]);
731
732 if ((i + 1) < orderByFields.length) {
733 if (orderByComparator.isAscending() ^ previous) {
734 query.append(WHERE_GREATER_THAN_HAS_NEXT);
735 }
736 else {
737 query.append(WHERE_LESSER_THAN_HAS_NEXT);
738 }
739 }
740 else {
741 if (orderByComparator.isAscending() ^ previous) {
742 query.append(WHERE_GREATER_THAN);
743 }
744 else {
745 query.append(WHERE_LESSER_THAN);
746 }
747 }
748 }
749
750 query.append(ORDER_BY_CLAUSE);
751
752 for (int i = 0; i < orderByFields.length; i++) {
753 query.append(_ORDER_BY_ENTITY_ALIAS);
754 query.append(orderByFields[i]);
755
756 if ((i + 1) < orderByFields.length) {
757 if (orderByComparator.isAscending() ^ previous) {
758 query.append(ORDER_BY_ASC_HAS_NEXT);
759 }
760 else {
761 query.append(ORDER_BY_DESC_HAS_NEXT);
762 }
763 }
764 else {
765 if (orderByComparator.isAscending() ^ previous) {
766 query.append(ORDER_BY_ASC);
767 }
768 else {
769 query.append(ORDER_BY_DESC);
770 }
771 }
772 }
773 }
774
775 String sql = query.toString();
776
777 Query q = session.createQuery(sql);
778
779 q.setFirstResult(0);
780 q.setMaxResults(2);
781
782 QueryPos qPos = QueryPos.getInstance(q);
783
784 qPos.add(classNameId);
785
786 qPos.add(classPK);
787
788 if (orderByComparator != null) {
789 Object[] values = orderByComparator.getOrderByValues(ratingsEntry);
790
791 for (Object value : values) {
792 qPos.add(value);
793 }
794 }
795
796 List<RatingsEntry> list = q.list();
797
798 if (list.size() == 2) {
799 return list.get(1);
800 }
801 else {
802 return null;
803 }
804 }
805
806
816 public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
817 throws NoSuchEntryException, SystemException {
818 RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
819
820 if (ratingsEntry == null) {
821 StringBundler msg = new StringBundler(8);
822
823 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
824
825 msg.append("userId=");
826 msg.append(userId);
827
828 msg.append(", classNameId=");
829 msg.append(classNameId);
830
831 msg.append(", classPK=");
832 msg.append(classPK);
833
834 msg.append(StringPool.CLOSE_CURLY_BRACE);
835
836 if (_log.isWarnEnabled()) {
837 _log.warn(msg.toString());
838 }
839
840 throw new NoSuchEntryException(msg.toString());
841 }
842
843 return ratingsEntry;
844 }
845
846
855 public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
856 throws SystemException {
857 return fetchByU_C_C(userId, classNameId, classPK, true);
858 }
859
860
869 public RatingsEntry fetchByU_C_C(long userId, long classNameId,
870 long classPK, boolean retrieveFromCache) throws SystemException {
871 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
872
873 Object result = null;
874
875 if (retrieveFromCache) {
876 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
877 finderArgs, this);
878 }
879
880 if (result == null) {
881 Session session = null;
882
883 try {
884 session = openSession();
885
886 StringBundler query = new StringBundler(4);
887
888 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
889
890 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
891
892 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
893
894 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
895
896 String sql = query.toString();
897
898 Query q = session.createQuery(sql);
899
900 QueryPos qPos = QueryPos.getInstance(q);
901
902 qPos.add(userId);
903
904 qPos.add(classNameId);
905
906 qPos.add(classPK);
907
908 List<RatingsEntry> list = q.list();
909
910 result = list;
911
912 RatingsEntry ratingsEntry = null;
913
914 if (list.isEmpty()) {
915 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
916 finderArgs, list);
917 }
918 else {
919 ratingsEntry = list.get(0);
920
921 cacheResult(ratingsEntry);
922
923 if ((ratingsEntry.getUserId() != userId) ||
924 (ratingsEntry.getClassNameId() != classNameId) ||
925 (ratingsEntry.getClassPK() != classPK)) {
926 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
927 finderArgs, ratingsEntry);
928 }
929 }
930
931 return ratingsEntry;
932 }
933 catch (Exception e) {
934 throw processException(e);
935 }
936 finally {
937 if (result == null) {
938 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
939 finderArgs, new ArrayList<RatingsEntry>());
940 }
941
942 closeSession(session);
943 }
944 }
945 else {
946 if (result instanceof List<?>) {
947 return null;
948 }
949 else {
950 return (RatingsEntry)result;
951 }
952 }
953 }
954
955
961 public List<RatingsEntry> findAll() throws SystemException {
962 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
963 }
964
965
977 public List<RatingsEntry> findAll(int start, int end)
978 throws SystemException {
979 return findAll(start, end, null);
980 }
981
982
995 public List<RatingsEntry> findAll(int start, int end,
996 OrderByComparator orderByComparator) throws SystemException {
997 Object[] finderArgs = new Object[] {
998 String.valueOf(start), String.valueOf(end),
999 String.valueOf(orderByComparator)
1000 };
1001
1002 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1003 finderArgs, this);
1004
1005 if (list == null) {
1006 Session session = null;
1007
1008 try {
1009 session = openSession();
1010
1011 StringBundler query = null;
1012 String sql = null;
1013
1014 if (orderByComparator != null) {
1015 query = new StringBundler(2 +
1016 (orderByComparator.getOrderByFields().length * 3));
1017
1018 query.append(_SQL_SELECT_RATINGSENTRY);
1019
1020 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1021 orderByComparator);
1022
1023 sql = query.toString();
1024 }
1025 else {
1026 sql = _SQL_SELECT_RATINGSENTRY;
1027 }
1028
1029 Query q = session.createQuery(sql);
1030
1031 if (orderByComparator == null) {
1032 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1033 start, end, false);
1034
1035 Collections.sort(list);
1036 }
1037 else {
1038 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1039 start, end);
1040 }
1041 }
1042 catch (Exception e) {
1043 throw processException(e);
1044 }
1045 finally {
1046 if (list == null) {
1047 list = new ArrayList<RatingsEntry>();
1048 }
1049
1050 cacheResult(list);
1051
1052 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1053
1054 closeSession(session);
1055 }
1056 }
1057
1058 return list;
1059 }
1060
1061
1068 public void removeByC_C(long classNameId, long classPK)
1069 throws SystemException {
1070 for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
1071 remove(ratingsEntry);
1072 }
1073 }
1074
1075
1083 public void removeByU_C_C(long userId, long classNameId, long classPK)
1084 throws NoSuchEntryException, SystemException {
1085 RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
1086
1087 remove(ratingsEntry);
1088 }
1089
1090
1095 public void removeAll() throws SystemException {
1096 for (RatingsEntry ratingsEntry : findAll()) {
1097 remove(ratingsEntry);
1098 }
1099 }
1100
1101
1109 public int countByC_C(long classNameId, long classPK)
1110 throws SystemException {
1111 Object[] finderArgs = new Object[] { classNameId, classPK };
1112
1113 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1114 finderArgs, this);
1115
1116 if (count == null) {
1117 Session session = null;
1118
1119 try {
1120 session = openSession();
1121
1122 StringBundler query = new StringBundler(3);
1123
1124 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1125
1126 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1127
1128 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1129
1130 String sql = query.toString();
1131
1132 Query q = session.createQuery(sql);
1133
1134 QueryPos qPos = QueryPos.getInstance(q);
1135
1136 qPos.add(classNameId);
1137
1138 qPos.add(classPK);
1139
1140 count = (Long)q.uniqueResult();
1141 }
1142 catch (Exception e) {
1143 throw processException(e);
1144 }
1145 finally {
1146 if (count == null) {
1147 count = Long.valueOf(0);
1148 }
1149
1150 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1151 count);
1152
1153 closeSession(session);
1154 }
1155 }
1156
1157 return count.intValue();
1158 }
1159
1160
1169 public int countByU_C_C(long userId, long classNameId, long classPK)
1170 throws SystemException {
1171 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1172
1173 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
1174 finderArgs, this);
1175
1176 if (count == null) {
1177 Session session = null;
1178
1179 try {
1180 session = openSession();
1181
1182 StringBundler query = new StringBundler(4);
1183
1184 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1185
1186 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1187
1188 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1189
1190 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1191
1192 String sql = query.toString();
1193
1194 Query q = session.createQuery(sql);
1195
1196 QueryPos qPos = QueryPos.getInstance(q);
1197
1198 qPos.add(userId);
1199
1200 qPos.add(classNameId);
1201
1202 qPos.add(classPK);
1203
1204 count = (Long)q.uniqueResult();
1205 }
1206 catch (Exception e) {
1207 throw processException(e);
1208 }
1209 finally {
1210 if (count == null) {
1211 count = Long.valueOf(0);
1212 }
1213
1214 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
1215 finderArgs, count);
1216
1217 closeSession(session);
1218 }
1219 }
1220
1221 return count.intValue();
1222 }
1223
1224
1230 public int countAll() throws SystemException {
1231 Object[] finderArgs = new Object[0];
1232
1233 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1234 finderArgs, this);
1235
1236 if (count == null) {
1237 Session session = null;
1238
1239 try {
1240 session = openSession();
1241
1242 Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
1243
1244 count = (Long)q.uniqueResult();
1245 }
1246 catch (Exception e) {
1247 throw processException(e);
1248 }
1249 finally {
1250 if (count == null) {
1251 count = Long.valueOf(0);
1252 }
1253
1254 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1255 count);
1256
1257 closeSession(session);
1258 }
1259 }
1260
1261 return count.intValue();
1262 }
1263
1264
1267 public void afterPropertiesSet() {
1268 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1269 com.liferay.portal.util.PropsUtil.get(
1270 "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1271
1272 if (listenerClassNames.length > 0) {
1273 try {
1274 List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1275
1276 for (String listenerClassName : listenerClassNames) {
1277 listenersList.add((ModelListener<RatingsEntry>)InstanceFactory.newInstance(
1278 listenerClassName));
1279 }
1280
1281 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1282 }
1283 catch (Exception e) {
1284 _log.error(e);
1285 }
1286 }
1287 }
1288
1289 @BeanReference(type = RatingsEntryPersistence.class)
1290 protected RatingsEntryPersistence ratingsEntryPersistence;
1291 @BeanReference(type = RatingsStatsPersistence.class)
1292 protected RatingsStatsPersistence ratingsStatsPersistence;
1293 @BeanReference(type = ResourcePersistence.class)
1294 protected ResourcePersistence resourcePersistence;
1295 @BeanReference(type = UserPersistence.class)
1296 protected UserPersistence userPersistence;
1297 @BeanReference(type = BlogsEntryPersistence.class)
1298 protected BlogsEntryPersistence blogsEntryPersistence;
1299 @BeanReference(type = BlogsStatsUserPersistence.class)
1300 protected BlogsStatsUserPersistence blogsStatsUserPersistence;
1301 @BeanReference(type = SocialEquityLogPersistence.class)
1302 protected SocialEquityLogPersistence socialEquityLogPersistence;
1303 private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
1304 private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
1305 private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
1306 private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
1307 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1308 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1309 private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1310 private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1311 private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1312 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
1313 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
1314 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
1315 private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1316 }