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