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