001    /**
002     * Copyright (c) 2000-2011 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.exception.SystemException;
028    import com.liferay.portal.kernel.log.Log;
029    import com.liferay.portal.kernel.log.LogFactoryUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.model.ModelListener;
037    import com.liferay.portal.service.persistence.BatchSessionUtil;
038    import com.liferay.portal.service.persistence.ResourcePersistence;
039    import com.liferay.portal.service.persistence.UserPersistence;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.messageboards.NoSuchBanException;
043    import com.liferay.portlet.messageboards.model.MBBan;
044    import com.liferay.portlet.messageboards.model.impl.MBBanImpl;
045    import com.liferay.portlet.messageboards.model.impl.MBBanModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    
053    /**
054     * The persistence implementation for the message boards ban service.
055     *
056     * <p>
057     * Never modify or reference this class directly. Always use {@link MBBanUtil} to access the message boards ban persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
058     * </p>
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see MBBanPersistence
066     * @see MBBanUtil
067     * @generated
068     */
069    public class MBBanPersistenceImpl extends BasePersistenceImpl<MBBan>
070            implements MBBanPersistence {
071            public static final String FINDER_CLASS_NAME_ENTITY = MBBanImpl.class.getName();
072            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
073                    ".List";
074            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
075                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
076                            "findByGroupId",
077                            new String[] {
078                                    Long.class.getName(),
079                                    
080                            "java.lang.Integer", "java.lang.Integer",
081                                    "com.liferay.portal.kernel.util.OrderByComparator"
082                            });
083            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
084                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
085                            "countByGroupId", new String[] { Long.class.getName() });
086            public static final FinderPath FINDER_PATH_FIND_BY_USERID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
087                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
088                            "findByUserId",
089                            new String[] {
090                                    Long.class.getName(),
091                                    
092                            "java.lang.Integer", "java.lang.Integer",
093                                    "com.liferay.portal.kernel.util.OrderByComparator"
094                            });
095            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
096                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
097                            "countByUserId", new String[] { Long.class.getName() });
098            public static final FinderPath FINDER_PATH_FIND_BY_BANUSERID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
099                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100                            "findByBanUserId",
101                            new String[] {
102                                    Long.class.getName(),
103                                    
104                            "java.lang.Integer", "java.lang.Integer",
105                                    "com.liferay.portal.kernel.util.OrderByComparator"
106                            });
107            public static final FinderPath FINDER_PATH_COUNT_BY_BANUSERID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
108                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
109                            "countByBanUserId", new String[] { Long.class.getName() });
110            public static final FinderPath FINDER_PATH_FETCH_BY_G_B = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
111                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
112                            "fetchByG_B",
113                            new String[] { Long.class.getName(), Long.class.getName() });
114            public static final FinderPath FINDER_PATH_COUNT_BY_G_B = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
115                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
116                            "countByG_B",
117                            new String[] { Long.class.getName(), Long.class.getName() });
118            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
119                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
120                            "findAll", new String[0]);
121            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
122                            MBBanModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
123                            "countAll", new String[0]);
124    
125            /**
126             * Caches the message boards ban in the entity cache if it is enabled.
127             *
128             * @param mbBan the message boards ban to cache
129             */
130            public void cacheResult(MBBan mbBan) {
131                    EntityCacheUtil.putResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
132                            MBBanImpl.class, mbBan.getPrimaryKey(), mbBan);
133    
134                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_B,
135                            new Object[] {
136                                    new Long(mbBan.getGroupId()), new Long(mbBan.getBanUserId())
137                            }, mbBan);
138            }
139    
140            /**
141             * Caches the message boards bans in the entity cache if it is enabled.
142             *
143             * @param mbBans the message boards bans to cache
144             */
145            public void cacheResult(List<MBBan> mbBans) {
146                    for (MBBan mbBan : mbBans) {
147                            if (EntityCacheUtil.getResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
148                                                    MBBanImpl.class, mbBan.getPrimaryKey(), this) == null) {
149                                    cacheResult(mbBan);
150                            }
151                    }
152            }
153    
154            /**
155             * Clears the cache for all message boards bans.
156             *
157             * <p>
158             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
159             * </p>
160             */
161            public void clearCache() {
162                    CacheRegistryUtil.clear(MBBanImpl.class.getName());
163                    EntityCacheUtil.clearCache(MBBanImpl.class.getName());
164                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
165                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
166            }
167    
168            /**
169             * Clears the cache for the message boards ban.
170             *
171             * <p>
172             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
173             * </p>
174             */
175            public void clearCache(MBBan mbBan) {
176                    EntityCacheUtil.removeResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
177                            MBBanImpl.class, mbBan.getPrimaryKey());
178    
179                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_B,
180                            new Object[] {
181                                    new Long(mbBan.getGroupId()), new Long(mbBan.getBanUserId())
182                            });
183            }
184    
185            /**
186             * Creates a new message boards ban with the primary key. Does not add the message boards ban to the database.
187             *
188             * @param banId the primary key for the new message boards ban
189             * @return the new message boards ban
190             */
191            public MBBan create(long banId) {
192                    MBBan mbBan = new MBBanImpl();
193    
194                    mbBan.setNew(true);
195                    mbBan.setPrimaryKey(banId);
196    
197                    return mbBan;
198            }
199    
200            /**
201             * Removes the message boards ban with the primary key from the database. Also notifies the appropriate model listeners.
202             *
203             * @param primaryKey the primary key of the message boards ban to remove
204             * @return the message boards ban that was removed
205             * @throws com.liferay.portal.NoSuchModelException if a message boards ban with the primary key could not be found
206             * @throws SystemException if a system exception occurred
207             */
208            public MBBan remove(Serializable primaryKey)
209                    throws NoSuchModelException, SystemException {
210                    return remove(((Long)primaryKey).longValue());
211            }
212    
213            /**
214             * Removes the message boards ban with the primary key from the database. Also notifies the appropriate model listeners.
215             *
216             * @param banId the primary key of the message boards ban to remove
217             * @return the message boards ban that was removed
218             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
219             * @throws SystemException if a system exception occurred
220             */
221            public MBBan remove(long banId) throws NoSuchBanException, SystemException {
222                    Session session = null;
223    
224                    try {
225                            session = openSession();
226    
227                            MBBan mbBan = (MBBan)session.get(MBBanImpl.class, new Long(banId));
228    
229                            if (mbBan == null) {
230                                    if (_log.isWarnEnabled()) {
231                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + banId);
232                                    }
233    
234                                    throw new NoSuchBanException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
235                                            banId);
236                            }
237    
238                            return remove(mbBan);
239                    }
240                    catch (NoSuchBanException nsee) {
241                            throw nsee;
242                    }
243                    catch (Exception e) {
244                            throw processException(e);
245                    }
246                    finally {
247                            closeSession(session);
248                    }
249            }
250    
251            protected MBBan removeImpl(MBBan mbBan) throws SystemException {
252                    mbBan = toUnwrappedModel(mbBan);
253    
254                    Session session = null;
255    
256                    try {
257                            session = openSession();
258    
259                            BatchSessionUtil.delete(session, mbBan);
260                    }
261                    catch (Exception e) {
262                            throw processException(e);
263                    }
264                    finally {
265                            closeSession(session);
266                    }
267    
268                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
269    
270                    MBBanModelImpl mbBanModelImpl = (MBBanModelImpl)mbBan;
271    
272                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_B,
273                            new Object[] {
274                                    new Long(mbBanModelImpl.getGroupId()),
275                                    new Long(mbBanModelImpl.getBanUserId())
276                            });
277    
278                    EntityCacheUtil.removeResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
279                            MBBanImpl.class, mbBan.getPrimaryKey());
280    
281                    return mbBan;
282            }
283    
284            public MBBan updateImpl(
285                    com.liferay.portlet.messageboards.model.MBBan mbBan, boolean merge)
286                    throws SystemException {
287                    mbBan = toUnwrappedModel(mbBan);
288    
289                    boolean isNew = mbBan.isNew();
290    
291                    MBBanModelImpl mbBanModelImpl = (MBBanModelImpl)mbBan;
292    
293                    Session session = null;
294    
295                    try {
296                            session = openSession();
297    
298                            BatchSessionUtil.update(session, mbBan, merge);
299    
300                            mbBan.setNew(false);
301                    }
302                    catch (Exception e) {
303                            throw processException(e);
304                    }
305                    finally {
306                            closeSession(session);
307                    }
308    
309                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
310    
311                    EntityCacheUtil.putResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
312                            MBBanImpl.class, mbBan.getPrimaryKey(), mbBan);
313    
314                    if (!isNew &&
315                                    ((mbBan.getGroupId() != mbBanModelImpl.getOriginalGroupId()) ||
316                                    (mbBan.getBanUserId() != mbBanModelImpl.getOriginalBanUserId()))) {
317                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_B,
318                                    new Object[] {
319                                            new Long(mbBanModelImpl.getOriginalGroupId()),
320                                            new Long(mbBanModelImpl.getOriginalBanUserId())
321                                    });
322                    }
323    
324                    if (isNew ||
325                                    ((mbBan.getGroupId() != mbBanModelImpl.getOriginalGroupId()) ||
326                                    (mbBan.getBanUserId() != mbBanModelImpl.getOriginalBanUserId()))) {
327                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_B,
328                                    new Object[] {
329                                            new Long(mbBan.getGroupId()), new Long(mbBan.getBanUserId())
330                                    }, mbBan);
331                    }
332    
333                    return mbBan;
334            }
335    
336            protected MBBan toUnwrappedModel(MBBan mbBan) {
337                    if (mbBan instanceof MBBanImpl) {
338                            return mbBan;
339                    }
340    
341                    MBBanImpl mbBanImpl = new MBBanImpl();
342    
343                    mbBanImpl.setNew(mbBan.isNew());
344                    mbBanImpl.setPrimaryKey(mbBan.getPrimaryKey());
345    
346                    mbBanImpl.setBanId(mbBan.getBanId());
347                    mbBanImpl.setGroupId(mbBan.getGroupId());
348                    mbBanImpl.setCompanyId(mbBan.getCompanyId());
349                    mbBanImpl.setUserId(mbBan.getUserId());
350                    mbBanImpl.setUserName(mbBan.getUserName());
351                    mbBanImpl.setCreateDate(mbBan.getCreateDate());
352                    mbBanImpl.setModifiedDate(mbBan.getModifiedDate());
353                    mbBanImpl.setBanUserId(mbBan.getBanUserId());
354    
355                    return mbBanImpl;
356            }
357    
358            /**
359             * Finds the message boards ban with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
360             *
361             * @param primaryKey the primary key of the message boards ban to find
362             * @return the message boards ban
363             * @throws com.liferay.portal.NoSuchModelException if a message boards ban with the primary key could not be found
364             * @throws SystemException if a system exception occurred
365             */
366            public MBBan findByPrimaryKey(Serializable primaryKey)
367                    throws NoSuchModelException, SystemException {
368                    return findByPrimaryKey(((Long)primaryKey).longValue());
369            }
370    
371            /**
372             * Finds the message boards ban with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchBanException} if it could not be found.
373             *
374             * @param banId the primary key of the message boards ban to find
375             * @return the message boards ban
376             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
377             * @throws SystemException if a system exception occurred
378             */
379            public MBBan findByPrimaryKey(long banId)
380                    throws NoSuchBanException, SystemException {
381                    MBBan mbBan = fetchByPrimaryKey(banId);
382    
383                    if (mbBan == null) {
384                            if (_log.isWarnEnabled()) {
385                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + banId);
386                            }
387    
388                            throw new NoSuchBanException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
389                                    banId);
390                    }
391    
392                    return mbBan;
393            }
394    
395            /**
396             * Finds the message boards ban with the primary key or returns <code>null</code> if it could not be found.
397             *
398             * @param primaryKey the primary key of the message boards ban to find
399             * @return the message boards ban, or <code>null</code> if a message boards ban with the primary key could not be found
400             * @throws SystemException if a system exception occurred
401             */
402            public MBBan fetchByPrimaryKey(Serializable primaryKey)
403                    throws SystemException {
404                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
405            }
406    
407            /**
408             * Finds the message boards ban with the primary key or returns <code>null</code> if it could not be found.
409             *
410             * @param banId the primary key of the message boards ban to find
411             * @return the message boards ban, or <code>null</code> if a message boards ban with the primary key could not be found
412             * @throws SystemException if a system exception occurred
413             */
414            public MBBan fetchByPrimaryKey(long banId) throws SystemException {
415                    MBBan mbBan = (MBBan)EntityCacheUtil.getResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
416                                    MBBanImpl.class, banId, this);
417    
418                    if (mbBan == null) {
419                            Session session = null;
420    
421                            try {
422                                    session = openSession();
423    
424                                    mbBan = (MBBan)session.get(MBBanImpl.class, new Long(banId));
425                            }
426                            catch (Exception e) {
427                                    throw processException(e);
428                            }
429                            finally {
430                                    if (mbBan != null) {
431                                            cacheResult(mbBan);
432                                    }
433    
434                                    closeSession(session);
435                            }
436                    }
437    
438                    return mbBan;
439            }
440    
441            /**
442             * Finds all the message boards bans where groupId = &#63;.
443             *
444             * @param groupId the group id to search with
445             * @return the matching message boards bans
446             * @throws SystemException if a system exception occurred
447             */
448            public List<MBBan> findByGroupId(long groupId) throws SystemException {
449                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
450            }
451    
452            /**
453             * Finds a range of all the message boards bans where groupId = &#63;.
454             *
455             * <p>
456             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
457             * </p>
458             *
459             * @param groupId the group id to search with
460             * @param start the lower bound of the range of message boards bans to return
461             * @param end the upper bound of the range of message boards bans to return (not inclusive)
462             * @return the range of matching message boards bans
463             * @throws SystemException if a system exception occurred
464             */
465            public List<MBBan> findByGroupId(long groupId, int start, int end)
466                    throws SystemException {
467                    return findByGroupId(groupId, start, end, null);
468            }
469    
470            /**
471             * Finds an ordered range of all the message boards bans where groupId = &#63;.
472             *
473             * <p>
474             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
475             * </p>
476             *
477             * @param groupId the group id to search with
478             * @param start the lower bound of the range of message boards bans to return
479             * @param end the upper bound of the range of message boards bans to return (not inclusive)
480             * @param orderByComparator the comparator to order the results by
481             * @return the ordered range of matching message boards bans
482             * @throws SystemException if a system exception occurred
483             */
484            public List<MBBan> findByGroupId(long groupId, int start, int end,
485                    OrderByComparator orderByComparator) throws SystemException {
486                    Object[] finderArgs = new Object[] {
487                                    groupId,
488                                    
489                                    String.valueOf(start), String.valueOf(end),
490                                    String.valueOf(orderByComparator)
491                            };
492    
493                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
494                                    finderArgs, this);
495    
496                    if (list == null) {
497                            StringBundler query = null;
498    
499                            if (orderByComparator != null) {
500                                    query = new StringBundler(3 +
501                                                    (orderByComparator.getOrderByFields().length * 3));
502                            }
503                            else {
504                                    query = new StringBundler(2);
505                            }
506    
507                            query.append(_SQL_SELECT_MBBAN_WHERE);
508    
509                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
510    
511                            if (orderByComparator != null) {
512                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
513                                            orderByComparator);
514                            }
515    
516                            String sql = query.toString();
517    
518                            Session session = null;
519    
520                            try {
521                                    session = openSession();
522    
523                                    Query q = session.createQuery(sql);
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                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID,
537                                                    finderArgs);
538                                    }
539                                    else {
540                                            cacheResult(list);
541    
542                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
543                                                    finderArgs, list);
544                                    }
545    
546                                    closeSession(session);
547                            }
548                    }
549    
550                    return list;
551            }
552    
553            /**
554             * Finds the first message boards ban in the ordered set where groupId = &#63;.
555             *
556             * <p>
557             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
558             * </p>
559             *
560             * @param groupId the group id to search with
561             * @param orderByComparator the comparator to order the set by
562             * @return the first matching message boards ban
563             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
564             * @throws SystemException if a system exception occurred
565             */
566            public MBBan findByGroupId_First(long groupId,
567                    OrderByComparator orderByComparator)
568                    throws NoSuchBanException, SystemException {
569                    List<MBBan> list = findByGroupId(groupId, 0, 1, orderByComparator);
570    
571                    if (list.isEmpty()) {
572                            StringBundler msg = new StringBundler(4);
573    
574                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
575    
576                            msg.append("groupId=");
577                            msg.append(groupId);
578    
579                            msg.append(StringPool.CLOSE_CURLY_BRACE);
580    
581                            throw new NoSuchBanException(msg.toString());
582                    }
583                    else {
584                            return list.get(0);
585                    }
586            }
587    
588            /**
589             * Finds the last message boards ban in the ordered set where groupId = &#63;.
590             *
591             * <p>
592             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
593             * </p>
594             *
595             * @param groupId the group id to search with
596             * @param orderByComparator the comparator to order the set by
597             * @return the last matching message boards ban
598             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
599             * @throws SystemException if a system exception occurred
600             */
601            public MBBan findByGroupId_Last(long groupId,
602                    OrderByComparator orderByComparator)
603                    throws NoSuchBanException, SystemException {
604                    int count = countByGroupId(groupId);
605    
606                    List<MBBan> list = findByGroupId(groupId, count - 1, count,
607                                    orderByComparator);
608    
609                    if (list.isEmpty()) {
610                            StringBundler msg = new StringBundler(4);
611    
612                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
613    
614                            msg.append("groupId=");
615                            msg.append(groupId);
616    
617                            msg.append(StringPool.CLOSE_CURLY_BRACE);
618    
619                            throw new NoSuchBanException(msg.toString());
620                    }
621                    else {
622                            return list.get(0);
623                    }
624            }
625    
626            /**
627             * Finds the message boards bans before and after the current message boards ban in the ordered set where groupId = &#63;.
628             *
629             * <p>
630             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
631             * </p>
632             *
633             * @param banId the primary key of the current message boards ban
634             * @param groupId the group id to search with
635             * @param orderByComparator the comparator to order the set by
636             * @return the previous, current, and next message boards ban
637             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
638             * @throws SystemException if a system exception occurred
639             */
640            public MBBan[] findByGroupId_PrevAndNext(long banId, long groupId,
641                    OrderByComparator orderByComparator)
642                    throws NoSuchBanException, SystemException {
643                    MBBan mbBan = findByPrimaryKey(banId);
644    
645                    Session session = null;
646    
647                    try {
648                            session = openSession();
649    
650                            MBBan[] array = new MBBanImpl[3];
651    
652                            array[0] = getByGroupId_PrevAndNext(session, mbBan, groupId,
653                                            orderByComparator, true);
654    
655                            array[1] = mbBan;
656    
657                            array[2] = getByGroupId_PrevAndNext(session, mbBan, groupId,
658                                            orderByComparator, false);
659    
660                            return array;
661                    }
662                    catch (Exception e) {
663                            throw processException(e);
664                    }
665                    finally {
666                            closeSession(session);
667                    }
668            }
669    
670            protected MBBan getByGroupId_PrevAndNext(Session session, MBBan mbBan,
671                    long groupId, OrderByComparator orderByComparator, boolean previous) {
672                    StringBundler query = null;
673    
674                    if (orderByComparator != null) {
675                            query = new StringBundler(6 +
676                                            (orderByComparator.getOrderByFields().length * 6));
677                    }
678                    else {
679                            query = new StringBundler(3);
680                    }
681    
682                    query.append(_SQL_SELECT_MBBAN_WHERE);
683    
684                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
685    
686                    if (orderByComparator != null) {
687                            String[] orderByFields = orderByComparator.getOrderByFields();
688    
689                            if (orderByFields.length > 0) {
690                                    query.append(WHERE_AND);
691                            }
692    
693                            for (int i = 0; i < orderByFields.length; i++) {
694                                    query.append(_ORDER_BY_ENTITY_ALIAS);
695                                    query.append(orderByFields[i]);
696    
697                                    if ((i + 1) < orderByFields.length) {
698                                            if (orderByComparator.isAscending() ^ previous) {
699                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
700                                            }
701                                            else {
702                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
703                                            }
704                                    }
705                                    else {
706                                            if (orderByComparator.isAscending() ^ previous) {
707                                                    query.append(WHERE_GREATER_THAN);
708                                            }
709                                            else {
710                                                    query.append(WHERE_LESSER_THAN);
711                                            }
712                                    }
713                            }
714    
715                            query.append(ORDER_BY_CLAUSE);
716    
717                            for (int i = 0; i < orderByFields.length; i++) {
718                                    query.append(_ORDER_BY_ENTITY_ALIAS);
719                                    query.append(orderByFields[i]);
720    
721                                    if ((i + 1) < orderByFields.length) {
722                                            if (orderByComparator.isAscending() ^ previous) {
723                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
724                                            }
725                                            else {
726                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
727                                            }
728                                    }
729                                    else {
730                                            if (orderByComparator.isAscending() ^ previous) {
731                                                    query.append(ORDER_BY_ASC);
732                                            }
733                                            else {
734                                                    query.append(ORDER_BY_DESC);
735                                            }
736                                    }
737                            }
738                    }
739    
740                    String sql = query.toString();
741    
742                    Query q = session.createQuery(sql);
743    
744                    q.setFirstResult(0);
745                    q.setMaxResults(2);
746    
747                    QueryPos qPos = QueryPos.getInstance(q);
748    
749                    qPos.add(groupId);
750    
751                    if (orderByComparator != null) {
752                            Object[] values = orderByComparator.getOrderByValues(mbBan);
753    
754                            for (Object value : values) {
755                                    qPos.add(value);
756                            }
757                    }
758    
759                    List<MBBan> list = q.list();
760    
761                    if (list.size() == 2) {
762                            return list.get(1);
763                    }
764                    else {
765                            return null;
766                    }
767            }
768    
769            /**
770             * Finds all the message boards bans where userId = &#63;.
771             *
772             * @param userId the user id to search with
773             * @return the matching message boards bans
774             * @throws SystemException if a system exception occurred
775             */
776            public List<MBBan> findByUserId(long userId) throws SystemException {
777                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
778            }
779    
780            /**
781             * Finds a range of all the message boards bans where userId = &#63;.
782             *
783             * <p>
784             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
785             * </p>
786             *
787             * @param userId the user id to search with
788             * @param start the lower bound of the range of message boards bans to return
789             * @param end the upper bound of the range of message boards bans to return (not inclusive)
790             * @return the range of matching message boards bans
791             * @throws SystemException if a system exception occurred
792             */
793            public List<MBBan> findByUserId(long userId, int start, int end)
794                    throws SystemException {
795                    return findByUserId(userId, start, end, null);
796            }
797    
798            /**
799             * Finds an ordered range of all the message boards bans where userId = &#63;.
800             *
801             * <p>
802             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
803             * </p>
804             *
805             * @param userId the user id to search with
806             * @param start the lower bound of the range of message boards bans to return
807             * @param end the upper bound of the range of message boards bans to return (not inclusive)
808             * @param orderByComparator the comparator to order the results by
809             * @return the ordered range of matching message boards bans
810             * @throws SystemException if a system exception occurred
811             */
812            public List<MBBan> findByUserId(long userId, int start, int end,
813                    OrderByComparator orderByComparator) throws SystemException {
814                    Object[] finderArgs = new Object[] {
815                                    userId,
816                                    
817                                    String.valueOf(start), String.valueOf(end),
818                                    String.valueOf(orderByComparator)
819                            };
820    
821                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_USERID,
822                                    finderArgs, this);
823    
824                    if (list == null) {
825                            StringBundler query = null;
826    
827                            if (orderByComparator != null) {
828                                    query = new StringBundler(3 +
829                                                    (orderByComparator.getOrderByFields().length * 3));
830                            }
831                            else {
832                                    query = new StringBundler(2);
833                            }
834    
835                            query.append(_SQL_SELECT_MBBAN_WHERE);
836    
837                            query.append(_FINDER_COLUMN_USERID_USERID_2);
838    
839                            if (orderByComparator != null) {
840                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
841                                            orderByComparator);
842                            }
843    
844                            String sql = query.toString();
845    
846                            Session session = null;
847    
848                            try {
849                                    session = openSession();
850    
851                                    Query q = session.createQuery(sql);
852    
853                                    QueryPos qPos = QueryPos.getInstance(q);
854    
855                                    qPos.add(userId);
856    
857                                    list = (List<MBBan>)QueryUtil.list(q, getDialect(), start, end);
858                            }
859                            catch (Exception e) {
860                                    throw processException(e);
861                            }
862                            finally {
863                                    if (list == null) {
864                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_USERID,
865                                                    finderArgs);
866                                    }
867                                    else {
868                                            cacheResult(list);
869    
870                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_USERID,
871                                                    finderArgs, list);
872                                    }
873    
874                                    closeSession(session);
875                            }
876                    }
877    
878                    return list;
879            }
880    
881            /**
882             * Finds the first message boards ban in the ordered set where userId = &#63;.
883             *
884             * <p>
885             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
886             * </p>
887             *
888             * @param userId the user id to search with
889             * @param orderByComparator the comparator to order the set by
890             * @return the first matching message boards ban
891             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
892             * @throws SystemException if a system exception occurred
893             */
894            public MBBan findByUserId_First(long userId,
895                    OrderByComparator orderByComparator)
896                    throws NoSuchBanException, SystemException {
897                    List<MBBan> list = findByUserId(userId, 0, 1, orderByComparator);
898    
899                    if (list.isEmpty()) {
900                            StringBundler msg = new StringBundler(4);
901    
902                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
903    
904                            msg.append("userId=");
905                            msg.append(userId);
906    
907                            msg.append(StringPool.CLOSE_CURLY_BRACE);
908    
909                            throw new NoSuchBanException(msg.toString());
910                    }
911                    else {
912                            return list.get(0);
913                    }
914            }
915    
916            /**
917             * Finds the last message boards ban in the ordered set where userId = &#63;.
918             *
919             * <p>
920             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
921             * </p>
922             *
923             * @param userId the user id to search with
924             * @param orderByComparator the comparator to order the set by
925             * @return the last matching message boards ban
926             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
927             * @throws SystemException if a system exception occurred
928             */
929            public MBBan findByUserId_Last(long userId,
930                    OrderByComparator orderByComparator)
931                    throws NoSuchBanException, SystemException {
932                    int count = countByUserId(userId);
933    
934                    List<MBBan> list = findByUserId(userId, count - 1, count,
935                                    orderByComparator);
936    
937                    if (list.isEmpty()) {
938                            StringBundler msg = new StringBundler(4);
939    
940                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
941    
942                            msg.append("userId=");
943                            msg.append(userId);
944    
945                            msg.append(StringPool.CLOSE_CURLY_BRACE);
946    
947                            throw new NoSuchBanException(msg.toString());
948                    }
949                    else {
950                            return list.get(0);
951                    }
952            }
953    
954            /**
955             * Finds the message boards bans before and after the current message boards ban in the ordered set where userId = &#63;.
956             *
957             * <p>
958             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
959             * </p>
960             *
961             * @param banId the primary key of the current message boards ban
962             * @param userId the user id to search with
963             * @param orderByComparator the comparator to order the set by
964             * @return the previous, current, and next message boards ban
965             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
966             * @throws SystemException if a system exception occurred
967             */
968            public MBBan[] findByUserId_PrevAndNext(long banId, long userId,
969                    OrderByComparator orderByComparator)
970                    throws NoSuchBanException, SystemException {
971                    MBBan mbBan = findByPrimaryKey(banId);
972    
973                    Session session = null;
974    
975                    try {
976                            session = openSession();
977    
978                            MBBan[] array = new MBBanImpl[3];
979    
980                            array[0] = getByUserId_PrevAndNext(session, mbBan, userId,
981                                            orderByComparator, true);
982    
983                            array[1] = mbBan;
984    
985                            array[2] = getByUserId_PrevAndNext(session, mbBan, userId,
986                                            orderByComparator, false);
987    
988                            return array;
989                    }
990                    catch (Exception e) {
991                            throw processException(e);
992                    }
993                    finally {
994                            closeSession(session);
995                    }
996            }
997    
998            protected MBBan getByUserId_PrevAndNext(Session session, MBBan mbBan,
999                    long userId, OrderByComparator orderByComparator, boolean previous) {
1000                    StringBundler query = null;
1001    
1002                    if (orderByComparator != null) {
1003                            query = new StringBundler(6 +
1004                                            (orderByComparator.getOrderByFields().length * 6));
1005                    }
1006                    else {
1007                            query = new StringBundler(3);
1008                    }
1009    
1010                    query.append(_SQL_SELECT_MBBAN_WHERE);
1011    
1012                    query.append(_FINDER_COLUMN_USERID_USERID_2);
1013    
1014                    if (orderByComparator != null) {
1015                            String[] orderByFields = orderByComparator.getOrderByFields();
1016    
1017                            if (orderByFields.length > 0) {
1018                                    query.append(WHERE_AND);
1019                            }
1020    
1021                            for (int i = 0; i < orderByFields.length; i++) {
1022                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1023                                    query.append(orderByFields[i]);
1024    
1025                                    if ((i + 1) < orderByFields.length) {
1026                                            if (orderByComparator.isAscending() ^ previous) {
1027                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1028                                            }
1029                                            else {
1030                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1031                                            }
1032                                    }
1033                                    else {
1034                                            if (orderByComparator.isAscending() ^ previous) {
1035                                                    query.append(WHERE_GREATER_THAN);
1036                                            }
1037                                            else {
1038                                                    query.append(WHERE_LESSER_THAN);
1039                                            }
1040                                    }
1041                            }
1042    
1043                            query.append(ORDER_BY_CLAUSE);
1044    
1045                            for (int i = 0; i < orderByFields.length; i++) {
1046                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1047                                    query.append(orderByFields[i]);
1048    
1049                                    if ((i + 1) < orderByFields.length) {
1050                                            if (orderByComparator.isAscending() ^ previous) {
1051                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1052                                            }
1053                                            else {
1054                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1055                                            }
1056                                    }
1057                                    else {
1058                                            if (orderByComparator.isAscending() ^ previous) {
1059                                                    query.append(ORDER_BY_ASC);
1060                                            }
1061                                            else {
1062                                                    query.append(ORDER_BY_DESC);
1063                                            }
1064                                    }
1065                            }
1066                    }
1067    
1068                    String sql = query.toString();
1069    
1070                    Query q = session.createQuery(sql);
1071    
1072                    q.setFirstResult(0);
1073                    q.setMaxResults(2);
1074    
1075                    QueryPos qPos = QueryPos.getInstance(q);
1076    
1077                    qPos.add(userId);
1078    
1079                    if (orderByComparator != null) {
1080                            Object[] values = orderByComparator.getOrderByValues(mbBan);
1081    
1082                            for (Object value : values) {
1083                                    qPos.add(value);
1084                            }
1085                    }
1086    
1087                    List<MBBan> list = q.list();
1088    
1089                    if (list.size() == 2) {
1090                            return list.get(1);
1091                    }
1092                    else {
1093                            return null;
1094                    }
1095            }
1096    
1097            /**
1098             * Finds all the message boards bans where banUserId = &#63;.
1099             *
1100             * @param banUserId the ban user id to search with
1101             * @return the matching message boards bans
1102             * @throws SystemException if a system exception occurred
1103             */
1104            public List<MBBan> findByBanUserId(long banUserId)
1105                    throws SystemException {
1106                    return findByBanUserId(banUserId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1107                            null);
1108            }
1109    
1110            /**
1111             * Finds a range of all the message boards bans where banUserId = &#63;.
1112             *
1113             * <p>
1114             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1115             * </p>
1116             *
1117             * @param banUserId the ban user id to search with
1118             * @param start the lower bound of the range of message boards bans to return
1119             * @param end the upper bound of the range of message boards bans to return (not inclusive)
1120             * @return the range of matching message boards bans
1121             * @throws SystemException if a system exception occurred
1122             */
1123            public List<MBBan> findByBanUserId(long banUserId, int start, int end)
1124                    throws SystemException {
1125                    return findByBanUserId(banUserId, start, end, null);
1126            }
1127    
1128            /**
1129             * Finds an ordered range of all the message boards bans where banUserId = &#63;.
1130             *
1131             * <p>
1132             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1133             * </p>
1134             *
1135             * @param banUserId the ban user id to search with
1136             * @param start the lower bound of the range of message boards bans to return
1137             * @param end the upper bound of the range of message boards bans to return (not inclusive)
1138             * @param orderByComparator the comparator to order the results by
1139             * @return the ordered range of matching message boards bans
1140             * @throws SystemException if a system exception occurred
1141             */
1142            public List<MBBan> findByBanUserId(long banUserId, int start, int end,
1143                    OrderByComparator orderByComparator) throws SystemException {
1144                    Object[] finderArgs = new Object[] {
1145                                    banUserId,
1146                                    
1147                                    String.valueOf(start), String.valueOf(end),
1148                                    String.valueOf(orderByComparator)
1149                            };
1150    
1151                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_BANUSERID,
1152                                    finderArgs, this);
1153    
1154                    if (list == null) {
1155                            StringBundler query = null;
1156    
1157                            if (orderByComparator != null) {
1158                                    query = new StringBundler(3 +
1159                                                    (orderByComparator.getOrderByFields().length * 3));
1160                            }
1161                            else {
1162                                    query = new StringBundler(2);
1163                            }
1164    
1165                            query.append(_SQL_SELECT_MBBAN_WHERE);
1166    
1167                            query.append(_FINDER_COLUMN_BANUSERID_BANUSERID_2);
1168    
1169                            if (orderByComparator != null) {
1170                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1171                                            orderByComparator);
1172                            }
1173    
1174                            String sql = query.toString();
1175    
1176                            Session session = null;
1177    
1178                            try {
1179                                    session = openSession();
1180    
1181                                    Query q = session.createQuery(sql);
1182    
1183                                    QueryPos qPos = QueryPos.getInstance(q);
1184    
1185                                    qPos.add(banUserId);
1186    
1187                                    list = (List<MBBan>)QueryUtil.list(q, getDialect(), start, end);
1188                            }
1189                            catch (Exception e) {
1190                                    throw processException(e);
1191                            }
1192                            finally {
1193                                    if (list == null) {
1194                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_BANUSERID,
1195                                                    finderArgs);
1196                                    }
1197                                    else {
1198                                            cacheResult(list);
1199    
1200                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_BANUSERID,
1201                                                    finderArgs, list);
1202                                    }
1203    
1204                                    closeSession(session);
1205                            }
1206                    }
1207    
1208                    return list;
1209            }
1210    
1211            /**
1212             * Finds the first message boards ban in the ordered set where banUserId = &#63;.
1213             *
1214             * <p>
1215             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1216             * </p>
1217             *
1218             * @param banUserId the ban user id to search with
1219             * @param orderByComparator the comparator to order the set by
1220             * @return the first matching message boards ban
1221             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
1222             * @throws SystemException if a system exception occurred
1223             */
1224            public MBBan findByBanUserId_First(long banUserId,
1225                    OrderByComparator orderByComparator)
1226                    throws NoSuchBanException, SystemException {
1227                    List<MBBan> list = findByBanUserId(banUserId, 0, 1, orderByComparator);
1228    
1229                    if (list.isEmpty()) {
1230                            StringBundler msg = new StringBundler(4);
1231    
1232                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1233    
1234                            msg.append("banUserId=");
1235                            msg.append(banUserId);
1236    
1237                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1238    
1239                            throw new NoSuchBanException(msg.toString());
1240                    }
1241                    else {
1242                            return list.get(0);
1243                    }
1244            }
1245    
1246            /**
1247             * Finds the last message boards ban in the ordered set where banUserId = &#63;.
1248             *
1249             * <p>
1250             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1251             * </p>
1252             *
1253             * @param banUserId the ban user id to search with
1254             * @param orderByComparator the comparator to order the set by
1255             * @return the last matching message boards ban
1256             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
1257             * @throws SystemException if a system exception occurred
1258             */
1259            public MBBan findByBanUserId_Last(long banUserId,
1260                    OrderByComparator orderByComparator)
1261                    throws NoSuchBanException, SystemException {
1262                    int count = countByBanUserId(banUserId);
1263    
1264                    List<MBBan> list = findByBanUserId(banUserId, count - 1, count,
1265                                    orderByComparator);
1266    
1267                    if (list.isEmpty()) {
1268                            StringBundler msg = new StringBundler(4);
1269    
1270                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1271    
1272                            msg.append("banUserId=");
1273                            msg.append(banUserId);
1274    
1275                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1276    
1277                            throw new NoSuchBanException(msg.toString());
1278                    }
1279                    else {
1280                            return list.get(0);
1281                    }
1282            }
1283    
1284            /**
1285             * Finds the message boards bans before and after the current message boards ban in the ordered set where banUserId = &#63;.
1286             *
1287             * <p>
1288             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1289             * </p>
1290             *
1291             * @param banId the primary key of the current message boards ban
1292             * @param banUserId the ban user id to search with
1293             * @param orderByComparator the comparator to order the set by
1294             * @return the previous, current, and next message boards ban
1295             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
1296             * @throws SystemException if a system exception occurred
1297             */
1298            public MBBan[] findByBanUserId_PrevAndNext(long banId, long banUserId,
1299                    OrderByComparator orderByComparator)
1300                    throws NoSuchBanException, SystemException {
1301                    MBBan mbBan = findByPrimaryKey(banId);
1302    
1303                    Session session = null;
1304    
1305                    try {
1306                            session = openSession();
1307    
1308                            MBBan[] array = new MBBanImpl[3];
1309    
1310                            array[0] = getByBanUserId_PrevAndNext(session, mbBan, banUserId,
1311                                            orderByComparator, true);
1312    
1313                            array[1] = mbBan;
1314    
1315                            array[2] = getByBanUserId_PrevAndNext(session, mbBan, banUserId,
1316                                            orderByComparator, false);
1317    
1318                            return array;
1319                    }
1320                    catch (Exception e) {
1321                            throw processException(e);
1322                    }
1323                    finally {
1324                            closeSession(session);
1325                    }
1326            }
1327    
1328            protected MBBan getByBanUserId_PrevAndNext(Session session, MBBan mbBan,
1329                    long banUserId, OrderByComparator orderByComparator, boolean previous) {
1330                    StringBundler query = null;
1331    
1332                    if (orderByComparator != null) {
1333                            query = new StringBundler(6 +
1334                                            (orderByComparator.getOrderByFields().length * 6));
1335                    }
1336                    else {
1337                            query = new StringBundler(3);
1338                    }
1339    
1340                    query.append(_SQL_SELECT_MBBAN_WHERE);
1341    
1342                    query.append(_FINDER_COLUMN_BANUSERID_BANUSERID_2);
1343    
1344                    if (orderByComparator != null) {
1345                            String[] orderByFields = orderByComparator.getOrderByFields();
1346    
1347                            if (orderByFields.length > 0) {
1348                                    query.append(WHERE_AND);
1349                            }
1350    
1351                            for (int i = 0; i < orderByFields.length; i++) {
1352                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1353                                    query.append(orderByFields[i]);
1354    
1355                                    if ((i + 1) < orderByFields.length) {
1356                                            if (orderByComparator.isAscending() ^ previous) {
1357                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1358                                            }
1359                                            else {
1360                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1361                                            }
1362                                    }
1363                                    else {
1364                                            if (orderByComparator.isAscending() ^ previous) {
1365                                                    query.append(WHERE_GREATER_THAN);
1366                                            }
1367                                            else {
1368                                                    query.append(WHERE_LESSER_THAN);
1369                                            }
1370                                    }
1371                            }
1372    
1373                            query.append(ORDER_BY_CLAUSE);
1374    
1375                            for (int i = 0; i < orderByFields.length; i++) {
1376                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1377                                    query.append(orderByFields[i]);
1378    
1379                                    if ((i + 1) < orderByFields.length) {
1380                                            if (orderByComparator.isAscending() ^ previous) {
1381                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1382                                            }
1383                                            else {
1384                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1385                                            }
1386                                    }
1387                                    else {
1388                                            if (orderByComparator.isAscending() ^ previous) {
1389                                                    query.append(ORDER_BY_ASC);
1390                                            }
1391                                            else {
1392                                                    query.append(ORDER_BY_DESC);
1393                                            }
1394                                    }
1395                            }
1396                    }
1397    
1398                    String sql = query.toString();
1399    
1400                    Query q = session.createQuery(sql);
1401    
1402                    q.setFirstResult(0);
1403                    q.setMaxResults(2);
1404    
1405                    QueryPos qPos = QueryPos.getInstance(q);
1406    
1407                    qPos.add(banUserId);
1408    
1409                    if (orderByComparator != null) {
1410                            Object[] values = orderByComparator.getOrderByValues(mbBan);
1411    
1412                            for (Object value : values) {
1413                                    qPos.add(value);
1414                            }
1415                    }
1416    
1417                    List<MBBan> list = q.list();
1418    
1419                    if (list.size() == 2) {
1420                            return list.get(1);
1421                    }
1422                    else {
1423                            return null;
1424                    }
1425            }
1426    
1427            /**
1428             * Finds the message boards ban where groupId = &#63; and banUserId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchBanException} if it could not be found.
1429             *
1430             * @param groupId the group id to search with
1431             * @param banUserId the ban user id to search with
1432             * @return the matching message boards ban
1433             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
1434             * @throws SystemException if a system exception occurred
1435             */
1436            public MBBan findByG_B(long groupId, long banUserId)
1437                    throws NoSuchBanException, SystemException {
1438                    MBBan mbBan = fetchByG_B(groupId, banUserId);
1439    
1440                    if (mbBan == null) {
1441                            StringBundler msg = new StringBundler(6);
1442    
1443                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1444    
1445                            msg.append("groupId=");
1446                            msg.append(groupId);
1447    
1448                            msg.append(", banUserId=");
1449                            msg.append(banUserId);
1450    
1451                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1452    
1453                            if (_log.isWarnEnabled()) {
1454                                    _log.warn(msg.toString());
1455                            }
1456    
1457                            throw new NoSuchBanException(msg.toString());
1458                    }
1459    
1460                    return mbBan;
1461            }
1462    
1463            /**
1464             * Finds the message boards ban where groupId = &#63; and banUserId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1465             *
1466             * @param groupId the group id to search with
1467             * @param banUserId the ban user id to search with
1468             * @return the matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
1469             * @throws SystemException if a system exception occurred
1470             */
1471            public MBBan fetchByG_B(long groupId, long banUserId)
1472                    throws SystemException {
1473                    return fetchByG_B(groupId, banUserId, true);
1474            }
1475    
1476            /**
1477             * Finds the message boards ban where groupId = &#63; and banUserId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1478             *
1479             * @param groupId the group id to search with
1480             * @param banUserId the ban user id to search with
1481             * @return the matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
1482             * @throws SystemException if a system exception occurred
1483             */
1484            public MBBan fetchByG_B(long groupId, long banUserId,
1485                    boolean retrieveFromCache) throws SystemException {
1486                    Object[] finderArgs = new Object[] { groupId, banUserId };
1487    
1488                    Object result = null;
1489    
1490                    if (retrieveFromCache) {
1491                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_B,
1492                                            finderArgs, this);
1493                    }
1494    
1495                    if (result == null) {
1496                            StringBundler query = new StringBundler(3);
1497    
1498                            query.append(_SQL_SELECT_MBBAN_WHERE);
1499    
1500                            query.append(_FINDER_COLUMN_G_B_GROUPID_2);
1501    
1502                            query.append(_FINDER_COLUMN_G_B_BANUSERID_2);
1503    
1504                            String sql = query.toString();
1505    
1506                            Session session = null;
1507    
1508                            try {
1509                                    session = openSession();
1510    
1511                                    Query q = session.createQuery(sql);
1512    
1513                                    QueryPos qPos = QueryPos.getInstance(q);
1514    
1515                                    qPos.add(groupId);
1516    
1517                                    qPos.add(banUserId);
1518    
1519                                    List<MBBan> list = q.list();
1520    
1521                                    result = list;
1522    
1523                                    MBBan mbBan = null;
1524    
1525                                    if (list.isEmpty()) {
1526                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_B,
1527                                                    finderArgs, list);
1528                                    }
1529                                    else {
1530                                            mbBan = list.get(0);
1531    
1532                                            cacheResult(mbBan);
1533    
1534                                            if ((mbBan.getGroupId() != groupId) ||
1535                                                            (mbBan.getBanUserId() != banUserId)) {
1536                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_B,
1537                                                            finderArgs, mbBan);
1538                                            }
1539                                    }
1540    
1541                                    return mbBan;
1542                            }
1543                            catch (Exception e) {
1544                                    throw processException(e);
1545                            }
1546                            finally {
1547                                    if (result == null) {
1548                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_B,
1549                                                    finderArgs);
1550                                    }
1551    
1552                                    closeSession(session);
1553                            }
1554                    }
1555                    else {
1556                            if (result instanceof List<?>) {
1557                                    return null;
1558                            }
1559                            else {
1560                                    return (MBBan)result;
1561                            }
1562                    }
1563            }
1564    
1565            /**
1566             * Finds all the message boards bans.
1567             *
1568             * @return the message boards bans
1569             * @throws SystemException if a system exception occurred
1570             */
1571            public List<MBBan> findAll() throws SystemException {
1572                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1573            }
1574    
1575            /**
1576             * Finds a range of all the message boards bans.
1577             *
1578             * <p>
1579             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1580             * </p>
1581             *
1582             * @param start the lower bound of the range of message boards bans to return
1583             * @param end the upper bound of the range of message boards bans to return (not inclusive)
1584             * @return the range of message boards bans
1585             * @throws SystemException if a system exception occurred
1586             */
1587            public List<MBBan> findAll(int start, int end) throws SystemException {
1588                    return findAll(start, end, null);
1589            }
1590    
1591            /**
1592             * Finds an ordered range of all the message boards bans.
1593             *
1594             * <p>
1595             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
1596             * </p>
1597             *
1598             * @param start the lower bound of the range of message boards bans to return
1599             * @param end the upper bound of the range of message boards bans to return (not inclusive)
1600             * @param orderByComparator the comparator to order the results by
1601             * @return the ordered range of message boards bans
1602             * @throws SystemException if a system exception occurred
1603             */
1604            public List<MBBan> findAll(int start, int end,
1605                    OrderByComparator orderByComparator) throws SystemException {
1606                    Object[] finderArgs = new Object[] {
1607                                    String.valueOf(start), String.valueOf(end),
1608                                    String.valueOf(orderByComparator)
1609                            };
1610    
1611                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
1612                                    finderArgs, this);
1613    
1614                    if (list == null) {
1615                            StringBundler query = null;
1616                            String sql = null;
1617    
1618                            if (orderByComparator != null) {
1619                                    query = new StringBundler(2 +
1620                                                    (orderByComparator.getOrderByFields().length * 3));
1621    
1622                                    query.append(_SQL_SELECT_MBBAN);
1623    
1624                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1625                                            orderByComparator);
1626    
1627                                    sql = query.toString();
1628                            }
1629                            else {
1630                                    sql = _SQL_SELECT_MBBAN;
1631                            }
1632    
1633                            Session session = null;
1634    
1635                            try {
1636                                    session = openSession();
1637    
1638                                    Query q = session.createQuery(sql);
1639    
1640                                    if (orderByComparator == null) {
1641                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
1642                                                            end, false);
1643    
1644                                            Collections.sort(list);
1645                                    }
1646                                    else {
1647                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
1648                                                            end);
1649                                    }
1650                            }
1651                            catch (Exception e) {
1652                                    throw processException(e);
1653                            }
1654                            finally {
1655                                    if (list == null) {
1656                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
1657                                                    finderArgs);
1658                                    }
1659                                    else {
1660                                            cacheResult(list);
1661    
1662                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
1663                                                    list);
1664                                    }
1665    
1666                                    closeSession(session);
1667                            }
1668                    }
1669    
1670                    return list;
1671            }
1672    
1673            /**
1674             * Removes all the message boards bans where groupId = &#63; from the database.
1675             *
1676             * @param groupId the group id to search with
1677             * @throws SystemException if a system exception occurred
1678             */
1679            public void removeByGroupId(long groupId) throws SystemException {
1680                    for (MBBan mbBan : findByGroupId(groupId)) {
1681                            remove(mbBan);
1682                    }
1683            }
1684    
1685            /**
1686             * Removes all the message boards bans where userId = &#63; from the database.
1687             *
1688             * @param userId the user id to search with
1689             * @throws SystemException if a system exception occurred
1690             */
1691            public void removeByUserId(long userId) throws SystemException {
1692                    for (MBBan mbBan : findByUserId(userId)) {
1693                            remove(mbBan);
1694                    }
1695            }
1696    
1697            /**
1698             * Removes all the message boards bans where banUserId = &#63; from the database.
1699             *
1700             * @param banUserId the ban user id to search with
1701             * @throws SystemException if a system exception occurred
1702             */
1703            public void removeByBanUserId(long banUserId) throws SystemException {
1704                    for (MBBan mbBan : findByBanUserId(banUserId)) {
1705                            remove(mbBan);
1706                    }
1707            }
1708    
1709            /**
1710             * Removes the message boards ban where groupId = &#63; and banUserId = &#63; from the database.
1711             *
1712             * @param groupId the group id to search with
1713             * @param banUserId the ban user id to search with
1714             * @throws SystemException if a system exception occurred
1715             */
1716            public void removeByG_B(long groupId, long banUserId)
1717                    throws NoSuchBanException, SystemException {
1718                    MBBan mbBan = findByG_B(groupId, banUserId);
1719    
1720                    remove(mbBan);
1721            }
1722    
1723            /**
1724             * Removes all the message boards bans from the database.
1725             *
1726             * @throws SystemException if a system exception occurred
1727             */
1728            public void removeAll() throws SystemException {
1729                    for (MBBan mbBan : findAll()) {
1730                            remove(mbBan);
1731                    }
1732            }
1733    
1734            /**
1735             * Counts all the message boards bans where groupId = &#63;.
1736             *
1737             * @param groupId the group id to search with
1738             * @return the number of matching message boards bans
1739             * @throws SystemException if a system exception occurred
1740             */
1741            public int countByGroupId(long groupId) throws SystemException {
1742                    Object[] finderArgs = new Object[] { groupId };
1743    
1744                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
1745                                    finderArgs, this);
1746    
1747                    if (count == null) {
1748                            StringBundler query = new StringBundler(2);
1749    
1750                            query.append(_SQL_COUNT_MBBAN_WHERE);
1751    
1752                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1753    
1754                            String sql = query.toString();
1755    
1756                            Session session = null;
1757    
1758                            try {
1759                                    session = openSession();
1760    
1761                                    Query q = session.createQuery(sql);
1762    
1763                                    QueryPos qPos = QueryPos.getInstance(q);
1764    
1765                                    qPos.add(groupId);
1766    
1767                                    count = (Long)q.uniqueResult();
1768                            }
1769                            catch (Exception e) {
1770                                    throw processException(e);
1771                            }
1772                            finally {
1773                                    if (count == null) {
1774                                            count = Long.valueOf(0);
1775                                    }
1776    
1777                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
1778                                            finderArgs, count);
1779    
1780                                    closeSession(session);
1781                            }
1782                    }
1783    
1784                    return count.intValue();
1785            }
1786    
1787            /**
1788             * Counts all the message boards bans where userId = &#63;.
1789             *
1790             * @param userId the user id to search with
1791             * @return the number of matching message boards bans
1792             * @throws SystemException if a system exception occurred
1793             */
1794            public int countByUserId(long userId) throws SystemException {
1795                    Object[] finderArgs = new Object[] { userId };
1796    
1797                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_USERID,
1798                                    finderArgs, this);
1799    
1800                    if (count == null) {
1801                            StringBundler query = new StringBundler(2);
1802    
1803                            query.append(_SQL_COUNT_MBBAN_WHERE);
1804    
1805                            query.append(_FINDER_COLUMN_USERID_USERID_2);
1806    
1807                            String sql = query.toString();
1808    
1809                            Session session = null;
1810    
1811                            try {
1812                                    session = openSession();
1813    
1814                                    Query q = session.createQuery(sql);
1815    
1816                                    QueryPos qPos = QueryPos.getInstance(q);
1817    
1818                                    qPos.add(userId);
1819    
1820                                    count = (Long)q.uniqueResult();
1821                            }
1822                            catch (Exception e) {
1823                                    throw processException(e);
1824                            }
1825                            finally {
1826                                    if (count == null) {
1827                                            count = Long.valueOf(0);
1828                                    }
1829    
1830                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_USERID,
1831                                            finderArgs, count);
1832    
1833                                    closeSession(session);
1834                            }
1835                    }
1836    
1837                    return count.intValue();
1838            }
1839    
1840            /**
1841             * Counts all the message boards bans where banUserId = &#63;.
1842             *
1843             * @param banUserId the ban user id to search with
1844             * @return the number of matching message boards bans
1845             * @throws SystemException if a system exception occurred
1846             */
1847            public int countByBanUserId(long banUserId) throws SystemException {
1848                    Object[] finderArgs = new Object[] { banUserId };
1849    
1850                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_BANUSERID,
1851                                    finderArgs, this);
1852    
1853                    if (count == null) {
1854                            StringBundler query = new StringBundler(2);
1855    
1856                            query.append(_SQL_COUNT_MBBAN_WHERE);
1857    
1858                            query.append(_FINDER_COLUMN_BANUSERID_BANUSERID_2);
1859    
1860                            String sql = query.toString();
1861    
1862                            Session session = null;
1863    
1864                            try {
1865                                    session = openSession();
1866    
1867                                    Query q = session.createQuery(sql);
1868    
1869                                    QueryPos qPos = QueryPos.getInstance(q);
1870    
1871                                    qPos.add(banUserId);
1872    
1873                                    count = (Long)q.uniqueResult();
1874                            }
1875                            catch (Exception e) {
1876                                    throw processException(e);
1877                            }
1878                            finally {
1879                                    if (count == null) {
1880                                            count = Long.valueOf(0);
1881                                    }
1882    
1883                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_BANUSERID,
1884                                            finderArgs, count);
1885    
1886                                    closeSession(session);
1887                            }
1888                    }
1889    
1890                    return count.intValue();
1891            }
1892    
1893            /**
1894             * Counts all the message boards bans where groupId = &#63; and banUserId = &#63;.
1895             *
1896             * @param groupId the group id to search with
1897             * @param banUserId the ban user id to search with
1898             * @return the number of matching message boards bans
1899             * @throws SystemException if a system exception occurred
1900             */
1901            public int countByG_B(long groupId, long banUserId)
1902                    throws SystemException {
1903                    Object[] finderArgs = new Object[] { groupId, banUserId };
1904    
1905                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_B,
1906                                    finderArgs, this);
1907    
1908                    if (count == null) {
1909                            StringBundler query = new StringBundler(3);
1910    
1911                            query.append(_SQL_COUNT_MBBAN_WHERE);
1912    
1913                            query.append(_FINDER_COLUMN_G_B_GROUPID_2);
1914    
1915                            query.append(_FINDER_COLUMN_G_B_BANUSERID_2);
1916    
1917                            String sql = query.toString();
1918    
1919                            Session session = null;
1920    
1921                            try {
1922                                    session = openSession();
1923    
1924                                    Query q = session.createQuery(sql);
1925    
1926                                    QueryPos qPos = QueryPos.getInstance(q);
1927    
1928                                    qPos.add(groupId);
1929    
1930                                    qPos.add(banUserId);
1931    
1932                                    count = (Long)q.uniqueResult();
1933                            }
1934                            catch (Exception e) {
1935                                    throw processException(e);
1936                            }
1937                            finally {
1938                                    if (count == null) {
1939                                            count = Long.valueOf(0);
1940                                    }
1941    
1942                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_B, finderArgs,
1943                                            count);
1944    
1945                                    closeSession(session);
1946                            }
1947                    }
1948    
1949                    return count.intValue();
1950            }
1951    
1952            /**
1953             * Counts all the message boards bans.
1954             *
1955             * @return the number of message boards bans
1956             * @throws SystemException if a system exception occurred
1957             */
1958            public int countAll() throws SystemException {
1959                    Object[] finderArgs = new Object[0];
1960    
1961                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1962                                    finderArgs, this);
1963    
1964                    if (count == null) {
1965                            Session session = null;
1966    
1967                            try {
1968                                    session = openSession();
1969    
1970                                    Query q = session.createQuery(_SQL_COUNT_MBBAN);
1971    
1972                                    count = (Long)q.uniqueResult();
1973                            }
1974                            catch (Exception e) {
1975                                    throw processException(e);
1976                            }
1977                            finally {
1978                                    if (count == null) {
1979                                            count = Long.valueOf(0);
1980                                    }
1981    
1982                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
1983                                            count);
1984    
1985                                    closeSession(session);
1986                            }
1987                    }
1988    
1989                    return count.intValue();
1990            }
1991    
1992            /**
1993             * Initializes the message boards ban persistence.
1994             */
1995            public void afterPropertiesSet() {
1996                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1997                                            com.liferay.portal.util.PropsUtil.get(
1998                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBBan")));
1999    
2000                    if (listenerClassNames.length > 0) {
2001                            try {
2002                                    List<ModelListener<MBBan>> listenersList = new ArrayList<ModelListener<MBBan>>();
2003    
2004                                    for (String listenerClassName : listenerClassNames) {
2005                                            listenersList.add((ModelListener<MBBan>)InstanceFactory.newInstance(
2006                                                            listenerClassName));
2007                                    }
2008    
2009                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
2010                            }
2011                            catch (Exception e) {
2012                                    _log.error(e);
2013                            }
2014                    }
2015            }
2016    
2017            public void destroy() {
2018                    EntityCacheUtil.removeCache(MBBanImpl.class.getName());
2019                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
2020                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
2021            }
2022    
2023            @BeanReference(type = MBBanPersistence.class)
2024            protected MBBanPersistence mbBanPersistence;
2025            @BeanReference(type = MBCategoryPersistence.class)
2026            protected MBCategoryPersistence mbCategoryPersistence;
2027            @BeanReference(type = MBDiscussionPersistence.class)
2028            protected MBDiscussionPersistence mbDiscussionPersistence;
2029            @BeanReference(type = MBMailingListPersistence.class)
2030            protected MBMailingListPersistence mbMailingListPersistence;
2031            @BeanReference(type = MBMessagePersistence.class)
2032            protected MBMessagePersistence mbMessagePersistence;
2033            @BeanReference(type = MBMessageFlagPersistence.class)
2034            protected MBMessageFlagPersistence mbMessageFlagPersistence;
2035            @BeanReference(type = MBStatsUserPersistence.class)
2036            protected MBStatsUserPersistence mbStatsUserPersistence;
2037            @BeanReference(type = MBThreadPersistence.class)
2038            protected MBThreadPersistence mbThreadPersistence;
2039            @BeanReference(type = ResourcePersistence.class)
2040            protected ResourcePersistence resourcePersistence;
2041            @BeanReference(type = UserPersistence.class)
2042            protected UserPersistence userPersistence;
2043            private static final String _SQL_SELECT_MBBAN = "SELECT mbBan FROM MBBan mbBan";
2044            private static final String _SQL_SELECT_MBBAN_WHERE = "SELECT mbBan FROM MBBan mbBan WHERE ";
2045            private static final String _SQL_COUNT_MBBAN = "SELECT COUNT(mbBan) FROM MBBan mbBan";
2046            private static final String _SQL_COUNT_MBBAN_WHERE = "SELECT COUNT(mbBan) FROM MBBan mbBan WHERE ";
2047            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbBan.groupId = ?";
2048            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbBan.userId = ?";
2049            private static final String _FINDER_COLUMN_BANUSERID_BANUSERID_2 = "mbBan.banUserId = ?";
2050            private static final String _FINDER_COLUMN_G_B_GROUPID_2 = "mbBan.groupId = ? AND ";
2051            private static final String _FINDER_COLUMN_G_B_BANUSERID_2 = "mbBan.banUserId = ?";
2052            private static final String _ORDER_BY_ENTITY_ALIAS = "mbBan.";
2053            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBBan exists with the primary key ";
2054            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBBan exists with the key {";
2055            private static Log _log = LogFactoryUtil.getLog(MBBanPersistenceImpl.class);
2056    }