001
014
015 package com.liferay.portlet.ratings.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.kernel.bean.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.CacheModel;
037 import com.liferay.portal.model.ModelListener;
038 import com.liferay.portal.service.persistence.BatchSessionUtil;
039 import com.liferay.portal.service.persistence.ResourcePersistence;
040 import com.liferay.portal.service.persistence.UserPersistence;
041 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
042
043 import com.liferay.portlet.asset.service.persistence.AssetEntryPersistence;
044 import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
045 import com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence;
046 import com.liferay.portlet.ratings.NoSuchEntryException;
047 import com.liferay.portlet.ratings.model.RatingsEntry;
048 import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
049 import com.liferay.portlet.ratings.model.impl.RatingsEntryModelImpl;
050 import com.liferay.portlet.social.service.persistence.SocialActivityPersistence;
051
052 import java.io.Serializable;
053
054 import java.util.ArrayList;
055 import java.util.Collections;
056 import java.util.List;
057
058
070 public class RatingsEntryPersistenceImpl extends BasePersistenceImpl<RatingsEntry>
071 implements RatingsEntryPersistence {
072
077 public static final String FINDER_CLASS_NAME_ENTITY = RatingsEntryImpl.class.getName();
078 public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
079 ".List1";
080 public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081 ".List2";
082 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
083 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
084 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
085 new String[] {
086 Long.class.getName(), Long.class.getName(),
087
088 "java.lang.Integer", "java.lang.Integer",
089 "com.liferay.portal.kernel.util.OrderByComparator"
090 });
091 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
092 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
093 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
094 new String[] { Long.class.getName(), Long.class.getName() },
095 RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
096 RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK);
097 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
098 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
100 new String[] { Long.class.getName(), Long.class.getName() });
101 public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
102 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
103 FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C",
104 new String[] {
105 Long.class.getName(), Long.class.getName(), Long.class.getName()
106 },
107 RatingsEntryModelImpl.USERID_COLUMN_BITMASK |
108 RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
109 RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK);
110 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
111 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
112 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
113 new String[] {
114 Long.class.getName(), Long.class.getName(), Long.class.getName()
115 });
116 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
117 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
118 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
119 new String[] {
120 Long.class.getName(), Long.class.getName(),
121 Double.class.getName(),
122
123 "java.lang.Integer", "java.lang.Integer",
124 "com.liferay.portal.kernel.util.OrderByComparator"
125 });
126 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
127 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
128 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
129 new String[] {
130 Long.class.getName(), Long.class.getName(),
131 Double.class.getName()
132 },
133 RatingsEntryModelImpl.CLASSNAMEID_COLUMN_BITMASK |
134 RatingsEntryModelImpl.CLASSPK_COLUMN_BITMASK |
135 RatingsEntryModelImpl.SCORE_COLUMN_BITMASK);
136 public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
137 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
138 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
139 new String[] {
140 Long.class.getName(), Long.class.getName(),
141 Double.class.getName()
142 });
143 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
144 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
145 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
146 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
147 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, RatingsEntryImpl.class,
148 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
149 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
150 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, Long.class,
151 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
152
153
158 public void cacheResult(RatingsEntry ratingsEntry) {
159 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
160 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
161
162 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
163 new Object[] {
164 Long.valueOf(ratingsEntry.getUserId()),
165 Long.valueOf(ratingsEntry.getClassNameId()),
166 Long.valueOf(ratingsEntry.getClassPK())
167 }, ratingsEntry);
168
169 ratingsEntry.resetOriginalValues();
170 }
171
172
177 public void cacheResult(List<RatingsEntry> ratingsEntries) {
178 for (RatingsEntry ratingsEntry : ratingsEntries) {
179 if (EntityCacheUtil.getResult(
180 RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
181 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey()) == null) {
182 cacheResult(ratingsEntry);
183 }
184 else {
185 ratingsEntry.resetOriginalValues();
186 }
187 }
188 }
189
190
197 @Override
198 public void clearCache() {
199 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
200 CacheRegistryUtil.clear(RatingsEntryImpl.class.getName());
201 }
202
203 EntityCacheUtil.clearCache(RatingsEntryImpl.class.getName());
204
205 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
206 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
207 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
208 }
209
210
217 @Override
218 public void clearCache(RatingsEntry ratingsEntry) {
219 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
220 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
221
222 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
223 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
224
225 clearUniqueFindersCache(ratingsEntry);
226 }
227
228 @Override
229 public void clearCache(List<RatingsEntry> ratingsEntries) {
230 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
231 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
232
233 for (RatingsEntry ratingsEntry : ratingsEntries) {
234 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
235 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
236
237 clearUniqueFindersCache(ratingsEntry);
238 }
239 }
240
241 protected void clearUniqueFindersCache(RatingsEntry ratingsEntry) {
242 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
243 new Object[] {
244 Long.valueOf(ratingsEntry.getUserId()),
245 Long.valueOf(ratingsEntry.getClassNameId()),
246 Long.valueOf(ratingsEntry.getClassPK())
247 });
248 }
249
250
256 public RatingsEntry create(long entryId) {
257 RatingsEntry ratingsEntry = new RatingsEntryImpl();
258
259 ratingsEntry.setNew(true);
260 ratingsEntry.setPrimaryKey(entryId);
261
262 return ratingsEntry;
263 }
264
265
273 public RatingsEntry remove(long entryId)
274 throws NoSuchEntryException, SystemException {
275 return remove(Long.valueOf(entryId));
276 }
277
278
286 @Override
287 public RatingsEntry remove(Serializable primaryKey)
288 throws NoSuchEntryException, SystemException {
289 Session session = null;
290
291 try {
292 session = openSession();
293
294 RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
295 primaryKey);
296
297 if (ratingsEntry == null) {
298 if (_log.isWarnEnabled()) {
299 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
300 }
301
302 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
303 primaryKey);
304 }
305
306 return remove(ratingsEntry);
307 }
308 catch (NoSuchEntryException nsee) {
309 throw nsee;
310 }
311 catch (Exception e) {
312 throw processException(e);
313 }
314 finally {
315 closeSession(session);
316 }
317 }
318
319 @Override
320 protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
321 throws SystemException {
322 ratingsEntry = toUnwrappedModel(ratingsEntry);
323
324 Session session = null;
325
326 try {
327 session = openSession();
328
329 BatchSessionUtil.delete(session, ratingsEntry);
330 }
331 catch (Exception e) {
332 throw processException(e);
333 }
334 finally {
335 closeSession(session);
336 }
337
338 clearCache(ratingsEntry);
339
340 return ratingsEntry;
341 }
342
343 @Override
344 public RatingsEntry updateImpl(
345 com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
346 boolean merge) throws SystemException {
347 ratingsEntry = toUnwrappedModel(ratingsEntry);
348
349 boolean isNew = ratingsEntry.isNew();
350
351 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
352
353 Session session = null;
354
355 try {
356 session = openSession();
357
358 BatchSessionUtil.update(session, ratingsEntry, merge);
359
360 ratingsEntry.setNew(false);
361 }
362 catch (Exception e) {
363 throw processException(e);
364 }
365 finally {
366 closeSession(session);
367 }
368
369 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
370
371 if (isNew || !RatingsEntryModelImpl.COLUMN_BITMASK_ENABLED) {
372 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
373 }
374 else {
375 if ((ratingsEntryModelImpl.getColumnBitmask() &
376 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
377 Object[] args = new Object[] {
378 Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
379 Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK())
380 };
381
382 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
383 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
384 args);
385
386 args = new Object[] {
387 Long.valueOf(ratingsEntryModelImpl.getClassNameId()),
388 Long.valueOf(ratingsEntryModelImpl.getClassPK())
389 };
390
391 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
392 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
393 args);
394 }
395
396 if ((ratingsEntryModelImpl.getColumnBitmask() &
397 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
398 Object[] args = new Object[] {
399 Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
400 Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK()),
401 Double.valueOf(ratingsEntryModelImpl.getOriginalScore())
402 };
403
404 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
405 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
406 args);
407
408 args = new Object[] {
409 Long.valueOf(ratingsEntryModelImpl.getClassNameId()),
410 Long.valueOf(ratingsEntryModelImpl.getClassPK()),
411 Double.valueOf(ratingsEntryModelImpl.getScore())
412 };
413
414 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
415 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
416 args);
417 }
418 }
419
420 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
421 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
422
423 if (isNew) {
424 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
425 new Object[] {
426 Long.valueOf(ratingsEntry.getUserId()),
427 Long.valueOf(ratingsEntry.getClassNameId()),
428 Long.valueOf(ratingsEntry.getClassPK())
429 }, ratingsEntry);
430 }
431 else {
432 if ((ratingsEntryModelImpl.getColumnBitmask() &
433 FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
434 Object[] args = new Object[] {
435 Long.valueOf(ratingsEntryModelImpl.getOriginalUserId()),
436 Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
437 Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK())
438 };
439
440 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
441 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
442
443 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
444 new Object[] {
445 Long.valueOf(ratingsEntry.getUserId()),
446 Long.valueOf(ratingsEntry.getClassNameId()),
447 Long.valueOf(ratingsEntry.getClassPK())
448 }, ratingsEntry);
449 }
450 }
451
452 return ratingsEntry;
453 }
454
455 protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
456 if (ratingsEntry instanceof RatingsEntryImpl) {
457 return ratingsEntry;
458 }
459
460 RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
461
462 ratingsEntryImpl.setNew(ratingsEntry.isNew());
463 ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
464
465 ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
466 ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
467 ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
468 ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
469 ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
470 ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
471 ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
472 ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
473 ratingsEntryImpl.setScore(ratingsEntry.getScore());
474
475 return ratingsEntryImpl;
476 }
477
478
486 @Override
487 public RatingsEntry findByPrimaryKey(Serializable primaryKey)
488 throws NoSuchModelException, SystemException {
489 return findByPrimaryKey(((Long)primaryKey).longValue());
490 }
491
492
500 public RatingsEntry findByPrimaryKey(long entryId)
501 throws NoSuchEntryException, SystemException {
502 RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
503
504 if (ratingsEntry == null) {
505 if (_log.isWarnEnabled()) {
506 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
507 }
508
509 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
510 entryId);
511 }
512
513 return ratingsEntry;
514 }
515
516
523 @Override
524 public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
525 throws SystemException {
526 return fetchByPrimaryKey(((Long)primaryKey).longValue());
527 }
528
529
536 public RatingsEntry fetchByPrimaryKey(long entryId)
537 throws SystemException {
538 RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
539 RatingsEntryImpl.class, entryId);
540
541 if (ratingsEntry == _nullRatingsEntry) {
542 return null;
543 }
544
545 if (ratingsEntry == null) {
546 Session session = null;
547
548 boolean hasException = false;
549
550 try {
551 session = openSession();
552
553 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
554 Long.valueOf(entryId));
555 }
556 catch (Exception e) {
557 hasException = true;
558
559 throw processException(e);
560 }
561 finally {
562 if (ratingsEntry != null) {
563 cacheResult(ratingsEntry);
564 }
565 else if (!hasException) {
566 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
567 RatingsEntryImpl.class, entryId, _nullRatingsEntry);
568 }
569
570 closeSession(session);
571 }
572 }
573
574 return ratingsEntry;
575 }
576
577
585 public List<RatingsEntry> findByC_C(long classNameId, long classPK)
586 throws SystemException {
587 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
588 QueryUtil.ALL_POS, null);
589 }
590
591
605 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
606 int start, int end) throws SystemException {
607 return findByC_C(classNameId, classPK, start, end, null);
608 }
609
610
625 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
626 int start, int end, OrderByComparator orderByComparator)
627 throws SystemException {
628 FinderPath finderPath = null;
629 Object[] finderArgs = null;
630
631 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
632 (orderByComparator == null)) {
633 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
634 finderArgs = new Object[] { classNameId, classPK };
635 }
636 else {
637 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
638 finderArgs = new Object[] {
639 classNameId, classPK,
640
641 start, end, orderByComparator
642 };
643 }
644
645 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
646 finderArgs, this);
647
648 if ((list != null) && !list.isEmpty()) {
649 for (RatingsEntry ratingsEntry : list) {
650 if ((classNameId != ratingsEntry.getClassNameId()) ||
651 (classPK != ratingsEntry.getClassPK())) {
652 list = null;
653
654 break;
655 }
656 }
657 }
658
659 if (list == null) {
660 StringBundler query = null;
661
662 if (orderByComparator != null) {
663 query = new StringBundler(4 +
664 (orderByComparator.getOrderByFields().length * 3));
665 }
666 else {
667 query = new StringBundler(3);
668 }
669
670 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
671
672 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
673
674 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
675
676 if (orderByComparator != null) {
677 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
678 orderByComparator);
679 }
680
681 String sql = query.toString();
682
683 Session session = null;
684
685 try {
686 session = openSession();
687
688 Query q = session.createQuery(sql);
689
690 QueryPos qPos = QueryPos.getInstance(q);
691
692 qPos.add(classNameId);
693
694 qPos.add(classPK);
695
696 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
697 start, end);
698 }
699 catch (Exception e) {
700 throw processException(e);
701 }
702 finally {
703 if (list == null) {
704 FinderCacheUtil.removeResult(finderPath, finderArgs);
705 }
706 else {
707 cacheResult(list);
708
709 FinderCacheUtil.putResult(finderPath, finderArgs, list);
710 }
711
712 closeSession(session);
713 }
714 }
715
716 return list;
717 }
718
719
733 public RatingsEntry findByC_C_First(long classNameId, long classPK,
734 OrderByComparator orderByComparator)
735 throws NoSuchEntryException, SystemException {
736 List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
737 orderByComparator);
738
739 if (list.isEmpty()) {
740 StringBundler msg = new StringBundler(6);
741
742 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
743
744 msg.append("classNameId=");
745 msg.append(classNameId);
746
747 msg.append(", classPK=");
748 msg.append(classPK);
749
750 msg.append(StringPool.CLOSE_CURLY_BRACE);
751
752 throw new NoSuchEntryException(msg.toString());
753 }
754 else {
755 return list.get(0);
756 }
757 }
758
759
773 public RatingsEntry findByC_C_Last(long classNameId, long classPK,
774 OrderByComparator orderByComparator)
775 throws NoSuchEntryException, SystemException {
776 int count = countByC_C(classNameId, classPK);
777
778 List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
779 count, orderByComparator);
780
781 if (list.isEmpty()) {
782 StringBundler msg = new StringBundler(6);
783
784 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
785
786 msg.append("classNameId=");
787 msg.append(classNameId);
788
789 msg.append(", classPK=");
790 msg.append(classPK);
791
792 msg.append(StringPool.CLOSE_CURLY_BRACE);
793
794 throw new NoSuchEntryException(msg.toString());
795 }
796 else {
797 return list.get(0);
798 }
799 }
800
801
816 public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
817 long classPK, OrderByComparator orderByComparator)
818 throws NoSuchEntryException, SystemException {
819 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
820
821 Session session = null;
822
823 try {
824 session = openSession();
825
826 RatingsEntry[] array = new RatingsEntryImpl[3];
827
828 array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
829 classPK, orderByComparator, true);
830
831 array[1] = ratingsEntry;
832
833 array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
834 classPK, orderByComparator, false);
835
836 return array;
837 }
838 catch (Exception e) {
839 throw processException(e);
840 }
841 finally {
842 closeSession(session);
843 }
844 }
845
846 protected RatingsEntry getByC_C_PrevAndNext(Session session,
847 RatingsEntry ratingsEntry, long classNameId, long classPK,
848 OrderByComparator orderByComparator, boolean previous) {
849 StringBundler query = null;
850
851 if (orderByComparator != null) {
852 query = new StringBundler(6 +
853 (orderByComparator.getOrderByFields().length * 6));
854 }
855 else {
856 query = new StringBundler(3);
857 }
858
859 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
860
861 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
862
863 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
864
865 if (orderByComparator != null) {
866 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
867
868 if (orderByConditionFields.length > 0) {
869 query.append(WHERE_AND);
870 }
871
872 for (int i = 0; i < orderByConditionFields.length; i++) {
873 query.append(_ORDER_BY_ENTITY_ALIAS);
874 query.append(orderByConditionFields[i]);
875
876 if ((i + 1) < orderByConditionFields.length) {
877 if (orderByComparator.isAscending() ^ previous) {
878 query.append(WHERE_GREATER_THAN_HAS_NEXT);
879 }
880 else {
881 query.append(WHERE_LESSER_THAN_HAS_NEXT);
882 }
883 }
884 else {
885 if (orderByComparator.isAscending() ^ previous) {
886 query.append(WHERE_GREATER_THAN);
887 }
888 else {
889 query.append(WHERE_LESSER_THAN);
890 }
891 }
892 }
893
894 query.append(ORDER_BY_CLAUSE);
895
896 String[] orderByFields = orderByComparator.getOrderByFields();
897
898 for (int i = 0; i < orderByFields.length; i++) {
899 query.append(_ORDER_BY_ENTITY_ALIAS);
900 query.append(orderByFields[i]);
901
902 if ((i + 1) < orderByFields.length) {
903 if (orderByComparator.isAscending() ^ previous) {
904 query.append(ORDER_BY_ASC_HAS_NEXT);
905 }
906 else {
907 query.append(ORDER_BY_DESC_HAS_NEXT);
908 }
909 }
910 else {
911 if (orderByComparator.isAscending() ^ previous) {
912 query.append(ORDER_BY_ASC);
913 }
914 else {
915 query.append(ORDER_BY_DESC);
916 }
917 }
918 }
919 }
920
921 String sql = query.toString();
922
923 Query q = session.createQuery(sql);
924
925 q.setFirstResult(0);
926 q.setMaxResults(2);
927
928 QueryPos qPos = QueryPos.getInstance(q);
929
930 qPos.add(classNameId);
931
932 qPos.add(classPK);
933
934 if (orderByComparator != null) {
935 Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
936
937 for (Object value : values) {
938 qPos.add(value);
939 }
940 }
941
942 List<RatingsEntry> list = q.list();
943
944 if (list.size() == 2) {
945 return list.get(1);
946 }
947 else {
948 return null;
949 }
950 }
951
952
962 public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
963 throws NoSuchEntryException, SystemException {
964 RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
965
966 if (ratingsEntry == null) {
967 StringBundler msg = new StringBundler(8);
968
969 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
970
971 msg.append("userId=");
972 msg.append(userId);
973
974 msg.append(", classNameId=");
975 msg.append(classNameId);
976
977 msg.append(", classPK=");
978 msg.append(classPK);
979
980 msg.append(StringPool.CLOSE_CURLY_BRACE);
981
982 if (_log.isWarnEnabled()) {
983 _log.warn(msg.toString());
984 }
985
986 throw new NoSuchEntryException(msg.toString());
987 }
988
989 return ratingsEntry;
990 }
991
992
1001 public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
1002 throws SystemException {
1003 return fetchByU_C_C(userId, classNameId, classPK, true);
1004 }
1005
1006
1016 public RatingsEntry fetchByU_C_C(long userId, long classNameId,
1017 long classPK, boolean retrieveFromCache) throws SystemException {
1018 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1019
1020 Object result = null;
1021
1022 if (retrieveFromCache) {
1023 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
1024 finderArgs, this);
1025 }
1026
1027 if (result instanceof RatingsEntry) {
1028 RatingsEntry ratingsEntry = (RatingsEntry)result;
1029
1030 if ((userId != ratingsEntry.getUserId()) ||
1031 (classNameId != ratingsEntry.getClassNameId()) ||
1032 (classPK != ratingsEntry.getClassPK())) {
1033 result = null;
1034 }
1035 }
1036
1037 if (result == null) {
1038 StringBundler query = new StringBundler(4);
1039
1040 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1041
1042 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1043
1044 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1045
1046 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1047
1048 String sql = query.toString();
1049
1050 Session session = null;
1051
1052 try {
1053 session = openSession();
1054
1055 Query q = session.createQuery(sql);
1056
1057 QueryPos qPos = QueryPos.getInstance(q);
1058
1059 qPos.add(userId);
1060
1061 qPos.add(classNameId);
1062
1063 qPos.add(classPK);
1064
1065 List<RatingsEntry> list = q.list();
1066
1067 result = list;
1068
1069 RatingsEntry ratingsEntry = null;
1070
1071 if (list.isEmpty()) {
1072 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1073 finderArgs, list);
1074 }
1075 else {
1076 ratingsEntry = list.get(0);
1077
1078 cacheResult(ratingsEntry);
1079
1080 if ((ratingsEntry.getUserId() != userId) ||
1081 (ratingsEntry.getClassNameId() != classNameId) ||
1082 (ratingsEntry.getClassPK() != classPK)) {
1083 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1084 finderArgs, ratingsEntry);
1085 }
1086 }
1087
1088 return ratingsEntry;
1089 }
1090 catch (Exception e) {
1091 throw processException(e);
1092 }
1093 finally {
1094 if (result == null) {
1095 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
1096 finderArgs);
1097 }
1098
1099 closeSession(session);
1100 }
1101 }
1102 else {
1103 if (result instanceof List<?>) {
1104 return null;
1105 }
1106 else {
1107 return (RatingsEntry)result;
1108 }
1109 }
1110 }
1111
1112
1121 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1122 double score) throws SystemException {
1123 return findByC_C_S(classNameId, classPK, score, QueryUtil.ALL_POS,
1124 QueryUtil.ALL_POS, null);
1125 }
1126
1127
1142 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1143 double score, int start, int end) throws SystemException {
1144 return findByC_C_S(classNameId, classPK, score, start, end, null);
1145 }
1146
1147
1163 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1164 double score, int start, int end, OrderByComparator orderByComparator)
1165 throws SystemException {
1166 FinderPath finderPath = null;
1167 Object[] finderArgs = null;
1168
1169 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1170 (orderByComparator == null)) {
1171 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
1172 finderArgs = new Object[] { classNameId, classPK, score };
1173 }
1174 else {
1175 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
1176 finderArgs = new Object[] {
1177 classNameId, classPK, score,
1178
1179 start, end, orderByComparator
1180 };
1181 }
1182
1183 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1184 finderArgs, this);
1185
1186 if ((list != null) && !list.isEmpty()) {
1187 for (RatingsEntry ratingsEntry : list) {
1188 if ((classNameId != ratingsEntry.getClassNameId()) ||
1189 (classPK != ratingsEntry.getClassPK()) ||
1190 (score != ratingsEntry.getScore())) {
1191 list = null;
1192
1193 break;
1194 }
1195 }
1196 }
1197
1198 if (list == null) {
1199 StringBundler query = null;
1200
1201 if (orderByComparator != null) {
1202 query = new StringBundler(5 +
1203 (orderByComparator.getOrderByFields().length * 3));
1204 }
1205 else {
1206 query = new StringBundler(4);
1207 }
1208
1209 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1210
1211 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1212
1213 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1214
1215 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1216
1217 if (orderByComparator != null) {
1218 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1219 orderByComparator);
1220 }
1221
1222 String sql = query.toString();
1223
1224 Session session = null;
1225
1226 try {
1227 session = openSession();
1228
1229 Query q = session.createQuery(sql);
1230
1231 QueryPos qPos = QueryPos.getInstance(q);
1232
1233 qPos.add(classNameId);
1234
1235 qPos.add(classPK);
1236
1237 qPos.add(score);
1238
1239 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1240 start, end);
1241 }
1242 catch (Exception e) {
1243 throw processException(e);
1244 }
1245 finally {
1246 if (list == null) {
1247 FinderCacheUtil.removeResult(finderPath, finderArgs);
1248 }
1249 else {
1250 cacheResult(list);
1251
1252 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1253 }
1254
1255 closeSession(session);
1256 }
1257 }
1258
1259 return list;
1260 }
1261
1262
1277 public RatingsEntry findByC_C_S_First(long classNameId, long classPK,
1278 double score, OrderByComparator orderByComparator)
1279 throws NoSuchEntryException, SystemException {
1280 List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score, 0,
1281 1, orderByComparator);
1282
1283 if (list.isEmpty()) {
1284 StringBundler msg = new StringBundler(8);
1285
1286 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1287
1288 msg.append("classNameId=");
1289 msg.append(classNameId);
1290
1291 msg.append(", classPK=");
1292 msg.append(classPK);
1293
1294 msg.append(", score=");
1295 msg.append(score);
1296
1297 msg.append(StringPool.CLOSE_CURLY_BRACE);
1298
1299 throw new NoSuchEntryException(msg.toString());
1300 }
1301 else {
1302 return list.get(0);
1303 }
1304 }
1305
1306
1321 public RatingsEntry findByC_C_S_Last(long classNameId, long classPK,
1322 double score, OrderByComparator orderByComparator)
1323 throws NoSuchEntryException, SystemException {
1324 int count = countByC_C_S(classNameId, classPK, score);
1325
1326 List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score,
1327 count - 1, count, orderByComparator);
1328
1329 if (list.isEmpty()) {
1330 StringBundler msg = new StringBundler(8);
1331
1332 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1333
1334 msg.append("classNameId=");
1335 msg.append(classNameId);
1336
1337 msg.append(", classPK=");
1338 msg.append(classPK);
1339
1340 msg.append(", score=");
1341 msg.append(score);
1342
1343 msg.append(StringPool.CLOSE_CURLY_BRACE);
1344
1345 throw new NoSuchEntryException(msg.toString());
1346 }
1347 else {
1348 return list.get(0);
1349 }
1350 }
1351
1352
1368 public RatingsEntry[] findByC_C_S_PrevAndNext(long entryId,
1369 long classNameId, long classPK, double score,
1370 OrderByComparator orderByComparator)
1371 throws NoSuchEntryException, SystemException {
1372 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
1373
1374 Session session = null;
1375
1376 try {
1377 session = openSession();
1378
1379 RatingsEntry[] array = new RatingsEntryImpl[3];
1380
1381 array[0] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1382 classNameId, classPK, score, orderByComparator, true);
1383
1384 array[1] = ratingsEntry;
1385
1386 array[2] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1387 classNameId, classPK, score, orderByComparator, false);
1388
1389 return array;
1390 }
1391 catch (Exception e) {
1392 throw processException(e);
1393 }
1394 finally {
1395 closeSession(session);
1396 }
1397 }
1398
1399 protected RatingsEntry getByC_C_S_PrevAndNext(Session session,
1400 RatingsEntry ratingsEntry, long classNameId, long classPK,
1401 double score, OrderByComparator orderByComparator, boolean previous) {
1402 StringBundler query = null;
1403
1404 if (orderByComparator != null) {
1405 query = new StringBundler(6 +
1406 (orderByComparator.getOrderByFields().length * 6));
1407 }
1408 else {
1409 query = new StringBundler(3);
1410 }
1411
1412 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1413
1414 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1415
1416 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1417
1418 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1419
1420 if (orderByComparator != null) {
1421 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1422
1423 if (orderByConditionFields.length > 0) {
1424 query.append(WHERE_AND);
1425 }
1426
1427 for (int i = 0; i < orderByConditionFields.length; i++) {
1428 query.append(_ORDER_BY_ENTITY_ALIAS);
1429 query.append(orderByConditionFields[i]);
1430
1431 if ((i + 1) < orderByConditionFields.length) {
1432 if (orderByComparator.isAscending() ^ previous) {
1433 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1434 }
1435 else {
1436 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1437 }
1438 }
1439 else {
1440 if (orderByComparator.isAscending() ^ previous) {
1441 query.append(WHERE_GREATER_THAN);
1442 }
1443 else {
1444 query.append(WHERE_LESSER_THAN);
1445 }
1446 }
1447 }
1448
1449 query.append(ORDER_BY_CLAUSE);
1450
1451 String[] orderByFields = orderByComparator.getOrderByFields();
1452
1453 for (int i = 0; i < orderByFields.length; i++) {
1454 query.append(_ORDER_BY_ENTITY_ALIAS);
1455 query.append(orderByFields[i]);
1456
1457 if ((i + 1) < orderByFields.length) {
1458 if (orderByComparator.isAscending() ^ previous) {
1459 query.append(ORDER_BY_ASC_HAS_NEXT);
1460 }
1461 else {
1462 query.append(ORDER_BY_DESC_HAS_NEXT);
1463 }
1464 }
1465 else {
1466 if (orderByComparator.isAscending() ^ previous) {
1467 query.append(ORDER_BY_ASC);
1468 }
1469 else {
1470 query.append(ORDER_BY_DESC);
1471 }
1472 }
1473 }
1474 }
1475
1476 String sql = query.toString();
1477
1478 Query q = session.createQuery(sql);
1479
1480 q.setFirstResult(0);
1481 q.setMaxResults(2);
1482
1483 QueryPos qPos = QueryPos.getInstance(q);
1484
1485 qPos.add(classNameId);
1486
1487 qPos.add(classPK);
1488
1489 qPos.add(score);
1490
1491 if (orderByComparator != null) {
1492 Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
1493
1494 for (Object value : values) {
1495 qPos.add(value);
1496 }
1497 }
1498
1499 List<RatingsEntry> list = q.list();
1500
1501 if (list.size() == 2) {
1502 return list.get(1);
1503 }
1504 else {
1505 return null;
1506 }
1507 }
1508
1509
1515 public List<RatingsEntry> findAll() throws SystemException {
1516 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1517 }
1518
1519
1531 public List<RatingsEntry> findAll(int start, int end)
1532 throws SystemException {
1533 return findAll(start, end, null);
1534 }
1535
1536
1549 public List<RatingsEntry> findAll(int start, int end,
1550 OrderByComparator orderByComparator) throws SystemException {
1551 FinderPath finderPath = null;
1552 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1553
1554 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1555 (orderByComparator == null)) {
1556 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1557 finderArgs = FINDER_ARGS_EMPTY;
1558 }
1559 else {
1560 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1561 finderArgs = new Object[] { start, end, orderByComparator };
1562 }
1563
1564 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1565 finderArgs, this);
1566
1567 if (list == null) {
1568 StringBundler query = null;
1569 String sql = null;
1570
1571 if (orderByComparator != null) {
1572 query = new StringBundler(2 +
1573 (orderByComparator.getOrderByFields().length * 3));
1574
1575 query.append(_SQL_SELECT_RATINGSENTRY);
1576
1577 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1578 orderByComparator);
1579
1580 sql = query.toString();
1581 }
1582 else {
1583 sql = _SQL_SELECT_RATINGSENTRY;
1584 }
1585
1586 Session session = null;
1587
1588 try {
1589 session = openSession();
1590
1591 Query q = session.createQuery(sql);
1592
1593 if (orderByComparator == null) {
1594 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1595 start, end, false);
1596
1597 Collections.sort(list);
1598 }
1599 else {
1600 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1601 start, end);
1602 }
1603 }
1604 catch (Exception e) {
1605 throw processException(e);
1606 }
1607 finally {
1608 if (list == null) {
1609 FinderCacheUtil.removeResult(finderPath, finderArgs);
1610 }
1611 else {
1612 cacheResult(list);
1613
1614 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1615 }
1616
1617 closeSession(session);
1618 }
1619 }
1620
1621 return list;
1622 }
1623
1624
1631 public void removeByC_C(long classNameId, long classPK)
1632 throws SystemException {
1633 for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
1634 remove(ratingsEntry);
1635 }
1636 }
1637
1638
1646 public void removeByU_C_C(long userId, long classNameId, long classPK)
1647 throws NoSuchEntryException, SystemException {
1648 RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
1649
1650 remove(ratingsEntry);
1651 }
1652
1653
1661 public void removeByC_C_S(long classNameId, long classPK, double score)
1662 throws SystemException {
1663 for (RatingsEntry ratingsEntry : findByC_C_S(classNameId, classPK, score)) {
1664 remove(ratingsEntry);
1665 }
1666 }
1667
1668
1673 public void removeAll() throws SystemException {
1674 for (RatingsEntry ratingsEntry : findAll()) {
1675 remove(ratingsEntry);
1676 }
1677 }
1678
1679
1687 public int countByC_C(long classNameId, long classPK)
1688 throws SystemException {
1689 Object[] finderArgs = new Object[] { classNameId, classPK };
1690
1691 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1692 finderArgs, this);
1693
1694 if (count == null) {
1695 StringBundler query = new StringBundler(3);
1696
1697 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1698
1699 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1700
1701 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1702
1703 String sql = query.toString();
1704
1705 Session session = null;
1706
1707 try {
1708 session = openSession();
1709
1710 Query q = session.createQuery(sql);
1711
1712 QueryPos qPos = QueryPos.getInstance(q);
1713
1714 qPos.add(classNameId);
1715
1716 qPos.add(classPK);
1717
1718 count = (Long)q.uniqueResult();
1719 }
1720 catch (Exception e) {
1721 throw processException(e);
1722 }
1723 finally {
1724 if (count == null) {
1725 count = Long.valueOf(0);
1726 }
1727
1728 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1729 count);
1730
1731 closeSession(session);
1732 }
1733 }
1734
1735 return count.intValue();
1736 }
1737
1738
1747 public int countByU_C_C(long userId, long classNameId, long classPK)
1748 throws SystemException {
1749 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1750
1751 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
1752 finderArgs, this);
1753
1754 if (count == null) {
1755 StringBundler query = new StringBundler(4);
1756
1757 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1758
1759 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1760
1761 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1762
1763 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1764
1765 String sql = query.toString();
1766
1767 Session session = null;
1768
1769 try {
1770 session = openSession();
1771
1772 Query q = session.createQuery(sql);
1773
1774 QueryPos qPos = QueryPos.getInstance(q);
1775
1776 qPos.add(userId);
1777
1778 qPos.add(classNameId);
1779
1780 qPos.add(classPK);
1781
1782 count = (Long)q.uniqueResult();
1783 }
1784 catch (Exception e) {
1785 throw processException(e);
1786 }
1787 finally {
1788 if (count == null) {
1789 count = Long.valueOf(0);
1790 }
1791
1792 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
1793 finderArgs, count);
1794
1795 closeSession(session);
1796 }
1797 }
1798
1799 return count.intValue();
1800 }
1801
1802
1811 public int countByC_C_S(long classNameId, long classPK, double score)
1812 throws SystemException {
1813 Object[] finderArgs = new Object[] { classNameId, classPK, score };
1814
1815 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
1816 finderArgs, this);
1817
1818 if (count == null) {
1819 StringBundler query = new StringBundler(4);
1820
1821 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1822
1823 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1824
1825 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1826
1827 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1828
1829 String sql = query.toString();
1830
1831 Session session = null;
1832
1833 try {
1834 session = openSession();
1835
1836 Query q = session.createQuery(sql);
1837
1838 QueryPos qPos = QueryPos.getInstance(q);
1839
1840 qPos.add(classNameId);
1841
1842 qPos.add(classPK);
1843
1844 qPos.add(score);
1845
1846 count = (Long)q.uniqueResult();
1847 }
1848 catch (Exception e) {
1849 throw processException(e);
1850 }
1851 finally {
1852 if (count == null) {
1853 count = Long.valueOf(0);
1854 }
1855
1856 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
1857 finderArgs, count);
1858
1859 closeSession(session);
1860 }
1861 }
1862
1863 return count.intValue();
1864 }
1865
1866
1872 public int countAll() throws SystemException {
1873 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1874 FINDER_ARGS_EMPTY, this);
1875
1876 if (count == null) {
1877 Session session = null;
1878
1879 try {
1880 session = openSession();
1881
1882 Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
1883
1884 count = (Long)q.uniqueResult();
1885 }
1886 catch (Exception e) {
1887 throw processException(e);
1888 }
1889 finally {
1890 if (count == null) {
1891 count = Long.valueOf(0);
1892 }
1893
1894 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1895 FINDER_ARGS_EMPTY, count);
1896
1897 closeSession(session);
1898 }
1899 }
1900
1901 return count.intValue();
1902 }
1903
1904
1907 public void afterPropertiesSet() {
1908 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1909 com.liferay.portal.util.PropsUtil.get(
1910 "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1911
1912 if (listenerClassNames.length > 0) {
1913 try {
1914 List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1915
1916 for (String listenerClassName : listenerClassNames) {
1917 listenersList.add((ModelListener<RatingsEntry>)InstanceFactory.newInstance(
1918 listenerClassName));
1919 }
1920
1921 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1922 }
1923 catch (Exception e) {
1924 _log.error(e);
1925 }
1926 }
1927 }
1928
1929 public void destroy() {
1930 EntityCacheUtil.removeCache(RatingsEntryImpl.class.getName());
1931 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1932 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1933 }
1934
1935 @BeanReference(type = RatingsEntryPersistence.class)
1936 protected RatingsEntryPersistence ratingsEntryPersistence;
1937 @BeanReference(type = RatingsStatsPersistence.class)
1938 protected RatingsStatsPersistence ratingsStatsPersistence;
1939 @BeanReference(type = ResourcePersistence.class)
1940 protected ResourcePersistence resourcePersistence;
1941 @BeanReference(type = UserPersistence.class)
1942 protected UserPersistence userPersistence;
1943 @BeanReference(type = AssetEntryPersistence.class)
1944 protected AssetEntryPersistence assetEntryPersistence;
1945 @BeanReference(type = BlogsEntryPersistence.class)
1946 protected BlogsEntryPersistence blogsEntryPersistence;
1947 @BeanReference(type = BlogsStatsUserPersistence.class)
1948 protected BlogsStatsUserPersistence blogsStatsUserPersistence;
1949 @BeanReference(type = SocialActivityPersistence.class)
1950 protected SocialActivityPersistence socialActivityPersistence;
1951 private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
1952 private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
1953 private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
1954 private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
1955 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1956 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1957 private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1958 private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1959 private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1960 private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1961 private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "ratingsEntry.classPK = ? AND ";
1962 private static final String _FINDER_COLUMN_C_C_S_SCORE_2 = "ratingsEntry.score = ?";
1963 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
1964 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
1965 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
1966 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1967 private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1968 private static RatingsEntry _nullRatingsEntry = new RatingsEntryImpl() {
1969 @Override
1970 public Object clone() {
1971 return this;
1972 }
1973
1974 @Override
1975 public CacheModel<RatingsEntry> toCacheModel() {
1976 return _nullRatingsEntryCacheModel;
1977 }
1978 };
1979
1980 private static CacheModel<RatingsEntry> _nullRatingsEntryCacheModel = new CacheModel<RatingsEntry>() {
1981 public RatingsEntry toEntityModel() {
1982 return _nullRatingsEntry;
1983 }
1984 };
1985 }