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