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