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