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