001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.dao.orm.EntityCache;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCache;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryPos;
026    import com.liferay.portal.kernel.dao.orm.QueryUtil;
027    import com.liferay.portal.kernel.dao.orm.SQLQuery;
028    import com.liferay.portal.kernel.dao.orm.Session;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.ArrayUtil;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.CacheModel;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.ServiceContext;
042    import com.liferay.portal.service.ServiceContextThreadLocal;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.messageboards.NoSuchCategoryException;
046    import com.liferay.portlet.messageboards.model.MBCategory;
047    import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
048    import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
049    import com.liferay.portlet.messageboards.service.persistence.MBCategoryPersistence;
050    
051    import java.io.Serializable;
052    
053    import java.util.Arrays;
054    import java.util.Collections;
055    import java.util.Date;
056    import java.util.HashMap;
057    import java.util.HashSet;
058    import java.util.Iterator;
059    import java.util.List;
060    import java.util.Map;
061    import java.util.Set;
062    
063    /**
064     * The persistence implementation for the message boards category service.
065     *
066     * <p>
067     * Caching information and settings can be found in <code>portal.properties</code>
068     * </p>
069     *
070     * @author Brian Wing Shun Chan
071     * @see MBCategoryPersistence
072     * @see com.liferay.portlet.messageboards.service.persistence.MBCategoryUtil
073     * @generated
074     */
075    @ProviderType
076    public class MBCategoryPersistenceImpl extends BasePersistenceImpl<MBCategory>
077            implements MBCategoryPersistence {
078            /*
079             * NOTE FOR DEVELOPERS:
080             *
081             * Never modify or reference this class directly. Always use {@link MBCategoryUtil} to access the message boards category persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
082             */
083            public static final String FINDER_CLASS_NAME_ENTITY = MBCategoryImpl.class.getName();
084            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085                    ".List1";
086            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
087                    ".List2";
088            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
089                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
090                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
091            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
092                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
093                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
094            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
095                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
097            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
098                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
099                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
100                            new String[] {
101                                    String.class.getName(),
102                                    
103                            Integer.class.getName(), Integer.class.getName(),
104                                    OrderByComparator.class.getName()
105                            });
106            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
107                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
109                            new String[] { String.class.getName() },
110                            MBCategoryModelImpl.UUID_COLUMN_BITMASK |
111                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
112                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
113            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
114                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
115                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
116                            new String[] { String.class.getName() });
117    
118            /**
119             * Returns all the message boards categories where uuid = &#63;.
120             *
121             * @param uuid the uuid
122             * @return the matching message boards categories
123             */
124            @Override
125            public List<MBCategory> findByUuid(String uuid) {
126                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
127            }
128    
129            /**
130             * Returns a range of all the message boards categories where uuid = &#63;.
131             *
132             * <p>
133             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
134             * </p>
135             *
136             * @param uuid the uuid
137             * @param start the lower bound of the range of message boards categories
138             * @param end the upper bound of the range of message boards categories (not inclusive)
139             * @return the range of matching message boards categories
140             */
141            @Override
142            public List<MBCategory> findByUuid(String uuid, int start, int end) {
143                    return findByUuid(uuid, start, end, null);
144            }
145    
146            /**
147             * Returns an ordered range of all the message boards categories where uuid = &#63;.
148             *
149             * <p>
150             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
151             * </p>
152             *
153             * @param uuid the uuid
154             * @param start the lower bound of the range of message boards categories
155             * @param end the upper bound of the range of message boards categories (not inclusive)
156             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
157             * @return the ordered range of matching message boards categories
158             */
159            @Override
160            public List<MBCategory> findByUuid(String uuid, int start, int end,
161                    OrderByComparator<MBCategory> orderByComparator) {
162                    return findByUuid(uuid, start, end, orderByComparator, true);
163            }
164    
165            /**
166             * Returns an ordered range of all the message boards categories where uuid = &#63;.
167             *
168             * <p>
169             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
170             * </p>
171             *
172             * @param uuid the uuid
173             * @param start the lower bound of the range of message boards categories
174             * @param end the upper bound of the range of message boards categories (not inclusive)
175             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
176             * @param retrieveFromCache whether to retrieve from the finder cache
177             * @return the ordered range of matching message boards categories
178             */
179            @Override
180            public List<MBCategory> findByUuid(String uuid, int start, int end,
181                    OrderByComparator<MBCategory> orderByComparator,
182                    boolean retrieveFromCache) {
183                    boolean pagination = true;
184                    FinderPath finderPath = null;
185                    Object[] finderArgs = null;
186    
187                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
188                                    (orderByComparator == null)) {
189                            pagination = false;
190                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
191                            finderArgs = new Object[] { uuid };
192                    }
193                    else {
194                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
195                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
196                    }
197    
198                    List<MBCategory> list = null;
199    
200                    if (retrieveFromCache) {
201                            list = (List<MBCategory>)finderCache.getResult(finderPath,
202                                            finderArgs, this);
203    
204                            if ((list != null) && !list.isEmpty()) {
205                                    for (MBCategory mbCategory : list) {
206                                            if (!Validator.equals(uuid, mbCategory.getUuid())) {
207                                                    list = null;
208    
209                                                    break;
210                                            }
211                                    }
212                            }
213                    }
214    
215                    if (list == null) {
216                            StringBundler query = null;
217    
218                            if (orderByComparator != null) {
219                                    query = new StringBundler(3 +
220                                                    (orderByComparator.getOrderByFields().length * 3));
221                            }
222                            else {
223                                    query = new StringBundler(3);
224                            }
225    
226                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
227    
228                            boolean bindUuid = false;
229    
230                            if (uuid == null) {
231                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
232                            }
233                            else if (uuid.equals(StringPool.BLANK)) {
234                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
235                            }
236                            else {
237                                    bindUuid = true;
238    
239                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
240                            }
241    
242                            if (orderByComparator != null) {
243                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
244                                            orderByComparator);
245                            }
246                            else
247                             if (pagination) {
248                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
249                            }
250    
251                            String sql = query.toString();
252    
253                            Session session = null;
254    
255                            try {
256                                    session = openSession();
257    
258                                    Query q = session.createQuery(sql);
259    
260                                    QueryPos qPos = QueryPos.getInstance(q);
261    
262                                    if (bindUuid) {
263                                            qPos.add(uuid);
264                                    }
265    
266                                    if (!pagination) {
267                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
268                                                            start, end, false);
269    
270                                            Collections.sort(list);
271    
272                                            list = Collections.unmodifiableList(list);
273                                    }
274                                    else {
275                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
276                                                            start, end);
277                                    }
278    
279                                    cacheResult(list);
280    
281                                    finderCache.putResult(finderPath, finderArgs, list);
282                            }
283                            catch (Exception e) {
284                                    finderCache.removeResult(finderPath, finderArgs);
285    
286                                    throw processException(e);
287                            }
288                            finally {
289                                    closeSession(session);
290                            }
291                    }
292    
293                    return list;
294            }
295    
296            /**
297             * Returns the first message boards category in the ordered set where uuid = &#63;.
298             *
299             * @param uuid the uuid
300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
301             * @return the first matching message boards category
302             * @throws NoSuchCategoryException if a matching message boards category could not be found
303             */
304            @Override
305            public MBCategory findByUuid_First(String uuid,
306                    OrderByComparator<MBCategory> orderByComparator)
307                    throws NoSuchCategoryException {
308                    MBCategory mbCategory = fetchByUuid_First(uuid, orderByComparator);
309    
310                    if (mbCategory != null) {
311                            return mbCategory;
312                    }
313    
314                    StringBundler msg = new StringBundler(4);
315    
316                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
317    
318                    msg.append("uuid=");
319                    msg.append(uuid);
320    
321                    msg.append(StringPool.CLOSE_CURLY_BRACE);
322    
323                    throw new NoSuchCategoryException(msg.toString());
324            }
325    
326            /**
327             * Returns the first message boards category in the ordered set where uuid = &#63;.
328             *
329             * @param uuid the uuid
330             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
331             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
332             */
333            @Override
334            public MBCategory fetchByUuid_First(String uuid,
335                    OrderByComparator<MBCategory> orderByComparator) {
336                    List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
337    
338                    if (!list.isEmpty()) {
339                            return list.get(0);
340                    }
341    
342                    return null;
343            }
344    
345            /**
346             * Returns the last message boards category in the ordered set where uuid = &#63;.
347             *
348             * @param uuid the uuid
349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
350             * @return the last matching message boards category
351             * @throws NoSuchCategoryException if a matching message boards category could not be found
352             */
353            @Override
354            public MBCategory findByUuid_Last(String uuid,
355                    OrderByComparator<MBCategory> orderByComparator)
356                    throws NoSuchCategoryException {
357                    MBCategory mbCategory = fetchByUuid_Last(uuid, orderByComparator);
358    
359                    if (mbCategory != null) {
360                            return mbCategory;
361                    }
362    
363                    StringBundler msg = new StringBundler(4);
364    
365                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
366    
367                    msg.append("uuid=");
368                    msg.append(uuid);
369    
370                    msg.append(StringPool.CLOSE_CURLY_BRACE);
371    
372                    throw new NoSuchCategoryException(msg.toString());
373            }
374    
375            /**
376             * Returns the last message boards category in the ordered set where uuid = &#63;.
377             *
378             * @param uuid the uuid
379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
380             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
381             */
382            @Override
383            public MBCategory fetchByUuid_Last(String uuid,
384                    OrderByComparator<MBCategory> orderByComparator) {
385                    int count = countByUuid(uuid);
386    
387                    if (count == 0) {
388                            return null;
389                    }
390    
391                    List<MBCategory> list = findByUuid(uuid, count - 1, count,
392                                    orderByComparator);
393    
394                    if (!list.isEmpty()) {
395                            return list.get(0);
396                    }
397    
398                    return null;
399            }
400    
401            /**
402             * Returns the message boards categories before and after the current message boards category in the ordered set where uuid = &#63;.
403             *
404             * @param categoryId the primary key of the current message boards category
405             * @param uuid the uuid
406             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
407             * @return the previous, current, and next message boards category
408             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
409             */
410            @Override
411            public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
412                    OrderByComparator<MBCategory> orderByComparator)
413                    throws NoSuchCategoryException {
414                    MBCategory mbCategory = findByPrimaryKey(categoryId);
415    
416                    Session session = null;
417    
418                    try {
419                            session = openSession();
420    
421                            MBCategory[] array = new MBCategoryImpl[3];
422    
423                            array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
424                                            orderByComparator, true);
425    
426                            array[1] = mbCategory;
427    
428                            array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
429                                            orderByComparator, false);
430    
431                            return array;
432                    }
433                    catch (Exception e) {
434                            throw processException(e);
435                    }
436                    finally {
437                            closeSession(session);
438                    }
439            }
440    
441            protected MBCategory getByUuid_PrevAndNext(Session session,
442                    MBCategory mbCategory, String uuid,
443                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
444                    StringBundler query = null;
445    
446                    if (orderByComparator != null) {
447                            query = new StringBundler(6 +
448                                            (orderByComparator.getOrderByFields().length * 6));
449                    }
450                    else {
451                            query = new StringBundler(3);
452                    }
453    
454                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
455    
456                    boolean bindUuid = false;
457    
458                    if (uuid == null) {
459                            query.append(_FINDER_COLUMN_UUID_UUID_1);
460                    }
461                    else if (uuid.equals(StringPool.BLANK)) {
462                            query.append(_FINDER_COLUMN_UUID_UUID_3);
463                    }
464                    else {
465                            bindUuid = true;
466    
467                            query.append(_FINDER_COLUMN_UUID_UUID_2);
468                    }
469    
470                    if (orderByComparator != null) {
471                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
472    
473                            if (orderByConditionFields.length > 0) {
474                                    query.append(WHERE_AND);
475                            }
476    
477                            for (int i = 0; i < orderByConditionFields.length; i++) {
478                                    query.append(_ORDER_BY_ENTITY_ALIAS);
479                                    query.append(orderByConditionFields[i]);
480    
481                                    if ((i + 1) < orderByConditionFields.length) {
482                                            if (orderByComparator.isAscending() ^ previous) {
483                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
484                                            }
485                                            else {
486                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
487                                            }
488                                    }
489                                    else {
490                                            if (orderByComparator.isAscending() ^ previous) {
491                                                    query.append(WHERE_GREATER_THAN);
492                                            }
493                                            else {
494                                                    query.append(WHERE_LESSER_THAN);
495                                            }
496                                    }
497                            }
498    
499                            query.append(ORDER_BY_CLAUSE);
500    
501                            String[] orderByFields = orderByComparator.getOrderByFields();
502    
503                            for (int i = 0; i < orderByFields.length; i++) {
504                                    query.append(_ORDER_BY_ENTITY_ALIAS);
505                                    query.append(orderByFields[i]);
506    
507                                    if ((i + 1) < orderByFields.length) {
508                                            if (orderByComparator.isAscending() ^ previous) {
509                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
510                                            }
511                                            else {
512                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
513                                            }
514                                    }
515                                    else {
516                                            if (orderByComparator.isAscending() ^ previous) {
517                                                    query.append(ORDER_BY_ASC);
518                                            }
519                                            else {
520                                                    query.append(ORDER_BY_DESC);
521                                            }
522                                    }
523                            }
524                    }
525                    else {
526                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
527                    }
528    
529                    String sql = query.toString();
530    
531                    Query q = session.createQuery(sql);
532    
533                    q.setFirstResult(0);
534                    q.setMaxResults(2);
535    
536                    QueryPos qPos = QueryPos.getInstance(q);
537    
538                    if (bindUuid) {
539                            qPos.add(uuid);
540                    }
541    
542                    if (orderByComparator != null) {
543                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
544    
545                            for (Object value : values) {
546                                    qPos.add(value);
547                            }
548                    }
549    
550                    List<MBCategory> list = q.list();
551    
552                    if (list.size() == 2) {
553                            return list.get(1);
554                    }
555                    else {
556                            return null;
557                    }
558            }
559    
560            /**
561             * Removes all the message boards categories where uuid = &#63; from the database.
562             *
563             * @param uuid the uuid
564             */
565            @Override
566            public void removeByUuid(String uuid) {
567                    for (MBCategory mbCategory : findByUuid(uuid, QueryUtil.ALL_POS,
568                                    QueryUtil.ALL_POS, null)) {
569                            remove(mbCategory);
570                    }
571            }
572    
573            /**
574             * Returns the number of message boards categories where uuid = &#63;.
575             *
576             * @param uuid the uuid
577             * @return the number of matching message boards categories
578             */
579            @Override
580            public int countByUuid(String uuid) {
581                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
582    
583                    Object[] finderArgs = new Object[] { uuid };
584    
585                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
586    
587                    if (count == null) {
588                            StringBundler query = new StringBundler(2);
589    
590                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
591    
592                            boolean bindUuid = false;
593    
594                            if (uuid == null) {
595                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
596                            }
597                            else if (uuid.equals(StringPool.BLANK)) {
598                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
599                            }
600                            else {
601                                    bindUuid = true;
602    
603                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
604                            }
605    
606                            String sql = query.toString();
607    
608                            Session session = null;
609    
610                            try {
611                                    session = openSession();
612    
613                                    Query q = session.createQuery(sql);
614    
615                                    QueryPos qPos = QueryPos.getInstance(q);
616    
617                                    if (bindUuid) {
618                                            qPos.add(uuid);
619                                    }
620    
621                                    count = (Long)q.uniqueResult();
622    
623                                    finderCache.putResult(finderPath, finderArgs, count);
624                            }
625                            catch (Exception e) {
626                                    finderCache.removeResult(finderPath, finderArgs);
627    
628                                    throw processException(e);
629                            }
630                            finally {
631                                    closeSession(session);
632                            }
633                    }
634    
635                    return count.intValue();
636            }
637    
638            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
639            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
640            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '')";
641            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
642                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
643                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
644                            new String[] { String.class.getName(), Long.class.getName() },
645                            MBCategoryModelImpl.UUID_COLUMN_BITMASK |
646                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK);
647            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
648                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
649                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
650                            new String[] { String.class.getName(), Long.class.getName() });
651    
652            /**
653             * Returns the message boards category where uuid = &#63; and groupId = &#63; or throws a {@link NoSuchCategoryException} if it could not be found.
654             *
655             * @param uuid the uuid
656             * @param groupId the group ID
657             * @return the matching message boards category
658             * @throws NoSuchCategoryException if a matching message boards category could not be found
659             */
660            @Override
661            public MBCategory findByUUID_G(String uuid, long groupId)
662                    throws NoSuchCategoryException {
663                    MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
664    
665                    if (mbCategory == null) {
666                            StringBundler msg = new StringBundler(6);
667    
668                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
669    
670                            msg.append("uuid=");
671                            msg.append(uuid);
672    
673                            msg.append(", groupId=");
674                            msg.append(groupId);
675    
676                            msg.append(StringPool.CLOSE_CURLY_BRACE);
677    
678                            if (_log.isWarnEnabled()) {
679                                    _log.warn(msg.toString());
680                            }
681    
682                            throw new NoSuchCategoryException(msg.toString());
683                    }
684    
685                    return mbCategory;
686            }
687    
688            /**
689             * Returns the message boards category where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
690             *
691             * @param uuid the uuid
692             * @param groupId the group ID
693             * @return the matching message boards category, or <code>null</code> if a matching message boards category could not be found
694             */
695            @Override
696            public MBCategory fetchByUUID_G(String uuid, long groupId) {
697                    return fetchByUUID_G(uuid, groupId, true);
698            }
699    
700            /**
701             * Returns the message boards category where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
702             *
703             * @param uuid the uuid
704             * @param groupId the group ID
705             * @param retrieveFromCache whether to retrieve from the finder cache
706             * @return the matching message boards category, or <code>null</code> if a matching message boards category could not be found
707             */
708            @Override
709            public MBCategory fetchByUUID_G(String uuid, long groupId,
710                    boolean retrieveFromCache) {
711                    Object[] finderArgs = new Object[] { uuid, groupId };
712    
713                    Object result = null;
714    
715                    if (retrieveFromCache) {
716                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_UUID_G,
717                                            finderArgs, this);
718                    }
719    
720                    if (result instanceof MBCategory) {
721                            MBCategory mbCategory = (MBCategory)result;
722    
723                            if (!Validator.equals(uuid, mbCategory.getUuid()) ||
724                                            (groupId != mbCategory.getGroupId())) {
725                                    result = null;
726                            }
727                    }
728    
729                    if (result == null) {
730                            StringBundler query = new StringBundler(4);
731    
732                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
733    
734                            boolean bindUuid = false;
735    
736                            if (uuid == null) {
737                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
738                            }
739                            else if (uuid.equals(StringPool.BLANK)) {
740                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
741                            }
742                            else {
743                                    bindUuid = true;
744    
745                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
746                            }
747    
748                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
749    
750                            String sql = query.toString();
751    
752                            Session session = null;
753    
754                            try {
755                                    session = openSession();
756    
757                                    Query q = session.createQuery(sql);
758    
759                                    QueryPos qPos = QueryPos.getInstance(q);
760    
761                                    if (bindUuid) {
762                                            qPos.add(uuid);
763                                    }
764    
765                                    qPos.add(groupId);
766    
767                                    List<MBCategory> list = q.list();
768    
769                                    if (list.isEmpty()) {
770                                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
771                                                    finderArgs, list);
772                                    }
773                                    else {
774                                            MBCategory mbCategory = list.get(0);
775    
776                                            result = mbCategory;
777    
778                                            cacheResult(mbCategory);
779    
780                                            if ((mbCategory.getUuid() == null) ||
781                                                            !mbCategory.getUuid().equals(uuid) ||
782                                                            (mbCategory.getGroupId() != groupId)) {
783                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
784                                                            finderArgs, mbCategory);
785                                            }
786                                    }
787                            }
788                            catch (Exception e) {
789                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
790    
791                                    throw processException(e);
792                            }
793                            finally {
794                                    closeSession(session);
795                            }
796                    }
797    
798                    if (result instanceof List<?>) {
799                            return null;
800                    }
801                    else {
802                            return (MBCategory)result;
803                    }
804            }
805    
806            /**
807             * Removes the message boards category where uuid = &#63; and groupId = &#63; from the database.
808             *
809             * @param uuid the uuid
810             * @param groupId the group ID
811             * @return the message boards category that was removed
812             */
813            @Override
814            public MBCategory removeByUUID_G(String uuid, long groupId)
815                    throws NoSuchCategoryException {
816                    MBCategory mbCategory = findByUUID_G(uuid, groupId);
817    
818                    return remove(mbCategory);
819            }
820    
821            /**
822             * Returns the number of message boards categories where uuid = &#63; and groupId = &#63;.
823             *
824             * @param uuid the uuid
825             * @param groupId the group ID
826             * @return the number of matching message boards categories
827             */
828            @Override
829            public int countByUUID_G(String uuid, long groupId) {
830                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
831    
832                    Object[] finderArgs = new Object[] { uuid, groupId };
833    
834                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
835    
836                    if (count == null) {
837                            StringBundler query = new StringBundler(3);
838    
839                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
840    
841                            boolean bindUuid = false;
842    
843                            if (uuid == null) {
844                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
845                            }
846                            else if (uuid.equals(StringPool.BLANK)) {
847                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
848                            }
849                            else {
850                                    bindUuid = true;
851    
852                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
853                            }
854    
855                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
856    
857                            String sql = query.toString();
858    
859                            Session session = null;
860    
861                            try {
862                                    session = openSession();
863    
864                                    Query q = session.createQuery(sql);
865    
866                                    QueryPos qPos = QueryPos.getInstance(q);
867    
868                                    if (bindUuid) {
869                                            qPos.add(uuid);
870                                    }
871    
872                                    qPos.add(groupId);
873    
874                                    count = (Long)q.uniqueResult();
875    
876                                    finderCache.putResult(finderPath, finderArgs, count);
877                            }
878                            catch (Exception e) {
879                                    finderCache.removeResult(finderPath, finderArgs);
880    
881                                    throw processException(e);
882                            }
883                            finally {
884                                    closeSession(session);
885                            }
886                    }
887    
888                    return count.intValue();
889            }
890    
891            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
892            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
893            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '') AND ";
894            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
895            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
896                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
897                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
898                            new String[] {
899                                    String.class.getName(), Long.class.getName(),
900                                    
901                            Integer.class.getName(), Integer.class.getName(),
902                                    OrderByComparator.class.getName()
903                            });
904            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
905                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
906                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
907                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
908                            new String[] { String.class.getName(), Long.class.getName() },
909                            MBCategoryModelImpl.UUID_COLUMN_BITMASK |
910                            MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
911                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
912                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
913            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
914                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
915                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
916                            new String[] { String.class.getName(), Long.class.getName() });
917    
918            /**
919             * Returns all the message boards categories where uuid = &#63; and companyId = &#63;.
920             *
921             * @param uuid the uuid
922             * @param companyId the company ID
923             * @return the matching message boards categories
924             */
925            @Override
926            public List<MBCategory> findByUuid_C(String uuid, long companyId) {
927                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
928                            QueryUtil.ALL_POS, null);
929            }
930    
931            /**
932             * Returns a range of all the message boards categories where uuid = &#63; and companyId = &#63;.
933             *
934             * <p>
935             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
936             * </p>
937             *
938             * @param uuid the uuid
939             * @param companyId the company ID
940             * @param start the lower bound of the range of message boards categories
941             * @param end the upper bound of the range of message boards categories (not inclusive)
942             * @return the range of matching message boards categories
943             */
944            @Override
945            public List<MBCategory> findByUuid_C(String uuid, long companyId,
946                    int start, int end) {
947                    return findByUuid_C(uuid, companyId, start, end, null);
948            }
949    
950            /**
951             * Returns an ordered range of all the message boards categories where uuid = &#63; and companyId = &#63;.
952             *
953             * <p>
954             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
955             * </p>
956             *
957             * @param uuid the uuid
958             * @param companyId the company ID
959             * @param start the lower bound of the range of message boards categories
960             * @param end the upper bound of the range of message boards categories (not inclusive)
961             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
962             * @return the ordered range of matching message boards categories
963             */
964            @Override
965            public List<MBCategory> findByUuid_C(String uuid, long companyId,
966                    int start, int end, OrderByComparator<MBCategory> orderByComparator) {
967                    return findByUuid_C(uuid, companyId, start, end, orderByComparator, true);
968            }
969    
970            /**
971             * Returns an ordered range of all the message boards categories where uuid = &#63; and companyId = &#63;.
972             *
973             * <p>
974             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
975             * </p>
976             *
977             * @param uuid the uuid
978             * @param companyId the company ID
979             * @param start the lower bound of the range of message boards categories
980             * @param end the upper bound of the range of message boards categories (not inclusive)
981             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
982             * @param retrieveFromCache whether to retrieve from the finder cache
983             * @return the ordered range of matching message boards categories
984             */
985            @Override
986            public List<MBCategory> findByUuid_C(String uuid, long companyId,
987                    int start, int end, OrderByComparator<MBCategory> orderByComparator,
988                    boolean retrieveFromCache) {
989                    boolean pagination = true;
990                    FinderPath finderPath = null;
991                    Object[] finderArgs = null;
992    
993                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
994                                    (orderByComparator == null)) {
995                            pagination = false;
996                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
997                            finderArgs = new Object[] { uuid, companyId };
998                    }
999                    else {
1000                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1001                            finderArgs = new Object[] {
1002                                            uuid, companyId,
1003                                            
1004                                            start, end, orderByComparator
1005                                    };
1006                    }
1007    
1008                    List<MBCategory> list = null;
1009    
1010                    if (retrieveFromCache) {
1011                            list = (List<MBCategory>)finderCache.getResult(finderPath,
1012                                            finderArgs, this);
1013    
1014                            if ((list != null) && !list.isEmpty()) {
1015                                    for (MBCategory mbCategory : list) {
1016                                            if (!Validator.equals(uuid, mbCategory.getUuid()) ||
1017                                                            (companyId != mbCategory.getCompanyId())) {
1018                                                    list = null;
1019    
1020                                                    break;
1021                                            }
1022                                    }
1023                            }
1024                    }
1025    
1026                    if (list == null) {
1027                            StringBundler query = null;
1028    
1029                            if (orderByComparator != null) {
1030                                    query = new StringBundler(4 +
1031                                                    (orderByComparator.getOrderByFields().length * 3));
1032                            }
1033                            else {
1034                                    query = new StringBundler(4);
1035                            }
1036    
1037                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1038    
1039                            boolean bindUuid = false;
1040    
1041                            if (uuid == null) {
1042                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1043                            }
1044                            else if (uuid.equals(StringPool.BLANK)) {
1045                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1046                            }
1047                            else {
1048                                    bindUuid = true;
1049    
1050                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1051                            }
1052    
1053                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1054    
1055                            if (orderByComparator != null) {
1056                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1057                                            orderByComparator);
1058                            }
1059                            else
1060                             if (pagination) {
1061                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1062                            }
1063    
1064                            String sql = query.toString();
1065    
1066                            Session session = null;
1067    
1068                            try {
1069                                    session = openSession();
1070    
1071                                    Query q = session.createQuery(sql);
1072    
1073                                    QueryPos qPos = QueryPos.getInstance(q);
1074    
1075                                    if (bindUuid) {
1076                                            qPos.add(uuid);
1077                                    }
1078    
1079                                    qPos.add(companyId);
1080    
1081                                    if (!pagination) {
1082                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1083                                                            start, end, false);
1084    
1085                                            Collections.sort(list);
1086    
1087                                            list = Collections.unmodifiableList(list);
1088                                    }
1089                                    else {
1090                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1091                                                            start, end);
1092                                    }
1093    
1094                                    cacheResult(list);
1095    
1096                                    finderCache.putResult(finderPath, finderArgs, list);
1097                            }
1098                            catch (Exception e) {
1099                                    finderCache.removeResult(finderPath, finderArgs);
1100    
1101                                    throw processException(e);
1102                            }
1103                            finally {
1104                                    closeSession(session);
1105                            }
1106                    }
1107    
1108                    return list;
1109            }
1110    
1111            /**
1112             * Returns the first message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1113             *
1114             * @param uuid the uuid
1115             * @param companyId the company ID
1116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1117             * @return the first matching message boards category
1118             * @throws NoSuchCategoryException if a matching message boards category could not be found
1119             */
1120            @Override
1121            public MBCategory findByUuid_C_First(String uuid, long companyId,
1122                    OrderByComparator<MBCategory> orderByComparator)
1123                    throws NoSuchCategoryException {
1124                    MBCategory mbCategory = fetchByUuid_C_First(uuid, companyId,
1125                                    orderByComparator);
1126    
1127                    if (mbCategory != null) {
1128                            return mbCategory;
1129                    }
1130    
1131                    StringBundler msg = new StringBundler(6);
1132    
1133                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1134    
1135                    msg.append("uuid=");
1136                    msg.append(uuid);
1137    
1138                    msg.append(", companyId=");
1139                    msg.append(companyId);
1140    
1141                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1142    
1143                    throw new NoSuchCategoryException(msg.toString());
1144            }
1145    
1146            /**
1147             * Returns the first message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1148             *
1149             * @param uuid the uuid
1150             * @param companyId the company ID
1151             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1152             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
1153             */
1154            @Override
1155            public MBCategory fetchByUuid_C_First(String uuid, long companyId,
1156                    OrderByComparator<MBCategory> orderByComparator) {
1157                    List<MBCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1158                                    orderByComparator);
1159    
1160                    if (!list.isEmpty()) {
1161                            return list.get(0);
1162                    }
1163    
1164                    return null;
1165            }
1166    
1167            /**
1168             * Returns the last message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1169             *
1170             * @param uuid the uuid
1171             * @param companyId the company ID
1172             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1173             * @return the last matching message boards category
1174             * @throws NoSuchCategoryException if a matching message boards category could not be found
1175             */
1176            @Override
1177            public MBCategory findByUuid_C_Last(String uuid, long companyId,
1178                    OrderByComparator<MBCategory> orderByComparator)
1179                    throws NoSuchCategoryException {
1180                    MBCategory mbCategory = fetchByUuid_C_Last(uuid, companyId,
1181                                    orderByComparator);
1182    
1183                    if (mbCategory != null) {
1184                            return mbCategory;
1185                    }
1186    
1187                    StringBundler msg = new StringBundler(6);
1188    
1189                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1190    
1191                    msg.append("uuid=");
1192                    msg.append(uuid);
1193    
1194                    msg.append(", companyId=");
1195                    msg.append(companyId);
1196    
1197                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1198    
1199                    throw new NoSuchCategoryException(msg.toString());
1200            }
1201    
1202            /**
1203             * Returns the last message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1204             *
1205             * @param uuid the uuid
1206             * @param companyId the company ID
1207             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1208             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
1209             */
1210            @Override
1211            public MBCategory fetchByUuid_C_Last(String uuid, long companyId,
1212                    OrderByComparator<MBCategory> orderByComparator) {
1213                    int count = countByUuid_C(uuid, companyId);
1214    
1215                    if (count == 0) {
1216                            return null;
1217                    }
1218    
1219                    List<MBCategory> list = findByUuid_C(uuid, companyId, count - 1, count,
1220                                    orderByComparator);
1221    
1222                    if (!list.isEmpty()) {
1223                            return list.get(0);
1224                    }
1225    
1226                    return null;
1227            }
1228    
1229            /**
1230             * Returns the message boards categories before and after the current message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1231             *
1232             * @param categoryId the primary key of the current message boards category
1233             * @param uuid the uuid
1234             * @param companyId the company ID
1235             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1236             * @return the previous, current, and next message boards category
1237             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
1238             */
1239            @Override
1240            public MBCategory[] findByUuid_C_PrevAndNext(long categoryId, String uuid,
1241                    long companyId, OrderByComparator<MBCategory> orderByComparator)
1242                    throws NoSuchCategoryException {
1243                    MBCategory mbCategory = findByPrimaryKey(categoryId);
1244    
1245                    Session session = null;
1246    
1247                    try {
1248                            session = openSession();
1249    
1250                            MBCategory[] array = new MBCategoryImpl[3];
1251    
1252                            array[0] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1253                                            companyId, orderByComparator, true);
1254    
1255                            array[1] = mbCategory;
1256    
1257                            array[2] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1258                                            companyId, orderByComparator, false);
1259    
1260                            return array;
1261                    }
1262                    catch (Exception e) {
1263                            throw processException(e);
1264                    }
1265                    finally {
1266                            closeSession(session);
1267                    }
1268            }
1269    
1270            protected MBCategory getByUuid_C_PrevAndNext(Session session,
1271                    MBCategory mbCategory, String uuid, long companyId,
1272                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
1273                    StringBundler query = null;
1274    
1275                    if (orderByComparator != null) {
1276                            query = new StringBundler(6 +
1277                                            (orderByComparator.getOrderByFields().length * 6));
1278                    }
1279                    else {
1280                            query = new StringBundler(3);
1281                    }
1282    
1283                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1284    
1285                    boolean bindUuid = false;
1286    
1287                    if (uuid == null) {
1288                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1289                    }
1290                    else if (uuid.equals(StringPool.BLANK)) {
1291                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1292                    }
1293                    else {
1294                            bindUuid = true;
1295    
1296                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1297                    }
1298    
1299                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1300    
1301                    if (orderByComparator != null) {
1302                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1303    
1304                            if (orderByConditionFields.length > 0) {
1305                                    query.append(WHERE_AND);
1306                            }
1307    
1308                            for (int i = 0; i < orderByConditionFields.length; i++) {
1309                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1310                                    query.append(orderByConditionFields[i]);
1311    
1312                                    if ((i + 1) < orderByConditionFields.length) {
1313                                            if (orderByComparator.isAscending() ^ previous) {
1314                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1315                                            }
1316                                            else {
1317                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1318                                            }
1319                                    }
1320                                    else {
1321                                            if (orderByComparator.isAscending() ^ previous) {
1322                                                    query.append(WHERE_GREATER_THAN);
1323                                            }
1324                                            else {
1325                                                    query.append(WHERE_LESSER_THAN);
1326                                            }
1327                                    }
1328                            }
1329    
1330                            query.append(ORDER_BY_CLAUSE);
1331    
1332                            String[] orderByFields = orderByComparator.getOrderByFields();
1333    
1334                            for (int i = 0; i < orderByFields.length; i++) {
1335                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1336                                    query.append(orderByFields[i]);
1337    
1338                                    if ((i + 1) < orderByFields.length) {
1339                                            if (orderByComparator.isAscending() ^ previous) {
1340                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1341                                            }
1342                                            else {
1343                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1344                                            }
1345                                    }
1346                                    else {
1347                                            if (orderByComparator.isAscending() ^ previous) {
1348                                                    query.append(ORDER_BY_ASC);
1349                                            }
1350                                            else {
1351                                                    query.append(ORDER_BY_DESC);
1352                                            }
1353                                    }
1354                            }
1355                    }
1356                    else {
1357                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1358                    }
1359    
1360                    String sql = query.toString();
1361    
1362                    Query q = session.createQuery(sql);
1363    
1364                    q.setFirstResult(0);
1365                    q.setMaxResults(2);
1366    
1367                    QueryPos qPos = QueryPos.getInstance(q);
1368    
1369                    if (bindUuid) {
1370                            qPos.add(uuid);
1371                    }
1372    
1373                    qPos.add(companyId);
1374    
1375                    if (orderByComparator != null) {
1376                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1377    
1378                            for (Object value : values) {
1379                                    qPos.add(value);
1380                            }
1381                    }
1382    
1383                    List<MBCategory> list = q.list();
1384    
1385                    if (list.size() == 2) {
1386                            return list.get(1);
1387                    }
1388                    else {
1389                            return null;
1390                    }
1391            }
1392    
1393            /**
1394             * Removes all the message boards categories where uuid = &#63; and companyId = &#63; from the database.
1395             *
1396             * @param uuid the uuid
1397             * @param companyId the company ID
1398             */
1399            @Override
1400            public void removeByUuid_C(String uuid, long companyId) {
1401                    for (MBCategory mbCategory : findByUuid_C(uuid, companyId,
1402                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1403                            remove(mbCategory);
1404                    }
1405            }
1406    
1407            /**
1408             * Returns the number of message boards categories where uuid = &#63; and companyId = &#63;.
1409             *
1410             * @param uuid the uuid
1411             * @param companyId the company ID
1412             * @return the number of matching message boards categories
1413             */
1414            @Override
1415            public int countByUuid_C(String uuid, long companyId) {
1416                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1417    
1418                    Object[] finderArgs = new Object[] { uuid, companyId };
1419    
1420                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1421    
1422                    if (count == null) {
1423                            StringBundler query = new StringBundler(3);
1424    
1425                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
1426    
1427                            boolean bindUuid = false;
1428    
1429                            if (uuid == null) {
1430                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1431                            }
1432                            else if (uuid.equals(StringPool.BLANK)) {
1433                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1434                            }
1435                            else {
1436                                    bindUuid = true;
1437    
1438                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1439                            }
1440    
1441                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1442    
1443                            String sql = query.toString();
1444    
1445                            Session session = null;
1446    
1447                            try {
1448                                    session = openSession();
1449    
1450                                    Query q = session.createQuery(sql);
1451    
1452                                    QueryPos qPos = QueryPos.getInstance(q);
1453    
1454                                    if (bindUuid) {
1455                                            qPos.add(uuid);
1456                                    }
1457    
1458                                    qPos.add(companyId);
1459    
1460                                    count = (Long)q.uniqueResult();
1461    
1462                                    finderCache.putResult(finderPath, finderArgs, count);
1463                            }
1464                            catch (Exception e) {
1465                                    finderCache.removeResult(finderPath, finderArgs);
1466    
1467                                    throw processException(e);
1468                            }
1469                            finally {
1470                                    closeSession(session);
1471                            }
1472                    }
1473    
1474                    return count.intValue();
1475            }
1476    
1477            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbCategory.uuid IS NULL AND ";
1478            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbCategory.uuid = ? AND ";
1479            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '') AND ";
1480            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbCategory.companyId = ?";
1481            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1482                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1483                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1484                            new String[] {
1485                                    Long.class.getName(),
1486                                    
1487                            Integer.class.getName(), Integer.class.getName(),
1488                                    OrderByComparator.class.getName()
1489                            });
1490            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1491                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1492                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1493                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1494                            new String[] { Long.class.getName() },
1495                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
1496                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
1497                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
1498            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1499                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1500                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1501                            new String[] { Long.class.getName() });
1502    
1503            /**
1504             * Returns all the message boards categories where groupId = &#63;.
1505             *
1506             * @param groupId the group ID
1507             * @return the matching message boards categories
1508             */
1509            @Override
1510            public List<MBCategory> findByGroupId(long groupId) {
1511                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1512            }
1513    
1514            /**
1515             * Returns a range of all the message boards categories where groupId = &#63;.
1516             *
1517             * <p>
1518             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
1519             * </p>
1520             *
1521             * @param groupId the group ID
1522             * @param start the lower bound of the range of message boards categories
1523             * @param end the upper bound of the range of message boards categories (not inclusive)
1524             * @return the range of matching message boards categories
1525             */
1526            @Override
1527            public List<MBCategory> findByGroupId(long groupId, int start, int end) {
1528                    return findByGroupId(groupId, start, end, null);
1529            }
1530    
1531            /**
1532             * Returns an ordered range of all the message boards categories where groupId = &#63;.
1533             *
1534             * <p>
1535             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
1536             * </p>
1537             *
1538             * @param groupId the group ID
1539             * @param start the lower bound of the range of message boards categories
1540             * @param end the upper bound of the range of message boards categories (not inclusive)
1541             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1542             * @return the ordered range of matching message boards categories
1543             */
1544            @Override
1545            public List<MBCategory> findByGroupId(long groupId, int start, int end,
1546                    OrderByComparator<MBCategory> orderByComparator) {
1547                    return findByGroupId(groupId, start, end, orderByComparator, true);
1548            }
1549    
1550            /**
1551             * Returns an ordered range of all the message boards categories where groupId = &#63;.
1552             *
1553             * <p>
1554             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
1555             * </p>
1556             *
1557             * @param groupId the group ID
1558             * @param start the lower bound of the range of message boards categories
1559             * @param end the upper bound of the range of message boards categories (not inclusive)
1560             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1561             * @param retrieveFromCache whether to retrieve from the finder cache
1562             * @return the ordered range of matching message boards categories
1563             */
1564            @Override
1565            public List<MBCategory> findByGroupId(long groupId, int start, int end,
1566                    OrderByComparator<MBCategory> orderByComparator,
1567                    boolean retrieveFromCache) {
1568                    boolean pagination = true;
1569                    FinderPath finderPath = null;
1570                    Object[] finderArgs = null;
1571    
1572                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1573                                    (orderByComparator == null)) {
1574                            pagination = false;
1575                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1576                            finderArgs = new Object[] { groupId };
1577                    }
1578                    else {
1579                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1580                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1581                    }
1582    
1583                    List<MBCategory> list = null;
1584    
1585                    if (retrieveFromCache) {
1586                            list = (List<MBCategory>)finderCache.getResult(finderPath,
1587                                            finderArgs, this);
1588    
1589                            if ((list != null) && !list.isEmpty()) {
1590                                    for (MBCategory mbCategory : list) {
1591                                            if ((groupId != mbCategory.getGroupId())) {
1592                                                    list = null;
1593    
1594                                                    break;
1595                                            }
1596                                    }
1597                            }
1598                    }
1599    
1600                    if (list == null) {
1601                            StringBundler query = null;
1602    
1603                            if (orderByComparator != null) {
1604                                    query = new StringBundler(3 +
1605                                                    (orderByComparator.getOrderByFields().length * 3));
1606                            }
1607                            else {
1608                                    query = new StringBundler(3);
1609                            }
1610    
1611                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1612    
1613                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1614    
1615                            if (orderByComparator != null) {
1616                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1617                                            orderByComparator);
1618                            }
1619                            else
1620                             if (pagination) {
1621                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1622                            }
1623    
1624                            String sql = query.toString();
1625    
1626                            Session session = null;
1627    
1628                            try {
1629                                    session = openSession();
1630    
1631                                    Query q = session.createQuery(sql);
1632    
1633                                    QueryPos qPos = QueryPos.getInstance(q);
1634    
1635                                    qPos.add(groupId);
1636    
1637                                    if (!pagination) {
1638                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1639                                                            start, end, false);
1640    
1641                                            Collections.sort(list);
1642    
1643                                            list = Collections.unmodifiableList(list);
1644                                    }
1645                                    else {
1646                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1647                                                            start, end);
1648                                    }
1649    
1650                                    cacheResult(list);
1651    
1652                                    finderCache.putResult(finderPath, finderArgs, list);
1653                            }
1654                            catch (Exception e) {
1655                                    finderCache.removeResult(finderPath, finderArgs);
1656    
1657                                    throw processException(e);
1658                            }
1659                            finally {
1660                                    closeSession(session);
1661                            }
1662                    }
1663    
1664                    return list;
1665            }
1666    
1667            /**
1668             * Returns the first message boards category in the ordered set where groupId = &#63;.
1669             *
1670             * @param groupId the group ID
1671             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1672             * @return the first matching message boards category
1673             * @throws NoSuchCategoryException if a matching message boards category could not be found
1674             */
1675            @Override
1676            public MBCategory findByGroupId_First(long groupId,
1677                    OrderByComparator<MBCategory> orderByComparator)
1678                    throws NoSuchCategoryException {
1679                    MBCategory mbCategory = fetchByGroupId_First(groupId, orderByComparator);
1680    
1681                    if (mbCategory != null) {
1682                            return mbCategory;
1683                    }
1684    
1685                    StringBundler msg = new StringBundler(4);
1686    
1687                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1688    
1689                    msg.append("groupId=");
1690                    msg.append(groupId);
1691    
1692                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1693    
1694                    throw new NoSuchCategoryException(msg.toString());
1695            }
1696    
1697            /**
1698             * Returns the first message boards category in the ordered set where groupId = &#63;.
1699             *
1700             * @param groupId the group ID
1701             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1702             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
1703             */
1704            @Override
1705            public MBCategory fetchByGroupId_First(long groupId,
1706                    OrderByComparator<MBCategory> orderByComparator) {
1707                    List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1708    
1709                    if (!list.isEmpty()) {
1710                            return list.get(0);
1711                    }
1712    
1713                    return null;
1714            }
1715    
1716            /**
1717             * Returns the last message boards category in the ordered set where groupId = &#63;.
1718             *
1719             * @param groupId the group ID
1720             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1721             * @return the last matching message boards category
1722             * @throws NoSuchCategoryException if a matching message boards category could not be found
1723             */
1724            @Override
1725            public MBCategory findByGroupId_Last(long groupId,
1726                    OrderByComparator<MBCategory> orderByComparator)
1727                    throws NoSuchCategoryException {
1728                    MBCategory mbCategory = fetchByGroupId_Last(groupId, orderByComparator);
1729    
1730                    if (mbCategory != null) {
1731                            return mbCategory;
1732                    }
1733    
1734                    StringBundler msg = new StringBundler(4);
1735    
1736                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1737    
1738                    msg.append("groupId=");
1739                    msg.append(groupId);
1740    
1741                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1742    
1743                    throw new NoSuchCategoryException(msg.toString());
1744            }
1745    
1746            /**
1747             * Returns the last message boards category in the ordered set where groupId = &#63;.
1748             *
1749             * @param groupId the group ID
1750             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1751             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
1752             */
1753            @Override
1754            public MBCategory fetchByGroupId_Last(long groupId,
1755                    OrderByComparator<MBCategory> orderByComparator) {
1756                    int count = countByGroupId(groupId);
1757    
1758                    if (count == 0) {
1759                            return null;
1760                    }
1761    
1762                    List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1763                                    orderByComparator);
1764    
1765                    if (!list.isEmpty()) {
1766                            return list.get(0);
1767                    }
1768    
1769                    return null;
1770            }
1771    
1772            /**
1773             * Returns the message boards categories before and after the current message boards category in the ordered set where groupId = &#63;.
1774             *
1775             * @param categoryId the primary key of the current message boards category
1776             * @param groupId the group ID
1777             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1778             * @return the previous, current, and next message boards category
1779             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
1780             */
1781            @Override
1782            public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1783                    long groupId, OrderByComparator<MBCategory> orderByComparator)
1784                    throws NoSuchCategoryException {
1785                    MBCategory mbCategory = findByPrimaryKey(categoryId);
1786    
1787                    Session session = null;
1788    
1789                    try {
1790                            session = openSession();
1791    
1792                            MBCategory[] array = new MBCategoryImpl[3];
1793    
1794                            array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1795                                            orderByComparator, true);
1796    
1797                            array[1] = mbCategory;
1798    
1799                            array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1800                                            orderByComparator, false);
1801    
1802                            return array;
1803                    }
1804                    catch (Exception e) {
1805                            throw processException(e);
1806                    }
1807                    finally {
1808                            closeSession(session);
1809                    }
1810            }
1811    
1812            protected MBCategory getByGroupId_PrevAndNext(Session session,
1813                    MBCategory mbCategory, long groupId,
1814                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
1815                    StringBundler query = null;
1816    
1817                    if (orderByComparator != null) {
1818                            query = new StringBundler(6 +
1819                                            (orderByComparator.getOrderByFields().length * 6));
1820                    }
1821                    else {
1822                            query = new StringBundler(3);
1823                    }
1824    
1825                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1826    
1827                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1828    
1829                    if (orderByComparator != null) {
1830                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1831    
1832                            if (orderByConditionFields.length > 0) {
1833                                    query.append(WHERE_AND);
1834                            }
1835    
1836                            for (int i = 0; i < orderByConditionFields.length; i++) {
1837                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1838                                    query.append(orderByConditionFields[i]);
1839    
1840                                    if ((i + 1) < orderByConditionFields.length) {
1841                                            if (orderByComparator.isAscending() ^ previous) {
1842                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1843                                            }
1844                                            else {
1845                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1846                                            }
1847                                    }
1848                                    else {
1849                                            if (orderByComparator.isAscending() ^ previous) {
1850                                                    query.append(WHERE_GREATER_THAN);
1851                                            }
1852                                            else {
1853                                                    query.append(WHERE_LESSER_THAN);
1854                                            }
1855                                    }
1856                            }
1857    
1858                            query.append(ORDER_BY_CLAUSE);
1859    
1860                            String[] orderByFields = orderByComparator.getOrderByFields();
1861    
1862                            for (int i = 0; i < orderByFields.length; i++) {
1863                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1864                                    query.append(orderByFields[i]);
1865    
1866                                    if ((i + 1) < orderByFields.length) {
1867                                            if (orderByComparator.isAscending() ^ previous) {
1868                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1869                                            }
1870                                            else {
1871                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1872                                            }
1873                                    }
1874                                    else {
1875                                            if (orderByComparator.isAscending() ^ previous) {
1876                                                    query.append(ORDER_BY_ASC);
1877                                            }
1878                                            else {
1879                                                    query.append(ORDER_BY_DESC);
1880                                            }
1881                                    }
1882                            }
1883                    }
1884                    else {
1885                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1886                    }
1887    
1888                    String sql = query.toString();
1889    
1890                    Query q = session.createQuery(sql);
1891    
1892                    q.setFirstResult(0);
1893                    q.setMaxResults(2);
1894    
1895                    QueryPos qPos = QueryPos.getInstance(q);
1896    
1897                    qPos.add(groupId);
1898    
1899                    if (orderByComparator != null) {
1900                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1901    
1902                            for (Object value : values) {
1903                                    qPos.add(value);
1904                            }
1905                    }
1906    
1907                    List<MBCategory> list = q.list();
1908    
1909                    if (list.size() == 2) {
1910                            return list.get(1);
1911                    }
1912                    else {
1913                            return null;
1914                    }
1915            }
1916    
1917            /**
1918             * Returns all the message boards categories that the user has permission to view where groupId = &#63;.
1919             *
1920             * @param groupId the group ID
1921             * @return the matching message boards categories that the user has permission to view
1922             */
1923            @Override
1924            public List<MBCategory> filterFindByGroupId(long groupId) {
1925                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1926                            QueryUtil.ALL_POS, null);
1927            }
1928    
1929            /**
1930             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63;.
1931             *
1932             * <p>
1933             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
1934             * </p>
1935             *
1936             * @param groupId the group ID
1937             * @param start the lower bound of the range of message boards categories
1938             * @param end the upper bound of the range of message boards categories (not inclusive)
1939             * @return the range of matching message boards categories that the user has permission to view
1940             */
1941            @Override
1942            public List<MBCategory> filterFindByGroupId(long groupId, int start, int end) {
1943                    return filterFindByGroupId(groupId, start, end, null);
1944            }
1945    
1946            /**
1947             * Returns an ordered range of all the message boards categories that the user has permissions to view where groupId = &#63;.
1948             *
1949             * <p>
1950             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
1951             * </p>
1952             *
1953             * @param groupId the group ID
1954             * @param start the lower bound of the range of message boards categories
1955             * @param end the upper bound of the range of message boards categories (not inclusive)
1956             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1957             * @return the ordered range of matching message boards categories that the user has permission to view
1958             */
1959            @Override
1960            public List<MBCategory> filterFindByGroupId(long groupId, int start,
1961                    int end, OrderByComparator<MBCategory> orderByComparator) {
1962                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1963                            return findByGroupId(groupId, start, end, orderByComparator);
1964                    }
1965    
1966                    StringBundler query = null;
1967    
1968                    if (orderByComparator != null) {
1969                            query = new StringBundler(3 +
1970                                            (orderByComparator.getOrderByFields().length * 3));
1971                    }
1972                    else {
1973                            query = new StringBundler(3);
1974                    }
1975    
1976                    if (getDB().isSupportsInlineDistinct()) {
1977                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1978                    }
1979                    else {
1980                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1981                    }
1982    
1983                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1984    
1985                    if (!getDB().isSupportsInlineDistinct()) {
1986                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1987                    }
1988    
1989                    if (orderByComparator != null) {
1990                            if (getDB().isSupportsInlineDistinct()) {
1991                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1992                                            orderByComparator, true);
1993                            }
1994                            else {
1995                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1996                                            orderByComparator, true);
1997                            }
1998                    }
1999                    else {
2000                            if (getDB().isSupportsInlineDistinct()) {
2001                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2002                            }
2003                            else {
2004                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2005                            }
2006                    }
2007    
2008                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2009                                    MBCategory.class.getName(),
2010                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2011    
2012                    Session session = null;
2013    
2014                    try {
2015                            session = openSession();
2016    
2017                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2018    
2019                            if (getDB().isSupportsInlineDistinct()) {
2020                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2021                            }
2022                            else {
2023                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2024                            }
2025    
2026                            QueryPos qPos = QueryPos.getInstance(q);
2027    
2028                            qPos.add(groupId);
2029    
2030                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
2031                    }
2032                    catch (Exception e) {
2033                            throw processException(e);
2034                    }
2035                    finally {
2036                            closeSession(session);
2037                    }
2038            }
2039    
2040            /**
2041             * Returns the message boards categories before and after the current message boards category in the ordered set of message boards categories that the user has permission to view where groupId = &#63;.
2042             *
2043             * @param categoryId the primary key of the current message boards category
2044             * @param groupId the group ID
2045             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2046             * @return the previous, current, and next message boards category
2047             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
2048             */
2049            @Override
2050            public MBCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
2051                    long groupId, OrderByComparator<MBCategory> orderByComparator)
2052                    throws NoSuchCategoryException {
2053                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2054                            return findByGroupId_PrevAndNext(categoryId, groupId,
2055                                    orderByComparator);
2056                    }
2057    
2058                    MBCategory mbCategory = findByPrimaryKey(categoryId);
2059    
2060                    Session session = null;
2061    
2062                    try {
2063                            session = openSession();
2064    
2065                            MBCategory[] array = new MBCategoryImpl[3];
2066    
2067                            array[0] = filterGetByGroupId_PrevAndNext(session, mbCategory,
2068                                            groupId, orderByComparator, true);
2069    
2070                            array[1] = mbCategory;
2071    
2072                            array[2] = filterGetByGroupId_PrevAndNext(session, mbCategory,
2073                                            groupId, orderByComparator, false);
2074    
2075                            return array;
2076                    }
2077                    catch (Exception e) {
2078                            throw processException(e);
2079                    }
2080                    finally {
2081                            closeSession(session);
2082                    }
2083            }
2084    
2085            protected MBCategory filterGetByGroupId_PrevAndNext(Session session,
2086                    MBCategory mbCategory, long groupId,
2087                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
2088                    StringBundler query = null;
2089    
2090                    if (orderByComparator != null) {
2091                            query = new StringBundler(6 +
2092                                            (orderByComparator.getOrderByFields().length * 6));
2093                    }
2094                    else {
2095                            query = new StringBundler(3);
2096                    }
2097    
2098                    if (getDB().isSupportsInlineDistinct()) {
2099                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2100                    }
2101                    else {
2102                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2103                    }
2104    
2105                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2106    
2107                    if (!getDB().isSupportsInlineDistinct()) {
2108                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2109                    }
2110    
2111                    if (orderByComparator != null) {
2112                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2113    
2114                            if (orderByConditionFields.length > 0) {
2115                                    query.append(WHERE_AND);
2116                            }
2117    
2118                            for (int i = 0; i < orderByConditionFields.length; i++) {
2119                                    if (getDB().isSupportsInlineDistinct()) {
2120                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2121                                    }
2122                                    else {
2123                                            query.append(_ORDER_BY_ENTITY_TABLE);
2124                                    }
2125    
2126                                    query.append(orderByConditionFields[i]);
2127    
2128                                    if ((i + 1) < orderByConditionFields.length) {
2129                                            if (orderByComparator.isAscending() ^ previous) {
2130                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2131                                            }
2132                                            else {
2133                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2134                                            }
2135                                    }
2136                                    else {
2137                                            if (orderByComparator.isAscending() ^ previous) {
2138                                                    query.append(WHERE_GREATER_THAN);
2139                                            }
2140                                            else {
2141                                                    query.append(WHERE_LESSER_THAN);
2142                                            }
2143                                    }
2144                            }
2145    
2146                            query.append(ORDER_BY_CLAUSE);
2147    
2148                            String[] orderByFields = orderByComparator.getOrderByFields();
2149    
2150                            for (int i = 0; i < orderByFields.length; i++) {
2151                                    if (getDB().isSupportsInlineDistinct()) {
2152                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2153                                    }
2154                                    else {
2155                                            query.append(_ORDER_BY_ENTITY_TABLE);
2156                                    }
2157    
2158                                    query.append(orderByFields[i]);
2159    
2160                                    if ((i + 1) < orderByFields.length) {
2161                                            if (orderByComparator.isAscending() ^ previous) {
2162                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2163                                            }
2164                                            else {
2165                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2166                                            }
2167                                    }
2168                                    else {
2169                                            if (orderByComparator.isAscending() ^ previous) {
2170                                                    query.append(ORDER_BY_ASC);
2171                                            }
2172                                            else {
2173                                                    query.append(ORDER_BY_DESC);
2174                                            }
2175                                    }
2176                            }
2177                    }
2178                    else {
2179                            if (getDB().isSupportsInlineDistinct()) {
2180                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2181                            }
2182                            else {
2183                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2184                            }
2185                    }
2186    
2187                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2188                                    MBCategory.class.getName(),
2189                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2190    
2191                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
2192    
2193                    q.setFirstResult(0);
2194                    q.setMaxResults(2);
2195    
2196                    if (getDB().isSupportsInlineDistinct()) {
2197                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2198                    }
2199                    else {
2200                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2201                    }
2202    
2203                    QueryPos qPos = QueryPos.getInstance(q);
2204    
2205                    qPos.add(groupId);
2206    
2207                    if (orderByComparator != null) {
2208                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2209    
2210                            for (Object value : values) {
2211                                    qPos.add(value);
2212                            }
2213                    }
2214    
2215                    List<MBCategory> list = q.list();
2216    
2217                    if (list.size() == 2) {
2218                            return list.get(1);
2219                    }
2220                    else {
2221                            return null;
2222                    }
2223            }
2224    
2225            /**
2226             * Removes all the message boards categories where groupId = &#63; from the database.
2227             *
2228             * @param groupId the group ID
2229             */
2230            @Override
2231            public void removeByGroupId(long groupId) {
2232                    for (MBCategory mbCategory : findByGroupId(groupId, QueryUtil.ALL_POS,
2233                                    QueryUtil.ALL_POS, null)) {
2234                            remove(mbCategory);
2235                    }
2236            }
2237    
2238            /**
2239             * Returns the number of message boards categories where groupId = &#63;.
2240             *
2241             * @param groupId the group ID
2242             * @return the number of matching message boards categories
2243             */
2244            @Override
2245            public int countByGroupId(long groupId) {
2246                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2247    
2248                    Object[] finderArgs = new Object[] { groupId };
2249    
2250                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2251    
2252                    if (count == null) {
2253                            StringBundler query = new StringBundler(2);
2254    
2255                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2256    
2257                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2258    
2259                            String sql = query.toString();
2260    
2261                            Session session = null;
2262    
2263                            try {
2264                                    session = openSession();
2265    
2266                                    Query q = session.createQuery(sql);
2267    
2268                                    QueryPos qPos = QueryPos.getInstance(q);
2269    
2270                                    qPos.add(groupId);
2271    
2272                                    count = (Long)q.uniqueResult();
2273    
2274                                    finderCache.putResult(finderPath, finderArgs, count);
2275                            }
2276                            catch (Exception e) {
2277                                    finderCache.removeResult(finderPath, finderArgs);
2278    
2279                                    throw processException(e);
2280                            }
2281                            finally {
2282                                    closeSession(session);
2283                            }
2284                    }
2285    
2286                    return count.intValue();
2287            }
2288    
2289            /**
2290             * Returns the number of message boards categories that the user has permission to view where groupId = &#63;.
2291             *
2292             * @param groupId the group ID
2293             * @return the number of matching message boards categories that the user has permission to view
2294             */
2295            @Override
2296            public int filterCountByGroupId(long groupId) {
2297                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2298                            return countByGroupId(groupId);
2299                    }
2300    
2301                    StringBundler query = new StringBundler(2);
2302    
2303                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
2304    
2305                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2306    
2307                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2308                                    MBCategory.class.getName(),
2309                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2310    
2311                    Session session = null;
2312    
2313                    try {
2314                            session = openSession();
2315    
2316                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
2317    
2318                            q.addScalar(COUNT_COLUMN_NAME,
2319                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2320    
2321                            QueryPos qPos = QueryPos.getInstance(q);
2322    
2323                            qPos.add(groupId);
2324    
2325                            Long count = (Long)q.uniqueResult();
2326    
2327                            return count.intValue();
2328                    }
2329                    catch (Exception e) {
2330                            throw processException(e);
2331                    }
2332                    finally {
2333                            closeSession(session);
2334                    }
2335            }
2336    
2337            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
2338            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2339                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2340                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2341                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2342                            new String[] {
2343                                    Long.class.getName(),
2344                                    
2345                            Integer.class.getName(), Integer.class.getName(),
2346                                    OrderByComparator.class.getName()
2347                            });
2348            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2349                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2350                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2351                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2352                            new String[] { Long.class.getName() },
2353                            MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
2354                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2355                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2356            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2357                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2358                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2359                            new String[] { Long.class.getName() });
2360    
2361            /**
2362             * Returns all the message boards categories where companyId = &#63;.
2363             *
2364             * @param companyId the company ID
2365             * @return the matching message boards categories
2366             */
2367            @Override
2368            public List<MBCategory> findByCompanyId(long companyId) {
2369                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2370                            null);
2371            }
2372    
2373            /**
2374             * Returns a range of all the message boards categories where companyId = &#63;.
2375             *
2376             * <p>
2377             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
2378             * </p>
2379             *
2380             * @param companyId the company ID
2381             * @param start the lower bound of the range of message boards categories
2382             * @param end the upper bound of the range of message boards categories (not inclusive)
2383             * @return the range of matching message boards categories
2384             */
2385            @Override
2386            public List<MBCategory> findByCompanyId(long companyId, int start, int end) {
2387                    return findByCompanyId(companyId, start, end, null);
2388            }
2389    
2390            /**
2391             * Returns an ordered range of all the message boards categories where companyId = &#63;.
2392             *
2393             * <p>
2394             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
2395             * </p>
2396             *
2397             * @param companyId the company ID
2398             * @param start the lower bound of the range of message boards categories
2399             * @param end the upper bound of the range of message boards categories (not inclusive)
2400             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2401             * @return the ordered range of matching message boards categories
2402             */
2403            @Override
2404            public List<MBCategory> findByCompanyId(long companyId, int start, int end,
2405                    OrderByComparator<MBCategory> orderByComparator) {
2406                    return findByCompanyId(companyId, start, end, orderByComparator, true);
2407            }
2408    
2409            /**
2410             * Returns an ordered range of all the message boards categories where companyId = &#63;.
2411             *
2412             * <p>
2413             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
2414             * </p>
2415             *
2416             * @param companyId the company ID
2417             * @param start the lower bound of the range of message boards categories
2418             * @param end the upper bound of the range of message boards categories (not inclusive)
2419             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2420             * @param retrieveFromCache whether to retrieve from the finder cache
2421             * @return the ordered range of matching message boards categories
2422             */
2423            @Override
2424            public List<MBCategory> findByCompanyId(long companyId, int start, int end,
2425                    OrderByComparator<MBCategory> orderByComparator,
2426                    boolean retrieveFromCache) {
2427                    boolean pagination = true;
2428                    FinderPath finderPath = null;
2429                    Object[] finderArgs = null;
2430    
2431                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2432                                    (orderByComparator == null)) {
2433                            pagination = false;
2434                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2435                            finderArgs = new Object[] { companyId };
2436                    }
2437                    else {
2438                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2439                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2440                    }
2441    
2442                    List<MBCategory> list = null;
2443    
2444                    if (retrieveFromCache) {
2445                            list = (List<MBCategory>)finderCache.getResult(finderPath,
2446                                            finderArgs, this);
2447    
2448                            if ((list != null) && !list.isEmpty()) {
2449                                    for (MBCategory mbCategory : list) {
2450                                            if ((companyId != mbCategory.getCompanyId())) {
2451                                                    list = null;
2452    
2453                                                    break;
2454                                            }
2455                                    }
2456                            }
2457                    }
2458    
2459                    if (list == null) {
2460                            StringBundler query = null;
2461    
2462                            if (orderByComparator != null) {
2463                                    query = new StringBundler(3 +
2464                                                    (orderByComparator.getOrderByFields().length * 3));
2465                            }
2466                            else {
2467                                    query = new StringBundler(3);
2468                            }
2469    
2470                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2471    
2472                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2473    
2474                            if (orderByComparator != null) {
2475                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2476                                            orderByComparator);
2477                            }
2478                            else
2479                             if (pagination) {
2480                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2481                            }
2482    
2483                            String sql = query.toString();
2484    
2485                            Session session = null;
2486    
2487                            try {
2488                                    session = openSession();
2489    
2490                                    Query q = session.createQuery(sql);
2491    
2492                                    QueryPos qPos = QueryPos.getInstance(q);
2493    
2494                                    qPos.add(companyId);
2495    
2496                                    if (!pagination) {
2497                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2498                                                            start, end, false);
2499    
2500                                            Collections.sort(list);
2501    
2502                                            list = Collections.unmodifiableList(list);
2503                                    }
2504                                    else {
2505                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2506                                                            start, end);
2507                                    }
2508    
2509                                    cacheResult(list);
2510    
2511                                    finderCache.putResult(finderPath, finderArgs, list);
2512                            }
2513                            catch (Exception e) {
2514                                    finderCache.removeResult(finderPath, finderArgs);
2515    
2516                                    throw processException(e);
2517                            }
2518                            finally {
2519                                    closeSession(session);
2520                            }
2521                    }
2522    
2523                    return list;
2524            }
2525    
2526            /**
2527             * Returns the first message boards category in the ordered set where companyId = &#63;.
2528             *
2529             * @param companyId the company ID
2530             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2531             * @return the first matching message boards category
2532             * @throws NoSuchCategoryException if a matching message boards category could not be found
2533             */
2534            @Override
2535            public MBCategory findByCompanyId_First(long companyId,
2536                    OrderByComparator<MBCategory> orderByComparator)
2537                    throws NoSuchCategoryException {
2538                    MBCategory mbCategory = fetchByCompanyId_First(companyId,
2539                                    orderByComparator);
2540    
2541                    if (mbCategory != null) {
2542                            return mbCategory;
2543                    }
2544    
2545                    StringBundler msg = new StringBundler(4);
2546    
2547                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2548    
2549                    msg.append("companyId=");
2550                    msg.append(companyId);
2551    
2552                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2553    
2554                    throw new NoSuchCategoryException(msg.toString());
2555            }
2556    
2557            /**
2558             * Returns the first message boards category in the ordered set where companyId = &#63;.
2559             *
2560             * @param companyId the company ID
2561             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2562             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
2563             */
2564            @Override
2565            public MBCategory fetchByCompanyId_First(long companyId,
2566                    OrderByComparator<MBCategory> orderByComparator) {
2567                    List<MBCategory> list = findByCompanyId(companyId, 0, 1,
2568                                    orderByComparator);
2569    
2570                    if (!list.isEmpty()) {
2571                            return list.get(0);
2572                    }
2573    
2574                    return null;
2575            }
2576    
2577            /**
2578             * Returns the last message boards category in the ordered set where companyId = &#63;.
2579             *
2580             * @param companyId the company ID
2581             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2582             * @return the last matching message boards category
2583             * @throws NoSuchCategoryException if a matching message boards category could not be found
2584             */
2585            @Override
2586            public MBCategory findByCompanyId_Last(long companyId,
2587                    OrderByComparator<MBCategory> orderByComparator)
2588                    throws NoSuchCategoryException {
2589                    MBCategory mbCategory = fetchByCompanyId_Last(companyId,
2590                                    orderByComparator);
2591    
2592                    if (mbCategory != null) {
2593                            return mbCategory;
2594                    }
2595    
2596                    StringBundler msg = new StringBundler(4);
2597    
2598                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2599    
2600                    msg.append("companyId=");
2601                    msg.append(companyId);
2602    
2603                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2604    
2605                    throw new NoSuchCategoryException(msg.toString());
2606            }
2607    
2608            /**
2609             * Returns the last message boards category in the ordered set where companyId = &#63;.
2610             *
2611             * @param companyId the company ID
2612             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2613             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
2614             */
2615            @Override
2616            public MBCategory fetchByCompanyId_Last(long companyId,
2617                    OrderByComparator<MBCategory> orderByComparator) {
2618                    int count = countByCompanyId(companyId);
2619    
2620                    if (count == 0) {
2621                            return null;
2622                    }
2623    
2624                    List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
2625                                    orderByComparator);
2626    
2627                    if (!list.isEmpty()) {
2628                            return list.get(0);
2629                    }
2630    
2631                    return null;
2632            }
2633    
2634            /**
2635             * Returns the message boards categories before and after the current message boards category in the ordered set where companyId = &#63;.
2636             *
2637             * @param categoryId the primary key of the current message boards category
2638             * @param companyId the company ID
2639             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2640             * @return the previous, current, and next message boards category
2641             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
2642             */
2643            @Override
2644            public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
2645                    long companyId, OrderByComparator<MBCategory> orderByComparator)
2646                    throws NoSuchCategoryException {
2647                    MBCategory mbCategory = findByPrimaryKey(categoryId);
2648    
2649                    Session session = null;
2650    
2651                    try {
2652                            session = openSession();
2653    
2654                            MBCategory[] array = new MBCategoryImpl[3];
2655    
2656                            array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
2657                                            companyId, orderByComparator, true);
2658    
2659                            array[1] = mbCategory;
2660    
2661                            array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
2662                                            companyId, orderByComparator, false);
2663    
2664                            return array;
2665                    }
2666                    catch (Exception e) {
2667                            throw processException(e);
2668                    }
2669                    finally {
2670                            closeSession(session);
2671                    }
2672            }
2673    
2674            protected MBCategory getByCompanyId_PrevAndNext(Session session,
2675                    MBCategory mbCategory, long companyId,
2676                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
2677                    StringBundler query = null;
2678    
2679                    if (orderByComparator != null) {
2680                            query = new StringBundler(6 +
2681                                            (orderByComparator.getOrderByFields().length * 6));
2682                    }
2683                    else {
2684                            query = new StringBundler(3);
2685                    }
2686    
2687                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2688    
2689                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2690    
2691                    if (orderByComparator != null) {
2692                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2693    
2694                            if (orderByConditionFields.length > 0) {
2695                                    query.append(WHERE_AND);
2696                            }
2697    
2698                            for (int i = 0; i < orderByConditionFields.length; i++) {
2699                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2700                                    query.append(orderByConditionFields[i]);
2701    
2702                                    if ((i + 1) < orderByConditionFields.length) {
2703                                            if (orderByComparator.isAscending() ^ previous) {
2704                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2705                                            }
2706                                            else {
2707                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2708                                            }
2709                                    }
2710                                    else {
2711                                            if (orderByComparator.isAscending() ^ previous) {
2712                                                    query.append(WHERE_GREATER_THAN);
2713                                            }
2714                                            else {
2715                                                    query.append(WHERE_LESSER_THAN);
2716                                            }
2717                                    }
2718                            }
2719    
2720                            query.append(ORDER_BY_CLAUSE);
2721    
2722                            String[] orderByFields = orderByComparator.getOrderByFields();
2723    
2724                            for (int i = 0; i < orderByFields.length; i++) {
2725                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2726                                    query.append(orderByFields[i]);
2727    
2728                                    if ((i + 1) < orderByFields.length) {
2729                                            if (orderByComparator.isAscending() ^ previous) {
2730                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2731                                            }
2732                                            else {
2733                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2734                                            }
2735                                    }
2736                                    else {
2737                                            if (orderByComparator.isAscending() ^ previous) {
2738                                                    query.append(ORDER_BY_ASC);
2739                                            }
2740                                            else {
2741                                                    query.append(ORDER_BY_DESC);
2742                                            }
2743                                    }
2744                            }
2745                    }
2746                    else {
2747                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2748                    }
2749    
2750                    String sql = query.toString();
2751    
2752                    Query q = session.createQuery(sql);
2753    
2754                    q.setFirstResult(0);
2755                    q.setMaxResults(2);
2756    
2757                    QueryPos qPos = QueryPos.getInstance(q);
2758    
2759                    qPos.add(companyId);
2760    
2761                    if (orderByComparator != null) {
2762                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2763    
2764                            for (Object value : values) {
2765                                    qPos.add(value);
2766                            }
2767                    }
2768    
2769                    List<MBCategory> list = q.list();
2770    
2771                    if (list.size() == 2) {
2772                            return list.get(1);
2773                    }
2774                    else {
2775                            return null;
2776                    }
2777            }
2778    
2779            /**
2780             * Removes all the message boards categories where companyId = &#63; from the database.
2781             *
2782             * @param companyId the company ID
2783             */
2784            @Override
2785            public void removeByCompanyId(long companyId) {
2786                    for (MBCategory mbCategory : findByCompanyId(companyId,
2787                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2788                            remove(mbCategory);
2789                    }
2790            }
2791    
2792            /**
2793             * Returns the number of message boards categories where companyId = &#63;.
2794             *
2795             * @param companyId the company ID
2796             * @return the number of matching message boards categories
2797             */
2798            @Override
2799            public int countByCompanyId(long companyId) {
2800                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2801    
2802                    Object[] finderArgs = new Object[] { companyId };
2803    
2804                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
2805    
2806                    if (count == null) {
2807                            StringBundler query = new StringBundler(2);
2808    
2809                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2810    
2811                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2812    
2813                            String sql = query.toString();
2814    
2815                            Session session = null;
2816    
2817                            try {
2818                                    session = openSession();
2819    
2820                                    Query q = session.createQuery(sql);
2821    
2822                                    QueryPos qPos = QueryPos.getInstance(q);
2823    
2824                                    qPos.add(companyId);
2825    
2826                                    count = (Long)q.uniqueResult();
2827    
2828                                    finderCache.putResult(finderPath, finderArgs, count);
2829                            }
2830                            catch (Exception e) {
2831                                    finderCache.removeResult(finderPath, finderArgs);
2832    
2833                                    throw processException(e);
2834                            }
2835                            finally {
2836                                    closeSession(session);
2837                            }
2838                    }
2839    
2840                    return count.intValue();
2841            }
2842    
2843            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
2844            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2845                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2846                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
2847                            new String[] {
2848                                    Long.class.getName(), Long.class.getName(),
2849                                    
2850                            Integer.class.getName(), Integer.class.getName(),
2851                                    OrderByComparator.class.getName()
2852                            });
2853            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2854                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2855                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
2856                            new String[] { Long.class.getName(), Long.class.getName() },
2857                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
2858                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2859                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2860            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2861                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2862                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
2863                            new String[] { Long.class.getName(), Long.class.getName() });
2864            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2865                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2866                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P",
2867                            new String[] { Long.class.getName(), Long.class.getName() });
2868    
2869            /**
2870             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2871             *
2872             * @param groupId the group ID
2873             * @param parentCategoryId the parent category ID
2874             * @return the matching message boards categories
2875             */
2876            @Override
2877            public List<MBCategory> findByG_P(long groupId, long parentCategoryId) {
2878                    return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2879                            QueryUtil.ALL_POS, null);
2880            }
2881    
2882            /**
2883             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2884             *
2885             * <p>
2886             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
2887             * </p>
2888             *
2889             * @param groupId the group ID
2890             * @param parentCategoryId the parent category ID
2891             * @param start the lower bound of the range of message boards categories
2892             * @param end the upper bound of the range of message boards categories (not inclusive)
2893             * @return the range of matching message boards categories
2894             */
2895            @Override
2896            public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2897                    int start, int end) {
2898                    return findByG_P(groupId, parentCategoryId, start, end, null);
2899            }
2900    
2901            /**
2902             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2903             *
2904             * <p>
2905             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
2906             * </p>
2907             *
2908             * @param groupId the group ID
2909             * @param parentCategoryId the parent category ID
2910             * @param start the lower bound of the range of message boards categories
2911             * @param end the upper bound of the range of message boards categories (not inclusive)
2912             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2913             * @return the ordered range of matching message boards categories
2914             */
2915            @Override
2916            public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2917                    int start, int end, OrderByComparator<MBCategory> orderByComparator) {
2918                    return findByG_P(groupId, parentCategoryId, start, end,
2919                            orderByComparator, true);
2920            }
2921    
2922            /**
2923             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2924             *
2925             * <p>
2926             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
2927             * </p>
2928             *
2929             * @param groupId the group ID
2930             * @param parentCategoryId the parent category ID
2931             * @param start the lower bound of the range of message boards categories
2932             * @param end the upper bound of the range of message boards categories (not inclusive)
2933             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2934             * @param retrieveFromCache whether to retrieve from the finder cache
2935             * @return the ordered range of matching message boards categories
2936             */
2937            @Override
2938            public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2939                    int start, int end, OrderByComparator<MBCategory> orderByComparator,
2940                    boolean retrieveFromCache) {
2941                    boolean pagination = true;
2942                    FinderPath finderPath = null;
2943                    Object[] finderArgs = null;
2944    
2945                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2946                                    (orderByComparator == null)) {
2947                            pagination = false;
2948                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2949                            finderArgs = new Object[] { groupId, parentCategoryId };
2950                    }
2951                    else {
2952                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2953                            finderArgs = new Object[] {
2954                                            groupId, parentCategoryId,
2955                                            
2956                                            start, end, orderByComparator
2957                                    };
2958                    }
2959    
2960                    List<MBCategory> list = null;
2961    
2962                    if (retrieveFromCache) {
2963                            list = (List<MBCategory>)finderCache.getResult(finderPath,
2964                                            finderArgs, this);
2965    
2966                            if ((list != null) && !list.isEmpty()) {
2967                                    for (MBCategory mbCategory : list) {
2968                                            if ((groupId != mbCategory.getGroupId()) ||
2969                                                            (parentCategoryId != mbCategory.getParentCategoryId())) {
2970                                                    list = null;
2971    
2972                                                    break;
2973                                            }
2974                                    }
2975                            }
2976                    }
2977    
2978                    if (list == null) {
2979                            StringBundler query = null;
2980    
2981                            if (orderByComparator != null) {
2982                                    query = new StringBundler(4 +
2983                                                    (orderByComparator.getOrderByFields().length * 3));
2984                            }
2985                            else {
2986                                    query = new StringBundler(4);
2987                            }
2988    
2989                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2990    
2991                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2992    
2993                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2994    
2995                            if (orderByComparator != null) {
2996                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2997                                            orderByComparator);
2998                            }
2999                            else
3000                             if (pagination) {
3001                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3002                            }
3003    
3004                            String sql = query.toString();
3005    
3006                            Session session = null;
3007    
3008                            try {
3009                                    session = openSession();
3010    
3011                                    Query q = session.createQuery(sql);
3012    
3013                                    QueryPos qPos = QueryPos.getInstance(q);
3014    
3015                                    qPos.add(groupId);
3016    
3017                                    qPos.add(parentCategoryId);
3018    
3019                                    if (!pagination) {
3020                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3021                                                            start, end, false);
3022    
3023                                            Collections.sort(list);
3024    
3025                                            list = Collections.unmodifiableList(list);
3026                                    }
3027                                    else {
3028                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3029                                                            start, end);
3030                                    }
3031    
3032                                    cacheResult(list);
3033    
3034                                    finderCache.putResult(finderPath, finderArgs, list);
3035                            }
3036                            catch (Exception e) {
3037                                    finderCache.removeResult(finderPath, finderArgs);
3038    
3039                                    throw processException(e);
3040                            }
3041                            finally {
3042                                    closeSession(session);
3043                            }
3044                    }
3045    
3046                    return list;
3047            }
3048    
3049            /**
3050             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3051             *
3052             * @param groupId the group ID
3053             * @param parentCategoryId the parent category ID
3054             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3055             * @return the first matching message boards category
3056             * @throws NoSuchCategoryException if a matching message boards category could not be found
3057             */
3058            @Override
3059            public MBCategory findByG_P_First(long groupId, long parentCategoryId,
3060                    OrderByComparator<MBCategory> orderByComparator)
3061                    throws NoSuchCategoryException {
3062                    MBCategory mbCategory = fetchByG_P_First(groupId, parentCategoryId,
3063                                    orderByComparator);
3064    
3065                    if (mbCategory != null) {
3066                            return mbCategory;
3067                    }
3068    
3069                    StringBundler msg = new StringBundler(6);
3070    
3071                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3072    
3073                    msg.append("groupId=");
3074                    msg.append(groupId);
3075    
3076                    msg.append(", parentCategoryId=");
3077                    msg.append(parentCategoryId);
3078    
3079                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3080    
3081                    throw new NoSuchCategoryException(msg.toString());
3082            }
3083    
3084            /**
3085             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3086             *
3087             * @param groupId the group ID
3088             * @param parentCategoryId the parent category ID
3089             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3090             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
3091             */
3092            @Override
3093            public MBCategory fetchByG_P_First(long groupId, long parentCategoryId,
3094                    OrderByComparator<MBCategory> orderByComparator) {
3095                    List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
3096                                    orderByComparator);
3097    
3098                    if (!list.isEmpty()) {
3099                            return list.get(0);
3100                    }
3101    
3102                    return null;
3103            }
3104    
3105            /**
3106             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3107             *
3108             * @param groupId the group ID
3109             * @param parentCategoryId the parent category ID
3110             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3111             * @return the last matching message boards category
3112             * @throws NoSuchCategoryException if a matching message boards category could not be found
3113             */
3114            @Override
3115            public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
3116                    OrderByComparator<MBCategory> orderByComparator)
3117                    throws NoSuchCategoryException {
3118                    MBCategory mbCategory = fetchByG_P_Last(groupId, parentCategoryId,
3119                                    orderByComparator);
3120    
3121                    if (mbCategory != null) {
3122                            return mbCategory;
3123                    }
3124    
3125                    StringBundler msg = new StringBundler(6);
3126    
3127                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3128    
3129                    msg.append("groupId=");
3130                    msg.append(groupId);
3131    
3132                    msg.append(", parentCategoryId=");
3133                    msg.append(parentCategoryId);
3134    
3135                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3136    
3137                    throw new NoSuchCategoryException(msg.toString());
3138            }
3139    
3140            /**
3141             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3142             *
3143             * @param groupId the group ID
3144             * @param parentCategoryId the parent category ID
3145             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3146             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
3147             */
3148            @Override
3149            public MBCategory fetchByG_P_Last(long groupId, long parentCategoryId,
3150                    OrderByComparator<MBCategory> orderByComparator) {
3151                    int count = countByG_P(groupId, parentCategoryId);
3152    
3153                    if (count == 0) {
3154                            return null;
3155                    }
3156    
3157                    List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
3158                                    count, orderByComparator);
3159    
3160                    if (!list.isEmpty()) {
3161                            return list.get(0);
3162                    }
3163    
3164                    return null;
3165            }
3166    
3167            /**
3168             * Returns the message boards categories before and after the current message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3169             *
3170             * @param categoryId the primary key of the current message boards category
3171             * @param groupId the group ID
3172             * @param parentCategoryId the parent category ID
3173             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3174             * @return the previous, current, and next message boards category
3175             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
3176             */
3177            @Override
3178            public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
3179                    long parentCategoryId, OrderByComparator<MBCategory> orderByComparator)
3180                    throws NoSuchCategoryException {
3181                    MBCategory mbCategory = findByPrimaryKey(categoryId);
3182    
3183                    Session session = null;
3184    
3185                    try {
3186                            session = openSession();
3187    
3188                            MBCategory[] array = new MBCategoryImpl[3];
3189    
3190                            array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3191                                            parentCategoryId, orderByComparator, true);
3192    
3193                            array[1] = mbCategory;
3194    
3195                            array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3196                                            parentCategoryId, orderByComparator, false);
3197    
3198                            return array;
3199                    }
3200                    catch (Exception e) {
3201                            throw processException(e);
3202                    }
3203                    finally {
3204                            closeSession(session);
3205                    }
3206            }
3207    
3208            protected MBCategory getByG_P_PrevAndNext(Session session,
3209                    MBCategory mbCategory, long groupId, long parentCategoryId,
3210                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
3211                    StringBundler query = null;
3212    
3213                    if (orderByComparator != null) {
3214                            query = new StringBundler(6 +
3215                                            (orderByComparator.getOrderByFields().length * 6));
3216                    }
3217                    else {
3218                            query = new StringBundler(3);
3219                    }
3220    
3221                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3222    
3223                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3224    
3225                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3226    
3227                    if (orderByComparator != null) {
3228                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3229    
3230                            if (orderByConditionFields.length > 0) {
3231                                    query.append(WHERE_AND);
3232                            }
3233    
3234                            for (int i = 0; i < orderByConditionFields.length; i++) {
3235                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3236                                    query.append(orderByConditionFields[i]);
3237    
3238                                    if ((i + 1) < orderByConditionFields.length) {
3239                                            if (orderByComparator.isAscending() ^ previous) {
3240                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3241                                            }
3242                                            else {
3243                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3244                                            }
3245                                    }
3246                                    else {
3247                                            if (orderByComparator.isAscending() ^ previous) {
3248                                                    query.append(WHERE_GREATER_THAN);
3249                                            }
3250                                            else {
3251                                                    query.append(WHERE_LESSER_THAN);
3252                                            }
3253                                    }
3254                            }
3255    
3256                            query.append(ORDER_BY_CLAUSE);
3257    
3258                            String[] orderByFields = orderByComparator.getOrderByFields();
3259    
3260                            for (int i = 0; i < orderByFields.length; i++) {
3261                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3262                                    query.append(orderByFields[i]);
3263    
3264                                    if ((i + 1) < orderByFields.length) {
3265                                            if (orderByComparator.isAscending() ^ previous) {
3266                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3267                                            }
3268                                            else {
3269                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3270                                            }
3271                                    }
3272                                    else {
3273                                            if (orderByComparator.isAscending() ^ previous) {
3274                                                    query.append(ORDER_BY_ASC);
3275                                            }
3276                                            else {
3277                                                    query.append(ORDER_BY_DESC);
3278                                            }
3279                                    }
3280                            }
3281                    }
3282                    else {
3283                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3284                    }
3285    
3286                    String sql = query.toString();
3287    
3288                    Query q = session.createQuery(sql);
3289    
3290                    q.setFirstResult(0);
3291                    q.setMaxResults(2);
3292    
3293                    QueryPos qPos = QueryPos.getInstance(q);
3294    
3295                    qPos.add(groupId);
3296    
3297                    qPos.add(parentCategoryId);
3298    
3299                    if (orderByComparator != null) {
3300                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3301    
3302                            for (Object value : values) {
3303                                    qPos.add(value);
3304                            }
3305                    }
3306    
3307                    List<MBCategory> list = q.list();
3308    
3309                    if (list.size() == 2) {
3310                            return list.get(1);
3311                    }
3312                    else {
3313                            return null;
3314                    }
3315            }
3316    
3317            /**
3318             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
3319             *
3320             * @param groupId the group ID
3321             * @param parentCategoryId the parent category ID
3322             * @return the matching message boards categories that the user has permission to view
3323             */
3324            @Override
3325            public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId) {
3326                    return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
3327                            QueryUtil.ALL_POS, null);
3328            }
3329    
3330            /**
3331             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
3332             *
3333             * <p>
3334             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
3335             * </p>
3336             *
3337             * @param groupId the group ID
3338             * @param parentCategoryId the parent category ID
3339             * @param start the lower bound of the range of message boards categories
3340             * @param end the upper bound of the range of message boards categories (not inclusive)
3341             * @return the range of matching message boards categories that the user has permission to view
3342             */
3343            @Override
3344            public List<MBCategory> filterFindByG_P(long groupId,
3345                    long parentCategoryId, int start, int end) {
3346                    return filterFindByG_P(groupId, parentCategoryId, start, end, null);
3347            }
3348    
3349            /**
3350             * Returns an ordered range of all the message boards categories that the user has permissions to view where groupId = &#63; and parentCategoryId = &#63;.
3351             *
3352             * <p>
3353             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
3354             * </p>
3355             *
3356             * @param groupId the group ID
3357             * @param parentCategoryId the parent category ID
3358             * @param start the lower bound of the range of message boards categories
3359             * @param end the upper bound of the range of message boards categories (not inclusive)
3360             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3361             * @return the ordered range of matching message boards categories that the user has permission to view
3362             */
3363            @Override
3364            public List<MBCategory> filterFindByG_P(long groupId,
3365                    long parentCategoryId, int start, int end,
3366                    OrderByComparator<MBCategory> orderByComparator) {
3367                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3368                            return findByG_P(groupId, parentCategoryId, start, end,
3369                                    orderByComparator);
3370                    }
3371    
3372                    StringBundler query = null;
3373    
3374                    if (orderByComparator != null) {
3375                            query = new StringBundler(4 +
3376                                            (orderByComparator.getOrderByFields().length * 3));
3377                    }
3378                    else {
3379                            query = new StringBundler(4);
3380                    }
3381    
3382                    if (getDB().isSupportsInlineDistinct()) {
3383                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3384                    }
3385                    else {
3386                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3387                    }
3388    
3389                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3390    
3391                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3392    
3393                    if (!getDB().isSupportsInlineDistinct()) {
3394                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3395                    }
3396    
3397                    if (orderByComparator != null) {
3398                            if (getDB().isSupportsInlineDistinct()) {
3399                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3400                                            orderByComparator, true);
3401                            }
3402                            else {
3403                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3404                                            orderByComparator, true);
3405                            }
3406                    }
3407                    else {
3408                            if (getDB().isSupportsInlineDistinct()) {
3409                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3410                            }
3411                            else {
3412                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3413                            }
3414                    }
3415    
3416                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3417                                    MBCategory.class.getName(),
3418                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3419    
3420                    Session session = null;
3421    
3422                    try {
3423                            session = openSession();
3424    
3425                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3426    
3427                            if (getDB().isSupportsInlineDistinct()) {
3428                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3429                            }
3430                            else {
3431                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3432                            }
3433    
3434                            QueryPos qPos = QueryPos.getInstance(q);
3435    
3436                            qPos.add(groupId);
3437    
3438                            qPos.add(parentCategoryId);
3439    
3440                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3441                    }
3442                    catch (Exception e) {
3443                            throw processException(e);
3444                    }
3445                    finally {
3446                            closeSession(session);
3447                    }
3448            }
3449    
3450            /**
3451             * Returns the message boards categories before and after the current message boards category in the ordered set of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
3452             *
3453             * @param categoryId the primary key of the current message boards category
3454             * @param groupId the group ID
3455             * @param parentCategoryId the parent category ID
3456             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3457             * @return the previous, current, and next message boards category
3458             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
3459             */
3460            @Override
3461            public MBCategory[] filterFindByG_P_PrevAndNext(long categoryId,
3462                    long groupId, long parentCategoryId,
3463                    OrderByComparator<MBCategory> orderByComparator)
3464                    throws NoSuchCategoryException {
3465                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3466                            return findByG_P_PrevAndNext(categoryId, groupId, parentCategoryId,
3467                                    orderByComparator);
3468                    }
3469    
3470                    MBCategory mbCategory = findByPrimaryKey(categoryId);
3471    
3472                    Session session = null;
3473    
3474                    try {
3475                            session = openSession();
3476    
3477                            MBCategory[] array = new MBCategoryImpl[3];
3478    
3479                            array[0] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3480                                            parentCategoryId, orderByComparator, true);
3481    
3482                            array[1] = mbCategory;
3483    
3484                            array[2] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3485                                            parentCategoryId, orderByComparator, false);
3486    
3487                            return array;
3488                    }
3489                    catch (Exception e) {
3490                            throw processException(e);
3491                    }
3492                    finally {
3493                            closeSession(session);
3494                    }
3495            }
3496    
3497            protected MBCategory filterGetByG_P_PrevAndNext(Session session,
3498                    MBCategory mbCategory, long groupId, long parentCategoryId,
3499                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
3500                    StringBundler query = null;
3501    
3502                    if (orderByComparator != null) {
3503                            query = new StringBundler(6 +
3504                                            (orderByComparator.getOrderByFields().length * 6));
3505                    }
3506                    else {
3507                            query = new StringBundler(3);
3508                    }
3509    
3510                    if (getDB().isSupportsInlineDistinct()) {
3511                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3512                    }
3513                    else {
3514                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3515                    }
3516    
3517                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3518    
3519                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3520    
3521                    if (!getDB().isSupportsInlineDistinct()) {
3522                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3523                    }
3524    
3525                    if (orderByComparator != null) {
3526                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3527    
3528                            if (orderByConditionFields.length > 0) {
3529                                    query.append(WHERE_AND);
3530                            }
3531    
3532                            for (int i = 0; i < orderByConditionFields.length; i++) {
3533                                    if (getDB().isSupportsInlineDistinct()) {
3534                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3535                                    }
3536                                    else {
3537                                            query.append(_ORDER_BY_ENTITY_TABLE);
3538                                    }
3539    
3540                                    query.append(orderByConditionFields[i]);
3541    
3542                                    if ((i + 1) < orderByConditionFields.length) {
3543                                            if (orderByComparator.isAscending() ^ previous) {
3544                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3545                                            }
3546                                            else {
3547                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3548                                            }
3549                                    }
3550                                    else {
3551                                            if (orderByComparator.isAscending() ^ previous) {
3552                                                    query.append(WHERE_GREATER_THAN);
3553                                            }
3554                                            else {
3555                                                    query.append(WHERE_LESSER_THAN);
3556                                            }
3557                                    }
3558                            }
3559    
3560                            query.append(ORDER_BY_CLAUSE);
3561    
3562                            String[] orderByFields = orderByComparator.getOrderByFields();
3563    
3564                            for (int i = 0; i < orderByFields.length; i++) {
3565                                    if (getDB().isSupportsInlineDistinct()) {
3566                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3567                                    }
3568                                    else {
3569                                            query.append(_ORDER_BY_ENTITY_TABLE);
3570                                    }
3571    
3572                                    query.append(orderByFields[i]);
3573    
3574                                    if ((i + 1) < orderByFields.length) {
3575                                            if (orderByComparator.isAscending() ^ previous) {
3576                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3577                                            }
3578                                            else {
3579                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3580                                            }
3581                                    }
3582                                    else {
3583                                            if (orderByComparator.isAscending() ^ previous) {
3584                                                    query.append(ORDER_BY_ASC);
3585                                            }
3586                                            else {
3587                                                    query.append(ORDER_BY_DESC);
3588                                            }
3589                                    }
3590                            }
3591                    }
3592                    else {
3593                            if (getDB().isSupportsInlineDistinct()) {
3594                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3595                            }
3596                            else {
3597                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3598                            }
3599                    }
3600    
3601                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3602                                    MBCategory.class.getName(),
3603                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3604    
3605                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
3606    
3607                    q.setFirstResult(0);
3608                    q.setMaxResults(2);
3609    
3610                    if (getDB().isSupportsInlineDistinct()) {
3611                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3612                    }
3613                    else {
3614                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3615                    }
3616    
3617                    QueryPos qPos = QueryPos.getInstance(q);
3618    
3619                    qPos.add(groupId);
3620    
3621                    qPos.add(parentCategoryId);
3622    
3623                    if (orderByComparator != null) {
3624                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3625    
3626                            for (Object value : values) {
3627                                    qPos.add(value);
3628                            }
3629                    }
3630    
3631                    List<MBCategory> list = q.list();
3632    
3633                    if (list.size() == 2) {
3634                            return list.get(1);
3635                    }
3636                    else {
3637                            return null;
3638                    }
3639            }
3640    
3641            /**
3642             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
3643             *
3644             * @param groupId the group ID
3645             * @param parentCategoryIds the parent category IDs
3646             * @return the matching message boards categories that the user has permission to view
3647             */
3648            @Override
3649            public List<MBCategory> filterFindByG_P(long groupId,
3650                    long[] parentCategoryIds) {
3651                    return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3652                            QueryUtil.ALL_POS, null);
3653            }
3654    
3655            /**
3656             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
3657             *
3658             * <p>
3659             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
3660             * </p>
3661             *
3662             * @param groupId the group ID
3663             * @param parentCategoryIds the parent category IDs
3664             * @param start the lower bound of the range of message boards categories
3665             * @param end the upper bound of the range of message boards categories (not inclusive)
3666             * @return the range of matching message boards categories that the user has permission to view
3667             */
3668            @Override
3669            public List<MBCategory> filterFindByG_P(long groupId,
3670                    long[] parentCategoryIds, int start, int end) {
3671                    return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
3672            }
3673    
3674            /**
3675             * Returns an ordered range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
3676             *
3677             * <p>
3678             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
3679             * </p>
3680             *
3681             * @param groupId the group ID
3682             * @param parentCategoryIds the parent category IDs
3683             * @param start the lower bound of the range of message boards categories
3684             * @param end the upper bound of the range of message boards categories (not inclusive)
3685             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3686             * @return the ordered range of matching message boards categories that the user has permission to view
3687             */
3688            @Override
3689            public List<MBCategory> filterFindByG_P(long groupId,
3690                    long[] parentCategoryIds, int start, int end,
3691                    OrderByComparator<MBCategory> orderByComparator) {
3692                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3693                            return findByG_P(groupId, parentCategoryIds, start, end,
3694                                    orderByComparator);
3695                    }
3696    
3697                    if (parentCategoryIds == null) {
3698                            parentCategoryIds = new long[0];
3699                    }
3700                    else if (parentCategoryIds.length > 1) {
3701                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
3702    
3703                            Arrays.sort(parentCategoryIds);
3704                    }
3705    
3706                    StringBundler query = new StringBundler();
3707    
3708                    if (getDB().isSupportsInlineDistinct()) {
3709                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3710                    }
3711                    else {
3712                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3713                    }
3714    
3715                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3716    
3717                    if (parentCategoryIds.length > 0) {
3718                            query.append(StringPool.OPEN_PARENTHESIS);
3719    
3720                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_7);
3721    
3722                            query.append(StringUtil.merge(parentCategoryIds));
3723    
3724                            query.append(StringPool.CLOSE_PARENTHESIS);
3725    
3726                            query.append(StringPool.CLOSE_PARENTHESIS);
3727                    }
3728    
3729                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
3730                            query.index() - 1);
3731    
3732                    if (!getDB().isSupportsInlineDistinct()) {
3733                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3734                    }
3735    
3736                    if (orderByComparator != null) {
3737                            if (getDB().isSupportsInlineDistinct()) {
3738                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3739                                            orderByComparator, true);
3740                            }
3741                            else {
3742                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3743                                            orderByComparator, true);
3744                            }
3745                    }
3746                    else {
3747                            if (getDB().isSupportsInlineDistinct()) {
3748                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3749                            }
3750                            else {
3751                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3752                            }
3753                    }
3754    
3755                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3756                                    MBCategory.class.getName(),
3757                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3758    
3759                    Session session = null;
3760    
3761                    try {
3762                            session = openSession();
3763    
3764                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
3765    
3766                            if (getDB().isSupportsInlineDistinct()) {
3767                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3768                            }
3769                            else {
3770                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3771                            }
3772    
3773                            QueryPos qPos = QueryPos.getInstance(q);
3774    
3775                            qPos.add(groupId);
3776    
3777                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3778                    }
3779                    catch (Exception e) {
3780                            throw processException(e);
3781                    }
3782                    finally {
3783                            closeSession(session);
3784                    }
3785            }
3786    
3787            /**
3788             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3789             *
3790             * <p>
3791             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
3792             * </p>
3793             *
3794             * @param groupId the group ID
3795             * @param parentCategoryIds the parent category IDs
3796             * @return the matching message boards categories
3797             */
3798            @Override
3799            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds) {
3800                    return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3801                            QueryUtil.ALL_POS, null);
3802            }
3803    
3804            /**
3805             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3806             *
3807             * <p>
3808             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
3809             * </p>
3810             *
3811             * @param groupId the group ID
3812             * @param parentCategoryIds the parent category IDs
3813             * @param start the lower bound of the range of message boards categories
3814             * @param end the upper bound of the range of message boards categories (not inclusive)
3815             * @return the range of matching message boards categories
3816             */
3817            @Override
3818            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3819                    int start, int end) {
3820                    return findByG_P(groupId, parentCategoryIds, start, end, null);
3821            }
3822    
3823            /**
3824             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3825             *
3826             * <p>
3827             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
3828             * </p>
3829             *
3830             * @param groupId the group ID
3831             * @param parentCategoryIds the parent category IDs
3832             * @param start the lower bound of the range of message boards categories
3833             * @param end the upper bound of the range of message boards categories (not inclusive)
3834             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3835             * @return the ordered range of matching message boards categories
3836             */
3837            @Override
3838            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3839                    int start, int end, OrderByComparator<MBCategory> orderByComparator) {
3840                    return findByG_P(groupId, parentCategoryIds, start, end,
3841                            orderByComparator, true);
3842            }
3843    
3844            /**
3845             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;, optionally using the finder cache.
3846             *
3847             * <p>
3848             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
3849             * </p>
3850             *
3851             * @param groupId the group ID
3852             * @param parentCategoryId the parent category ID
3853             * @param start the lower bound of the range of message boards categories
3854             * @param end the upper bound of the range of message boards categories (not inclusive)
3855             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3856             * @param retrieveFromCache whether to retrieve from the finder cache
3857             * @return the ordered range of matching message boards categories
3858             */
3859            @Override
3860            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3861                    int start, int end, OrderByComparator<MBCategory> orderByComparator,
3862                    boolean retrieveFromCache) {
3863                    if (parentCategoryIds == null) {
3864                            parentCategoryIds = new long[0];
3865                    }
3866                    else if (parentCategoryIds.length > 1) {
3867                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
3868    
3869                            Arrays.sort(parentCategoryIds);
3870                    }
3871    
3872                    if (parentCategoryIds.length == 1) {
3873                            return findByG_P(groupId, parentCategoryIds[0], start, end,
3874                                    orderByComparator);
3875                    }
3876    
3877                    boolean pagination = true;
3878                    Object[] finderArgs = null;
3879    
3880                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3881                                    (orderByComparator == null)) {
3882                            pagination = false;
3883                            finderArgs = new Object[] {
3884                                            groupId, StringUtil.merge(parentCategoryIds)
3885                                    };
3886                    }
3887                    else {
3888                            finderArgs = new Object[] {
3889                                            groupId, StringUtil.merge(parentCategoryIds),
3890                                            
3891                                            start, end, orderByComparator
3892                                    };
3893                    }
3894    
3895                    List<MBCategory> list = null;
3896    
3897                    if (retrieveFromCache) {
3898                            list = (List<MBCategory>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3899                                            finderArgs, this);
3900    
3901                            if ((list != null) && !list.isEmpty()) {
3902                                    for (MBCategory mbCategory : list) {
3903                                            if ((groupId != mbCategory.getGroupId()) ||
3904                                                            !ArrayUtil.contains(parentCategoryIds,
3905                                                                    mbCategory.getParentCategoryId())) {
3906                                                    list = null;
3907    
3908                                                    break;
3909                                            }
3910                                    }
3911                            }
3912                    }
3913    
3914                    if (list == null) {
3915                            StringBundler query = new StringBundler();
3916    
3917                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3918    
3919                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3920    
3921                            if (parentCategoryIds.length > 0) {
3922                                    query.append(StringPool.OPEN_PARENTHESIS);
3923    
3924                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_7);
3925    
3926                                    query.append(StringUtil.merge(parentCategoryIds));
3927    
3928                                    query.append(StringPool.CLOSE_PARENTHESIS);
3929    
3930                                    query.append(StringPool.CLOSE_PARENTHESIS);
3931                            }
3932    
3933                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
3934                                                    1)), query.index() - 1);
3935    
3936                            if (orderByComparator != null) {
3937                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3938                                            orderByComparator);
3939                            }
3940                            else
3941                             if (pagination) {
3942                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3943                            }
3944    
3945                            String sql = query.toString();
3946    
3947                            Session session = null;
3948    
3949                            try {
3950                                    session = openSession();
3951    
3952                                    Query q = session.createQuery(sql);
3953    
3954                                    QueryPos qPos = QueryPos.getInstance(q);
3955    
3956                                    qPos.add(groupId);
3957    
3958                                    if (!pagination) {
3959                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3960                                                            start, end, false);
3961    
3962                                            Collections.sort(list);
3963    
3964                                            list = Collections.unmodifiableList(list);
3965                                    }
3966                                    else {
3967                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3968                                                            start, end);
3969                                    }
3970    
3971                                    cacheResult(list);
3972    
3973                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3974                                            finderArgs, list);
3975                            }
3976                            catch (Exception e) {
3977                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3978                                            finderArgs);
3979    
3980                                    throw processException(e);
3981                            }
3982                            finally {
3983                                    closeSession(session);
3984                            }
3985                    }
3986    
3987                    return list;
3988            }
3989    
3990            /**
3991             * Removes all the message boards categories where groupId = &#63; and parentCategoryId = &#63; from the database.
3992             *
3993             * @param groupId the group ID
3994             * @param parentCategoryId the parent category ID
3995             */
3996            @Override
3997            public void removeByG_P(long groupId, long parentCategoryId) {
3998                    for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId,
3999                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4000                            remove(mbCategory);
4001                    }
4002            }
4003    
4004            /**
4005             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = &#63;.
4006             *
4007             * @param groupId the group ID
4008             * @param parentCategoryId the parent category ID
4009             * @return the number of matching message boards categories
4010             */
4011            @Override
4012            public int countByG_P(long groupId, long parentCategoryId) {
4013                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
4014    
4015                    Object[] finderArgs = new Object[] { groupId, parentCategoryId };
4016    
4017                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
4018    
4019                    if (count == null) {
4020                            StringBundler query = new StringBundler(3);
4021    
4022                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4023    
4024                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4025    
4026                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
4027    
4028                            String sql = query.toString();
4029    
4030                            Session session = null;
4031    
4032                            try {
4033                                    session = openSession();
4034    
4035                                    Query q = session.createQuery(sql);
4036    
4037                                    QueryPos qPos = QueryPos.getInstance(q);
4038    
4039                                    qPos.add(groupId);
4040    
4041                                    qPos.add(parentCategoryId);
4042    
4043                                    count = (Long)q.uniqueResult();
4044    
4045                                    finderCache.putResult(finderPath, finderArgs, count);
4046                            }
4047                            catch (Exception e) {
4048                                    finderCache.removeResult(finderPath, finderArgs);
4049    
4050                                    throw processException(e);
4051                            }
4052                            finally {
4053                                    closeSession(session);
4054                            }
4055                    }
4056    
4057                    return count.intValue();
4058            }
4059    
4060            /**
4061             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
4062             *
4063             * @param groupId the group ID
4064             * @param parentCategoryIds the parent category IDs
4065             * @return the number of matching message boards categories
4066             */
4067            @Override
4068            public int countByG_P(long groupId, long[] parentCategoryIds) {
4069                    if (parentCategoryIds == null) {
4070                            parentCategoryIds = new long[0];
4071                    }
4072                    else if (parentCategoryIds.length > 1) {
4073                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
4074    
4075                            Arrays.sort(parentCategoryIds);
4076                    }
4077    
4078                    Object[] finderArgs = new Object[] {
4079                                    groupId, StringUtil.merge(parentCategoryIds)
4080                            };
4081    
4082                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
4083                                    finderArgs, this);
4084    
4085                    if (count == null) {
4086                            StringBundler query = new StringBundler();
4087    
4088                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4089    
4090                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4091    
4092                            if (parentCategoryIds.length > 0) {
4093                                    query.append(StringPool.OPEN_PARENTHESIS);
4094    
4095                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_7);
4096    
4097                                    query.append(StringUtil.merge(parentCategoryIds));
4098    
4099                                    query.append(StringPool.CLOSE_PARENTHESIS);
4100    
4101                                    query.append(StringPool.CLOSE_PARENTHESIS);
4102                            }
4103    
4104                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
4105                                                    1)), query.index() - 1);
4106    
4107                            String sql = query.toString();
4108    
4109                            Session session = null;
4110    
4111                            try {
4112                                    session = openSession();
4113    
4114                                    Query q = session.createQuery(sql);
4115    
4116                                    QueryPos qPos = QueryPos.getInstance(q);
4117    
4118                                    qPos.add(groupId);
4119    
4120                                    count = (Long)q.uniqueResult();
4121    
4122                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
4123                                            finderArgs, count);
4124                            }
4125                            catch (Exception e) {
4126                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
4127                                            finderArgs);
4128    
4129                                    throw processException(e);
4130                            }
4131                            finally {
4132                                    closeSession(session);
4133                            }
4134                    }
4135    
4136                    return count.intValue();
4137            }
4138    
4139            /**
4140             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
4141             *
4142             * @param groupId the group ID
4143             * @param parentCategoryId the parent category ID
4144             * @return the number of matching message boards categories that the user has permission to view
4145             */
4146            @Override
4147            public int filterCountByG_P(long groupId, long parentCategoryId) {
4148                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4149                            return countByG_P(groupId, parentCategoryId);
4150                    }
4151    
4152                    StringBundler query = new StringBundler(3);
4153    
4154                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4155    
4156                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4157    
4158                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
4159    
4160                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4161                                    MBCategory.class.getName(),
4162                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4163    
4164                    Session session = null;
4165    
4166                    try {
4167                            session = openSession();
4168    
4169                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4170    
4171                            q.addScalar(COUNT_COLUMN_NAME,
4172                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4173    
4174                            QueryPos qPos = QueryPos.getInstance(q);
4175    
4176                            qPos.add(groupId);
4177    
4178                            qPos.add(parentCategoryId);
4179    
4180                            Long count = (Long)q.uniqueResult();
4181    
4182                            return count.intValue();
4183                    }
4184                    catch (Exception e) {
4185                            throw processException(e);
4186                    }
4187                    finally {
4188                            closeSession(session);
4189                    }
4190            }
4191    
4192            /**
4193             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
4194             *
4195             * @param groupId the group ID
4196             * @param parentCategoryIds the parent category IDs
4197             * @return the number of matching message boards categories that the user has permission to view
4198             */
4199            @Override
4200            public int filterCountByG_P(long groupId, long[] parentCategoryIds) {
4201                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4202                            return countByG_P(groupId, parentCategoryIds);
4203                    }
4204    
4205                    if (parentCategoryIds == null) {
4206                            parentCategoryIds = new long[0];
4207                    }
4208                    else if (parentCategoryIds.length > 1) {
4209                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
4210    
4211                            Arrays.sort(parentCategoryIds);
4212                    }
4213    
4214                    StringBundler query = new StringBundler();
4215    
4216                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4217    
4218                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4219    
4220                    if (parentCategoryIds.length > 0) {
4221                            query.append(StringPool.OPEN_PARENTHESIS);
4222    
4223                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_7);
4224    
4225                            query.append(StringUtil.merge(parentCategoryIds));
4226    
4227                            query.append(StringPool.CLOSE_PARENTHESIS);
4228    
4229                            query.append(StringPool.CLOSE_PARENTHESIS);
4230                    }
4231    
4232                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
4233                            query.index() - 1);
4234    
4235                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4236                                    MBCategory.class.getName(),
4237                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4238    
4239                    Session session = null;
4240    
4241                    try {
4242                            session = openSession();
4243    
4244                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4245    
4246                            q.addScalar(COUNT_COLUMN_NAME,
4247                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4248    
4249                            QueryPos qPos = QueryPos.getInstance(q);
4250    
4251                            qPos.add(groupId);
4252    
4253                            Long count = (Long)q.uniqueResult();
4254    
4255                            return count.intValue();
4256                    }
4257                    catch (Exception e) {
4258                            throw processException(e);
4259                    }
4260                    finally {
4261                            closeSession(session);
4262                    }
4263            }
4264    
4265            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
4266            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
4267            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_7 = "mbCategory.parentCategoryId IN (";
4268            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4269                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4270                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4271                            new String[] {
4272                                    Long.class.getName(), Integer.class.getName(),
4273                                    
4274                            Integer.class.getName(), Integer.class.getName(),
4275                                    OrderByComparator.class.getName()
4276                            });
4277            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4278                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4279                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4280                            new String[] { Long.class.getName(), Integer.class.getName() },
4281                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
4282                            MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
4283                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4284                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
4285            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4286                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4287                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4288                            new String[] { Long.class.getName(), Integer.class.getName() });
4289    
4290            /**
4291             * Returns all the message boards categories where groupId = &#63; and status = &#63;.
4292             *
4293             * @param groupId the group ID
4294             * @param status the status
4295             * @return the matching message boards categories
4296             */
4297            @Override
4298            public List<MBCategory> findByG_S(long groupId, int status) {
4299                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4300                            null);
4301            }
4302    
4303            /**
4304             * Returns a range of all the message boards categories where groupId = &#63; and status = &#63;.
4305             *
4306             * <p>
4307             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
4308             * </p>
4309             *
4310             * @param groupId the group ID
4311             * @param status the status
4312             * @param start the lower bound of the range of message boards categories
4313             * @param end the upper bound of the range of message boards categories (not inclusive)
4314             * @return the range of matching message boards categories
4315             */
4316            @Override
4317            public List<MBCategory> findByG_S(long groupId, int status, int start,
4318                    int end) {
4319                    return findByG_S(groupId, status, start, end, null);
4320            }
4321    
4322            /**
4323             * Returns an ordered range of all the message boards categories where groupId = &#63; and status = &#63;.
4324             *
4325             * <p>
4326             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
4327             * </p>
4328             *
4329             * @param groupId the group ID
4330             * @param status the status
4331             * @param start the lower bound of the range of message boards categories
4332             * @param end the upper bound of the range of message boards categories (not inclusive)
4333             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4334             * @return the ordered range of matching message boards categories
4335             */
4336            @Override
4337            public List<MBCategory> findByG_S(long groupId, int status, int start,
4338                    int end, OrderByComparator<MBCategory> orderByComparator) {
4339                    return findByG_S(groupId, status, start, end, orderByComparator, true);
4340            }
4341    
4342            /**
4343             * Returns an ordered range of all the message boards categories where groupId = &#63; and status = &#63;.
4344             *
4345             * <p>
4346             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
4347             * </p>
4348             *
4349             * @param groupId the group ID
4350             * @param status the status
4351             * @param start the lower bound of the range of message boards categories
4352             * @param end the upper bound of the range of message boards categories (not inclusive)
4353             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4354             * @param retrieveFromCache whether to retrieve from the finder cache
4355             * @return the ordered range of matching message boards categories
4356             */
4357            @Override
4358            public List<MBCategory> findByG_S(long groupId, int status, int start,
4359                    int end, OrderByComparator<MBCategory> orderByComparator,
4360                    boolean retrieveFromCache) {
4361                    boolean pagination = true;
4362                    FinderPath finderPath = null;
4363                    Object[] finderArgs = null;
4364    
4365                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4366                                    (orderByComparator == null)) {
4367                            pagination = false;
4368                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4369                            finderArgs = new Object[] { groupId, status };
4370                    }
4371                    else {
4372                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4373                            finderArgs = new Object[] {
4374                                            groupId, status,
4375                                            
4376                                            start, end, orderByComparator
4377                                    };
4378                    }
4379    
4380                    List<MBCategory> list = null;
4381    
4382                    if (retrieveFromCache) {
4383                            list = (List<MBCategory>)finderCache.getResult(finderPath,
4384                                            finderArgs, this);
4385    
4386                            if ((list != null) && !list.isEmpty()) {
4387                                    for (MBCategory mbCategory : list) {
4388                                            if ((groupId != mbCategory.getGroupId()) ||
4389                                                            (status != mbCategory.getStatus())) {
4390                                                    list = null;
4391    
4392                                                    break;
4393                                            }
4394                                    }
4395                            }
4396                    }
4397    
4398                    if (list == null) {
4399                            StringBundler query = null;
4400    
4401                            if (orderByComparator != null) {
4402                                    query = new StringBundler(4 +
4403                                                    (orderByComparator.getOrderByFields().length * 3));
4404                            }
4405                            else {
4406                                    query = new StringBundler(4);
4407                            }
4408    
4409                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4410    
4411                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4412    
4413                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
4414    
4415                            if (orderByComparator != null) {
4416                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4417                                            orderByComparator);
4418                            }
4419                            else
4420                             if (pagination) {
4421                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4422                            }
4423    
4424                            String sql = query.toString();
4425    
4426                            Session session = null;
4427    
4428                            try {
4429                                    session = openSession();
4430    
4431                                    Query q = session.createQuery(sql);
4432    
4433                                    QueryPos qPos = QueryPos.getInstance(q);
4434    
4435                                    qPos.add(groupId);
4436    
4437                                    qPos.add(status);
4438    
4439                                    if (!pagination) {
4440                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4441                                                            start, end, false);
4442    
4443                                            Collections.sort(list);
4444    
4445                                            list = Collections.unmodifiableList(list);
4446                                    }
4447                                    else {
4448                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4449                                                            start, end);
4450                                    }
4451    
4452                                    cacheResult(list);
4453    
4454                                    finderCache.putResult(finderPath, finderArgs, list);
4455                            }
4456                            catch (Exception e) {
4457                                    finderCache.removeResult(finderPath, finderArgs);
4458    
4459                                    throw processException(e);
4460                            }
4461                            finally {
4462                                    closeSession(session);
4463                            }
4464                    }
4465    
4466                    return list;
4467            }
4468    
4469            /**
4470             * Returns the first message boards category in the ordered set where groupId = &#63; and status = &#63;.
4471             *
4472             * @param groupId the group ID
4473             * @param status the status
4474             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4475             * @return the first matching message boards category
4476             * @throws NoSuchCategoryException if a matching message boards category could not be found
4477             */
4478            @Override
4479            public MBCategory findByG_S_First(long groupId, int status,
4480                    OrderByComparator<MBCategory> orderByComparator)
4481                    throws NoSuchCategoryException {
4482                    MBCategory mbCategory = fetchByG_S_First(groupId, status,
4483                                    orderByComparator);
4484    
4485                    if (mbCategory != null) {
4486                            return mbCategory;
4487                    }
4488    
4489                    StringBundler msg = new StringBundler(6);
4490    
4491                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4492    
4493                    msg.append("groupId=");
4494                    msg.append(groupId);
4495    
4496                    msg.append(", status=");
4497                    msg.append(status);
4498    
4499                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4500    
4501                    throw new NoSuchCategoryException(msg.toString());
4502            }
4503    
4504            /**
4505             * Returns the first message boards category in the ordered set where groupId = &#63; and status = &#63;.
4506             *
4507             * @param groupId the group ID
4508             * @param status the status
4509             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4510             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
4511             */
4512            @Override
4513            public MBCategory fetchByG_S_First(long groupId, int status,
4514                    OrderByComparator<MBCategory> orderByComparator) {
4515                    List<MBCategory> list = findByG_S(groupId, status, 0, 1,
4516                                    orderByComparator);
4517    
4518                    if (!list.isEmpty()) {
4519                            return list.get(0);
4520                    }
4521    
4522                    return null;
4523            }
4524    
4525            /**
4526             * Returns the last message boards category in the ordered set where groupId = &#63; and status = &#63;.
4527             *
4528             * @param groupId the group ID
4529             * @param status the status
4530             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4531             * @return the last matching message boards category
4532             * @throws NoSuchCategoryException if a matching message boards category could not be found
4533             */
4534            @Override
4535            public MBCategory findByG_S_Last(long groupId, int status,
4536                    OrderByComparator<MBCategory> orderByComparator)
4537                    throws NoSuchCategoryException {
4538                    MBCategory mbCategory = fetchByG_S_Last(groupId, status,
4539                                    orderByComparator);
4540    
4541                    if (mbCategory != null) {
4542                            return mbCategory;
4543                    }
4544    
4545                    StringBundler msg = new StringBundler(6);
4546    
4547                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4548    
4549                    msg.append("groupId=");
4550                    msg.append(groupId);
4551    
4552                    msg.append(", status=");
4553                    msg.append(status);
4554    
4555                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4556    
4557                    throw new NoSuchCategoryException(msg.toString());
4558            }
4559    
4560            /**
4561             * Returns the last message boards category in the ordered set where groupId = &#63; and status = &#63;.
4562             *
4563             * @param groupId the group ID
4564             * @param status the status
4565             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4566             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
4567             */
4568            @Override
4569            public MBCategory fetchByG_S_Last(long groupId, int status,
4570                    OrderByComparator<MBCategory> orderByComparator) {
4571                    int count = countByG_S(groupId, status);
4572    
4573                    if (count == 0) {
4574                            return null;
4575                    }
4576    
4577                    List<MBCategory> list = findByG_S(groupId, status, count - 1, count,
4578                                    orderByComparator);
4579    
4580                    if (!list.isEmpty()) {
4581                            return list.get(0);
4582                    }
4583    
4584                    return null;
4585            }
4586    
4587            /**
4588             * Returns the message boards categories before and after the current message boards category in the ordered set where groupId = &#63; and status = &#63;.
4589             *
4590             * @param categoryId the primary key of the current message boards category
4591             * @param groupId the group ID
4592             * @param status the status
4593             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4594             * @return the previous, current, and next message boards category
4595             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
4596             */
4597            @Override
4598            public MBCategory[] findByG_S_PrevAndNext(long categoryId, long groupId,
4599                    int status, OrderByComparator<MBCategory> orderByComparator)
4600                    throws NoSuchCategoryException {
4601                    MBCategory mbCategory = findByPrimaryKey(categoryId);
4602    
4603                    Session session = null;
4604    
4605                    try {
4606                            session = openSession();
4607    
4608                            MBCategory[] array = new MBCategoryImpl[3];
4609    
4610                            array[0] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4611                                            status, orderByComparator, true);
4612    
4613                            array[1] = mbCategory;
4614    
4615                            array[2] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4616                                            status, orderByComparator, false);
4617    
4618                            return array;
4619                    }
4620                    catch (Exception e) {
4621                            throw processException(e);
4622                    }
4623                    finally {
4624                            closeSession(session);
4625                    }
4626            }
4627    
4628            protected MBCategory getByG_S_PrevAndNext(Session session,
4629                    MBCategory mbCategory, long groupId, int status,
4630                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
4631                    StringBundler query = null;
4632    
4633                    if (orderByComparator != null) {
4634                            query = new StringBundler(6 +
4635                                            (orderByComparator.getOrderByFields().length * 6));
4636                    }
4637                    else {
4638                            query = new StringBundler(3);
4639                    }
4640    
4641                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4642    
4643                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4644    
4645                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4646    
4647                    if (orderByComparator != null) {
4648                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4649    
4650                            if (orderByConditionFields.length > 0) {
4651                                    query.append(WHERE_AND);
4652                            }
4653    
4654                            for (int i = 0; i < orderByConditionFields.length; i++) {
4655                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4656                                    query.append(orderByConditionFields[i]);
4657    
4658                                    if ((i + 1) < orderByConditionFields.length) {
4659                                            if (orderByComparator.isAscending() ^ previous) {
4660                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4661                                            }
4662                                            else {
4663                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4664                                            }
4665                                    }
4666                                    else {
4667                                            if (orderByComparator.isAscending() ^ previous) {
4668                                                    query.append(WHERE_GREATER_THAN);
4669                                            }
4670                                            else {
4671                                                    query.append(WHERE_LESSER_THAN);
4672                                            }
4673                                    }
4674                            }
4675    
4676                            query.append(ORDER_BY_CLAUSE);
4677    
4678                            String[] orderByFields = orderByComparator.getOrderByFields();
4679    
4680                            for (int i = 0; i < orderByFields.length; i++) {
4681                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4682                                    query.append(orderByFields[i]);
4683    
4684                                    if ((i + 1) < orderByFields.length) {
4685                                            if (orderByComparator.isAscending() ^ previous) {
4686                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4687                                            }
4688                                            else {
4689                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4690                                            }
4691                                    }
4692                                    else {
4693                                            if (orderByComparator.isAscending() ^ previous) {
4694                                                    query.append(ORDER_BY_ASC);
4695                                            }
4696                                            else {
4697                                                    query.append(ORDER_BY_DESC);
4698                                            }
4699                                    }
4700                            }
4701                    }
4702                    else {
4703                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4704                    }
4705    
4706                    String sql = query.toString();
4707    
4708                    Query q = session.createQuery(sql);
4709    
4710                    q.setFirstResult(0);
4711                    q.setMaxResults(2);
4712    
4713                    QueryPos qPos = QueryPos.getInstance(q);
4714    
4715                    qPos.add(groupId);
4716    
4717                    qPos.add(status);
4718    
4719                    if (orderByComparator != null) {
4720                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
4721    
4722                            for (Object value : values) {
4723                                    qPos.add(value);
4724                            }
4725                    }
4726    
4727                    List<MBCategory> list = q.list();
4728    
4729                    if (list.size() == 2) {
4730                            return list.get(1);
4731                    }
4732                    else {
4733                            return null;
4734                    }
4735            }
4736    
4737            /**
4738             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and status = &#63;.
4739             *
4740             * @param groupId the group ID
4741             * @param status the status
4742             * @return the matching message boards categories that the user has permission to view
4743             */
4744            @Override
4745            public List<MBCategory> filterFindByG_S(long groupId, int status) {
4746                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
4747                            QueryUtil.ALL_POS, null);
4748            }
4749    
4750            /**
4751             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and status = &#63;.
4752             *
4753             * <p>
4754             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
4755             * </p>
4756             *
4757             * @param groupId the group ID
4758             * @param status the status
4759             * @param start the lower bound of the range of message boards categories
4760             * @param end the upper bound of the range of message boards categories (not inclusive)
4761             * @return the range of matching message boards categories that the user has permission to view
4762             */
4763            @Override
4764            public List<MBCategory> filterFindByG_S(long groupId, int status,
4765                    int start, int end) {
4766                    return filterFindByG_S(groupId, status, start, end, null);
4767            }
4768    
4769            /**
4770             * Returns an ordered range of all the message boards categories that the user has permissions to view where groupId = &#63; and status = &#63;.
4771             *
4772             * <p>
4773             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
4774             * </p>
4775             *
4776             * @param groupId the group ID
4777             * @param status the status
4778             * @param start the lower bound of the range of message boards categories
4779             * @param end the upper bound of the range of message boards categories (not inclusive)
4780             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4781             * @return the ordered range of matching message boards categories that the user has permission to view
4782             */
4783            @Override
4784            public List<MBCategory> filterFindByG_S(long groupId, int status,
4785                    int start, int end, OrderByComparator<MBCategory> orderByComparator) {
4786                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4787                            return findByG_S(groupId, status, start, end, orderByComparator);
4788                    }
4789    
4790                    StringBundler query = null;
4791    
4792                    if (orderByComparator != null) {
4793                            query = new StringBundler(4 +
4794                                            (orderByComparator.getOrderByFields().length * 3));
4795                    }
4796                    else {
4797                            query = new StringBundler(4);
4798                    }
4799    
4800                    if (getDB().isSupportsInlineDistinct()) {
4801                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4802                    }
4803                    else {
4804                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4805                    }
4806    
4807                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4808    
4809                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4810    
4811                    if (!getDB().isSupportsInlineDistinct()) {
4812                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4813                    }
4814    
4815                    if (orderByComparator != null) {
4816                            if (getDB().isSupportsInlineDistinct()) {
4817                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4818                                            orderByComparator, true);
4819                            }
4820                            else {
4821                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4822                                            orderByComparator, true);
4823                            }
4824                    }
4825                    else {
4826                            if (getDB().isSupportsInlineDistinct()) {
4827                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4828                            }
4829                            else {
4830                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
4831                            }
4832                    }
4833    
4834                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4835                                    MBCategory.class.getName(),
4836                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4837    
4838                    Session session = null;
4839    
4840                    try {
4841                            session = openSession();
4842    
4843                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
4844    
4845                            if (getDB().isSupportsInlineDistinct()) {
4846                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
4847                            }
4848                            else {
4849                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
4850                            }
4851    
4852                            QueryPos qPos = QueryPos.getInstance(q);
4853    
4854                            qPos.add(groupId);
4855    
4856                            qPos.add(status);
4857    
4858                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
4859                    }
4860                    catch (Exception e) {
4861                            throw processException(e);
4862                    }
4863                    finally {
4864                            closeSession(session);
4865                    }
4866            }
4867    
4868            /**
4869             * Returns the message boards categories before and after the current message boards category in the ordered set of message boards categories that the user has permission to view where groupId = &#63; and status = &#63;.
4870             *
4871             * @param categoryId the primary key of the current message boards category
4872             * @param groupId the group ID
4873             * @param status the status
4874             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4875             * @return the previous, current, and next message boards category
4876             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
4877             */
4878            @Override
4879            public MBCategory[] filterFindByG_S_PrevAndNext(long categoryId,
4880                    long groupId, int status,
4881                    OrderByComparator<MBCategory> orderByComparator)
4882                    throws NoSuchCategoryException {
4883                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4884                            return findByG_S_PrevAndNext(categoryId, groupId, status,
4885                                    orderByComparator);
4886                    }
4887    
4888                    MBCategory mbCategory = findByPrimaryKey(categoryId);
4889    
4890                    Session session = null;
4891    
4892                    try {
4893                            session = openSession();
4894    
4895                            MBCategory[] array = new MBCategoryImpl[3];
4896    
4897                            array[0] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4898                                            status, orderByComparator, true);
4899    
4900                            array[1] = mbCategory;
4901    
4902                            array[2] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4903                                            status, orderByComparator, false);
4904    
4905                            return array;
4906                    }
4907                    catch (Exception e) {
4908                            throw processException(e);
4909                    }
4910                    finally {
4911                            closeSession(session);
4912                    }
4913            }
4914    
4915            protected MBCategory filterGetByG_S_PrevAndNext(Session session,
4916                    MBCategory mbCategory, long groupId, int status,
4917                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
4918                    StringBundler query = null;
4919    
4920                    if (orderByComparator != null) {
4921                            query = new StringBundler(6 +
4922                                            (orderByComparator.getOrderByFields().length * 6));
4923                    }
4924                    else {
4925                            query = new StringBundler(3);
4926                    }
4927    
4928                    if (getDB().isSupportsInlineDistinct()) {
4929                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4930                    }
4931                    else {
4932                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4933                    }
4934    
4935                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4936    
4937                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4938    
4939                    if (!getDB().isSupportsInlineDistinct()) {
4940                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4941                    }
4942    
4943                    if (orderByComparator != null) {
4944                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4945    
4946                            if (orderByConditionFields.length > 0) {
4947                                    query.append(WHERE_AND);
4948                            }
4949    
4950                            for (int i = 0; i < orderByConditionFields.length; i++) {
4951                                    if (getDB().isSupportsInlineDistinct()) {
4952                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4953                                    }
4954                                    else {
4955                                            query.append(_ORDER_BY_ENTITY_TABLE);
4956                                    }
4957    
4958                                    query.append(orderByConditionFields[i]);
4959    
4960                                    if ((i + 1) < orderByConditionFields.length) {
4961                                            if (orderByComparator.isAscending() ^ previous) {
4962                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4963                                            }
4964                                            else {
4965                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4966                                            }
4967                                    }
4968                                    else {
4969                                            if (orderByComparator.isAscending() ^ previous) {
4970                                                    query.append(WHERE_GREATER_THAN);
4971                                            }
4972                                            else {
4973                                                    query.append(WHERE_LESSER_THAN);
4974                                            }
4975                                    }
4976                            }
4977    
4978                            query.append(ORDER_BY_CLAUSE);
4979    
4980                            String[] orderByFields = orderByComparator.getOrderByFields();
4981    
4982                            for (int i = 0; i < orderByFields.length; i++) {
4983                                    if (getDB().isSupportsInlineDistinct()) {
4984                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4985                                    }
4986                                    else {
4987                                            query.append(_ORDER_BY_ENTITY_TABLE);
4988                                    }
4989    
4990                                    query.append(orderByFields[i]);
4991    
4992                                    if ((i + 1) < orderByFields.length) {
4993                                            if (orderByComparator.isAscending() ^ previous) {
4994                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4995                                            }
4996                                            else {
4997                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4998                                            }
4999                                    }
5000                                    else {
5001                                            if (orderByComparator.isAscending() ^ previous) {
5002                                                    query.append(ORDER_BY_ASC);
5003                                            }
5004                                            else {
5005                                                    query.append(ORDER_BY_DESC);
5006                                            }
5007                                    }
5008                            }
5009                    }
5010                    else {
5011                            if (getDB().isSupportsInlineDistinct()) {
5012                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5013                            }
5014                            else {
5015                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
5016                            }
5017                    }
5018    
5019                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5020                                    MBCategory.class.getName(),
5021                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5022    
5023                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
5024    
5025                    q.setFirstResult(0);
5026                    q.setMaxResults(2);
5027    
5028                    if (getDB().isSupportsInlineDistinct()) {
5029                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
5030                    }
5031                    else {
5032                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
5033                    }
5034    
5035                    QueryPos qPos = QueryPos.getInstance(q);
5036    
5037                    qPos.add(groupId);
5038    
5039                    qPos.add(status);
5040    
5041                    if (orderByComparator != null) {
5042                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
5043    
5044                            for (Object value : values) {
5045                                    qPos.add(value);
5046                            }
5047                    }
5048    
5049                    List<MBCategory> list = q.list();
5050    
5051                    if (list.size() == 2) {
5052                            return list.get(1);
5053                    }
5054                    else {
5055                            return null;
5056                    }
5057            }
5058    
5059            /**
5060             * Removes all the message boards categories where groupId = &#63; and status = &#63; from the database.
5061             *
5062             * @param groupId the group ID
5063             * @param status the status
5064             */
5065            @Override
5066            public void removeByG_S(long groupId, int status) {
5067                    for (MBCategory mbCategory : findByG_S(groupId, status,
5068                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5069                            remove(mbCategory);
5070                    }
5071            }
5072    
5073            /**
5074             * Returns the number of message boards categories where groupId = &#63; and status = &#63;.
5075             *
5076             * @param groupId the group ID
5077             * @param status the status
5078             * @return the number of matching message boards categories
5079             */
5080            @Override
5081            public int countByG_S(long groupId, int status) {
5082                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
5083    
5084                    Object[] finderArgs = new Object[] { groupId, status };
5085    
5086                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5087    
5088                    if (count == null) {
5089                            StringBundler query = new StringBundler(3);
5090    
5091                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
5092    
5093                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5094    
5095                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
5096    
5097                            String sql = query.toString();
5098    
5099                            Session session = null;
5100    
5101                            try {
5102                                    session = openSession();
5103    
5104                                    Query q = session.createQuery(sql);
5105    
5106                                    QueryPos qPos = QueryPos.getInstance(q);
5107    
5108                                    qPos.add(groupId);
5109    
5110                                    qPos.add(status);
5111    
5112                                    count = (Long)q.uniqueResult();
5113    
5114                                    finderCache.putResult(finderPath, finderArgs, count);
5115                            }
5116                            catch (Exception e) {
5117                                    finderCache.removeResult(finderPath, finderArgs);
5118    
5119                                    throw processException(e);
5120                            }
5121                            finally {
5122                                    closeSession(session);
5123                            }
5124                    }
5125    
5126                    return count.intValue();
5127            }
5128    
5129            /**
5130             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and status = &#63;.
5131             *
5132             * @param groupId the group ID
5133             * @param status the status
5134             * @return the number of matching message boards categories that the user has permission to view
5135             */
5136            @Override
5137            public int filterCountByG_S(long groupId, int status) {
5138                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5139                            return countByG_S(groupId, status);
5140                    }
5141    
5142                    StringBundler query = new StringBundler(3);
5143    
5144                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
5145    
5146                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5147    
5148                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5149    
5150                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5151                                    MBCategory.class.getName(),
5152                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5153    
5154                    Session session = null;
5155    
5156                    try {
5157                            session = openSession();
5158    
5159                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
5160    
5161                            q.addScalar(COUNT_COLUMN_NAME,
5162                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5163    
5164                            QueryPos qPos = QueryPos.getInstance(q);
5165    
5166                            qPos.add(groupId);
5167    
5168                            qPos.add(status);
5169    
5170                            Long count = (Long)q.uniqueResult();
5171    
5172                            return count.intValue();
5173                    }
5174                    catch (Exception e) {
5175                            throw processException(e);
5176                    }
5177                    finally {
5178                            closeSession(session);
5179                    }
5180            }
5181    
5182            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
5183            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbCategory.status = ?";
5184            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5185                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5186                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
5187                            new String[] {
5188                                    Long.class.getName(), Integer.class.getName(),
5189                                    
5190                            Integer.class.getName(), Integer.class.getName(),
5191                                    OrderByComparator.class.getName()
5192                            });
5193            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5194                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5195                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
5196                            new String[] { Long.class.getName(), Integer.class.getName() },
5197                            MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
5198                            MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
5199                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5200                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
5201            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5202                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5203                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
5204                            new String[] { Long.class.getName(), Integer.class.getName() });
5205    
5206            /**
5207             * Returns all the message boards categories where companyId = &#63; and status = &#63;.
5208             *
5209             * @param companyId the company ID
5210             * @param status the status
5211             * @return the matching message boards categories
5212             */
5213            @Override
5214            public List<MBCategory> findByC_S(long companyId, int status) {
5215                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
5216                            QueryUtil.ALL_POS, null);
5217            }
5218    
5219            /**
5220             * Returns a range of all the message boards categories where companyId = &#63; and status = &#63;.
5221             *
5222             * <p>
5223             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
5224             * </p>
5225             *
5226             * @param companyId the company ID
5227             * @param status the status
5228             * @param start the lower bound of the range of message boards categories
5229             * @param end the upper bound of the range of message boards categories (not inclusive)
5230             * @return the range of matching message boards categories
5231             */
5232            @Override
5233            public List<MBCategory> findByC_S(long companyId, int status, int start,
5234                    int end) {
5235                    return findByC_S(companyId, status, start, end, null);
5236            }
5237    
5238            /**
5239             * Returns an ordered range of all the message boards categories where companyId = &#63; and status = &#63;.
5240             *
5241             * <p>
5242             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
5243             * </p>
5244             *
5245             * @param companyId the company ID
5246             * @param status the status
5247             * @param start the lower bound of the range of message boards categories
5248             * @param end the upper bound of the range of message boards categories (not inclusive)
5249             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5250             * @return the ordered range of matching message boards categories
5251             */
5252            @Override
5253            public List<MBCategory> findByC_S(long companyId, int status, int start,
5254                    int end, OrderByComparator<MBCategory> orderByComparator) {
5255                    return findByC_S(companyId, status, start, end, orderByComparator, true);
5256            }
5257    
5258            /**
5259             * Returns an ordered range of all the message boards categories where companyId = &#63; and status = &#63;.
5260             *
5261             * <p>
5262             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
5263             * </p>
5264             *
5265             * @param companyId the company ID
5266             * @param status the status
5267             * @param start the lower bound of the range of message boards categories
5268             * @param end the upper bound of the range of message boards categories (not inclusive)
5269             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5270             * @param retrieveFromCache whether to retrieve from the finder cache
5271             * @return the ordered range of matching message boards categories
5272             */
5273            @Override
5274            public List<MBCategory> findByC_S(long companyId, int status, int start,
5275                    int end, OrderByComparator<MBCategory> orderByComparator,
5276                    boolean retrieveFromCache) {
5277                    boolean pagination = true;
5278                    FinderPath finderPath = null;
5279                    Object[] finderArgs = null;
5280    
5281                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5282                                    (orderByComparator == null)) {
5283                            pagination = false;
5284                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
5285                            finderArgs = new Object[] { companyId, status };
5286                    }
5287                    else {
5288                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
5289                            finderArgs = new Object[] {
5290                                            companyId, status,
5291                                            
5292                                            start, end, orderByComparator
5293                                    };
5294                    }
5295    
5296                    List<MBCategory> list = null;
5297    
5298                    if (retrieveFromCache) {
5299                            list = (List<MBCategory>)finderCache.getResult(finderPath,
5300                                            finderArgs, this);
5301    
5302                            if ((list != null) && !list.isEmpty()) {
5303                                    for (MBCategory mbCategory : list) {
5304                                            if ((companyId != mbCategory.getCompanyId()) ||
5305                                                            (status != mbCategory.getStatus())) {
5306                                                    list = null;
5307    
5308                                                    break;
5309                                            }
5310                                    }
5311                            }
5312                    }
5313    
5314                    if (list == null) {
5315                            StringBundler query = null;
5316    
5317                            if (orderByComparator != null) {
5318                                    query = new StringBundler(4 +
5319                                                    (orderByComparator.getOrderByFields().length * 3));
5320                            }
5321                            else {
5322                                    query = new StringBundler(4);
5323                            }
5324    
5325                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5326    
5327                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5328    
5329                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
5330    
5331                            if (orderByComparator != null) {
5332                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5333                                            orderByComparator);
5334                            }
5335                            else
5336                             if (pagination) {
5337                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5338                            }
5339    
5340                            String sql = query.toString();
5341    
5342                            Session session = null;
5343    
5344                            try {
5345                                    session = openSession();
5346    
5347                                    Query q = session.createQuery(sql);
5348    
5349                                    QueryPos qPos = QueryPos.getInstance(q);
5350    
5351                                    qPos.add(companyId);
5352    
5353                                    qPos.add(status);
5354    
5355                                    if (!pagination) {
5356                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5357                                                            start, end, false);
5358    
5359                                            Collections.sort(list);
5360    
5361                                            list = Collections.unmodifiableList(list);
5362                                    }
5363                                    else {
5364                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5365                                                            start, end);
5366                                    }
5367    
5368                                    cacheResult(list);
5369    
5370                                    finderCache.putResult(finderPath, finderArgs, list);
5371                            }
5372                            catch (Exception e) {
5373                                    finderCache.removeResult(finderPath, finderArgs);
5374    
5375                                    throw processException(e);
5376                            }
5377                            finally {
5378                                    closeSession(session);
5379                            }
5380                    }
5381    
5382                    return list;
5383            }
5384    
5385            /**
5386             * Returns the first message boards category in the ordered set where companyId = &#63; and status = &#63;.
5387             *
5388             * @param companyId the company ID
5389             * @param status the status
5390             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5391             * @return the first matching message boards category
5392             * @throws NoSuchCategoryException if a matching message boards category could not be found
5393             */
5394            @Override
5395            public MBCategory findByC_S_First(long companyId, int status,
5396                    OrderByComparator<MBCategory> orderByComparator)
5397                    throws NoSuchCategoryException {
5398                    MBCategory mbCategory = fetchByC_S_First(companyId, status,
5399                                    orderByComparator);
5400    
5401                    if (mbCategory != null) {
5402                            return mbCategory;
5403                    }
5404    
5405                    StringBundler msg = new StringBundler(6);
5406    
5407                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5408    
5409                    msg.append("companyId=");
5410                    msg.append(companyId);
5411    
5412                    msg.append(", status=");
5413                    msg.append(status);
5414    
5415                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5416    
5417                    throw new NoSuchCategoryException(msg.toString());
5418            }
5419    
5420            /**
5421             * Returns the first message boards category in the ordered set where companyId = &#63; and status = &#63;.
5422             *
5423             * @param companyId the company ID
5424             * @param status the status
5425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5426             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
5427             */
5428            @Override
5429            public MBCategory fetchByC_S_First(long companyId, int status,
5430                    OrderByComparator<MBCategory> orderByComparator) {
5431                    List<MBCategory> list = findByC_S(companyId, status, 0, 1,
5432                                    orderByComparator);
5433    
5434                    if (!list.isEmpty()) {
5435                            return list.get(0);
5436                    }
5437    
5438                    return null;
5439            }
5440    
5441            /**
5442             * Returns the last message boards category in the ordered set where companyId = &#63; and status = &#63;.
5443             *
5444             * @param companyId the company ID
5445             * @param status the status
5446             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5447             * @return the last matching message boards category
5448             * @throws NoSuchCategoryException if a matching message boards category could not be found
5449             */
5450            @Override
5451            public MBCategory findByC_S_Last(long companyId, int status,
5452                    OrderByComparator<MBCategory> orderByComparator)
5453                    throws NoSuchCategoryException {
5454                    MBCategory mbCategory = fetchByC_S_Last(companyId, status,
5455                                    orderByComparator);
5456    
5457                    if (mbCategory != null) {
5458                            return mbCategory;
5459                    }
5460    
5461                    StringBundler msg = new StringBundler(6);
5462    
5463                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5464    
5465                    msg.append("companyId=");
5466                    msg.append(companyId);
5467    
5468                    msg.append(", status=");
5469                    msg.append(status);
5470    
5471                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5472    
5473                    throw new NoSuchCategoryException(msg.toString());
5474            }
5475    
5476            /**
5477             * Returns the last message boards category in the ordered set where companyId = &#63; and status = &#63;.
5478             *
5479             * @param companyId the company ID
5480             * @param status the status
5481             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5482             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
5483             */
5484            @Override
5485            public MBCategory fetchByC_S_Last(long companyId, int status,
5486                    OrderByComparator<MBCategory> orderByComparator) {
5487                    int count = countByC_S(companyId, status);
5488    
5489                    if (count == 0) {
5490                            return null;
5491                    }
5492    
5493                    List<MBCategory> list = findByC_S(companyId, status, count - 1, count,
5494                                    orderByComparator);
5495    
5496                    if (!list.isEmpty()) {
5497                            return list.get(0);
5498                    }
5499    
5500                    return null;
5501            }
5502    
5503            /**
5504             * Returns the message boards categories before and after the current message boards category in the ordered set where companyId = &#63; and status = &#63;.
5505             *
5506             * @param categoryId the primary key of the current message boards category
5507             * @param companyId the company ID
5508             * @param status the status
5509             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5510             * @return the previous, current, and next message boards category
5511             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
5512             */
5513            @Override
5514            public MBCategory[] findByC_S_PrevAndNext(long categoryId, long companyId,
5515                    int status, OrderByComparator<MBCategory> orderByComparator)
5516                    throws NoSuchCategoryException {
5517                    MBCategory mbCategory = findByPrimaryKey(categoryId);
5518    
5519                    Session session = null;
5520    
5521                    try {
5522                            session = openSession();
5523    
5524                            MBCategory[] array = new MBCategoryImpl[3];
5525    
5526                            array[0] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5527                                            status, orderByComparator, true);
5528    
5529                            array[1] = mbCategory;
5530    
5531                            array[2] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5532                                            status, orderByComparator, false);
5533    
5534                            return array;
5535                    }
5536                    catch (Exception e) {
5537                            throw processException(e);
5538                    }
5539                    finally {
5540                            closeSession(session);
5541                    }
5542            }
5543    
5544            protected MBCategory getByC_S_PrevAndNext(Session session,
5545                    MBCategory mbCategory, long companyId, int status,
5546                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
5547                    StringBundler query = null;
5548    
5549                    if (orderByComparator != null) {
5550                            query = new StringBundler(6 +
5551                                            (orderByComparator.getOrderByFields().length * 6));
5552                    }
5553                    else {
5554                            query = new StringBundler(3);
5555                    }
5556    
5557                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5558    
5559                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5560    
5561                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
5562    
5563                    if (orderByComparator != null) {
5564                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5565    
5566                            if (orderByConditionFields.length > 0) {
5567                                    query.append(WHERE_AND);
5568                            }
5569    
5570                            for (int i = 0; i < orderByConditionFields.length; i++) {
5571                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5572                                    query.append(orderByConditionFields[i]);
5573    
5574                                    if ((i + 1) < orderByConditionFields.length) {
5575                                            if (orderByComparator.isAscending() ^ previous) {
5576                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5577                                            }
5578                                            else {
5579                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5580                                            }
5581                                    }
5582                                    else {
5583                                            if (orderByComparator.isAscending() ^ previous) {
5584                                                    query.append(WHERE_GREATER_THAN);
5585                                            }
5586                                            else {
5587                                                    query.append(WHERE_LESSER_THAN);
5588                                            }
5589                                    }
5590                            }
5591    
5592                            query.append(ORDER_BY_CLAUSE);
5593    
5594                            String[] orderByFields = orderByComparator.getOrderByFields();
5595    
5596                            for (int i = 0; i < orderByFields.length; i++) {
5597                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5598                                    query.append(orderByFields[i]);
5599    
5600                                    if ((i + 1) < orderByFields.length) {
5601                                            if (orderByComparator.isAscending() ^ previous) {
5602                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5603                                            }
5604                                            else {
5605                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5606                                            }
5607                                    }
5608                                    else {
5609                                            if (orderByComparator.isAscending() ^ previous) {
5610                                                    query.append(ORDER_BY_ASC);
5611                                            }
5612                                            else {
5613                                                    query.append(ORDER_BY_DESC);
5614                                            }
5615                                    }
5616                            }
5617                    }
5618                    else {
5619                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5620                    }
5621    
5622                    String sql = query.toString();
5623    
5624                    Query q = session.createQuery(sql);
5625    
5626                    q.setFirstResult(0);
5627                    q.setMaxResults(2);
5628    
5629                    QueryPos qPos = QueryPos.getInstance(q);
5630    
5631                    qPos.add(companyId);
5632    
5633                    qPos.add(status);
5634    
5635                    if (orderByComparator != null) {
5636                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
5637    
5638                            for (Object value : values) {
5639                                    qPos.add(value);
5640                            }
5641                    }
5642    
5643                    List<MBCategory> list = q.list();
5644    
5645                    if (list.size() == 2) {
5646                            return list.get(1);
5647                    }
5648                    else {
5649                            return null;
5650                    }
5651            }
5652    
5653            /**
5654             * Removes all the message boards categories where companyId = &#63; and status = &#63; from the database.
5655             *
5656             * @param companyId the company ID
5657             * @param status the status
5658             */
5659            @Override
5660            public void removeByC_S(long companyId, int status) {
5661                    for (MBCategory mbCategory : findByC_S(companyId, status,
5662                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5663                            remove(mbCategory);
5664                    }
5665            }
5666    
5667            /**
5668             * Returns the number of message boards categories where companyId = &#63; and status = &#63;.
5669             *
5670             * @param companyId the company ID
5671             * @param status the status
5672             * @return the number of matching message boards categories
5673             */
5674            @Override
5675            public int countByC_S(long companyId, int status) {
5676                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
5677    
5678                    Object[] finderArgs = new Object[] { companyId, status };
5679    
5680                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
5681    
5682                    if (count == null) {
5683                            StringBundler query = new StringBundler(3);
5684    
5685                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
5686    
5687                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5688    
5689                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
5690    
5691                            String sql = query.toString();
5692    
5693                            Session session = null;
5694    
5695                            try {
5696                                    session = openSession();
5697    
5698                                    Query q = session.createQuery(sql);
5699    
5700                                    QueryPos qPos = QueryPos.getInstance(q);
5701    
5702                                    qPos.add(companyId);
5703    
5704                                    qPos.add(status);
5705    
5706                                    count = (Long)q.uniqueResult();
5707    
5708                                    finderCache.putResult(finderPath, finderArgs, count);
5709                            }
5710                            catch (Exception e) {
5711                                    finderCache.removeResult(finderPath, finderArgs);
5712    
5713                                    throw processException(e);
5714                            }
5715                            finally {
5716                                    closeSession(session);
5717                            }
5718                    }
5719    
5720                    return count.intValue();
5721            }
5722    
5723            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbCategory.companyId = ? AND ";
5724            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbCategory.status = ?";
5725            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5726                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5727                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNotC_G_P",
5728                            new String[] {
5729                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
5730                                    
5731                            Integer.class.getName(), Integer.class.getName(),
5732                                    OrderByComparator.class.getName()
5733                            });
5734            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P =
5735                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5736                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5737                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByNotC_G_P",
5738                            new String[] {
5739                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
5740                            });
5741    
5742            /**
5743             * Returns all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
5744             *
5745             * @param categoryId the category ID
5746             * @param groupId the group ID
5747             * @param parentCategoryId the parent category ID
5748             * @return the matching message boards categories
5749             */
5750            @Override
5751            public List<MBCategory> findByNotC_G_P(long categoryId, long groupId,
5752                    long parentCategoryId) {
5753                    return findByNotC_G_P(categoryId, groupId, parentCategoryId,
5754                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5755            }
5756    
5757            /**
5758             * Returns a range of all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
5759             *
5760             * <p>
5761             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
5762             * </p>
5763             *
5764             * @param categoryId the category ID
5765             * @param groupId the group ID
5766             * @param parentCategoryId the parent category ID
5767             * @param start the lower bound of the range of message boards categories
5768             * @param end the upper bound of the range of message boards categories (not inclusive)
5769             * @return the range of matching message boards categories
5770             */
5771            @Override
5772            public List<MBCategory> findByNotC_G_P(long categoryId, long groupId,
5773                    long parentCategoryId, int start, int end) {
5774                    return findByNotC_G_P(categoryId, groupId, parentCategoryId, start,
5775                            end, null);
5776            }
5777    
5778            /**
5779             * Returns an ordered range of all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
5780             *
5781             * <p>
5782             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
5783             * </p>
5784             *
5785             * @param categoryId the category ID
5786             * @param groupId the group ID
5787             * @param parentCategoryId the parent category ID
5788             * @param start the lower bound of the range of message boards categories
5789             * @param end the upper bound of the range of message boards categories (not inclusive)
5790             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5791             * @return the ordered range of matching message boards categories
5792             */
5793            @Override
5794            public List<MBCategory> findByNotC_G_P(long categoryId, long groupId,
5795                    long parentCategoryId, int start, int end,
5796                    OrderByComparator<MBCategory> orderByComparator) {
5797                    return findByNotC_G_P(categoryId, groupId, parentCategoryId, start,
5798                            end, orderByComparator, true);
5799            }
5800    
5801            /**
5802             * Returns an ordered range of all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
5803             *
5804             * <p>
5805             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
5806             * </p>
5807             *
5808             * @param categoryId the category ID
5809             * @param groupId the group ID
5810             * @param parentCategoryId the parent category ID
5811             * @param start the lower bound of the range of message boards categories
5812             * @param end the upper bound of the range of message boards categories (not inclusive)
5813             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5814             * @param retrieveFromCache whether to retrieve from the finder cache
5815             * @return the ordered range of matching message boards categories
5816             */
5817            @Override
5818            public List<MBCategory> findByNotC_G_P(long categoryId, long groupId,
5819                    long parentCategoryId, int start, int end,
5820                    OrderByComparator<MBCategory> orderByComparator,
5821                    boolean retrieveFromCache) {
5822                    boolean pagination = true;
5823                    FinderPath finderPath = null;
5824                    Object[] finderArgs = null;
5825    
5826                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P;
5827                    finderArgs = new Object[] {
5828                                    categoryId, groupId, parentCategoryId,
5829                                    
5830                                    start, end, orderByComparator
5831                            };
5832    
5833                    List<MBCategory> list = null;
5834    
5835                    if (retrieveFromCache) {
5836                            list = (List<MBCategory>)finderCache.getResult(finderPath,
5837                                            finderArgs, this);
5838    
5839                            if ((list != null) && !list.isEmpty()) {
5840                                    for (MBCategory mbCategory : list) {
5841                                            if ((categoryId == mbCategory.getCategoryId()) ||
5842                                                            (groupId != mbCategory.getGroupId()) ||
5843                                                            (parentCategoryId != mbCategory.getParentCategoryId())) {
5844                                                    list = null;
5845    
5846                                                    break;
5847                                            }
5848                                    }
5849                            }
5850                    }
5851    
5852                    if (list == null) {
5853                            StringBundler query = null;
5854    
5855                            if (orderByComparator != null) {
5856                                    query = new StringBundler(5 +
5857                                                    (orderByComparator.getOrderByFields().length * 3));
5858                            }
5859                            else {
5860                                    query = new StringBundler(5);
5861                            }
5862    
5863                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5864    
5865                            query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_2);
5866    
5867                            query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
5868    
5869                            query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2);
5870    
5871                            if (orderByComparator != null) {
5872                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5873                                            orderByComparator);
5874                            }
5875                            else
5876                             if (pagination) {
5877                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5878                            }
5879    
5880                            String sql = query.toString();
5881    
5882                            Session session = null;
5883    
5884                            try {
5885                                    session = openSession();
5886    
5887                                    Query q = session.createQuery(sql);
5888    
5889                                    QueryPos qPos = QueryPos.getInstance(q);
5890    
5891                                    qPos.add(categoryId);
5892    
5893                                    qPos.add(groupId);
5894    
5895                                    qPos.add(parentCategoryId);
5896    
5897                                    if (!pagination) {
5898                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5899                                                            start, end, false);
5900    
5901                                            Collections.sort(list);
5902    
5903                                            list = Collections.unmodifiableList(list);
5904                                    }
5905                                    else {
5906                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5907                                                            start, end);
5908                                    }
5909    
5910                                    cacheResult(list);
5911    
5912                                    finderCache.putResult(finderPath, finderArgs, list);
5913                            }
5914                            catch (Exception e) {
5915                                    finderCache.removeResult(finderPath, finderArgs);
5916    
5917                                    throw processException(e);
5918                            }
5919                            finally {
5920                                    closeSession(session);
5921                            }
5922                    }
5923    
5924                    return list;
5925            }
5926    
5927            /**
5928             * Returns the first message boards category in the ordered set where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
5929             *
5930             * @param categoryId the category ID
5931             * @param groupId the group ID
5932             * @param parentCategoryId the parent category ID
5933             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5934             * @return the first matching message boards category
5935             * @throws NoSuchCategoryException if a matching message boards category could not be found
5936             */
5937            @Override
5938            public MBCategory findByNotC_G_P_First(long categoryId, long groupId,
5939                    long parentCategoryId, OrderByComparator<MBCategory> orderByComparator)
5940                    throws NoSuchCategoryException {
5941                    MBCategory mbCategory = fetchByNotC_G_P_First(categoryId, groupId,
5942                                    parentCategoryId, orderByComparator);
5943    
5944                    if (mbCategory != null) {
5945                            return mbCategory;
5946                    }
5947    
5948                    StringBundler msg = new StringBundler(8);
5949    
5950                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5951    
5952                    msg.append("categoryId=");
5953                    msg.append(categoryId);
5954    
5955                    msg.append(", groupId=");
5956                    msg.append(groupId);
5957    
5958                    msg.append(", parentCategoryId=");
5959                    msg.append(parentCategoryId);
5960    
5961                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5962    
5963                    throw new NoSuchCategoryException(msg.toString());
5964            }
5965    
5966            /**
5967             * Returns the first message boards category in the ordered set where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
5968             *
5969             * @param categoryId the category ID
5970             * @param groupId the group ID
5971             * @param parentCategoryId the parent category ID
5972             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5973             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
5974             */
5975            @Override
5976            public MBCategory fetchByNotC_G_P_First(long categoryId, long groupId,
5977                    long parentCategoryId, OrderByComparator<MBCategory> orderByComparator) {
5978                    List<MBCategory> list = findByNotC_G_P(categoryId, groupId,
5979                                    parentCategoryId, 0, 1, orderByComparator);
5980    
5981                    if (!list.isEmpty()) {
5982                            return list.get(0);
5983                    }
5984    
5985                    return null;
5986            }
5987    
5988            /**
5989             * Returns the last message boards category in the ordered set where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
5990             *
5991             * @param categoryId the category ID
5992             * @param groupId the group ID
5993             * @param parentCategoryId the parent category ID
5994             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5995             * @return the last matching message boards category
5996             * @throws NoSuchCategoryException if a matching message boards category could not be found
5997             */
5998            @Override
5999            public MBCategory findByNotC_G_P_Last(long categoryId, long groupId,
6000                    long parentCategoryId, OrderByComparator<MBCategory> orderByComparator)
6001                    throws NoSuchCategoryException {
6002                    MBCategory mbCategory = fetchByNotC_G_P_Last(categoryId, groupId,
6003                                    parentCategoryId, orderByComparator);
6004    
6005                    if (mbCategory != null) {
6006                            return mbCategory;
6007                    }
6008    
6009                    StringBundler msg = new StringBundler(8);
6010    
6011                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6012    
6013                    msg.append("categoryId=");
6014                    msg.append(categoryId);
6015    
6016                    msg.append(", groupId=");
6017                    msg.append(groupId);
6018    
6019                    msg.append(", parentCategoryId=");
6020                    msg.append(parentCategoryId);
6021    
6022                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6023    
6024                    throw new NoSuchCategoryException(msg.toString());
6025            }
6026    
6027            /**
6028             * Returns the last message boards category in the ordered set where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
6029             *
6030             * @param categoryId the category ID
6031             * @param groupId the group ID
6032             * @param parentCategoryId the parent category ID
6033             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6034             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
6035             */
6036            @Override
6037            public MBCategory fetchByNotC_G_P_Last(long categoryId, long groupId,
6038                    long parentCategoryId, OrderByComparator<MBCategory> orderByComparator) {
6039                    int count = countByNotC_G_P(categoryId, groupId, parentCategoryId);
6040    
6041                    if (count == 0) {
6042                            return null;
6043                    }
6044    
6045                    List<MBCategory> list = findByNotC_G_P(categoryId, groupId,
6046                                    parentCategoryId, count - 1, count, orderByComparator);
6047    
6048                    if (!list.isEmpty()) {
6049                            return list.get(0);
6050                    }
6051    
6052                    return null;
6053            }
6054    
6055            /**
6056             * Returns all the message boards categories that the user has permission to view where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
6057             *
6058             * @param categoryId the category ID
6059             * @param groupId the group ID
6060             * @param parentCategoryId the parent category ID
6061             * @return the matching message boards categories that the user has permission to view
6062             */
6063            @Override
6064            public List<MBCategory> filterFindByNotC_G_P(long categoryId, long groupId,
6065                    long parentCategoryId) {
6066                    return filterFindByNotC_G_P(categoryId, groupId, parentCategoryId,
6067                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6068            }
6069    
6070            /**
6071             * Returns a range of all the message boards categories that the user has permission to view where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
6072             *
6073             * <p>
6074             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
6075             * </p>
6076             *
6077             * @param categoryId the category ID
6078             * @param groupId the group ID
6079             * @param parentCategoryId the parent category ID
6080             * @param start the lower bound of the range of message boards categories
6081             * @param end the upper bound of the range of message boards categories (not inclusive)
6082             * @return the range of matching message boards categories that the user has permission to view
6083             */
6084            @Override
6085            public List<MBCategory> filterFindByNotC_G_P(long categoryId, long groupId,
6086                    long parentCategoryId, int start, int end) {
6087                    return filterFindByNotC_G_P(categoryId, groupId, parentCategoryId,
6088                            start, end, null);
6089            }
6090    
6091            /**
6092             * Returns an ordered range of all the message boards categories that the user has permissions to view where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
6093             *
6094             * <p>
6095             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
6096             * </p>
6097             *
6098             * @param categoryId the category ID
6099             * @param groupId the group ID
6100             * @param parentCategoryId the parent category ID
6101             * @param start the lower bound of the range of message boards categories
6102             * @param end the upper bound of the range of message boards categories (not inclusive)
6103             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6104             * @return the ordered range of matching message boards categories that the user has permission to view
6105             */
6106            @Override
6107            public List<MBCategory> filterFindByNotC_G_P(long categoryId, long groupId,
6108                    long parentCategoryId, int start, int end,
6109                    OrderByComparator<MBCategory> orderByComparator) {
6110                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6111                            return findByNotC_G_P(categoryId, groupId, parentCategoryId, start,
6112                                    end, orderByComparator);
6113                    }
6114    
6115                    StringBundler query = null;
6116    
6117                    if (orderByComparator != null) {
6118                            query = new StringBundler(5 +
6119                                            (orderByComparator.getOrderByFields().length * 3));
6120                    }
6121                    else {
6122                            query = new StringBundler(5);
6123                    }
6124    
6125                    if (getDB().isSupportsInlineDistinct()) {
6126                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6127                    }
6128                    else {
6129                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6130                    }
6131    
6132                    query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_2);
6133    
6134                    query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6135    
6136                    query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2);
6137    
6138                    if (!getDB().isSupportsInlineDistinct()) {
6139                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6140                    }
6141    
6142                    if (orderByComparator != null) {
6143                            if (getDB().isSupportsInlineDistinct()) {
6144                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6145                                            orderByComparator, true);
6146                            }
6147                            else {
6148                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6149                                            orderByComparator, true);
6150                            }
6151                    }
6152                    else {
6153                            if (getDB().isSupportsInlineDistinct()) {
6154                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6155                            }
6156                            else {
6157                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6158                            }
6159                    }
6160    
6161                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6162                                    MBCategory.class.getName(),
6163                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6164    
6165                    Session session = null;
6166    
6167                    try {
6168                            session = openSession();
6169    
6170                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6171    
6172                            if (getDB().isSupportsInlineDistinct()) {
6173                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6174                            }
6175                            else {
6176                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6177                            }
6178    
6179                            QueryPos qPos = QueryPos.getInstance(q);
6180    
6181                            qPos.add(categoryId);
6182    
6183                            qPos.add(groupId);
6184    
6185                            qPos.add(parentCategoryId);
6186    
6187                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
6188                    }
6189                    catch (Exception e) {
6190                            throw processException(e);
6191                    }
6192                    finally {
6193                            closeSession(session);
6194                    }
6195            }
6196    
6197            /**
6198             * Returns all the message boards categories that the user has permission to view where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63;.
6199             *
6200             * @param categoryIds the category IDs
6201             * @param groupId the group ID
6202             * @param parentCategoryIds the parent category IDs
6203             * @return the matching message boards categories that the user has permission to view
6204             */
6205            @Override
6206            public List<MBCategory> filterFindByNotC_G_P(long[] categoryIds,
6207                    long groupId, long[] parentCategoryIds) {
6208                    return filterFindByNotC_G_P(categoryIds, groupId, parentCategoryIds,
6209                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6210            }
6211    
6212            /**
6213             * Returns a range of all the message boards categories that the user has permission to view where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63;.
6214             *
6215             * <p>
6216             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
6217             * </p>
6218             *
6219             * @param categoryIds the category IDs
6220             * @param groupId the group ID
6221             * @param parentCategoryIds the parent category IDs
6222             * @param start the lower bound of the range of message boards categories
6223             * @param end the upper bound of the range of message boards categories (not inclusive)
6224             * @return the range of matching message boards categories that the user has permission to view
6225             */
6226            @Override
6227            public List<MBCategory> filterFindByNotC_G_P(long[] categoryIds,
6228                    long groupId, long[] parentCategoryIds, int start, int end) {
6229                    return filterFindByNotC_G_P(categoryIds, groupId, parentCategoryIds,
6230                            start, end, null);
6231            }
6232    
6233            /**
6234             * Returns an ordered range of all the message boards categories that the user has permission to view where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63;.
6235             *
6236             * <p>
6237             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
6238             * </p>
6239             *
6240             * @param categoryIds the category IDs
6241             * @param groupId the group ID
6242             * @param parentCategoryIds the parent category IDs
6243             * @param start the lower bound of the range of message boards categories
6244             * @param end the upper bound of the range of message boards categories (not inclusive)
6245             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6246             * @return the ordered range of matching message boards categories that the user has permission to view
6247             */
6248            @Override
6249            public List<MBCategory> filterFindByNotC_G_P(long[] categoryIds,
6250                    long groupId, long[] parentCategoryIds, int start, int end,
6251                    OrderByComparator<MBCategory> orderByComparator) {
6252                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6253                            return findByNotC_G_P(categoryIds, groupId, parentCategoryIds,
6254                                    start, end, orderByComparator);
6255                    }
6256    
6257                    if (categoryIds == null) {
6258                            categoryIds = new long[0];
6259                    }
6260                    else if (categoryIds.length > 1) {
6261                            categoryIds = ArrayUtil.unique(categoryIds);
6262    
6263                            Arrays.sort(categoryIds);
6264                    }
6265    
6266                    if (parentCategoryIds == null) {
6267                            parentCategoryIds = new long[0];
6268                    }
6269                    else if (parentCategoryIds.length > 1) {
6270                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
6271    
6272                            Arrays.sort(parentCategoryIds);
6273                    }
6274    
6275                    StringBundler query = new StringBundler();
6276    
6277                    if (getDB().isSupportsInlineDistinct()) {
6278                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6279                    }
6280                    else {
6281                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6282                    }
6283    
6284                    if (categoryIds.length > 0) {
6285                            query.append(StringPool.OPEN_PARENTHESIS);
6286    
6287                            query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_7);
6288    
6289                            query.append(StringUtil.merge(categoryIds));
6290    
6291                            query.append(StringPool.CLOSE_PARENTHESIS);
6292    
6293                            query.append(StringPool.CLOSE_PARENTHESIS);
6294    
6295                            query.append(WHERE_AND);
6296                    }
6297    
6298                    query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6299    
6300                    if (parentCategoryIds.length > 0) {
6301                            query.append(StringPool.OPEN_PARENTHESIS);
6302    
6303                            query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7);
6304    
6305                            query.append(StringUtil.merge(parentCategoryIds));
6306    
6307                            query.append(StringPool.CLOSE_PARENTHESIS);
6308    
6309                            query.append(StringPool.CLOSE_PARENTHESIS);
6310                    }
6311    
6312                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
6313                            query.index() - 1);
6314    
6315                    if (!getDB().isSupportsInlineDistinct()) {
6316                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6317                    }
6318    
6319                    if (orderByComparator != null) {
6320                            if (getDB().isSupportsInlineDistinct()) {
6321                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6322                                            orderByComparator, true);
6323                            }
6324                            else {
6325                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6326                                            orderByComparator, true);
6327                            }
6328                    }
6329                    else {
6330                            if (getDB().isSupportsInlineDistinct()) {
6331                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6332                            }
6333                            else {
6334                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6335                            }
6336                    }
6337    
6338                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6339                                    MBCategory.class.getName(),
6340                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6341    
6342                    Session session = null;
6343    
6344                    try {
6345                            session = openSession();
6346    
6347                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6348    
6349                            if (getDB().isSupportsInlineDistinct()) {
6350                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6351                            }
6352                            else {
6353                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6354                            }
6355    
6356                            QueryPos qPos = QueryPos.getInstance(q);
6357    
6358                            qPos.add(groupId);
6359    
6360                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
6361                    }
6362                    catch (Exception e) {
6363                            throw processException(e);
6364                    }
6365                    finally {
6366                            closeSession(session);
6367                    }
6368            }
6369    
6370            /**
6371             * Returns all the message boards categories where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63;.
6372             *
6373             * <p>
6374             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
6375             * </p>
6376             *
6377             * @param categoryIds the category IDs
6378             * @param groupId the group ID
6379             * @param parentCategoryIds the parent category IDs
6380             * @return the matching message boards categories
6381             */
6382            @Override
6383            public List<MBCategory> findByNotC_G_P(long[] categoryIds, long groupId,
6384                    long[] parentCategoryIds) {
6385                    return findByNotC_G_P(categoryIds, groupId, parentCategoryIds,
6386                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6387            }
6388    
6389            /**
6390             * Returns a range of all the message boards categories where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63;.
6391             *
6392             * <p>
6393             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
6394             * </p>
6395             *
6396             * @param categoryIds the category IDs
6397             * @param groupId the group ID
6398             * @param parentCategoryIds the parent category IDs
6399             * @param start the lower bound of the range of message boards categories
6400             * @param end the upper bound of the range of message boards categories (not inclusive)
6401             * @return the range of matching message boards categories
6402             */
6403            @Override
6404            public List<MBCategory> findByNotC_G_P(long[] categoryIds, long groupId,
6405                    long[] parentCategoryIds, int start, int end) {
6406                    return findByNotC_G_P(categoryIds, groupId, parentCategoryIds, start,
6407                            end, null);
6408            }
6409    
6410            /**
6411             * Returns an ordered range of all the message boards categories where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63;.
6412             *
6413             * <p>
6414             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
6415             * </p>
6416             *
6417             * @param categoryIds the category IDs
6418             * @param groupId the group ID
6419             * @param parentCategoryIds the parent category IDs
6420             * @param start the lower bound of the range of message boards categories
6421             * @param end the upper bound of the range of message boards categories (not inclusive)
6422             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6423             * @return the ordered range of matching message boards categories
6424             */
6425            @Override
6426            public List<MBCategory> findByNotC_G_P(long[] categoryIds, long groupId,
6427                    long[] parentCategoryIds, int start, int end,
6428                    OrderByComparator<MBCategory> orderByComparator) {
6429                    return findByNotC_G_P(categoryIds, groupId, parentCategoryIds, start,
6430                            end, orderByComparator, true);
6431            }
6432    
6433            /**
6434             * Returns an ordered range of all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;, optionally using the finder cache.
6435             *
6436             * <p>
6437             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
6438             * </p>
6439             *
6440             * @param categoryId the category ID
6441             * @param groupId the group ID
6442             * @param parentCategoryId the parent category ID
6443             * @param start the lower bound of the range of message boards categories
6444             * @param end the upper bound of the range of message boards categories (not inclusive)
6445             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6446             * @param retrieveFromCache whether to retrieve from the finder cache
6447             * @return the ordered range of matching message boards categories
6448             */
6449            @Override
6450            public List<MBCategory> findByNotC_G_P(long[] categoryIds, long groupId,
6451                    long[] parentCategoryIds, int start, int end,
6452                    OrderByComparator<MBCategory> orderByComparator,
6453                    boolean retrieveFromCache) {
6454                    if (categoryIds == null) {
6455                            categoryIds = new long[0];
6456                    }
6457                    else if (categoryIds.length > 1) {
6458                            categoryIds = ArrayUtil.unique(categoryIds);
6459    
6460                            Arrays.sort(categoryIds);
6461                    }
6462    
6463                    if (parentCategoryIds == null) {
6464                            parentCategoryIds = new long[0];
6465                    }
6466                    else if (parentCategoryIds.length > 1) {
6467                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
6468    
6469                            Arrays.sort(parentCategoryIds);
6470                    }
6471    
6472                    if ((categoryIds.length == 1) && (parentCategoryIds.length == 1)) {
6473                            return findByNotC_G_P(categoryIds[0], groupId,
6474                                    parentCategoryIds[0], start, end, orderByComparator);
6475                    }
6476    
6477                    boolean pagination = true;
6478                    Object[] finderArgs = null;
6479    
6480                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6481                                    (orderByComparator == null)) {
6482                            pagination = false;
6483                            finderArgs = new Object[] {
6484                                            StringUtil.merge(categoryIds), groupId,
6485                                            StringUtil.merge(parentCategoryIds)
6486                                    };
6487                    }
6488                    else {
6489                            finderArgs = new Object[] {
6490                                            StringUtil.merge(categoryIds), groupId,
6491                                            StringUtil.merge(parentCategoryIds),
6492                                            
6493                                            start, end, orderByComparator
6494                                    };
6495                    }
6496    
6497                    List<MBCategory> list = null;
6498    
6499                    if (retrieveFromCache) {
6500                            list = (List<MBCategory>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P,
6501                                            finderArgs, this);
6502    
6503                            if ((list != null) && !list.isEmpty()) {
6504                                    for (MBCategory mbCategory : list) {
6505                                            if (!ArrayUtil.contains(categoryIds,
6506                                                                    mbCategory.getCategoryId()) ||
6507                                                            (groupId != mbCategory.getGroupId()) ||
6508                                                            !ArrayUtil.contains(parentCategoryIds,
6509                                                                    mbCategory.getParentCategoryId())) {
6510                                                    list = null;
6511    
6512                                                    break;
6513                                            }
6514                                    }
6515                            }
6516                    }
6517    
6518                    if (list == null) {
6519                            StringBundler query = new StringBundler();
6520    
6521                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
6522    
6523                            if (categoryIds.length > 0) {
6524                                    query.append(StringPool.OPEN_PARENTHESIS);
6525    
6526                                    query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_7);
6527    
6528                                    query.append(StringUtil.merge(categoryIds));
6529    
6530                                    query.append(StringPool.CLOSE_PARENTHESIS);
6531    
6532                                    query.append(StringPool.CLOSE_PARENTHESIS);
6533    
6534                                    query.append(WHERE_AND);
6535                            }
6536    
6537                            query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6538    
6539                            if (parentCategoryIds.length > 0) {
6540                                    query.append(StringPool.OPEN_PARENTHESIS);
6541    
6542                                    query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7);
6543    
6544                                    query.append(StringUtil.merge(parentCategoryIds));
6545    
6546                                    query.append(StringPool.CLOSE_PARENTHESIS);
6547    
6548                                    query.append(StringPool.CLOSE_PARENTHESIS);
6549                            }
6550    
6551                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
6552                                                    1)), query.index() - 1);
6553    
6554                            if (orderByComparator != null) {
6555                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6556                                            orderByComparator);
6557                            }
6558                            else
6559                             if (pagination) {
6560                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6561                            }
6562    
6563                            String sql = query.toString();
6564    
6565                            Session session = null;
6566    
6567                            try {
6568                                    session = openSession();
6569    
6570                                    Query q = session.createQuery(sql);
6571    
6572                                    QueryPos qPos = QueryPos.getInstance(q);
6573    
6574                                    qPos.add(groupId);
6575    
6576                                    if (!pagination) {
6577                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6578                                                            start, end, false);
6579    
6580                                            Collections.sort(list);
6581    
6582                                            list = Collections.unmodifiableList(list);
6583                                    }
6584                                    else {
6585                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6586                                                            start, end);
6587                                    }
6588    
6589                                    cacheResult(list);
6590    
6591                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P,
6592                                            finderArgs, list);
6593                            }
6594                            catch (Exception e) {
6595                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P,
6596                                            finderArgs);
6597    
6598                                    throw processException(e);
6599                            }
6600                            finally {
6601                                    closeSession(session);
6602                            }
6603                    }
6604    
6605                    return list;
6606            }
6607    
6608            /**
6609             * Removes all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; from the database.
6610             *
6611             * @param categoryId the category ID
6612             * @param groupId the group ID
6613             * @param parentCategoryId the parent category ID
6614             */
6615            @Override
6616            public void removeByNotC_G_P(long categoryId, long groupId,
6617                    long parentCategoryId) {
6618                    for (MBCategory mbCategory : findByNotC_G_P(categoryId, groupId,
6619                                    parentCategoryId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6620                            remove(mbCategory);
6621                    }
6622            }
6623    
6624            /**
6625             * Returns the number of message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
6626             *
6627             * @param categoryId the category ID
6628             * @param groupId the group ID
6629             * @param parentCategoryId the parent category ID
6630             * @return the number of matching message boards categories
6631             */
6632            @Override
6633            public int countByNotC_G_P(long categoryId, long groupId,
6634                    long parentCategoryId) {
6635                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P;
6636    
6637                    Object[] finderArgs = new Object[] { categoryId, groupId, parentCategoryId };
6638    
6639                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
6640    
6641                    if (count == null) {
6642                            StringBundler query = new StringBundler(4);
6643    
6644                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6645    
6646                            query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_2);
6647    
6648                            query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6649    
6650                            query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2);
6651    
6652                            String sql = query.toString();
6653    
6654                            Session session = null;
6655    
6656                            try {
6657                                    session = openSession();
6658    
6659                                    Query q = session.createQuery(sql);
6660    
6661                                    QueryPos qPos = QueryPos.getInstance(q);
6662    
6663                                    qPos.add(categoryId);
6664    
6665                                    qPos.add(groupId);
6666    
6667                                    qPos.add(parentCategoryId);
6668    
6669                                    count = (Long)q.uniqueResult();
6670    
6671                                    finderCache.putResult(finderPath, finderArgs, count);
6672                            }
6673                            catch (Exception e) {
6674                                    finderCache.removeResult(finderPath, finderArgs);
6675    
6676                                    throw processException(e);
6677                            }
6678                            finally {
6679                                    closeSession(session);
6680                            }
6681                    }
6682    
6683                    return count.intValue();
6684            }
6685    
6686            /**
6687             * Returns the number of message boards categories where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63;.
6688             *
6689             * @param categoryIds the category IDs
6690             * @param groupId the group ID
6691             * @param parentCategoryIds the parent category IDs
6692             * @return the number of matching message boards categories
6693             */
6694            @Override
6695            public int countByNotC_G_P(long[] categoryIds, long groupId,
6696                    long[] parentCategoryIds) {
6697                    if (categoryIds == null) {
6698                            categoryIds = new long[0];
6699                    }
6700                    else if (categoryIds.length > 1) {
6701                            categoryIds = ArrayUtil.unique(categoryIds);
6702    
6703                            Arrays.sort(categoryIds);
6704                    }
6705    
6706                    if (parentCategoryIds == null) {
6707                            parentCategoryIds = new long[0];
6708                    }
6709                    else if (parentCategoryIds.length > 1) {
6710                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
6711    
6712                            Arrays.sort(parentCategoryIds);
6713                    }
6714    
6715                    Object[] finderArgs = new Object[] {
6716                                    StringUtil.merge(categoryIds), groupId,
6717                                    StringUtil.merge(parentCategoryIds)
6718                            };
6719    
6720                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P,
6721                                    finderArgs, this);
6722    
6723                    if (count == null) {
6724                            StringBundler query = new StringBundler();
6725    
6726                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6727    
6728                            if (categoryIds.length > 0) {
6729                                    query.append(StringPool.OPEN_PARENTHESIS);
6730    
6731                                    query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_7);
6732    
6733                                    query.append(StringUtil.merge(categoryIds));
6734    
6735                                    query.append(StringPool.CLOSE_PARENTHESIS);
6736    
6737                                    query.append(StringPool.CLOSE_PARENTHESIS);
6738    
6739                                    query.append(WHERE_AND);
6740                            }
6741    
6742                            query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6743    
6744                            if (parentCategoryIds.length > 0) {
6745                                    query.append(StringPool.OPEN_PARENTHESIS);
6746    
6747                                    query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7);
6748    
6749                                    query.append(StringUtil.merge(parentCategoryIds));
6750    
6751                                    query.append(StringPool.CLOSE_PARENTHESIS);
6752    
6753                                    query.append(StringPool.CLOSE_PARENTHESIS);
6754                            }
6755    
6756                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
6757                                                    1)), query.index() - 1);
6758    
6759                            String sql = query.toString();
6760    
6761                            Session session = null;
6762    
6763                            try {
6764                                    session = openSession();
6765    
6766                                    Query q = session.createQuery(sql);
6767    
6768                                    QueryPos qPos = QueryPos.getInstance(q);
6769    
6770                                    qPos.add(groupId);
6771    
6772                                    count = (Long)q.uniqueResult();
6773    
6774                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P,
6775                                            finderArgs, count);
6776                            }
6777                            catch (Exception e) {
6778                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P,
6779                                            finderArgs);
6780    
6781                                    throw processException(e);
6782                            }
6783                            finally {
6784                                    closeSession(session);
6785                            }
6786                    }
6787    
6788                    return count.intValue();
6789            }
6790    
6791            /**
6792             * Returns the number of message boards categories that the user has permission to view where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63;.
6793             *
6794             * @param categoryId the category ID
6795             * @param groupId the group ID
6796             * @param parentCategoryId the parent category ID
6797             * @return the number of matching message boards categories that the user has permission to view
6798             */
6799            @Override
6800            public int filterCountByNotC_G_P(long categoryId, long groupId,
6801                    long parentCategoryId) {
6802                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6803                            return countByNotC_G_P(categoryId, groupId, parentCategoryId);
6804                    }
6805    
6806                    StringBundler query = new StringBundler(4);
6807    
6808                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
6809    
6810                    query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_2);
6811    
6812                    query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6813    
6814                    query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2);
6815    
6816                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6817                                    MBCategory.class.getName(),
6818                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6819    
6820                    Session session = null;
6821    
6822                    try {
6823                            session = openSession();
6824    
6825                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6826    
6827                            q.addScalar(COUNT_COLUMN_NAME,
6828                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6829    
6830                            QueryPos qPos = QueryPos.getInstance(q);
6831    
6832                            qPos.add(categoryId);
6833    
6834                            qPos.add(groupId);
6835    
6836                            qPos.add(parentCategoryId);
6837    
6838                            Long count = (Long)q.uniqueResult();
6839    
6840                            return count.intValue();
6841                    }
6842                    catch (Exception e) {
6843                            throw processException(e);
6844                    }
6845                    finally {
6846                            closeSession(session);
6847                    }
6848            }
6849    
6850            /**
6851             * Returns the number of message boards categories that the user has permission to view where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63;.
6852             *
6853             * @param categoryIds the category IDs
6854             * @param groupId the group ID
6855             * @param parentCategoryIds the parent category IDs
6856             * @return the number of matching message boards categories that the user has permission to view
6857             */
6858            @Override
6859            public int filterCountByNotC_G_P(long[] categoryIds, long groupId,
6860                    long[] parentCategoryIds) {
6861                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6862                            return countByNotC_G_P(categoryIds, groupId, parentCategoryIds);
6863                    }
6864    
6865                    if (categoryIds == null) {
6866                            categoryIds = new long[0];
6867                    }
6868                    else if (categoryIds.length > 1) {
6869                            categoryIds = ArrayUtil.unique(categoryIds);
6870    
6871                            Arrays.sort(categoryIds);
6872                    }
6873    
6874                    if (parentCategoryIds == null) {
6875                            parentCategoryIds = new long[0];
6876                    }
6877                    else if (parentCategoryIds.length > 1) {
6878                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
6879    
6880                            Arrays.sort(parentCategoryIds);
6881                    }
6882    
6883                    StringBundler query = new StringBundler();
6884    
6885                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
6886    
6887                    if (categoryIds.length > 0) {
6888                            query.append(StringPool.OPEN_PARENTHESIS);
6889    
6890                            query.append(_FINDER_COLUMN_NOTC_G_P_CATEGORYID_7);
6891    
6892                            query.append(StringUtil.merge(categoryIds));
6893    
6894                            query.append(StringPool.CLOSE_PARENTHESIS);
6895    
6896                            query.append(StringPool.CLOSE_PARENTHESIS);
6897    
6898                            query.append(WHERE_AND);
6899                    }
6900    
6901                    query.append(_FINDER_COLUMN_NOTC_G_P_GROUPID_2);
6902    
6903                    if (parentCategoryIds.length > 0) {
6904                            query.append(StringPool.OPEN_PARENTHESIS);
6905    
6906                            query.append(_FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7);
6907    
6908                            query.append(StringUtil.merge(parentCategoryIds));
6909    
6910                            query.append(StringPool.CLOSE_PARENTHESIS);
6911    
6912                            query.append(StringPool.CLOSE_PARENTHESIS);
6913                    }
6914    
6915                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
6916                            query.index() - 1);
6917    
6918                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6919                                    MBCategory.class.getName(),
6920                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6921    
6922                    Session session = null;
6923    
6924                    try {
6925                            session = openSession();
6926    
6927                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
6928    
6929                            q.addScalar(COUNT_COLUMN_NAME,
6930                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6931    
6932                            QueryPos qPos = QueryPos.getInstance(q);
6933    
6934                            qPos.add(groupId);
6935    
6936                            Long count = (Long)q.uniqueResult();
6937    
6938                            return count.intValue();
6939                    }
6940                    catch (Exception e) {
6941                            throw processException(e);
6942                    }
6943                    finally {
6944                            closeSession(session);
6945                    }
6946            }
6947    
6948            private static final String _FINDER_COLUMN_NOTC_G_P_CATEGORYID_2 = "mbCategory.categoryId != ? AND ";
6949            private static final String _FINDER_COLUMN_NOTC_G_P_CATEGORYID_7 = "mbCategory.categoryId NOT IN (";
6950            private static final String _FINDER_COLUMN_NOTC_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
6951            private static final String _FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
6952            private static final String _FINDER_COLUMN_NOTC_G_P_PARENTCATEGORYID_7 = "mbCategory.parentCategoryId IN (";
6953            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
6954                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
6955                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_S",
6956                            new String[] {
6957                                    Long.class.getName(), Long.class.getName(),
6958                                    Integer.class.getName(),
6959                                    
6960                            Integer.class.getName(), Integer.class.getName(),
6961                                    OrderByComparator.class.getName()
6962                            });
6963            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
6964                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
6965                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_S",
6966                            new String[] {
6967                                    Long.class.getName(), Long.class.getName(),
6968                                    Integer.class.getName()
6969                            },
6970                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
6971                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
6972                            MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
6973                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
6974            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
6975                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
6976                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_S",
6977                            new String[] {
6978                                    Long.class.getName(), Long.class.getName(),
6979                                    Integer.class.getName()
6980                            });
6981            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
6982                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
6983                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P_S",
6984                            new String[] {
6985                                    Long.class.getName(), Long.class.getName(),
6986                                    Integer.class.getName()
6987                            });
6988    
6989            /**
6990             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
6991             *
6992             * @param groupId the group ID
6993             * @param parentCategoryId the parent category ID
6994             * @param status the status
6995             * @return the matching message boards categories
6996             */
6997            @Override
6998            public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
6999                    int status) {
7000                    return findByG_P_S(groupId, parentCategoryId, status,
7001                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7002            }
7003    
7004            /**
7005             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7006             *
7007             * <p>
7008             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
7009             * </p>
7010             *
7011             * @param groupId the group ID
7012             * @param parentCategoryId the parent category ID
7013             * @param status the status
7014             * @param start the lower bound of the range of message boards categories
7015             * @param end the upper bound of the range of message boards categories (not inclusive)
7016             * @return the range of matching message boards categories
7017             */
7018            @Override
7019            public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
7020                    int status, int start, int end) {
7021                    return findByG_P_S(groupId, parentCategoryId, status, start, end, null);
7022            }
7023    
7024            /**
7025             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7026             *
7027             * <p>
7028             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
7029             * </p>
7030             *
7031             * @param groupId the group ID
7032             * @param parentCategoryId the parent category ID
7033             * @param status the status
7034             * @param start the lower bound of the range of message boards categories
7035             * @param end the upper bound of the range of message boards categories (not inclusive)
7036             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7037             * @return the ordered range of matching message boards categories
7038             */
7039            @Override
7040            public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
7041                    int status, int start, int end,
7042                    OrderByComparator<MBCategory> orderByComparator) {
7043                    return findByG_P_S(groupId, parentCategoryId, status, start, end,
7044                            orderByComparator, true);
7045            }
7046    
7047            /**
7048             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7049             *
7050             * <p>
7051             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
7052             * </p>
7053             *
7054             * @param groupId the group ID
7055             * @param parentCategoryId the parent category ID
7056             * @param status the status
7057             * @param start the lower bound of the range of message boards categories
7058             * @param end the upper bound of the range of message boards categories (not inclusive)
7059             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7060             * @param retrieveFromCache whether to retrieve from the finder cache
7061             * @return the ordered range of matching message boards categories
7062             */
7063            @Override
7064            public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
7065                    int status, int start, int end,
7066                    OrderByComparator<MBCategory> orderByComparator,
7067                    boolean retrieveFromCache) {
7068                    boolean pagination = true;
7069                    FinderPath finderPath = null;
7070                    Object[] finderArgs = null;
7071    
7072                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7073                                    (orderByComparator == null)) {
7074                            pagination = false;
7075                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S;
7076                            finderArgs = new Object[] { groupId, parentCategoryId, status };
7077                    }
7078                    else {
7079                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S;
7080                            finderArgs = new Object[] {
7081                                            groupId, parentCategoryId, status,
7082                                            
7083                                            start, end, orderByComparator
7084                                    };
7085                    }
7086    
7087                    List<MBCategory> list = null;
7088    
7089                    if (retrieveFromCache) {
7090                            list = (List<MBCategory>)finderCache.getResult(finderPath,
7091                                            finderArgs, this);
7092    
7093                            if ((list != null) && !list.isEmpty()) {
7094                                    for (MBCategory mbCategory : list) {
7095                                            if ((groupId != mbCategory.getGroupId()) ||
7096                                                            (parentCategoryId != mbCategory.getParentCategoryId()) ||
7097                                                            (status != mbCategory.getStatus())) {
7098                                                    list = null;
7099    
7100                                                    break;
7101                                            }
7102                                    }
7103                            }
7104                    }
7105    
7106                    if (list == null) {
7107                            StringBundler query = null;
7108    
7109                            if (orderByComparator != null) {
7110                                    query = new StringBundler(5 +
7111                                                    (orderByComparator.getOrderByFields().length * 3));
7112                            }
7113                            else {
7114                                    query = new StringBundler(5);
7115                            }
7116    
7117                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
7118    
7119                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7120    
7121                            query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
7122    
7123                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7124    
7125                            if (orderByComparator != null) {
7126                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7127                                            orderByComparator);
7128                            }
7129                            else
7130                             if (pagination) {
7131                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7132                            }
7133    
7134                            String sql = query.toString();
7135    
7136                            Session session = null;
7137    
7138                            try {
7139                                    session = openSession();
7140    
7141                                    Query q = session.createQuery(sql);
7142    
7143                                    QueryPos qPos = QueryPos.getInstance(q);
7144    
7145                                    qPos.add(groupId);
7146    
7147                                    qPos.add(parentCategoryId);
7148    
7149                                    qPos.add(status);
7150    
7151                                    if (!pagination) {
7152                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7153                                                            start, end, false);
7154    
7155                                            Collections.sort(list);
7156    
7157                                            list = Collections.unmodifiableList(list);
7158                                    }
7159                                    else {
7160                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7161                                                            start, end);
7162                                    }
7163    
7164                                    cacheResult(list);
7165    
7166                                    finderCache.putResult(finderPath, finderArgs, list);
7167                            }
7168                            catch (Exception e) {
7169                                    finderCache.removeResult(finderPath, finderArgs);
7170    
7171                                    throw processException(e);
7172                            }
7173                            finally {
7174                                    closeSession(session);
7175                            }
7176                    }
7177    
7178                    return list;
7179            }
7180    
7181            /**
7182             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7183             *
7184             * @param groupId the group ID
7185             * @param parentCategoryId the parent category ID
7186             * @param status the status
7187             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7188             * @return the first matching message boards category
7189             * @throws NoSuchCategoryException if a matching message boards category could not be found
7190             */
7191            @Override
7192            public MBCategory findByG_P_S_First(long groupId, long parentCategoryId,
7193                    int status, OrderByComparator<MBCategory> orderByComparator)
7194                    throws NoSuchCategoryException {
7195                    MBCategory mbCategory = fetchByG_P_S_First(groupId, parentCategoryId,
7196                                    status, orderByComparator);
7197    
7198                    if (mbCategory != null) {
7199                            return mbCategory;
7200                    }
7201    
7202                    StringBundler msg = new StringBundler(8);
7203    
7204                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7205    
7206                    msg.append("groupId=");
7207                    msg.append(groupId);
7208    
7209                    msg.append(", parentCategoryId=");
7210                    msg.append(parentCategoryId);
7211    
7212                    msg.append(", status=");
7213                    msg.append(status);
7214    
7215                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7216    
7217                    throw new NoSuchCategoryException(msg.toString());
7218            }
7219    
7220            /**
7221             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7222             *
7223             * @param groupId the group ID
7224             * @param parentCategoryId the parent category ID
7225             * @param status the status
7226             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7227             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
7228             */
7229            @Override
7230            public MBCategory fetchByG_P_S_First(long groupId, long parentCategoryId,
7231                    int status, OrderByComparator<MBCategory> orderByComparator) {
7232                    List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
7233                                    0, 1, orderByComparator);
7234    
7235                    if (!list.isEmpty()) {
7236                            return list.get(0);
7237                    }
7238    
7239                    return null;
7240            }
7241    
7242            /**
7243             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7244             *
7245             * @param groupId the group ID
7246             * @param parentCategoryId the parent category ID
7247             * @param status the status
7248             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7249             * @return the last matching message boards category
7250             * @throws NoSuchCategoryException if a matching message boards category could not be found
7251             */
7252            @Override
7253            public MBCategory findByG_P_S_Last(long groupId, long parentCategoryId,
7254                    int status, OrderByComparator<MBCategory> orderByComparator)
7255                    throws NoSuchCategoryException {
7256                    MBCategory mbCategory = fetchByG_P_S_Last(groupId, parentCategoryId,
7257                                    status, orderByComparator);
7258    
7259                    if (mbCategory != null) {
7260                            return mbCategory;
7261                    }
7262    
7263                    StringBundler msg = new StringBundler(8);
7264    
7265                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7266    
7267                    msg.append("groupId=");
7268                    msg.append(groupId);
7269    
7270                    msg.append(", parentCategoryId=");
7271                    msg.append(parentCategoryId);
7272    
7273                    msg.append(", status=");
7274                    msg.append(status);
7275    
7276                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7277    
7278                    throw new NoSuchCategoryException(msg.toString());
7279            }
7280    
7281            /**
7282             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7283             *
7284             * @param groupId the group ID
7285             * @param parentCategoryId the parent category ID
7286             * @param status the status
7287             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7288             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
7289             */
7290            @Override
7291            public MBCategory fetchByG_P_S_Last(long groupId, long parentCategoryId,
7292                    int status, OrderByComparator<MBCategory> orderByComparator) {
7293                    int count = countByG_P_S(groupId, parentCategoryId, status);
7294    
7295                    if (count == 0) {
7296                            return null;
7297                    }
7298    
7299                    List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
7300                                    count - 1, count, orderByComparator);
7301    
7302                    if (!list.isEmpty()) {
7303                            return list.get(0);
7304                    }
7305    
7306                    return null;
7307            }
7308    
7309            /**
7310             * Returns the message boards categories before and after the current message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7311             *
7312             * @param categoryId the primary key of the current message boards category
7313             * @param groupId the group ID
7314             * @param parentCategoryId the parent category ID
7315             * @param status the status
7316             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7317             * @return the previous, current, and next message boards category
7318             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
7319             */
7320            @Override
7321            public MBCategory[] findByG_P_S_PrevAndNext(long categoryId, long groupId,
7322                    long parentCategoryId, int status,
7323                    OrderByComparator<MBCategory> orderByComparator)
7324                    throws NoSuchCategoryException {
7325                    MBCategory mbCategory = findByPrimaryKey(categoryId);
7326    
7327                    Session session = null;
7328    
7329                    try {
7330                            session = openSession();
7331    
7332                            MBCategory[] array = new MBCategoryImpl[3];
7333    
7334                            array[0] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
7335                                            parentCategoryId, status, orderByComparator, true);
7336    
7337                            array[1] = mbCategory;
7338    
7339                            array[2] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
7340                                            parentCategoryId, status, orderByComparator, false);
7341    
7342                            return array;
7343                    }
7344                    catch (Exception e) {
7345                            throw processException(e);
7346                    }
7347                    finally {
7348                            closeSession(session);
7349                    }
7350            }
7351    
7352            protected MBCategory getByG_P_S_PrevAndNext(Session session,
7353                    MBCategory mbCategory, long groupId, long parentCategoryId, int status,
7354                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
7355                    StringBundler query = null;
7356    
7357                    if (orderByComparator != null) {
7358                            query = new StringBundler(6 +
7359                                            (orderByComparator.getOrderByFields().length * 6));
7360                    }
7361                    else {
7362                            query = new StringBundler(3);
7363                    }
7364    
7365                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
7366    
7367                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7368    
7369                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
7370    
7371                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7372    
7373                    if (orderByComparator != null) {
7374                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7375    
7376                            if (orderByConditionFields.length > 0) {
7377                                    query.append(WHERE_AND);
7378                            }
7379    
7380                            for (int i = 0; i < orderByConditionFields.length; i++) {
7381                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7382                                    query.append(orderByConditionFields[i]);
7383    
7384                                    if ((i + 1) < orderByConditionFields.length) {
7385                                            if (orderByComparator.isAscending() ^ previous) {
7386                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7387                                            }
7388                                            else {
7389                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7390                                            }
7391                                    }
7392                                    else {
7393                                            if (orderByComparator.isAscending() ^ previous) {
7394                                                    query.append(WHERE_GREATER_THAN);
7395                                            }
7396                                            else {
7397                                                    query.append(WHERE_LESSER_THAN);
7398                                            }
7399                                    }
7400                            }
7401    
7402                            query.append(ORDER_BY_CLAUSE);
7403    
7404                            String[] orderByFields = orderByComparator.getOrderByFields();
7405    
7406                            for (int i = 0; i < orderByFields.length; i++) {
7407                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7408                                    query.append(orderByFields[i]);
7409    
7410                                    if ((i + 1) < orderByFields.length) {
7411                                            if (orderByComparator.isAscending() ^ previous) {
7412                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7413                                            }
7414                                            else {
7415                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7416                                            }
7417                                    }
7418                                    else {
7419                                            if (orderByComparator.isAscending() ^ previous) {
7420                                                    query.append(ORDER_BY_ASC);
7421                                            }
7422                                            else {
7423                                                    query.append(ORDER_BY_DESC);
7424                                            }
7425                                    }
7426                            }
7427                    }
7428                    else {
7429                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7430                    }
7431    
7432                    String sql = query.toString();
7433    
7434                    Query q = session.createQuery(sql);
7435    
7436                    q.setFirstResult(0);
7437                    q.setMaxResults(2);
7438    
7439                    QueryPos qPos = QueryPos.getInstance(q);
7440    
7441                    qPos.add(groupId);
7442    
7443                    qPos.add(parentCategoryId);
7444    
7445                    qPos.add(status);
7446    
7447                    if (orderByComparator != null) {
7448                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
7449    
7450                            for (Object value : values) {
7451                                    qPos.add(value);
7452                            }
7453                    }
7454    
7455                    List<MBCategory> list = q.list();
7456    
7457                    if (list.size() == 2) {
7458                            return list.get(1);
7459                    }
7460                    else {
7461                            return null;
7462                    }
7463            }
7464    
7465            /**
7466             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7467             *
7468             * @param groupId the group ID
7469             * @param parentCategoryId the parent category ID
7470             * @param status the status
7471             * @return the matching message boards categories that the user has permission to view
7472             */
7473            @Override
7474            public List<MBCategory> filterFindByG_P_S(long groupId,
7475                    long parentCategoryId, int status) {
7476                    return filterFindByG_P_S(groupId, parentCategoryId, status,
7477                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7478            }
7479    
7480            /**
7481             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7482             *
7483             * <p>
7484             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
7485             * </p>
7486             *
7487             * @param groupId the group ID
7488             * @param parentCategoryId the parent category ID
7489             * @param status the status
7490             * @param start the lower bound of the range of message boards categories
7491             * @param end the upper bound of the range of message boards categories (not inclusive)
7492             * @return the range of matching message boards categories that the user has permission to view
7493             */
7494            @Override
7495            public List<MBCategory> filterFindByG_P_S(long groupId,
7496                    long parentCategoryId, int status, int start, int end) {
7497                    return filterFindByG_P_S(groupId, parentCategoryId, status, start, end,
7498                            null);
7499            }
7500    
7501            /**
7502             * Returns an ordered range of all the message boards categories that the user has permissions to view where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7503             *
7504             * <p>
7505             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
7506             * </p>
7507             *
7508             * @param groupId the group ID
7509             * @param parentCategoryId the parent category ID
7510             * @param status the status
7511             * @param start the lower bound of the range of message boards categories
7512             * @param end the upper bound of the range of message boards categories (not inclusive)
7513             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7514             * @return the ordered range of matching message boards categories that the user has permission to view
7515             */
7516            @Override
7517            public List<MBCategory> filterFindByG_P_S(long groupId,
7518                    long parentCategoryId, int status, int start, int end,
7519                    OrderByComparator<MBCategory> orderByComparator) {
7520                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7521                            return findByG_P_S(groupId, parentCategoryId, status, start, end,
7522                                    orderByComparator);
7523                    }
7524    
7525                    StringBundler query = null;
7526    
7527                    if (orderByComparator != null) {
7528                            query = new StringBundler(5 +
7529                                            (orderByComparator.getOrderByFields().length * 3));
7530                    }
7531                    else {
7532                            query = new StringBundler(5);
7533                    }
7534    
7535                    if (getDB().isSupportsInlineDistinct()) {
7536                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
7537                    }
7538                    else {
7539                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7540                    }
7541    
7542                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7543    
7544                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
7545    
7546                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7547    
7548                    if (!getDB().isSupportsInlineDistinct()) {
7549                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7550                    }
7551    
7552                    if (orderByComparator != null) {
7553                            if (getDB().isSupportsInlineDistinct()) {
7554                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7555                                            orderByComparator, true);
7556                            }
7557                            else {
7558                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7559                                            orderByComparator, true);
7560                            }
7561                    }
7562                    else {
7563                            if (getDB().isSupportsInlineDistinct()) {
7564                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7565                            }
7566                            else {
7567                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
7568                            }
7569                    }
7570    
7571                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7572                                    MBCategory.class.getName(),
7573                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7574    
7575                    Session session = null;
7576    
7577                    try {
7578                            session = openSession();
7579    
7580                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7581    
7582                            if (getDB().isSupportsInlineDistinct()) {
7583                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
7584                            }
7585                            else {
7586                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
7587                            }
7588    
7589                            QueryPos qPos = QueryPos.getInstance(q);
7590    
7591                            qPos.add(groupId);
7592    
7593                            qPos.add(parentCategoryId);
7594    
7595                            qPos.add(status);
7596    
7597                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
7598                    }
7599                    catch (Exception e) {
7600                            throw processException(e);
7601                    }
7602                    finally {
7603                            closeSession(session);
7604                    }
7605            }
7606    
7607            /**
7608             * Returns the message boards categories before and after the current message boards category in the ordered set of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7609             *
7610             * @param categoryId the primary key of the current message boards category
7611             * @param groupId the group ID
7612             * @param parentCategoryId the parent category ID
7613             * @param status the status
7614             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7615             * @return the previous, current, and next message boards category
7616             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
7617             */
7618            @Override
7619            public MBCategory[] filterFindByG_P_S_PrevAndNext(long categoryId,
7620                    long groupId, long parentCategoryId, int status,
7621                    OrderByComparator<MBCategory> orderByComparator)
7622                    throws NoSuchCategoryException {
7623                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7624                            return findByG_P_S_PrevAndNext(categoryId, groupId,
7625                                    parentCategoryId, status, orderByComparator);
7626                    }
7627    
7628                    MBCategory mbCategory = findByPrimaryKey(categoryId);
7629    
7630                    Session session = null;
7631    
7632                    try {
7633                            session = openSession();
7634    
7635                            MBCategory[] array = new MBCategoryImpl[3];
7636    
7637                            array[0] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
7638                                            groupId, parentCategoryId, status, orderByComparator, true);
7639    
7640                            array[1] = mbCategory;
7641    
7642                            array[2] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
7643                                            groupId, parentCategoryId, status, orderByComparator, false);
7644    
7645                            return array;
7646                    }
7647                    catch (Exception e) {
7648                            throw processException(e);
7649                    }
7650                    finally {
7651                            closeSession(session);
7652                    }
7653            }
7654    
7655            protected MBCategory filterGetByG_P_S_PrevAndNext(Session session,
7656                    MBCategory mbCategory, long groupId, long parentCategoryId, int status,
7657                    OrderByComparator<MBCategory> orderByComparator, boolean previous) {
7658                    StringBundler query = null;
7659    
7660                    if (orderByComparator != null) {
7661                            query = new StringBundler(6 +
7662                                            (orderByComparator.getOrderByFields().length * 6));
7663                    }
7664                    else {
7665                            query = new StringBundler(3);
7666                    }
7667    
7668                    if (getDB().isSupportsInlineDistinct()) {
7669                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
7670                    }
7671                    else {
7672                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7673                    }
7674    
7675                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7676    
7677                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
7678    
7679                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7680    
7681                    if (!getDB().isSupportsInlineDistinct()) {
7682                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7683                    }
7684    
7685                    if (orderByComparator != null) {
7686                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7687    
7688                            if (orderByConditionFields.length > 0) {
7689                                    query.append(WHERE_AND);
7690                            }
7691    
7692                            for (int i = 0; i < orderByConditionFields.length; i++) {
7693                                    if (getDB().isSupportsInlineDistinct()) {
7694                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7695                                    }
7696                                    else {
7697                                            query.append(_ORDER_BY_ENTITY_TABLE);
7698                                    }
7699    
7700                                    query.append(orderByConditionFields[i]);
7701    
7702                                    if ((i + 1) < orderByConditionFields.length) {
7703                                            if (orderByComparator.isAscending() ^ previous) {
7704                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7705                                            }
7706                                            else {
7707                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7708                                            }
7709                                    }
7710                                    else {
7711                                            if (orderByComparator.isAscending() ^ previous) {
7712                                                    query.append(WHERE_GREATER_THAN);
7713                                            }
7714                                            else {
7715                                                    query.append(WHERE_LESSER_THAN);
7716                                            }
7717                                    }
7718                            }
7719    
7720                            query.append(ORDER_BY_CLAUSE);
7721    
7722                            String[] orderByFields = orderByComparator.getOrderByFields();
7723    
7724                            for (int i = 0; i < orderByFields.length; i++) {
7725                                    if (getDB().isSupportsInlineDistinct()) {
7726                                            query.append(_ORDER_BY_ENTITY_ALIAS);
7727                                    }
7728                                    else {
7729                                            query.append(_ORDER_BY_ENTITY_TABLE);
7730                                    }
7731    
7732                                    query.append(orderByFields[i]);
7733    
7734                                    if ((i + 1) < orderByFields.length) {
7735                                            if (orderByComparator.isAscending() ^ previous) {
7736                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7737                                            }
7738                                            else {
7739                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7740                                            }
7741                                    }
7742                                    else {
7743                                            if (orderByComparator.isAscending() ^ previous) {
7744                                                    query.append(ORDER_BY_ASC);
7745                                            }
7746                                            else {
7747                                                    query.append(ORDER_BY_DESC);
7748                                            }
7749                                    }
7750                            }
7751                    }
7752                    else {
7753                            if (getDB().isSupportsInlineDistinct()) {
7754                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7755                            }
7756                            else {
7757                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
7758                            }
7759                    }
7760    
7761                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7762                                    MBCategory.class.getName(),
7763                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7764    
7765                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
7766    
7767                    q.setFirstResult(0);
7768                    q.setMaxResults(2);
7769    
7770                    if (getDB().isSupportsInlineDistinct()) {
7771                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
7772                    }
7773                    else {
7774                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
7775                    }
7776    
7777                    QueryPos qPos = QueryPos.getInstance(q);
7778    
7779                    qPos.add(groupId);
7780    
7781                    qPos.add(parentCategoryId);
7782    
7783                    qPos.add(status);
7784    
7785                    if (orderByComparator != null) {
7786                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
7787    
7788                            for (Object value : values) {
7789                                    qPos.add(value);
7790                            }
7791                    }
7792    
7793                    List<MBCategory> list = q.list();
7794    
7795                    if (list.size() == 2) {
7796                            return list.get(1);
7797                    }
7798                    else {
7799                            return null;
7800                    }
7801            }
7802    
7803            /**
7804             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
7805             *
7806             * @param groupId the group ID
7807             * @param parentCategoryIds the parent category IDs
7808             * @param status the status
7809             * @return the matching message boards categories that the user has permission to view
7810             */
7811            @Override
7812            public List<MBCategory> filterFindByG_P_S(long groupId,
7813                    long[] parentCategoryIds, int status) {
7814                    return filterFindByG_P_S(groupId, parentCategoryIds, status,
7815                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7816            }
7817    
7818            /**
7819             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
7820             *
7821             * <p>
7822             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
7823             * </p>
7824             *
7825             * @param groupId the group ID
7826             * @param parentCategoryIds the parent category IDs
7827             * @param status the status
7828             * @param start the lower bound of the range of message boards categories
7829             * @param end the upper bound of the range of message boards categories (not inclusive)
7830             * @return the range of matching message boards categories that the user has permission to view
7831             */
7832            @Override
7833            public List<MBCategory> filterFindByG_P_S(long groupId,
7834                    long[] parentCategoryIds, int status, int start, int end) {
7835                    return filterFindByG_P_S(groupId, parentCategoryIds, status, start,
7836                            end, null);
7837            }
7838    
7839            /**
7840             * Returns an ordered range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
7841             *
7842             * <p>
7843             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
7844             * </p>
7845             *
7846             * @param groupId the group ID
7847             * @param parentCategoryIds the parent category IDs
7848             * @param status the status
7849             * @param start the lower bound of the range of message boards categories
7850             * @param end the upper bound of the range of message boards categories (not inclusive)
7851             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7852             * @return the ordered range of matching message boards categories that the user has permission to view
7853             */
7854            @Override
7855            public List<MBCategory> filterFindByG_P_S(long groupId,
7856                    long[] parentCategoryIds, int status, int start, int end,
7857                    OrderByComparator<MBCategory> orderByComparator) {
7858                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7859                            return findByG_P_S(groupId, parentCategoryIds, status, start, end,
7860                                    orderByComparator);
7861                    }
7862    
7863                    if (parentCategoryIds == null) {
7864                            parentCategoryIds = new long[0];
7865                    }
7866                    else if (parentCategoryIds.length > 1) {
7867                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
7868    
7869                            Arrays.sort(parentCategoryIds);
7870                    }
7871    
7872                    StringBundler query = new StringBundler();
7873    
7874                    if (getDB().isSupportsInlineDistinct()) {
7875                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
7876                    }
7877                    else {
7878                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
7879                    }
7880    
7881                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7882    
7883                    if (parentCategoryIds.length > 0) {
7884                            query.append(StringPool.OPEN_PARENTHESIS);
7885    
7886                            query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7);
7887    
7888                            query.append(StringUtil.merge(parentCategoryIds));
7889    
7890                            query.append(StringPool.CLOSE_PARENTHESIS);
7891    
7892                            query.append(StringPool.CLOSE_PARENTHESIS);
7893    
7894                            query.append(WHERE_AND);
7895                    }
7896    
7897                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7898    
7899                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
7900                            query.index() - 1);
7901    
7902                    if (!getDB().isSupportsInlineDistinct()) {
7903                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
7904                    }
7905    
7906                    if (orderByComparator != null) {
7907                            if (getDB().isSupportsInlineDistinct()) {
7908                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7909                                            orderByComparator, true);
7910                            }
7911                            else {
7912                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
7913                                            orderByComparator, true);
7914                            }
7915                    }
7916                    else {
7917                            if (getDB().isSupportsInlineDistinct()) {
7918                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
7919                            }
7920                            else {
7921                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
7922                            }
7923                    }
7924    
7925                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7926                                    MBCategory.class.getName(),
7927                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7928    
7929                    Session session = null;
7930    
7931                    try {
7932                            session = openSession();
7933    
7934                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
7935    
7936                            if (getDB().isSupportsInlineDistinct()) {
7937                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
7938                            }
7939                            else {
7940                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
7941                            }
7942    
7943                            QueryPos qPos = QueryPos.getInstance(q);
7944    
7945                            qPos.add(groupId);
7946    
7947                            qPos.add(status);
7948    
7949                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
7950                    }
7951                    catch (Exception e) {
7952                            throw processException(e);
7953                    }
7954                    finally {
7955                            closeSession(session);
7956                    }
7957            }
7958    
7959            /**
7960             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
7961             *
7962             * <p>
7963             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
7964             * </p>
7965             *
7966             * @param groupId the group ID
7967             * @param parentCategoryIds the parent category IDs
7968             * @param status the status
7969             * @return the matching message boards categories
7970             */
7971            @Override
7972            public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
7973                    int status) {
7974                    return findByG_P_S(groupId, parentCategoryIds, status,
7975                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7976            }
7977    
7978            /**
7979             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
7980             *
7981             * <p>
7982             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
7983             * </p>
7984             *
7985             * @param groupId the group ID
7986             * @param parentCategoryIds the parent category IDs
7987             * @param status the status
7988             * @param start the lower bound of the range of message boards categories
7989             * @param end the upper bound of the range of message boards categories (not inclusive)
7990             * @return the range of matching message boards categories
7991             */
7992            @Override
7993            public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
7994                    int status, int start, int end) {
7995                    return findByG_P_S(groupId, parentCategoryIds, status, start, end, null);
7996            }
7997    
7998            /**
7999             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
8000             *
8001             * <p>
8002             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
8003             * </p>
8004             *
8005             * @param groupId the group ID
8006             * @param parentCategoryIds the parent category IDs
8007             * @param status the status
8008             * @param start the lower bound of the range of message boards categories
8009             * @param end the upper bound of the range of message boards categories (not inclusive)
8010             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8011             * @return the ordered range of matching message boards categories
8012             */
8013            @Override
8014            public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
8015                    int status, int start, int end,
8016                    OrderByComparator<MBCategory> orderByComparator) {
8017                    return findByG_P_S(groupId, parentCategoryIds, status, start, end,
8018                            orderByComparator, true);
8019            }
8020    
8021            /**
8022             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;, optionally using the finder cache.
8023             *
8024             * <p>
8025             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
8026             * </p>
8027             *
8028             * @param groupId the group ID
8029             * @param parentCategoryId the parent category ID
8030             * @param status the status
8031             * @param start the lower bound of the range of message boards categories
8032             * @param end the upper bound of the range of message boards categories (not inclusive)
8033             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8034             * @param retrieveFromCache whether to retrieve from the finder cache
8035             * @return the ordered range of matching message boards categories
8036             */
8037            @Override
8038            public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
8039                    int status, int start, int end,
8040                    OrderByComparator<MBCategory> orderByComparator,
8041                    boolean retrieveFromCache) {
8042                    if (parentCategoryIds == null) {
8043                            parentCategoryIds = new long[0];
8044                    }
8045                    else if (parentCategoryIds.length > 1) {
8046                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
8047    
8048                            Arrays.sort(parentCategoryIds);
8049                    }
8050    
8051                    if (parentCategoryIds.length == 1) {
8052                            return findByG_P_S(groupId, parentCategoryIds[0], status, start,
8053                                    end, orderByComparator);
8054                    }
8055    
8056                    boolean pagination = true;
8057                    Object[] finderArgs = null;
8058    
8059                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8060                                    (orderByComparator == null)) {
8061                            pagination = false;
8062                            finderArgs = new Object[] {
8063                                            groupId, StringUtil.merge(parentCategoryIds), status
8064                                    };
8065                    }
8066                    else {
8067                            finderArgs = new Object[] {
8068                                            groupId, StringUtil.merge(parentCategoryIds), status,
8069                                            
8070                                            start, end, orderByComparator
8071                                    };
8072                    }
8073    
8074                    List<MBCategory> list = null;
8075    
8076                    if (retrieveFromCache) {
8077                            list = (List<MBCategory>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
8078                                            finderArgs, this);
8079    
8080                            if ((list != null) && !list.isEmpty()) {
8081                                    for (MBCategory mbCategory : list) {
8082                                            if ((groupId != mbCategory.getGroupId()) ||
8083                                                            !ArrayUtil.contains(parentCategoryIds,
8084                                                                    mbCategory.getParentCategoryId()) ||
8085                                                            (status != mbCategory.getStatus())) {
8086                                                    list = null;
8087    
8088                                                    break;
8089                                            }
8090                                    }
8091                            }
8092                    }
8093    
8094                    if (list == null) {
8095                            StringBundler query = new StringBundler();
8096    
8097                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
8098    
8099                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
8100    
8101                            if (parentCategoryIds.length > 0) {
8102                                    query.append(StringPool.OPEN_PARENTHESIS);
8103    
8104                                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7);
8105    
8106                                    query.append(StringUtil.merge(parentCategoryIds));
8107    
8108                                    query.append(StringPool.CLOSE_PARENTHESIS);
8109    
8110                                    query.append(StringPool.CLOSE_PARENTHESIS);
8111    
8112                                    query.append(WHERE_AND);
8113                            }
8114    
8115                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
8116    
8117                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8118                                                    1)), query.index() - 1);
8119    
8120                            if (orderByComparator != null) {
8121                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8122                                            orderByComparator);
8123                            }
8124                            else
8125                             if (pagination) {
8126                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
8127                            }
8128    
8129                            String sql = query.toString();
8130    
8131                            Session session = null;
8132    
8133                            try {
8134                                    session = openSession();
8135    
8136                                    Query q = session.createQuery(sql);
8137    
8138                                    QueryPos qPos = QueryPos.getInstance(q);
8139    
8140                                    qPos.add(groupId);
8141    
8142                                    qPos.add(status);
8143    
8144                                    if (!pagination) {
8145                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
8146                                                            start, end, false);
8147    
8148                                            Collections.sort(list);
8149    
8150                                            list = Collections.unmodifiableList(list);
8151                                    }
8152                                    else {
8153                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
8154                                                            start, end);
8155                                    }
8156    
8157                                    cacheResult(list);
8158    
8159                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
8160                                            finderArgs, list);
8161                            }
8162                            catch (Exception e) {
8163                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
8164                                            finderArgs);
8165    
8166                                    throw processException(e);
8167                            }
8168                            finally {
8169                                    closeSession(session);
8170                            }
8171                    }
8172    
8173                    return list;
8174            }
8175    
8176            /**
8177             * Removes all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63; from the database.
8178             *
8179             * @param groupId the group ID
8180             * @param parentCategoryId the parent category ID
8181             * @param status the status
8182             */
8183            @Override
8184            public void removeByG_P_S(long groupId, long parentCategoryId, int status) {
8185                    for (MBCategory mbCategory : findByG_P_S(groupId, parentCategoryId,
8186                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8187                            remove(mbCategory);
8188                    }
8189            }
8190    
8191            /**
8192             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8193             *
8194             * @param groupId the group ID
8195             * @param parentCategoryId the parent category ID
8196             * @param status the status
8197             * @return the number of matching message boards categories
8198             */
8199            @Override
8200            public int countByG_P_S(long groupId, long parentCategoryId, int status) {
8201                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_S;
8202    
8203                    Object[] finderArgs = new Object[] { groupId, parentCategoryId, status };
8204    
8205                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
8206    
8207                    if (count == null) {
8208                            StringBundler query = new StringBundler(4);
8209    
8210                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
8211    
8212                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
8213    
8214                            query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
8215    
8216                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
8217    
8218                            String sql = query.toString();
8219    
8220                            Session session = null;
8221    
8222                            try {
8223                                    session = openSession();
8224    
8225                                    Query q = session.createQuery(sql);
8226    
8227                                    QueryPos qPos = QueryPos.getInstance(q);
8228    
8229                                    qPos.add(groupId);
8230    
8231                                    qPos.add(parentCategoryId);
8232    
8233                                    qPos.add(status);
8234    
8235                                    count = (Long)q.uniqueResult();
8236    
8237                                    finderCache.putResult(finderPath, finderArgs, count);
8238                            }
8239                            catch (Exception e) {
8240                                    finderCache.removeResult(finderPath, finderArgs);
8241    
8242                                    throw processException(e);
8243                            }
8244                            finally {
8245                                    closeSession(session);
8246                            }
8247                    }
8248    
8249                    return count.intValue();
8250            }
8251    
8252            /**
8253             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
8254             *
8255             * @param groupId the group ID
8256             * @param parentCategoryIds the parent category IDs
8257             * @param status the status
8258             * @return the number of matching message boards categories
8259             */
8260            @Override
8261            public int countByG_P_S(long groupId, long[] parentCategoryIds, int status) {
8262                    if (parentCategoryIds == null) {
8263                            parentCategoryIds = new long[0];
8264                    }
8265                    else if (parentCategoryIds.length > 1) {
8266                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
8267    
8268                            Arrays.sort(parentCategoryIds);
8269                    }
8270    
8271                    Object[] finderArgs = new Object[] {
8272                                    groupId, StringUtil.merge(parentCategoryIds), status
8273                            };
8274    
8275                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
8276                                    finderArgs, this);
8277    
8278                    if (count == null) {
8279                            StringBundler query = new StringBundler();
8280    
8281                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
8282    
8283                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
8284    
8285                            if (parentCategoryIds.length > 0) {
8286                                    query.append(StringPool.OPEN_PARENTHESIS);
8287    
8288                                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7);
8289    
8290                                    query.append(StringUtil.merge(parentCategoryIds));
8291    
8292                                    query.append(StringPool.CLOSE_PARENTHESIS);
8293    
8294                                    query.append(StringPool.CLOSE_PARENTHESIS);
8295    
8296                                    query.append(WHERE_AND);
8297                            }
8298    
8299                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
8300    
8301                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
8302                                                    1)), query.index() - 1);
8303    
8304                            String sql = query.toString();
8305    
8306                            Session session = null;
8307    
8308                            try {
8309                                    session = openSession();
8310    
8311                                    Query q = session.createQuery(sql);
8312    
8313                                    QueryPos qPos = QueryPos.getInstance(q);
8314    
8315                                    qPos.add(groupId);
8316    
8317                                    qPos.add(status);
8318    
8319                                    count = (Long)q.uniqueResult();
8320    
8321                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
8322                                            finderArgs, count);
8323                            }
8324                            catch (Exception e) {
8325                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
8326                                            finderArgs);
8327    
8328                                    throw processException(e);
8329                            }
8330                            finally {
8331                                    closeSession(session);
8332                            }
8333                    }
8334    
8335                    return count.intValue();
8336            }
8337    
8338            /**
8339             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8340             *
8341             * @param groupId the group ID
8342             * @param parentCategoryId the parent category ID
8343             * @param status the status
8344             * @return the number of matching message boards categories that the user has permission to view
8345             */
8346            @Override
8347            public int filterCountByG_P_S(long groupId, long parentCategoryId,
8348                    int status) {
8349                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8350                            return countByG_P_S(groupId, parentCategoryId, status);
8351                    }
8352    
8353                    StringBundler query = new StringBundler(4);
8354    
8355                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
8356    
8357                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
8358    
8359                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
8360    
8361                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
8362    
8363                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8364                                    MBCategory.class.getName(),
8365                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8366    
8367                    Session session = null;
8368    
8369                    try {
8370                            session = openSession();
8371    
8372                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8373    
8374                            q.addScalar(COUNT_COLUMN_NAME,
8375                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8376    
8377                            QueryPos qPos = QueryPos.getInstance(q);
8378    
8379                            qPos.add(groupId);
8380    
8381                            qPos.add(parentCategoryId);
8382    
8383                            qPos.add(status);
8384    
8385                            Long count = (Long)q.uniqueResult();
8386    
8387                            return count.intValue();
8388                    }
8389                    catch (Exception e) {
8390                            throw processException(e);
8391                    }
8392                    finally {
8393                            closeSession(session);
8394                    }
8395            }
8396    
8397            /**
8398             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
8399             *
8400             * @param groupId the group ID
8401             * @param parentCategoryIds the parent category IDs
8402             * @param status the status
8403             * @return the number of matching message boards categories that the user has permission to view
8404             */
8405            @Override
8406            public int filterCountByG_P_S(long groupId, long[] parentCategoryIds,
8407                    int status) {
8408                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8409                            return countByG_P_S(groupId, parentCategoryIds, status);
8410                    }
8411    
8412                    if (parentCategoryIds == null) {
8413                            parentCategoryIds = new long[0];
8414                    }
8415                    else if (parentCategoryIds.length > 1) {
8416                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
8417    
8418                            Arrays.sort(parentCategoryIds);
8419                    }
8420    
8421                    StringBundler query = new StringBundler();
8422    
8423                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
8424    
8425                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
8426    
8427                    if (parentCategoryIds.length > 0) {
8428                            query.append(StringPool.OPEN_PARENTHESIS);
8429    
8430                            query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7);
8431    
8432                            query.append(StringUtil.merge(parentCategoryIds));
8433    
8434                            query.append(StringPool.CLOSE_PARENTHESIS);
8435    
8436                            query.append(StringPool.CLOSE_PARENTHESIS);
8437    
8438                            query.append(WHERE_AND);
8439                    }
8440    
8441                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
8442    
8443                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
8444                            query.index() - 1);
8445    
8446                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8447                                    MBCategory.class.getName(),
8448                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8449    
8450                    Session session = null;
8451    
8452                    try {
8453                            session = openSession();
8454    
8455                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8456    
8457                            q.addScalar(COUNT_COLUMN_NAME,
8458                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
8459    
8460                            QueryPos qPos = QueryPos.getInstance(q);
8461    
8462                            qPos.add(groupId);
8463    
8464                            qPos.add(status);
8465    
8466                            Long count = (Long)q.uniqueResult();
8467    
8468                            return count.intValue();
8469                    }
8470                    catch (Exception e) {
8471                            throw processException(e);
8472                    }
8473                    finally {
8474                            closeSession(session);
8475                    }
8476            }
8477    
8478            private static final String _FINDER_COLUMN_G_P_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
8479            private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ? AND ";
8480            private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_7 = "mbCategory.parentCategoryId IN (";
8481            private static final String _FINDER_COLUMN_G_P_S_STATUS_2 = "mbCategory.status = ?";
8482            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S =
8483                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
8484                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
8485                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByNotC_G_P_S",
8486                            new String[] {
8487                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
8488                                    Integer.class.getName(),
8489                                    
8490                            Integer.class.getName(), Integer.class.getName(),
8491                                    OrderByComparator.class.getName()
8492                            });
8493            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S =
8494                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
8495                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
8496                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByNotC_G_P_S",
8497                            new String[] {
8498                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
8499                                    Integer.class.getName()
8500                            });
8501    
8502            /**
8503             * Returns all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8504             *
8505             * @param categoryId the category ID
8506             * @param groupId the group ID
8507             * @param parentCategoryId the parent category ID
8508             * @param status the status
8509             * @return the matching message boards categories
8510             */
8511            @Override
8512            public List<MBCategory> findByNotC_G_P_S(long categoryId, long groupId,
8513                    long parentCategoryId, int status) {
8514                    return findByNotC_G_P_S(categoryId, groupId, parentCategoryId, status,
8515                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8516            }
8517    
8518            /**
8519             * Returns a range of all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8520             *
8521             * <p>
8522             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
8523             * </p>
8524             *
8525             * @param categoryId the category ID
8526             * @param groupId the group ID
8527             * @param parentCategoryId the parent category ID
8528             * @param status the status
8529             * @param start the lower bound of the range of message boards categories
8530             * @param end the upper bound of the range of message boards categories (not inclusive)
8531             * @return the range of matching message boards categories
8532             */
8533            @Override
8534            public List<MBCategory> findByNotC_G_P_S(long categoryId, long groupId,
8535                    long parentCategoryId, int status, int start, int end) {
8536                    return findByNotC_G_P_S(categoryId, groupId, parentCategoryId, status,
8537                            start, end, null);
8538            }
8539    
8540            /**
8541             * Returns an ordered range of all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8542             *
8543             * <p>
8544             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
8545             * </p>
8546             *
8547             * @param categoryId the category ID
8548             * @param groupId the group ID
8549             * @param parentCategoryId the parent category ID
8550             * @param status the status
8551             * @param start the lower bound of the range of message boards categories
8552             * @param end the upper bound of the range of message boards categories (not inclusive)
8553             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8554             * @return the ordered range of matching message boards categories
8555             */
8556            @Override
8557            public List<MBCategory> findByNotC_G_P_S(long categoryId, long groupId,
8558                    long parentCategoryId, int status, int start, int end,
8559                    OrderByComparator<MBCategory> orderByComparator) {
8560                    return findByNotC_G_P_S(categoryId, groupId, parentCategoryId, status,
8561                            start, end, orderByComparator, true);
8562            }
8563    
8564            /**
8565             * Returns an ordered range of all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8566             *
8567             * <p>
8568             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
8569             * </p>
8570             *
8571             * @param categoryId the category ID
8572             * @param groupId the group ID
8573             * @param parentCategoryId the parent category ID
8574             * @param status the status
8575             * @param start the lower bound of the range of message boards categories
8576             * @param end the upper bound of the range of message boards categories (not inclusive)
8577             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8578             * @param retrieveFromCache whether to retrieve from the finder cache
8579             * @return the ordered range of matching message boards categories
8580             */
8581            @Override
8582            public List<MBCategory> findByNotC_G_P_S(long categoryId, long groupId,
8583                    long parentCategoryId, int status, int start, int end,
8584                    OrderByComparator<MBCategory> orderByComparator,
8585                    boolean retrieveFromCache) {
8586                    boolean pagination = true;
8587                    FinderPath finderPath = null;
8588                    Object[] finderArgs = null;
8589    
8590                    finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S;
8591                    finderArgs = new Object[] {
8592                                    categoryId, groupId, parentCategoryId, status,
8593                                    
8594                                    start, end, orderByComparator
8595                            };
8596    
8597                    List<MBCategory> list = null;
8598    
8599                    if (retrieveFromCache) {
8600                            list = (List<MBCategory>)finderCache.getResult(finderPath,
8601                                            finderArgs, this);
8602    
8603                            if ((list != null) && !list.isEmpty()) {
8604                                    for (MBCategory mbCategory : list) {
8605                                            if ((categoryId == mbCategory.getCategoryId()) ||
8606                                                            (groupId != mbCategory.getGroupId()) ||
8607                                                            (parentCategoryId != mbCategory.getParentCategoryId()) ||
8608                                                            (status != mbCategory.getStatus())) {
8609                                                    list = null;
8610    
8611                                                    break;
8612                                            }
8613                                    }
8614                            }
8615                    }
8616    
8617                    if (list == null) {
8618                            StringBundler query = null;
8619    
8620                            if (orderByComparator != null) {
8621                                    query = new StringBundler(6 +
8622                                                    (orderByComparator.getOrderByFields().length * 3));
8623                            }
8624                            else {
8625                                    query = new StringBundler(6);
8626                            }
8627    
8628                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
8629    
8630                            query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2);
8631    
8632                            query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
8633    
8634                            query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2);
8635    
8636                            query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
8637    
8638                            if (orderByComparator != null) {
8639                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8640                                            orderByComparator);
8641                            }
8642                            else
8643                             if (pagination) {
8644                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
8645                            }
8646    
8647                            String sql = query.toString();
8648    
8649                            Session session = null;
8650    
8651                            try {
8652                                    session = openSession();
8653    
8654                                    Query q = session.createQuery(sql);
8655    
8656                                    QueryPos qPos = QueryPos.getInstance(q);
8657    
8658                                    qPos.add(categoryId);
8659    
8660                                    qPos.add(groupId);
8661    
8662                                    qPos.add(parentCategoryId);
8663    
8664                                    qPos.add(status);
8665    
8666                                    if (!pagination) {
8667                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
8668                                                            start, end, false);
8669    
8670                                            Collections.sort(list);
8671    
8672                                            list = Collections.unmodifiableList(list);
8673                                    }
8674                                    else {
8675                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
8676                                                            start, end);
8677                                    }
8678    
8679                                    cacheResult(list);
8680    
8681                                    finderCache.putResult(finderPath, finderArgs, list);
8682                            }
8683                            catch (Exception e) {
8684                                    finderCache.removeResult(finderPath, finderArgs);
8685    
8686                                    throw processException(e);
8687                            }
8688                            finally {
8689                                    closeSession(session);
8690                            }
8691                    }
8692    
8693                    return list;
8694            }
8695    
8696            /**
8697             * Returns the first message boards category in the ordered set where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8698             *
8699             * @param categoryId the category ID
8700             * @param groupId the group ID
8701             * @param parentCategoryId the parent category ID
8702             * @param status the status
8703             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8704             * @return the first matching message boards category
8705             * @throws NoSuchCategoryException if a matching message boards category could not be found
8706             */
8707            @Override
8708            public MBCategory findByNotC_G_P_S_First(long categoryId, long groupId,
8709                    long parentCategoryId, int status,
8710                    OrderByComparator<MBCategory> orderByComparator)
8711                    throws NoSuchCategoryException {
8712                    MBCategory mbCategory = fetchByNotC_G_P_S_First(categoryId, groupId,
8713                                    parentCategoryId, status, orderByComparator);
8714    
8715                    if (mbCategory != null) {
8716                            return mbCategory;
8717                    }
8718    
8719                    StringBundler msg = new StringBundler(10);
8720    
8721                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8722    
8723                    msg.append("categoryId=");
8724                    msg.append(categoryId);
8725    
8726                    msg.append(", groupId=");
8727                    msg.append(groupId);
8728    
8729                    msg.append(", parentCategoryId=");
8730                    msg.append(parentCategoryId);
8731    
8732                    msg.append(", status=");
8733                    msg.append(status);
8734    
8735                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8736    
8737                    throw new NoSuchCategoryException(msg.toString());
8738            }
8739    
8740            /**
8741             * Returns the first message boards category in the ordered set where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8742             *
8743             * @param categoryId the category ID
8744             * @param groupId the group ID
8745             * @param parentCategoryId the parent category ID
8746             * @param status the status
8747             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8748             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
8749             */
8750            @Override
8751            public MBCategory fetchByNotC_G_P_S_First(long categoryId, long groupId,
8752                    long parentCategoryId, int status,
8753                    OrderByComparator<MBCategory> orderByComparator) {
8754                    List<MBCategory> list = findByNotC_G_P_S(categoryId, groupId,
8755                                    parentCategoryId, status, 0, 1, orderByComparator);
8756    
8757                    if (!list.isEmpty()) {
8758                            return list.get(0);
8759                    }
8760    
8761                    return null;
8762            }
8763    
8764            /**
8765             * Returns the last message boards category in the ordered set where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8766             *
8767             * @param categoryId the category ID
8768             * @param groupId the group ID
8769             * @param parentCategoryId the parent category ID
8770             * @param status the status
8771             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8772             * @return the last matching message boards category
8773             * @throws NoSuchCategoryException if a matching message boards category could not be found
8774             */
8775            @Override
8776            public MBCategory findByNotC_G_P_S_Last(long categoryId, long groupId,
8777                    long parentCategoryId, int status,
8778                    OrderByComparator<MBCategory> orderByComparator)
8779                    throws NoSuchCategoryException {
8780                    MBCategory mbCategory = fetchByNotC_G_P_S_Last(categoryId, groupId,
8781                                    parentCategoryId, status, orderByComparator);
8782    
8783                    if (mbCategory != null) {
8784                            return mbCategory;
8785                    }
8786    
8787                    StringBundler msg = new StringBundler(10);
8788    
8789                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8790    
8791                    msg.append("categoryId=");
8792                    msg.append(categoryId);
8793    
8794                    msg.append(", groupId=");
8795                    msg.append(groupId);
8796    
8797                    msg.append(", parentCategoryId=");
8798                    msg.append(parentCategoryId);
8799    
8800                    msg.append(", status=");
8801                    msg.append(status);
8802    
8803                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8804    
8805                    throw new NoSuchCategoryException(msg.toString());
8806            }
8807    
8808            /**
8809             * Returns the last message boards category in the ordered set where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8810             *
8811             * @param categoryId the category ID
8812             * @param groupId the group ID
8813             * @param parentCategoryId the parent category ID
8814             * @param status the status
8815             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8816             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
8817             */
8818            @Override
8819            public MBCategory fetchByNotC_G_P_S_Last(long categoryId, long groupId,
8820                    long parentCategoryId, int status,
8821                    OrderByComparator<MBCategory> orderByComparator) {
8822                    int count = countByNotC_G_P_S(categoryId, groupId, parentCategoryId,
8823                                    status);
8824    
8825                    if (count == 0) {
8826                            return null;
8827                    }
8828    
8829                    List<MBCategory> list = findByNotC_G_P_S(categoryId, groupId,
8830                                    parentCategoryId, status, count - 1, count, orderByComparator);
8831    
8832                    if (!list.isEmpty()) {
8833                            return list.get(0);
8834                    }
8835    
8836                    return null;
8837            }
8838    
8839            /**
8840             * Returns all the message boards categories that the user has permission to view where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8841             *
8842             * @param categoryId the category ID
8843             * @param groupId the group ID
8844             * @param parentCategoryId the parent category ID
8845             * @param status the status
8846             * @return the matching message boards categories that the user has permission to view
8847             */
8848            @Override
8849            public List<MBCategory> filterFindByNotC_G_P_S(long categoryId,
8850                    long groupId, long parentCategoryId, int status) {
8851                    return filterFindByNotC_G_P_S(categoryId, groupId, parentCategoryId,
8852                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
8853            }
8854    
8855            /**
8856             * Returns a range of all the message boards categories that the user has permission to view where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8857             *
8858             * <p>
8859             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
8860             * </p>
8861             *
8862             * @param categoryId the category ID
8863             * @param groupId the group ID
8864             * @param parentCategoryId the parent category ID
8865             * @param status the status
8866             * @param start the lower bound of the range of message boards categories
8867             * @param end the upper bound of the range of message boards categories (not inclusive)
8868             * @return the range of matching message boards categories that the user has permission to view
8869             */
8870            @Override
8871            public List<MBCategory> filterFindByNotC_G_P_S(long categoryId,
8872                    long groupId, long parentCategoryId, int status, int start, int end) {
8873                    return filterFindByNotC_G_P_S(categoryId, groupId, parentCategoryId,
8874                            status, start, end, null);
8875            }
8876    
8877            /**
8878             * Returns an ordered range of all the message boards categories that the user has permissions to view where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
8879             *
8880             * <p>
8881             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
8882             * </p>
8883             *
8884             * @param categoryId the category ID
8885             * @param groupId the group ID
8886             * @param parentCategoryId the parent category ID
8887             * @param status the status
8888             * @param start the lower bound of the range of message boards categories
8889             * @param end the upper bound of the range of message boards categories (not inclusive)
8890             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8891             * @return the ordered range of matching message boards categories that the user has permission to view
8892             */
8893            @Override
8894            public List<MBCategory> filterFindByNotC_G_P_S(long categoryId,
8895                    long groupId, long parentCategoryId, int status, int start, int end,
8896                    OrderByComparator<MBCategory> orderByComparator) {
8897                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
8898                            return findByNotC_G_P_S(categoryId, groupId, parentCategoryId,
8899                                    status, start, end, orderByComparator);
8900                    }
8901    
8902                    StringBundler query = null;
8903    
8904                    if (orderByComparator != null) {
8905                            query = new StringBundler(6 +
8906                                            (orderByComparator.getOrderByFields().length * 3));
8907                    }
8908                    else {
8909                            query = new StringBundler(6);
8910                    }
8911    
8912                    if (getDB().isSupportsInlineDistinct()) {
8913                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
8914                    }
8915                    else {
8916                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
8917                    }
8918    
8919                    query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2);
8920    
8921                    query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
8922    
8923                    query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2);
8924    
8925                    query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
8926    
8927                    if (!getDB().isSupportsInlineDistinct()) {
8928                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
8929                    }
8930    
8931                    if (orderByComparator != null) {
8932                            if (getDB().isSupportsInlineDistinct()) {
8933                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8934                                            orderByComparator, true);
8935                            }
8936                            else {
8937                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
8938                                            orderByComparator, true);
8939                            }
8940                    }
8941                    else {
8942                            if (getDB().isSupportsInlineDistinct()) {
8943                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
8944                            }
8945                            else {
8946                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
8947                            }
8948                    }
8949    
8950                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
8951                                    MBCategory.class.getName(),
8952                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
8953    
8954                    Session session = null;
8955    
8956                    try {
8957                            session = openSession();
8958    
8959                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
8960    
8961                            if (getDB().isSupportsInlineDistinct()) {
8962                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
8963                            }
8964                            else {
8965                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
8966                            }
8967    
8968                            QueryPos qPos = QueryPos.getInstance(q);
8969    
8970                            qPos.add(categoryId);
8971    
8972                            qPos.add(groupId);
8973    
8974                            qPos.add(parentCategoryId);
8975    
8976                            qPos.add(status);
8977    
8978                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
8979                    }
8980                    catch (Exception e) {
8981                            throw processException(e);
8982                    }
8983                    finally {
8984                            closeSession(session);
8985                    }
8986            }
8987    
8988            /**
8989             * Returns all the message boards categories that the user has permission to view where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
8990             *
8991             * @param categoryIds the category IDs
8992             * @param groupId the group ID
8993             * @param parentCategoryIds the parent category IDs
8994             * @param status the status
8995             * @return the matching message boards categories that the user has permission to view
8996             */
8997            @Override
8998            public List<MBCategory> filterFindByNotC_G_P_S(long[] categoryIds,
8999                    long groupId, long[] parentCategoryIds, int status) {
9000                    return filterFindByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
9001                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9002            }
9003    
9004            /**
9005             * Returns a range of all the message boards categories that the user has permission to view where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
9006             *
9007             * <p>
9008             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
9009             * </p>
9010             *
9011             * @param categoryIds the category IDs
9012             * @param groupId the group ID
9013             * @param parentCategoryIds the parent category IDs
9014             * @param status the status
9015             * @param start the lower bound of the range of message boards categories
9016             * @param end the upper bound of the range of message boards categories (not inclusive)
9017             * @return the range of matching message boards categories that the user has permission to view
9018             */
9019            @Override
9020            public List<MBCategory> filterFindByNotC_G_P_S(long[] categoryIds,
9021                    long groupId, long[] parentCategoryIds, int status, int start, int end) {
9022                    return filterFindByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
9023                            status, start, end, null);
9024            }
9025    
9026            /**
9027             * Returns an ordered range of all the message boards categories that the user has permission to view where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
9028             *
9029             * <p>
9030             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
9031             * </p>
9032             *
9033             * @param categoryIds the category IDs
9034             * @param groupId the group ID
9035             * @param parentCategoryIds the parent category IDs
9036             * @param status the status
9037             * @param start the lower bound of the range of message boards categories
9038             * @param end the upper bound of the range of message boards categories (not inclusive)
9039             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9040             * @return the ordered range of matching message boards categories that the user has permission to view
9041             */
9042            @Override
9043            public List<MBCategory> filterFindByNotC_G_P_S(long[] categoryIds,
9044                    long groupId, long[] parentCategoryIds, int status, int start, int end,
9045                    OrderByComparator<MBCategory> orderByComparator) {
9046                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9047                            return findByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
9048                                    status, start, end, orderByComparator);
9049                    }
9050    
9051                    if (categoryIds == null) {
9052                            categoryIds = new long[0];
9053                    }
9054                    else if (categoryIds.length > 1) {
9055                            categoryIds = ArrayUtil.unique(categoryIds);
9056    
9057                            Arrays.sort(categoryIds);
9058                    }
9059    
9060                    if (parentCategoryIds == null) {
9061                            parentCategoryIds = new long[0];
9062                    }
9063                    else if (parentCategoryIds.length > 1) {
9064                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
9065    
9066                            Arrays.sort(parentCategoryIds);
9067                    }
9068    
9069                    StringBundler query = new StringBundler();
9070    
9071                    if (getDB().isSupportsInlineDistinct()) {
9072                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
9073                    }
9074                    else {
9075                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
9076                    }
9077    
9078                    if (categoryIds.length > 0) {
9079                            query.append(StringPool.OPEN_PARENTHESIS);
9080    
9081                            query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7);
9082    
9083                            query.append(StringUtil.merge(categoryIds));
9084    
9085                            query.append(StringPool.CLOSE_PARENTHESIS);
9086    
9087                            query.append(StringPool.CLOSE_PARENTHESIS);
9088    
9089                            query.append(WHERE_AND);
9090                    }
9091    
9092                    query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9093    
9094                    if (parentCategoryIds.length > 0) {
9095                            query.append(StringPool.OPEN_PARENTHESIS);
9096    
9097                            query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7);
9098    
9099                            query.append(StringUtil.merge(parentCategoryIds));
9100    
9101                            query.append(StringPool.CLOSE_PARENTHESIS);
9102    
9103                            query.append(StringPool.CLOSE_PARENTHESIS);
9104    
9105                            query.append(WHERE_AND);
9106                    }
9107    
9108                    query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9109    
9110                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
9111                            query.index() - 1);
9112    
9113                    if (!getDB().isSupportsInlineDistinct()) {
9114                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
9115                    }
9116    
9117                    if (orderByComparator != null) {
9118                            if (getDB().isSupportsInlineDistinct()) {
9119                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9120                                            orderByComparator, true);
9121                            }
9122                            else {
9123                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
9124                                            orderByComparator, true);
9125                            }
9126                    }
9127                    else {
9128                            if (getDB().isSupportsInlineDistinct()) {
9129                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
9130                            }
9131                            else {
9132                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
9133                            }
9134                    }
9135    
9136                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9137                                    MBCategory.class.getName(),
9138                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9139    
9140                    Session session = null;
9141    
9142                    try {
9143                            session = openSession();
9144    
9145                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9146    
9147                            if (getDB().isSupportsInlineDistinct()) {
9148                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
9149                            }
9150                            else {
9151                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
9152                            }
9153    
9154                            QueryPos qPos = QueryPos.getInstance(q);
9155    
9156                            qPos.add(groupId);
9157    
9158                            qPos.add(status);
9159    
9160                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
9161                    }
9162                    catch (Exception e) {
9163                            throw processException(e);
9164                    }
9165                    finally {
9166                            closeSession(session);
9167                    }
9168            }
9169    
9170            /**
9171             * Returns all the message boards categories where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
9172             *
9173             * <p>
9174             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
9175             * </p>
9176             *
9177             * @param categoryIds the category IDs
9178             * @param groupId the group ID
9179             * @param parentCategoryIds the parent category IDs
9180             * @param status the status
9181             * @return the matching message boards categories
9182             */
9183            @Override
9184            public List<MBCategory> findByNotC_G_P_S(long[] categoryIds, long groupId,
9185                    long[] parentCategoryIds, int status) {
9186                    return findByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
9187                            status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
9188            }
9189    
9190            /**
9191             * Returns a range of all the message boards categories where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
9192             *
9193             * <p>
9194             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
9195             * </p>
9196             *
9197             * @param categoryIds the category IDs
9198             * @param groupId the group ID
9199             * @param parentCategoryIds the parent category IDs
9200             * @param status the status
9201             * @param start the lower bound of the range of message boards categories
9202             * @param end the upper bound of the range of message boards categories (not inclusive)
9203             * @return the range of matching message boards categories
9204             */
9205            @Override
9206            public List<MBCategory> findByNotC_G_P_S(long[] categoryIds, long groupId,
9207                    long[] parentCategoryIds, int status, int start, int end) {
9208                    return findByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
9209                            status, start, end, null);
9210            }
9211    
9212            /**
9213             * Returns an ordered range of all the message boards categories where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
9214             *
9215             * <p>
9216             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
9217             * </p>
9218             *
9219             * @param categoryIds the category IDs
9220             * @param groupId the group ID
9221             * @param parentCategoryIds the parent category IDs
9222             * @param status the status
9223             * @param start the lower bound of the range of message boards categories
9224             * @param end the upper bound of the range of message boards categories (not inclusive)
9225             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9226             * @return the ordered range of matching message boards categories
9227             */
9228            @Override
9229            public List<MBCategory> findByNotC_G_P_S(long[] categoryIds, long groupId,
9230                    long[] parentCategoryIds, int status, int start, int end,
9231                    OrderByComparator<MBCategory> orderByComparator) {
9232                    return findByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
9233                            status, start, end, orderByComparator, true);
9234            }
9235    
9236            /**
9237             * Returns an ordered range of all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;, optionally using the finder cache.
9238             *
9239             * <p>
9240             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
9241             * </p>
9242             *
9243             * @param categoryId the category ID
9244             * @param groupId the group ID
9245             * @param parentCategoryId the parent category ID
9246             * @param status the status
9247             * @param start the lower bound of the range of message boards categories
9248             * @param end the upper bound of the range of message boards categories (not inclusive)
9249             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9250             * @param retrieveFromCache whether to retrieve from the finder cache
9251             * @return the ordered range of matching message boards categories
9252             */
9253            @Override
9254            public List<MBCategory> findByNotC_G_P_S(long[] categoryIds, long groupId,
9255                    long[] parentCategoryIds, int status, int start, int end,
9256                    OrderByComparator<MBCategory> orderByComparator,
9257                    boolean retrieveFromCache) {
9258                    if (categoryIds == null) {
9259                            categoryIds = new long[0];
9260                    }
9261                    else if (categoryIds.length > 1) {
9262                            categoryIds = ArrayUtil.unique(categoryIds);
9263    
9264                            Arrays.sort(categoryIds);
9265                    }
9266    
9267                    if (parentCategoryIds == null) {
9268                            parentCategoryIds = new long[0];
9269                    }
9270                    else if (parentCategoryIds.length > 1) {
9271                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
9272    
9273                            Arrays.sort(parentCategoryIds);
9274                    }
9275    
9276                    if ((categoryIds.length == 1) && (parentCategoryIds.length == 1)) {
9277                            return findByNotC_G_P_S(categoryIds[0], groupId,
9278                                    parentCategoryIds[0], status, start, end, orderByComparator);
9279                    }
9280    
9281                    boolean pagination = true;
9282                    Object[] finderArgs = null;
9283    
9284                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9285                                    (orderByComparator == null)) {
9286                            pagination = false;
9287                            finderArgs = new Object[] {
9288                                            StringUtil.merge(categoryIds), groupId,
9289                                            StringUtil.merge(parentCategoryIds), status
9290                                    };
9291                    }
9292                    else {
9293                            finderArgs = new Object[] {
9294                                            StringUtil.merge(categoryIds), groupId,
9295                                            StringUtil.merge(parentCategoryIds), status,
9296                                            
9297                                            start, end, orderByComparator
9298                                    };
9299                    }
9300    
9301                    List<MBCategory> list = null;
9302    
9303                    if (retrieveFromCache) {
9304                            list = (List<MBCategory>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S,
9305                                            finderArgs, this);
9306    
9307                            if ((list != null) && !list.isEmpty()) {
9308                                    for (MBCategory mbCategory : list) {
9309                                            if (!ArrayUtil.contains(categoryIds,
9310                                                                    mbCategory.getCategoryId()) ||
9311                                                            (groupId != mbCategory.getGroupId()) ||
9312                                                            !ArrayUtil.contains(parentCategoryIds,
9313                                                                    mbCategory.getParentCategoryId()) ||
9314                                                            (status != mbCategory.getStatus())) {
9315                                                    list = null;
9316    
9317                                                    break;
9318                                            }
9319                                    }
9320                            }
9321                    }
9322    
9323                    if (list == null) {
9324                            StringBundler query = new StringBundler();
9325    
9326                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
9327    
9328                            if (categoryIds.length > 0) {
9329                                    query.append(StringPool.OPEN_PARENTHESIS);
9330    
9331                                    query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7);
9332    
9333                                    query.append(StringUtil.merge(categoryIds));
9334    
9335                                    query.append(StringPool.CLOSE_PARENTHESIS);
9336    
9337                                    query.append(StringPool.CLOSE_PARENTHESIS);
9338    
9339                                    query.append(WHERE_AND);
9340                            }
9341    
9342                            query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9343    
9344                            if (parentCategoryIds.length > 0) {
9345                                    query.append(StringPool.OPEN_PARENTHESIS);
9346    
9347                                    query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7);
9348    
9349                                    query.append(StringUtil.merge(parentCategoryIds));
9350    
9351                                    query.append(StringPool.CLOSE_PARENTHESIS);
9352    
9353                                    query.append(StringPool.CLOSE_PARENTHESIS);
9354    
9355                                    query.append(WHERE_AND);
9356                            }
9357    
9358                            query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9359    
9360                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
9361                                                    1)), query.index() - 1);
9362    
9363                            if (orderByComparator != null) {
9364                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9365                                            orderByComparator);
9366                            }
9367                            else
9368                             if (pagination) {
9369                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
9370                            }
9371    
9372                            String sql = query.toString();
9373    
9374                            Session session = null;
9375    
9376                            try {
9377                                    session = openSession();
9378    
9379                                    Query q = session.createQuery(sql);
9380    
9381                                    QueryPos qPos = QueryPos.getInstance(q);
9382    
9383                                    qPos.add(groupId);
9384    
9385                                    qPos.add(status);
9386    
9387                                    if (!pagination) {
9388                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
9389                                                            start, end, false);
9390    
9391                                            Collections.sort(list);
9392    
9393                                            list = Collections.unmodifiableList(list);
9394                                    }
9395                                    else {
9396                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
9397                                                            start, end);
9398                                    }
9399    
9400                                    cacheResult(list);
9401    
9402                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S,
9403                                            finderArgs, list);
9404                            }
9405                            catch (Exception e) {
9406                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NOTC_G_P_S,
9407                                            finderArgs);
9408    
9409                                    throw processException(e);
9410                            }
9411                            finally {
9412                                    closeSession(session);
9413                            }
9414                    }
9415    
9416                    return list;
9417            }
9418    
9419            /**
9420             * Removes all the message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63; from the database.
9421             *
9422             * @param categoryId the category ID
9423             * @param groupId the group ID
9424             * @param parentCategoryId the parent category ID
9425             * @param status the status
9426             */
9427            @Override
9428            public void removeByNotC_G_P_S(long categoryId, long groupId,
9429                    long parentCategoryId, int status) {
9430                    for (MBCategory mbCategory : findByNotC_G_P_S(categoryId, groupId,
9431                                    parentCategoryId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
9432                                    null)) {
9433                            remove(mbCategory);
9434                    }
9435            }
9436    
9437            /**
9438             * Returns the number of message boards categories where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
9439             *
9440             * @param categoryId the category ID
9441             * @param groupId the group ID
9442             * @param parentCategoryId the parent category ID
9443             * @param status the status
9444             * @return the number of matching message boards categories
9445             */
9446            @Override
9447            public int countByNotC_G_P_S(long categoryId, long groupId,
9448                    long parentCategoryId, int status) {
9449                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S;
9450    
9451                    Object[] finderArgs = new Object[] {
9452                                    categoryId, groupId, parentCategoryId, status
9453                            };
9454    
9455                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
9456    
9457                    if (count == null) {
9458                            StringBundler query = new StringBundler(5);
9459    
9460                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
9461    
9462                            query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2);
9463    
9464                            query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9465    
9466                            query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2);
9467    
9468                            query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9469    
9470                            String sql = query.toString();
9471    
9472                            Session session = null;
9473    
9474                            try {
9475                                    session = openSession();
9476    
9477                                    Query q = session.createQuery(sql);
9478    
9479                                    QueryPos qPos = QueryPos.getInstance(q);
9480    
9481                                    qPos.add(categoryId);
9482    
9483                                    qPos.add(groupId);
9484    
9485                                    qPos.add(parentCategoryId);
9486    
9487                                    qPos.add(status);
9488    
9489                                    count = (Long)q.uniqueResult();
9490    
9491                                    finderCache.putResult(finderPath, finderArgs, count);
9492                            }
9493                            catch (Exception e) {
9494                                    finderCache.removeResult(finderPath, finderArgs);
9495    
9496                                    throw processException(e);
9497                            }
9498                            finally {
9499                                    closeSession(session);
9500                            }
9501                    }
9502    
9503                    return count.intValue();
9504            }
9505    
9506            /**
9507             * Returns the number of message boards categories where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
9508             *
9509             * @param categoryIds the category IDs
9510             * @param groupId the group ID
9511             * @param parentCategoryIds the parent category IDs
9512             * @param status the status
9513             * @return the number of matching message boards categories
9514             */
9515            @Override
9516            public int countByNotC_G_P_S(long[] categoryIds, long groupId,
9517                    long[] parentCategoryIds, int status) {
9518                    if (categoryIds == null) {
9519                            categoryIds = new long[0];
9520                    }
9521                    else if (categoryIds.length > 1) {
9522                            categoryIds = ArrayUtil.unique(categoryIds);
9523    
9524                            Arrays.sort(categoryIds);
9525                    }
9526    
9527                    if (parentCategoryIds == null) {
9528                            parentCategoryIds = new long[0];
9529                    }
9530                    else if (parentCategoryIds.length > 1) {
9531                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
9532    
9533                            Arrays.sort(parentCategoryIds);
9534                    }
9535    
9536                    Object[] finderArgs = new Object[] {
9537                                    StringUtil.merge(categoryIds), groupId,
9538                                    StringUtil.merge(parentCategoryIds), status
9539                            };
9540    
9541                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S,
9542                                    finderArgs, this);
9543    
9544                    if (count == null) {
9545                            StringBundler query = new StringBundler();
9546    
9547                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
9548    
9549                            if (categoryIds.length > 0) {
9550                                    query.append(StringPool.OPEN_PARENTHESIS);
9551    
9552                                    query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7);
9553    
9554                                    query.append(StringUtil.merge(categoryIds));
9555    
9556                                    query.append(StringPool.CLOSE_PARENTHESIS);
9557    
9558                                    query.append(StringPool.CLOSE_PARENTHESIS);
9559    
9560                                    query.append(WHERE_AND);
9561                            }
9562    
9563                            query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9564    
9565                            if (parentCategoryIds.length > 0) {
9566                                    query.append(StringPool.OPEN_PARENTHESIS);
9567    
9568                                    query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7);
9569    
9570                                    query.append(StringUtil.merge(parentCategoryIds));
9571    
9572                                    query.append(StringPool.CLOSE_PARENTHESIS);
9573    
9574                                    query.append(StringPool.CLOSE_PARENTHESIS);
9575    
9576                                    query.append(WHERE_AND);
9577                            }
9578    
9579                            query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9580    
9581                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
9582                                                    1)), query.index() - 1);
9583    
9584                            String sql = query.toString();
9585    
9586                            Session session = null;
9587    
9588                            try {
9589                                    session = openSession();
9590    
9591                                    Query q = session.createQuery(sql);
9592    
9593                                    QueryPos qPos = QueryPos.getInstance(q);
9594    
9595                                    qPos.add(groupId);
9596    
9597                                    qPos.add(status);
9598    
9599                                    count = (Long)q.uniqueResult();
9600    
9601                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S,
9602                                            finderArgs, count);
9603                            }
9604                            catch (Exception e) {
9605                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NOTC_G_P_S,
9606                                            finderArgs);
9607    
9608                                    throw processException(e);
9609                            }
9610                            finally {
9611                                    closeSession(session);
9612                            }
9613                    }
9614    
9615                    return count.intValue();
9616            }
9617    
9618            /**
9619             * Returns the number of message boards categories that the user has permission to view where categoryId &ne; &#63; and groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
9620             *
9621             * @param categoryId the category ID
9622             * @param groupId the group ID
9623             * @param parentCategoryId the parent category ID
9624             * @param status the status
9625             * @return the number of matching message boards categories that the user has permission to view
9626             */
9627            @Override
9628            public int filterCountByNotC_G_P_S(long categoryId, long groupId,
9629                    long parentCategoryId, int status) {
9630                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9631                            return countByNotC_G_P_S(categoryId, groupId, parentCategoryId,
9632                                    status);
9633                    }
9634    
9635                    StringBundler query = new StringBundler(5);
9636    
9637                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
9638    
9639                    query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2);
9640    
9641                    query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9642    
9643                    query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2);
9644    
9645                    query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9646    
9647                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9648                                    MBCategory.class.getName(),
9649                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9650    
9651                    Session session = null;
9652    
9653                    try {
9654                            session = openSession();
9655    
9656                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9657    
9658                            q.addScalar(COUNT_COLUMN_NAME,
9659                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9660    
9661                            QueryPos qPos = QueryPos.getInstance(q);
9662    
9663                            qPos.add(categoryId);
9664    
9665                            qPos.add(groupId);
9666    
9667                            qPos.add(parentCategoryId);
9668    
9669                            qPos.add(status);
9670    
9671                            Long count = (Long)q.uniqueResult();
9672    
9673                            return count.intValue();
9674                    }
9675                    catch (Exception e) {
9676                            throw processException(e);
9677                    }
9678                    finally {
9679                            closeSession(session);
9680                    }
9681            }
9682    
9683            /**
9684             * Returns the number of message boards categories that the user has permission to view where categoryId &ne; all &#63; and groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
9685             *
9686             * @param categoryIds the category IDs
9687             * @param groupId the group ID
9688             * @param parentCategoryIds the parent category IDs
9689             * @param status the status
9690             * @return the number of matching message boards categories that the user has permission to view
9691             */
9692            @Override
9693            public int filterCountByNotC_G_P_S(long[] categoryIds, long groupId,
9694                    long[] parentCategoryIds, int status) {
9695                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
9696                            return countByNotC_G_P_S(categoryIds, groupId, parentCategoryIds,
9697                                    status);
9698                    }
9699    
9700                    if (categoryIds == null) {
9701                            categoryIds = new long[0];
9702                    }
9703                    else if (categoryIds.length > 1) {
9704                            categoryIds = ArrayUtil.unique(categoryIds);
9705    
9706                            Arrays.sort(categoryIds);
9707                    }
9708    
9709                    if (parentCategoryIds == null) {
9710                            parentCategoryIds = new long[0];
9711                    }
9712                    else if (parentCategoryIds.length > 1) {
9713                            parentCategoryIds = ArrayUtil.unique(parentCategoryIds);
9714    
9715                            Arrays.sort(parentCategoryIds);
9716                    }
9717    
9718                    StringBundler query = new StringBundler();
9719    
9720                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
9721    
9722                    if (categoryIds.length > 0) {
9723                            query.append(StringPool.OPEN_PARENTHESIS);
9724    
9725                            query.append(_FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7);
9726    
9727                            query.append(StringUtil.merge(categoryIds));
9728    
9729                            query.append(StringPool.CLOSE_PARENTHESIS);
9730    
9731                            query.append(StringPool.CLOSE_PARENTHESIS);
9732    
9733                            query.append(WHERE_AND);
9734                    }
9735    
9736                    query.append(_FINDER_COLUMN_NOTC_G_P_S_GROUPID_2);
9737    
9738                    if (parentCategoryIds.length > 0) {
9739                            query.append(StringPool.OPEN_PARENTHESIS);
9740    
9741                            query.append(_FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7);
9742    
9743                            query.append(StringUtil.merge(parentCategoryIds));
9744    
9745                            query.append(StringPool.CLOSE_PARENTHESIS);
9746    
9747                            query.append(StringPool.CLOSE_PARENTHESIS);
9748    
9749                            query.append(WHERE_AND);
9750                    }
9751    
9752                    query.append(_FINDER_COLUMN_NOTC_G_P_S_STATUS_2);
9753    
9754                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
9755                            query.index() - 1);
9756    
9757                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
9758                                    MBCategory.class.getName(),
9759                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
9760    
9761                    Session session = null;
9762    
9763                    try {
9764                            session = openSession();
9765    
9766                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
9767    
9768                            q.addScalar(COUNT_COLUMN_NAME,
9769                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
9770    
9771                            QueryPos qPos = QueryPos.getInstance(q);
9772    
9773                            qPos.add(groupId);
9774    
9775                            qPos.add(status);
9776    
9777                            Long count = (Long)q.uniqueResult();
9778    
9779                            return count.intValue();
9780                    }
9781                    catch (Exception e) {
9782                            throw processException(e);
9783                    }
9784                    finally {
9785                            closeSession(session);
9786                    }
9787            }
9788    
9789            private static final String _FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_2 = "mbCategory.categoryId != ? AND ";
9790            private static final String _FINDER_COLUMN_NOTC_G_P_S_CATEGORYID_7 = "mbCategory.categoryId NOT IN (";
9791            private static final String _FINDER_COLUMN_NOTC_G_P_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
9792            private static final String _FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ? AND ";
9793            private static final String _FINDER_COLUMN_NOTC_G_P_S_PARENTCATEGORYID_7 = "mbCategory.parentCategoryId IN (";
9794            private static final String _FINDER_COLUMN_NOTC_G_P_S_STATUS_2 = "mbCategory.status = ?";
9795    
9796            public MBCategoryPersistenceImpl() {
9797                    setModelClass(MBCategory.class);
9798            }
9799    
9800            /**
9801             * Caches the message boards category in the entity cache if it is enabled.
9802             *
9803             * @param mbCategory the message boards category
9804             */
9805            @Override
9806            public void cacheResult(MBCategory mbCategory) {
9807                    entityCache.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9808                            MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
9809    
9810                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G,
9811                            new Object[] { mbCategory.getUuid(), mbCategory.getGroupId() },
9812                            mbCategory);
9813    
9814                    mbCategory.resetOriginalValues();
9815            }
9816    
9817            /**
9818             * Caches the message boards categories in the entity cache if it is enabled.
9819             *
9820             * @param mbCategories the message boards categories
9821             */
9822            @Override
9823            public void cacheResult(List<MBCategory> mbCategories) {
9824                    for (MBCategory mbCategory : mbCategories) {
9825                            if (entityCache.getResult(
9826                                                    MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9827                                                    MBCategoryImpl.class, mbCategory.getPrimaryKey()) == null) {
9828                                    cacheResult(mbCategory);
9829                            }
9830                            else {
9831                                    mbCategory.resetOriginalValues();
9832                            }
9833                    }
9834            }
9835    
9836            /**
9837             * Clears the cache for all message boards categories.
9838             *
9839             * <p>
9840             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
9841             * </p>
9842             */
9843            @Override
9844            public void clearCache() {
9845                    entityCache.clearCache(MBCategoryImpl.class);
9846    
9847                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
9848                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9849                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9850            }
9851    
9852            /**
9853             * Clears the cache for the message boards category.
9854             *
9855             * <p>
9856             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
9857             * </p>
9858             */
9859            @Override
9860            public void clearCache(MBCategory mbCategory) {
9861                    entityCache.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9862                            MBCategoryImpl.class, mbCategory.getPrimaryKey());
9863    
9864                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9865                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9866    
9867                    clearUniqueFindersCache((MBCategoryModelImpl)mbCategory);
9868            }
9869    
9870            @Override
9871            public void clearCache(List<MBCategory> mbCategories) {
9872                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
9873                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
9874    
9875                    for (MBCategory mbCategory : mbCategories) {
9876                            entityCache.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
9877                                    MBCategoryImpl.class, mbCategory.getPrimaryKey());
9878    
9879                            clearUniqueFindersCache((MBCategoryModelImpl)mbCategory);
9880                    }
9881            }
9882    
9883            protected void cacheUniqueFindersCache(
9884                    MBCategoryModelImpl mbCategoryModelImpl, boolean isNew) {
9885                    if (isNew) {
9886                            Object[] args = new Object[] {
9887                                            mbCategoryModelImpl.getUuid(),
9888                                            mbCategoryModelImpl.getGroupId()
9889                                    };
9890    
9891                            finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
9892                                    Long.valueOf(1));
9893                            finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
9894                                    mbCategoryModelImpl);
9895                    }
9896                    else {
9897                            if ((mbCategoryModelImpl.getColumnBitmask() &
9898                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
9899                                    Object[] args = new Object[] {
9900                                                    mbCategoryModelImpl.getUuid(),
9901                                                    mbCategoryModelImpl.getGroupId()
9902                                            };
9903    
9904                                    finderCache.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
9905                                            Long.valueOf(1));
9906                                    finderCache.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
9907                                            mbCategoryModelImpl);
9908                            }
9909                    }
9910            }
9911    
9912            protected void clearUniqueFindersCache(
9913                    MBCategoryModelImpl mbCategoryModelImpl) {
9914                    Object[] args = new Object[] {
9915                                    mbCategoryModelImpl.getUuid(), mbCategoryModelImpl.getGroupId()
9916                            };
9917    
9918                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
9919                    finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
9920    
9921                    if ((mbCategoryModelImpl.getColumnBitmask() &
9922                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
9923                            args = new Object[] {
9924                                            mbCategoryModelImpl.getOriginalUuid(),
9925                                            mbCategoryModelImpl.getOriginalGroupId()
9926                                    };
9927    
9928                            finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
9929                            finderCache.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
9930                    }
9931            }
9932    
9933            /**
9934             * Creates a new message boards category with the primary key. Does not add the message boards category to the database.
9935             *
9936             * @param categoryId the primary key for the new message boards category
9937             * @return the new message boards category
9938             */
9939            @Override
9940            public MBCategory create(long categoryId) {
9941                    MBCategory mbCategory = new MBCategoryImpl();
9942    
9943                    mbCategory.setNew(true);
9944                    mbCategory.setPrimaryKey(categoryId);
9945    
9946                    String uuid = PortalUUIDUtil.generate();
9947    
9948                    mbCategory.setUuid(uuid);
9949    
9950                    return mbCategory;
9951            }
9952    
9953            /**
9954             * Removes the message boards category with the primary key from the database. Also notifies the appropriate model listeners.
9955             *
9956             * @param categoryId the primary key of the message boards category
9957             * @return the message boards category that was removed
9958             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
9959             */
9960            @Override
9961            public MBCategory remove(long categoryId) throws NoSuchCategoryException {
9962                    return remove((Serializable)categoryId);
9963            }
9964    
9965            /**
9966             * Removes the message boards category with the primary key from the database. Also notifies the appropriate model listeners.
9967             *
9968             * @param primaryKey the primary key of the message boards category
9969             * @return the message boards category that was removed
9970             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
9971             */
9972            @Override
9973            public MBCategory remove(Serializable primaryKey)
9974                    throws NoSuchCategoryException {
9975                    Session session = null;
9976    
9977                    try {
9978                            session = openSession();
9979    
9980                            MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
9981                                            primaryKey);
9982    
9983                            if (mbCategory == null) {
9984                                    if (_log.isWarnEnabled()) {
9985                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
9986                                    }
9987    
9988                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
9989                                            primaryKey);
9990                            }
9991    
9992                            return remove(mbCategory);
9993                    }
9994                    catch (NoSuchCategoryException nsee) {
9995                            throw nsee;
9996                    }
9997                    catch (Exception e) {
9998                            throw processException(e);
9999                    }
10000                    finally {
10001                            closeSession(session);
10002                    }
10003            }
10004    
10005            @Override
10006            protected MBCategory removeImpl(MBCategory mbCategory) {
10007                    mbCategory = toUnwrappedModel(mbCategory);
10008    
10009                    Session session = null;
10010    
10011                    try {
10012                            session = openSession();
10013    
10014                            if (!session.contains(mbCategory)) {
10015                                    mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
10016                                                    mbCategory.getPrimaryKeyObj());
10017                            }
10018    
10019                            if (mbCategory != null) {
10020                                    session.delete(mbCategory);
10021                            }
10022                    }
10023                    catch (Exception e) {
10024                            throw processException(e);
10025                    }
10026                    finally {
10027                            closeSession(session);
10028                    }
10029    
10030                    if (mbCategory != null) {
10031                            clearCache(mbCategory);
10032                    }
10033    
10034                    return mbCategory;
10035            }
10036    
10037            @Override
10038            public MBCategory updateImpl(MBCategory mbCategory) {
10039                    mbCategory = toUnwrappedModel(mbCategory);
10040    
10041                    boolean isNew = mbCategory.isNew();
10042    
10043                    MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
10044    
10045                    if (Validator.isNull(mbCategory.getUuid())) {
10046                            String uuid = PortalUUIDUtil.generate();
10047    
10048                            mbCategory.setUuid(uuid);
10049                    }
10050    
10051                    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();
10052    
10053                    Date now = new Date();
10054    
10055                    if (isNew && (mbCategory.getCreateDate() == null)) {
10056                            if (serviceContext == null) {
10057                                    mbCategory.setCreateDate(now);
10058                            }
10059                            else {
10060                                    mbCategory.setCreateDate(serviceContext.getCreateDate(now));
10061                            }
10062                    }
10063    
10064                    if (!mbCategoryModelImpl.hasSetModifiedDate()) {
10065                            if (serviceContext == null) {
10066                                    mbCategory.setModifiedDate(now);
10067                            }
10068                            else {
10069                                    mbCategory.setModifiedDate(serviceContext.getModifiedDate(now));
10070                            }
10071                    }
10072    
10073                    Session session = null;
10074    
10075                    try {
10076                            session = openSession();
10077    
10078                            if (mbCategory.isNew()) {
10079                                    session.save(mbCategory);
10080    
10081                                    mbCategory.setNew(false);
10082                            }
10083                            else {
10084                                    mbCategory = (MBCategory)session.merge(mbCategory);
10085                            }
10086                    }
10087                    catch (Exception e) {
10088                            throw processException(e);
10089                    }
10090                    finally {
10091                            closeSession(session);
10092                    }
10093    
10094                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10095    
10096                    if (isNew || !MBCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
10097                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10098                    }
10099    
10100                    else {
10101                            if ((mbCategoryModelImpl.getColumnBitmask() &
10102                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
10103                                    Object[] args = new Object[] {
10104                                                    mbCategoryModelImpl.getOriginalUuid()
10105                                            };
10106    
10107                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
10108                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
10109                                            args);
10110    
10111                                    args = new Object[] { mbCategoryModelImpl.getUuid() };
10112    
10113                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
10114                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
10115                                            args);
10116                            }
10117    
10118                            if ((mbCategoryModelImpl.getColumnBitmask() &
10119                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
10120                                    Object[] args = new Object[] {
10121                                                    mbCategoryModelImpl.getOriginalUuid(),
10122                                                    mbCategoryModelImpl.getOriginalCompanyId()
10123                                            };
10124    
10125                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
10126                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
10127                                            args);
10128    
10129                                    args = new Object[] {
10130                                                    mbCategoryModelImpl.getUuid(),
10131                                                    mbCategoryModelImpl.getCompanyId()
10132                                            };
10133    
10134                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
10135                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
10136                                            args);
10137                            }
10138    
10139                            if ((mbCategoryModelImpl.getColumnBitmask() &
10140                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
10141                                    Object[] args = new Object[] {
10142                                                    mbCategoryModelImpl.getOriginalGroupId()
10143                                            };
10144    
10145                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
10146                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
10147                                            args);
10148    
10149                                    args = new Object[] { mbCategoryModelImpl.getGroupId() };
10150    
10151                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
10152                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
10153                                            args);
10154                            }
10155    
10156                            if ((mbCategoryModelImpl.getColumnBitmask() &
10157                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
10158                                    Object[] args = new Object[] {
10159                                                    mbCategoryModelImpl.getOriginalCompanyId()
10160                                            };
10161    
10162                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
10163                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
10164                                            args);
10165    
10166                                    args = new Object[] { mbCategoryModelImpl.getCompanyId() };
10167    
10168                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_COMPANYID, args);
10169                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
10170                                            args);
10171                            }
10172    
10173                            if ((mbCategoryModelImpl.getColumnBitmask() &
10174                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
10175                                    Object[] args = new Object[] {
10176                                                    mbCategoryModelImpl.getOriginalGroupId(),
10177                                                    mbCategoryModelImpl.getOriginalParentCategoryId()
10178                                            };
10179    
10180                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
10181                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
10182                                            args);
10183    
10184                                    args = new Object[] {
10185                                                    mbCategoryModelImpl.getGroupId(),
10186                                                    mbCategoryModelImpl.getParentCategoryId()
10187                                            };
10188    
10189                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
10190                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
10191                                            args);
10192                            }
10193    
10194                            if ((mbCategoryModelImpl.getColumnBitmask() &
10195                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
10196                                    Object[] args = new Object[] {
10197                                                    mbCategoryModelImpl.getOriginalGroupId(),
10198                                                    mbCategoryModelImpl.getOriginalStatus()
10199                                            };
10200    
10201                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
10202                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
10203                                            args);
10204    
10205                                    args = new Object[] {
10206                                                    mbCategoryModelImpl.getGroupId(),
10207                                                    mbCategoryModelImpl.getStatus()
10208                                            };
10209    
10210                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
10211                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
10212                                            args);
10213                            }
10214    
10215                            if ((mbCategoryModelImpl.getColumnBitmask() &
10216                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
10217                                    Object[] args = new Object[] {
10218                                                    mbCategoryModelImpl.getOriginalCompanyId(),
10219                                                    mbCategoryModelImpl.getOriginalStatus()
10220                                            };
10221    
10222                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
10223                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
10224                                            args);
10225    
10226                                    args = new Object[] {
10227                                                    mbCategoryModelImpl.getCompanyId(),
10228                                                    mbCategoryModelImpl.getStatus()
10229                                            };
10230    
10231                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
10232                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
10233                                            args);
10234                            }
10235    
10236                            if ((mbCategoryModelImpl.getColumnBitmask() &
10237                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S.getColumnBitmask()) != 0) {
10238                                    Object[] args = new Object[] {
10239                                                    mbCategoryModelImpl.getOriginalGroupId(),
10240                                                    mbCategoryModelImpl.getOriginalParentCategoryId(),
10241                                                    mbCategoryModelImpl.getOriginalStatus()
10242                                            };
10243    
10244                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
10245                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
10246                                            args);
10247    
10248                                    args = new Object[] {
10249                                                    mbCategoryModelImpl.getGroupId(),
10250                                                    mbCategoryModelImpl.getParentCategoryId(),
10251                                                    mbCategoryModelImpl.getStatus()
10252                                            };
10253    
10254                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
10255                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
10256                                            args);
10257                            }
10258                    }
10259    
10260                    entityCache.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
10261                            MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory, false);
10262    
10263                    clearUniqueFindersCache(mbCategoryModelImpl);
10264                    cacheUniqueFindersCache(mbCategoryModelImpl, isNew);
10265    
10266                    mbCategory.resetOriginalValues();
10267    
10268                    return mbCategory;
10269            }
10270    
10271            protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
10272                    if (mbCategory instanceof MBCategoryImpl) {
10273                            return mbCategory;
10274                    }
10275    
10276                    MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
10277    
10278                    mbCategoryImpl.setNew(mbCategory.isNew());
10279                    mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
10280    
10281                    mbCategoryImpl.setUuid(mbCategory.getUuid());
10282                    mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
10283                    mbCategoryImpl.setGroupId(mbCategory.getGroupId());
10284                    mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
10285                    mbCategoryImpl.setUserId(mbCategory.getUserId());
10286                    mbCategoryImpl.setUserName(mbCategory.getUserName());
10287                    mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
10288                    mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
10289                    mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
10290                    mbCategoryImpl.setName(mbCategory.getName());
10291                    mbCategoryImpl.setDescription(mbCategory.getDescription());
10292                    mbCategoryImpl.setDisplayStyle(mbCategory.getDisplayStyle());
10293                    mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
10294                    mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
10295                    mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
10296                    mbCategoryImpl.setLastPublishDate(mbCategory.getLastPublishDate());
10297                    mbCategoryImpl.setStatus(mbCategory.getStatus());
10298                    mbCategoryImpl.setStatusByUserId(mbCategory.getStatusByUserId());
10299                    mbCategoryImpl.setStatusByUserName(mbCategory.getStatusByUserName());
10300                    mbCategoryImpl.setStatusDate(mbCategory.getStatusDate());
10301    
10302                    return mbCategoryImpl;
10303            }
10304    
10305            /**
10306             * Returns the message boards category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
10307             *
10308             * @param primaryKey the primary key of the message boards category
10309             * @return the message boards category
10310             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
10311             */
10312            @Override
10313            public MBCategory findByPrimaryKey(Serializable primaryKey)
10314                    throws NoSuchCategoryException {
10315                    MBCategory mbCategory = fetchByPrimaryKey(primaryKey);
10316    
10317                    if (mbCategory == null) {
10318                            if (_log.isWarnEnabled()) {
10319                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
10320                            }
10321    
10322                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
10323                                    primaryKey);
10324                    }
10325    
10326                    return mbCategory;
10327            }
10328    
10329            /**
10330             * Returns the message boards category with the primary key or throws a {@link NoSuchCategoryException} if it could not be found.
10331             *
10332             * @param categoryId the primary key of the message boards category
10333             * @return the message boards category
10334             * @throws NoSuchCategoryException if a message boards category with the primary key could not be found
10335             */
10336            @Override
10337            public MBCategory findByPrimaryKey(long categoryId)
10338                    throws NoSuchCategoryException {
10339                    return findByPrimaryKey((Serializable)categoryId);
10340            }
10341    
10342            /**
10343             * Returns the message boards category with the primary key or returns <code>null</code> if it could not be found.
10344             *
10345             * @param primaryKey the primary key of the message boards category
10346             * @return the message boards category, or <code>null</code> if a message boards category with the primary key could not be found
10347             */
10348            @Override
10349            public MBCategory fetchByPrimaryKey(Serializable primaryKey) {
10350                    MBCategory mbCategory = (MBCategory)entityCache.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
10351                                    MBCategoryImpl.class, primaryKey);
10352    
10353                    if (mbCategory == _nullMBCategory) {
10354                            return null;
10355                    }
10356    
10357                    if (mbCategory == null) {
10358                            Session session = null;
10359    
10360                            try {
10361                                    session = openSession();
10362    
10363                                    mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
10364                                                    primaryKey);
10365    
10366                                    if (mbCategory != null) {
10367                                            cacheResult(mbCategory);
10368                                    }
10369                                    else {
10370                                            entityCache.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
10371                                                    MBCategoryImpl.class, primaryKey, _nullMBCategory);
10372                                    }
10373                            }
10374                            catch (Exception e) {
10375                                    entityCache.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
10376                                            MBCategoryImpl.class, primaryKey);
10377    
10378                                    throw processException(e);
10379                            }
10380                            finally {
10381                                    closeSession(session);
10382                            }
10383                    }
10384    
10385                    return mbCategory;
10386            }
10387    
10388            /**
10389             * Returns the message boards category with the primary key or returns <code>null</code> if it could not be found.
10390             *
10391             * @param categoryId the primary key of the message boards category
10392             * @return the message boards category, or <code>null</code> if a message boards category with the primary key could not be found
10393             */
10394            @Override
10395            public MBCategory fetchByPrimaryKey(long categoryId) {
10396                    return fetchByPrimaryKey((Serializable)categoryId);
10397            }
10398    
10399            @Override
10400            public Map<Serializable, MBCategory> fetchByPrimaryKeys(
10401                    Set<Serializable> primaryKeys) {
10402                    if (primaryKeys.isEmpty()) {
10403                            return Collections.emptyMap();
10404                    }
10405    
10406                    Map<Serializable, MBCategory> map = new HashMap<Serializable, MBCategory>();
10407    
10408                    if (primaryKeys.size() == 1) {
10409                            Iterator<Serializable> iterator = primaryKeys.iterator();
10410    
10411                            Serializable primaryKey = iterator.next();
10412    
10413                            MBCategory mbCategory = fetchByPrimaryKey(primaryKey);
10414    
10415                            if (mbCategory != null) {
10416                                    map.put(primaryKey, mbCategory);
10417                            }
10418    
10419                            return map;
10420                    }
10421    
10422                    Set<Serializable> uncachedPrimaryKeys = null;
10423    
10424                    for (Serializable primaryKey : primaryKeys) {
10425                            MBCategory mbCategory = (MBCategory)entityCache.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
10426                                            MBCategoryImpl.class, primaryKey);
10427    
10428                            if (mbCategory == null) {
10429                                    if (uncachedPrimaryKeys == null) {
10430                                            uncachedPrimaryKeys = new HashSet<Serializable>();
10431                                    }
10432    
10433                                    uncachedPrimaryKeys.add(primaryKey);
10434                            }
10435                            else {
10436                                    map.put(primaryKey, mbCategory);
10437                            }
10438                    }
10439    
10440                    if (uncachedPrimaryKeys == null) {
10441                            return map;
10442                    }
10443    
10444                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
10445                                    1);
10446    
10447                    query.append(_SQL_SELECT_MBCATEGORY_WHERE_PKS_IN);
10448    
10449                    for (Serializable primaryKey : uncachedPrimaryKeys) {
10450                            query.append(String.valueOf(primaryKey));
10451    
10452                            query.append(StringPool.COMMA);
10453                    }
10454    
10455                    query.setIndex(query.index() - 1);
10456    
10457                    query.append(StringPool.CLOSE_PARENTHESIS);
10458    
10459                    String sql = query.toString();
10460    
10461                    Session session = null;
10462    
10463                    try {
10464                            session = openSession();
10465    
10466                            Query q = session.createQuery(sql);
10467    
10468                            for (MBCategory mbCategory : (List<MBCategory>)q.list()) {
10469                                    map.put(mbCategory.getPrimaryKeyObj(), mbCategory);
10470    
10471                                    cacheResult(mbCategory);
10472    
10473                                    uncachedPrimaryKeys.remove(mbCategory.getPrimaryKeyObj());
10474                            }
10475    
10476                            for (Serializable primaryKey : uncachedPrimaryKeys) {
10477                                    entityCache.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
10478                                            MBCategoryImpl.class, primaryKey, _nullMBCategory);
10479                            }
10480                    }
10481                    catch (Exception e) {
10482                            throw processException(e);
10483                    }
10484                    finally {
10485                            closeSession(session);
10486                    }
10487    
10488                    return map;
10489            }
10490    
10491            /**
10492             * Returns all the message boards categories.
10493             *
10494             * @return the message boards categories
10495             */
10496            @Override
10497            public List<MBCategory> findAll() {
10498                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
10499            }
10500    
10501            /**
10502             * Returns a range of all the message boards categories.
10503             *
10504             * <p>
10505             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
10506             * </p>
10507             *
10508             * @param start the lower bound of the range of message boards categories
10509             * @param end the upper bound of the range of message boards categories (not inclusive)
10510             * @return the range of message boards categories
10511             */
10512            @Override
10513            public List<MBCategory> findAll(int start, int end) {
10514                    return findAll(start, end, null);
10515            }
10516    
10517            /**
10518             * Returns an ordered range of all the message boards categories.
10519             *
10520             * <p>
10521             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
10522             * </p>
10523             *
10524             * @param start the lower bound of the range of message boards categories
10525             * @param end the upper bound of the range of message boards categories (not inclusive)
10526             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10527             * @return the ordered range of message boards categories
10528             */
10529            @Override
10530            public List<MBCategory> findAll(int start, int end,
10531                    OrderByComparator<MBCategory> orderByComparator) {
10532                    return findAll(start, end, orderByComparator, true);
10533            }
10534    
10535            /**
10536             * Returns an ordered range of all the message boards categories.
10537             *
10538             * <p>
10539             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link MBCategoryModelImpl}. 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.
10540             * </p>
10541             *
10542             * @param start the lower bound of the range of message boards categories
10543             * @param end the upper bound of the range of message boards categories (not inclusive)
10544             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10545             * @param retrieveFromCache whether to retrieve from the finder cache
10546             * @return the ordered range of message boards categories
10547             */
10548            @Override
10549            public List<MBCategory> findAll(int start, int end,
10550                    OrderByComparator<MBCategory> orderByComparator,
10551                    boolean retrieveFromCache) {
10552                    boolean pagination = true;
10553                    FinderPath finderPath = null;
10554                    Object[] finderArgs = null;
10555    
10556                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10557                                    (orderByComparator == null)) {
10558                            pagination = false;
10559                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
10560                            finderArgs = FINDER_ARGS_EMPTY;
10561                    }
10562                    else {
10563                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
10564                            finderArgs = new Object[] { start, end, orderByComparator };
10565                    }
10566    
10567                    List<MBCategory> list = null;
10568    
10569                    if (retrieveFromCache) {
10570                            list = (List<MBCategory>)finderCache.getResult(finderPath,
10571                                            finderArgs, this);
10572                    }
10573    
10574                    if (list == null) {
10575                            StringBundler query = null;
10576                            String sql = null;
10577    
10578                            if (orderByComparator != null) {
10579                                    query = new StringBundler(2 +
10580                                                    (orderByComparator.getOrderByFields().length * 3));
10581    
10582                                    query.append(_SQL_SELECT_MBCATEGORY);
10583    
10584                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10585                                            orderByComparator);
10586    
10587                                    sql = query.toString();
10588                            }
10589                            else {
10590                                    sql = _SQL_SELECT_MBCATEGORY;
10591    
10592                                    if (pagination) {
10593                                            sql = sql.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
10594                                    }
10595                            }
10596    
10597                            Session session = null;
10598    
10599                            try {
10600                                    session = openSession();
10601    
10602                                    Query q = session.createQuery(sql);
10603    
10604                                    if (!pagination) {
10605                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
10606                                                            start, end, false);
10607    
10608                                            Collections.sort(list);
10609    
10610                                            list = Collections.unmodifiableList(list);
10611                                    }
10612                                    else {
10613                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
10614                                                            start, end);
10615                                    }
10616    
10617                                    cacheResult(list);
10618    
10619                                    finderCache.putResult(finderPath, finderArgs, list);
10620                            }
10621                            catch (Exception e) {
10622                                    finderCache.removeResult(finderPath, finderArgs);
10623    
10624                                    throw processException(e);
10625                            }
10626                            finally {
10627                                    closeSession(session);
10628                            }
10629                    }
10630    
10631                    return list;
10632            }
10633    
10634            /**
10635             * Removes all the message boards categories from the database.
10636             *
10637             */
10638            @Override
10639            public void removeAll() {
10640                    for (MBCategory mbCategory : findAll()) {
10641                            remove(mbCategory);
10642                    }
10643            }
10644    
10645            /**
10646             * Returns the number of message boards categories.
10647             *
10648             * @return the number of message boards categories
10649             */
10650            @Override
10651            public int countAll() {
10652                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
10653                                    FINDER_ARGS_EMPTY, this);
10654    
10655                    if (count == null) {
10656                            Session session = null;
10657    
10658                            try {
10659                                    session = openSession();
10660    
10661                                    Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
10662    
10663                                    count = (Long)q.uniqueResult();
10664    
10665                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
10666                                            count);
10667                            }
10668                            catch (Exception e) {
10669                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
10670                                            FINDER_ARGS_EMPTY);
10671    
10672                                    throw processException(e);
10673                            }
10674                            finally {
10675                                    closeSession(session);
10676                            }
10677                    }
10678    
10679                    return count.intValue();
10680            }
10681    
10682            @Override
10683            public Set<String> getBadColumnNames() {
10684                    return _badColumnNames;
10685            }
10686    
10687            @Override
10688            protected Map<String, Integer> getTableColumnsMap() {
10689                    return MBCategoryModelImpl.TABLE_COLUMNS_MAP;
10690            }
10691    
10692            /**
10693             * Initializes the message boards category persistence.
10694             */
10695            public void afterPropertiesSet() {
10696            }
10697    
10698            public void destroy() {
10699                    entityCache.removeCache(MBCategoryImpl.class.getName());
10700                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
10701                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
10702                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
10703            }
10704    
10705            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
10706            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
10707            private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
10708            private static final String _SQL_SELECT_MBCATEGORY_WHERE_PKS_IN = "SELECT mbCategory FROM MBCategory mbCategory WHERE categoryId IN (";
10709            private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
10710            private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
10711            private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
10712            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbCategory.categoryId";
10713            private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
10714            private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
10715                    "SELECT {MBCategory.*} FROM (SELECT DISTINCT mbCategory.categoryId FROM MBCategory mbCategory WHERE ";
10716            private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
10717                    ") TEMP_TABLE INNER JOIN MBCategory ON TEMP_TABLE.categoryId = MBCategory.categoryId";
10718            private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
10719            private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
10720            private static final String _FILTER_ENTITY_TABLE = "MBCategory";
10721            private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
10722            private static final String _ORDER_BY_ENTITY_TABLE = "MBCategory.";
10723            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
10724            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
10725            private static final Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
10726            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
10727                                    "uuid"
10728                            });
10729            private static final MBCategory _nullMBCategory = new MBCategoryImpl() {
10730                            @Override
10731                            public Object clone() {
10732                                    return this;
10733                            }
10734    
10735                            @Override
10736                            public CacheModel<MBCategory> toCacheModel() {
10737                                    return _nullMBCategoryCacheModel;
10738                            }
10739                    };
10740    
10741            private static final CacheModel<MBCategory> _nullMBCategoryCacheModel = new CacheModel<MBCategory>() {
10742                            @Override
10743                            public MBCategory toEntityModel() {
10744                                    return _nullMBCategory;
10745                            }
10746                    };
10747    }