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