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