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