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