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.dao.orm.DynamicQuery;
27  import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
28  import com.liferay.portal.kernel.dao.orm.Query;
29  import com.liferay.portal.kernel.dao.orm.QueryPos;
30  import com.liferay.portal.kernel.dao.orm.QueryUtil;
31  import com.liferay.portal.kernel.dao.orm.Session;
32  import com.liferay.portal.kernel.util.GetterUtil;
33  import com.liferay.portal.kernel.util.ListUtil;
34  import com.liferay.portal.kernel.util.OrderByComparator;
35  import com.liferay.portal.kernel.util.StringPool;
36  import com.liferay.portal.kernel.util.StringUtil;
37  import com.liferay.portal.model.ModelListener;
38  import com.liferay.portal.service.persistence.BatchSessionUtil;
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 {
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             if (BatchSessionUtil.isEnabled()) {
126                 Object staleObject = session.get(MBBanImpl.class,
127                         mbBan.getPrimaryKeyObj());
128 
129                 if (staleObject != null) {
130                     session.evict(staleObject);
131                 }
132             }
133 
134             session.delete(mbBan);
135 
136             session.flush();
137 
138             return mbBan;
139         }
140         catch (Exception e) {
141             throw processException(e);
142         }
143         finally {
144             closeSession(session);
145 
146             FinderCacheUtil.clearCache(MBBan.class.getName());
147         }
148     }
149 
150     /**
151      * @deprecated Use <code>update(MBBan mbBan, boolean merge)</code>.
152      */
153     public MBBan update(MBBan mbBan) throws SystemException {
154         if (_log.isWarnEnabled()) {
155             _log.warn(
156                 "Using the deprecated update(MBBan mbBan) method. Use update(MBBan mbBan, boolean merge) instead.");
157         }
158 
159         return update(mbBan, false);
160     }
161 
162     /**
163      * Add, update, or merge, the entity. This method also calls the model
164      * listeners to trigger the proper events associated with adding, deleting,
165      * or updating an entity.
166      *
167      * @param        mbBan the entity to add, update, or merge
168      * @param        merge boolean value for whether to merge the entity. The
169      *                default value is false. Setting merge to true is more
170      *                expensive and should only be true when mbBan is
171      *                transient. See LEP-5473 for a detailed discussion of this
172      *                method.
173      * @return        true if the portlet can be displayed via Ajax
174      */
175     public MBBan update(MBBan mbBan, boolean merge) throws SystemException {
176         boolean isNew = mbBan.isNew();
177 
178         if (_listeners.length > 0) {
179             for (ModelListener listener : _listeners) {
180                 if (isNew) {
181                     listener.onBeforeCreate(mbBan);
182                 }
183                 else {
184                     listener.onBeforeUpdate(mbBan);
185                 }
186             }
187         }
188 
189         mbBan = updateImpl(mbBan, merge);
190 
191         if (_listeners.length > 0) {
192             for (ModelListener listener : _listeners) {
193                 if (isNew) {
194                     listener.onAfterCreate(mbBan);
195                 }
196                 else {
197                     listener.onAfterUpdate(mbBan);
198                 }
199             }
200         }
201 
202         return mbBan;
203     }
204 
205     public MBBan updateImpl(
206         com.liferay.portlet.messageboards.model.MBBan mbBan, boolean merge)
207         throws SystemException {
208         Session session = null;
209 
210         try {
211             session = openSession();
212 
213             BatchSessionUtil.update(session, mbBan, merge);
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 = null;
1119
1120                if (obc == null) {
1121                    list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
1122                            end, false);
1123
1124                    Collections.sort(list);
1125                }
1126                else {
1127                    list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
1128                            end);
1129                }
1130
1131                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1132                    finderClassName, finderMethodName, finderParams,
1133                    finderArgs, list);
1134
1135                return list;
1136            }
1137            catch (Exception e) {
1138                throw processException(e);
1139            }
1140            finally {
1141                closeSession(session);
1142            }
1143        }
1144        else {
1145            return (List<MBBan>)result;
1146        }
1147    }
1148
1149    public void removeByGroupId(long groupId) throws SystemException {
1150        for (MBBan mbBan : findByGroupId(groupId)) {
1151            remove(mbBan);
1152        }
1153    }
1154
1155    public void removeByUserId(long userId) throws SystemException {
1156        for (MBBan mbBan : findByUserId(userId)) {
1157            remove(mbBan);
1158        }
1159    }
1160
1161    public void removeByBanUserId(long banUserId) throws SystemException {
1162        for (MBBan mbBan : findByBanUserId(banUserId)) {
1163            remove(mbBan);
1164        }
1165    }
1166
1167    public void removeByG_B(long groupId, long banUserId)
1168        throws NoSuchBanException, SystemException {
1169        MBBan mbBan = findByG_B(groupId, banUserId);
1170
1171        remove(mbBan);
1172    }
1173
1174    public void removeAll() throws SystemException {
1175        for (MBBan mbBan : findAll()) {
1176            remove(mbBan);
1177        }
1178    }
1179
1180    public int countByGroupId(long groupId) throws SystemException {
1181        boolean finderClassNameCacheEnabled = MBBanModelImpl.CACHE_ENABLED;
1182        String finderClassName = MBBan.class.getName();
1183        String finderMethodName = "countByGroupId";
1184        String[] finderParams = new String[] { Long.class.getName() };
1185        Object[] finderArgs = new Object[] { new Long(groupId) };
1186
1187        Object result = null;
1188
1189        if (finderClassNameCacheEnabled) {
1190            result = FinderCacheUtil.getResult(finderClassName,
1191                    finderMethodName, finderParams, finderArgs, this);
1192        }
1193
1194        if (result == null) {
1195            Session session = null;
1196
1197            try {
1198                session = openSession();
1199
1200                StringBuilder query = new StringBuilder();
1201
1202                query.append("SELECT COUNT(*) ");
1203                query.append(
1204                    "FROM com.liferay.portlet.messageboards.model.MBBan WHERE ");
1205
1206                query.append("groupId = ?");
1207
1208                query.append(" ");
1209
1210                Query q = session.createQuery(query.toString());
1211
1212                QueryPos qPos = QueryPos.getInstance(q);
1213
1214                qPos.add(groupId);
1215
1216                Long count = null;
1217
1218                Iterator<Long> itr = q.list().iterator();
1219
1220                if (itr.hasNext()) {
1221                    count = itr.next();
1222                }
1223
1224                if (count == null) {
1225                    count = new Long(0);
1226                }
1227
1228                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1229                    finderClassName, finderMethodName, finderParams,
1230                    finderArgs, count);
1231
1232                return count.intValue();
1233            }
1234            catch (Exception e) {
1235                throw processException(e);
1236            }
1237            finally {
1238                closeSession(session);
1239            }
1240        }
1241        else {
1242            return ((Long)result).intValue();
1243        }
1244    }
1245
1246    public int countByUserId(long userId) throws SystemException {
1247        boolean finderClassNameCacheEnabled = MBBanModelImpl.CACHE_ENABLED;
1248        String finderClassName = MBBan.class.getName();
1249        String finderMethodName = "countByUserId";
1250        String[] finderParams = new String[] { Long.class.getName() };
1251        Object[] finderArgs = new Object[] { new Long(userId) };
1252
1253        Object result = null;
1254
1255        if (finderClassNameCacheEnabled) {
1256            result = FinderCacheUtil.getResult(finderClassName,
1257                    finderMethodName, finderParams, finderArgs, this);
1258        }
1259
1260        if (result == null) {
1261            Session session = null;
1262
1263            try {
1264                session = openSession();
1265
1266                StringBuilder query = new StringBuilder();
1267
1268                query.append("SELECT COUNT(*) ");
1269                query.append(
1270                    "FROM com.liferay.portlet.messageboards.model.MBBan WHERE ");
1271
1272                query.append("userId = ?");
1273
1274                query.append(" ");
1275
1276                Query q = session.createQuery(query.toString());
1277
1278                QueryPos qPos = QueryPos.getInstance(q);
1279
1280                qPos.add(userId);
1281
1282                Long count = null;
1283
1284                Iterator<Long> itr = q.list().iterator();
1285
1286                if (itr.hasNext()) {
1287                    count = itr.next();
1288                }
1289
1290                if (count == null) {
1291                    count = new Long(0);
1292                }
1293
1294                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1295                    finderClassName, finderMethodName, finderParams,
1296                    finderArgs, count);
1297
1298                return count.intValue();
1299            }
1300            catch (Exception e) {
1301                throw processException(e);
1302            }
1303            finally {
1304                closeSession(session);
1305            }
1306        }
1307        else {
1308            return ((Long)result).intValue();
1309        }
1310    }
1311
1312    public int countByBanUserId(long banUserId) throws SystemException {
1313        boolean finderClassNameCacheEnabled = MBBanModelImpl.CACHE_ENABLED;
1314        String finderClassName = MBBan.class.getName();
1315        String finderMethodName = "countByBanUserId";
1316        String[] finderParams = new String[] { Long.class.getName() };
1317        Object[] finderArgs = new Object[] { new Long(banUserId) };
1318
1319        Object result = null;
1320
1321        if (finderClassNameCacheEnabled) {
1322            result = FinderCacheUtil.getResult(finderClassName,
1323                    finderMethodName, finderParams, finderArgs, this);
1324        }
1325
1326        if (result == null) {
1327            Session session = null;
1328
1329            try {
1330                session = openSession();
1331
1332                StringBuilder query = new StringBuilder();
1333
1334                query.append("SELECT COUNT(*) ");
1335                query.append(
1336                    "FROM com.liferay.portlet.messageboards.model.MBBan WHERE ");
1337
1338                query.append("banUserId = ?");
1339
1340                query.append(" ");
1341
1342                Query q = session.createQuery(query.toString());
1343
1344                QueryPos qPos = QueryPos.getInstance(q);
1345
1346                qPos.add(banUserId);
1347
1348                Long count = null;
1349
1350                Iterator<Long> itr = q.list().iterator();
1351
1352                if (itr.hasNext()) {
1353                    count = itr.next();
1354                }
1355
1356                if (count == null) {
1357                    count = new Long(0);
1358                }
1359
1360                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1361                    finderClassName, finderMethodName, finderParams,
1362                    finderArgs, count);
1363
1364                return count.intValue();
1365            }
1366            catch (Exception e) {
1367                throw processException(e);
1368            }
1369            finally {
1370                closeSession(session);
1371            }
1372        }
1373        else {
1374            return ((Long)result).intValue();
1375        }
1376    }
1377
1378    public int countByG_B(long groupId, long banUserId)
1379        throws SystemException {
1380        boolean finderClassNameCacheEnabled = MBBanModelImpl.CACHE_ENABLED;
1381        String finderClassName = MBBan.class.getName();
1382        String finderMethodName = "countByG_B";
1383        String[] finderParams = new String[] {
1384                Long.class.getName(), Long.class.getName()
1385            };
1386        Object[] finderArgs = new Object[] {
1387                new Long(groupId), new Long(banUserId)
1388            };
1389
1390        Object result = null;
1391
1392        if (finderClassNameCacheEnabled) {
1393            result = FinderCacheUtil.getResult(finderClassName,
1394                    finderMethodName, finderParams, finderArgs, this);
1395        }
1396
1397        if (result == null) {
1398            Session session = null;
1399
1400            try {
1401                session = openSession();
1402
1403                StringBuilder query = new StringBuilder();
1404
1405                query.append("SELECT COUNT(*) ");
1406                query.append(
1407                    "FROM com.liferay.portlet.messageboards.model.MBBan WHERE ");
1408
1409                query.append("groupId = ?");
1410
1411                query.append(" AND ");
1412
1413                query.append("banUserId = ?");
1414
1415                query.append(" ");
1416
1417                Query q = session.createQuery(query.toString());
1418
1419                QueryPos qPos = QueryPos.getInstance(q);
1420
1421                qPos.add(groupId);
1422
1423                qPos.add(banUserId);
1424
1425                Long count = null;
1426
1427                Iterator<Long> itr = q.list().iterator();
1428
1429                if (itr.hasNext()) {
1430                    count = itr.next();
1431                }
1432
1433                if (count == null) {
1434                    count = new Long(0);
1435                }
1436
1437                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1438                    finderClassName, finderMethodName, finderParams,
1439                    finderArgs, count);
1440
1441                return count.intValue();
1442            }
1443            catch (Exception e) {
1444                throw processException(e);
1445            }
1446            finally {
1447                closeSession(session);
1448            }
1449        }
1450        else {
1451            return ((Long)result).intValue();
1452        }
1453    }
1454
1455    public int countAll() throws SystemException {
1456        boolean finderClassNameCacheEnabled = MBBanModelImpl.CACHE_ENABLED;
1457        String finderClassName = MBBan.class.getName();
1458        String finderMethodName = "countAll";
1459        String[] finderParams = new String[] {  };
1460        Object[] finderArgs = new Object[] {  };
1461
1462        Object result = null;
1463
1464        if (finderClassNameCacheEnabled) {
1465            result = FinderCacheUtil.getResult(finderClassName,
1466                    finderMethodName, finderParams, finderArgs, this);
1467        }
1468
1469        if (result == null) {
1470            Session session = null;
1471
1472            try {
1473                session = openSession();
1474
1475                Query q = session.createQuery(
1476                        "SELECT COUNT(*) FROM com.liferay.portlet.messageboards.model.MBBan");
1477
1478                Long count = null;
1479
1480                Iterator<Long> itr = q.list().iterator();
1481
1482                if (itr.hasNext()) {
1483                    count = itr.next();
1484                }
1485
1486                if (count == null) {
1487                    count = new Long(0);
1488                }
1489
1490                FinderCacheUtil.putResult(finderClassNameCacheEnabled,
1491                    finderClassName, finderMethodName, finderParams,
1492                    finderArgs, count);
1493
1494                return count.intValue();
1495            }
1496            catch (Exception e) {
1497                throw processException(e);
1498            }
1499            finally {
1500                closeSession(session);
1501            }
1502        }
1503        else {
1504            return ((Long)result).intValue();
1505        }
1506    }
1507
1508    public void registerListener(ModelListener listener) {
1509        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1510
1511        listeners.add(listener);
1512
1513        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1514    }
1515
1516    public void unregisterListener(ModelListener listener) {
1517        List<ModelListener> listeners = ListUtil.fromArray(_listeners);
1518
1519        listeners.remove(listener);
1520
1521        _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1522    }
1523
1524    public void afterPropertiesSet() {
1525        String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1526                    com.liferay.portal.util.PropsUtil.get(
1527                        "value.object.listener.com.liferay.portlet.messageboards.model.MBBan")));
1528
1529        if (listenerClassNames.length > 0) {
1530            try {
1531                List<ModelListener> listeners = new ArrayList<ModelListener>();
1532
1533                for (String listenerClassName : listenerClassNames) {
1534                    listeners.add((ModelListener)Class.forName(
1535                            listenerClassName).newInstance());
1536                }
1537
1538                _listeners = listeners.toArray(new ModelListener[listeners.size()]);
1539            }
1540            catch (Exception e) {
1541                _log.error(e);
1542            }
1543        }
1544    }
1545
1546    private static Log _log = LogFactory.getLog(MBBanPersistenceImpl.class);
1547    private ModelListener[] _listeners = new ModelListener[0];
1548}