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