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