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