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