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