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