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