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