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