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