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