001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.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.SetUtil;
032    import com.liferay.portal.kernel.util.StringBundler;
033    import com.liferay.portal.kernel.util.StringPool;
034    import com.liferay.portal.kernel.util.StringUtil;
035    import com.liferay.portal.kernel.util.UnmodifiableList;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
038    import com.liferay.portal.model.CacheModel;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.messageboards.NoSuchBanException;
043    import com.liferay.portlet.messageboards.model.MBBan;
044    import com.liferay.portlet.messageboards.model.impl.MBBanImpl;
045    import com.liferay.portlet.messageboards.model.impl.MBBanModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    import java.util.Set;
053    
054    /**
055     * The persistence implementation for the message boards ban service.
056     *
057     * <p>
058     * Caching information and settings can be found in <code>portal.properties</code>
059     * </p>
060     *
061     * @author Brian Wing Shun Chan
062     * @see MBBanPersistence
063     * @see MBBanUtil
064     * @generated
065     */
066    public class MBBanPersistenceImpl extends BasePersistenceImpl<MBBan>
067            implements MBBanPersistence {
068            /*
069             * NOTE FOR DEVELOPERS:
070             *
071             * Never modify or reference this class directly. Always use {@link MBBanUtil} to access the message boards ban persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
072             */
073            public static final String FINDER_CLASS_NAME_ENTITY = MBBanImpl.class.getName();
074            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
075                    ".List1";
076            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
077                    ".List2";
078            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
079                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
082                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
085                            MBBanModelImpl.FINDER_CACHE_ENABLED, Long.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
088                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
090                            new String[] {
091                                    String.class.getName(),
092                                    
093                            Integer.class.getName(), Integer.class.getName(),
094                                    OrderByComparator.class.getName()
095                            });
096            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
097                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
099                            new String[] { String.class.getName() },
100                            MBBanModelImpl.UUID_COLUMN_BITMASK);
101            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
102                            MBBanModelImpl.FINDER_CACHE_ENABLED, Long.class,
103                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
104                            new String[] { String.class.getName() });
105    
106            /**
107             * Returns all the message boards bans where uuid = &#63;.
108             *
109             * @param uuid the uuid
110             * @return the matching message boards bans
111             * @throws SystemException if a system exception occurred
112             */
113            @Override
114            public List<MBBan> findByUuid(String uuid) throws SystemException {
115                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
116            }
117    
118            /**
119             * Returns a range of all the message boards bans where uuid = &#63;.
120             *
121             * <p>
122             * 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.
123             * </p>
124             *
125             * @param uuid the uuid
126             * @param start the lower bound of the range of message boards bans
127             * @param end the upper bound of the range of message boards bans (not inclusive)
128             * @return the range of matching message boards bans
129             * @throws SystemException if a system exception occurred
130             */
131            @Override
132            public List<MBBan> findByUuid(String uuid, int start, int end)
133                    throws SystemException {
134                    return findByUuid(uuid, start, end, null);
135            }
136    
137            /**
138             * Returns an ordered range of all the message boards bans where uuid = &#63;.
139             *
140             * <p>
141             * 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.
142             * </p>
143             *
144             * @param uuid the uuid
145             * @param start the lower bound of the range of message boards bans
146             * @param end the upper bound of the range of message boards bans (not inclusive)
147             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
148             * @return the ordered range of matching message boards bans
149             * @throws SystemException if a system exception occurred
150             */
151            @Override
152            public List<MBBan> findByUuid(String uuid, int start, int end,
153                    OrderByComparator orderByComparator) throws SystemException {
154                    boolean pagination = true;
155                    FinderPath finderPath = null;
156                    Object[] finderArgs = null;
157    
158                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
159                                    (orderByComparator == null)) {
160                            pagination = false;
161                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
162                            finderArgs = new Object[] { uuid };
163                    }
164                    else {
165                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
167                    }
168    
169                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(finderPath,
170                                    finderArgs, this);
171    
172                    if ((list != null) && !list.isEmpty()) {
173                            for (MBBan mbBan : list) {
174                                    if (!Validator.equals(uuid, mbBan.getUuid())) {
175                                            list = null;
176    
177                                            break;
178                                    }
179                            }
180                    }
181    
182                    if (list == null) {
183                            StringBundler query = null;
184    
185                            if (orderByComparator != null) {
186                                    query = new StringBundler(3 +
187                                                    (orderByComparator.getOrderByFields().length * 3));
188                            }
189                            else {
190                                    query = new StringBundler(3);
191                            }
192    
193                            query.append(_SQL_SELECT_MBBAN_WHERE);
194    
195                            boolean bindUuid = false;
196    
197                            if (uuid == null) {
198                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
199                            }
200                            else if (uuid.equals(StringPool.BLANK)) {
201                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
202                            }
203                            else {
204                                    bindUuid = true;
205    
206                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
207                            }
208    
209                            if (orderByComparator != null) {
210                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
211                                            orderByComparator);
212                            }
213                            else
214                             if (pagination) {
215                                    query.append(MBBanModelImpl.ORDER_BY_JPQL);
216                            }
217    
218                            String sql = query.toString();
219    
220                            Session session = null;
221    
222                            try {
223                                    session = openSession();
224    
225                                    Query q = session.createQuery(sql);
226    
227                                    QueryPos qPos = QueryPos.getInstance(q);
228    
229                                    if (bindUuid) {
230                                            qPos.add(uuid);
231                                    }
232    
233                                    if (!pagination) {
234                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
235                                                            end, false);
236    
237                                            Collections.sort(list);
238    
239                                            list = new UnmodifiableList<MBBan>(list);
240                                    }
241                                    else {
242                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
243                                                            end);
244                                    }
245    
246                                    cacheResult(list);
247    
248                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
249                            }
250                            catch (Exception e) {
251                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
252    
253                                    throw processException(e);
254                            }
255                            finally {
256                                    closeSession(session);
257                            }
258                    }
259    
260                    return list;
261            }
262    
263            /**
264             * Returns the first message boards ban in the ordered set where uuid = &#63;.
265             *
266             * @param uuid the uuid
267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
268             * @return the first matching message boards ban
269             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
270             * @throws SystemException if a system exception occurred
271             */
272            @Override
273            public MBBan findByUuid_First(String uuid,
274                    OrderByComparator orderByComparator)
275                    throws NoSuchBanException, SystemException {
276                    MBBan mbBan = fetchByUuid_First(uuid, orderByComparator);
277    
278                    if (mbBan != null) {
279                            return mbBan;
280                    }
281    
282                    StringBundler msg = new StringBundler(4);
283    
284                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
285    
286                    msg.append("uuid=");
287                    msg.append(uuid);
288    
289                    msg.append(StringPool.CLOSE_CURLY_BRACE);
290    
291                    throw new NoSuchBanException(msg.toString());
292            }
293    
294            /**
295             * Returns the first message boards ban in the ordered set where uuid = &#63;.
296             *
297             * @param uuid the uuid
298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
299             * @return the first matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
300             * @throws SystemException if a system exception occurred
301             */
302            @Override
303            public MBBan fetchByUuid_First(String uuid,
304                    OrderByComparator orderByComparator) throws SystemException {
305                    List<MBBan> list = findByUuid(uuid, 0, 1, orderByComparator);
306    
307                    if (!list.isEmpty()) {
308                            return list.get(0);
309                    }
310    
311                    return null;
312            }
313    
314            /**
315             * Returns the last message boards ban in the ordered set where uuid = &#63;.
316             *
317             * @param uuid the uuid
318             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
319             * @return the last matching message boards ban
320             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
321             * @throws SystemException if a system exception occurred
322             */
323            @Override
324            public MBBan findByUuid_Last(String uuid,
325                    OrderByComparator orderByComparator)
326                    throws NoSuchBanException, SystemException {
327                    MBBan mbBan = fetchByUuid_Last(uuid, orderByComparator);
328    
329                    if (mbBan != null) {
330                            return mbBan;
331                    }
332    
333                    StringBundler msg = new StringBundler(4);
334    
335                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
336    
337                    msg.append("uuid=");
338                    msg.append(uuid);
339    
340                    msg.append(StringPool.CLOSE_CURLY_BRACE);
341    
342                    throw new NoSuchBanException(msg.toString());
343            }
344    
345            /**
346             * Returns the last message boards ban in the ordered set where uuid = &#63;.
347             *
348             * @param uuid the uuid
349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
350             * @return the last matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
351             * @throws SystemException if a system exception occurred
352             */
353            @Override
354            public MBBan fetchByUuid_Last(String uuid,
355                    OrderByComparator orderByComparator) throws SystemException {
356                    int count = countByUuid(uuid);
357    
358                    if (count == 0) {
359                            return null;
360                    }
361    
362                    List<MBBan> list = findByUuid(uuid, count - 1, count, orderByComparator);
363    
364                    if (!list.isEmpty()) {
365                            return list.get(0);
366                    }
367    
368                    return null;
369            }
370    
371            /**
372             * Returns the message boards bans before and after the current message boards ban in the ordered set where uuid = &#63;.
373             *
374             * @param banId the primary key of the current message boards ban
375             * @param uuid the uuid
376             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
377             * @return the previous, current, and next message boards ban
378             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
379             * @throws SystemException if a system exception occurred
380             */
381            @Override
382            public MBBan[] findByUuid_PrevAndNext(long banId, String uuid,
383                    OrderByComparator orderByComparator)
384                    throws NoSuchBanException, SystemException {
385                    MBBan mbBan = findByPrimaryKey(banId);
386    
387                    Session session = null;
388    
389                    try {
390                            session = openSession();
391    
392                            MBBan[] array = new MBBanImpl[3];
393    
394                            array[0] = getByUuid_PrevAndNext(session, mbBan, uuid,
395                                            orderByComparator, true);
396    
397                            array[1] = mbBan;
398    
399                            array[2] = getByUuid_PrevAndNext(session, mbBan, uuid,
400                                            orderByComparator, false);
401    
402                            return array;
403                    }
404                    catch (Exception e) {
405                            throw processException(e);
406                    }
407                    finally {
408                            closeSession(session);
409                    }
410            }
411    
412            protected MBBan getByUuid_PrevAndNext(Session session, MBBan mbBan,
413                    String uuid, OrderByComparator orderByComparator, boolean previous) {
414                    StringBundler query = null;
415    
416                    if (orderByComparator != null) {
417                            query = new StringBundler(6 +
418                                            (orderByComparator.getOrderByFields().length * 6));
419                    }
420                    else {
421                            query = new StringBundler(3);
422                    }
423    
424                    query.append(_SQL_SELECT_MBBAN_WHERE);
425    
426                    boolean bindUuid = false;
427    
428                    if (uuid == null) {
429                            query.append(_FINDER_COLUMN_UUID_UUID_1);
430                    }
431                    else if (uuid.equals(StringPool.BLANK)) {
432                            query.append(_FINDER_COLUMN_UUID_UUID_3);
433                    }
434                    else {
435                            bindUuid = true;
436    
437                            query.append(_FINDER_COLUMN_UUID_UUID_2);
438                    }
439    
440                    if (orderByComparator != null) {
441                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
442    
443                            if (orderByConditionFields.length > 0) {
444                                    query.append(WHERE_AND);
445                            }
446    
447                            for (int i = 0; i < orderByConditionFields.length; i++) {
448                                    query.append(_ORDER_BY_ENTITY_ALIAS);
449                                    query.append(orderByConditionFields[i]);
450    
451                                    if ((i + 1) < orderByConditionFields.length) {
452                                            if (orderByComparator.isAscending() ^ previous) {
453                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
454                                            }
455                                            else {
456                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
457                                            }
458                                    }
459                                    else {
460                                            if (orderByComparator.isAscending() ^ previous) {
461                                                    query.append(WHERE_GREATER_THAN);
462                                            }
463                                            else {
464                                                    query.append(WHERE_LESSER_THAN);
465                                            }
466                                    }
467                            }
468    
469                            query.append(ORDER_BY_CLAUSE);
470    
471                            String[] orderByFields = orderByComparator.getOrderByFields();
472    
473                            for (int i = 0; i < orderByFields.length; i++) {
474                                    query.append(_ORDER_BY_ENTITY_ALIAS);
475                                    query.append(orderByFields[i]);
476    
477                                    if ((i + 1) < orderByFields.length) {
478                                            if (orderByComparator.isAscending() ^ previous) {
479                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
480                                            }
481                                            else {
482                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
483                                            }
484                                    }
485                                    else {
486                                            if (orderByComparator.isAscending() ^ previous) {
487                                                    query.append(ORDER_BY_ASC);
488                                            }
489                                            else {
490                                                    query.append(ORDER_BY_DESC);
491                                            }
492                                    }
493                            }
494                    }
495                    else {
496                            query.append(MBBanModelImpl.ORDER_BY_JPQL);
497                    }
498    
499                    String sql = query.toString();
500    
501                    Query q = session.createQuery(sql);
502    
503                    q.setFirstResult(0);
504                    q.setMaxResults(2);
505    
506                    QueryPos qPos = QueryPos.getInstance(q);
507    
508                    if (bindUuid) {
509                            qPos.add(uuid);
510                    }
511    
512                    if (orderByComparator != null) {
513                            Object[] values = orderByComparator.getOrderByConditionValues(mbBan);
514    
515                            for (Object value : values) {
516                                    qPos.add(value);
517                            }
518                    }
519    
520                    List<MBBan> list = q.list();
521    
522                    if (list.size() == 2) {
523                            return list.get(1);
524                    }
525                    else {
526                            return null;
527                    }
528            }
529    
530            /**
531             * Removes all the message boards bans where uuid = &#63; from the database.
532             *
533             * @param uuid the uuid
534             * @throws SystemException if a system exception occurred
535             */
536            @Override
537            public void removeByUuid(String uuid) throws SystemException {
538                    for (MBBan mbBan : findByUuid(uuid, QueryUtil.ALL_POS,
539                                    QueryUtil.ALL_POS, null)) {
540                            remove(mbBan);
541                    }
542            }
543    
544            /**
545             * Returns the number of message boards bans where uuid = &#63;.
546             *
547             * @param uuid the uuid
548             * @return the number of matching message boards bans
549             * @throws SystemException if a system exception occurred
550             */
551            @Override
552            public int countByUuid(String uuid) throws SystemException {
553                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
554    
555                    Object[] finderArgs = new Object[] { uuid };
556    
557                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
558                                    this);
559    
560                    if (count == null) {
561                            StringBundler query = new StringBundler(2);
562    
563                            query.append(_SQL_COUNT_MBBAN_WHERE);
564    
565                            boolean bindUuid = false;
566    
567                            if (uuid == null) {
568                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
569                            }
570                            else if (uuid.equals(StringPool.BLANK)) {
571                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
572                            }
573                            else {
574                                    bindUuid = true;
575    
576                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
577                            }
578    
579                            String sql = query.toString();
580    
581                            Session session = null;
582    
583                            try {
584                                    session = openSession();
585    
586                                    Query q = session.createQuery(sql);
587    
588                                    QueryPos qPos = QueryPos.getInstance(q);
589    
590                                    if (bindUuid) {
591                                            qPos.add(uuid);
592                                    }
593    
594                                    count = (Long)q.uniqueResult();
595    
596                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
597                            }
598                            catch (Exception e) {
599                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
600    
601                                    throw processException(e);
602                            }
603                            finally {
604                                    closeSession(session);
605                            }
606                    }
607    
608                    return count.intValue();
609            }
610    
611            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbBan.uuid IS NULL";
612            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbBan.uuid = ?";
613            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbBan.uuid IS NULL OR mbBan.uuid = '')";
614            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
615                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
616                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
617                            new String[] { String.class.getName(), Long.class.getName() },
618                            MBBanModelImpl.UUID_COLUMN_BITMASK |
619                            MBBanModelImpl.GROUPID_COLUMN_BITMASK);
620            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
621                            MBBanModelImpl.FINDER_CACHE_ENABLED, Long.class,
622                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
623                            new String[] { String.class.getName(), Long.class.getName() });
624    
625            /**
626             * Returns the message boards ban where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchBanException} if it could not be found.
627             *
628             * @param uuid the uuid
629             * @param groupId the group ID
630             * @return the matching message boards ban
631             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
632             * @throws SystemException if a system exception occurred
633             */
634            @Override
635            public MBBan findByUUID_G(String uuid, long groupId)
636                    throws NoSuchBanException, SystemException {
637                    MBBan mbBan = fetchByUUID_G(uuid, groupId);
638    
639                    if (mbBan == null) {
640                            StringBundler msg = new StringBundler(6);
641    
642                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
643    
644                            msg.append("uuid=");
645                            msg.append(uuid);
646    
647                            msg.append(", groupId=");
648                            msg.append(groupId);
649    
650                            msg.append(StringPool.CLOSE_CURLY_BRACE);
651    
652                            if (_log.isWarnEnabled()) {
653                                    _log.warn(msg.toString());
654                            }
655    
656                            throw new NoSuchBanException(msg.toString());
657                    }
658    
659                    return mbBan;
660            }
661    
662            /**
663             * Returns the message boards ban where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
664             *
665             * @param uuid the uuid
666             * @param groupId the group ID
667             * @return the matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
668             * @throws SystemException if a system exception occurred
669             */
670            @Override
671            public MBBan fetchByUUID_G(String uuid, long groupId)
672                    throws SystemException {
673                    return fetchByUUID_G(uuid, groupId, true);
674            }
675    
676            /**
677             * Returns the message boards ban where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
678             *
679             * @param uuid the uuid
680             * @param groupId the group ID
681             * @param retrieveFromCache whether to use the finder cache
682             * @return the matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
683             * @throws SystemException if a system exception occurred
684             */
685            @Override
686            public MBBan fetchByUUID_G(String uuid, long groupId,
687                    boolean retrieveFromCache) throws SystemException {
688                    Object[] finderArgs = new Object[] { uuid, groupId };
689    
690                    Object result = null;
691    
692                    if (retrieveFromCache) {
693                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
694                                            finderArgs, this);
695                    }
696    
697                    if (result instanceof MBBan) {
698                            MBBan mbBan = (MBBan)result;
699    
700                            if (!Validator.equals(uuid, mbBan.getUuid()) ||
701                                            (groupId != mbBan.getGroupId())) {
702                                    result = null;
703                            }
704                    }
705    
706                    if (result == null) {
707                            StringBundler query = new StringBundler(4);
708    
709                            query.append(_SQL_SELECT_MBBAN_WHERE);
710    
711                            boolean bindUuid = false;
712    
713                            if (uuid == null) {
714                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
715                            }
716                            else if (uuid.equals(StringPool.BLANK)) {
717                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
718                            }
719                            else {
720                                    bindUuid = true;
721    
722                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
723                            }
724    
725                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
726    
727                            String sql = query.toString();
728    
729                            Session session = null;
730    
731                            try {
732                                    session = openSession();
733    
734                                    Query q = session.createQuery(sql);
735    
736                                    QueryPos qPos = QueryPos.getInstance(q);
737    
738                                    if (bindUuid) {
739                                            qPos.add(uuid);
740                                    }
741    
742                                    qPos.add(groupId);
743    
744                                    List<MBBan> list = q.list();
745    
746                                    if (list.isEmpty()) {
747                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
748                                                    finderArgs, list);
749                                    }
750                                    else {
751                                            MBBan mbBan = list.get(0);
752    
753                                            result = mbBan;
754    
755                                            cacheResult(mbBan);
756    
757                                            if ((mbBan.getUuid() == null) ||
758                                                            !mbBan.getUuid().equals(uuid) ||
759                                                            (mbBan.getGroupId() != groupId)) {
760                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
761                                                            finderArgs, mbBan);
762                                            }
763                                    }
764                            }
765                            catch (Exception e) {
766                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
767                                            finderArgs);
768    
769                                    throw processException(e);
770                            }
771                            finally {
772                                    closeSession(session);
773                            }
774                    }
775    
776                    if (result instanceof List<?>) {
777                            return null;
778                    }
779                    else {
780                            return (MBBan)result;
781                    }
782            }
783    
784            /**
785             * Removes the message boards ban where uuid = &#63; and groupId = &#63; from the database.
786             *
787             * @param uuid the uuid
788             * @param groupId the group ID
789             * @return the message boards ban that was removed
790             * @throws SystemException if a system exception occurred
791             */
792            @Override
793            public MBBan removeByUUID_G(String uuid, long groupId)
794                    throws NoSuchBanException, SystemException {
795                    MBBan mbBan = findByUUID_G(uuid, groupId);
796    
797                    return remove(mbBan);
798            }
799    
800            /**
801             * Returns the number of message boards bans where uuid = &#63; and groupId = &#63;.
802             *
803             * @param uuid the uuid
804             * @param groupId the group ID
805             * @return the number of matching message boards bans
806             * @throws SystemException if a system exception occurred
807             */
808            @Override
809            public int countByUUID_G(String uuid, long groupId)
810                    throws SystemException {
811                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
812    
813                    Object[] finderArgs = new Object[] { uuid, groupId };
814    
815                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
816                                    this);
817    
818                    if (count == null) {
819                            StringBundler query = new StringBundler(3);
820    
821                            query.append(_SQL_COUNT_MBBAN_WHERE);
822    
823                            boolean bindUuid = false;
824    
825                            if (uuid == null) {
826                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
827                            }
828                            else if (uuid.equals(StringPool.BLANK)) {
829                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
830                            }
831                            else {
832                                    bindUuid = true;
833    
834                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
835                            }
836    
837                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
838    
839                            String sql = query.toString();
840    
841                            Session session = null;
842    
843                            try {
844                                    session = openSession();
845    
846                                    Query q = session.createQuery(sql);
847    
848                                    QueryPos qPos = QueryPos.getInstance(q);
849    
850                                    if (bindUuid) {
851                                            qPos.add(uuid);
852                                    }
853    
854                                    qPos.add(groupId);
855    
856                                    count = (Long)q.uniqueResult();
857    
858                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
859                            }
860                            catch (Exception e) {
861                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
862    
863                                    throw processException(e);
864                            }
865                            finally {
866                                    closeSession(session);
867                            }
868                    }
869    
870                    return count.intValue();
871            }
872    
873            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbBan.uuid IS NULL AND ";
874            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbBan.uuid = ? AND ";
875            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbBan.uuid IS NULL OR mbBan.uuid = '') AND ";
876            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbBan.groupId = ?";
877            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
878                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
879                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
880                            new String[] {
881                                    String.class.getName(), Long.class.getName(),
882                                    
883                            Integer.class.getName(), Integer.class.getName(),
884                                    OrderByComparator.class.getName()
885                            });
886            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
887                    new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
888                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
889                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
890                            new String[] { String.class.getName(), Long.class.getName() },
891                            MBBanModelImpl.UUID_COLUMN_BITMASK |
892                            MBBanModelImpl.COMPANYID_COLUMN_BITMASK);
893            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
894                            MBBanModelImpl.FINDER_CACHE_ENABLED, Long.class,
895                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
896                            new String[] { String.class.getName(), Long.class.getName() });
897    
898            /**
899             * Returns all the message boards bans where uuid = &#63; and companyId = &#63;.
900             *
901             * @param uuid the uuid
902             * @param companyId the company ID
903             * @return the matching message boards bans
904             * @throws SystemException if a system exception occurred
905             */
906            @Override
907            public List<MBBan> findByUuid_C(String uuid, long companyId)
908                    throws SystemException {
909                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
910                            QueryUtil.ALL_POS, null);
911            }
912    
913            /**
914             * Returns a range of all the message boards bans where uuid = &#63; and companyId = &#63;.
915             *
916             * <p>
917             * 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.
918             * </p>
919             *
920             * @param uuid the uuid
921             * @param companyId the company ID
922             * @param start the lower bound of the range of message boards bans
923             * @param end the upper bound of the range of message boards bans (not inclusive)
924             * @return the range of matching message boards bans
925             * @throws SystemException if a system exception occurred
926             */
927            @Override
928            public List<MBBan> findByUuid_C(String uuid, long companyId, int start,
929                    int end) throws SystemException {
930                    return findByUuid_C(uuid, companyId, start, end, null);
931            }
932    
933            /**
934             * Returns an ordered range of all the message boards bans where uuid = &#63; and companyId = &#63;.
935             *
936             * <p>
937             * 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.
938             * </p>
939             *
940             * @param uuid the uuid
941             * @param companyId the company ID
942             * @param start the lower bound of the range of message boards bans
943             * @param end the upper bound of the range of message boards bans (not inclusive)
944             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
945             * @return the ordered range of matching message boards bans
946             * @throws SystemException if a system exception occurred
947             */
948            @Override
949            public List<MBBan> findByUuid_C(String uuid, long companyId, int start,
950                    int end, OrderByComparator orderByComparator) throws SystemException {
951                    boolean pagination = true;
952                    FinderPath finderPath = null;
953                    Object[] finderArgs = null;
954    
955                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
956                                    (orderByComparator == null)) {
957                            pagination = false;
958                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
959                            finderArgs = new Object[] { uuid, companyId };
960                    }
961                    else {
962                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
963                            finderArgs = new Object[] {
964                                            uuid, companyId,
965                                            
966                                            start, end, orderByComparator
967                                    };
968                    }
969    
970                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(finderPath,
971                                    finderArgs, this);
972    
973                    if ((list != null) && !list.isEmpty()) {
974                            for (MBBan mbBan : list) {
975                                    if (!Validator.equals(uuid, mbBan.getUuid()) ||
976                                                    (companyId != mbBan.getCompanyId())) {
977                                            list = null;
978    
979                                            break;
980                                    }
981                            }
982                    }
983    
984                    if (list == null) {
985                            StringBundler query = null;
986    
987                            if (orderByComparator != null) {
988                                    query = new StringBundler(4 +
989                                                    (orderByComparator.getOrderByFields().length * 3));
990                            }
991                            else {
992                                    query = new StringBundler(4);
993                            }
994    
995                            query.append(_SQL_SELECT_MBBAN_WHERE);
996    
997                            boolean bindUuid = false;
998    
999                            if (uuid == null) {
1000                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1001                            }
1002                            else if (uuid.equals(StringPool.BLANK)) {
1003                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1004                            }
1005                            else {
1006                                    bindUuid = true;
1007    
1008                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1009                            }
1010    
1011                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1012    
1013                            if (orderByComparator != null) {
1014                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1015                                            orderByComparator);
1016                            }
1017                            else
1018                             if (pagination) {
1019                                    query.append(MBBanModelImpl.ORDER_BY_JPQL);
1020                            }
1021    
1022                            String sql = query.toString();
1023    
1024                            Session session = null;
1025    
1026                            try {
1027                                    session = openSession();
1028    
1029                                    Query q = session.createQuery(sql);
1030    
1031                                    QueryPos qPos = QueryPos.getInstance(q);
1032    
1033                                    if (bindUuid) {
1034                                            qPos.add(uuid);
1035                                    }
1036    
1037                                    qPos.add(companyId);
1038    
1039                                    if (!pagination) {
1040                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
1041                                                            end, false);
1042    
1043                                            Collections.sort(list);
1044    
1045                                            list = new UnmodifiableList<MBBan>(list);
1046                                    }
1047                                    else {
1048                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
1049                                                            end);
1050                                    }
1051    
1052                                    cacheResult(list);
1053    
1054                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1055                            }
1056                            catch (Exception e) {
1057                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1058    
1059                                    throw processException(e);
1060                            }
1061                            finally {
1062                                    closeSession(session);
1063                            }
1064                    }
1065    
1066                    return list;
1067            }
1068    
1069            /**
1070             * Returns the first message boards ban in the ordered set where uuid = &#63; and companyId = &#63;.
1071             *
1072             * @param uuid the uuid
1073             * @param companyId the company ID
1074             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1075             * @return the first matching message boards ban
1076             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
1077             * @throws SystemException if a system exception occurred
1078             */
1079            @Override
1080            public MBBan findByUuid_C_First(String uuid, long companyId,
1081                    OrderByComparator orderByComparator)
1082                    throws NoSuchBanException, SystemException {
1083                    MBBan mbBan = fetchByUuid_C_First(uuid, companyId, orderByComparator);
1084    
1085                    if (mbBan != null) {
1086                            return mbBan;
1087                    }
1088    
1089                    StringBundler msg = new StringBundler(6);
1090    
1091                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1092    
1093                    msg.append("uuid=");
1094                    msg.append(uuid);
1095    
1096                    msg.append(", companyId=");
1097                    msg.append(companyId);
1098    
1099                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1100    
1101                    throw new NoSuchBanException(msg.toString());
1102            }
1103    
1104            /**
1105             * Returns the first message boards ban in the ordered set where uuid = &#63; and companyId = &#63;.
1106             *
1107             * @param uuid the uuid
1108             * @param companyId the company ID
1109             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1110             * @return the first matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
1111             * @throws SystemException if a system exception occurred
1112             */
1113            @Override
1114            public MBBan fetchByUuid_C_First(String uuid, long companyId,
1115                    OrderByComparator orderByComparator) throws SystemException {
1116                    List<MBBan> list = findByUuid_C(uuid, companyId, 0, 1, orderByComparator);
1117    
1118                    if (!list.isEmpty()) {
1119                            return list.get(0);
1120                    }
1121    
1122                    return null;
1123            }
1124    
1125            /**
1126             * Returns the last message boards ban in the ordered set where uuid = &#63; and companyId = &#63;.
1127             *
1128             * @param uuid the uuid
1129             * @param companyId the company ID
1130             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1131             * @return the last matching message boards ban
1132             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
1133             * @throws SystemException if a system exception occurred
1134             */
1135            @Override
1136            public MBBan findByUuid_C_Last(String uuid, long companyId,
1137                    OrderByComparator orderByComparator)
1138                    throws NoSuchBanException, SystemException {
1139                    MBBan mbBan = fetchByUuid_C_Last(uuid, companyId, orderByComparator);
1140    
1141                    if (mbBan != null) {
1142                            return mbBan;
1143                    }
1144    
1145                    StringBundler msg = new StringBundler(6);
1146    
1147                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1148    
1149                    msg.append("uuid=");
1150                    msg.append(uuid);
1151    
1152                    msg.append(", companyId=");
1153                    msg.append(companyId);
1154    
1155                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1156    
1157                    throw new NoSuchBanException(msg.toString());
1158            }
1159    
1160            /**
1161             * Returns the last message boards ban in the ordered set where uuid = &#63; and companyId = &#63;.
1162             *
1163             * @param uuid the uuid
1164             * @param companyId the company ID
1165             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1166             * @return the last matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
1167             * @throws SystemException if a system exception occurred
1168             */
1169            @Override
1170            public MBBan fetchByUuid_C_Last(String uuid, long companyId,
1171                    OrderByComparator orderByComparator) throws SystemException {
1172                    int count = countByUuid_C(uuid, companyId);
1173    
1174                    if (count == 0) {
1175                            return null;
1176                    }
1177    
1178                    List<MBBan> list = findByUuid_C(uuid, companyId, count - 1, count,
1179                                    orderByComparator);
1180    
1181                    if (!list.isEmpty()) {
1182                            return list.get(0);
1183                    }
1184    
1185                    return null;
1186            }
1187    
1188            /**
1189             * Returns the message boards bans before and after the current message boards ban in the ordered set where uuid = &#63; and companyId = &#63;.
1190             *
1191             * @param banId the primary key of the current message boards ban
1192             * @param uuid the uuid
1193             * @param companyId the company ID
1194             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1195             * @return the previous, current, and next message boards ban
1196             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
1197             * @throws SystemException if a system exception occurred
1198             */
1199            @Override
1200            public MBBan[] findByUuid_C_PrevAndNext(long banId, String uuid,
1201                    long companyId, OrderByComparator orderByComparator)
1202                    throws NoSuchBanException, SystemException {
1203                    MBBan mbBan = findByPrimaryKey(banId);
1204    
1205                    Session session = null;
1206    
1207                    try {
1208                            session = openSession();
1209    
1210                            MBBan[] array = new MBBanImpl[3];
1211    
1212                            array[0] = getByUuid_C_PrevAndNext(session, mbBan, uuid, companyId,
1213                                            orderByComparator, true);
1214    
1215                            array[1] = mbBan;
1216    
1217                            array[2] = getByUuid_C_PrevAndNext(session, mbBan, uuid, companyId,
1218                                            orderByComparator, false);
1219    
1220                            return array;
1221                    }
1222                    catch (Exception e) {
1223                            throw processException(e);
1224                    }
1225                    finally {
1226                            closeSession(session);
1227                    }
1228            }
1229    
1230            protected MBBan getByUuid_C_PrevAndNext(Session session, MBBan mbBan,
1231                    String uuid, long companyId, OrderByComparator orderByComparator,
1232                    boolean previous) {
1233                    StringBundler query = null;
1234    
1235                    if (orderByComparator != null) {
1236                            query = new StringBundler(6 +
1237                                            (orderByComparator.getOrderByFields().length * 6));
1238                    }
1239                    else {
1240                            query = new StringBundler(3);
1241                    }
1242    
1243                    query.append(_SQL_SELECT_MBBAN_WHERE);
1244    
1245                    boolean bindUuid = false;
1246    
1247                    if (uuid == null) {
1248                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1249                    }
1250                    else if (uuid.equals(StringPool.BLANK)) {
1251                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1252                    }
1253                    else {
1254                            bindUuid = true;
1255    
1256                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1257                    }
1258    
1259                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1260    
1261                    if (orderByComparator != null) {
1262                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1263    
1264                            if (orderByConditionFields.length > 0) {
1265                                    query.append(WHERE_AND);
1266                            }
1267    
1268                            for (int i = 0; i < orderByConditionFields.length; i++) {
1269                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1270                                    query.append(orderByConditionFields[i]);
1271    
1272                                    if ((i + 1) < orderByConditionFields.length) {
1273                                            if (orderByComparator.isAscending() ^ previous) {
1274                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1275                                            }
1276                                            else {
1277                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1278                                            }
1279                                    }
1280                                    else {
1281                                            if (orderByComparator.isAscending() ^ previous) {
1282                                                    query.append(WHERE_GREATER_THAN);
1283                                            }
1284                                            else {
1285                                                    query.append(WHERE_LESSER_THAN);
1286                                            }
1287                                    }
1288                            }
1289    
1290                            query.append(ORDER_BY_CLAUSE);
1291    
1292                            String[] orderByFields = orderByComparator.getOrderByFields();
1293    
1294                            for (int i = 0; i < orderByFields.length; i++) {
1295                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1296                                    query.append(orderByFields[i]);
1297    
1298                                    if ((i + 1) < orderByFields.length) {
1299                                            if (orderByComparator.isAscending() ^ previous) {
1300                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1301                                            }
1302                                            else {
1303                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1304                                            }
1305                                    }
1306                                    else {
1307                                            if (orderByComparator.isAscending() ^ previous) {
1308                                                    query.append(ORDER_BY_ASC);
1309                                            }
1310                                            else {
1311                                                    query.append(ORDER_BY_DESC);
1312                                            }
1313                                    }
1314                            }
1315                    }
1316                    else {
1317                            query.append(MBBanModelImpl.ORDER_BY_JPQL);
1318                    }
1319    
1320                    String sql = query.toString();
1321    
1322                    Query q = session.createQuery(sql);
1323    
1324                    q.setFirstResult(0);
1325                    q.setMaxResults(2);
1326    
1327                    QueryPos qPos = QueryPos.getInstance(q);
1328    
1329                    if (bindUuid) {
1330                            qPos.add(uuid);
1331                    }
1332    
1333                    qPos.add(companyId);
1334    
1335                    if (orderByComparator != null) {
1336                            Object[] values = orderByComparator.getOrderByConditionValues(mbBan);
1337    
1338                            for (Object value : values) {
1339                                    qPos.add(value);
1340                            }
1341                    }
1342    
1343                    List<MBBan> list = q.list();
1344    
1345                    if (list.size() == 2) {
1346                            return list.get(1);
1347                    }
1348                    else {
1349                            return null;
1350                    }
1351            }
1352    
1353            /**
1354             * Removes all the message boards bans where uuid = &#63; and companyId = &#63; from the database.
1355             *
1356             * @param uuid the uuid
1357             * @param companyId the company ID
1358             * @throws SystemException if a system exception occurred
1359             */
1360            @Override
1361            public void removeByUuid_C(String uuid, long companyId)
1362                    throws SystemException {
1363                    for (MBBan mbBan : findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1364                                    QueryUtil.ALL_POS, null)) {
1365                            remove(mbBan);
1366                    }
1367            }
1368    
1369            /**
1370             * Returns the number of message boards bans where uuid = &#63; and companyId = &#63;.
1371             *
1372             * @param uuid the uuid
1373             * @param companyId the company ID
1374             * @return the number of matching message boards bans
1375             * @throws SystemException if a system exception occurred
1376             */
1377            @Override
1378            public int countByUuid_C(String uuid, long companyId)
1379                    throws SystemException {
1380                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1381    
1382                    Object[] finderArgs = new Object[] { uuid, companyId };
1383    
1384                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1385                                    this);
1386    
1387                    if (count == null) {
1388                            StringBundler query = new StringBundler(3);
1389    
1390                            query.append(_SQL_COUNT_MBBAN_WHERE);
1391    
1392                            boolean bindUuid = false;
1393    
1394                            if (uuid == null) {
1395                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1396                            }
1397                            else if (uuid.equals(StringPool.BLANK)) {
1398                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1399                            }
1400                            else {
1401                                    bindUuid = true;
1402    
1403                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1404                            }
1405    
1406                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1407    
1408                            String sql = query.toString();
1409    
1410                            Session session = null;
1411    
1412                            try {
1413                                    session = openSession();
1414    
1415                                    Query q = session.createQuery(sql);
1416    
1417                                    QueryPos qPos = QueryPos.getInstance(q);
1418    
1419                                    if (bindUuid) {
1420                                            qPos.add(uuid);
1421                                    }
1422    
1423                                    qPos.add(companyId);
1424    
1425                                    count = (Long)q.uniqueResult();
1426    
1427                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1428                            }
1429                            catch (Exception e) {
1430                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1431    
1432                                    throw processException(e);
1433                            }
1434                            finally {
1435                                    closeSession(session);
1436                            }
1437                    }
1438    
1439                    return count.intValue();
1440            }
1441    
1442            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbBan.uuid IS NULL AND ";
1443            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbBan.uuid = ? AND ";
1444            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbBan.uuid IS NULL OR mbBan.uuid = '') AND ";
1445            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbBan.companyId = ?";
1446            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
1447                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
1448                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1449                            new String[] {
1450                                    Long.class.getName(),
1451                                    
1452                            Integer.class.getName(), Integer.class.getName(),
1453                                    OrderByComparator.class.getName()
1454                            });
1455            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1456                    new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
1457                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
1458                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1459                            new String[] { Long.class.getName() },
1460                            MBBanModelImpl.GROUPID_COLUMN_BITMASK);
1461            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
1462                            MBBanModelImpl.FINDER_CACHE_ENABLED, Long.class,
1463                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1464                            new String[] { Long.class.getName() });
1465    
1466            /**
1467             * Returns all the message boards bans where groupId = &#63;.
1468             *
1469             * @param groupId the group ID
1470             * @return the matching message boards bans
1471             * @throws SystemException if a system exception occurred
1472             */
1473            @Override
1474            public List<MBBan> findByGroupId(long groupId) throws SystemException {
1475                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1476            }
1477    
1478            /**
1479             * Returns a range of all the message boards bans where groupId = &#63;.
1480             *
1481             * <p>
1482             * 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.
1483             * </p>
1484             *
1485             * @param groupId the group ID
1486             * @param start the lower bound of the range of message boards bans
1487             * @param end the upper bound of the range of message boards bans (not inclusive)
1488             * @return the range of matching message boards bans
1489             * @throws SystemException if a system exception occurred
1490             */
1491            @Override
1492            public List<MBBan> findByGroupId(long groupId, int start, int end)
1493                    throws SystemException {
1494                    return findByGroupId(groupId, start, end, null);
1495            }
1496    
1497            /**
1498             * Returns an ordered range of all the message boards bans where groupId = &#63;.
1499             *
1500             * <p>
1501             * 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.
1502             * </p>
1503             *
1504             * @param groupId the group ID
1505             * @param start the lower bound of the range of message boards bans
1506             * @param end the upper bound of the range of message boards bans (not inclusive)
1507             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1508             * @return the ordered range of matching message boards bans
1509             * @throws SystemException if a system exception occurred
1510             */
1511            @Override
1512            public List<MBBan> findByGroupId(long groupId, int start, int end,
1513                    OrderByComparator orderByComparator) throws SystemException {
1514                    boolean pagination = true;
1515                    FinderPath finderPath = null;
1516                    Object[] finderArgs = null;
1517    
1518                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1519                                    (orderByComparator == null)) {
1520                            pagination = false;
1521                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1522                            finderArgs = new Object[] { groupId };
1523                    }
1524                    else {
1525                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1526                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1527                    }
1528    
1529                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(finderPath,
1530                                    finderArgs, this);
1531    
1532                    if ((list != null) && !list.isEmpty()) {
1533                            for (MBBan mbBan : list) {
1534                                    if ((groupId != mbBan.getGroupId())) {
1535                                            list = null;
1536    
1537                                            break;
1538                                    }
1539                            }
1540                    }
1541    
1542                    if (list == null) {
1543                            StringBundler query = null;
1544    
1545                            if (orderByComparator != null) {
1546                                    query = new StringBundler(3 +
1547                                                    (orderByComparator.getOrderByFields().length * 3));
1548                            }
1549                            else {
1550                                    query = new StringBundler(3);
1551                            }
1552    
1553                            query.append(_SQL_SELECT_MBBAN_WHERE);
1554    
1555                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1556    
1557                            if (orderByComparator != null) {
1558                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1559                                            orderByComparator);
1560                            }
1561                            else
1562                             if (pagination) {
1563                                    query.append(MBBanModelImpl.ORDER_BY_JPQL);
1564                            }
1565    
1566                            String sql = query.toString();
1567    
1568                            Session session = null;
1569    
1570                            try {
1571                                    session = openSession();
1572    
1573                                    Query q = session.createQuery(sql);
1574    
1575                                    QueryPos qPos = QueryPos.getInstance(q);
1576    
1577                                    qPos.add(groupId);
1578    
1579                                    if (!pagination) {
1580                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
1581                                                            end, false);
1582    
1583                                            Collections.sort(list);
1584    
1585                                            list = new UnmodifiableList<MBBan>(list);
1586                                    }
1587                                    else {
1588                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
1589                                                            end);
1590                                    }
1591    
1592                                    cacheResult(list);
1593    
1594                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1595                            }
1596                            catch (Exception e) {
1597                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1598    
1599                                    throw processException(e);
1600                            }
1601                            finally {
1602                                    closeSession(session);
1603                            }
1604                    }
1605    
1606                    return list;
1607            }
1608    
1609            /**
1610             * Returns the first message boards ban in the ordered set where groupId = &#63;.
1611             *
1612             * @param groupId the group ID
1613             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1614             * @return the first matching message boards ban
1615             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
1616             * @throws SystemException if a system exception occurred
1617             */
1618            @Override
1619            public MBBan findByGroupId_First(long groupId,
1620                    OrderByComparator orderByComparator)
1621                    throws NoSuchBanException, SystemException {
1622                    MBBan mbBan = fetchByGroupId_First(groupId, orderByComparator);
1623    
1624                    if (mbBan != null) {
1625                            return mbBan;
1626                    }
1627    
1628                    StringBundler msg = new StringBundler(4);
1629    
1630                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1631    
1632                    msg.append("groupId=");
1633                    msg.append(groupId);
1634    
1635                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1636    
1637                    throw new NoSuchBanException(msg.toString());
1638            }
1639    
1640            /**
1641             * Returns the first message boards ban in the ordered set where groupId = &#63;.
1642             *
1643             * @param groupId the group ID
1644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1645             * @return the first matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
1646             * @throws SystemException if a system exception occurred
1647             */
1648            @Override
1649            public MBBan fetchByGroupId_First(long groupId,
1650                    OrderByComparator orderByComparator) throws SystemException {
1651                    List<MBBan> list = findByGroupId(groupId, 0, 1, orderByComparator);
1652    
1653                    if (!list.isEmpty()) {
1654                            return list.get(0);
1655                    }
1656    
1657                    return null;
1658            }
1659    
1660            /**
1661             * Returns the last message boards ban in the ordered set where groupId = &#63;.
1662             *
1663             * @param groupId the group ID
1664             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1665             * @return the last matching message boards ban
1666             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
1667             * @throws SystemException if a system exception occurred
1668             */
1669            @Override
1670            public MBBan findByGroupId_Last(long groupId,
1671                    OrderByComparator orderByComparator)
1672                    throws NoSuchBanException, SystemException {
1673                    MBBan mbBan = fetchByGroupId_Last(groupId, orderByComparator);
1674    
1675                    if (mbBan != null) {
1676                            return mbBan;
1677                    }
1678    
1679                    StringBundler msg = new StringBundler(4);
1680    
1681                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1682    
1683                    msg.append("groupId=");
1684                    msg.append(groupId);
1685    
1686                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1687    
1688                    throw new NoSuchBanException(msg.toString());
1689            }
1690    
1691            /**
1692             * Returns the last message boards ban in the ordered set where groupId = &#63;.
1693             *
1694             * @param groupId the group ID
1695             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1696             * @return the last matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
1697             * @throws SystemException if a system exception occurred
1698             */
1699            @Override
1700            public MBBan fetchByGroupId_Last(long groupId,
1701                    OrderByComparator orderByComparator) throws SystemException {
1702                    int count = countByGroupId(groupId);
1703    
1704                    if (count == 0) {
1705                            return null;
1706                    }
1707    
1708                    List<MBBan> list = findByGroupId(groupId, count - 1, count,
1709                                    orderByComparator);
1710    
1711                    if (!list.isEmpty()) {
1712                            return list.get(0);
1713                    }
1714    
1715                    return null;
1716            }
1717    
1718            /**
1719             * Returns the message boards bans before and after the current message boards ban in the ordered set where groupId = &#63;.
1720             *
1721             * @param banId the primary key of the current message boards ban
1722             * @param groupId the group ID
1723             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1724             * @return the previous, current, and next message boards ban
1725             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
1726             * @throws SystemException if a system exception occurred
1727             */
1728            @Override
1729            public MBBan[] findByGroupId_PrevAndNext(long banId, long groupId,
1730                    OrderByComparator orderByComparator)
1731                    throws NoSuchBanException, SystemException {
1732                    MBBan mbBan = findByPrimaryKey(banId);
1733    
1734                    Session session = null;
1735    
1736                    try {
1737                            session = openSession();
1738    
1739                            MBBan[] array = new MBBanImpl[3];
1740    
1741                            array[0] = getByGroupId_PrevAndNext(session, mbBan, groupId,
1742                                            orderByComparator, true);
1743    
1744                            array[1] = mbBan;
1745    
1746                            array[2] = getByGroupId_PrevAndNext(session, mbBan, groupId,
1747                                            orderByComparator, false);
1748    
1749                            return array;
1750                    }
1751                    catch (Exception e) {
1752                            throw processException(e);
1753                    }
1754                    finally {
1755                            closeSession(session);
1756                    }
1757            }
1758    
1759            protected MBBan getByGroupId_PrevAndNext(Session session, MBBan mbBan,
1760                    long groupId, OrderByComparator orderByComparator, boolean previous) {
1761                    StringBundler query = null;
1762    
1763                    if (orderByComparator != null) {
1764                            query = new StringBundler(6 +
1765                                            (orderByComparator.getOrderByFields().length * 6));
1766                    }
1767                    else {
1768                            query = new StringBundler(3);
1769                    }
1770    
1771                    query.append(_SQL_SELECT_MBBAN_WHERE);
1772    
1773                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1774    
1775                    if (orderByComparator != null) {
1776                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1777    
1778                            if (orderByConditionFields.length > 0) {
1779                                    query.append(WHERE_AND);
1780                            }
1781    
1782                            for (int i = 0; i < orderByConditionFields.length; i++) {
1783                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1784                                    query.append(orderByConditionFields[i]);
1785    
1786                                    if ((i + 1) < orderByConditionFields.length) {
1787                                            if (orderByComparator.isAscending() ^ previous) {
1788                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1789                                            }
1790                                            else {
1791                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1792                                            }
1793                                    }
1794                                    else {
1795                                            if (orderByComparator.isAscending() ^ previous) {
1796                                                    query.append(WHERE_GREATER_THAN);
1797                                            }
1798                                            else {
1799                                                    query.append(WHERE_LESSER_THAN);
1800                                            }
1801                                    }
1802                            }
1803    
1804                            query.append(ORDER_BY_CLAUSE);
1805    
1806                            String[] orderByFields = orderByComparator.getOrderByFields();
1807    
1808                            for (int i = 0; i < orderByFields.length; i++) {
1809                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1810                                    query.append(orderByFields[i]);
1811    
1812                                    if ((i + 1) < orderByFields.length) {
1813                                            if (orderByComparator.isAscending() ^ previous) {
1814                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1815                                            }
1816                                            else {
1817                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1818                                            }
1819                                    }
1820                                    else {
1821                                            if (orderByComparator.isAscending() ^ previous) {
1822                                                    query.append(ORDER_BY_ASC);
1823                                            }
1824                                            else {
1825                                                    query.append(ORDER_BY_DESC);
1826                                            }
1827                                    }
1828                            }
1829                    }
1830                    else {
1831                            query.append(MBBanModelImpl.ORDER_BY_JPQL);
1832                    }
1833    
1834                    String sql = query.toString();
1835    
1836                    Query q = session.createQuery(sql);
1837    
1838                    q.setFirstResult(0);
1839                    q.setMaxResults(2);
1840    
1841                    QueryPos qPos = QueryPos.getInstance(q);
1842    
1843                    qPos.add(groupId);
1844    
1845                    if (orderByComparator != null) {
1846                            Object[] values = orderByComparator.getOrderByConditionValues(mbBan);
1847    
1848                            for (Object value : values) {
1849                                    qPos.add(value);
1850                            }
1851                    }
1852    
1853                    List<MBBan> list = q.list();
1854    
1855                    if (list.size() == 2) {
1856                            return list.get(1);
1857                    }
1858                    else {
1859                            return null;
1860                    }
1861            }
1862    
1863            /**
1864             * Removes all the message boards bans where groupId = &#63; from the database.
1865             *
1866             * @param groupId the group ID
1867             * @throws SystemException if a system exception occurred
1868             */
1869            @Override
1870            public void removeByGroupId(long groupId) throws SystemException {
1871                    for (MBBan mbBan : findByGroupId(groupId, QueryUtil.ALL_POS,
1872                                    QueryUtil.ALL_POS, null)) {
1873                            remove(mbBan);
1874                    }
1875            }
1876    
1877            /**
1878             * Returns the number of message boards bans where groupId = &#63;.
1879             *
1880             * @param groupId the group ID
1881             * @return the number of matching message boards bans
1882             * @throws SystemException if a system exception occurred
1883             */
1884            @Override
1885            public int countByGroupId(long groupId) throws SystemException {
1886                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
1887    
1888                    Object[] finderArgs = new Object[] { groupId };
1889    
1890                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1891                                    this);
1892    
1893                    if (count == null) {
1894                            StringBundler query = new StringBundler(2);
1895    
1896                            query.append(_SQL_COUNT_MBBAN_WHERE);
1897    
1898                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1899    
1900                            String sql = query.toString();
1901    
1902                            Session session = null;
1903    
1904                            try {
1905                                    session = openSession();
1906    
1907                                    Query q = session.createQuery(sql);
1908    
1909                                    QueryPos qPos = QueryPos.getInstance(q);
1910    
1911                                    qPos.add(groupId);
1912    
1913                                    count = (Long)q.uniqueResult();
1914    
1915                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1916                            }
1917                            catch (Exception e) {
1918                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1919    
1920                                    throw processException(e);
1921                            }
1922                            finally {
1923                                    closeSession(session);
1924                            }
1925                    }
1926    
1927                    return count.intValue();
1928            }
1929    
1930            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbBan.groupId = ?";
1931            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
1932                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
1933                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
1934                            new String[] {
1935                                    Long.class.getName(),
1936                                    
1937                            Integer.class.getName(), Integer.class.getName(),
1938                                    OrderByComparator.class.getName()
1939                            });
1940            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
1941                    new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
1942                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
1943                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
1944                            new String[] { Long.class.getName() },
1945                            MBBanModelImpl.USERID_COLUMN_BITMASK);
1946            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
1947                            MBBanModelImpl.FINDER_CACHE_ENABLED, Long.class,
1948                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
1949                            new String[] { Long.class.getName() });
1950    
1951            /**
1952             * Returns all the message boards bans where userId = &#63;.
1953             *
1954             * @param userId the user ID
1955             * @return the matching message boards bans
1956             * @throws SystemException if a system exception occurred
1957             */
1958            @Override
1959            public List<MBBan> findByUserId(long userId) throws SystemException {
1960                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1961            }
1962    
1963            /**
1964             * Returns a range of all the message boards bans where userId = &#63;.
1965             *
1966             * <p>
1967             * 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.
1968             * </p>
1969             *
1970             * @param userId the user ID
1971             * @param start the lower bound of the range of message boards bans
1972             * @param end the upper bound of the range of message boards bans (not inclusive)
1973             * @return the range of matching message boards bans
1974             * @throws SystemException if a system exception occurred
1975             */
1976            @Override
1977            public List<MBBan> findByUserId(long userId, int start, int end)
1978                    throws SystemException {
1979                    return findByUserId(userId, start, end, null);
1980            }
1981    
1982            /**
1983             * Returns an ordered range of all the message boards bans where userId = &#63;.
1984             *
1985             * <p>
1986             * 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.
1987             * </p>
1988             *
1989             * @param userId the user ID
1990             * @param start the lower bound of the range of message boards bans
1991             * @param end the upper bound of the range of message boards bans (not inclusive)
1992             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1993             * @return the ordered range of matching message boards bans
1994             * @throws SystemException if a system exception occurred
1995             */
1996            @Override
1997            public List<MBBan> findByUserId(long userId, int start, int end,
1998                    OrderByComparator orderByComparator) throws SystemException {
1999                    boolean pagination = true;
2000                    FinderPath finderPath = null;
2001                    Object[] finderArgs = null;
2002    
2003                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2004                                    (orderByComparator == null)) {
2005                            pagination = false;
2006                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
2007                            finderArgs = new Object[] { userId };
2008                    }
2009                    else {
2010                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
2011                            finderArgs = new Object[] { userId, start, end, orderByComparator };
2012                    }
2013    
2014                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(finderPath,
2015                                    finderArgs, this);
2016    
2017                    if ((list != null) && !list.isEmpty()) {
2018                            for (MBBan mbBan : list) {
2019                                    if ((userId != mbBan.getUserId())) {
2020                                            list = null;
2021    
2022                                            break;
2023                                    }
2024                            }
2025                    }
2026    
2027                    if (list == null) {
2028                            StringBundler query = null;
2029    
2030                            if (orderByComparator != null) {
2031                                    query = new StringBundler(3 +
2032                                                    (orderByComparator.getOrderByFields().length * 3));
2033                            }
2034                            else {
2035                                    query = new StringBundler(3);
2036                            }
2037    
2038                            query.append(_SQL_SELECT_MBBAN_WHERE);
2039    
2040                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2041    
2042                            if (orderByComparator != null) {
2043                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2044                                            orderByComparator);
2045                            }
2046                            else
2047                             if (pagination) {
2048                                    query.append(MBBanModelImpl.ORDER_BY_JPQL);
2049                            }
2050    
2051                            String sql = query.toString();
2052    
2053                            Session session = null;
2054    
2055                            try {
2056                                    session = openSession();
2057    
2058                                    Query q = session.createQuery(sql);
2059    
2060                                    QueryPos qPos = QueryPos.getInstance(q);
2061    
2062                                    qPos.add(userId);
2063    
2064                                    if (!pagination) {
2065                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
2066                                                            end, false);
2067    
2068                                            Collections.sort(list);
2069    
2070                                            list = new UnmodifiableList<MBBan>(list);
2071                                    }
2072                                    else {
2073                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
2074                                                            end);
2075                                    }
2076    
2077                                    cacheResult(list);
2078    
2079                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2080                            }
2081                            catch (Exception e) {
2082                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2083    
2084                                    throw processException(e);
2085                            }
2086                            finally {
2087                                    closeSession(session);
2088                            }
2089                    }
2090    
2091                    return list;
2092            }
2093    
2094            /**
2095             * Returns the first message boards ban in the ordered set where userId = &#63;.
2096             *
2097             * @param userId the user ID
2098             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2099             * @return the first matching message boards ban
2100             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
2101             * @throws SystemException if a system exception occurred
2102             */
2103            @Override
2104            public MBBan findByUserId_First(long userId,
2105                    OrderByComparator orderByComparator)
2106                    throws NoSuchBanException, SystemException {
2107                    MBBan mbBan = fetchByUserId_First(userId, orderByComparator);
2108    
2109                    if (mbBan != null) {
2110                            return mbBan;
2111                    }
2112    
2113                    StringBundler msg = new StringBundler(4);
2114    
2115                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2116    
2117                    msg.append("userId=");
2118                    msg.append(userId);
2119    
2120                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2121    
2122                    throw new NoSuchBanException(msg.toString());
2123            }
2124    
2125            /**
2126             * Returns the first message boards ban in the ordered set where userId = &#63;.
2127             *
2128             * @param userId the user ID
2129             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2130             * @return the first matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
2131             * @throws SystemException if a system exception occurred
2132             */
2133            @Override
2134            public MBBan fetchByUserId_First(long userId,
2135                    OrderByComparator orderByComparator) throws SystemException {
2136                    List<MBBan> list = findByUserId(userId, 0, 1, orderByComparator);
2137    
2138                    if (!list.isEmpty()) {
2139                            return list.get(0);
2140                    }
2141    
2142                    return null;
2143            }
2144    
2145            /**
2146             * Returns the last message boards ban in the ordered set where userId = &#63;.
2147             *
2148             * @param userId the user ID
2149             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2150             * @return the last matching message boards ban
2151             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
2152             * @throws SystemException if a system exception occurred
2153             */
2154            @Override
2155            public MBBan findByUserId_Last(long userId,
2156                    OrderByComparator orderByComparator)
2157                    throws NoSuchBanException, SystemException {
2158                    MBBan mbBan = fetchByUserId_Last(userId, orderByComparator);
2159    
2160                    if (mbBan != null) {
2161                            return mbBan;
2162                    }
2163    
2164                    StringBundler msg = new StringBundler(4);
2165    
2166                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2167    
2168                    msg.append("userId=");
2169                    msg.append(userId);
2170    
2171                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2172    
2173                    throw new NoSuchBanException(msg.toString());
2174            }
2175    
2176            /**
2177             * Returns the last message boards ban in the ordered set where userId = &#63;.
2178             *
2179             * @param userId the user ID
2180             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2181             * @return the last matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
2182             * @throws SystemException if a system exception occurred
2183             */
2184            @Override
2185            public MBBan fetchByUserId_Last(long userId,
2186                    OrderByComparator orderByComparator) throws SystemException {
2187                    int count = countByUserId(userId);
2188    
2189                    if (count == 0) {
2190                            return null;
2191                    }
2192    
2193                    List<MBBan> list = findByUserId(userId, count - 1, count,
2194                                    orderByComparator);
2195    
2196                    if (!list.isEmpty()) {
2197                            return list.get(0);
2198                    }
2199    
2200                    return null;
2201            }
2202    
2203            /**
2204             * Returns the message boards bans before and after the current message boards ban in the ordered set where userId = &#63;.
2205             *
2206             * @param banId the primary key of the current message boards ban
2207             * @param userId the user ID
2208             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2209             * @return the previous, current, and next message boards ban
2210             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
2211             * @throws SystemException if a system exception occurred
2212             */
2213            @Override
2214            public MBBan[] findByUserId_PrevAndNext(long banId, long userId,
2215                    OrderByComparator orderByComparator)
2216                    throws NoSuchBanException, SystemException {
2217                    MBBan mbBan = findByPrimaryKey(banId);
2218    
2219                    Session session = null;
2220    
2221                    try {
2222                            session = openSession();
2223    
2224                            MBBan[] array = new MBBanImpl[3];
2225    
2226                            array[0] = getByUserId_PrevAndNext(session, mbBan, userId,
2227                                            orderByComparator, true);
2228    
2229                            array[1] = mbBan;
2230    
2231                            array[2] = getByUserId_PrevAndNext(session, mbBan, userId,
2232                                            orderByComparator, false);
2233    
2234                            return array;
2235                    }
2236                    catch (Exception e) {
2237                            throw processException(e);
2238                    }
2239                    finally {
2240                            closeSession(session);
2241                    }
2242            }
2243    
2244            protected MBBan getByUserId_PrevAndNext(Session session, MBBan mbBan,
2245                    long userId, OrderByComparator orderByComparator, boolean previous) {
2246                    StringBundler query = null;
2247    
2248                    if (orderByComparator != null) {
2249                            query = new StringBundler(6 +
2250                                            (orderByComparator.getOrderByFields().length * 6));
2251                    }
2252                    else {
2253                            query = new StringBundler(3);
2254                    }
2255    
2256                    query.append(_SQL_SELECT_MBBAN_WHERE);
2257    
2258                    query.append(_FINDER_COLUMN_USERID_USERID_2);
2259    
2260                    if (orderByComparator != null) {
2261                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2262    
2263                            if (orderByConditionFields.length > 0) {
2264                                    query.append(WHERE_AND);
2265                            }
2266    
2267                            for (int i = 0; i < orderByConditionFields.length; i++) {
2268                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2269                                    query.append(orderByConditionFields[i]);
2270    
2271                                    if ((i + 1) < orderByConditionFields.length) {
2272                                            if (orderByComparator.isAscending() ^ previous) {
2273                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2274                                            }
2275                                            else {
2276                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2277                                            }
2278                                    }
2279                                    else {
2280                                            if (orderByComparator.isAscending() ^ previous) {
2281                                                    query.append(WHERE_GREATER_THAN);
2282                                            }
2283                                            else {
2284                                                    query.append(WHERE_LESSER_THAN);
2285                                            }
2286                                    }
2287                            }
2288    
2289                            query.append(ORDER_BY_CLAUSE);
2290    
2291                            String[] orderByFields = orderByComparator.getOrderByFields();
2292    
2293                            for (int i = 0; i < orderByFields.length; i++) {
2294                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2295                                    query.append(orderByFields[i]);
2296    
2297                                    if ((i + 1) < orderByFields.length) {
2298                                            if (orderByComparator.isAscending() ^ previous) {
2299                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2300                                            }
2301                                            else {
2302                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2303                                            }
2304                                    }
2305                                    else {
2306                                            if (orderByComparator.isAscending() ^ previous) {
2307                                                    query.append(ORDER_BY_ASC);
2308                                            }
2309                                            else {
2310                                                    query.append(ORDER_BY_DESC);
2311                                            }
2312                                    }
2313                            }
2314                    }
2315                    else {
2316                            query.append(MBBanModelImpl.ORDER_BY_JPQL);
2317                    }
2318    
2319                    String sql = query.toString();
2320    
2321                    Query q = session.createQuery(sql);
2322    
2323                    q.setFirstResult(0);
2324                    q.setMaxResults(2);
2325    
2326                    QueryPos qPos = QueryPos.getInstance(q);
2327    
2328                    qPos.add(userId);
2329    
2330                    if (orderByComparator != null) {
2331                            Object[] values = orderByComparator.getOrderByConditionValues(mbBan);
2332    
2333                            for (Object value : values) {
2334                                    qPos.add(value);
2335                            }
2336                    }
2337    
2338                    List<MBBan> list = q.list();
2339    
2340                    if (list.size() == 2) {
2341                            return list.get(1);
2342                    }
2343                    else {
2344                            return null;
2345                    }
2346            }
2347    
2348            /**
2349             * Removes all the message boards bans where userId = &#63; from the database.
2350             *
2351             * @param userId the user ID
2352             * @throws SystemException if a system exception occurred
2353             */
2354            @Override
2355            public void removeByUserId(long userId) throws SystemException {
2356                    for (MBBan mbBan : findByUserId(userId, QueryUtil.ALL_POS,
2357                                    QueryUtil.ALL_POS, null)) {
2358                            remove(mbBan);
2359                    }
2360            }
2361    
2362            /**
2363             * Returns the number of message boards bans where userId = &#63;.
2364             *
2365             * @param userId the user ID
2366             * @return the number of matching message boards bans
2367             * @throws SystemException if a system exception occurred
2368             */
2369            @Override
2370            public int countByUserId(long userId) throws SystemException {
2371                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
2372    
2373                    Object[] finderArgs = new Object[] { userId };
2374    
2375                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2376                                    this);
2377    
2378                    if (count == null) {
2379                            StringBundler query = new StringBundler(2);
2380    
2381                            query.append(_SQL_COUNT_MBBAN_WHERE);
2382    
2383                            query.append(_FINDER_COLUMN_USERID_USERID_2);
2384    
2385                            String sql = query.toString();
2386    
2387                            Session session = null;
2388    
2389                            try {
2390                                    session = openSession();
2391    
2392                                    Query q = session.createQuery(sql);
2393    
2394                                    QueryPos qPos = QueryPos.getInstance(q);
2395    
2396                                    qPos.add(userId);
2397    
2398                                    count = (Long)q.uniqueResult();
2399    
2400                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2401                            }
2402                            catch (Exception e) {
2403                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2404    
2405                                    throw processException(e);
2406                            }
2407                            finally {
2408                                    closeSession(session);
2409                            }
2410                    }
2411    
2412                    return count.intValue();
2413            }
2414    
2415            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbBan.userId = ?";
2416            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_BANUSERID =
2417                    new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
2418                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
2419                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByBanUserId",
2420                            new String[] {
2421                                    Long.class.getName(),
2422                                    
2423                            Integer.class.getName(), Integer.class.getName(),
2424                                    OrderByComparator.class.getName()
2425                            });
2426            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BANUSERID =
2427                    new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
2428                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
2429                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByBanUserId",
2430                            new String[] { Long.class.getName() },
2431                            MBBanModelImpl.BANUSERID_COLUMN_BITMASK);
2432            public static final FinderPath FINDER_PATH_COUNT_BY_BANUSERID = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
2433                            MBBanModelImpl.FINDER_CACHE_ENABLED, Long.class,
2434                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByBanUserId",
2435                            new String[] { Long.class.getName() });
2436    
2437            /**
2438             * Returns all the message boards bans where banUserId = &#63;.
2439             *
2440             * @param banUserId the ban user ID
2441             * @return the matching message boards bans
2442             * @throws SystemException if a system exception occurred
2443             */
2444            @Override
2445            public List<MBBan> findByBanUserId(long banUserId)
2446                    throws SystemException {
2447                    return findByBanUserId(banUserId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2448                            null);
2449            }
2450    
2451            /**
2452             * Returns a range of all the message boards bans where banUserId = &#63;.
2453             *
2454             * <p>
2455             * 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.
2456             * </p>
2457             *
2458             * @param banUserId the ban user ID
2459             * @param start the lower bound of the range of message boards bans
2460             * @param end the upper bound of the range of message boards bans (not inclusive)
2461             * @return the range of matching message boards bans
2462             * @throws SystemException if a system exception occurred
2463             */
2464            @Override
2465            public List<MBBan> findByBanUserId(long banUserId, int start, int end)
2466                    throws SystemException {
2467                    return findByBanUserId(banUserId, start, end, null);
2468            }
2469    
2470            /**
2471             * Returns an ordered range of all the message boards bans where banUserId = &#63;.
2472             *
2473             * <p>
2474             * 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.
2475             * </p>
2476             *
2477             * @param banUserId the ban user ID
2478             * @param start the lower bound of the range of message boards bans
2479             * @param end the upper bound of the range of message boards bans (not inclusive)
2480             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2481             * @return the ordered range of matching message boards bans
2482             * @throws SystemException if a system exception occurred
2483             */
2484            @Override
2485            public List<MBBan> findByBanUserId(long banUserId, int start, int end,
2486                    OrderByComparator orderByComparator) throws SystemException {
2487                    boolean pagination = true;
2488                    FinderPath finderPath = null;
2489                    Object[] finderArgs = null;
2490    
2491                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2492                                    (orderByComparator == null)) {
2493                            pagination = false;
2494                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BANUSERID;
2495                            finderArgs = new Object[] { banUserId };
2496                    }
2497                    else {
2498                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_BANUSERID;
2499                            finderArgs = new Object[] { banUserId, start, end, orderByComparator };
2500                    }
2501    
2502                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(finderPath,
2503                                    finderArgs, this);
2504    
2505                    if ((list != null) && !list.isEmpty()) {
2506                            for (MBBan mbBan : list) {
2507                                    if ((banUserId != mbBan.getBanUserId())) {
2508                                            list = null;
2509    
2510                                            break;
2511                                    }
2512                            }
2513                    }
2514    
2515                    if (list == null) {
2516                            StringBundler query = null;
2517    
2518                            if (orderByComparator != null) {
2519                                    query = new StringBundler(3 +
2520                                                    (orderByComparator.getOrderByFields().length * 3));
2521                            }
2522                            else {
2523                                    query = new StringBundler(3);
2524                            }
2525    
2526                            query.append(_SQL_SELECT_MBBAN_WHERE);
2527    
2528                            query.append(_FINDER_COLUMN_BANUSERID_BANUSERID_2);
2529    
2530                            if (orderByComparator != null) {
2531                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2532                                            orderByComparator);
2533                            }
2534                            else
2535                             if (pagination) {
2536                                    query.append(MBBanModelImpl.ORDER_BY_JPQL);
2537                            }
2538    
2539                            String sql = query.toString();
2540    
2541                            Session session = null;
2542    
2543                            try {
2544                                    session = openSession();
2545    
2546                                    Query q = session.createQuery(sql);
2547    
2548                                    QueryPos qPos = QueryPos.getInstance(q);
2549    
2550                                    qPos.add(banUserId);
2551    
2552                                    if (!pagination) {
2553                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
2554                                                            end, false);
2555    
2556                                            Collections.sort(list);
2557    
2558                                            list = new UnmodifiableList<MBBan>(list);
2559                                    }
2560                                    else {
2561                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
2562                                                            end);
2563                                    }
2564    
2565                                    cacheResult(list);
2566    
2567                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2568                            }
2569                            catch (Exception e) {
2570                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2571    
2572                                    throw processException(e);
2573                            }
2574                            finally {
2575                                    closeSession(session);
2576                            }
2577                    }
2578    
2579                    return list;
2580            }
2581    
2582            /**
2583             * Returns the first message boards ban in the ordered set where banUserId = &#63;.
2584             *
2585             * @param banUserId the ban user ID
2586             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2587             * @return the first matching message boards ban
2588             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
2589             * @throws SystemException if a system exception occurred
2590             */
2591            @Override
2592            public MBBan findByBanUserId_First(long banUserId,
2593                    OrderByComparator orderByComparator)
2594                    throws NoSuchBanException, SystemException {
2595                    MBBan mbBan = fetchByBanUserId_First(banUserId, orderByComparator);
2596    
2597                    if (mbBan != null) {
2598                            return mbBan;
2599                    }
2600    
2601                    StringBundler msg = new StringBundler(4);
2602    
2603                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2604    
2605                    msg.append("banUserId=");
2606                    msg.append(banUserId);
2607    
2608                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2609    
2610                    throw new NoSuchBanException(msg.toString());
2611            }
2612    
2613            /**
2614             * Returns the first message boards ban in the ordered set where banUserId = &#63;.
2615             *
2616             * @param banUserId the ban user ID
2617             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2618             * @return the first matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
2619             * @throws SystemException if a system exception occurred
2620             */
2621            @Override
2622            public MBBan fetchByBanUserId_First(long banUserId,
2623                    OrderByComparator orderByComparator) throws SystemException {
2624                    List<MBBan> list = findByBanUserId(banUserId, 0, 1, orderByComparator);
2625    
2626                    if (!list.isEmpty()) {
2627                            return list.get(0);
2628                    }
2629    
2630                    return null;
2631            }
2632    
2633            /**
2634             * Returns the last message boards ban in the ordered set where banUserId = &#63;.
2635             *
2636             * @param banUserId the ban user ID
2637             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2638             * @return the last matching message boards ban
2639             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
2640             * @throws SystemException if a system exception occurred
2641             */
2642            @Override
2643            public MBBan findByBanUserId_Last(long banUserId,
2644                    OrderByComparator orderByComparator)
2645                    throws NoSuchBanException, SystemException {
2646                    MBBan mbBan = fetchByBanUserId_Last(banUserId, orderByComparator);
2647    
2648                    if (mbBan != null) {
2649                            return mbBan;
2650                    }
2651    
2652                    StringBundler msg = new StringBundler(4);
2653    
2654                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2655    
2656                    msg.append("banUserId=");
2657                    msg.append(banUserId);
2658    
2659                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2660    
2661                    throw new NoSuchBanException(msg.toString());
2662            }
2663    
2664            /**
2665             * Returns the last message boards ban in the ordered set where banUserId = &#63;.
2666             *
2667             * @param banUserId the ban user ID
2668             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2669             * @return the last matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
2670             * @throws SystemException if a system exception occurred
2671             */
2672            @Override
2673            public MBBan fetchByBanUserId_Last(long banUserId,
2674                    OrderByComparator orderByComparator) throws SystemException {
2675                    int count = countByBanUserId(banUserId);
2676    
2677                    if (count == 0) {
2678                            return null;
2679                    }
2680    
2681                    List<MBBan> list = findByBanUserId(banUserId, count - 1, count,
2682                                    orderByComparator);
2683    
2684                    if (!list.isEmpty()) {
2685                            return list.get(0);
2686                    }
2687    
2688                    return null;
2689            }
2690    
2691            /**
2692             * Returns the message boards bans before and after the current message boards ban in the ordered set where banUserId = &#63;.
2693             *
2694             * @param banId the primary key of the current message boards ban
2695             * @param banUserId the ban user ID
2696             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2697             * @return the previous, current, and next message boards ban
2698             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
2699             * @throws SystemException if a system exception occurred
2700             */
2701            @Override
2702            public MBBan[] findByBanUserId_PrevAndNext(long banId, long banUserId,
2703                    OrderByComparator orderByComparator)
2704                    throws NoSuchBanException, SystemException {
2705                    MBBan mbBan = findByPrimaryKey(banId);
2706    
2707                    Session session = null;
2708    
2709                    try {
2710                            session = openSession();
2711    
2712                            MBBan[] array = new MBBanImpl[3];
2713    
2714                            array[0] = getByBanUserId_PrevAndNext(session, mbBan, banUserId,
2715                                            orderByComparator, true);
2716    
2717                            array[1] = mbBan;
2718    
2719                            array[2] = getByBanUserId_PrevAndNext(session, mbBan, banUserId,
2720                                            orderByComparator, false);
2721    
2722                            return array;
2723                    }
2724                    catch (Exception e) {
2725                            throw processException(e);
2726                    }
2727                    finally {
2728                            closeSession(session);
2729                    }
2730            }
2731    
2732            protected MBBan getByBanUserId_PrevAndNext(Session session, MBBan mbBan,
2733                    long banUserId, OrderByComparator orderByComparator, boolean previous) {
2734                    StringBundler query = null;
2735    
2736                    if (orderByComparator != null) {
2737                            query = new StringBundler(6 +
2738                                            (orderByComparator.getOrderByFields().length * 6));
2739                    }
2740                    else {
2741                            query = new StringBundler(3);
2742                    }
2743    
2744                    query.append(_SQL_SELECT_MBBAN_WHERE);
2745    
2746                    query.append(_FINDER_COLUMN_BANUSERID_BANUSERID_2);
2747    
2748                    if (orderByComparator != null) {
2749                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2750    
2751                            if (orderByConditionFields.length > 0) {
2752                                    query.append(WHERE_AND);
2753                            }
2754    
2755                            for (int i = 0; i < orderByConditionFields.length; i++) {
2756                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2757                                    query.append(orderByConditionFields[i]);
2758    
2759                                    if ((i + 1) < orderByConditionFields.length) {
2760                                            if (orderByComparator.isAscending() ^ previous) {
2761                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2762                                            }
2763                                            else {
2764                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2765                                            }
2766                                    }
2767                                    else {
2768                                            if (orderByComparator.isAscending() ^ previous) {
2769                                                    query.append(WHERE_GREATER_THAN);
2770                                            }
2771                                            else {
2772                                                    query.append(WHERE_LESSER_THAN);
2773                                            }
2774                                    }
2775                            }
2776    
2777                            query.append(ORDER_BY_CLAUSE);
2778    
2779                            String[] orderByFields = orderByComparator.getOrderByFields();
2780    
2781                            for (int i = 0; i < orderByFields.length; i++) {
2782                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2783                                    query.append(orderByFields[i]);
2784    
2785                                    if ((i + 1) < orderByFields.length) {
2786                                            if (orderByComparator.isAscending() ^ previous) {
2787                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2788                                            }
2789                                            else {
2790                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2791                                            }
2792                                    }
2793                                    else {
2794                                            if (orderByComparator.isAscending() ^ previous) {
2795                                                    query.append(ORDER_BY_ASC);
2796                                            }
2797                                            else {
2798                                                    query.append(ORDER_BY_DESC);
2799                                            }
2800                                    }
2801                            }
2802                    }
2803                    else {
2804                            query.append(MBBanModelImpl.ORDER_BY_JPQL);
2805                    }
2806    
2807                    String sql = query.toString();
2808    
2809                    Query q = session.createQuery(sql);
2810    
2811                    q.setFirstResult(0);
2812                    q.setMaxResults(2);
2813    
2814                    QueryPos qPos = QueryPos.getInstance(q);
2815    
2816                    qPos.add(banUserId);
2817    
2818                    if (orderByComparator != null) {
2819                            Object[] values = orderByComparator.getOrderByConditionValues(mbBan);
2820    
2821                            for (Object value : values) {
2822                                    qPos.add(value);
2823                            }
2824                    }
2825    
2826                    List<MBBan> list = q.list();
2827    
2828                    if (list.size() == 2) {
2829                            return list.get(1);
2830                    }
2831                    else {
2832                            return null;
2833                    }
2834            }
2835    
2836            /**
2837             * Removes all the message boards bans where banUserId = &#63; from the database.
2838             *
2839             * @param banUserId the ban user ID
2840             * @throws SystemException if a system exception occurred
2841             */
2842            @Override
2843            public void removeByBanUserId(long banUserId) throws SystemException {
2844                    for (MBBan mbBan : findByBanUserId(banUserId, QueryUtil.ALL_POS,
2845                                    QueryUtil.ALL_POS, null)) {
2846                            remove(mbBan);
2847                    }
2848            }
2849    
2850            /**
2851             * Returns the number of message boards bans where banUserId = &#63;.
2852             *
2853             * @param banUserId the ban user ID
2854             * @return the number of matching message boards bans
2855             * @throws SystemException if a system exception occurred
2856             */
2857            @Override
2858            public int countByBanUserId(long banUserId) throws SystemException {
2859                    FinderPath finderPath = FINDER_PATH_COUNT_BY_BANUSERID;
2860    
2861                    Object[] finderArgs = new Object[] { banUserId };
2862    
2863                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2864                                    this);
2865    
2866                    if (count == null) {
2867                            StringBundler query = new StringBundler(2);
2868    
2869                            query.append(_SQL_COUNT_MBBAN_WHERE);
2870    
2871                            query.append(_FINDER_COLUMN_BANUSERID_BANUSERID_2);
2872    
2873                            String sql = query.toString();
2874    
2875                            Session session = null;
2876    
2877                            try {
2878                                    session = openSession();
2879    
2880                                    Query q = session.createQuery(sql);
2881    
2882                                    QueryPos qPos = QueryPos.getInstance(q);
2883    
2884                                    qPos.add(banUserId);
2885    
2886                                    count = (Long)q.uniqueResult();
2887    
2888                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2889                            }
2890                            catch (Exception e) {
2891                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2892    
2893                                    throw processException(e);
2894                            }
2895                            finally {
2896                                    closeSession(session);
2897                            }
2898                    }
2899    
2900                    return count.intValue();
2901            }
2902    
2903            private static final String _FINDER_COLUMN_BANUSERID_BANUSERID_2 = "mbBan.banUserId = ?";
2904            public static final FinderPath FINDER_PATH_FETCH_BY_G_B = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
2905                            MBBanModelImpl.FINDER_CACHE_ENABLED, MBBanImpl.class,
2906                            FINDER_CLASS_NAME_ENTITY, "fetchByG_B",
2907                            new String[] { Long.class.getName(), Long.class.getName() },
2908                            MBBanModelImpl.GROUPID_COLUMN_BITMASK |
2909                            MBBanModelImpl.BANUSERID_COLUMN_BITMASK);
2910            public static final FinderPath FINDER_PATH_COUNT_BY_G_B = new FinderPath(MBBanModelImpl.ENTITY_CACHE_ENABLED,
2911                            MBBanModelImpl.FINDER_CACHE_ENABLED, Long.class,
2912                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_B",
2913                            new String[] { Long.class.getName(), Long.class.getName() });
2914    
2915            /**
2916             * 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.
2917             *
2918             * @param groupId the group ID
2919             * @param banUserId the ban user ID
2920             * @return the matching message boards ban
2921             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a matching message boards ban could not be found
2922             * @throws SystemException if a system exception occurred
2923             */
2924            @Override
2925            public MBBan findByG_B(long groupId, long banUserId)
2926                    throws NoSuchBanException, SystemException {
2927                    MBBan mbBan = fetchByG_B(groupId, banUserId);
2928    
2929                    if (mbBan == null) {
2930                            StringBundler msg = new StringBundler(6);
2931    
2932                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2933    
2934                            msg.append("groupId=");
2935                            msg.append(groupId);
2936    
2937                            msg.append(", banUserId=");
2938                            msg.append(banUserId);
2939    
2940                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2941    
2942                            if (_log.isWarnEnabled()) {
2943                                    _log.warn(msg.toString());
2944                            }
2945    
2946                            throw new NoSuchBanException(msg.toString());
2947                    }
2948    
2949                    return mbBan;
2950            }
2951    
2952            /**
2953             * 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.
2954             *
2955             * @param groupId the group ID
2956             * @param banUserId the ban user ID
2957             * @return the matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
2958             * @throws SystemException if a system exception occurred
2959             */
2960            @Override
2961            public MBBan fetchByG_B(long groupId, long banUserId)
2962                    throws SystemException {
2963                    return fetchByG_B(groupId, banUserId, true);
2964            }
2965    
2966            /**
2967             * 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.
2968             *
2969             * @param groupId the group ID
2970             * @param banUserId the ban user ID
2971             * @param retrieveFromCache whether to use the finder cache
2972             * @return the matching message boards ban, or <code>null</code> if a matching message boards ban could not be found
2973             * @throws SystemException if a system exception occurred
2974             */
2975            @Override
2976            public MBBan fetchByG_B(long groupId, long banUserId,
2977                    boolean retrieveFromCache) throws SystemException {
2978                    Object[] finderArgs = new Object[] { groupId, banUserId };
2979    
2980                    Object result = null;
2981    
2982                    if (retrieveFromCache) {
2983                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_G_B,
2984                                            finderArgs, this);
2985                    }
2986    
2987                    if (result instanceof MBBan) {
2988                            MBBan mbBan = (MBBan)result;
2989    
2990                            if ((groupId != mbBan.getGroupId()) ||
2991                                            (banUserId != mbBan.getBanUserId())) {
2992                                    result = null;
2993                            }
2994                    }
2995    
2996                    if (result == null) {
2997                            StringBundler query = new StringBundler(4);
2998    
2999                            query.append(_SQL_SELECT_MBBAN_WHERE);
3000    
3001                            query.append(_FINDER_COLUMN_G_B_GROUPID_2);
3002    
3003                            query.append(_FINDER_COLUMN_G_B_BANUSERID_2);
3004    
3005                            String sql = query.toString();
3006    
3007                            Session session = null;
3008    
3009                            try {
3010                                    session = openSession();
3011    
3012                                    Query q = session.createQuery(sql);
3013    
3014                                    QueryPos qPos = QueryPos.getInstance(q);
3015    
3016                                    qPos.add(groupId);
3017    
3018                                    qPos.add(banUserId);
3019    
3020                                    List<MBBan> list = q.list();
3021    
3022                                    if (list.isEmpty()) {
3023                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_B,
3024                                                    finderArgs, list);
3025                                    }
3026                                    else {
3027                                            MBBan mbBan = list.get(0);
3028    
3029                                            result = mbBan;
3030    
3031                                            cacheResult(mbBan);
3032    
3033                                            if ((mbBan.getGroupId() != groupId) ||
3034                                                            (mbBan.getBanUserId() != banUserId)) {
3035                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_B,
3036                                                            finderArgs, mbBan);
3037                                            }
3038                                    }
3039                            }
3040                            catch (Exception e) {
3041                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_B,
3042                                            finderArgs);
3043    
3044                                    throw processException(e);
3045                            }
3046                            finally {
3047                                    closeSession(session);
3048                            }
3049                    }
3050    
3051                    if (result instanceof List<?>) {
3052                            return null;
3053                    }
3054                    else {
3055                            return (MBBan)result;
3056                    }
3057            }
3058    
3059            /**
3060             * Removes the message boards ban where groupId = &#63; and banUserId = &#63; from the database.
3061             *
3062             * @param groupId the group ID
3063             * @param banUserId the ban user ID
3064             * @return the message boards ban that was removed
3065             * @throws SystemException if a system exception occurred
3066             */
3067            @Override
3068            public MBBan removeByG_B(long groupId, long banUserId)
3069                    throws NoSuchBanException, SystemException {
3070                    MBBan mbBan = findByG_B(groupId, banUserId);
3071    
3072                    return remove(mbBan);
3073            }
3074    
3075            /**
3076             * Returns the number of message boards bans where groupId = &#63; and banUserId = &#63;.
3077             *
3078             * @param groupId the group ID
3079             * @param banUserId the ban user ID
3080             * @return the number of matching message boards bans
3081             * @throws SystemException if a system exception occurred
3082             */
3083            @Override
3084            public int countByG_B(long groupId, long banUserId)
3085                    throws SystemException {
3086                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_B;
3087    
3088                    Object[] finderArgs = new Object[] { groupId, banUserId };
3089    
3090                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3091                                    this);
3092    
3093                    if (count == null) {
3094                            StringBundler query = new StringBundler(3);
3095    
3096                            query.append(_SQL_COUNT_MBBAN_WHERE);
3097    
3098                            query.append(_FINDER_COLUMN_G_B_GROUPID_2);
3099    
3100                            query.append(_FINDER_COLUMN_G_B_BANUSERID_2);
3101    
3102                            String sql = query.toString();
3103    
3104                            Session session = null;
3105    
3106                            try {
3107                                    session = openSession();
3108    
3109                                    Query q = session.createQuery(sql);
3110    
3111                                    QueryPos qPos = QueryPos.getInstance(q);
3112    
3113                                    qPos.add(groupId);
3114    
3115                                    qPos.add(banUserId);
3116    
3117                                    count = (Long)q.uniqueResult();
3118    
3119                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3120                            }
3121                            catch (Exception e) {
3122                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3123    
3124                                    throw processException(e);
3125                            }
3126                            finally {
3127                                    closeSession(session);
3128                            }
3129                    }
3130    
3131                    return count.intValue();
3132            }
3133    
3134            private static final String _FINDER_COLUMN_G_B_GROUPID_2 = "mbBan.groupId = ? AND ";
3135            private static final String _FINDER_COLUMN_G_B_BANUSERID_2 = "mbBan.banUserId = ?";
3136    
3137            public MBBanPersistenceImpl() {
3138                    setModelClass(MBBan.class);
3139            }
3140    
3141            /**
3142             * Caches the message boards ban in the entity cache if it is enabled.
3143             *
3144             * @param mbBan the message boards ban
3145             */
3146            @Override
3147            public void cacheResult(MBBan mbBan) {
3148                    EntityCacheUtil.putResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
3149                            MBBanImpl.class, mbBan.getPrimaryKey(), mbBan);
3150    
3151                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
3152                            new Object[] { mbBan.getUuid(), mbBan.getGroupId() }, mbBan);
3153    
3154                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_B,
3155                            new Object[] { mbBan.getGroupId(), mbBan.getBanUserId() }, mbBan);
3156    
3157                    mbBan.resetOriginalValues();
3158            }
3159    
3160            /**
3161             * Caches the message boards bans in the entity cache if it is enabled.
3162             *
3163             * @param mbBans the message boards bans
3164             */
3165            @Override
3166            public void cacheResult(List<MBBan> mbBans) {
3167                    for (MBBan mbBan : mbBans) {
3168                            if (EntityCacheUtil.getResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
3169                                                    MBBanImpl.class, mbBan.getPrimaryKey()) == null) {
3170                                    cacheResult(mbBan);
3171                            }
3172                            else {
3173                                    mbBan.resetOriginalValues();
3174                            }
3175                    }
3176            }
3177    
3178            /**
3179             * Clears the cache for all message boards bans.
3180             *
3181             * <p>
3182             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3183             * </p>
3184             */
3185            @Override
3186            public void clearCache() {
3187                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
3188                            CacheRegistryUtil.clear(MBBanImpl.class.getName());
3189                    }
3190    
3191                    EntityCacheUtil.clearCache(MBBanImpl.class.getName());
3192    
3193                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
3194                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3195                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3196            }
3197    
3198            /**
3199             * Clears the cache for the message boards ban.
3200             *
3201             * <p>
3202             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
3203             * </p>
3204             */
3205            @Override
3206            public void clearCache(MBBan mbBan) {
3207                    EntityCacheUtil.removeResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
3208                            MBBanImpl.class, mbBan.getPrimaryKey());
3209    
3210                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3211                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3212    
3213                    clearUniqueFindersCache(mbBan);
3214            }
3215    
3216            @Override
3217            public void clearCache(List<MBBan> mbBans) {
3218                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3219                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3220    
3221                    for (MBBan mbBan : mbBans) {
3222                            EntityCacheUtil.removeResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
3223                                    MBBanImpl.class, mbBan.getPrimaryKey());
3224    
3225                            clearUniqueFindersCache(mbBan);
3226                    }
3227            }
3228    
3229            protected void cacheUniqueFindersCache(MBBan mbBan) {
3230                    if (mbBan.isNew()) {
3231                            Object[] args = new Object[] { mbBan.getUuid(), mbBan.getGroupId() };
3232    
3233                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
3234                                    Long.valueOf(1));
3235                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args, mbBan);
3236    
3237                            args = new Object[] { mbBan.getGroupId(), mbBan.getBanUserId() };
3238    
3239                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_B, args,
3240                                    Long.valueOf(1));
3241                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_B, args, mbBan);
3242                    }
3243                    else {
3244                            MBBanModelImpl mbBanModelImpl = (MBBanModelImpl)mbBan;
3245    
3246                            if ((mbBanModelImpl.getColumnBitmask() &
3247                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
3248                                    Object[] args = new Object[] { mbBan.getUuid(), mbBan.getGroupId() };
3249    
3250                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
3251                                            Long.valueOf(1));
3252                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
3253                                            mbBan);
3254                            }
3255    
3256                            if ((mbBanModelImpl.getColumnBitmask() &
3257                                            FINDER_PATH_FETCH_BY_G_B.getColumnBitmask()) != 0) {
3258                                    Object[] args = new Object[] {
3259                                                    mbBan.getGroupId(), mbBan.getBanUserId()
3260                                            };
3261    
3262                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_B, args,
3263                                            Long.valueOf(1));
3264                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_G_B, args, mbBan);
3265                            }
3266                    }
3267            }
3268    
3269            protected void clearUniqueFindersCache(MBBan mbBan) {
3270                    MBBanModelImpl mbBanModelImpl = (MBBanModelImpl)mbBan;
3271    
3272                    Object[] args = new Object[] { mbBan.getUuid(), mbBan.getGroupId() };
3273    
3274                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
3275                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
3276    
3277                    if ((mbBanModelImpl.getColumnBitmask() &
3278                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
3279                            args = new Object[] {
3280                                            mbBanModelImpl.getOriginalUuid(),
3281                                            mbBanModelImpl.getOriginalGroupId()
3282                                    };
3283    
3284                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
3285                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
3286                    }
3287    
3288                    args = new Object[] { mbBan.getGroupId(), mbBan.getBanUserId() };
3289    
3290                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_B, args);
3291                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_B, args);
3292    
3293                    if ((mbBanModelImpl.getColumnBitmask() &
3294                                    FINDER_PATH_FETCH_BY_G_B.getColumnBitmask()) != 0) {
3295                            args = new Object[] {
3296                                            mbBanModelImpl.getOriginalGroupId(),
3297                                            mbBanModelImpl.getOriginalBanUserId()
3298                                    };
3299    
3300                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_B, args);
3301                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_G_B, args);
3302                    }
3303            }
3304    
3305            /**
3306             * Creates a new message boards ban with the primary key. Does not add the message boards ban to the database.
3307             *
3308             * @param banId the primary key for the new message boards ban
3309             * @return the new message boards ban
3310             */
3311            @Override
3312            public MBBan create(long banId) {
3313                    MBBan mbBan = new MBBanImpl();
3314    
3315                    mbBan.setNew(true);
3316                    mbBan.setPrimaryKey(banId);
3317    
3318                    String uuid = PortalUUIDUtil.generate();
3319    
3320                    mbBan.setUuid(uuid);
3321    
3322                    return mbBan;
3323            }
3324    
3325            /**
3326             * Removes the message boards ban with the primary key from the database. Also notifies the appropriate model listeners.
3327             *
3328             * @param banId the primary key of the message boards ban
3329             * @return the message boards ban that was removed
3330             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
3331             * @throws SystemException if a system exception occurred
3332             */
3333            @Override
3334            public MBBan remove(long banId) throws NoSuchBanException, SystemException {
3335                    return remove((Serializable)banId);
3336            }
3337    
3338            /**
3339             * Removes the message boards ban with the primary key from the database. Also notifies the appropriate model listeners.
3340             *
3341             * @param primaryKey the primary key of the message boards ban
3342             * @return the message boards ban that was removed
3343             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
3344             * @throws SystemException if a system exception occurred
3345             */
3346            @Override
3347            public MBBan remove(Serializable primaryKey)
3348                    throws NoSuchBanException, SystemException {
3349                    Session session = null;
3350    
3351                    try {
3352                            session = openSession();
3353    
3354                            MBBan mbBan = (MBBan)session.get(MBBanImpl.class, primaryKey);
3355    
3356                            if (mbBan == null) {
3357                                    if (_log.isWarnEnabled()) {
3358                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3359                                    }
3360    
3361                                    throw new NoSuchBanException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3362                                            primaryKey);
3363                            }
3364    
3365                            return remove(mbBan);
3366                    }
3367                    catch (NoSuchBanException nsee) {
3368                            throw nsee;
3369                    }
3370                    catch (Exception e) {
3371                            throw processException(e);
3372                    }
3373                    finally {
3374                            closeSession(session);
3375                    }
3376            }
3377    
3378            @Override
3379            protected MBBan removeImpl(MBBan mbBan) throws SystemException {
3380                    mbBan = toUnwrappedModel(mbBan);
3381    
3382                    Session session = null;
3383    
3384                    try {
3385                            session = openSession();
3386    
3387                            if (!session.contains(mbBan)) {
3388                                    mbBan = (MBBan)session.get(MBBanImpl.class,
3389                                                    mbBan.getPrimaryKeyObj());
3390                            }
3391    
3392                            if (mbBan != null) {
3393                                    session.delete(mbBan);
3394                            }
3395                    }
3396                    catch (Exception e) {
3397                            throw processException(e);
3398                    }
3399                    finally {
3400                            closeSession(session);
3401                    }
3402    
3403                    if (mbBan != null) {
3404                            clearCache(mbBan);
3405                    }
3406    
3407                    return mbBan;
3408            }
3409    
3410            @Override
3411            public MBBan updateImpl(com.liferay.portlet.messageboards.model.MBBan mbBan)
3412                    throws SystemException {
3413                    mbBan = toUnwrappedModel(mbBan);
3414    
3415                    boolean isNew = mbBan.isNew();
3416    
3417                    MBBanModelImpl mbBanModelImpl = (MBBanModelImpl)mbBan;
3418    
3419                    if (Validator.isNull(mbBan.getUuid())) {
3420                            String uuid = PortalUUIDUtil.generate();
3421    
3422                            mbBan.setUuid(uuid);
3423                    }
3424    
3425                    Session session = null;
3426    
3427                    try {
3428                            session = openSession();
3429    
3430                            if (mbBan.isNew()) {
3431                                    session.save(mbBan);
3432    
3433                                    mbBan.setNew(false);
3434                            }
3435                            else {
3436                                    session.merge(mbBan);
3437                            }
3438                    }
3439                    catch (Exception e) {
3440                            throw processException(e);
3441                    }
3442                    finally {
3443                            closeSession(session);
3444                    }
3445    
3446                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3447    
3448                    if (isNew || !MBBanModelImpl.COLUMN_BITMASK_ENABLED) {
3449                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3450                    }
3451    
3452                    else {
3453                            if ((mbBanModelImpl.getColumnBitmask() &
3454                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
3455                                    Object[] args = new Object[] { mbBanModelImpl.getOriginalUuid() };
3456    
3457                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3458                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3459                                            args);
3460    
3461                                    args = new Object[] { mbBanModelImpl.getUuid() };
3462    
3463                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
3464                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
3465                                            args);
3466                            }
3467    
3468                            if ((mbBanModelImpl.getColumnBitmask() &
3469                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
3470                                    Object[] args = new Object[] {
3471                                                    mbBanModelImpl.getOriginalUuid(),
3472                                                    mbBanModelImpl.getOriginalCompanyId()
3473                                            };
3474    
3475                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3476                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3477                                            args);
3478    
3479                                    args = new Object[] {
3480                                                    mbBanModelImpl.getUuid(), mbBanModelImpl.getCompanyId()
3481                                            };
3482    
3483                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
3484                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
3485                                            args);
3486                            }
3487    
3488                            if ((mbBanModelImpl.getColumnBitmask() &
3489                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
3490                                    Object[] args = new Object[] { mbBanModelImpl.getOriginalGroupId() };
3491    
3492                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3493                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3494                                            args);
3495    
3496                                    args = new Object[] { mbBanModelImpl.getGroupId() };
3497    
3498                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
3499                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
3500                                            args);
3501                            }
3502    
3503                            if ((mbBanModelImpl.getColumnBitmask() &
3504                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
3505                                    Object[] args = new Object[] { mbBanModelImpl.getOriginalUserId() };
3506    
3507                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
3508                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
3509                                            args);
3510    
3511                                    args = new Object[] { mbBanModelImpl.getUserId() };
3512    
3513                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
3514                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
3515                                            args);
3516                            }
3517    
3518                            if ((mbBanModelImpl.getColumnBitmask() &
3519                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BANUSERID.getColumnBitmask()) != 0) {
3520                                    Object[] args = new Object[] {
3521                                                    mbBanModelImpl.getOriginalBanUserId()
3522                                            };
3523    
3524                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BANUSERID,
3525                                            args);
3526                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BANUSERID,
3527                                            args);
3528    
3529                                    args = new Object[] { mbBanModelImpl.getBanUserId() };
3530    
3531                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_BANUSERID,
3532                                            args);
3533                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_BANUSERID,
3534                                            args);
3535                            }
3536                    }
3537    
3538                    EntityCacheUtil.putResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
3539                            MBBanImpl.class, mbBan.getPrimaryKey(), mbBan);
3540    
3541                    clearUniqueFindersCache(mbBan);
3542                    cacheUniqueFindersCache(mbBan);
3543    
3544                    return mbBan;
3545            }
3546    
3547            protected MBBan toUnwrappedModel(MBBan mbBan) {
3548                    if (mbBan instanceof MBBanImpl) {
3549                            return mbBan;
3550                    }
3551    
3552                    MBBanImpl mbBanImpl = new MBBanImpl();
3553    
3554                    mbBanImpl.setNew(mbBan.isNew());
3555                    mbBanImpl.setPrimaryKey(mbBan.getPrimaryKey());
3556    
3557                    mbBanImpl.setUuid(mbBan.getUuid());
3558                    mbBanImpl.setBanId(mbBan.getBanId());
3559                    mbBanImpl.setGroupId(mbBan.getGroupId());
3560                    mbBanImpl.setCompanyId(mbBan.getCompanyId());
3561                    mbBanImpl.setUserId(mbBan.getUserId());
3562                    mbBanImpl.setUserName(mbBan.getUserName());
3563                    mbBanImpl.setCreateDate(mbBan.getCreateDate());
3564                    mbBanImpl.setModifiedDate(mbBan.getModifiedDate());
3565                    mbBanImpl.setBanUserId(mbBan.getBanUserId());
3566    
3567                    return mbBanImpl;
3568            }
3569    
3570            /**
3571             * Returns the message boards ban with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
3572             *
3573             * @param primaryKey the primary key of the message boards ban
3574             * @return the message boards ban
3575             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
3576             * @throws SystemException if a system exception occurred
3577             */
3578            @Override
3579            public MBBan findByPrimaryKey(Serializable primaryKey)
3580                    throws NoSuchBanException, SystemException {
3581                    MBBan mbBan = fetchByPrimaryKey(primaryKey);
3582    
3583                    if (mbBan == null) {
3584                            if (_log.isWarnEnabled()) {
3585                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
3586                            }
3587    
3588                            throw new NoSuchBanException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
3589                                    primaryKey);
3590                    }
3591    
3592                    return mbBan;
3593            }
3594    
3595            /**
3596             * Returns the message boards ban with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchBanException} if it could not be found.
3597             *
3598             * @param banId the primary key of the message boards ban
3599             * @return the message boards ban
3600             * @throws com.liferay.portlet.messageboards.NoSuchBanException if a message boards ban with the primary key could not be found
3601             * @throws SystemException if a system exception occurred
3602             */
3603            @Override
3604            public MBBan findByPrimaryKey(long banId)
3605                    throws NoSuchBanException, SystemException {
3606                    return findByPrimaryKey((Serializable)banId);
3607            }
3608    
3609            /**
3610             * Returns the message boards ban with the primary key or returns <code>null</code> if it could not be found.
3611             *
3612             * @param primaryKey the primary key of the message boards ban
3613             * @return the message boards ban, or <code>null</code> if a message boards ban with the primary key could not be found
3614             * @throws SystemException if a system exception occurred
3615             */
3616            @Override
3617            public MBBan fetchByPrimaryKey(Serializable primaryKey)
3618                    throws SystemException {
3619                    MBBan mbBan = (MBBan)EntityCacheUtil.getResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
3620                                    MBBanImpl.class, primaryKey);
3621    
3622                    if (mbBan == _nullMBBan) {
3623                            return null;
3624                    }
3625    
3626                    if (mbBan == null) {
3627                            Session session = null;
3628    
3629                            try {
3630                                    session = openSession();
3631    
3632                                    mbBan = (MBBan)session.get(MBBanImpl.class, primaryKey);
3633    
3634                                    if (mbBan != null) {
3635                                            cacheResult(mbBan);
3636                                    }
3637                                    else {
3638                                            EntityCacheUtil.putResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
3639                                                    MBBanImpl.class, primaryKey, _nullMBBan);
3640                                    }
3641                            }
3642                            catch (Exception e) {
3643                                    EntityCacheUtil.removeResult(MBBanModelImpl.ENTITY_CACHE_ENABLED,
3644                                            MBBanImpl.class, primaryKey);
3645    
3646                                    throw processException(e);
3647                            }
3648                            finally {
3649                                    closeSession(session);
3650                            }
3651                    }
3652    
3653                    return mbBan;
3654            }
3655    
3656            /**
3657             * Returns the message boards ban with the primary key or returns <code>null</code> if it could not be found.
3658             *
3659             * @param banId the primary key of the message boards ban
3660             * @return the message boards ban, or <code>null</code> if a message boards ban with the primary key could not be found
3661             * @throws SystemException if a system exception occurred
3662             */
3663            @Override
3664            public MBBan fetchByPrimaryKey(long banId) throws SystemException {
3665                    return fetchByPrimaryKey((Serializable)banId);
3666            }
3667    
3668            /**
3669             * Returns all the message boards bans.
3670             *
3671             * @return the message boards bans
3672             * @throws SystemException if a system exception occurred
3673             */
3674            @Override
3675            public List<MBBan> findAll() throws SystemException {
3676                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3677            }
3678    
3679            /**
3680             * Returns a range of all the message boards bans.
3681             *
3682             * <p>
3683             * 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.
3684             * </p>
3685             *
3686             * @param start the lower bound of the range of message boards bans
3687             * @param end the upper bound of the range of message boards bans (not inclusive)
3688             * @return the range of message boards bans
3689             * @throws SystemException if a system exception occurred
3690             */
3691            @Override
3692            public List<MBBan> findAll(int start, int end) throws SystemException {
3693                    return findAll(start, end, null);
3694            }
3695    
3696            /**
3697             * Returns an ordered range of all the message boards bans.
3698             *
3699             * <p>
3700             * 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.
3701             * </p>
3702             *
3703             * @param start the lower bound of the range of message boards bans
3704             * @param end the upper bound of the range of message boards bans (not inclusive)
3705             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3706             * @return the ordered range of message boards bans
3707             * @throws SystemException if a system exception occurred
3708             */
3709            @Override
3710            public List<MBBan> findAll(int start, int end,
3711                    OrderByComparator orderByComparator) throws SystemException {
3712                    boolean pagination = true;
3713                    FinderPath finderPath = null;
3714                    Object[] finderArgs = null;
3715    
3716                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3717                                    (orderByComparator == null)) {
3718                            pagination = false;
3719                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3720                            finderArgs = FINDER_ARGS_EMPTY;
3721                    }
3722                    else {
3723                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3724                            finderArgs = new Object[] { start, end, orderByComparator };
3725                    }
3726    
3727                    List<MBBan> list = (List<MBBan>)FinderCacheUtil.getResult(finderPath,
3728                                    finderArgs, this);
3729    
3730                    if (list == null) {
3731                            StringBundler query = null;
3732                            String sql = null;
3733    
3734                            if (orderByComparator != null) {
3735                                    query = new StringBundler(2 +
3736                                                    (orderByComparator.getOrderByFields().length * 3));
3737    
3738                                    query.append(_SQL_SELECT_MBBAN);
3739    
3740                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3741                                            orderByComparator);
3742    
3743                                    sql = query.toString();
3744                            }
3745                            else {
3746                                    sql = _SQL_SELECT_MBBAN;
3747    
3748                                    if (pagination) {
3749                                            sql = sql.concat(MBBanModelImpl.ORDER_BY_JPQL);
3750                                    }
3751                            }
3752    
3753                            Session session = null;
3754    
3755                            try {
3756                                    session = openSession();
3757    
3758                                    Query q = session.createQuery(sql);
3759    
3760                                    if (!pagination) {
3761                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
3762                                                            end, false);
3763    
3764                                            Collections.sort(list);
3765    
3766                                            list = new UnmodifiableList<MBBan>(list);
3767                                    }
3768                                    else {
3769                                            list = (List<MBBan>)QueryUtil.list(q, getDialect(), start,
3770                                                            end);
3771                                    }
3772    
3773                                    cacheResult(list);
3774    
3775                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3776                            }
3777                            catch (Exception e) {
3778                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3779    
3780                                    throw processException(e);
3781                            }
3782                            finally {
3783                                    closeSession(session);
3784                            }
3785                    }
3786    
3787                    return list;
3788            }
3789    
3790            /**
3791             * Removes all the message boards bans from the database.
3792             *
3793             * @throws SystemException if a system exception occurred
3794             */
3795            @Override
3796            public void removeAll() throws SystemException {
3797                    for (MBBan mbBan : findAll()) {
3798                            remove(mbBan);
3799                    }
3800            }
3801    
3802            /**
3803             * Returns the number of message boards bans.
3804             *
3805             * @return the number of message boards bans
3806             * @throws SystemException if a system exception occurred
3807             */
3808            @Override
3809            public int countAll() throws SystemException {
3810                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3811                                    FINDER_ARGS_EMPTY, this);
3812    
3813                    if (count == null) {
3814                            Session session = null;
3815    
3816                            try {
3817                                    session = openSession();
3818    
3819                                    Query q = session.createQuery(_SQL_COUNT_MBBAN);
3820    
3821                                    count = (Long)q.uniqueResult();
3822    
3823                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
3824                                            FINDER_ARGS_EMPTY, count);
3825                            }
3826                            catch (Exception e) {
3827                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
3828                                            FINDER_ARGS_EMPTY);
3829    
3830                                    throw processException(e);
3831                            }
3832                            finally {
3833                                    closeSession(session);
3834                            }
3835                    }
3836    
3837                    return count.intValue();
3838            }
3839    
3840            @Override
3841            protected Set<String> getBadColumnNames() {
3842                    return _badColumnNames;
3843            }
3844    
3845            /**
3846             * Initializes the message boards ban persistence.
3847             */
3848            public void afterPropertiesSet() {
3849                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3850                                            com.liferay.portal.util.PropsUtil.get(
3851                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBBan")));
3852    
3853                    if (listenerClassNames.length > 0) {
3854                            try {
3855                                    List<ModelListener<MBBan>> listenersList = new ArrayList<ModelListener<MBBan>>();
3856    
3857                                    for (String listenerClassName : listenerClassNames) {
3858                                            listenersList.add((ModelListener<MBBan>)InstanceFactory.newInstance(
3859                                                            getClassLoader(), listenerClassName));
3860                                    }
3861    
3862                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3863                            }
3864                            catch (Exception e) {
3865                                    _log.error(e);
3866                            }
3867                    }
3868            }
3869    
3870            public void destroy() {
3871                    EntityCacheUtil.removeCache(MBBanImpl.class.getName());
3872                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3873                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
3874                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
3875            }
3876    
3877            private static final String _SQL_SELECT_MBBAN = "SELECT mbBan FROM MBBan mbBan";
3878            private static final String _SQL_SELECT_MBBAN_WHERE = "SELECT mbBan FROM MBBan mbBan WHERE ";
3879            private static final String _SQL_COUNT_MBBAN = "SELECT COUNT(mbBan) FROM MBBan mbBan";
3880            private static final String _SQL_COUNT_MBBAN_WHERE = "SELECT COUNT(mbBan) FROM MBBan mbBan WHERE ";
3881            private static final String _ORDER_BY_ENTITY_ALIAS = "mbBan.";
3882            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBBan exists with the primary key ";
3883            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBBan exists with the key {";
3884            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
3885            private static Log _log = LogFactoryUtil.getLog(MBBanPersistenceImpl.class);
3886            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
3887                                    "uuid"
3888                            });
3889            private static MBBan _nullMBBan = new MBBanImpl() {
3890                            @Override
3891                            public Object clone() {
3892                                    return this;
3893                            }
3894    
3895                            @Override
3896                            public CacheModel<MBBan> toCacheModel() {
3897                                    return _nullMBBanCacheModel;
3898                            }
3899                    };
3900    
3901            private static CacheModel<MBBan> _nullMBBanCacheModel = new CacheModel<MBBan>() {
3902                            @Override
3903                            public MBBan toEntityModel() {
3904                                    return _nullMBBan;
3905                            }
3906                    };
3907    }