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