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