1
22
23 package com.liferay.portlet.messageboards.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.messageboards.NoSuchStatsUserException;
44 import com.liferay.portlet.messageboards.model.MBStatsUser;
45 import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
46 import com.liferay.portlet.messageboards.model.impl.MBStatsUserModelImpl;
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 MBStatsUserPersistenceImpl extends BasePersistenceImpl
60 implements MBStatsUserPersistence {
61 public MBStatsUser create(long statsUserId) {
62 MBStatsUser mbStatsUser = new MBStatsUserImpl();
63
64 mbStatsUser.setNew(true);
65 mbStatsUser.setPrimaryKey(statsUserId);
66
67 return mbStatsUser;
68 }
69
70 public MBStatsUser remove(long statsUserId)
71 throws NoSuchStatsUserException, SystemException {
72 Session session = null;
73
74 try {
75 session = openSession();
76
77 MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
78 new Long(statsUserId));
79
80 if (mbStatsUser == null) {
81 if (_log.isWarnEnabled()) {
82 _log.warn("No MBStatsUser exists with the primary key " +
83 statsUserId);
84 }
85
86 throw new NoSuchStatsUserException(
87 "No MBStatsUser exists with the primary key " +
88 statsUserId);
89 }
90
91 return remove(mbStatsUser);
92 }
93 catch (NoSuchStatsUserException nsee) {
94 throw nsee;
95 }
96 catch (Exception e) {
97 throw processException(e);
98 }
99 finally {
100 closeSession(session);
101 }
102 }
103
104 public MBStatsUser remove(MBStatsUser mbStatsUser)
105 throws SystemException {
106 for (ModelListener listener : listeners) {
107 listener.onBeforeRemove(mbStatsUser);
108 }
109
110 mbStatsUser = removeImpl(mbStatsUser);
111
112 for (ModelListener listener : listeners) {
113 listener.onAfterRemove(mbStatsUser);
114 }
115
116 return mbStatsUser;
117 }
118
119 protected MBStatsUser removeImpl(MBStatsUser mbStatsUser)
120 throws SystemException {
121 Session session = null;
122
123 try {
124 session = openSession();
125
126 if (BatchSessionUtil.isEnabled()) {
127 Object staleObject = session.get(MBStatsUserImpl.class,
128 mbStatsUser.getPrimaryKeyObj());
129
130 if (staleObject != null) {
131 session.evict(staleObject);
132 }
133 }
134
135 session.delete(mbStatsUser);
136
137 session.flush();
138
139 return mbStatsUser;
140 }
141 catch (Exception e) {
142 throw processException(e);
143 }
144 finally {
145 closeSession(session);
146
147 FinderCacheUtil.clearCache(MBStatsUser.class.getName());
148 }
149 }
150
151
154 public MBStatsUser update(MBStatsUser mbStatsUser)
155 throws SystemException {
156 if (_log.isWarnEnabled()) {
157 _log.warn(
158 "Using the deprecated update(MBStatsUser mbStatsUser) method. Use update(MBStatsUser mbStatsUser, boolean merge) instead.");
159 }
160
161 return update(mbStatsUser, false);
162 }
163
164
177 public MBStatsUser update(MBStatsUser mbStatsUser, boolean merge)
178 throws SystemException {
179 boolean isNew = mbStatsUser.isNew();
180
181 for (ModelListener listener : listeners) {
182 if (isNew) {
183 listener.onBeforeCreate(mbStatsUser);
184 }
185 else {
186 listener.onBeforeUpdate(mbStatsUser);
187 }
188 }
189
190 mbStatsUser = updateImpl(mbStatsUser, merge);
191
192 for (ModelListener listener : listeners) {
193 if (isNew) {
194 listener.onAfterCreate(mbStatsUser);
195 }
196 else {
197 listener.onAfterUpdate(mbStatsUser);
198 }
199 }
200
201 return mbStatsUser;
202 }
203
204 public MBStatsUser updateImpl(
205 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser,
206 boolean merge) throws SystemException {
207 Session session = null;
208
209 try {
210 session = openSession();
211
212 BatchSessionUtil.update(session, mbStatsUser, merge);
213
214 mbStatsUser.setNew(false);
215
216 return mbStatsUser;
217 }
218 catch (Exception e) {
219 throw processException(e);
220 }
221 finally {
222 closeSession(session);
223
224 FinderCacheUtil.clearCache(MBStatsUser.class.getName());
225 }
226 }
227
228 public MBStatsUser findByPrimaryKey(long statsUserId)
229 throws NoSuchStatsUserException, SystemException {
230 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
231
232 if (mbStatsUser == null) {
233 if (_log.isWarnEnabled()) {
234 _log.warn("No MBStatsUser exists with the primary key " +
235 statsUserId);
236 }
237
238 throw new NoSuchStatsUserException(
239 "No MBStatsUser exists with the primary key " + statsUserId);
240 }
241
242 return mbStatsUser;
243 }
244
245 public MBStatsUser fetchByPrimaryKey(long statsUserId)
246 throws SystemException {
247 Session session = null;
248
249 try {
250 session = openSession();
251
252 return (MBStatsUser)session.get(MBStatsUserImpl.class,
253 new Long(statsUserId));
254 }
255 catch (Exception e) {
256 throw processException(e);
257 }
258 finally {
259 closeSession(session);
260 }
261 }
262
263 public List<MBStatsUser> findByGroupId(long groupId)
264 throws SystemException {
265 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
266 String finderClassName = MBStatsUser.class.getName();
267 String finderMethodName = "findByGroupId";
268 String[] finderParams = new String[] { Long.class.getName() };
269 Object[] finderArgs = new Object[] { new Long(groupId) };
270
271 Object result = null;
272
273 if (finderClassNameCacheEnabled) {
274 result = FinderCacheUtil.getResult(finderClassName,
275 finderMethodName, finderParams, finderArgs, this);
276 }
277
278 if (result == null) {
279 Session session = null;
280
281 try {
282 session = openSession();
283
284 StringBuilder query = new StringBuilder();
285
286 query.append(
287 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
288
289 query.append("groupId = ?");
290
291 query.append(" ");
292
293 query.append("ORDER BY ");
294
295 query.append("messageCount DESC");
296
297 Query q = session.createQuery(query.toString());
298
299 QueryPos qPos = QueryPos.getInstance(q);
300
301 qPos.add(groupId);
302
303 List<MBStatsUser> list = q.list();
304
305 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
306 finderClassName, finderMethodName, finderParams,
307 finderArgs, list);
308
309 return list;
310 }
311 catch (Exception e) {
312 throw processException(e);
313 }
314 finally {
315 closeSession(session);
316 }
317 }
318 else {
319 return (List<MBStatsUser>)result;
320 }
321 }
322
323 public List<MBStatsUser> findByGroupId(long groupId, int start, int end)
324 throws SystemException {
325 return findByGroupId(groupId, start, end, null);
326 }
327
328 public List<MBStatsUser> findByGroupId(long groupId, int start, int end,
329 OrderByComparator obc) throws SystemException {
330 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
331 String finderClassName = MBStatsUser.class.getName();
332 String finderMethodName = "findByGroupId";
333 String[] finderParams = new String[] {
334 Long.class.getName(),
335
336 "java.lang.Integer", "java.lang.Integer",
337 "com.liferay.portal.kernel.util.OrderByComparator"
338 };
339 Object[] finderArgs = new Object[] {
340 new Long(groupId),
341
342 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
343 };
344
345 Object result = null;
346
347 if (finderClassNameCacheEnabled) {
348 result = FinderCacheUtil.getResult(finderClassName,
349 finderMethodName, finderParams, finderArgs, this);
350 }
351
352 if (result == null) {
353 Session session = null;
354
355 try {
356 session = openSession();
357
358 StringBuilder query = new StringBuilder();
359
360 query.append(
361 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
362
363 query.append("groupId = ?");
364
365 query.append(" ");
366
367 if (obc != null) {
368 query.append("ORDER BY ");
369 query.append(obc.getOrderBy());
370 }
371
372 else {
373 query.append("ORDER BY ");
374
375 query.append("messageCount DESC");
376 }
377
378 Query q = session.createQuery(query.toString());
379
380 QueryPos qPos = QueryPos.getInstance(q);
381
382 qPos.add(groupId);
383
384 List<MBStatsUser> list = (List<MBStatsUser>)QueryUtil.list(q,
385 getDialect(), start, end);
386
387 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
388 finderClassName, finderMethodName, finderParams,
389 finderArgs, list);
390
391 return list;
392 }
393 catch (Exception e) {
394 throw processException(e);
395 }
396 finally {
397 closeSession(session);
398 }
399 }
400 else {
401 return (List<MBStatsUser>)result;
402 }
403 }
404
405 public MBStatsUser findByGroupId_First(long groupId, OrderByComparator obc)
406 throws NoSuchStatsUserException, SystemException {
407 List<MBStatsUser> list = findByGroupId(groupId, 0, 1, obc);
408
409 if (list.size() == 0) {
410 StringBuilder msg = new StringBuilder();
411
412 msg.append("No MBStatsUser exists with the key {");
413
414 msg.append("groupId=" + groupId);
415
416 msg.append(StringPool.CLOSE_CURLY_BRACE);
417
418 throw new NoSuchStatsUserException(msg.toString());
419 }
420 else {
421 return list.get(0);
422 }
423 }
424
425 public MBStatsUser findByGroupId_Last(long groupId, OrderByComparator obc)
426 throws NoSuchStatsUserException, SystemException {
427 int count = countByGroupId(groupId);
428
429 List<MBStatsUser> list = findByGroupId(groupId, count - 1, count, obc);
430
431 if (list.size() == 0) {
432 StringBuilder msg = new StringBuilder();
433
434 msg.append("No MBStatsUser exists with the key {");
435
436 msg.append("groupId=" + groupId);
437
438 msg.append(StringPool.CLOSE_CURLY_BRACE);
439
440 throw new NoSuchStatsUserException(msg.toString());
441 }
442 else {
443 return list.get(0);
444 }
445 }
446
447 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
448 long groupId, OrderByComparator obc)
449 throws NoSuchStatsUserException, SystemException {
450 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
451
452 int count = countByGroupId(groupId);
453
454 Session session = null;
455
456 try {
457 session = openSession();
458
459 StringBuilder query = new StringBuilder();
460
461 query.append(
462 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
463
464 query.append("groupId = ?");
465
466 query.append(" ");
467
468 if (obc != null) {
469 query.append("ORDER BY ");
470 query.append(obc.getOrderBy());
471 }
472
473 else {
474 query.append("ORDER BY ");
475
476 query.append("messageCount DESC");
477 }
478
479 Query q = session.createQuery(query.toString());
480
481 QueryPos qPos = QueryPos.getInstance(q);
482
483 qPos.add(groupId);
484
485 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
486 mbStatsUser);
487
488 MBStatsUser[] array = new MBStatsUserImpl[3];
489
490 array[0] = (MBStatsUser)objArray[0];
491 array[1] = (MBStatsUser)objArray[1];
492 array[2] = (MBStatsUser)objArray[2];
493
494 return array;
495 }
496 catch (Exception e) {
497 throw processException(e);
498 }
499 finally {
500 closeSession(session);
501 }
502 }
503
504 public List<MBStatsUser> findByUserId(long userId)
505 throws SystemException {
506 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
507 String finderClassName = MBStatsUser.class.getName();
508 String finderMethodName = "findByUserId";
509 String[] finderParams = new String[] { Long.class.getName() };
510 Object[] finderArgs = new Object[] { new Long(userId) };
511
512 Object result = null;
513
514 if (finderClassNameCacheEnabled) {
515 result = FinderCacheUtil.getResult(finderClassName,
516 finderMethodName, finderParams, finderArgs, this);
517 }
518
519 if (result == null) {
520 Session session = null;
521
522 try {
523 session = openSession();
524
525 StringBuilder query = new StringBuilder();
526
527 query.append(
528 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
529
530 query.append("userId = ?");
531
532 query.append(" ");
533
534 query.append("ORDER BY ");
535
536 query.append("messageCount DESC");
537
538 Query q = session.createQuery(query.toString());
539
540 QueryPos qPos = QueryPos.getInstance(q);
541
542 qPos.add(userId);
543
544 List<MBStatsUser> list = q.list();
545
546 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
547 finderClassName, finderMethodName, finderParams,
548 finderArgs, list);
549
550 return list;
551 }
552 catch (Exception e) {
553 throw processException(e);
554 }
555 finally {
556 closeSession(session);
557 }
558 }
559 else {
560 return (List<MBStatsUser>)result;
561 }
562 }
563
564 public List<MBStatsUser> findByUserId(long userId, int start, int end)
565 throws SystemException {
566 return findByUserId(userId, start, end, null);
567 }
568
569 public List<MBStatsUser> findByUserId(long userId, int start, int end,
570 OrderByComparator obc) throws SystemException {
571 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
572 String finderClassName = MBStatsUser.class.getName();
573 String finderMethodName = "findByUserId";
574 String[] finderParams = new String[] {
575 Long.class.getName(),
576
577 "java.lang.Integer", "java.lang.Integer",
578 "com.liferay.portal.kernel.util.OrderByComparator"
579 };
580 Object[] finderArgs = new Object[] {
581 new Long(userId),
582
583 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
584 };
585
586 Object result = null;
587
588 if (finderClassNameCacheEnabled) {
589 result = FinderCacheUtil.getResult(finderClassName,
590 finderMethodName, finderParams, finderArgs, this);
591 }
592
593 if (result == null) {
594 Session session = null;
595
596 try {
597 session = openSession();
598
599 StringBuilder query = new StringBuilder();
600
601 query.append(
602 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
603
604 query.append("userId = ?");
605
606 query.append(" ");
607
608 if (obc != null) {
609 query.append("ORDER BY ");
610 query.append(obc.getOrderBy());
611 }
612
613 else {
614 query.append("ORDER BY ");
615
616 query.append("messageCount DESC");
617 }
618
619 Query q = session.createQuery(query.toString());
620
621 QueryPos qPos = QueryPos.getInstance(q);
622
623 qPos.add(userId);
624
625 List<MBStatsUser> list = (List<MBStatsUser>)QueryUtil.list(q,
626 getDialect(), start, end);
627
628 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
629 finderClassName, finderMethodName, finderParams,
630 finderArgs, list);
631
632 return list;
633 }
634 catch (Exception e) {
635 throw processException(e);
636 }
637 finally {
638 closeSession(session);
639 }
640 }
641 else {
642 return (List<MBStatsUser>)result;
643 }
644 }
645
646 public MBStatsUser findByUserId_First(long userId, OrderByComparator obc)
647 throws NoSuchStatsUserException, SystemException {
648 List<MBStatsUser> list = findByUserId(userId, 0, 1, obc);
649
650 if (list.size() == 0) {
651 StringBuilder msg = new StringBuilder();
652
653 msg.append("No MBStatsUser exists with the key {");
654
655 msg.append("userId=" + userId);
656
657 msg.append(StringPool.CLOSE_CURLY_BRACE);
658
659 throw new NoSuchStatsUserException(msg.toString());
660 }
661 else {
662 return list.get(0);
663 }
664 }
665
666 public MBStatsUser findByUserId_Last(long userId, OrderByComparator obc)
667 throws NoSuchStatsUserException, SystemException {
668 int count = countByUserId(userId);
669
670 List<MBStatsUser> list = findByUserId(userId, count - 1, count, obc);
671
672 if (list.size() == 0) {
673 StringBuilder msg = new StringBuilder();
674
675 msg.append("No MBStatsUser exists with the key {");
676
677 msg.append("userId=" + userId);
678
679 msg.append(StringPool.CLOSE_CURLY_BRACE);
680
681 throw new NoSuchStatsUserException(msg.toString());
682 }
683 else {
684 return list.get(0);
685 }
686 }
687
688 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
689 long userId, OrderByComparator obc)
690 throws NoSuchStatsUserException, SystemException {
691 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
692
693 int count = countByUserId(userId);
694
695 Session session = null;
696
697 try {
698 session = openSession();
699
700 StringBuilder query = new StringBuilder();
701
702 query.append(
703 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
704
705 query.append("userId = ?");
706
707 query.append(" ");
708
709 if (obc != null) {
710 query.append("ORDER BY ");
711 query.append(obc.getOrderBy());
712 }
713
714 else {
715 query.append("ORDER BY ");
716
717 query.append("messageCount DESC");
718 }
719
720 Query q = session.createQuery(query.toString());
721
722 QueryPos qPos = QueryPos.getInstance(q);
723
724 qPos.add(userId);
725
726 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
727 mbStatsUser);
728
729 MBStatsUser[] array = new MBStatsUserImpl[3];
730
731 array[0] = (MBStatsUser)objArray[0];
732 array[1] = (MBStatsUser)objArray[1];
733 array[2] = (MBStatsUser)objArray[2];
734
735 return array;
736 }
737 catch (Exception e) {
738 throw processException(e);
739 }
740 finally {
741 closeSession(session);
742 }
743 }
744
745 public MBStatsUser findByG_U(long groupId, long userId)
746 throws NoSuchStatsUserException, SystemException {
747 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
748
749 if (mbStatsUser == null) {
750 StringBuilder msg = new StringBuilder();
751
752 msg.append("No MBStatsUser exists with the key {");
753
754 msg.append("groupId=" + groupId);
755
756 msg.append(", ");
757 msg.append("userId=" + userId);
758
759 msg.append(StringPool.CLOSE_CURLY_BRACE);
760
761 if (_log.isWarnEnabled()) {
762 _log.warn(msg.toString());
763 }
764
765 throw new NoSuchStatsUserException(msg.toString());
766 }
767
768 return mbStatsUser;
769 }
770
771 public MBStatsUser fetchByG_U(long groupId, long userId)
772 throws SystemException {
773 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
774 String finderClassName = MBStatsUser.class.getName();
775 String finderMethodName = "fetchByG_U";
776 String[] finderParams = new String[] {
777 Long.class.getName(), Long.class.getName()
778 };
779 Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
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(
797 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
798
799 query.append("groupId = ?");
800
801 query.append(" AND ");
802
803 query.append("userId = ?");
804
805 query.append(" ");
806
807 query.append("ORDER BY ");
808
809 query.append("messageCount DESC");
810
811 Query q = session.createQuery(query.toString());
812
813 QueryPos qPos = QueryPos.getInstance(q);
814
815 qPos.add(groupId);
816
817 qPos.add(userId);
818
819 List<MBStatsUser> list = q.list();
820
821 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
822 finderClassName, finderMethodName, finderParams,
823 finderArgs, list);
824
825 if (list.size() == 0) {
826 return null;
827 }
828 else {
829 return list.get(0);
830 }
831 }
832 catch (Exception e) {
833 throw processException(e);
834 }
835 finally {
836 closeSession(session);
837 }
838 }
839 else {
840 List<MBStatsUser> list = (List<MBStatsUser>)result;
841
842 if (list.size() == 0) {
843 return null;
844 }
845 else {
846 return list.get(0);
847 }
848 }
849 }
850
851 public List<MBStatsUser> findByG_M(long groupId, int messageCount)
852 throws SystemException {
853 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
854 String finderClassName = MBStatsUser.class.getName();
855 String finderMethodName = "findByG_M";
856 String[] finderParams = new String[] {
857 Long.class.getName(), Integer.class.getName()
858 };
859 Object[] finderArgs = new Object[] {
860 new Long(groupId), new Integer(messageCount)
861 };
862
863 Object result = null;
864
865 if (finderClassNameCacheEnabled) {
866 result = FinderCacheUtil.getResult(finderClassName,
867 finderMethodName, finderParams, finderArgs, this);
868 }
869
870 if (result == null) {
871 Session session = null;
872
873 try {
874 session = openSession();
875
876 StringBuilder query = new StringBuilder();
877
878 query.append(
879 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
880
881 query.append("groupId = ?");
882
883 query.append(" AND ");
884
885 query.append("messageCount != ?");
886
887 query.append(" ");
888
889 query.append("ORDER BY ");
890
891 query.append("messageCount DESC");
892
893 Query q = session.createQuery(query.toString());
894
895 QueryPos qPos = QueryPos.getInstance(q);
896
897 qPos.add(groupId);
898
899 qPos.add(messageCount);
900
901 List<MBStatsUser> list = q.list();
902
903 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
904 finderClassName, finderMethodName, finderParams,
905 finderArgs, list);
906
907 return list;
908 }
909 catch (Exception e) {
910 throw processException(e);
911 }
912 finally {
913 closeSession(session);
914 }
915 }
916 else {
917 return (List<MBStatsUser>)result;
918 }
919 }
920
921 public List<MBStatsUser> findByG_M(long groupId, int messageCount,
922 int start, int end) throws SystemException {
923 return findByG_M(groupId, messageCount, start, end, null);
924 }
925
926 public List<MBStatsUser> findByG_M(long groupId, int messageCount,
927 int start, int end, OrderByComparator obc) throws SystemException {
928 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
929 String finderClassName = MBStatsUser.class.getName();
930 String finderMethodName = "findByG_M";
931 String[] finderParams = new String[] {
932 Long.class.getName(), Integer.class.getName(),
933
934 "java.lang.Integer", "java.lang.Integer",
935 "com.liferay.portal.kernel.util.OrderByComparator"
936 };
937 Object[] finderArgs = new Object[] {
938 new Long(groupId), new Integer(messageCount),
939
940 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
941 };
942
943 Object result = null;
944
945 if (finderClassNameCacheEnabled) {
946 result = FinderCacheUtil.getResult(finderClassName,
947 finderMethodName, finderParams, finderArgs, this);
948 }
949
950 if (result == null) {
951 Session session = null;
952
953 try {
954 session = openSession();
955
956 StringBuilder query = new StringBuilder();
957
958 query.append(
959 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
960
961 query.append("groupId = ?");
962
963 query.append(" AND ");
964
965 query.append("messageCount != ?");
966
967 query.append(" ");
968
969 if (obc != null) {
970 query.append("ORDER BY ");
971 query.append(obc.getOrderBy());
972 }
973
974 else {
975 query.append("ORDER BY ");
976
977 query.append("messageCount DESC");
978 }
979
980 Query q = session.createQuery(query.toString());
981
982 QueryPos qPos = QueryPos.getInstance(q);
983
984 qPos.add(groupId);
985
986 qPos.add(messageCount);
987
988 List<MBStatsUser> list = (List<MBStatsUser>)QueryUtil.list(q,
989 getDialect(), start, end);
990
991 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
992 finderClassName, finderMethodName, finderParams,
993 finderArgs, list);
994
995 return list;
996 }
997 catch (Exception e) {
998 throw processException(e);
999 }
1000 finally {
1001 closeSession(session);
1002 }
1003 }
1004 else {
1005 return (List<MBStatsUser>)result;
1006 }
1007 }
1008
1009 public MBStatsUser findByG_M_First(long groupId, int messageCount,
1010 OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1011 List<MBStatsUser> list = findByG_M(groupId, messageCount, 0, 1, obc);
1012
1013 if (list.size() == 0) {
1014 StringBuilder msg = new StringBuilder();
1015
1016 msg.append("No MBStatsUser exists with the key {");
1017
1018 msg.append("groupId=" + groupId);
1019
1020 msg.append(", ");
1021 msg.append("messageCount=" + messageCount);
1022
1023 msg.append(StringPool.CLOSE_CURLY_BRACE);
1024
1025 throw new NoSuchStatsUserException(msg.toString());
1026 }
1027 else {
1028 return list.get(0);
1029 }
1030 }
1031
1032 public MBStatsUser findByG_M_Last(long groupId, int messageCount,
1033 OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
1034 int count = countByG_M(groupId, messageCount);
1035
1036 List<MBStatsUser> list = findByG_M(groupId, messageCount, count - 1,
1037 count, obc);
1038
1039 if (list.size() == 0) {
1040 StringBuilder msg = new StringBuilder();
1041
1042 msg.append("No MBStatsUser exists with the key {");
1043
1044 msg.append("groupId=" + groupId);
1045
1046 msg.append(", ");
1047 msg.append("messageCount=" + messageCount);
1048
1049 msg.append(StringPool.CLOSE_CURLY_BRACE);
1050
1051 throw new NoSuchStatsUserException(msg.toString());
1052 }
1053 else {
1054 return list.get(0);
1055 }
1056 }
1057
1058 public MBStatsUser[] findByG_M_PrevAndNext(long statsUserId, long groupId,
1059 int messageCount, OrderByComparator obc)
1060 throws NoSuchStatsUserException, SystemException {
1061 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
1062
1063 int count = countByG_M(groupId, messageCount);
1064
1065 Session session = null;
1066
1067 try {
1068 session = openSession();
1069
1070 StringBuilder query = new StringBuilder();
1071
1072 query.append(
1073 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1074
1075 query.append("groupId = ?");
1076
1077 query.append(" AND ");
1078
1079 query.append("messageCount != ?");
1080
1081 query.append(" ");
1082
1083 if (obc != null) {
1084 query.append("ORDER BY ");
1085 query.append(obc.getOrderBy());
1086 }
1087
1088 else {
1089 query.append("ORDER BY ");
1090
1091 query.append("messageCount DESC");
1092 }
1093
1094 Query q = session.createQuery(query.toString());
1095
1096 QueryPos qPos = QueryPos.getInstance(q);
1097
1098 qPos.add(groupId);
1099
1100 qPos.add(messageCount);
1101
1102 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
1103 mbStatsUser);
1104
1105 MBStatsUser[] array = new MBStatsUserImpl[3];
1106
1107 array[0] = (MBStatsUser)objArray[0];
1108 array[1] = (MBStatsUser)objArray[1];
1109 array[2] = (MBStatsUser)objArray[2];
1110
1111 return array;
1112 }
1113 catch (Exception e) {
1114 throw processException(e);
1115 }
1116 finally {
1117 closeSession(session);
1118 }
1119 }
1120
1121 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery)
1122 throws SystemException {
1123 Session session = null;
1124
1125 try {
1126 session = openSession();
1127
1128 dynamicQuery.compile(session);
1129
1130 return dynamicQuery.list();
1131 }
1132 catch (Exception e) {
1133 throw processException(e);
1134 }
1135 finally {
1136 closeSession(session);
1137 }
1138 }
1139
1140 public List<Object> findWithDynamicQuery(DynamicQuery dynamicQuery,
1141 int start, int end) throws SystemException {
1142 Session session = null;
1143
1144 try {
1145 session = openSession();
1146
1147 dynamicQuery.setLimit(start, end);
1148
1149 dynamicQuery.compile(session);
1150
1151 return dynamicQuery.list();
1152 }
1153 catch (Exception e) {
1154 throw processException(e);
1155 }
1156 finally {
1157 closeSession(session);
1158 }
1159 }
1160
1161 public List<MBStatsUser> findAll() throws SystemException {
1162 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1163 }
1164
1165 public List<MBStatsUser> findAll(int start, int end)
1166 throws SystemException {
1167 return findAll(start, end, null);
1168 }
1169
1170 public List<MBStatsUser> findAll(int start, int end, OrderByComparator obc)
1171 throws SystemException {
1172 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1173 String finderClassName = MBStatsUser.class.getName();
1174 String finderMethodName = "findAll";
1175 String[] finderParams = new String[] {
1176 "java.lang.Integer", "java.lang.Integer",
1177 "com.liferay.portal.kernel.util.OrderByComparator"
1178 };
1179 Object[] finderArgs = new Object[] {
1180 String.valueOf(start), String.valueOf(end), String.valueOf(obc)
1181 };
1182
1183 Object result = null;
1184
1185 if (finderClassNameCacheEnabled) {
1186 result = FinderCacheUtil.getResult(finderClassName,
1187 finderMethodName, finderParams, finderArgs, this);
1188 }
1189
1190 if (result == null) {
1191 Session session = null;
1192
1193 try {
1194 session = openSession();
1195
1196 StringBuilder query = new StringBuilder();
1197
1198 query.append(
1199 "FROM com.liferay.portlet.messageboards.model.MBStatsUser ");
1200
1201 if (obc != null) {
1202 query.append("ORDER BY ");
1203 query.append(obc.getOrderBy());
1204 }
1205
1206 else {
1207 query.append("ORDER BY ");
1208
1209 query.append("messageCount DESC");
1210 }
1211
1212 Query q = session.createQuery(query.toString());
1213
1214 List<MBStatsUser> list = null;
1215
1216 if (obc == null) {
1217 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1218 start, end, false);
1219
1220 Collections.sort(list);
1221 }
1222 else {
1223 list = (List<MBStatsUser>)QueryUtil.list(q, getDialect(),
1224 start, end);
1225 }
1226
1227 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1228 finderClassName, finderMethodName, finderParams,
1229 finderArgs, list);
1230
1231 return list;
1232 }
1233 catch (Exception e) {
1234 throw processException(e);
1235 }
1236 finally {
1237 closeSession(session);
1238 }
1239 }
1240 else {
1241 return (List<MBStatsUser>)result;
1242 }
1243 }
1244
1245 public void removeByGroupId(long groupId) throws SystemException {
1246 for (MBStatsUser mbStatsUser : findByGroupId(groupId)) {
1247 remove(mbStatsUser);
1248 }
1249 }
1250
1251 public void removeByUserId(long userId) throws SystemException {
1252 for (MBStatsUser mbStatsUser : findByUserId(userId)) {
1253 remove(mbStatsUser);
1254 }
1255 }
1256
1257 public void removeByG_U(long groupId, long userId)
1258 throws NoSuchStatsUserException, SystemException {
1259 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
1260
1261 remove(mbStatsUser);
1262 }
1263
1264 public void removeByG_M(long groupId, int messageCount)
1265 throws SystemException {
1266 for (MBStatsUser mbStatsUser : findByG_M(groupId, messageCount)) {
1267 remove(mbStatsUser);
1268 }
1269 }
1270
1271 public void removeAll() throws SystemException {
1272 for (MBStatsUser mbStatsUser : findAll()) {
1273 remove(mbStatsUser);
1274 }
1275 }
1276
1277 public int countByGroupId(long groupId) throws SystemException {
1278 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1279 String finderClassName = MBStatsUser.class.getName();
1280 String finderMethodName = "countByGroupId";
1281 String[] finderParams = new String[] { Long.class.getName() };
1282 Object[] finderArgs = new Object[] { new Long(groupId) };
1283
1284 Object result = null;
1285
1286 if (finderClassNameCacheEnabled) {
1287 result = FinderCacheUtil.getResult(finderClassName,
1288 finderMethodName, finderParams, finderArgs, this);
1289 }
1290
1291 if (result == null) {
1292 Session session = null;
1293
1294 try {
1295 session = openSession();
1296
1297 StringBuilder query = new StringBuilder();
1298
1299 query.append("SELECT COUNT(*) ");
1300 query.append(
1301 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1302
1303 query.append("groupId = ?");
1304
1305 query.append(" ");
1306
1307 Query q = session.createQuery(query.toString());
1308
1309 QueryPos qPos = QueryPos.getInstance(q);
1310
1311 qPos.add(groupId);
1312
1313 Long count = null;
1314
1315 Iterator<Long> itr = q.list().iterator();
1316
1317 if (itr.hasNext()) {
1318 count = itr.next();
1319 }
1320
1321 if (count == null) {
1322 count = new Long(0);
1323 }
1324
1325 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1326 finderClassName, finderMethodName, finderParams,
1327 finderArgs, count);
1328
1329 return count.intValue();
1330 }
1331 catch (Exception e) {
1332 throw processException(e);
1333 }
1334 finally {
1335 closeSession(session);
1336 }
1337 }
1338 else {
1339 return ((Long)result).intValue();
1340 }
1341 }
1342
1343 public int countByUserId(long userId) throws SystemException {
1344 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1345 String finderClassName = MBStatsUser.class.getName();
1346 String finderMethodName = "countByUserId";
1347 String[] finderParams = new String[] { Long.class.getName() };
1348 Object[] finderArgs = new Object[] { new Long(userId) };
1349
1350 Object result = null;
1351
1352 if (finderClassNameCacheEnabled) {
1353 result = FinderCacheUtil.getResult(finderClassName,
1354 finderMethodName, finderParams, finderArgs, this);
1355 }
1356
1357 if (result == null) {
1358 Session session = null;
1359
1360 try {
1361 session = openSession();
1362
1363 StringBuilder query = new StringBuilder();
1364
1365 query.append("SELECT COUNT(*) ");
1366 query.append(
1367 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1368
1369 query.append("userId = ?");
1370
1371 query.append(" ");
1372
1373 Query q = session.createQuery(query.toString());
1374
1375 QueryPos qPos = QueryPos.getInstance(q);
1376
1377 qPos.add(userId);
1378
1379 Long count = null;
1380
1381 Iterator<Long> itr = q.list().iterator();
1382
1383 if (itr.hasNext()) {
1384 count = itr.next();
1385 }
1386
1387 if (count == null) {
1388 count = new Long(0);
1389 }
1390
1391 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1392 finderClassName, finderMethodName, finderParams,
1393 finderArgs, count);
1394
1395 return count.intValue();
1396 }
1397 catch (Exception e) {
1398 throw processException(e);
1399 }
1400 finally {
1401 closeSession(session);
1402 }
1403 }
1404 else {
1405 return ((Long)result).intValue();
1406 }
1407 }
1408
1409 public int countByG_U(long groupId, long userId) throws SystemException {
1410 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1411 String finderClassName = MBStatsUser.class.getName();
1412 String finderMethodName = "countByG_U";
1413 String[] finderParams = new String[] {
1414 Long.class.getName(), Long.class.getName()
1415 };
1416 Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1417
1418 Object result = null;
1419
1420 if (finderClassNameCacheEnabled) {
1421 result = FinderCacheUtil.getResult(finderClassName,
1422 finderMethodName, finderParams, finderArgs, this);
1423 }
1424
1425 if (result == null) {
1426 Session session = null;
1427
1428 try {
1429 session = openSession();
1430
1431 StringBuilder query = new StringBuilder();
1432
1433 query.append("SELECT COUNT(*) ");
1434 query.append(
1435 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1436
1437 query.append("groupId = ?");
1438
1439 query.append(" AND ");
1440
1441 query.append("userId = ?");
1442
1443 query.append(" ");
1444
1445 Query q = session.createQuery(query.toString());
1446
1447 QueryPos qPos = QueryPos.getInstance(q);
1448
1449 qPos.add(groupId);
1450
1451 qPos.add(userId);
1452
1453 Long count = null;
1454
1455 Iterator<Long> itr = q.list().iterator();
1456
1457 if (itr.hasNext()) {
1458 count = itr.next();
1459 }
1460
1461 if (count == null) {
1462 count = new Long(0);
1463 }
1464
1465 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1466 finderClassName, finderMethodName, finderParams,
1467 finderArgs, count);
1468
1469 return count.intValue();
1470 }
1471 catch (Exception e) {
1472 throw processException(e);
1473 }
1474 finally {
1475 closeSession(session);
1476 }
1477 }
1478 else {
1479 return ((Long)result).intValue();
1480 }
1481 }
1482
1483 public int countByG_M(long groupId, int messageCount)
1484 throws SystemException {
1485 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1486 String finderClassName = MBStatsUser.class.getName();
1487 String finderMethodName = "countByG_M";
1488 String[] finderParams = new String[] {
1489 Long.class.getName(), Integer.class.getName()
1490 };
1491 Object[] finderArgs = new Object[] {
1492 new Long(groupId), new Integer(messageCount)
1493 };
1494
1495 Object result = null;
1496
1497 if (finderClassNameCacheEnabled) {
1498 result = FinderCacheUtil.getResult(finderClassName,
1499 finderMethodName, finderParams, finderArgs, this);
1500 }
1501
1502 if (result == null) {
1503 Session session = null;
1504
1505 try {
1506 session = openSession();
1507
1508 StringBuilder query = new StringBuilder();
1509
1510 query.append("SELECT COUNT(*) ");
1511 query.append(
1512 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1513
1514 query.append("groupId = ?");
1515
1516 query.append(" AND ");
1517
1518 query.append("messageCount != ?");
1519
1520 query.append(" ");
1521
1522 Query q = session.createQuery(query.toString());
1523
1524 QueryPos qPos = QueryPos.getInstance(q);
1525
1526 qPos.add(groupId);
1527
1528 qPos.add(messageCount);
1529
1530 Long count = null;
1531
1532 Iterator<Long> itr = q.list().iterator();
1533
1534 if (itr.hasNext()) {
1535 count = itr.next();
1536 }
1537
1538 if (count == null) {
1539 count = new Long(0);
1540 }
1541
1542 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1543 finderClassName, finderMethodName, finderParams,
1544 finderArgs, count);
1545
1546 return count.intValue();
1547 }
1548 catch (Exception e) {
1549 throw processException(e);
1550 }
1551 finally {
1552 closeSession(session);
1553 }
1554 }
1555 else {
1556 return ((Long)result).intValue();
1557 }
1558 }
1559
1560 public int countAll() throws SystemException {
1561 boolean finderClassNameCacheEnabled = MBStatsUserModelImpl.CACHE_ENABLED;
1562 String finderClassName = MBStatsUser.class.getName();
1563 String finderMethodName = "countAll";
1564 String[] finderParams = new String[] { };
1565 Object[] finderArgs = new Object[] { };
1566
1567 Object result = null;
1568
1569 if (finderClassNameCacheEnabled) {
1570 result = FinderCacheUtil.getResult(finderClassName,
1571 finderMethodName, finderParams, finderArgs, this);
1572 }
1573
1574 if (result == null) {
1575 Session session = null;
1576
1577 try {
1578 session = openSession();
1579
1580 Query q = session.createQuery(
1581 "SELECT COUNT(*) FROM com.liferay.portlet.messageboards.model.MBStatsUser");
1582
1583 Long count = null;
1584
1585 Iterator<Long> itr = q.list().iterator();
1586
1587 if (itr.hasNext()) {
1588 count = itr.next();
1589 }
1590
1591 if (count == null) {
1592 count = new Long(0);
1593 }
1594
1595 FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1596 finderClassName, finderMethodName, finderParams,
1597 finderArgs, count);
1598
1599 return count.intValue();
1600 }
1601 catch (Exception e) {
1602 throw processException(e);
1603 }
1604 finally {
1605 closeSession(session);
1606 }
1607 }
1608 else {
1609 return ((Long)result).intValue();
1610 }
1611 }
1612
1613 public void afterPropertiesSet() {
1614 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1615 com.liferay.portal.util.PropsUtil.get(
1616 "value.object.listener.com.liferay.portlet.messageboards.model.MBStatsUser")));
1617
1618 if (listenerClassNames.length > 0) {
1619 try {
1620 List<ModelListener> listenersList = new ArrayList<ModelListener>();
1621
1622 for (String listenerClassName : listenerClassNames) {
1623 listenersList.add((ModelListener)Class.forName(
1624 listenerClassName).newInstance());
1625 }
1626
1627 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1628 }
1629 catch (Exception e) {
1630 _log.error(e);
1631 }
1632 }
1633 }
1634
1635 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBBanPersistence.impl")
1636 protected com.liferay.portlet.messageboards.service.persistence.MBBanPersistence mbBanPersistence;
1637 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence.impl")
1638 protected com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence mbCategoryPersistence;
1639 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence.impl")
1640 protected com.liferay.portlet.messageboards.service.persistence.MBDiscussionPersistence mbDiscussionPersistence;
1641 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMailingListPersistence.impl")
1642 protected com.liferay.portlet.messageboards.service.persistence.MBMailingListPersistence mbMailingListPersistence;
1643 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence.impl")
1644 protected com.liferay.portlet.messageboards.service.persistence.MBMessagePersistence mbMessagePersistence;
1645 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence.impl")
1646 protected com.liferay.portlet.messageboards.service.persistence.MBMessageFlagPersistence mbMessageFlagPersistence;
1647 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence.impl")
1648 protected com.liferay.portlet.messageboards.service.persistence.MBStatsUserPersistence mbStatsUserPersistence;
1649 @BeanReference(name = "com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence.impl")
1650 protected com.liferay.portlet.messageboards.service.persistence.MBThreadPersistence mbThreadPersistence;
1651 private static Log _log = LogFactoryUtil.getLog(MBStatsUserPersistenceImpl.class);
1652}