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