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