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