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