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