1
14
15 package com.liferay.portlet.ratings.service.persistence;
16
17 import com.liferay.portal.NoSuchModelException;
18 import com.liferay.portal.SystemException;
19 import com.liferay.portal.kernel.annotation.BeanReference;
20 import com.liferay.portal.kernel.cache.CacheRegistry;
21 import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
22 import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
23 import com.liferay.portal.kernel.dao.orm.FinderPath;
24 import com.liferay.portal.kernel.dao.orm.Query;
25 import com.liferay.portal.kernel.dao.orm.QueryPos;
26 import com.liferay.portal.kernel.dao.orm.QueryUtil;
27 import com.liferay.portal.kernel.dao.orm.Session;
28 import com.liferay.portal.kernel.log.Log;
29 import com.liferay.portal.kernel.log.LogFactoryUtil;
30 import com.liferay.portal.kernel.util.GetterUtil;
31 import com.liferay.portal.kernel.util.OrderByComparator;
32 import com.liferay.portal.kernel.util.StringBundler;
33 import com.liferay.portal.kernel.util.StringPool;
34 import com.liferay.portal.kernel.util.StringUtil;
35 import com.liferay.portal.model.ModelListener;
36 import com.liferay.portal.service.persistence.BatchSessionUtil;
37 import com.liferay.portal.service.persistence.ResourcePersistence;
38 import com.liferay.portal.service.persistence.UserPersistence;
39 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
40
41 import com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence;
42 import com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence;
43 import com.liferay.portlet.ratings.NoSuchEntryException;
44 import com.liferay.portlet.ratings.model.RatingsEntry;
45 import com.liferay.portlet.ratings.model.impl.RatingsEntryImpl;
46 import com.liferay.portlet.ratings.model.impl.RatingsEntryModelImpl;
47
48 import java.io.Serializable;
49
50 import java.util.ArrayList;
51 import java.util.Collections;
52 import java.util.List;
53
54
67 public class RatingsEntryPersistenceImpl extends BasePersistenceImpl<RatingsEntry>
68 implements RatingsEntryPersistence {
69 public static final String FINDER_CLASS_NAME_ENTITY = RatingsEntryImpl.class.getName();
70 public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
71 ".List";
72 public static final FinderPath FINDER_PATH_FIND_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
73 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
74 "findByC_C",
75 new String[] { Long.class.getName(), Long.class.getName() });
76 public static final FinderPath FINDER_PATH_FIND_BY_OBC_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
77 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
78 "findByC_C",
79 new String[] {
80 Long.class.getName(), Long.class.getName(),
81
82 "java.lang.Integer", "java.lang.Integer",
83 "com.liferay.portal.kernel.util.OrderByComparator"
84 });
85 public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
86 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
87 "countByC_C",
88 new String[] { Long.class.getName(), Long.class.getName() });
89 public static final FinderPath FINDER_PATH_FETCH_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
90 RatingsEntryModelImpl.FINDER_CACHE_ENABLED,
91 FINDER_CLASS_NAME_ENTITY, "fetchByU_C_C",
92 new String[] {
93 Long.class.getName(), Long.class.getName(), Long.class.getName()
94 });
95 public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
96 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
97 "countByU_C_C",
98 new String[] {
99 Long.class.getName(), Long.class.getName(), Long.class.getName()
100 });
101 public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
102 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
103 "findAll", new String[0]);
104 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
105 RatingsEntryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
106 "countAll", new String[0]);
107
108 public void cacheResult(RatingsEntry ratingsEntry) {
109 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
110 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
111
112 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
113 new Object[] {
114 new Long(ratingsEntry.getUserId()),
115 new Long(ratingsEntry.getClassNameId()),
116 new Long(ratingsEntry.getClassPK())
117 }, ratingsEntry);
118 }
119
120 public void cacheResult(List<RatingsEntry> ratingsEntries) {
121 for (RatingsEntry ratingsEntry : ratingsEntries) {
122 if (EntityCacheUtil.getResult(
123 RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
124 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(),
125 this) == null) {
126 cacheResult(ratingsEntry);
127 }
128 }
129 }
130
131 public void clearCache() {
132 CacheRegistry.clear(RatingsEntryImpl.class.getName());
133 EntityCacheUtil.clearCache(RatingsEntryImpl.class.getName());
134 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
135 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
136 }
137
138 public RatingsEntry create(long entryId) {
139 RatingsEntry ratingsEntry = new RatingsEntryImpl();
140
141 ratingsEntry.setNew(true);
142 ratingsEntry.setPrimaryKey(entryId);
143
144 return ratingsEntry;
145 }
146
147 public RatingsEntry remove(Serializable primaryKey)
148 throws NoSuchModelException, SystemException {
149 return remove(((Long)primaryKey).longValue());
150 }
151
152 public RatingsEntry remove(long entryId)
153 throws NoSuchEntryException, SystemException {
154 Session session = null;
155
156 try {
157 session = openSession();
158
159 RatingsEntry ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
160 new Long(entryId));
161
162 if (ratingsEntry == null) {
163 if (_log.isWarnEnabled()) {
164 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
165 }
166
167 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
168 entryId);
169 }
170
171 return remove(ratingsEntry);
172 }
173 catch (NoSuchEntryException nsee) {
174 throw nsee;
175 }
176 catch (Exception e) {
177 throw processException(e);
178 }
179 finally {
180 closeSession(session);
181 }
182 }
183
184 public RatingsEntry remove(RatingsEntry ratingsEntry)
185 throws SystemException {
186 for (ModelListener<RatingsEntry> listener : listeners) {
187 listener.onBeforeRemove(ratingsEntry);
188 }
189
190 ratingsEntry = removeImpl(ratingsEntry);
191
192 for (ModelListener<RatingsEntry> listener : listeners) {
193 listener.onAfterRemove(ratingsEntry);
194 }
195
196 return ratingsEntry;
197 }
198
199 protected RatingsEntry removeImpl(RatingsEntry ratingsEntry)
200 throws SystemException {
201 ratingsEntry = toUnwrappedModel(ratingsEntry);
202
203 Session session = null;
204
205 try {
206 session = openSession();
207
208 if (ratingsEntry.isCachedModel() || BatchSessionUtil.isEnabled()) {
209 Object staleObject = session.get(RatingsEntryImpl.class,
210 ratingsEntry.getPrimaryKeyObj());
211
212 if (staleObject != null) {
213 session.evict(staleObject);
214 }
215 }
216
217 session.delete(ratingsEntry);
218
219 session.flush();
220 }
221 catch (Exception e) {
222 throw processException(e);
223 }
224 finally {
225 closeSession(session);
226 }
227
228 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
229
230 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
231
232 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
233 new Object[] {
234 new Long(ratingsEntryModelImpl.getOriginalUserId()),
235 new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
236 new Long(ratingsEntryModelImpl.getOriginalClassPK())
237 });
238
239 EntityCacheUtil.removeResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
240 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey());
241
242 return ratingsEntry;
243 }
244
245
248 public RatingsEntry update(RatingsEntry ratingsEntry)
249 throws SystemException {
250 if (_log.isWarnEnabled()) {
251 _log.warn(
252 "Using the deprecated update(RatingsEntry ratingsEntry) method. Use update(RatingsEntry ratingsEntry, boolean merge) instead.");
253 }
254
255 return update(ratingsEntry, false);
256 }
257
258 public RatingsEntry updateImpl(
259 com.liferay.portlet.ratings.model.RatingsEntry ratingsEntry,
260 boolean merge) throws SystemException {
261 ratingsEntry = toUnwrappedModel(ratingsEntry);
262
263 boolean isNew = ratingsEntry.isNew();
264
265 RatingsEntryModelImpl ratingsEntryModelImpl = (RatingsEntryModelImpl)ratingsEntry;
266
267 Session session = null;
268
269 try {
270 session = openSession();
271
272 BatchSessionUtil.update(session, ratingsEntry, merge);
273
274 ratingsEntry.setNew(false);
275 }
276 catch (Exception e) {
277 throw processException(e);
278 }
279 finally {
280 closeSession(session);
281 }
282
283 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
284
285 EntityCacheUtil.putResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
286 RatingsEntryImpl.class, ratingsEntry.getPrimaryKey(), ratingsEntry);
287
288 if (!isNew &&
289 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
290 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
291 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
292 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_U_C_C,
293 new Object[] {
294 new Long(ratingsEntryModelImpl.getOriginalUserId()),
295 new Long(ratingsEntryModelImpl.getOriginalClassNameId()),
296 new Long(ratingsEntryModelImpl.getOriginalClassPK())
297 });
298 }
299
300 if (isNew ||
301 ((ratingsEntry.getUserId() != ratingsEntryModelImpl.getOriginalUserId()) ||
302 (ratingsEntry.getClassNameId() != ratingsEntryModelImpl.getOriginalClassNameId()) ||
303 (ratingsEntry.getClassPK() != ratingsEntryModelImpl.getOriginalClassPK()))) {
304 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
305 new Object[] {
306 new Long(ratingsEntry.getUserId()),
307 new Long(ratingsEntry.getClassNameId()),
308 new Long(ratingsEntry.getClassPK())
309 }, ratingsEntry);
310 }
311
312 return ratingsEntry;
313 }
314
315 protected RatingsEntry toUnwrappedModel(RatingsEntry ratingsEntry) {
316 if (ratingsEntry instanceof RatingsEntryImpl) {
317 return ratingsEntry;
318 }
319
320 RatingsEntryImpl ratingsEntryImpl = new RatingsEntryImpl();
321
322 ratingsEntryImpl.setNew(ratingsEntry.isNew());
323 ratingsEntryImpl.setPrimaryKey(ratingsEntry.getPrimaryKey());
324
325 ratingsEntryImpl.setEntryId(ratingsEntry.getEntryId());
326 ratingsEntryImpl.setCompanyId(ratingsEntry.getCompanyId());
327 ratingsEntryImpl.setUserId(ratingsEntry.getUserId());
328 ratingsEntryImpl.setUserName(ratingsEntry.getUserName());
329 ratingsEntryImpl.setCreateDate(ratingsEntry.getCreateDate());
330 ratingsEntryImpl.setModifiedDate(ratingsEntry.getModifiedDate());
331 ratingsEntryImpl.setClassNameId(ratingsEntry.getClassNameId());
332 ratingsEntryImpl.setClassPK(ratingsEntry.getClassPK());
333 ratingsEntryImpl.setScore(ratingsEntry.getScore());
334
335 return ratingsEntryImpl;
336 }
337
338 public RatingsEntry findByPrimaryKey(Serializable primaryKey)
339 throws NoSuchModelException, SystemException {
340 return findByPrimaryKey(((Long)primaryKey).longValue());
341 }
342
343 public RatingsEntry findByPrimaryKey(long entryId)
344 throws NoSuchEntryException, SystemException {
345 RatingsEntry ratingsEntry = fetchByPrimaryKey(entryId);
346
347 if (ratingsEntry == null) {
348 if (_log.isWarnEnabled()) {
349 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + entryId);
350 }
351
352 throw new NoSuchEntryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
353 entryId);
354 }
355
356 return ratingsEntry;
357 }
358
359 public RatingsEntry fetchByPrimaryKey(Serializable primaryKey)
360 throws SystemException {
361 return fetchByPrimaryKey(((Long)primaryKey).longValue());
362 }
363
364 public RatingsEntry fetchByPrimaryKey(long entryId)
365 throws SystemException {
366 RatingsEntry ratingsEntry = (RatingsEntry)EntityCacheUtil.getResult(RatingsEntryModelImpl.ENTITY_CACHE_ENABLED,
367 RatingsEntryImpl.class, entryId, this);
368
369 if (ratingsEntry == null) {
370 Session session = null;
371
372 try {
373 session = openSession();
374
375 ratingsEntry = (RatingsEntry)session.get(RatingsEntryImpl.class,
376 new Long(entryId));
377 }
378 catch (Exception e) {
379 throw processException(e);
380 }
381 finally {
382 if (ratingsEntry != null) {
383 cacheResult(ratingsEntry);
384 }
385
386 closeSession(session);
387 }
388 }
389
390 return ratingsEntry;
391 }
392
393 public List<RatingsEntry> findByC_C(long classNameId, long classPK)
394 throws SystemException {
395 Object[] finderArgs = new Object[] {
396 new Long(classNameId), new Long(classPK)
397 };
398
399 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_C_C,
400 finderArgs, this);
401
402 if (list == null) {
403 Session session = null;
404
405 try {
406 session = openSession();
407
408 StringBundler query = new StringBundler(3);
409
410 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
411
412 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
413
414 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
415
416 String sql = query.toString();
417
418 Query q = session.createQuery(sql);
419
420 QueryPos qPos = QueryPos.getInstance(q);
421
422 qPos.add(classNameId);
423
424 qPos.add(classPK);
425
426 list = q.list();
427 }
428 catch (Exception e) {
429 throw processException(e);
430 }
431 finally {
432 if (list == null) {
433 list = new ArrayList<RatingsEntry>();
434 }
435
436 cacheResult(list);
437
438 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_C_C, finderArgs,
439 list);
440
441 closeSession(session);
442 }
443 }
444
445 return list;
446 }
447
448 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
449 int start, int end) throws SystemException {
450 return findByC_C(classNameId, classPK, start, end, null);
451 }
452
453 public List<RatingsEntry> findByC_C(long classNameId, long classPK,
454 int start, int end, OrderByComparator orderByComparator)
455 throws SystemException {
456 Object[] finderArgs = new Object[] {
457 new Long(classNameId), new Long(classPK),
458
459 String.valueOf(start), String.valueOf(end),
460 String.valueOf(orderByComparator)
461 };
462
463 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_OBC_C_C,
464 finderArgs, this);
465
466 if (list == null) {
467 Session session = null;
468
469 try {
470 session = openSession();
471
472 StringBundler query = null;
473
474 if (orderByComparator != null) {
475 query = new StringBundler(4 +
476 (orderByComparator.getOrderByFields().length * 3));
477 }
478 else {
479 query = new StringBundler(3);
480 }
481
482 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
483
484 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
485
486 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
487
488 if (orderByComparator != null) {
489 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
490 orderByComparator);
491 }
492
493 String sql = query.toString();
494
495 Query q = session.createQuery(sql);
496
497 QueryPos qPos = QueryPos.getInstance(q);
498
499 qPos.add(classNameId);
500
501 qPos.add(classPK);
502
503 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
504 start, end);
505 }
506 catch (Exception e) {
507 throw processException(e);
508 }
509 finally {
510 if (list == null) {
511 list = new ArrayList<RatingsEntry>();
512 }
513
514 cacheResult(list);
515
516 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C,
517 finderArgs, list);
518
519 closeSession(session);
520 }
521 }
522
523 return list;
524 }
525
526 public RatingsEntry findByC_C_First(long classNameId, long classPK,
527 OrderByComparator orderByComparator)
528 throws NoSuchEntryException, SystemException {
529 List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1,
530 orderByComparator);
531
532 if (list.isEmpty()) {
533 StringBundler msg = new StringBundler(6);
534
535 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
536
537 msg.append("classNameId=");
538 msg.append(classNameId);
539
540 msg.append(", classPK=");
541 msg.append(classPK);
542
543 msg.append(StringPool.CLOSE_CURLY_BRACE);
544
545 throw new NoSuchEntryException(msg.toString());
546 }
547 else {
548 return list.get(0);
549 }
550 }
551
552 public RatingsEntry findByC_C_Last(long classNameId, long classPK,
553 OrderByComparator orderByComparator)
554 throws NoSuchEntryException, SystemException {
555 int count = countByC_C(classNameId, classPK);
556
557 List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
558 count, orderByComparator);
559
560 if (list.isEmpty()) {
561 StringBundler msg = new StringBundler(6);
562
563 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
564
565 msg.append("classNameId=");
566 msg.append(classNameId);
567
568 msg.append(", classPK=");
569 msg.append(classPK);
570
571 msg.append(StringPool.CLOSE_CURLY_BRACE);
572
573 throw new NoSuchEntryException(msg.toString());
574 }
575 else {
576 return list.get(0);
577 }
578 }
579
580 public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
581 long classPK, OrderByComparator orderByComparator)
582 throws NoSuchEntryException, SystemException {
583 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
584
585 int count = countByC_C(classNameId, classPK);
586
587 Session session = null;
588
589 try {
590 session = openSession();
591
592 StringBundler query = null;
593
594 if (orderByComparator != null) {
595 query = new StringBundler(4 +
596 (orderByComparator.getOrderByFields().length * 3));
597 }
598 else {
599 query = new StringBundler(3);
600 }
601
602 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
603
604 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
605
606 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
607
608 if (orderByComparator != null) {
609 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
610 orderByComparator);
611 }
612
613 String sql = query.toString();
614
615 Query q = session.createQuery(sql);
616
617 QueryPos qPos = QueryPos.getInstance(q);
618
619 qPos.add(classNameId);
620
621 qPos.add(classPK);
622
623 Object[] objArray = QueryUtil.getPrevAndNext(q, count,
624 orderByComparator, ratingsEntry);
625
626 RatingsEntry[] array = new RatingsEntryImpl[3];
627
628 array[0] = (RatingsEntry)objArray[0];
629 array[1] = (RatingsEntry)objArray[1];
630 array[2] = (RatingsEntry)objArray[2];
631
632 return array;
633 }
634 catch (Exception e) {
635 throw processException(e);
636 }
637 finally {
638 closeSession(session);
639 }
640 }
641
642 public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
643 throws NoSuchEntryException, SystemException {
644 RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
645
646 if (ratingsEntry == null) {
647 StringBundler msg = new StringBundler(8);
648
649 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
650
651 msg.append("userId=");
652 msg.append(userId);
653
654 msg.append(", classNameId=");
655 msg.append(classNameId);
656
657 msg.append(", classPK=");
658 msg.append(classPK);
659
660 msg.append(StringPool.CLOSE_CURLY_BRACE);
661
662 if (_log.isWarnEnabled()) {
663 _log.warn(msg.toString());
664 }
665
666 throw new NoSuchEntryException(msg.toString());
667 }
668
669 return ratingsEntry;
670 }
671
672 public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
673 throws SystemException {
674 return fetchByU_C_C(userId, classNameId, classPK, true);
675 }
676
677 public RatingsEntry fetchByU_C_C(long userId, long classNameId,
678 long classPK, boolean retrieveFromCache) throws SystemException {
679 Object[] finderArgs = new Object[] {
680 new Long(userId), new Long(classNameId), new Long(classPK)
681 };
682
683 Object result = null;
684
685 if (retrieveFromCache) {
686 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
687 finderArgs, this);
688 }
689
690 if (result == null) {
691 Session session = null;
692
693 try {
694 session = openSession();
695
696 StringBundler query = new StringBundler(4);
697
698 query.append(_SQL_SELECT_RATINGSENTRY_WHERE);
699
700 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
701
702 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
703
704 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
705
706 String sql = query.toString();
707
708 Query q = session.createQuery(sql);
709
710 QueryPos qPos = QueryPos.getInstance(q);
711
712 qPos.add(userId);
713
714 qPos.add(classNameId);
715
716 qPos.add(classPK);
717
718 List<RatingsEntry> list = q.list();
719
720 result = list;
721
722 RatingsEntry ratingsEntry = null;
723
724 if (list.isEmpty()) {
725 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
726 finderArgs, list);
727 }
728 else {
729 ratingsEntry = list.get(0);
730
731 cacheResult(ratingsEntry);
732
733 if ((ratingsEntry.getUserId() != userId) ||
734 (ratingsEntry.getClassNameId() != classNameId) ||
735 (ratingsEntry.getClassPK() != classPK)) {
736 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
737 finderArgs, ratingsEntry);
738 }
739 }
740
741 return ratingsEntry;
742 }
743 catch (Exception e) {
744 throw processException(e);
745 }
746 finally {
747 if (result == null) {
748 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
749 finderArgs, new ArrayList<RatingsEntry>());
750 }
751
752 closeSession(session);
753 }
754 }
755 else {
756 if (result instanceof List<?>) {
757 return null;
758 }
759 else {
760 return (RatingsEntry)result;
761 }
762 }
763 }
764
765 public List<RatingsEntry> findAll() throws SystemException {
766 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
767 }
768
769 public List<RatingsEntry> findAll(int start, int end)
770 throws SystemException {
771 return findAll(start, end, null);
772 }
773
774 public List<RatingsEntry> findAll(int start, int end,
775 OrderByComparator orderByComparator) throws SystemException {
776 Object[] finderArgs = new Object[] {
777 String.valueOf(start), String.valueOf(end),
778 String.valueOf(orderByComparator)
779 };
780
781 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
782 finderArgs, this);
783
784 if (list == null) {
785 Session session = null;
786
787 try {
788 session = openSession();
789
790 StringBundler query = null;
791 String sql = null;
792
793 if (orderByComparator != null) {
794 query = new StringBundler(2 +
795 (orderByComparator.getOrderByFields().length * 3));
796
797 query.append(_SQL_SELECT_RATINGSENTRY);
798
799 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
800 orderByComparator);
801
802 sql = query.toString();
803 }
804
805 sql = _SQL_SELECT_RATINGSENTRY;
806
807 Query q = session.createQuery(sql);
808
809 if (orderByComparator == null) {
810 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
811 start, end, false);
812
813 Collections.sort(list);
814 }
815 else {
816 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
817 start, end);
818 }
819 }
820 catch (Exception e) {
821 throw processException(e);
822 }
823 finally {
824 if (list == null) {
825 list = new ArrayList<RatingsEntry>();
826 }
827
828 cacheResult(list);
829
830 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
831
832 closeSession(session);
833 }
834 }
835
836 return list;
837 }
838
839 public void removeByC_C(long classNameId, long classPK)
840 throws SystemException {
841 for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
842 remove(ratingsEntry);
843 }
844 }
845
846 public void removeByU_C_C(long userId, long classNameId, long classPK)
847 throws NoSuchEntryException, SystemException {
848 RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
849
850 remove(ratingsEntry);
851 }
852
853 public void removeAll() throws SystemException {
854 for (RatingsEntry ratingsEntry : findAll()) {
855 remove(ratingsEntry);
856 }
857 }
858
859 public int countByC_C(long classNameId, long classPK)
860 throws SystemException {
861 Object[] finderArgs = new Object[] {
862 new Long(classNameId), new Long(classPK)
863 };
864
865 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
866 finderArgs, this);
867
868 if (count == null) {
869 Session session = null;
870
871 try {
872 session = openSession();
873
874 StringBundler query = new StringBundler(3);
875
876 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
877
878 query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
879
880 query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
881
882 String sql = query.toString();
883
884 Query q = session.createQuery(sql);
885
886 QueryPos qPos = QueryPos.getInstance(q);
887
888 qPos.add(classNameId);
889
890 qPos.add(classPK);
891
892 count = (Long)q.uniqueResult();
893 }
894 catch (Exception e) {
895 throw processException(e);
896 }
897 finally {
898 if (count == null) {
899 count = Long.valueOf(0);
900 }
901
902 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
903 count);
904
905 closeSession(session);
906 }
907 }
908
909 return count.intValue();
910 }
911
912 public int countByU_C_C(long userId, long classNameId, long classPK)
913 throws SystemException {
914 Object[] finderArgs = new Object[] {
915 new Long(userId), new Long(classNameId), new Long(classPK)
916 };
917
918 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
919 finderArgs, this);
920
921 if (count == null) {
922 Session session = null;
923
924 try {
925 session = openSession();
926
927 StringBundler query = new StringBundler(4);
928
929 query.append(_SQL_COUNT_RATINGSENTRY_WHERE);
930
931 query.append(_FINDER_COLUMN_U_C_C_USERID_2);
932
933 query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
934
935 query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
936
937 String sql = query.toString();
938
939 Query q = session.createQuery(sql);
940
941 QueryPos qPos = QueryPos.getInstance(q);
942
943 qPos.add(userId);
944
945 qPos.add(classNameId);
946
947 qPos.add(classPK);
948
949 count = (Long)q.uniqueResult();
950 }
951 catch (Exception e) {
952 throw processException(e);
953 }
954 finally {
955 if (count == null) {
956 count = Long.valueOf(0);
957 }
958
959 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
960 finderArgs, count);
961
962 closeSession(session);
963 }
964 }
965
966 return count.intValue();
967 }
968
969 public int countAll() throws SystemException {
970 Object[] finderArgs = new Object[0];
971
972 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
973 finderArgs, this);
974
975 if (count == null) {
976 Session session = null;
977
978 try {
979 session = openSession();
980
981 Query q = session.createQuery(_SQL_COUNT_RATINGSENTRY);
982
983 count = (Long)q.uniqueResult();
984 }
985 catch (Exception e) {
986 throw processException(e);
987 }
988 finally {
989 if (count == null) {
990 count = Long.valueOf(0);
991 }
992
993 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
994 count);
995
996 closeSession(session);
997 }
998 }
999
1000 return count.intValue();
1001 }
1002
1003 public void afterPropertiesSet() {
1004 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1005 com.liferay.portal.util.PropsUtil.get(
1006 "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1007
1008 if (listenerClassNames.length > 0) {
1009 try {
1010 List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1011
1012 for (String listenerClassName : listenerClassNames) {
1013 listenersList.add((ModelListener<RatingsEntry>)Class.forName(
1014 listenerClassName).newInstance());
1015 }
1016
1017 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1018 }
1019 catch (Exception e) {
1020 _log.error(e);
1021 }
1022 }
1023 }
1024
1025 @BeanReference(type = RatingsEntryPersistence.class)
1026 protected RatingsEntryPersistence ratingsEntryPersistence;
1027 @BeanReference(type = RatingsStatsPersistence.class)
1028 protected RatingsStatsPersistence ratingsStatsPersistence;
1029 @BeanReference(type = ResourcePersistence.class)
1030 protected ResourcePersistence resourcePersistence;
1031 @BeanReference(type = UserPersistence.class)
1032 protected UserPersistence userPersistence;
1033 @BeanReference(type = BlogsEntryPersistence.class)
1034 protected BlogsEntryPersistence blogsEntryPersistence;
1035 @BeanReference(type = BlogsStatsUserPersistence.class)
1036 protected BlogsStatsUserPersistence blogsStatsUserPersistence;
1037 private static final String _SQL_SELECT_RATINGSENTRY = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry";
1038 private static final String _SQL_SELECT_RATINGSENTRY_WHERE = "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ";
1039 private static final String _SQL_COUNT_RATINGSENTRY = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry";
1040 private static final String _SQL_COUNT_RATINGSENTRY_WHERE = "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry WHERE ";
1041 private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1042 private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1043 private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "ratingsEntry.userId = ? AND ";
1044 private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "ratingsEntry.classNameId = ? AND ";
1045 private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "ratingsEntry.classPK = ?";
1046 private static final String _ORDER_BY_ENTITY_ALIAS = "ratingsEntry.";
1047 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No RatingsEntry exists with the primary key ";
1048 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No RatingsEntry exists with the key {";
1049 private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1050}