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