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