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