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 "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ");
403
404 query.append("ratingsEntry.classNameId = ?");
405
406 query.append(" AND ");
407
408 query.append("ratingsEntry.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 "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ");
468
469 query.append("ratingsEntry.classNameId = ?");
470
471 query.append(" AND ");
472
473 query.append("ratingsEntry.classPK = ?");
474
475 query.append(" ");
476
477 if (obc != null) {
478 query.append("ORDER BY ");
479
480 String[] orderByFields = obc.getOrderByFields();
481
482 for (int i = 0; i < orderByFields.length; i++) {
483 query.append("ratingsEntry.");
484 query.append(orderByFields[i]);
485
486 if (obc.isAscending()) {
487 query.append(" ASC");
488 }
489 else {
490 query.append(" DESC");
491 }
492
493 if ((i + 1) < orderByFields.length) {
494 query.append(", ");
495 }
496 }
497 }
498
499 Query q = session.createQuery(query.toString());
500
501 QueryPos qPos = QueryPos.getInstance(q);
502
503 qPos.add(classNameId);
504
505 qPos.add(classPK);
506
507 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
508 start, end);
509 }
510 catch (Exception e) {
511 throw processException(e);
512 }
513 finally {
514 if (list == null) {
515 list = new ArrayList<RatingsEntry>();
516 }
517
518 cacheResult(list);
519
520 FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_OBC_C_C,
521 finderArgs, list);
522
523 closeSession(session);
524 }
525 }
526
527 return list;
528 }
529
530 public RatingsEntry findByC_C_First(long classNameId, long classPK,
531 OrderByComparator obc) throws NoSuchEntryException, SystemException {
532 List<RatingsEntry> list = findByC_C(classNameId, classPK, 0, 1, obc);
533
534 if (list.isEmpty()) {
535 StringBuilder msg = new StringBuilder();
536
537 msg.append("No RatingsEntry exists with the key {");
538
539 msg.append("classNameId=" + classNameId);
540
541 msg.append(", ");
542 msg.append("classPK=" + classPK);
543
544 msg.append(StringPool.CLOSE_CURLY_BRACE);
545
546 throw new NoSuchEntryException(msg.toString());
547 }
548 else {
549 return list.get(0);
550 }
551 }
552
553 public RatingsEntry findByC_C_Last(long classNameId, long classPK,
554 OrderByComparator obc) throws NoSuchEntryException, SystemException {
555 int count = countByC_C(classNameId, classPK);
556
557 List<RatingsEntry> list = findByC_C(classNameId, classPK, count - 1,
558 count, obc);
559
560 if (list.isEmpty()) {
561 StringBuilder msg = new StringBuilder();
562
563 msg.append("No RatingsEntry exists with the key {");
564
565 msg.append("classNameId=" + classNameId);
566
567 msg.append(", ");
568 msg.append("classPK=" + classPK);
569
570 msg.append(StringPool.CLOSE_CURLY_BRACE);
571
572 throw new NoSuchEntryException(msg.toString());
573 }
574 else {
575 return list.get(0);
576 }
577 }
578
579 public RatingsEntry[] findByC_C_PrevAndNext(long entryId, long classNameId,
580 long classPK, OrderByComparator obc)
581 throws NoSuchEntryException, SystemException {
582 RatingsEntry ratingsEntry = findByPrimaryKey(entryId);
583
584 int count = countByC_C(classNameId, classPK);
585
586 Session session = null;
587
588 try {
589 session = openSession();
590
591 StringBuilder query = new StringBuilder();
592
593 query.append(
594 "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ");
595
596 query.append("ratingsEntry.classNameId = ?");
597
598 query.append(" AND ");
599
600 query.append("ratingsEntry.classPK = ?");
601
602 query.append(" ");
603
604 if (obc != null) {
605 query.append("ORDER BY ");
606
607 String[] orderByFields = obc.getOrderByFields();
608
609 for (int i = 0; i < orderByFields.length; i++) {
610 query.append("ratingsEntry.");
611 query.append(orderByFields[i]);
612
613 if (obc.isAscending()) {
614 query.append(" ASC");
615 }
616 else {
617 query.append(" DESC");
618 }
619
620 if ((i + 1) < orderByFields.length) {
621 query.append(", ");
622 }
623 }
624 }
625
626 Query q = session.createQuery(query.toString());
627
628 QueryPos qPos = QueryPos.getInstance(q);
629
630 qPos.add(classNameId);
631
632 qPos.add(classPK);
633
634 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
635 ratingsEntry);
636
637 RatingsEntry[] array = new RatingsEntryImpl[3];
638
639 array[0] = (RatingsEntry)objArray[0];
640 array[1] = (RatingsEntry)objArray[1];
641 array[2] = (RatingsEntry)objArray[2];
642
643 return array;
644 }
645 catch (Exception e) {
646 throw processException(e);
647 }
648 finally {
649 closeSession(session);
650 }
651 }
652
653 public RatingsEntry findByU_C_C(long userId, long classNameId, long classPK)
654 throws NoSuchEntryException, SystemException {
655 RatingsEntry ratingsEntry = fetchByU_C_C(userId, classNameId, classPK);
656
657 if (ratingsEntry == null) {
658 StringBuilder msg = new StringBuilder();
659
660 msg.append("No RatingsEntry exists with the key {");
661
662 msg.append("userId=" + userId);
663
664 msg.append(", ");
665 msg.append("classNameId=" + classNameId);
666
667 msg.append(", ");
668 msg.append("classPK=" + classPK);
669
670 msg.append(StringPool.CLOSE_CURLY_BRACE);
671
672 if (_log.isWarnEnabled()) {
673 _log.warn(msg.toString());
674 }
675
676 throw new NoSuchEntryException(msg.toString());
677 }
678
679 return ratingsEntry;
680 }
681
682 public RatingsEntry fetchByU_C_C(long userId, long classNameId, long classPK)
683 throws SystemException {
684 return fetchByU_C_C(userId, classNameId, classPK, true);
685 }
686
687 public RatingsEntry fetchByU_C_C(long userId, long classNameId,
688 long classPK, boolean retrieveFromCache) throws SystemException {
689 Object[] finderArgs = new Object[] {
690 new Long(userId), new Long(classNameId), new Long(classPK)
691 };
692
693 Object result = null;
694
695 if (retrieveFromCache) {
696 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_U_C_C,
697 finderArgs, this);
698 }
699
700 if (result == null) {
701 Session session = null;
702
703 try {
704 session = openSession();
705
706 StringBuilder query = new StringBuilder();
707
708 query.append(
709 "SELECT ratingsEntry FROM RatingsEntry ratingsEntry WHERE ");
710
711 query.append("ratingsEntry.userId = ?");
712
713 query.append(" AND ");
714
715 query.append("ratingsEntry.classNameId = ?");
716
717 query.append(" AND ");
718
719 query.append("ratingsEntry.classPK = ?");
720
721 query.append(" ");
722
723 Query q = session.createQuery(query.toString());
724
725 QueryPos qPos = QueryPos.getInstance(q);
726
727 qPos.add(userId);
728
729 qPos.add(classNameId);
730
731 qPos.add(classPK);
732
733 List<RatingsEntry> list = q.list();
734
735 result = list;
736
737 RatingsEntry ratingsEntry = null;
738
739 if (list.isEmpty()) {
740 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
741 finderArgs, list);
742 }
743 else {
744 ratingsEntry = list.get(0);
745
746 cacheResult(ratingsEntry);
747
748 if ((ratingsEntry.getUserId() != userId) ||
749 (ratingsEntry.getClassNameId() != classNameId) ||
750 (ratingsEntry.getClassPK() != classPK)) {
751 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
752 finderArgs, ratingsEntry);
753 }
754 }
755
756 return ratingsEntry;
757 }
758 catch (Exception e) {
759 throw processException(e);
760 }
761 finally {
762 if (result == null) {
763 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_U_C_C,
764 finderArgs, new ArrayList<RatingsEntry>());
765 }
766
767 closeSession(session);
768 }
769 }
770 else {
771 if (result instanceof List) {
772 return null;
773 }
774 else {
775 return (RatingsEntry)result;
776 }
777 }
778 }
779
780 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
781 throws SystemException {
782 Session session = null;
783
784 try {
785 session = openSession();
786
787 dynamicQuery.compile(session);
788
789 return dynamicQuery.list();
790 }
791 catch (Exception e) {
792 throw processException(e);
793 }
794 finally {
795 closeSession(session);
796 }
797 }
798
799 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
800 int start, int end) throws SystemException {
801 Session session = null;
802
803 try {
804 session = openSession();
805
806 dynamicQuery.setLimit(start, end);
807
808 dynamicQuery.compile(session);
809
810 return dynamicQuery.list();
811 }
812 catch (Exception e) {
813 throw processException(e);
814 }
815 finally {
816 closeSession(session);
817 }
818 }
819
820 public List<RatingsEntry> findAll() throws SystemException {
821 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
822 }
823
824 public List<RatingsEntry> findAll(int start, int end)
825 throws SystemException {
826 return findAll(start, end, null);
827 }
828
829 public List<RatingsEntry> findAll(int start, int end, OrderByComparator obc)
830 throws SystemException {
831 Object[] finderArgs = new Object[] {
832 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
833 };
834
835 List<RatingsEntry> list = (List<RatingsEntry>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
836 finderArgs, this);
837
838 if (list == null) {
839 Session session = null;
840
841 try {
842 session = openSession();
843
844 StringBuilder query = new StringBuilder();
845
846 query.append(
847 "SELECT ratingsEntry FROM RatingsEntry ratingsEntry ");
848
849 if (obc != null) {
850 query.append("ORDER BY ");
851
852 String[] orderByFields = obc.getOrderByFields();
853
854 for (int i = 0; i < orderByFields.length; i++) {
855 query.append("ratingsEntry.");
856 query.append(orderByFields[i]);
857
858 if (obc.isAscending()) {
859 query.append(" ASC");
860 }
861 else {
862 query.append(" DESC");
863 }
864
865 if ((i + 1) < orderByFields.length) {
866 query.append(", ");
867 }
868 }
869 }
870
871 Query q = session.createQuery(query.toString());
872
873 if (obc == null) {
874 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
875 start, end, false);
876
877 Collections.sort(list);
878 }
879 else {
880 list = (List<RatingsEntry>)QueryUtil.list(q, getDialect(),
881 start, end);
882 }
883 }
884 catch (Exception e) {
885 throw processException(e);
886 }
887 finally {
888 if (list == null) {
889 list = new ArrayList<RatingsEntry>();
890 }
891
892 cacheResult(list);
893
894 FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs, list);
895
896 closeSession(session);
897 }
898 }
899
900 return list;
901 }
902
903 public void removeByC_C(long classNameId, long classPK)
904 throws SystemException {
905 for (RatingsEntry ratingsEntry : findByC_C(classNameId, classPK)) {
906 remove(ratingsEntry);
907 }
908 }
909
910 public void removeByU_C_C(long userId, long classNameId, long classPK)
911 throws NoSuchEntryException, SystemException {
912 RatingsEntry ratingsEntry = findByU_C_C(userId, classNameId, classPK);
913
914 remove(ratingsEntry);
915 }
916
917 public void removeAll() throws SystemException {
918 for (RatingsEntry ratingsEntry : findAll()) {
919 remove(ratingsEntry);
920 }
921 }
922
923 public int countByC_C(long classNameId, long classPK)
924 throws SystemException {
925 Object[] finderArgs = new Object[] {
926 new Long(classNameId), new Long(classPK)
927 };
928
929 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
930 finderArgs, this);
931
932 if (count == null) {
933 Session session = null;
934
935 try {
936 session = openSession();
937
938 StringBuilder query = new StringBuilder();
939
940 query.append("SELECT COUNT(ratingsEntry) ");
941 query.append("FROM RatingsEntry ratingsEntry WHERE ");
942
943 query.append("ratingsEntry.classNameId = ?");
944
945 query.append(" AND ");
946
947 query.append("ratingsEntry.classPK = ?");
948
949 query.append(" ");
950
951 Query q = session.createQuery(query.toString());
952
953 QueryPos qPos = QueryPos.getInstance(q);
954
955 qPos.add(classNameId);
956
957 qPos.add(classPK);
958
959 count = (Long)q.uniqueResult();
960 }
961 catch (Exception e) {
962 throw processException(e);
963 }
964 finally {
965 if (count == null) {
966 count = Long.valueOf(0);
967 }
968
969 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
970 count);
971
972 closeSession(session);
973 }
974 }
975
976 return count.intValue();
977 }
978
979 public int countByU_C_C(long userId, long classNameId, long classPK)
980 throws SystemException {
981 Object[] finderArgs = new Object[] {
982 new Long(userId), new Long(classNameId), new Long(classPK)
983 };
984
985 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_U_C_C,
986 finderArgs, this);
987
988 if (count == null) {
989 Session session = null;
990
991 try {
992 session = openSession();
993
994 StringBuilder query = new StringBuilder();
995
996 query.append("SELECT COUNT(ratingsEntry) ");
997 query.append("FROM RatingsEntry ratingsEntry WHERE ");
998
999 query.append("ratingsEntry.userId = ?");
1000
1001 query.append(" AND ");
1002
1003 query.append("ratingsEntry.classNameId = ?");
1004
1005 query.append(" AND ");
1006
1007 query.append("ratingsEntry.classPK = ?");
1008
1009 query.append(" ");
1010
1011 Query q = session.createQuery(query.toString());
1012
1013 QueryPos qPos = QueryPos.getInstance(q);
1014
1015 qPos.add(userId);
1016
1017 qPos.add(classNameId);
1018
1019 qPos.add(classPK);
1020
1021 count = (Long)q.uniqueResult();
1022 }
1023 catch (Exception e) {
1024 throw processException(e);
1025 }
1026 finally {
1027 if (count == null) {
1028 count = Long.valueOf(0);
1029 }
1030
1031 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_U_C_C,
1032 finderArgs, count);
1033
1034 closeSession(session);
1035 }
1036 }
1037
1038 return count.intValue();
1039 }
1040
1041 public int countAll() throws SystemException {
1042 Object[] finderArgs = new Object[0];
1043
1044 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1045 finderArgs, this);
1046
1047 if (count == null) {
1048 Session session = null;
1049
1050 try {
1051 session = openSession();
1052
1053 Query q = session.createQuery(
1054 "SELECT COUNT(ratingsEntry) FROM RatingsEntry ratingsEntry");
1055
1056 count = (Long)q.uniqueResult();
1057 }
1058 catch (Exception e) {
1059 throw processException(e);
1060 }
1061 finally {
1062 if (count == null) {
1063 count = Long.valueOf(0);
1064 }
1065
1066 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1067 count);
1068
1069 closeSession(session);
1070 }
1071 }
1072
1073 return count.intValue();
1074 }
1075
1076 public void afterPropertiesSet() {
1077 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1078 com.liferay.portal.util.PropsUtil.get(
1079 "value.object.listener.com.liferay.portlet.ratings.model.RatingsEntry")));
1080
1081 if (listenerClassNames.length > 0) {
1082 try {
1083 List<ModelListener<RatingsEntry>> listenersList = new ArrayList<ModelListener<RatingsEntry>>();
1084
1085 for (String listenerClassName : listenerClassNames) {
1086 listenersList.add((ModelListener<RatingsEntry>)Class.forName(
1087 listenerClassName).newInstance());
1088 }
1089
1090 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1091 }
1092 catch (Exception e) {
1093 _log.error(e);
1094 }
1095 }
1096 }
1097
1098 @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence.impl")
1099 protected com.liferay.portlet.ratings.service.persistence.RatingsEntryPersistence ratingsEntryPersistence;
1100 @BeanReference(name = "com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence.impl")
1101 protected com.liferay.portlet.ratings.service.persistence.RatingsStatsPersistence ratingsStatsPersistence;
1102 @BeanReference(name = "com.liferay.portal.service.persistence.UserPersistence.impl")
1103 protected com.liferay.portal.service.persistence.UserPersistence userPersistence;
1104 @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence.impl")
1105 protected com.liferay.portlet.blogs.service.persistence.BlogsEntryPersistence blogsEntryPersistence;
1106 @BeanReference(name = "com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence.impl")
1107 protected com.liferay.portlet.blogs.service.persistence.BlogsStatsUserPersistence blogsStatsUserPersistence;
1108 private static Log _log = LogFactoryUtil.getLog(RatingsEntryPersistenceImpl.class);
1109}