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 BatchSessionUtil.delete(session, ratingsEntry);
253 }
254 catch (Exception e) {
255 throw processException(e);
256 }
257 finally {
258 closeSession(session);
259 }
260
261 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
262
263 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
264
265 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
266 new Object[] {
267 new Long(ratingsEntryModelImpl.getOriginalUserId()),
268 new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
269 new Long(ratingsEntryModelImpl.getOriginalClassPK())
270 });
271
272 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
273 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
274
275 return ratingsEntry;
276 }
277
278 public RatingsEntry updateImpl(
279 com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
280 boolean merge) throws SystemException {
281 ratingsEntry = toUnwrappedModel(ratingsEntry);
282
283 boolean isNew = ratingsEntry.isNew();
284
285 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
286
287 Session session = null;
288
289 try {
290 session = openSession();
291
292 BatchSessionUtil.update(session, ratingsEntry, merge);
293
294 ratingsEntry.setNew(false);
295 }
296 catch (Exception e) {
297 throw processException(e);
298 }
299 finally {
300 closeSession(session);
301 }
302
303 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
304
305 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
306 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
307
308 if (!isNew &&
309 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
310 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
311 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
312 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
313 new Object[] {
314 new Long(ratingsEntryModelImpl.getOriginalUserId()),
315 new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
316 new Long(ratingsEntryModelImpl.getOriginalClassPK())
317 });
318 }
319
320 if (isNew ||
321 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
322 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
323 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
324 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
325 new Object[] {
326 new Long(ratingsEntry.getUserId()),
327 new Long(ratingsEntry.getClassNameId()),
328 new Long(ratingsEntry.getClassPK())
329 }, ratingsEntry);
330 }
331
332 return ratingsEntry;
333 }
334
335 protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
336 if (ratingsEntry instanceof RatingsEntryImpl) {
337 return ratingsEntry;
338 }
339
340 RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
341
342 ratingsEntryImpl.setNew(ratingsEntry.isNew());
343 ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
344
345 ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
346 ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
347 ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
348 ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
349 ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
350 ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
351 ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
352 ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
353 ratingsEntryImpl.setScore(ratingsEntry.getScore());
354
355 return ratingsEntryImpl;
356 }
357
358
366 public RatingsEntry findByPrimaryKey(Serializable primaryKey)
367 throws NoSuchModelException, SystemException {
368 return findByPrimaryKey(((Long)primaryKey).longValue());
369 }
370
371
379 public RatingsEntry findByPrimaryKey(long entryId)
380 throws NoSuchEntryException, SystemException {
381 RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
382
383 if (ratingsEntry == null) {
384 if (_log.isWarnEnabled()) {
385 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
386 }
387
388 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
389 entryId);
390 }
391
392 return ratingsEntry;
393 }
394
395
402 public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
403 throws SystemException {
404 return fetchByPrimaryKey(((Long)primaryKey).longValue());
405 }
406
407
414 public RatingsEntry fetchByPrimaryKey(long entryId)
415 throws SystemException {
416 RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
417 RatingsEntryImpl.class, entryId, this);
418
419 if (ratingsEntry == null) {
420 Session session = null;
421
422 try {
423 session = openSession();
424
425 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
426 new Long(entryId));
427 }
428 catch (Exception e) {
429 throw processException(e);
430 }
431 finally {
432 if (ratingsEntry != null) {
433 cacheResult(ratingsEntry);
434 }
435
436 closeSession(session);
437 }
438 }
439
440 return ratingsEntry;
441 }
442
443
451 public List<RatingsEntry> findByC_C(long classNameId, long classPK)
452 throws SystemException {
453 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
454 QueryUtil.ALL_POS, null);
455 }
456
457
471 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
472 int start, int end) throws SystemException {
473 return findByC_C(classNameId, classPK, start, end, null);
474 }
475
476
491 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
492 int start, int end, OrderByComparator orderByComparator)
493 throws SystemException {
494 Object[] finderArgs = new Object[] {
495 classNameId, classPK,
496
497 String.valueOf(start), String.valueOf(end),
498 String.valueOf(orderByComparator)
499 };
500
501 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
502 finderArgs, this);
503
504 if (list == null) {
505 Session session = null;
506
507 try {
508 session = openSession();
509
510 StringBundler query = null;
511
512 if (orderByComparator != null) {
513 query = new StringBundler(4 +
514 (orderByComparator.getOrderByFields().length * 3));
515 }
516 else {
517 query = new StringBundler(3);
518 }
519
520 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
521
522 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
523
524 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
525
526 if (orderByComparator != null) {
527 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
528 orderByComparator);
529 }
530
531 String sql = query.toString();
532
533 Query q = session.createQuery(sql);
534
535 QueryPos qPos = QueryPos.getInstance(q);
536
537 qPos.add(classNameId);
538
539 qPos.add(classPK);
540
541 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
542 start, end);
543 }
544 catch (Exception e) {
545 throw processException(e);
546 }
547 finally {
548 if (list == null) {
549 list = new ArrayList<RatingsEntry>();
550 }
551
552 cacheResult(list);
553
554 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
555 list);
556
557 closeSession(session);
558 }
559 }
560
561 return list;
562 }
563
564
578 public RatingsEntry findByC_C_First(long classNameId, long classPK,
579 OrderByComparator orderByComparator)
580 throws NoSuchEntryException, SystemException {
581 List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
582 orderByComparator);
583
584 if (list.isEmpty()) {
585 StringBundler msg = new StringBundler(6);
586
587 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
588
589 msg.append("classNameId=");
590 msg.append(classNameId);
591
592 msg.append(", classPK=");
593 msg.append(classPK);
594
595 msg.append(StringPool.CLOSE_CURLY_BRACE);
596
597 throw new NoSuchEntryException(msg.toString());
598 }
599 else {
600 return list.get(0);
601 }
602 }
603
604
618 public RatingsEntry findByC_C_Last(long classNameId, long classPK,
619 OrderByComparator orderByComparator)
620 throws NoSuchEntryException, SystemException {
621 int count = countByC_C(classNameId, classPK);
622
623 List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
624 count, orderByComparator);
625
626 if (list.isEmpty()) {
627 StringBundler msg = new StringBundler(6);
628
629 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
630
631 msg.append("classNameId=");
632 msg.append(classNameId);
633
634 msg.append(", classPK=");
635 msg.append(classPK);
636
637 msg.append(StringPool.CLOSE_CURLY_BRACE);
638
639 throw new NoSuchEntryException(msg.toString());
640 }
641 else {
642 return list.get(0);
643 }
644 }
645
646
661 public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
662 long classPK, OrderByComparator orderByComparator)
663 throws NoSuchEntryException, SystemException {
664 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
665
666 Session session = null;
667
668 try {
669 session = openSession();
670
671 RatingsEntry[] array = new RatingsEntryImpl[3];
672
673 array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
674 classPK, orderByComparator, true);
675
676 array[1] = ratingsEntry;
677
678 array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
679 classPK, orderByComparator, false);
680
681 return array;
682 }
683 catch (Exception e) {
684 throw processException(e);
685 }
686 finally {
687 closeSession(session);
688 }
689 }
690
691 protected RatingsEntry getByC_C_PrevAndNext(Session session,
692 RatingsEntry ratingsEntry, long classNameId, long classPK,
693 OrderByComparator orderByComparator, boolean previous) {
694 StringBundler query = null;
695
696 if (orderByComparator != null) {
697 query = new StringBundler(6 +
698 (orderByComparator.getOrderByFields().length * 6));
699 }
700 else {
701 query = new StringBundler(3);
702 }
703
704 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
705
706 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
707
708 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
709
710 if (orderByComparator != null) {
711 String[] orderByFields = orderByComparator.getOrderByFields();
712
713 if (orderByFields.length > 0) {
714 query.append(WHERE_AND);
715 }
716
717 for (int i = 0; i < orderByFields.length; i++) {
718 query.append(_ORDER_BY_ENTITY_ALIAS);
719 query.append(orderByFields[i]);
720
721 if ((i + 1) < orderByFields.length) {
722 if (orderByComparator.isAscending() ^ previous) {
723 query.append(WHERE_GREATER_THAN_HAS_NEXT);
724 }
725 else {
726 query.append(WHERE_LESSER_THAN_HAS_NEXT);
727 }
728 }
729 else {
730 if (orderByComparator.isAscending() ^ previous) {
731 query.append(WHERE_GREATER_THAN);
732 }
733 else {
734 query.append(WHERE_LESSER_THAN);
735 }
736 }
737 }
738
739 query.append(ORDER_BY_CLAUSE);
740
741 for (int i = 0; i < orderByFields.length; i++) {
742 query.append(_ORDER_BY_ENTITY_ALIAS);
743 query.append(orderByFields[i]);
744
745 if ((i + 1) < orderByFields.length) {
746 if (orderByComparator.isAscending() ^ previous) {
747 query.append(ORDER_BY_ASC_HAS_NEXT);
748 }
749 else {
750 query.append(ORDER_BY_DESC_HAS_NEXT);
751 }
752 }
753 else {
754 if (orderByComparator.isAscending() ^ previous) {
755 query.append(ORDER_BY_ASC);
756 }
757 else {
758 query.append(ORDER_BY_DESC);
759 }
760 }
761 }
762 }
763
764 String sql = query.toString();
765
766 Query q = session.createQuery(sql);
767
768 q.setFirstResult(0);
769 q.setMaxResults(2);
770
771 QueryPos qPos = QueryPos.getInstance(q);
772
773 qPos.add(classNameId);
774
775 qPos.add(classPK);
776
777 if (orderByComparator != null) {
778 Object[] values = orderByComparator.getOrderByValues(ratingsEntry);
779
780 for (Object value : values) {
781 qPos.add(value);
782 }
783 }
784
785 List<RatingsEntry> list = q.list();
786
787 if (list.size() == 2) {
788 return list.get(1);
789 }
790 else {
791 return null;
792 }
793 }
794
795
805 public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
806 throws NoSuchEntryException, SystemException {
807 RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
808
809 if (ratingsEntry == null) {
810 StringBundler msg = new StringBundler(8);
811
812 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
813
814 msg.append("userId=");
815 msg.append(userId);
816
817 msg.append(", classNameId=");
818 msg.append(classNameId);
819
820 msg.append(", classPK=");
821 msg.append(classPK);
822
823 msg.append(StringPool.CLOSE_CURLY_BRACE);
824
825 if (_log.isWarnEnabled()) {
826 _log.warn(msg.toString());
827 }
828
829 throw new NoSuchEntryException(msg.toString());
830 }
831
832 return ratingsEntry;
833 }
834
835
844 public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
845 throws SystemException {
846 return fetchByU_C_C(userId, classNameId, classPK, true);
847 }
848
849
858 public RatingsEntry fetchByU_C_C(long userId, long classNameId,
859 long classPK, boolean retrieveFromCache) throws SystemException {
860 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
861
862 Object result = null;
863
864 if (retrieveFromCache) {
865 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
866 finderArgs, this);
867 }
868
869 if (result == null) {
870 Session session = null;
871
872 try {
873 session = openSession();
874
875 StringBundler query = new StringBundler(4);
876
877 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
878
879 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
880
881 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
882
883 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
884
885 String sql = query.toString();
886
887 Query q = session.createQuery(sql);
888
889 QueryPos qPos = QueryPos.getInstance(q);
890
891 qPos.add(userId);
892
893 qPos.add(classNameId);
894
895 qPos.add(classPK);
896
897 List<RatingsEntry> list = q.list();
898
899 result = list;
900
901 RatingsEntry ratingsEntry = null;
902
903 if (list.isEmpty()) {
904 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
905 finderArgs, list);
906 }
907 else {
908 ratingsEntry = list.get(0);
909
910 cacheResult(ratingsEntry);
911
912 if ((ratingsEntry.getUserId() != userId) ||
913 (ratingsEntry.getClassNameId() != classNameId) ||
914 (ratingsEntry.getClassPK() != classPK)) {
915 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
916 finderArgs, ratingsEntry);
917 }
918 }
919
920 return ratingsEntry;
921 }
922 catch (Exception e) {
923 throw processException(e);
924 }
925 finally {
926 if (result == null) {
927 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
928 finderArgs, new ArrayList<RatingsEntry>());
929 }
930
931 closeSession(session);
932 }
933 }
934 else {
935 if (result instanceof List<?>) {
936 return null;
937 }
938 else {
939 return (RatingsEntry)result;
940 }
941 }
942 }
943
944
950 public List<RatingsEntry> findAll() throws SystemException {
951 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
952 }
953
954
966 public List<RatingsEntry> findAll(int start, int end)
967 throws SystemException {
968 return findAll(start, end, null);
969 }
970
971
984 public List<RatingsEntry> findAll(int start, int end,
985 OrderByComparator orderByComparator) throws SystemException {
986 Object[] finderArgs = new Object[] {
987 String.valueOf(start), String.valueOf(end),
988 String.valueOf(orderByComparator)
989 };
990
991 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
992 finderArgs, this);
993
994 if (list == null) {
995 Session session = null;
996
997 try {
998 session = openSession();
999
1000 StringBundler query = null;
1001 String sql = null;
1002
1003 if (orderByComparator != null) {
1004 query = new StringBundler(2 +
1005 (orderByComparator.getOrderByFields().length * 3));
1006
1007 query.append(_SQL_SELECT_RATINGSENTRY);
1008
1009 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1010 orderByComparator);
1011
1012 sql = query.toString();
1013 }
1014 else {
1015 sql = _SQL_SELECT_RATINGSENTRY;
1016 }
1017
1018 Query q = session.createQuery(sql);
1019
1020 if (orderByComparator == null) {
1021 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1022 start, end, false);
1023
1024 Collections.sort(list);
1025 }
1026 else {
1027 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1028 start, end);
1029 }
1030 }
1031 catch (Exception e) {
1032 throw processException(e);
1033 }
1034 finally {
1035 if (list == null) {
1036 list = new ArrayList<RatingsEntry>();
1037 }
1038
1039 cacheResult(list);
1040
1041 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
1042
1043 closeSession(session);
1044 }
1045 }
1046
1047 return list;
1048 }
1049
1050
1057 public void removeByC_C(long classNameId, long classPK)
1058 throws SystemException {
1059 for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
1060 remove(ratingsEntry);
1061 }
1062 }
1063
1064
1072 public void removeByU_C_C(long userId, long classNameId, long classPK)
1073 throws NoSuchEntryException, SystemException {
1074 RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
1075
1076 remove(ratingsEntry);
1077 }
1078
1079
1084 public void removeAll() throws SystemException {
1085 for (RatingsEntry ratingsEntry : findAll()) {
1086 remove(ratingsEntry);
1087 }
1088 }
1089
1090
1098 public int countByC_C(long classNameId, long classPK)
1099 throws SystemException {
1100 Object[] finderArgs = new Object[] { classNameId, classPK };
1101
1102 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1103 finderArgs, this);
1104
1105 if (count == null) {
1106 Session session = null;
1107
1108 try {
1109 session = openSession();
1110
1111 StringBundler query = new StringBundler(3);
1112
1113 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1114
1115 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1116
1117 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1118
1119 String sql = query.toString();
1120
1121 Query q = session.createQuery(sql);
1122
1123 QueryPos qPos = QueryPos.getInstance(q);
1124
1125 qPos.add(classNameId);
1126
1127 qPos.add(classPK);
1128
1129 count = (Long)q.uniqueResult();
1130 }
1131 catch (Exception e) {
1132 throw processException(e);
1133 }
1134 finally {
1135 if (count == null) {
1136 count = Long.valueOf(0);
1137 }
1138
1139 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1140 count);
1141
1142 closeSession(session);
1143 }
1144 }
1145
1146 return count.intValue();
1147 }
1148
1149
1158 public int countByU_C_C(long userId, long classNameId, long classPK)
1159 throws SystemException {
1160 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1161
1162 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
1163 finderArgs, this);
1164
1165 if (count == null) {
1166 Session session = null;
1167
1168 try {
1169 session = openSession();
1170
1171 StringBundler query = new StringBundler(4);
1172
1173 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1174
1175 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1176
1177 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1178
1179 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1180
1181 String sql = query.toString();
1182
1183 Query q = session.createQuery(sql);
1184
1185 QueryPos qPos = QueryPos.getInstance(q);
1186
1187 qPos.add(userId);
1188
1189 qPos.add(classNameId);
1190
1191 qPos.add(classPK);
1192
1193 count = (Long)q.uniqueResult();
1194 }
1195 catch (Exception e) {
1196 throw processException(e);
1197 }
1198 finally {
1199 if (count == null) {
1200 count = Long.valueOf(0);
1201 }
1202
1203 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
1204 finderArgs, count);
1205
1206 closeSession(session);
1207 }
1208 }
1209
1210 return count.intValue();
1211 }
1212
1213
1219 public int countAll() throws SystemException {
1220 Object[] finderArgs = new Object[0];
1221
1222 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1223 finderArgs, this);
1224
1225 if (count == null) {
1226 Session session = null;
1227
1228 try {
1229 session = openSession();
1230
1231 Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
1232
1233 count = (Long)q.uniqueResult();
1234 }
1235 catch (Exception e) {
1236 throw processException(e);
1237 }
1238 finally {
1239 if (count == null) {
1240 count = Long.valueOf(0);
1241 }
1242
1243 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1244 count);
1245
1246 closeSession(session);
1247 }
1248 }
1249
1250 return count.intValue();
1251 }
1252
1253
1256 public void afterPropertiesSet() {
1257 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1258 com.liferay.portal.util.PropsUtil.get(
1259 "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1260
1261 if (listenerClassNames.length > 0) {
1262 try {
1263 List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1264
1265 for (String listenerClassName : listenerClassNames) {
1266 listenersList.add((ModelListener<RatingsEntry>)InstanceFactory.newInstance(
1267 listenerClassName));
1268 }
1269
1270 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1271 }
1272 catch (Exception e) {
1273 _log.error(e);
1274 }
1275 }
1276 }
1277
1278 public void destroy() {
1279 EntityCacheUtil.removeCache(RatingsEntryImpl.class.getName());
1280 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1281 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
1282 }
1283
1284 @BeanReference(type = RatingsEntryPersistence.class)
1285 protected RatingsEntryPersistence ratingsEntryPersistence;
1286 @BeanReference(type = RatingsStatsPersistence.class)
1287 protected RatingsStatsPersistence ratingsStatsPersistence;
1288 @BeanReference(type = ResourcePersistence.class)
1289 protected ResourcePersistence resourcePersistence;
1290 @BeanReference(type = UserPersistence.class)
1291 protected UserPersistence userPersistence;
1292 @BeanReference(type = BlogsEntryPersistence.class)
1293 protected BlogsEntryPersistence blogsEntryPersistence;
1294 @BeanReference(type = BlogsStatsUserPersistence.class)
1295 protected BlogsStatsUserPersistence blogsStatsUserPersistence;
1296 @BeanReference(type = SocialEquityLogPersistence.class)
1297 protected SocialEquityLogPersistence socialEquityLogPersistence;
1298 private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
1299 private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
1300 private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
1301 private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
1302 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1303 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1304 private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1305 private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1306 private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1307 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
1308 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
1309 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
1310 private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1311 }