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