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