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