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