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