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