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