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