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