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