1
22
23 package com.liferay.portlet.messageboards.service.persistence;
24
25 import com.liferay.portal.SystemException;
26 import com.liferay.portal.kernel.dao.DynamicQuery;
27 import com.liferay.portal.kernel.dao.DynamicQueryInitializer;
28 import com.liferay.portal.kernel.util.OrderByComparator;
29 import com.liferay.portal.kernel.util.StringMaker;
30 import com.liferay.portal.kernel.util.StringPool;
31 import com.liferay.portal.service.persistence.BasePersistence;
32 import com.liferay.portal.spring.hibernate.FinderCache;
33 import com.liferay.portal.spring.hibernate.HibernateUtil;
34
35 import com.liferay.portlet.messageboards.NoSuchStatsUserException;
36 import com.liferay.portlet.messageboards.model.MBStatsUser;
37 import com.liferay.portlet.messageboards.model.impl.MBStatsUserImpl;
38
39 import com.liferay.util.dao.hibernate.QueryUtil;
40
41 import org.apache.commons.logging.Log;
42 import org.apache.commons.logging.LogFactory;
43
44 import org.hibernate.Query;
45 import org.hibernate.Session;
46
47 import java.util.Collections;
48 import java.util.Iterator;
49 import java.util.List;
50
51
57 public class MBStatsUserPersistenceImpl extends BasePersistence
58 implements MBStatsUserPersistence {
59 public MBStatsUser create(long statsUserId) {
60 MBStatsUser mbStatsUser = new MBStatsUserImpl();
61 mbStatsUser.setNew(true);
62 mbStatsUser.setPrimaryKey(statsUserId);
63
64 return mbStatsUser;
65 }
66
67 public MBStatsUser remove(long statsUserId)
68 throws NoSuchStatsUserException, SystemException {
69 Session session = null;
70
71 try {
72 session = openSession();
73
74 MBStatsUser mbStatsUser = (MBStatsUser)session.get(MBStatsUserImpl.class,
75 new Long(statsUserId));
76
77 if (mbStatsUser == null) {
78 if (_log.isWarnEnabled()) {
79 _log.warn("No MBStatsUser exists with the primary key " +
80 statsUserId);
81 }
82
83 throw new NoSuchStatsUserException(
84 "No MBStatsUser exists with the primary key " +
85 statsUserId);
86 }
87
88 return remove(mbStatsUser);
89 }
90 catch (NoSuchStatsUserException nsee) {
91 throw nsee;
92 }
93 catch (Exception e) {
94 throw HibernateUtil.processException(e);
95 }
96 finally {
97 closeSession(session);
98 }
99 }
100
101 public MBStatsUser remove(MBStatsUser mbStatsUser)
102 throws SystemException {
103 Session session = null;
104
105 try {
106 session = openSession();
107 session.delete(mbStatsUser);
108 session.flush();
109
110 return mbStatsUser;
111 }
112 catch (Exception e) {
113 throw HibernateUtil.processException(e);
114 }
115 finally {
116 closeSession(session);
117 FinderCache.clearCache(MBStatsUser.class.getName());
118 }
119 }
120
121 public MBStatsUser update(
122 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser)
123 throws SystemException {
124 return update(mbStatsUser, false);
125 }
126
127 public MBStatsUser update(
128 com.liferay.portlet.messageboards.model.MBStatsUser mbStatsUser,
129 boolean merge) throws SystemException {
130 Session session = null;
131
132 try {
133 session = openSession();
134
135 if (merge) {
136 session.merge(mbStatsUser);
137 }
138 else {
139 if (mbStatsUser.isNew()) {
140 session.save(mbStatsUser);
141 }
142 }
143
144 session.flush();
145 mbStatsUser.setNew(false);
146
147 return mbStatsUser;
148 }
149 catch (Exception e) {
150 throw HibernateUtil.processException(e);
151 }
152 finally {
153 closeSession(session);
154 FinderCache.clearCache(MBStatsUser.class.getName());
155 }
156 }
157
158 public MBStatsUser findByPrimaryKey(long statsUserId)
159 throws NoSuchStatsUserException, SystemException {
160 MBStatsUser mbStatsUser = fetchByPrimaryKey(statsUserId);
161
162 if (mbStatsUser == null) {
163 if (_log.isWarnEnabled()) {
164 _log.warn("No MBStatsUser exists with the primary key " +
165 statsUserId);
166 }
167
168 throw new NoSuchStatsUserException(
169 "No MBStatsUser exists with the primary key " + statsUserId);
170 }
171
172 return mbStatsUser;
173 }
174
175 public MBStatsUser fetchByPrimaryKey(long statsUserId)
176 throws SystemException {
177 Session session = null;
178
179 try {
180 session = openSession();
181
182 return (MBStatsUser)session.get(MBStatsUserImpl.class,
183 new Long(statsUserId));
184 }
185 catch (Exception e) {
186 throw HibernateUtil.processException(e);
187 }
188 finally {
189 closeSession(session);
190 }
191 }
192
193 public List findByGroupId(long groupId) throws SystemException {
194 String finderClassName = MBStatsUser.class.getName();
195 String finderMethodName = "findByGroupId";
196 String[] finderParams = new String[] { Long.class.getName() };
197 Object[] finderArgs = new Object[] { new Long(groupId) };
198 Object result = FinderCache.getResult(finderClassName,
199 finderMethodName, finderParams, finderArgs, getSessionFactory());
200
201 if (result == null) {
202 Session session = null;
203
204 try {
205 session = openSession();
206
207 StringMaker query = new StringMaker();
208 query.append(
209 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
210 query.append("groupId = ?");
211 query.append(" ");
212 query.append("ORDER BY ");
213 query.append("messageCount DESC");
214
215 Query q = session.createQuery(query.toString());
216 int queryPos = 0;
217 q.setLong(queryPos++, groupId);
218
219 List list = q.list();
220 FinderCache.putResult(finderClassName, finderMethodName,
221 finderParams, finderArgs, list);
222
223 return list;
224 }
225 catch (Exception e) {
226 throw HibernateUtil.processException(e);
227 }
228 finally {
229 closeSession(session);
230 }
231 }
232 else {
233 return (List)result;
234 }
235 }
236
237 public List findByGroupId(long groupId, int begin, int end)
238 throws SystemException {
239 return findByGroupId(groupId, begin, end, null);
240 }
241
242 public List findByGroupId(long groupId, int begin, int end,
243 OrderByComparator obc) throws SystemException {
244 String finderClassName = MBStatsUser.class.getName();
245 String finderMethodName = "findByGroupId";
246 String[] finderParams = new String[] {
247 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
248 "com.liferay.portal.kernel.util.OrderByComparator"
249 };
250 Object[] finderArgs = new Object[] {
251 new Long(groupId), String.valueOf(begin), String.valueOf(end),
252 String.valueOf(obc)
253 };
254 Object result = FinderCache.getResult(finderClassName,
255 finderMethodName, finderParams, finderArgs, getSessionFactory());
256
257 if (result == null) {
258 Session session = null;
259
260 try {
261 session = openSession();
262
263 StringMaker query = new StringMaker();
264 query.append(
265 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
266 query.append("groupId = ?");
267 query.append(" ");
268
269 if (obc != null) {
270 query.append("ORDER BY ");
271 query.append(obc.getOrderBy());
272 }
273 else {
274 query.append("ORDER BY ");
275 query.append("messageCount DESC");
276 }
277
278 Query q = session.createQuery(query.toString());
279 int queryPos = 0;
280 q.setLong(queryPos++, groupId);
281
282 List list = QueryUtil.list(q, getDialect(), begin, end);
283 FinderCache.putResult(finderClassName, finderMethodName,
284 finderParams, finderArgs, list);
285
286 return list;
287 }
288 catch (Exception e) {
289 throw HibernateUtil.processException(e);
290 }
291 finally {
292 closeSession(session);
293 }
294 }
295 else {
296 return (List)result;
297 }
298 }
299
300 public MBStatsUser findByGroupId_First(long groupId, OrderByComparator obc)
301 throws NoSuchStatsUserException, SystemException {
302 List list = findByGroupId(groupId, 0, 1, obc);
303
304 if (list.size() == 0) {
305 StringMaker msg = new StringMaker();
306 msg.append("No MBStatsUser exists with the key ");
307 msg.append(StringPool.OPEN_CURLY_BRACE);
308 msg.append("groupId=");
309 msg.append(groupId);
310 msg.append(StringPool.CLOSE_CURLY_BRACE);
311 throw new NoSuchStatsUserException(msg.toString());
312 }
313 else {
314 return (MBStatsUser)list.get(0);
315 }
316 }
317
318 public MBStatsUser findByGroupId_Last(long groupId, OrderByComparator obc)
319 throws NoSuchStatsUserException, SystemException {
320 int count = countByGroupId(groupId);
321 List list = findByGroupId(groupId, count - 1, count, obc);
322
323 if (list.size() == 0) {
324 StringMaker msg = new StringMaker();
325 msg.append("No MBStatsUser exists with the key ");
326 msg.append(StringPool.OPEN_CURLY_BRACE);
327 msg.append("groupId=");
328 msg.append(groupId);
329 msg.append(StringPool.CLOSE_CURLY_BRACE);
330 throw new NoSuchStatsUserException(msg.toString());
331 }
332 else {
333 return (MBStatsUser)list.get(0);
334 }
335 }
336
337 public MBStatsUser[] findByGroupId_PrevAndNext(long statsUserId,
338 long groupId, OrderByComparator obc)
339 throws NoSuchStatsUserException, SystemException {
340 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
341 int count = countByGroupId(groupId);
342 Session session = null;
343
344 try {
345 session = openSession();
346
347 StringMaker query = new StringMaker();
348 query.append(
349 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
350 query.append("groupId = ?");
351 query.append(" ");
352
353 if (obc != null) {
354 query.append("ORDER BY ");
355 query.append(obc.getOrderBy());
356 }
357 else {
358 query.append("ORDER BY ");
359 query.append("messageCount DESC");
360 }
361
362 Query q = session.createQuery(query.toString());
363 int queryPos = 0;
364 q.setLong(queryPos++, groupId);
365
366 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
367 mbStatsUser);
368 MBStatsUser[] array = new MBStatsUserImpl[3];
369 array[0] = (MBStatsUser)objArray[0];
370 array[1] = (MBStatsUser)objArray[1];
371 array[2] = (MBStatsUser)objArray[2];
372
373 return array;
374 }
375 catch (Exception e) {
376 throw HibernateUtil.processException(e);
377 }
378 finally {
379 closeSession(session);
380 }
381 }
382
383 public List findByUserId(long userId) throws SystemException {
384 String finderClassName = MBStatsUser.class.getName();
385 String finderMethodName = "findByUserId";
386 String[] finderParams = new String[] { Long.class.getName() };
387 Object[] finderArgs = new Object[] { new Long(userId) };
388 Object result = FinderCache.getResult(finderClassName,
389 finderMethodName, finderParams, finderArgs, getSessionFactory());
390
391 if (result == null) {
392 Session session = null;
393
394 try {
395 session = openSession();
396
397 StringMaker query = new StringMaker();
398 query.append(
399 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
400 query.append("userId = ?");
401 query.append(" ");
402 query.append("ORDER BY ");
403 query.append("messageCount DESC");
404
405 Query q = session.createQuery(query.toString());
406 int queryPos = 0;
407 q.setLong(queryPos++, userId);
408
409 List list = q.list();
410 FinderCache.putResult(finderClassName, finderMethodName,
411 finderParams, finderArgs, list);
412
413 return list;
414 }
415 catch (Exception e) {
416 throw HibernateUtil.processException(e);
417 }
418 finally {
419 closeSession(session);
420 }
421 }
422 else {
423 return (List)result;
424 }
425 }
426
427 public List findByUserId(long userId, int begin, int end)
428 throws SystemException {
429 return findByUserId(userId, begin, end, null);
430 }
431
432 public List findByUserId(long userId, int begin, int end,
433 OrderByComparator obc) throws SystemException {
434 String finderClassName = MBStatsUser.class.getName();
435 String finderMethodName = "findByUserId";
436 String[] finderParams = new String[] {
437 Long.class.getName(), "java.lang.Integer", "java.lang.Integer",
438 "com.liferay.portal.kernel.util.OrderByComparator"
439 };
440 Object[] finderArgs = new Object[] {
441 new Long(userId), String.valueOf(begin), String.valueOf(end),
442 String.valueOf(obc)
443 };
444 Object result = FinderCache.getResult(finderClassName,
445 finderMethodName, finderParams, finderArgs, getSessionFactory());
446
447 if (result == null) {
448 Session session = null;
449
450 try {
451 session = openSession();
452
453 StringMaker query = new StringMaker();
454 query.append(
455 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
456 query.append("userId = ?");
457 query.append(" ");
458
459 if (obc != null) {
460 query.append("ORDER BY ");
461 query.append(obc.getOrderBy());
462 }
463 else {
464 query.append("ORDER BY ");
465 query.append("messageCount DESC");
466 }
467
468 Query q = session.createQuery(query.toString());
469 int queryPos = 0;
470 q.setLong(queryPos++, userId);
471
472 List list = QueryUtil.list(q, getDialect(), begin, end);
473 FinderCache.putResult(finderClassName, finderMethodName,
474 finderParams, finderArgs, list);
475
476 return list;
477 }
478 catch (Exception e) {
479 throw HibernateUtil.processException(e);
480 }
481 finally {
482 closeSession(session);
483 }
484 }
485 else {
486 return (List)result;
487 }
488 }
489
490 public MBStatsUser findByUserId_First(long userId, OrderByComparator obc)
491 throws NoSuchStatsUserException, SystemException {
492 List list = findByUserId(userId, 0, 1, obc);
493
494 if (list.size() == 0) {
495 StringMaker msg = new StringMaker();
496 msg.append("No MBStatsUser exists with the key ");
497 msg.append(StringPool.OPEN_CURLY_BRACE);
498 msg.append("userId=");
499 msg.append(userId);
500 msg.append(StringPool.CLOSE_CURLY_BRACE);
501 throw new NoSuchStatsUserException(msg.toString());
502 }
503 else {
504 return (MBStatsUser)list.get(0);
505 }
506 }
507
508 public MBStatsUser findByUserId_Last(long userId, OrderByComparator obc)
509 throws NoSuchStatsUserException, SystemException {
510 int count = countByUserId(userId);
511 List list = findByUserId(userId, count - 1, count, obc);
512
513 if (list.size() == 0) {
514 StringMaker msg = new StringMaker();
515 msg.append("No MBStatsUser exists with the key ");
516 msg.append(StringPool.OPEN_CURLY_BRACE);
517 msg.append("userId=");
518 msg.append(userId);
519 msg.append(StringPool.CLOSE_CURLY_BRACE);
520 throw new NoSuchStatsUserException(msg.toString());
521 }
522 else {
523 return (MBStatsUser)list.get(0);
524 }
525 }
526
527 public MBStatsUser[] findByUserId_PrevAndNext(long statsUserId,
528 long userId, OrderByComparator obc)
529 throws NoSuchStatsUserException, SystemException {
530 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
531 int count = countByUserId(userId);
532 Session session = null;
533
534 try {
535 session = openSession();
536
537 StringMaker query = new StringMaker();
538 query.append(
539 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
540 query.append("userId = ?");
541 query.append(" ");
542
543 if (obc != null) {
544 query.append("ORDER BY ");
545 query.append(obc.getOrderBy());
546 }
547 else {
548 query.append("ORDER BY ");
549 query.append("messageCount DESC");
550 }
551
552 Query q = session.createQuery(query.toString());
553 int queryPos = 0;
554 q.setLong(queryPos++, userId);
555
556 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
557 mbStatsUser);
558 MBStatsUser[] array = new MBStatsUserImpl[3];
559 array[0] = (MBStatsUser)objArray[0];
560 array[1] = (MBStatsUser)objArray[1];
561 array[2] = (MBStatsUser)objArray[2];
562
563 return array;
564 }
565 catch (Exception e) {
566 throw HibernateUtil.processException(e);
567 }
568 finally {
569 closeSession(session);
570 }
571 }
572
573 public MBStatsUser findByG_U(long groupId, long userId)
574 throws NoSuchStatsUserException, SystemException {
575 MBStatsUser mbStatsUser = fetchByG_U(groupId, userId);
576
577 if (mbStatsUser == null) {
578 StringMaker msg = new StringMaker();
579 msg.append("No MBStatsUser exists with the key ");
580 msg.append(StringPool.OPEN_CURLY_BRACE);
581 msg.append("groupId=");
582 msg.append(groupId);
583 msg.append(", ");
584 msg.append("userId=");
585 msg.append(userId);
586 msg.append(StringPool.CLOSE_CURLY_BRACE);
587
588 if (_log.isWarnEnabled()) {
589 _log.warn(msg.toString());
590 }
591
592 throw new NoSuchStatsUserException(msg.toString());
593 }
594
595 return mbStatsUser;
596 }
597
598 public MBStatsUser fetchByG_U(long groupId, long userId)
599 throws SystemException {
600 String finderClassName = MBStatsUser.class.getName();
601 String finderMethodName = "fetchByG_U";
602 String[] finderParams = new String[] {
603 Long.class.getName(), Long.class.getName()
604 };
605 Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
606 Object result = FinderCache.getResult(finderClassName,
607 finderMethodName, finderParams, finderArgs, getSessionFactory());
608
609 if (result == null) {
610 Session session = null;
611
612 try {
613 session = openSession();
614
615 StringMaker query = new StringMaker();
616 query.append(
617 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
618 query.append("groupId = ?");
619 query.append(" AND ");
620 query.append("userId = ?");
621 query.append(" ");
622 query.append("ORDER BY ");
623 query.append("messageCount DESC");
624
625 Query q = session.createQuery(query.toString());
626 int queryPos = 0;
627 q.setLong(queryPos++, groupId);
628 q.setLong(queryPos++, userId);
629
630 List list = q.list();
631 FinderCache.putResult(finderClassName, finderMethodName,
632 finderParams, finderArgs, list);
633
634 if (list.size() == 0) {
635 return null;
636 }
637 else {
638 return (MBStatsUser)list.get(0);
639 }
640 }
641 catch (Exception e) {
642 throw HibernateUtil.processException(e);
643 }
644 finally {
645 closeSession(session);
646 }
647 }
648 else {
649 List list = (List)result;
650
651 if (list.size() == 0) {
652 return null;
653 }
654 else {
655 return (MBStatsUser)list.get(0);
656 }
657 }
658 }
659
660 public List findByG_M(long groupId, int messageCount)
661 throws SystemException {
662 String finderClassName = MBStatsUser.class.getName();
663 String finderMethodName = "findByG_M";
664 String[] finderParams = new String[] {
665 Long.class.getName(), Integer.class.getName()
666 };
667 Object[] finderArgs = new Object[] {
668 new Long(groupId), new Integer(messageCount)
669 };
670 Object result = FinderCache.getResult(finderClassName,
671 finderMethodName, finderParams, finderArgs, getSessionFactory());
672
673 if (result == null) {
674 Session session = null;
675
676 try {
677 session = openSession();
678
679 StringMaker query = new StringMaker();
680 query.append(
681 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
682 query.append("groupId = ?");
683 query.append(" AND ");
684 query.append("messageCount != ?");
685 query.append(" ");
686 query.append("ORDER BY ");
687 query.append("messageCount DESC");
688
689 Query q = session.createQuery(query.toString());
690 int queryPos = 0;
691 q.setLong(queryPos++, groupId);
692 q.setInteger(queryPos++, messageCount);
693
694 List list = q.list();
695 FinderCache.putResult(finderClassName, finderMethodName,
696 finderParams, finderArgs, list);
697
698 return list;
699 }
700 catch (Exception e) {
701 throw HibernateUtil.processException(e);
702 }
703 finally {
704 closeSession(session);
705 }
706 }
707 else {
708 return (List)result;
709 }
710 }
711
712 public List findByG_M(long groupId, int messageCount, int begin, int end)
713 throws SystemException {
714 return findByG_M(groupId, messageCount, begin, end, null);
715 }
716
717 public List findByG_M(long groupId, int messageCount, int begin, int end,
718 OrderByComparator obc) throws SystemException {
719 String finderClassName = MBStatsUser.class.getName();
720 String finderMethodName = "findByG_M";
721 String[] finderParams = new String[] {
722 Long.class.getName(), Integer.class.getName(),
723 "java.lang.Integer", "java.lang.Integer",
724 "com.liferay.portal.kernel.util.OrderByComparator"
725 };
726 Object[] finderArgs = new Object[] {
727 new Long(groupId), new Integer(messageCount),
728 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
729 };
730 Object result = FinderCache.getResult(finderClassName,
731 finderMethodName, finderParams, finderArgs, getSessionFactory());
732
733 if (result == null) {
734 Session session = null;
735
736 try {
737 session = openSession();
738
739 StringMaker query = new StringMaker();
740 query.append(
741 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
742 query.append("groupId = ?");
743 query.append(" AND ");
744 query.append("messageCount != ?");
745 query.append(" ");
746
747 if (obc != null) {
748 query.append("ORDER BY ");
749 query.append(obc.getOrderBy());
750 }
751 else {
752 query.append("ORDER BY ");
753 query.append("messageCount DESC");
754 }
755
756 Query q = session.createQuery(query.toString());
757 int queryPos = 0;
758 q.setLong(queryPos++, groupId);
759 q.setInteger(queryPos++, messageCount);
760
761 List list = QueryUtil.list(q, getDialect(), begin, end);
762 FinderCache.putResult(finderClassName, finderMethodName,
763 finderParams, finderArgs, list);
764
765 return list;
766 }
767 catch (Exception e) {
768 throw HibernateUtil.processException(e);
769 }
770 finally {
771 closeSession(session);
772 }
773 }
774 else {
775 return (List)result;
776 }
777 }
778
779 public MBStatsUser findByG_M_First(long groupId, int messageCount,
780 OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
781 List list = findByG_M(groupId, messageCount, 0, 1, obc);
782
783 if (list.size() == 0) {
784 StringMaker msg = new StringMaker();
785 msg.append("No MBStatsUser exists with the key ");
786 msg.append(StringPool.OPEN_CURLY_BRACE);
787 msg.append("groupId=");
788 msg.append(groupId);
789 msg.append(", ");
790 msg.append("messageCount=");
791 msg.append(messageCount);
792 msg.append(StringPool.CLOSE_CURLY_BRACE);
793 throw new NoSuchStatsUserException(msg.toString());
794 }
795 else {
796 return (MBStatsUser)list.get(0);
797 }
798 }
799
800 public MBStatsUser findByG_M_Last(long groupId, int messageCount,
801 OrderByComparator obc) throws NoSuchStatsUserException, SystemException {
802 int count = countByG_M(groupId, messageCount);
803 List list = findByG_M(groupId, messageCount, count - 1, count, obc);
804
805 if (list.size() == 0) {
806 StringMaker msg = new StringMaker();
807 msg.append("No MBStatsUser exists with the key ");
808 msg.append(StringPool.OPEN_CURLY_BRACE);
809 msg.append("groupId=");
810 msg.append(groupId);
811 msg.append(", ");
812 msg.append("messageCount=");
813 msg.append(messageCount);
814 msg.append(StringPool.CLOSE_CURLY_BRACE);
815 throw new NoSuchStatsUserException(msg.toString());
816 }
817 else {
818 return (MBStatsUser)list.get(0);
819 }
820 }
821
822 public MBStatsUser[] findByG_M_PrevAndNext(long statsUserId, long groupId,
823 int messageCount, OrderByComparator obc)
824 throws NoSuchStatsUserException, SystemException {
825 MBStatsUser mbStatsUser = findByPrimaryKey(statsUserId);
826 int count = countByG_M(groupId, messageCount);
827 Session session = null;
828
829 try {
830 session = openSession();
831
832 StringMaker query = new StringMaker();
833 query.append(
834 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
835 query.append("groupId = ?");
836 query.append(" AND ");
837 query.append("messageCount != ?");
838 query.append(" ");
839
840 if (obc != null) {
841 query.append("ORDER BY ");
842 query.append(obc.getOrderBy());
843 }
844 else {
845 query.append("ORDER BY ");
846 query.append("messageCount DESC");
847 }
848
849 Query q = session.createQuery(query.toString());
850 int queryPos = 0;
851 q.setLong(queryPos++, groupId);
852 q.setInteger(queryPos++, messageCount);
853
854 Object[] objArray = QueryUtil.getPrevAndNext(q, count, obc,
855 mbStatsUser);
856 MBStatsUser[] array = new MBStatsUserImpl[3];
857 array[0] = (MBStatsUser)objArray[0];
858 array[1] = (MBStatsUser)objArray[1];
859 array[2] = (MBStatsUser)objArray[2];
860
861 return array;
862 }
863 catch (Exception e) {
864 throw HibernateUtil.processException(e);
865 }
866 finally {
867 closeSession(session);
868 }
869 }
870
871 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer)
872 throws SystemException {
873 Session session = null;
874
875 try {
876 session = openSession();
877
878 DynamicQuery query = queryInitializer.initialize(session);
879
880 return query.list();
881 }
882 catch (Exception e) {
883 throw HibernateUtil.processException(e);
884 }
885 finally {
886 closeSession(session);
887 }
888 }
889
890 public List findWithDynamicQuery(DynamicQueryInitializer queryInitializer,
891 int begin, int end) throws SystemException {
892 Session session = null;
893
894 try {
895 session = openSession();
896
897 DynamicQuery query = queryInitializer.initialize(session);
898 query.setLimit(begin, end);
899
900 return query.list();
901 }
902 catch (Exception e) {
903 throw HibernateUtil.processException(e);
904 }
905 finally {
906 closeSession(session);
907 }
908 }
909
910 public List findAll() throws SystemException {
911 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
912 }
913
914 public List findAll(int begin, int end) throws SystemException {
915 return findAll(begin, end, null);
916 }
917
918 public List findAll(int begin, int end, OrderByComparator obc)
919 throws SystemException {
920 String finderClassName = MBStatsUser.class.getName();
921 String finderMethodName = "findAll";
922 String[] finderParams = new String[] {
923 "java.lang.Integer", "java.lang.Integer",
924 "com.liferay.portal.kernel.util.OrderByComparator"
925 };
926 Object[] finderArgs = new Object[] {
927 String.valueOf(begin), String.valueOf(end), String.valueOf(obc)
928 };
929 Object result = FinderCache.getResult(finderClassName,
930 finderMethodName, finderParams, finderArgs, getSessionFactory());
931
932 if (result == null) {
933 Session session = null;
934
935 try {
936 session = openSession();
937
938 StringMaker query = new StringMaker();
939 query.append(
940 "FROM com.liferay.portlet.messageboards.model.MBStatsUser ");
941
942 if (obc != null) {
943 query.append("ORDER BY ");
944 query.append(obc.getOrderBy());
945 }
946 else {
947 query.append("ORDER BY ");
948 query.append("messageCount DESC");
949 }
950
951 Query q = session.createQuery(query.toString());
952 List list = QueryUtil.list(q, getDialect(), begin, end);
953
954 if (obc == null) {
955 Collections.sort(list);
956 }
957
958 FinderCache.putResult(finderClassName, finderMethodName,
959 finderParams, finderArgs, list);
960
961 return list;
962 }
963 catch (Exception e) {
964 throw HibernateUtil.processException(e);
965 }
966 finally {
967 closeSession(session);
968 }
969 }
970 else {
971 return (List)result;
972 }
973 }
974
975 public void removeByGroupId(long groupId) throws SystemException {
976 Iterator itr = findByGroupId(groupId).iterator();
977
978 while (itr.hasNext()) {
979 MBStatsUser mbStatsUser = (MBStatsUser)itr.next();
980 remove(mbStatsUser);
981 }
982 }
983
984 public void removeByUserId(long userId) throws SystemException {
985 Iterator itr = findByUserId(userId).iterator();
986
987 while (itr.hasNext()) {
988 MBStatsUser mbStatsUser = (MBStatsUser)itr.next();
989 remove(mbStatsUser);
990 }
991 }
992
993 public void removeByG_U(long groupId, long userId)
994 throws NoSuchStatsUserException, SystemException {
995 MBStatsUser mbStatsUser = findByG_U(groupId, userId);
996 remove(mbStatsUser);
997 }
998
999 public void removeByG_M(long groupId, int messageCount)
1000 throws SystemException {
1001 Iterator itr = findByG_M(groupId, messageCount).iterator();
1002
1003 while (itr.hasNext()) {
1004 MBStatsUser mbStatsUser = (MBStatsUser)itr.next();
1005 remove(mbStatsUser);
1006 }
1007 }
1008
1009 public void removeAll() throws SystemException {
1010 Iterator itr = findAll().iterator();
1011
1012 while (itr.hasNext()) {
1013 remove((MBStatsUser)itr.next());
1014 }
1015 }
1016
1017 public int countByGroupId(long groupId) throws SystemException {
1018 String finderClassName = MBStatsUser.class.getName();
1019 String finderMethodName = "countByGroupId";
1020 String[] finderParams = new String[] { Long.class.getName() };
1021 Object[] finderArgs = new Object[] { new Long(groupId) };
1022 Object result = FinderCache.getResult(finderClassName,
1023 finderMethodName, finderParams, finderArgs, getSessionFactory());
1024
1025 if (result == null) {
1026 Session session = null;
1027
1028 try {
1029 session = openSession();
1030
1031 StringMaker query = new StringMaker();
1032 query.append("SELECT COUNT(*) ");
1033 query.append(
1034 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1035 query.append("groupId = ?");
1036 query.append(" ");
1037
1038 Query q = session.createQuery(query.toString());
1039 int queryPos = 0;
1040 q.setLong(queryPos++, groupId);
1041
1042 Long count = null;
1043 Iterator itr = q.list().iterator();
1044
1045 if (itr.hasNext()) {
1046 count = (Long)itr.next();
1047 }
1048
1049 if (count == null) {
1050 count = new Long(0);
1051 }
1052
1053 FinderCache.putResult(finderClassName, finderMethodName,
1054 finderParams, finderArgs, count);
1055
1056 return count.intValue();
1057 }
1058 catch (Exception e) {
1059 throw HibernateUtil.processException(e);
1060 }
1061 finally {
1062 closeSession(session);
1063 }
1064 }
1065 else {
1066 return ((Long)result).intValue();
1067 }
1068 }
1069
1070 public int countByUserId(long userId) throws SystemException {
1071 String finderClassName = MBStatsUser.class.getName();
1072 String finderMethodName = "countByUserId";
1073 String[] finderParams = new String[] { Long.class.getName() };
1074 Object[] finderArgs = new Object[] { new Long(userId) };
1075 Object result = FinderCache.getResult(finderClassName,
1076 finderMethodName, finderParams, finderArgs, getSessionFactory());
1077
1078 if (result == null) {
1079 Session session = null;
1080
1081 try {
1082 session = openSession();
1083
1084 StringMaker query = new StringMaker();
1085 query.append("SELECT COUNT(*) ");
1086 query.append(
1087 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1088 query.append("userId = ?");
1089 query.append(" ");
1090
1091 Query q = session.createQuery(query.toString());
1092 int queryPos = 0;
1093 q.setLong(queryPos++, userId);
1094
1095 Long count = null;
1096 Iterator itr = q.list().iterator();
1097
1098 if (itr.hasNext()) {
1099 count = (Long)itr.next();
1100 }
1101
1102 if (count == null) {
1103 count = new Long(0);
1104 }
1105
1106 FinderCache.putResult(finderClassName, finderMethodName,
1107 finderParams, finderArgs, count);
1108
1109 return count.intValue();
1110 }
1111 catch (Exception e) {
1112 throw HibernateUtil.processException(e);
1113 }
1114 finally {
1115 closeSession(session);
1116 }
1117 }
1118 else {
1119 return ((Long)result).intValue();
1120 }
1121 }
1122
1123 public int countByG_U(long groupId, long userId) throws SystemException {
1124 String finderClassName = MBStatsUser.class.getName();
1125 String finderMethodName = "countByG_U";
1126 String[] finderParams = new String[] {
1127 Long.class.getName(), Long.class.getName()
1128 };
1129 Object[] finderArgs = new Object[] { new Long(groupId), new Long(userId) };
1130 Object result = FinderCache.getResult(finderClassName,
1131 finderMethodName, finderParams, finderArgs, getSessionFactory());
1132
1133 if (result == null) {
1134 Session session = null;
1135
1136 try {
1137 session = openSession();
1138
1139 StringMaker query = new StringMaker();
1140 query.append("SELECT COUNT(*) ");
1141 query.append(
1142 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1143 query.append("groupId = ?");
1144 query.append(" AND ");
1145 query.append("userId = ?");
1146 query.append(" ");
1147
1148 Query q = session.createQuery(query.toString());
1149 int queryPos = 0;
1150 q.setLong(queryPos++, groupId);
1151 q.setLong(queryPos++, userId);
1152
1153 Long count = null;
1154 Iterator itr = q.list().iterator();
1155
1156 if (itr.hasNext()) {
1157 count = (Long)itr.next();
1158 }
1159
1160 if (count == null) {
1161 count = new Long(0);
1162 }
1163
1164 FinderCache.putResult(finderClassName, finderMethodName,
1165 finderParams, finderArgs, count);
1166
1167 return count.intValue();
1168 }
1169 catch (Exception e) {
1170 throw HibernateUtil.processException(e);
1171 }
1172 finally {
1173 closeSession(session);
1174 }
1175 }
1176 else {
1177 return ((Long)result).intValue();
1178 }
1179 }
1180
1181 public int countByG_M(long groupId, int messageCount)
1182 throws SystemException {
1183 String finderClassName = MBStatsUser.class.getName();
1184 String finderMethodName = "countByG_M";
1185 String[] finderParams = new String[] {
1186 Long.class.getName(), Integer.class.getName()
1187 };
1188 Object[] finderArgs = new Object[] {
1189 new Long(groupId), new Integer(messageCount)
1190 };
1191 Object result = FinderCache.getResult(finderClassName,
1192 finderMethodName, finderParams, finderArgs, getSessionFactory());
1193
1194 if (result == null) {
1195 Session session = null;
1196
1197 try {
1198 session = openSession();
1199
1200 StringMaker query = new StringMaker();
1201 query.append("SELECT COUNT(*) ");
1202 query.append(
1203 "FROM com.liferay.portlet.messageboards.model.MBStatsUser WHERE ");
1204 query.append("groupId = ?");
1205 query.append(" AND ");
1206 query.append("messageCount != ?");
1207 query.append(" ");
1208
1209 Query q = session.createQuery(query.toString());
1210 int queryPos = 0;
1211 q.setLong(queryPos++, groupId);
1212 q.setInteger(queryPos++, messageCount);
1213
1214 Long count = null;
1215 Iterator itr = q.list().iterator();
1216
1217 if (itr.hasNext()) {
1218 count = (Long)itr.next();
1219 }
1220
1221 if (count == null) {
1222 count = new Long(0);
1223 }
1224
1225 FinderCache.putResult(finderClassName, finderMethodName,
1226 finderParams, finderArgs, count);
1227
1228 return count.intValue();
1229 }
1230 catch (Exception e) {
1231 throw HibernateUtil.processException(e);
1232 }
1233 finally {
1234 closeSession(session);
1235 }
1236 }
1237 else {
1238 return ((Long)result).intValue();
1239 }
1240 }
1241
1242 public int countAll() throws SystemException {
1243 String finderClassName = MBStatsUser.class.getName();
1244 String finderMethodName = "countAll";
1245 String[] finderParams = new String[] { };
1246 Object[] finderArgs = new Object[] { };
1247 Object result = FinderCache.getResult(finderClassName,
1248 finderMethodName, finderParams, finderArgs, getSessionFactory());
1249
1250 if (result == null) {
1251 Session session = null;
1252
1253 try {
1254 session = openSession();
1255
1256 StringMaker query = new StringMaker();
1257 query.append("SELECT COUNT(*) ");
1258 query.append(
1259 "FROM com.liferay.portlet.messageboards.model.MBStatsUser");
1260
1261 Query q = session.createQuery(query.toString());
1262 Long count = null;
1263 Iterator itr = q.list().iterator();
1264
1265 if (itr.hasNext()) {
1266 count = (Long)itr.next();
1267 }
1268
1269 if (count == null) {
1270 count = new Long(0);
1271 }
1272
1273 FinderCache.putResult(finderClassName, finderMethodName,
1274 finderParams, finderArgs, count);
1275
1276 return count.intValue();
1277 }
1278 catch (Exception e) {
1279 throw HibernateUtil.processException(e);
1280 }
1281 finally {
1282 closeSession(session);
1283 }
1284 }
1285 else {
1286 return ((Long)result).intValue();
1287 }
1288 }
1289
1290 protected void initDao() {
1291 }
1292
1293 private static Log _log = LogFactory.getLog(MBStatsUserPersistenceImpl.class);
1294}