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