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_WITHOUT_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_WITH_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 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
226 new Object[] {
227 Long.valueOf(ratingsEntry.getUserId()),
228 Long.valueOf(ratingsEntry.getClassNameId()),
229 Long.valueOf(ratingsEntry.getClassPK())
230 });
231 }
232
233
239 public RatingsEntry create(long entryId) {
240 RatingsEntry ratingsEntry = new RatingsEntryImpl();
241
242 ratingsEntry.setNew(true);
243 ratingsEntry.setPrimaryKey(entryId);
244
245 return ratingsEntry;
246 }
247
248
256 @Override
257 public RatingsEntry remove(Serializable primaryKey)
258 throws NoSuchModelException, SystemException {
259 return remove(((Long)primaryKey).longValue());
260 }
261
262
270 public RatingsEntry remove(long entryId)
271 throws NoSuchEntryException, SystemException {
272 Session session = null;
273
274 try {
275 session = openSession();
276
277 RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
278 Long.valueOf(entryId));
279
280 if (ratingsEntry == null) {
281 if (_log.isWarnEnabled()) {
282 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
283 }
284
285 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
286 entryId);
287 }
288
289 return ratingsEntryPersistence.remove(ratingsEntry);
290 }
291 catch (NoSuchEntryException nsee) {
292 throw nsee;
293 }
294 catch (Exception e) {
295 throw processException(e);
296 }
297 finally {
298 closeSession(session);
299 }
300 }
301
302
309 @Override
310 public RatingsEntry remove(RatingsEntry ratingsEntry)
311 throws SystemException {
312 return super.remove(ratingsEntry);
313 }
314
315 @Override
316 protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
317 throws SystemException {
318 ratingsEntry = toUnwrappedModel(ratingsEntry);
319
320 Session session = null;
321
322 try {
323 session = openSession();
324
325 BatchSessionUtil.delete(session, ratingsEntry);
326 }
327 catch (Exception e) {
328 throw processException(e);
329 }
330 finally {
331 closeSession(session);
332 }
333
334 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
335 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
336
337 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
338
339 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
340 new Object[] {
341 Long.valueOf(ratingsEntryModelImpl.getUserId()),
342 Long.valueOf(ratingsEntryModelImpl.getClassNameId()),
343 Long.valueOf(ratingsEntryModelImpl.getClassPK())
344 });
345
346 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
347 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
348
349 return ratingsEntry;
350 }
351
352 @Override
353 public RatingsEntry updateImpl(
354 com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
355 boolean merge) throws SystemException {
356 ratingsEntry = toUnwrappedModel(ratingsEntry);
357
358 boolean isNew = ratingsEntry.isNew();
359
360 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
361
362 Session session = null;
363
364 try {
365 session = openSession();
366
367 BatchSessionUtil.update(session, ratingsEntry, merge);
368
369 ratingsEntry.setNew(false);
370 }
371 catch (Exception e) {
372 throw processException(e);
373 }
374 finally {
375 closeSession(session);
376 }
377
378 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
379
380 if (isNew || !RatingsEntryModelImpl.COLUMN_BITMASK_ENABLED) {
381 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
382 }
383
384 else {
385 if ((ratingsEntryModelImpl.getColumnBitmask() &
386 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
387 Object[] args = new Object[] {
388 Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
389 Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK())
390 };
391
392 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
393 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
394 args);
395
396 args = new Object[] {
397 Long.valueOf(ratingsEntryModelImpl.getClassNameId()),
398 Long.valueOf(ratingsEntryModelImpl.getClassPK())
399 };
400
401 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
402 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
403 args);
404 }
405
406 if ((ratingsEntryModelImpl.getColumnBitmask() &
407 FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
408 Object[] args = new Object[] {
409 Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
410 Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK()),
411 Double.valueOf(ratingsEntryModelImpl.getOriginalScore())
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 args = new Object[] {
419 Long.valueOf(ratingsEntryModelImpl.getClassNameId()),
420 Long.valueOf(ratingsEntryModelImpl.getClassPK()),
421 Double.valueOf(ratingsEntryModelImpl.getScore())
422 };
423
424 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
425 FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
426 args);
427 }
428 }
429
430 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
431 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
432
433 if (isNew) {
434 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
435 new Object[] {
436 Long.valueOf(ratingsEntry.getUserId()),
437 Long.valueOf(ratingsEntry.getClassNameId()),
438 Long.valueOf(ratingsEntry.getClassPK())
439 }, ratingsEntry);
440 }
441 else {
442 if ((ratingsEntryModelImpl.getColumnBitmask() &
443 FINDER_PATH_FETCH_BY_U_C_C.getColumnBitmask()) != 0) {
444 Object[] args = new Object[] {
445 Long.valueOf(ratingsEntryModelImpl.getOriginalUserId()),
446 Long.valueOf(ratingsEntryModelImpl.getOriginalClassNameId()),
447 Long.valueOf(ratingsEntryModelImpl.getOriginalClassPK())
448 };
449
450 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
451 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C, args);
452
453 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
454 new Object[] {
455 Long.valueOf(ratingsEntry.getUserId()),
456 Long.valueOf(ratingsEntry.getClassNameId()),
457 Long.valueOf(ratingsEntry.getClassPK())
458 }, ratingsEntry);
459 }
460 }
461
462 return ratingsEntry;
463 }
464
465 protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
466 if (ratingsEntry instanceof RatingsEntryImpl) {
467 return ratingsEntry;
468 }
469
470 RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
471
472 ratingsEntryImpl.setNew(ratingsEntry.isNew());
473 ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
474
475 ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
476 ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
477 ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
478 ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
479 ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
480 ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
481 ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
482 ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
483 ratingsEntryImpl.setScore(ratingsEntry.getScore());
484
485 return ratingsEntryImpl;
486 }
487
488
496 @Override
497 public RatingsEntry findByPrimaryKey(Serializable primaryKey)
498 throws NoSuchModelException, SystemException {
499 return findByPrimaryKey(((Long)primaryKey).longValue());
500 }
501
502
510 public RatingsEntry findByPrimaryKey(long entryId)
511 throws NoSuchEntryException, SystemException {
512 RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
513
514 if (ratingsEntry == null) {
515 if (_log.isWarnEnabled()) {
516 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
517 }
518
519 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
520 entryId);
521 }
522
523 return ratingsEntry;
524 }
525
526
533 @Override
534 public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
535 throws SystemException {
536 return fetchByPrimaryKey(((Long)primaryKey).longValue());
537 }
538
539
546 public RatingsEntry fetchByPrimaryKey(long entryId)
547 throws SystemException {
548 RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
549 RatingsEntryImpl.class, entryId);
550
551 if (ratingsEntry == _nullRatingsEntry) {
552 return null;
553 }
554
555 if (ratingsEntry == null) {
556 Session session = null;
557
558 boolean hasException = false;
559
560 try {
561 session = openSession();
562
563 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
564 Long.valueOf(entryId));
565 }
566 catch (Exception e) {
567 hasException = true;
568
569 throw processException(e);
570 }
571 finally {
572 if (ratingsEntry != null) {
573 cacheResult(ratingsEntry);
574 }
575 else if (!hasException) {
576 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
577 RatingsEntryImpl.class, entryId, _nullRatingsEntry);
578 }
579
580 closeSession(session);
581 }
582 }
583
584 return ratingsEntry;
585 }
586
587
595 public List<RatingsEntry> findByC_C(long classNameId, long classPK)
596 throws SystemException {
597 return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
598 QueryUtil.ALL_POS, null);
599 }
600
601
615 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
616 int start, int end) throws SystemException {
617 return findByC_C(classNameId, classPK, start, end, null);
618 }
619
620
635 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
636 int start, int end, OrderByComparator orderByComparator)
637 throws SystemException {
638 FinderPath finderPath = null;
639 Object[] finderArgs = null;
640
641 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
642 (orderByComparator == null)) {
643 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
644 finderArgs = new Object[] { classNameId, classPK };
645 }
646 else {
647 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
648 finderArgs = new Object[] {
649 classNameId, classPK,
650
651 start, end, orderByComparator
652 };
653 }
654
655 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
656 finderArgs, this);
657
658 if (list == null) {
659 StringBundler query = null;
660
661 if (orderByComparator != null) {
662 query = new StringBundler(4 +
663 (orderByComparator.getOrderByFields().length * 3));
664 }
665 else {
666 query = new StringBundler(3);
667 }
668
669 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
670
671 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
672
673 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
674
675 if (orderByComparator != null) {
676 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
677 orderByComparator);
678 }
679
680 String sql = query.toString();
681
682 Session session = null;
683
684 try {
685 session = openSession();
686
687 Query q = session.createQuery(sql);
688
689 QueryPos qPos = QueryPos.getInstance(q);
690
691 qPos.add(classNameId);
692
693 qPos.add(classPK);
694
695 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
696 start, end);
697 }
698 catch (Exception e) {
699 throw processException(e);
700 }
701 finally {
702 if (list == null) {
703 FinderCacheUtil.removeResult(finderPath, finderArgs);
704 }
705 else {
706 cacheResult(list);
707
708 FinderCacheUtil.putResult(finderPath, finderArgs, list);
709 }
710
711 closeSession(session);
712 }
713 }
714
715 return list;
716 }
717
718
732 public RatingsEntry findByC_C_First(long classNameId, long classPK,
733 OrderByComparator orderByComparator)
734 throws NoSuchEntryException, SystemException {
735 List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
736 orderByComparator);
737
738 if (list.isEmpty()) {
739 StringBundler msg = new StringBundler(6);
740
741 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
742
743 msg.append("classNameId=");
744 msg.append(classNameId);
745
746 msg.append(", classPK=");
747 msg.append(classPK);
748
749 msg.append(StringPool.CLOSE_CURLY_BRACE);
750
751 throw new NoSuchEntryException(msg.toString());
752 }
753 else {
754 return list.get(0);
755 }
756 }
757
758
772 public RatingsEntry findByC_C_Last(long classNameId, long classPK,
773 OrderByComparator orderByComparator)
774 throws NoSuchEntryException, SystemException {
775 int count = countByC_C(classNameId, classPK);
776
777 List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
778 count, orderByComparator);
779
780 if (list.isEmpty()) {
781 StringBundler msg = new StringBundler(6);
782
783 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
784
785 msg.append("classNameId=");
786 msg.append(classNameId);
787
788 msg.append(", classPK=");
789 msg.append(classPK);
790
791 msg.append(StringPool.CLOSE_CURLY_BRACE);
792
793 throw new NoSuchEntryException(msg.toString());
794 }
795 else {
796 return list.get(0);
797 }
798 }
799
800
815 public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
816 long classPK, OrderByComparator orderByComparator)
817 throws NoSuchEntryException, SystemException {
818 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
819
820 Session session = null;
821
822 try {
823 session = openSession();
824
825 RatingsEntry[] array = new RatingsEntryImpl[3];
826
827 array[0] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
828 classPK, orderByComparator, true);
829
830 array[1] = ratingsEntry;
831
832 array[2] = getByC_C_PrevAndNext(session, ratingsEntry, classNameId,
833 classPK, orderByComparator, false);
834
835 return array;
836 }
837 catch (Exception e) {
838 throw processException(e);
839 }
840 finally {
841 closeSession(session);
842 }
843 }
844
845 protected RatingsEntry getByC_C_PrevAndNext(Session session,
846 RatingsEntry ratingsEntry, long classNameId, long classPK,
847 OrderByComparator orderByComparator, boolean previous) {
848 StringBundler query = null;
849
850 if (orderByComparator != null) {
851 query = new StringBundler(6 +
852 (orderByComparator.getOrderByFields().length * 6));
853 }
854 else {
855 query = new StringBundler(3);
856 }
857
858 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
859
860 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
861
862 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
863
864 if (orderByComparator != null) {
865 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
866
867 if (orderByConditionFields.length > 0) {
868 query.append(WHERE_AND);
869 }
870
871 for (int i = 0; i < orderByConditionFields.length; i++) {
872 query.append(_ORDER_BY_ENTITY_ALIAS);
873 query.append(orderByConditionFields[i]);
874
875 if ((i + 1) < orderByConditionFields.length) {
876 if (orderByComparator.isAscending() ^ previous) {
877 query.append(WHERE_GREATER_THAN_HAS_NEXT);
878 }
879 else {
880 query.append(WHERE_LESSER_THAN_HAS_NEXT);
881 }
882 }
883 else {
884 if (orderByComparator.isAscending() ^ previous) {
885 query.append(WHERE_GREATER_THAN);
886 }
887 else {
888 query.append(WHERE_LESSER_THAN);
889 }
890 }
891 }
892
893 query.append(ORDER_BY_CLAUSE);
894
895 String[] orderByFields = orderByComparator.getOrderByFields();
896
897 for (int i = 0; i < orderByFields.length; i++) {
898 query.append(_ORDER_BY_ENTITY_ALIAS);
899 query.append(orderByFields[i]);
900
901 if ((i + 1) < orderByFields.length) {
902 if (orderByComparator.isAscending() ^ previous) {
903 query.append(ORDER_BY_ASC_HAS_NEXT);
904 }
905 else {
906 query.append(ORDER_BY_DESC_HAS_NEXT);
907 }
908 }
909 else {
910 if (orderByComparator.isAscending() ^ previous) {
911 query.append(ORDER_BY_ASC);
912 }
913 else {
914 query.append(ORDER_BY_DESC);
915 }
916 }
917 }
918 }
919
920 String sql = query.toString();
921
922 Query q = session.createQuery(sql);
923
924 q.setFirstResult(0);
925 q.setMaxResults(2);
926
927 QueryPos qPos = QueryPos.getInstance(q);
928
929 qPos.add(classNameId);
930
931 qPos.add(classPK);
932
933 if (orderByComparator != null) {
934 Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
935
936 for (Object value : values) {
937 qPos.add(value);
938 }
939 }
940
941 List<RatingsEntry> list = q.list();
942
943 if (list.size() == 2) {
944 return list.get(1);
945 }
946 else {
947 return null;
948 }
949 }
950
951
961 public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
962 throws NoSuchEntryException, SystemException {
963 RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
964
965 if (ratingsEntry == null) {
966 StringBundler msg = new StringBundler(8);
967
968 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
969
970 msg.append("userId=");
971 msg.append(userId);
972
973 msg.append(", classNameId=");
974 msg.append(classNameId);
975
976 msg.append(", classPK=");
977 msg.append(classPK);
978
979 msg.append(StringPool.CLOSE_CURLY_BRACE);
980
981 if (_log.isWarnEnabled()) {
982 _log.warn(msg.toString());
983 }
984
985 throw new NoSuchEntryException(msg.toString());
986 }
987
988 return ratingsEntry;
989 }
990
991
1000 public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
1001 throws SystemException {
1002 return fetchByU_C_C(userId, classNameId, classPK, true);
1003 }
1004
1005
1015 public RatingsEntry fetchByU_C_C(long userId, long classNameId,
1016 long classPK, boolean retrieveFromCache) throws SystemException {
1017 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1018
1019 Object result = null;
1020
1021 if (retrieveFromCache) {
1022 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
1023 finderArgs, this);
1024 }
1025
1026 if (result == null) {
1027 StringBundler query = new StringBundler(4);
1028
1029 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1030
1031 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1032
1033 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1034
1035 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1036
1037 String sql = query.toString();
1038
1039 Session session = null;
1040
1041 try {
1042 session = openSession();
1043
1044 Query q = session.createQuery(sql);
1045
1046 QueryPos qPos = QueryPos.getInstance(q);
1047
1048 qPos.add(userId);
1049
1050 qPos.add(classNameId);
1051
1052 qPos.add(classPK);
1053
1054 List<RatingsEntry> list = q.list();
1055
1056 result = list;
1057
1058 RatingsEntry ratingsEntry = null;
1059
1060 if (list.isEmpty()) {
1061 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1062 finderArgs, list);
1063 }
1064 else {
1065 ratingsEntry = list.get(0);
1066
1067 cacheResult(ratingsEntry);
1068
1069 if ((ratingsEntry.getUserId() != userId) ||
1070 (ratingsEntry.getClassNameId() != classNameId) ||
1071 (ratingsEntry.getClassPK() != classPK)) {
1072 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
1073 finderArgs, ratingsEntry);
1074 }
1075 }
1076
1077 return ratingsEntry;
1078 }
1079 catch (Exception e) {
1080 throw processException(e);
1081 }
1082 finally {
1083 if (result == null) {
1084 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
1085 finderArgs);
1086 }
1087
1088 closeSession(session);
1089 }
1090 }
1091 else {
1092 if (result instanceof List<?>) {
1093 return null;
1094 }
1095 else {
1096 return (RatingsEntry)result;
1097 }
1098 }
1099 }
1100
1101
1110 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1111 double score) throws SystemException {
1112 return findByC_C_S(classNameId, classPK, score, QueryUtil.ALL_POS,
1113 QueryUtil.ALL_POS, null);
1114 }
1115
1116
1131 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1132 double score, int start, int end) throws SystemException {
1133 return findByC_C_S(classNameId, classPK, score, start, end, null);
1134 }
1135
1136
1152 public List<RatingsEntry> findByC_C_S(long classNameId, long classPK,
1153 double score, int start, int end, OrderByComparator orderByComparator)
1154 throws SystemException {
1155 FinderPath finderPath = null;
1156 Object[] finderArgs = null;
1157
1158 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1159 (orderByComparator == null)) {
1160 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
1161 finderArgs = new Object[] { classNameId, classPK, score };
1162 }
1163 else {
1164 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
1165 finderArgs = new Object[] {
1166 classNameId, classPK, score,
1167
1168 start, end, orderByComparator
1169 };
1170 }
1171
1172 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1173 finderArgs, this);
1174
1175 if (list == null) {
1176 StringBundler query = null;
1177
1178 if (orderByComparator != null) {
1179 query = new StringBundler(5 +
1180 (orderByComparator.getOrderByFields().length * 3));
1181 }
1182 else {
1183 query = new StringBundler(4);
1184 }
1185
1186 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1187
1188 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1189
1190 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1191
1192 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1193
1194 if (orderByComparator != null) {
1195 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1196 orderByComparator);
1197 }
1198
1199 String sql = query.toString();
1200
1201 Session session = null;
1202
1203 try {
1204 session = openSession();
1205
1206 Query q = session.createQuery(sql);
1207
1208 QueryPos qPos = QueryPos.getInstance(q);
1209
1210 qPos.add(classNameId);
1211
1212 qPos.add(classPK);
1213
1214 qPos.add(score);
1215
1216 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1217 start, end);
1218 }
1219 catch (Exception e) {
1220 throw processException(e);
1221 }
1222 finally {
1223 if (list == null) {
1224 FinderCacheUtil.removeResult(finderPath, finderArgs);
1225 }
1226 else {
1227 cacheResult(list);
1228
1229 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1230 }
1231
1232 closeSession(session);
1233 }
1234 }
1235
1236 return list;
1237 }
1238
1239
1254 public RatingsEntry findByC_C_S_First(long classNameId, long classPK,
1255 double score, OrderByComparator orderByComparator)
1256 throws NoSuchEntryException, SystemException {
1257 List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score, 0,
1258 1, orderByComparator);
1259
1260 if (list.isEmpty()) {
1261 StringBundler msg = new StringBundler(8);
1262
1263 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1264
1265 msg.append("classNameId=");
1266 msg.append(classNameId);
1267
1268 msg.append(", classPK=");
1269 msg.append(classPK);
1270
1271 msg.append(", score=");
1272 msg.append(score);
1273
1274 msg.append(StringPool.CLOSE_CURLY_BRACE);
1275
1276 throw new NoSuchEntryException(msg.toString());
1277 }
1278 else {
1279 return list.get(0);
1280 }
1281 }
1282
1283
1298 public RatingsEntry findByC_C_S_Last(long classNameId, long classPK,
1299 double score, OrderByComparator orderByComparator)
1300 throws NoSuchEntryException, SystemException {
1301 int count = countByC_C_S(classNameId, classPK, score);
1302
1303 List<RatingsEntry> list = findByC_C_S(classNameId, classPK, score,
1304 count - 1, count, orderByComparator);
1305
1306 if (list.isEmpty()) {
1307 StringBundler msg = new StringBundler(8);
1308
1309 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1310
1311 msg.append("classNameId=");
1312 msg.append(classNameId);
1313
1314 msg.append(", classPK=");
1315 msg.append(classPK);
1316
1317 msg.append(", score=");
1318 msg.append(score);
1319
1320 msg.append(StringPool.CLOSE_CURLY_BRACE);
1321
1322 throw new NoSuchEntryException(msg.toString());
1323 }
1324 else {
1325 return list.get(0);
1326 }
1327 }
1328
1329
1345 public RatingsEntry[] findByC_C_S_PrevAndNext(long entryId,
1346 long classNameId, long classPK, double score,
1347 OrderByComparator orderByComparator)
1348 throws NoSuchEntryException, SystemException {
1349 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
1350
1351 Session session = null;
1352
1353 try {
1354 session = openSession();
1355
1356 RatingsEntry[] array = new RatingsEntryImpl[3];
1357
1358 array[0] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1359 classNameId, classPK, score, orderByComparator, true);
1360
1361 array[1] = ratingsEntry;
1362
1363 array[2] = getByC_C_S_PrevAndNext(session, ratingsEntry,
1364 classNameId, classPK, score, orderByComparator, false);
1365
1366 return array;
1367 }
1368 catch (Exception e) {
1369 throw processException(e);
1370 }
1371 finally {
1372 closeSession(session);
1373 }
1374 }
1375
1376 protected RatingsEntry getByC_C_S_PrevAndNext(Session session,
1377 RatingsEntry ratingsEntry, long classNameId, long classPK,
1378 double score, OrderByComparator orderByComparator, boolean previous) {
1379 StringBundler query = null;
1380
1381 if (orderByComparator != null) {
1382 query = new StringBundler(6 +
1383 (orderByComparator.getOrderByFields().length * 6));
1384 }
1385 else {
1386 query = new StringBundler(3);
1387 }
1388
1389 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
1390
1391 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1392
1393 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1394
1395 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1396
1397 if (orderByComparator != null) {
1398 String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1399
1400 if (orderByConditionFields.length > 0) {
1401 query.append(WHERE_AND);
1402 }
1403
1404 for (int i = 0; i < orderByConditionFields.length; i++) {
1405 query.append(_ORDER_BY_ENTITY_ALIAS);
1406 query.append(orderByConditionFields[i]);
1407
1408 if ((i + 1) < orderByConditionFields.length) {
1409 if (orderByComparator.isAscending() ^ previous) {
1410 query.append(WHERE_GREATER_THAN_HAS_NEXT);
1411 }
1412 else {
1413 query.append(WHERE_LESSER_THAN_HAS_NEXT);
1414 }
1415 }
1416 else {
1417 if (orderByComparator.isAscending() ^ previous) {
1418 query.append(WHERE_GREATER_THAN);
1419 }
1420 else {
1421 query.append(WHERE_LESSER_THAN);
1422 }
1423 }
1424 }
1425
1426 query.append(ORDER_BY_CLAUSE);
1427
1428 String[] orderByFields = orderByComparator.getOrderByFields();
1429
1430 for (int i = 0; i < orderByFields.length; i++) {
1431 query.append(_ORDER_BY_ENTITY_ALIAS);
1432 query.append(orderByFields[i]);
1433
1434 if ((i + 1) < orderByFields.length) {
1435 if (orderByComparator.isAscending() ^ previous) {
1436 query.append(ORDER_BY_ASC_HAS_NEXT);
1437 }
1438 else {
1439 query.append(ORDER_BY_DESC_HAS_NEXT);
1440 }
1441 }
1442 else {
1443 if (orderByComparator.isAscending() ^ previous) {
1444 query.append(ORDER_BY_ASC);
1445 }
1446 else {
1447 query.append(ORDER_BY_DESC);
1448 }
1449 }
1450 }
1451 }
1452
1453 String sql = query.toString();
1454
1455 Query q = session.createQuery(sql);
1456
1457 q.setFirstResult(0);
1458 q.setMaxResults(2);
1459
1460 QueryPos qPos = QueryPos.getInstance(q);
1461
1462 qPos.add(classNameId);
1463
1464 qPos.add(classPK);
1465
1466 qPos.add(score);
1467
1468 if (orderByComparator != null) {
1469 Object[] values = orderByComparator.getOrderByConditionValues(ratingsEntry);
1470
1471 for (Object value : values) {
1472 qPos.add(value);
1473 }
1474 }
1475
1476 List<RatingsEntry> list = q.list();
1477
1478 if (list.size() == 2) {
1479 return list.get(1);
1480 }
1481 else {
1482 return null;
1483 }
1484 }
1485
1486
1492 public List<RatingsEntry> findAll() throws SystemException {
1493 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1494 }
1495
1496
1508 public List<RatingsEntry> findAll(int start, int end)
1509 throws SystemException {
1510 return findAll(start, end, null);
1511 }
1512
1513
1526 public List<RatingsEntry> findAll(int start, int end,
1527 OrderByComparator orderByComparator) throws SystemException {
1528 FinderPath finderPath = null;
1529 Object[] finderArgs = new Object[] { start, end, orderByComparator };
1530
1531 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1532 (orderByComparator == null)) {
1533 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1534 finderArgs = FINDER_ARGS_EMPTY;
1535 }
1536 else {
1537 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1538 finderArgs = new Object[] { start, end, orderByComparator };
1539 }
1540
1541 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(finderPath,
1542 finderArgs, this);
1543
1544 if (list == null) {
1545 StringBundler query = null;
1546 String sql = null;
1547
1548 if (orderByComparator != null) {
1549 query = new StringBundler(2 +
1550 (orderByComparator.getOrderByFields().length * 3));
1551
1552 query.append(_SQL_SELECT_RATINGSENTRY);
1553
1554 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1555 orderByComparator);
1556
1557 sql = query.toString();
1558 }
1559 else {
1560 sql = _SQL_SELECT_RATINGSENTRY;
1561 }
1562
1563 Session session = null;
1564
1565 try {
1566 session = openSession();
1567
1568 Query q = session.createQuery(sql);
1569
1570 if (orderByComparator == null) {
1571 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1572 start, end, false);
1573
1574 Collections.sort(list);
1575 }
1576 else {
1577 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
1578 start, end);
1579 }
1580 }
1581 catch (Exception e) {
1582 throw processException(e);
1583 }
1584 finally {
1585 if (list == null) {
1586 FinderCacheUtil.removeResult(finderPath, finderArgs);
1587 }
1588 else {
1589 cacheResult(list);
1590
1591 FinderCacheUtil.putResult(finderPath, finderArgs, list);
1592 }
1593
1594 closeSession(session);
1595 }
1596 }
1597
1598 return list;
1599 }
1600
1601
1608 public void removeByC_C(long classNameId, long classPK)
1609 throws SystemException {
1610 for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
1611 ratingsEntryPersistence.remove(ratingsEntry);
1612 }
1613 }
1614
1615
1623 public void removeByU_C_C(long userId, long classNameId, long classPK)
1624 throws NoSuchEntryException, SystemException {
1625 RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
1626
1627 ratingsEntryPersistence.remove(ratingsEntry);
1628 }
1629
1630
1638 public void removeByC_C_S(long classNameId, long classPK, double score)
1639 throws SystemException {
1640 for (RatingsEntry ratingsEntry : findByC_C_S(classNameId, classPK, score)) {
1641 ratingsEntryPersistence.remove(ratingsEntry);
1642 }
1643 }
1644
1645
1650 public void removeAll() throws SystemException {
1651 for (RatingsEntry ratingsEntry : findAll()) {
1652 ratingsEntryPersistence.remove(ratingsEntry);
1653 }
1654 }
1655
1656
1664 public int countByC_C(long classNameId, long classPK)
1665 throws SystemException {
1666 Object[] finderArgs = new Object[] { classNameId, classPK };
1667
1668 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1669 finderArgs, this);
1670
1671 if (count == null) {
1672 StringBundler query = new StringBundler(3);
1673
1674 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1675
1676 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1677
1678 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
1679
1680 String sql = query.toString();
1681
1682 Session session = null;
1683
1684 try {
1685 session = openSession();
1686
1687 Query q = session.createQuery(sql);
1688
1689 QueryPos qPos = QueryPos.getInstance(q);
1690
1691 qPos.add(classNameId);
1692
1693 qPos.add(classPK);
1694
1695 count = (Long)q.uniqueResult();
1696 }
1697 catch (Exception e) {
1698 throw processException(e);
1699 }
1700 finally {
1701 if (count == null) {
1702 count = Long.valueOf(0);
1703 }
1704
1705 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1706 count);
1707
1708 closeSession(session);
1709 }
1710 }
1711
1712 return count.intValue();
1713 }
1714
1715
1724 public int countByU_C_C(long userId, long classNameId, long classPK)
1725 throws SystemException {
1726 Object[] finderArgs = new Object[] { userId, classNameId, classPK };
1727
1728 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
1729 finderArgs, this);
1730
1731 if (count == null) {
1732 StringBundler query = new StringBundler(4);
1733
1734 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1735
1736 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
1737
1738 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
1739
1740 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
1741
1742 String sql = query.toString();
1743
1744 Session session = null;
1745
1746 try {
1747 session = openSession();
1748
1749 Query q = session.createQuery(sql);
1750
1751 QueryPos qPos = QueryPos.getInstance(q);
1752
1753 qPos.add(userId);
1754
1755 qPos.add(classNameId);
1756
1757 qPos.add(classPK);
1758
1759 count = (Long)q.uniqueResult();
1760 }
1761 catch (Exception e) {
1762 throw processException(e);
1763 }
1764 finally {
1765 if (count == null) {
1766 count = Long.valueOf(0);
1767 }
1768
1769 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
1770 finderArgs, count);
1771
1772 closeSession(session);
1773 }
1774 }
1775
1776 return count.intValue();
1777 }
1778
1779
1788 public int countByC_C_S(long classNameId, long classPK, double score)
1789 throws SystemException {
1790 Object[] finderArgs = new Object[] { classNameId, classPK, score };
1791
1792 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_S,
1793 finderArgs, this);
1794
1795 if (count == null) {
1796 StringBundler query = new StringBundler(4);
1797
1798 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
1799
1800 query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
1801
1802 query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
1803
1804 query.append(_FINDER_COLUMN_C_C_S_SCORE_2);
1805
1806 String sql = query.toString();
1807
1808 Session session = null;
1809
1810 try {
1811 session = openSession();
1812
1813 Query q = session.createQuery(sql);
1814
1815 QueryPos qPos = QueryPos.getInstance(q);
1816
1817 qPos.add(classNameId);
1818
1819 qPos.add(classPK);
1820
1821 qPos.add(score);
1822
1823 count = (Long)q.uniqueResult();
1824 }
1825 catch (Exception e) {
1826 throw processException(e);
1827 }
1828 finally {
1829 if (count == null) {
1830 count = Long.valueOf(0);
1831 }
1832
1833 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_S,
1834 finderArgs, count);
1835
1836 closeSession(session);
1837 }
1838 }
1839
1840 return count.intValue();
1841 }
1842
1843
1849 public int countAll() throws SystemException {
1850 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1851 FINDER_ARGS_EMPTY, this);
1852
1853 if (count == null) {
1854 Session session = null;
1855
1856 try {
1857 session = openSession();
1858
1859 Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
1860
1861 count = (Long)q.uniqueResult();
1862 }
1863 catch (Exception e) {
1864 throw processException(e);
1865 }
1866 finally {
1867 if (count == null) {
1868 count = Long.valueOf(0);
1869 }
1870
1871 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1872 FINDER_ARGS_EMPTY, count);
1873
1874 closeSession(session);
1875 }
1876 }
1877
1878 return count.intValue();
1879 }
1880
1881
1884 public void afterPropertiesSet() {
1885 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1886 com.liferay.portal.util.PropsUtil.get(
1887 "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1888
1889 if (listenerClassNames.length > 0) {
1890 try {
1891 List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1892
1893 for (String listenerClassName : listenerClassNames) {
1894 listenersList.add((ModelListener<RatingsEntry>)InstanceFactory.newInstance(
1895 listenerClassName));
1896 }
1897
1898 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1899 }
1900 catch (Exception e) {
1901 _log.error(e);
1902 }
1903 }
1904 }
1905
1906 public void destroy() {
1907 EntityCacheUtil.removeCache(RatingsEntryImpl.class.getName());
1908 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1909 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1910 }
1911
1912 @BeanReference(type = RatingsEntryPersistence.class)
1913 protected RatingsEntryPersistence ratingsEntryPersistence;
1914 @BeanReference(type = RatingsStatsPersistence.class)
1915 protected RatingsStatsPersistence ratingsStatsPersistence;
1916 @BeanReference(type = ResourcePersistence.class)
1917 protected ResourcePersistence resourcePersistence;
1918 @BeanReference(type = UserPersistence.class)
1919 protected UserPersistence userPersistence;
1920 @BeanReference(type = AssetEntryPersistence.class)
1921 protected AssetEntryPersistence assetEntryPersistence;
1922 @BeanReference(type = BlogsEntryPersistence.class)
1923 protected BlogsEntryPersistence blogsEntryPersistence;
1924 @BeanReference(type = BlogsStatsUserPersistence.class)
1925 protected BlogsStatsUserPersistence blogsStatsUserPersistence;
1926 @BeanReference(type = SocialActivityPersistence.class)
1927 protected SocialActivityPersistence socialActivityPersistence;
1928 private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
1929 private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
1930 private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
1931 private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
1932 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1933 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1934 private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1935 private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1936 private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1937 private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1938 private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "ratingsEntry.classPK = ? AND ";
1939 private static final String _FINDER_COLUMN_C_C_S_SCORE_2 = "ratingsEntry.score = ?";
1940 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
1941 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
1942 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
1943 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1944 private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1945 private static RatingsEntry _nullRatingsEntry = new RatingsEntryImpl() {
1946 @Override
1947 public Object clone() {
1948 return this;
1949 }
1950
1951 @Override
1952 public CacheModel<RatingsEntry> toCacheModel() {
1953 return _nullRatingsEntryCacheModel;
1954 }
1955 };
1956
1957 private static CacheModel<RatingsEntry> _nullRatingsEntryCacheModel = new CacheModel<RatingsEntry>() {
1958 public RatingsEntry toEntityModel() {
1959 return _nullRatingsEntry;
1960 }
1961 };
1962 }