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