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