001    /**
002     * Copyright (c) 2000-2013 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;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.ArrayUtil;
030    import com.liferay.portal.kernel.util.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.SetUtil;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.UnmodifiableList;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.ModelListener;
042    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.messageboards.NoSuchCategoryException;
046    import com.liferay.portlet.messageboards.model.MBCategory;
047    import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
048    import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
049    
050    import java.io.Serializable;
051    
052    import java.util.ArrayList;
053    import java.util.Collections;
054    import java.util.List;
055    import java.util.Set;
056    
057    /**
058     * The persistence implementation for the message boards category service.
059     *
060     * <p>
061     * Caching information and settings can be found in <code>portal.properties</code>
062     * </p>
063     *
064     * @author Brian Wing Shun Chan
065     * @see MBCategoryPersistence
066     * @see MBCategoryUtil
067     * @generated
068     */
069    public class MBCategoryPersistenceImpl extends BasePersistenceImpl<MBCategory>
070            implements MBCategoryPersistence {
071            /*
072             * NOTE FOR DEVELOPERS:
073             *
074             * 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.
075             */
076            public static final String FINDER_CLASS_NAME_ENTITY = MBCategoryImpl.class.getName();
077            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
078                    ".List1";
079            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
080                    ".List2";
081            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
082                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
083                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
084            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
085                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
088                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
090            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
091                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
092                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
093                            new String[] {
094                                    String.class.getName(),
095                                    
096                            Integer.class.getName(), Integer.class.getName(),
097                                    OrderByComparator.class.getName()
098                            });
099            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
100                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
102                            new String[] { String.class.getName() },
103                            MBCategoryModelImpl.UUID_COLUMN_BITMASK |
104                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
105                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
107                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
109                            new String[] { String.class.getName() });
110    
111            /**
112             * Returns all the message boards categories where uuid = &#63;.
113             *
114             * @param uuid the uuid
115             * @return the matching message boards categories
116             * @throws SystemException if a system exception occurred
117             */
118            @Override
119            public List<MBCategory> findByUuid(String uuid) throws SystemException {
120                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
121            }
122    
123            /**
124             * Returns a range of all the message boards categories where uuid = &#63;.
125             *
126             * <p>
127             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
128             * </p>
129             *
130             * @param uuid the uuid
131             * @param start the lower bound of the range of message boards categories
132             * @param end the upper bound of the range of message boards categories (not inclusive)
133             * @return the range of matching message boards categories
134             * @throws SystemException if a system exception occurred
135             */
136            @Override
137            public List<MBCategory> findByUuid(String uuid, int start, int end)
138                    throws SystemException {
139                    return findByUuid(uuid, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the message boards categories where uuid = &#63;.
144             *
145             * <p>
146             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
147             * </p>
148             *
149             * @param uuid the uuid
150             * @param start the lower bound of the range of message boards categories
151             * @param end the upper bound of the range of message boards categories (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching message boards categories
154             * @throws SystemException if a system exception occurred
155             */
156            @Override
157            public List<MBCategory> findByUuid(String uuid, int start, int end,
158                    OrderByComparator orderByComparator) throws SystemException {
159                    boolean pagination = true;
160                    FinderPath finderPath = null;
161                    Object[] finderArgs = null;
162    
163                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
164                                    (orderByComparator == null)) {
165                            pagination = false;
166                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
167                            finderArgs = new Object[] { uuid };
168                    }
169                    else {
170                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
171                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
172                    }
173    
174                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
175                                    finderArgs, this);
176    
177                    if ((list != null) && !list.isEmpty()) {
178                            for (MBCategory mbCategory : list) {
179                                    if (!Validator.equals(uuid, mbCategory.getUuid())) {
180                                            list = null;
181    
182                                            break;
183                                    }
184                            }
185                    }
186    
187                    if (list == null) {
188                            StringBundler query = null;
189    
190                            if (orderByComparator != null) {
191                                    query = new StringBundler(3 +
192                                                    (orderByComparator.getOrderByFields().length * 3));
193                            }
194                            else {
195                                    query = new StringBundler(3);
196                            }
197    
198                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
199    
200                            boolean bindUuid = false;
201    
202                            if (uuid == null) {
203                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
204                            }
205                            else if (uuid.equals(StringPool.BLANK)) {
206                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
207                            }
208                            else {
209                                    bindUuid = true;
210    
211                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
212                            }
213    
214                            if (orderByComparator != null) {
215                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
216                                            orderByComparator);
217                            }
218                            else
219                             if (pagination) {
220                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
221                            }
222    
223                            String sql = query.toString();
224    
225                            Session session = null;
226    
227                            try {
228                                    session = openSession();
229    
230                                    Query q = session.createQuery(sql);
231    
232                                    QueryPos qPos = QueryPos.getInstance(q);
233    
234                                    if (bindUuid) {
235                                            qPos.add(uuid);
236                                    }
237    
238                                    if (!pagination) {
239                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
240                                                            start, end, false);
241    
242                                            Collections.sort(list);
243    
244                                            list = new UnmodifiableList<MBCategory>(list);
245                                    }
246                                    else {
247                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
248                                                            start, end);
249                                    }
250    
251                                    cacheResult(list);
252    
253                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
254                            }
255                            catch (Exception e) {
256                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
257    
258                                    throw processException(e);
259                            }
260                            finally {
261                                    closeSession(session);
262                            }
263                    }
264    
265                    return list;
266            }
267    
268            /**
269             * Returns the first message boards category in the ordered set where uuid = &#63;.
270             *
271             * @param uuid the uuid
272             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
273             * @return the first matching message boards category
274             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
275             * @throws SystemException if a system exception occurred
276             */
277            @Override
278            public MBCategory findByUuid_First(String uuid,
279                    OrderByComparator orderByComparator)
280                    throws NoSuchCategoryException, SystemException {
281                    MBCategory mbCategory = fetchByUuid_First(uuid, orderByComparator);
282    
283                    if (mbCategory != null) {
284                            return mbCategory;
285                    }
286    
287                    StringBundler msg = new StringBundler(4);
288    
289                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
290    
291                    msg.append("uuid=");
292                    msg.append(uuid);
293    
294                    msg.append(StringPool.CLOSE_CURLY_BRACE);
295    
296                    throw new NoSuchCategoryException(msg.toString());
297            }
298    
299            /**
300             * Returns the first message boards category in the ordered set where uuid = &#63;.
301             *
302             * @param uuid the uuid
303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
304             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
305             * @throws SystemException if a system exception occurred
306             */
307            @Override
308            public MBCategory fetchByUuid_First(String uuid,
309                    OrderByComparator orderByComparator) throws SystemException {
310                    List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
311    
312                    if (!list.isEmpty()) {
313                            return list.get(0);
314                    }
315    
316                    return null;
317            }
318    
319            /**
320             * Returns the last message boards category in the ordered set where uuid = &#63;.
321             *
322             * @param uuid the uuid
323             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
324             * @return the last matching message boards category
325             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
326             * @throws SystemException if a system exception occurred
327             */
328            @Override
329            public MBCategory findByUuid_Last(String uuid,
330                    OrderByComparator orderByComparator)
331                    throws NoSuchCategoryException, SystemException {
332                    MBCategory mbCategory = fetchByUuid_Last(uuid, orderByComparator);
333    
334                    if (mbCategory != null) {
335                            return mbCategory;
336                    }
337    
338                    StringBundler msg = new StringBundler(4);
339    
340                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
341    
342                    msg.append("uuid=");
343                    msg.append(uuid);
344    
345                    msg.append(StringPool.CLOSE_CURLY_BRACE);
346    
347                    throw new NoSuchCategoryException(msg.toString());
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, or <code>null</code> if a matching message boards category could not be found
356             * @throws SystemException if a system exception occurred
357             */
358            @Override
359            public MBCategory fetchByUuid_Last(String uuid,
360                    OrderByComparator orderByComparator) throws SystemException {
361                    int count = countByUuid(uuid);
362    
363                    if (count == 0) {
364                            return null;
365                    }
366    
367                    List<MBCategory> list = findByUuid(uuid, count - 1, count,
368                                    orderByComparator);
369    
370                    if (!list.isEmpty()) {
371                            return list.get(0);
372                    }
373    
374                    return null;
375            }
376    
377            /**
378             * Returns the message boards categories before and after the current message boards category in the ordered set where uuid = &#63;.
379             *
380             * @param categoryId the primary key of the current message boards category
381             * @param uuid the uuid
382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
383             * @return the previous, current, and next message boards category
384             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
385             * @throws SystemException if a system exception occurred
386             */
387            @Override
388            public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
389                    OrderByComparator orderByComparator)
390                    throws NoSuchCategoryException, SystemException {
391                    MBCategory mbCategory = findByPrimaryKey(categoryId);
392    
393                    Session session = null;
394    
395                    try {
396                            session = openSession();
397    
398                            MBCategory[] array = new MBCategoryImpl[3];
399    
400                            array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
401                                            orderByComparator, true);
402    
403                            array[1] = mbCategory;
404    
405                            array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
406                                            orderByComparator, false);
407    
408                            return array;
409                    }
410                    catch (Exception e) {
411                            throw processException(e);
412                    }
413                    finally {
414                            closeSession(session);
415                    }
416            }
417    
418            protected MBCategory getByUuid_PrevAndNext(Session session,
419                    MBCategory mbCategory, String uuid,
420                    OrderByComparator orderByComparator, boolean previous) {
421                    StringBundler query = null;
422    
423                    if (orderByComparator != null) {
424                            query = new StringBundler(6 +
425                                            (orderByComparator.getOrderByFields().length * 6));
426                    }
427                    else {
428                            query = new StringBundler(3);
429                    }
430    
431                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
432    
433                    boolean bindUuid = false;
434    
435                    if (uuid == null) {
436                            query.append(_FINDER_COLUMN_UUID_UUID_1);
437                    }
438                    else if (uuid.equals(StringPool.BLANK)) {
439                            query.append(_FINDER_COLUMN_UUID_UUID_3);
440                    }
441                    else {
442                            bindUuid = true;
443    
444                            query.append(_FINDER_COLUMN_UUID_UUID_2);
445                    }
446    
447                    if (orderByComparator != null) {
448                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
449    
450                            if (orderByConditionFields.length > 0) {
451                                    query.append(WHERE_AND);
452                            }
453    
454                            for (int i = 0; i < orderByConditionFields.length; i++) {
455                                    query.append(_ORDER_BY_ENTITY_ALIAS);
456                                    query.append(orderByConditionFields[i]);
457    
458                                    if ((i + 1) < orderByConditionFields.length) {
459                                            if (orderByComparator.isAscending() ^ previous) {
460                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
461                                            }
462                                            else {
463                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
464                                            }
465                                    }
466                                    else {
467                                            if (orderByComparator.isAscending() ^ previous) {
468                                                    query.append(WHERE_GREATER_THAN);
469                                            }
470                                            else {
471                                                    query.append(WHERE_LESSER_THAN);
472                                            }
473                                    }
474                            }
475    
476                            query.append(ORDER_BY_CLAUSE);
477    
478                            String[] orderByFields = orderByComparator.getOrderByFields();
479    
480                            for (int i = 0; i < orderByFields.length; i++) {
481                                    query.append(_ORDER_BY_ENTITY_ALIAS);
482                                    query.append(orderByFields[i]);
483    
484                                    if ((i + 1) < orderByFields.length) {
485                                            if (orderByComparator.isAscending() ^ previous) {
486                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
487                                            }
488                                            else {
489                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
490                                            }
491                                    }
492                                    else {
493                                            if (orderByComparator.isAscending() ^ previous) {
494                                                    query.append(ORDER_BY_ASC);
495                                            }
496                                            else {
497                                                    query.append(ORDER_BY_DESC);
498                                            }
499                                    }
500                            }
501                    }
502                    else {
503                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
504                    }
505    
506                    String sql = query.toString();
507    
508                    Query q = session.createQuery(sql);
509    
510                    q.setFirstResult(0);
511                    q.setMaxResults(2);
512    
513                    QueryPos qPos = QueryPos.getInstance(q);
514    
515                    if (bindUuid) {
516                            qPos.add(uuid);
517                    }
518    
519                    if (orderByComparator != null) {
520                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
521    
522                            for (Object value : values) {
523                                    qPos.add(value);
524                            }
525                    }
526    
527                    List<MBCategory> list = q.list();
528    
529                    if (list.size() == 2) {
530                            return list.get(1);
531                    }
532                    else {
533                            return null;
534                    }
535            }
536    
537            /**
538             * Removes all the message boards categories where uuid = &#63; from the database.
539             *
540             * @param uuid the uuid
541             * @throws SystemException if a system exception occurred
542             */
543            @Override
544            public void removeByUuid(String uuid) throws SystemException {
545                    for (MBCategory mbCategory : findByUuid(uuid, QueryUtil.ALL_POS,
546                                    QueryUtil.ALL_POS, null)) {
547                            remove(mbCategory);
548                    }
549            }
550    
551            /**
552             * Returns the number of message boards categories where uuid = &#63;.
553             *
554             * @param uuid the uuid
555             * @return the number of matching message boards categories
556             * @throws SystemException if a system exception occurred
557             */
558            @Override
559            public int countByUuid(String uuid) throws SystemException {
560                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
561    
562                    Object[] finderArgs = new Object[] { uuid };
563    
564                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
565                                    this);
566    
567                    if (count == null) {
568                            StringBundler query = new StringBundler(2);
569    
570                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
571    
572                            boolean bindUuid = false;
573    
574                            if (uuid == null) {
575                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
576                            }
577                            else if (uuid.equals(StringPool.BLANK)) {
578                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
579                            }
580                            else {
581                                    bindUuid = true;
582    
583                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
584                            }
585    
586                            String sql = query.toString();
587    
588                            Session session = null;
589    
590                            try {
591                                    session = openSession();
592    
593                                    Query q = session.createQuery(sql);
594    
595                                    QueryPos qPos = QueryPos.getInstance(q);
596    
597                                    if (bindUuid) {
598                                            qPos.add(uuid);
599                                    }
600    
601                                    count = (Long)q.uniqueResult();
602    
603                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
604                            }
605                            catch (Exception e) {
606                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
607    
608                                    throw processException(e);
609                            }
610                            finally {
611                                    closeSession(session);
612                            }
613                    }
614    
615                    return count.intValue();
616            }
617    
618            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
619            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
620            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '')";
621            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
622                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
623                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
624                            new String[] { String.class.getName(), Long.class.getName() },
625                            MBCategoryModelImpl.UUID_COLUMN_BITMASK |
626                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK);
627            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
628                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
629                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
630                            new String[] { String.class.getName(), Long.class.getName() });
631    
632            /**
633             * Returns the message boards category where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchCategoryException} if it could not be found.
634             *
635             * @param uuid the uuid
636             * @param groupId the group ID
637             * @return the matching message boards category
638             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
639             * @throws SystemException if a system exception occurred
640             */
641            @Override
642            public MBCategory findByUUID_G(String uuid, long groupId)
643                    throws NoSuchCategoryException, SystemException {
644                    MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
645    
646                    if (mbCategory == null) {
647                            StringBundler msg = new StringBundler(6);
648    
649                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
650    
651                            msg.append("uuid=");
652                            msg.append(uuid);
653    
654                            msg.append(", groupId=");
655                            msg.append(groupId);
656    
657                            msg.append(StringPool.CLOSE_CURLY_BRACE);
658    
659                            if (_log.isWarnEnabled()) {
660                                    _log.warn(msg.toString());
661                            }
662    
663                            throw new NoSuchCategoryException(msg.toString());
664                    }
665    
666                    return mbCategory;
667            }
668    
669            /**
670             * 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.
671             *
672             * @param uuid the uuid
673             * @param groupId the group ID
674             * @return the matching message boards category, or <code>null</code> if a matching message boards category could not be found
675             * @throws SystemException if a system exception occurred
676             */
677            @Override
678            public MBCategory fetchByUUID_G(String uuid, long groupId)
679                    throws SystemException {
680                    return fetchByUUID_G(uuid, groupId, true);
681            }
682    
683            /**
684             * 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.
685             *
686             * @param uuid the uuid
687             * @param groupId the group ID
688             * @param retrieveFromCache whether to use the finder cache
689             * @return the matching message boards category, or <code>null</code> if a matching message boards category could not be found
690             * @throws SystemException if a system exception occurred
691             */
692            @Override
693            public MBCategory fetchByUUID_G(String uuid, long groupId,
694                    boolean retrieveFromCache) throws SystemException {
695                    Object[] finderArgs = new Object[] { uuid, groupId };
696    
697                    Object result = null;
698    
699                    if (retrieveFromCache) {
700                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
701                                            finderArgs, this);
702                    }
703    
704                    if (result instanceof MBCategory) {
705                            MBCategory mbCategory = (MBCategory)result;
706    
707                            if (!Validator.equals(uuid, mbCategory.getUuid()) ||
708                                            (groupId != mbCategory.getGroupId())) {
709                                    result = null;
710                            }
711                    }
712    
713                    if (result == null) {
714                            StringBundler query = new StringBundler(4);
715    
716                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
717    
718                            boolean bindUuid = false;
719    
720                            if (uuid == null) {
721                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
722                            }
723                            else if (uuid.equals(StringPool.BLANK)) {
724                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
725                            }
726                            else {
727                                    bindUuid = true;
728    
729                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
730                            }
731    
732                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
733    
734                            String sql = query.toString();
735    
736                            Session session = null;
737    
738                            try {
739                                    session = openSession();
740    
741                                    Query q = session.createQuery(sql);
742    
743                                    QueryPos qPos = QueryPos.getInstance(q);
744    
745                                    if (bindUuid) {
746                                            qPos.add(uuid);
747                                    }
748    
749                                    qPos.add(groupId);
750    
751                                    List<MBCategory> list = q.list();
752    
753                                    if (list.isEmpty()) {
754                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
755                                                    finderArgs, list);
756                                    }
757                                    else {
758                                            MBCategory mbCategory = list.get(0);
759    
760                                            result = mbCategory;
761    
762                                            cacheResult(mbCategory);
763    
764                                            if ((mbCategory.getUuid() == null) ||
765                                                            !mbCategory.getUuid().equals(uuid) ||
766                                                            (mbCategory.getGroupId() != groupId)) {
767                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
768                                                            finderArgs, mbCategory);
769                                            }
770                                    }
771                            }
772                            catch (Exception e) {
773                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
774                                            finderArgs);
775    
776                                    throw processException(e);
777                            }
778                            finally {
779                                    closeSession(session);
780                            }
781                    }
782    
783                    if (result instanceof List<?>) {
784                            return null;
785                    }
786                    else {
787                            return (MBCategory)result;
788                    }
789            }
790    
791            /**
792             * Removes the message boards category where uuid = &#63; and groupId = &#63; from the database.
793             *
794             * @param uuid the uuid
795             * @param groupId the group ID
796             * @return the message boards category that was removed
797             * @throws SystemException if a system exception occurred
798             */
799            @Override
800            public MBCategory removeByUUID_G(String uuid, long groupId)
801                    throws NoSuchCategoryException, SystemException {
802                    MBCategory mbCategory = findByUUID_G(uuid, groupId);
803    
804                    return remove(mbCategory);
805            }
806    
807            /**
808             * Returns the number of message boards categories where uuid = &#63; and groupId = &#63;.
809             *
810             * @param uuid the uuid
811             * @param groupId the group ID
812             * @return the number of matching message boards categories
813             * @throws SystemException if a system exception occurred
814             */
815            @Override
816            public int countByUUID_G(String uuid, long groupId)
817                    throws SystemException {
818                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
819    
820                    Object[] finderArgs = new Object[] { uuid, groupId };
821    
822                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
823                                    this);
824    
825                    if (count == null) {
826                            StringBundler query = new StringBundler(3);
827    
828                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
829    
830                            boolean bindUuid = false;
831    
832                            if (uuid == null) {
833                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
834                            }
835                            else if (uuid.equals(StringPool.BLANK)) {
836                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
837                            }
838                            else {
839                                    bindUuid = true;
840    
841                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
842                            }
843    
844                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
845    
846                            String sql = query.toString();
847    
848                            Session session = null;
849    
850                            try {
851                                    session = openSession();
852    
853                                    Query q = session.createQuery(sql);
854    
855                                    QueryPos qPos = QueryPos.getInstance(q);
856    
857                                    if (bindUuid) {
858                                            qPos.add(uuid);
859                                    }
860    
861                                    qPos.add(groupId);
862    
863                                    count = (Long)q.uniqueResult();
864    
865                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
866                            }
867                            catch (Exception e) {
868                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
869    
870                                    throw processException(e);
871                            }
872                            finally {
873                                    closeSession(session);
874                            }
875                    }
876    
877                    return count.intValue();
878            }
879    
880            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
881            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
882            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '') AND ";
883            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
884            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
885                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
886                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
887                            new String[] {
888                                    String.class.getName(), Long.class.getName(),
889                                    
890                            Integer.class.getName(), Integer.class.getName(),
891                                    OrderByComparator.class.getName()
892                            });
893            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
894                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
895                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
896                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
897                            new String[] { String.class.getName(), Long.class.getName() },
898                            MBCategoryModelImpl.UUID_COLUMN_BITMASK |
899                            MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
900                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
901                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
902            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
903                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
904                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
905                            new String[] { String.class.getName(), Long.class.getName() });
906    
907            /**
908             * Returns all the message boards categories where uuid = &#63; and companyId = &#63;.
909             *
910             * @param uuid the uuid
911             * @param companyId the company ID
912             * @return the matching message boards categories
913             * @throws SystemException if a system exception occurred
914             */
915            @Override
916            public List<MBCategory> findByUuid_C(String uuid, long companyId)
917                    throws SystemException {
918                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
919                            QueryUtil.ALL_POS, null);
920            }
921    
922            /**
923             * Returns a range of all the message boards categories where uuid = &#63; and companyId = &#63;.
924             *
925             * <p>
926             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
927             * </p>
928             *
929             * @param uuid the uuid
930             * @param companyId the company ID
931             * @param start the lower bound of the range of message boards categories
932             * @param end the upper bound of the range of message boards categories (not inclusive)
933             * @return the range of matching message boards categories
934             * @throws SystemException if a system exception occurred
935             */
936            @Override
937            public List<MBCategory> findByUuid_C(String uuid, long companyId,
938                    int start, int end) throws SystemException {
939                    return findByUuid_C(uuid, companyId, start, end, null);
940            }
941    
942            /**
943             * Returns an ordered range of all the message boards categories where uuid = &#63; and companyId = &#63;.
944             *
945             * <p>
946             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
947             * </p>
948             *
949             * @param uuid the uuid
950             * @param companyId the company ID
951             * @param start the lower bound of the range of message boards categories
952             * @param end the upper bound of the range of message boards categories (not inclusive)
953             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
954             * @return the ordered range of matching message boards categories
955             * @throws SystemException if a system exception occurred
956             */
957            @Override
958            public List<MBCategory> findByUuid_C(String uuid, long companyId,
959                    int start, int end, OrderByComparator orderByComparator)
960                    throws SystemException {
961                    boolean pagination = true;
962                    FinderPath finderPath = null;
963                    Object[] finderArgs = null;
964    
965                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
966                                    (orderByComparator == null)) {
967                            pagination = false;
968                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
969                            finderArgs = new Object[] { uuid, companyId };
970                    }
971                    else {
972                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
973                            finderArgs = new Object[] {
974                                            uuid, companyId,
975                                            
976                                            start, end, orderByComparator
977                                    };
978                    }
979    
980                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
981                                    finderArgs, this);
982    
983                    if ((list != null) && !list.isEmpty()) {
984                            for (MBCategory mbCategory : list) {
985                                    if (!Validator.equals(uuid, mbCategory.getUuid()) ||
986                                                    (companyId != mbCategory.getCompanyId())) {
987                                            list = null;
988    
989                                            break;
990                                    }
991                            }
992                    }
993    
994                    if (list == null) {
995                            StringBundler query = null;
996    
997                            if (orderByComparator != null) {
998                                    query = new StringBundler(4 +
999                                                    (orderByComparator.getOrderByFields().length * 3));
1000                            }
1001                            else {
1002                                    query = new StringBundler(4);
1003                            }
1004    
1005                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1006    
1007                            boolean bindUuid = false;
1008    
1009                            if (uuid == null) {
1010                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1011                            }
1012                            else if (uuid.equals(StringPool.BLANK)) {
1013                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1014                            }
1015                            else {
1016                                    bindUuid = true;
1017    
1018                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1019                            }
1020    
1021                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1022    
1023                            if (orderByComparator != null) {
1024                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1025                                            orderByComparator);
1026                            }
1027                            else
1028                             if (pagination) {
1029                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1030                            }
1031    
1032                            String sql = query.toString();
1033    
1034                            Session session = null;
1035    
1036                            try {
1037                                    session = openSession();
1038    
1039                                    Query q = session.createQuery(sql);
1040    
1041                                    QueryPos qPos = QueryPos.getInstance(q);
1042    
1043                                    if (bindUuid) {
1044                                            qPos.add(uuid);
1045                                    }
1046    
1047                                    qPos.add(companyId);
1048    
1049                                    if (!pagination) {
1050                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1051                                                            start, end, false);
1052    
1053                                            Collections.sort(list);
1054    
1055                                            list = new UnmodifiableList<MBCategory>(list);
1056                                    }
1057                                    else {
1058                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1059                                                            start, end);
1060                                    }
1061    
1062                                    cacheResult(list);
1063    
1064                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1065                            }
1066                            catch (Exception e) {
1067                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1068    
1069                                    throw processException(e);
1070                            }
1071                            finally {
1072                                    closeSession(session);
1073                            }
1074                    }
1075    
1076                    return list;
1077            }
1078    
1079            /**
1080             * Returns the first message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1081             *
1082             * @param uuid the uuid
1083             * @param companyId the company ID
1084             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1085             * @return the first matching message boards category
1086             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1087             * @throws SystemException if a system exception occurred
1088             */
1089            @Override
1090            public MBCategory findByUuid_C_First(String uuid, long companyId,
1091                    OrderByComparator orderByComparator)
1092                    throws NoSuchCategoryException, SystemException {
1093                    MBCategory mbCategory = fetchByUuid_C_First(uuid, companyId,
1094                                    orderByComparator);
1095    
1096                    if (mbCategory != null) {
1097                            return mbCategory;
1098                    }
1099    
1100                    StringBundler msg = new StringBundler(6);
1101    
1102                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1103    
1104                    msg.append("uuid=");
1105                    msg.append(uuid);
1106    
1107                    msg.append(", companyId=");
1108                    msg.append(companyId);
1109    
1110                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1111    
1112                    throw new NoSuchCategoryException(msg.toString());
1113            }
1114    
1115            /**
1116             * Returns the first message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1117             *
1118             * @param uuid the uuid
1119             * @param companyId the company ID
1120             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1121             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
1122             * @throws SystemException if a system exception occurred
1123             */
1124            @Override
1125            public MBCategory fetchByUuid_C_First(String uuid, long companyId,
1126                    OrderByComparator orderByComparator) throws SystemException {
1127                    List<MBCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1128                                    orderByComparator);
1129    
1130                    if (!list.isEmpty()) {
1131                            return list.get(0);
1132                    }
1133    
1134                    return null;
1135            }
1136    
1137            /**
1138             * Returns the last message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1139             *
1140             * @param uuid the uuid
1141             * @param companyId the company ID
1142             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1143             * @return the last matching message boards category
1144             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1145             * @throws SystemException if a system exception occurred
1146             */
1147            @Override
1148            public MBCategory findByUuid_C_Last(String uuid, long companyId,
1149                    OrderByComparator orderByComparator)
1150                    throws NoSuchCategoryException, SystemException {
1151                    MBCategory mbCategory = fetchByUuid_C_Last(uuid, companyId,
1152                                    orderByComparator);
1153    
1154                    if (mbCategory != null) {
1155                            return mbCategory;
1156                    }
1157    
1158                    StringBundler msg = new StringBundler(6);
1159    
1160                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1161    
1162                    msg.append("uuid=");
1163                    msg.append(uuid);
1164    
1165                    msg.append(", companyId=");
1166                    msg.append(companyId);
1167    
1168                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1169    
1170                    throw new NoSuchCategoryException(msg.toString());
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, or <code>null</code> if a matching message boards category could not be found
1180             * @throws SystemException if a system exception occurred
1181             */
1182            @Override
1183            public MBCategory fetchByUuid_C_Last(String uuid, long companyId,
1184                    OrderByComparator orderByComparator) throws SystemException {
1185                    int count = countByUuid_C(uuid, companyId);
1186    
1187                    if (count == 0) {
1188                            return null;
1189                    }
1190    
1191                    List<MBCategory> list = findByUuid_C(uuid, companyId, count - 1, count,
1192                                    orderByComparator);
1193    
1194                    if (!list.isEmpty()) {
1195                            return list.get(0);
1196                    }
1197    
1198                    return null;
1199            }
1200    
1201            /**
1202             * Returns the message boards categories before and after the current message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1203             *
1204             * @param categoryId the primary key of the current message boards category
1205             * @param uuid the uuid
1206             * @param companyId the company ID
1207             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1208             * @return the previous, current, and next message boards category
1209             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
1210             * @throws SystemException if a system exception occurred
1211             */
1212            @Override
1213            public MBCategory[] findByUuid_C_PrevAndNext(long categoryId, String uuid,
1214                    long companyId, OrderByComparator orderByComparator)
1215                    throws NoSuchCategoryException, SystemException {
1216                    MBCategory mbCategory = findByPrimaryKey(categoryId);
1217    
1218                    Session session = null;
1219    
1220                    try {
1221                            session = openSession();
1222    
1223                            MBCategory[] array = new MBCategoryImpl[3];
1224    
1225                            array[0] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1226                                            companyId, orderByComparator, true);
1227    
1228                            array[1] = mbCategory;
1229    
1230                            array[2] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1231                                            companyId, orderByComparator, false);
1232    
1233                            return array;
1234                    }
1235                    catch (Exception e) {
1236                            throw processException(e);
1237                    }
1238                    finally {
1239                            closeSession(session);
1240                    }
1241            }
1242    
1243            protected MBCategory getByUuid_C_PrevAndNext(Session session,
1244                    MBCategory mbCategory, String uuid, long companyId,
1245                    OrderByComparator orderByComparator, boolean previous) {
1246                    StringBundler query = null;
1247    
1248                    if (orderByComparator != null) {
1249                            query = new StringBundler(6 +
1250                                            (orderByComparator.getOrderByFields().length * 6));
1251                    }
1252                    else {
1253                            query = new StringBundler(3);
1254                    }
1255    
1256                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1257    
1258                    boolean bindUuid = false;
1259    
1260                    if (uuid == null) {
1261                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1262                    }
1263                    else if (uuid.equals(StringPool.BLANK)) {
1264                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1265                    }
1266                    else {
1267                            bindUuid = true;
1268    
1269                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1270                    }
1271    
1272                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1273    
1274                    if (orderByComparator != null) {
1275                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1276    
1277                            if (orderByConditionFields.length > 0) {
1278                                    query.append(WHERE_AND);
1279                            }
1280    
1281                            for (int i = 0; i < orderByConditionFields.length; i++) {
1282                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1283                                    query.append(orderByConditionFields[i]);
1284    
1285                                    if ((i + 1) < orderByConditionFields.length) {
1286                                            if (orderByComparator.isAscending() ^ previous) {
1287                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1288                                            }
1289                                            else {
1290                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1291                                            }
1292                                    }
1293                                    else {
1294                                            if (orderByComparator.isAscending() ^ previous) {
1295                                                    query.append(WHERE_GREATER_THAN);
1296                                            }
1297                                            else {
1298                                                    query.append(WHERE_LESSER_THAN);
1299                                            }
1300                                    }
1301                            }
1302    
1303                            query.append(ORDER_BY_CLAUSE);
1304    
1305                            String[] orderByFields = orderByComparator.getOrderByFields();
1306    
1307                            for (int i = 0; i < orderByFields.length; i++) {
1308                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1309                                    query.append(orderByFields[i]);
1310    
1311                                    if ((i + 1) < orderByFields.length) {
1312                                            if (orderByComparator.isAscending() ^ previous) {
1313                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1314                                            }
1315                                            else {
1316                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1317                                            }
1318                                    }
1319                                    else {
1320                                            if (orderByComparator.isAscending() ^ previous) {
1321                                                    query.append(ORDER_BY_ASC);
1322                                            }
1323                                            else {
1324                                                    query.append(ORDER_BY_DESC);
1325                                            }
1326                                    }
1327                            }
1328                    }
1329                    else {
1330                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1331                    }
1332    
1333                    String sql = query.toString();
1334    
1335                    Query q = session.createQuery(sql);
1336    
1337                    q.setFirstResult(0);
1338                    q.setMaxResults(2);
1339    
1340                    QueryPos qPos = QueryPos.getInstance(q);
1341    
1342                    if (bindUuid) {
1343                            qPos.add(uuid);
1344                    }
1345    
1346                    qPos.add(companyId);
1347    
1348                    if (orderByComparator != null) {
1349                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1350    
1351                            for (Object value : values) {
1352                                    qPos.add(value);
1353                            }
1354                    }
1355    
1356                    List<MBCategory> list = q.list();
1357    
1358                    if (list.size() == 2) {
1359                            return list.get(1);
1360                    }
1361                    else {
1362                            return null;
1363                    }
1364            }
1365    
1366            /**
1367             * Removes all the message boards categories where uuid = &#63; and companyId = &#63; from the database.
1368             *
1369             * @param uuid the uuid
1370             * @param companyId the company ID
1371             * @throws SystemException if a system exception occurred
1372             */
1373            @Override
1374            public void removeByUuid_C(String uuid, long companyId)
1375                    throws SystemException {
1376                    for (MBCategory mbCategory : findByUuid_C(uuid, companyId,
1377                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1378                            remove(mbCategory);
1379                    }
1380            }
1381    
1382            /**
1383             * Returns the number of message boards categories where uuid = &#63; and companyId = &#63;.
1384             *
1385             * @param uuid the uuid
1386             * @param companyId the company ID
1387             * @return the number of matching message boards categories
1388             * @throws SystemException if a system exception occurred
1389             */
1390            @Override
1391            public int countByUuid_C(String uuid, long companyId)
1392                    throws SystemException {
1393                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1394    
1395                    Object[] finderArgs = new Object[] { uuid, companyId };
1396    
1397                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1398                                    this);
1399    
1400                    if (count == null) {
1401                            StringBundler query = new StringBundler(3);
1402    
1403                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
1404    
1405                            boolean bindUuid = false;
1406    
1407                            if (uuid == null) {
1408                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1409                            }
1410                            else if (uuid.equals(StringPool.BLANK)) {
1411                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1412                            }
1413                            else {
1414                                    bindUuid = true;
1415    
1416                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1417                            }
1418    
1419                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1420    
1421                            String sql = query.toString();
1422    
1423                            Session session = null;
1424    
1425                            try {
1426                                    session = openSession();
1427    
1428                                    Query q = session.createQuery(sql);
1429    
1430                                    QueryPos qPos = QueryPos.getInstance(q);
1431    
1432                                    if (bindUuid) {
1433                                            qPos.add(uuid);
1434                                    }
1435    
1436                                    qPos.add(companyId);
1437    
1438                                    count = (Long)q.uniqueResult();
1439    
1440                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1441                            }
1442                            catch (Exception e) {
1443                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1444    
1445                                    throw processException(e);
1446                            }
1447                            finally {
1448                                    closeSession(session);
1449                            }
1450                    }
1451    
1452                    return count.intValue();
1453            }
1454    
1455            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbCategory.uuid IS NULL AND ";
1456            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbCategory.uuid = ? AND ";
1457            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = '') AND ";
1458            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbCategory.companyId = ?";
1459            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1460                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1461                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1462                            new String[] {
1463                                    Long.class.getName(),
1464                                    
1465                            Integer.class.getName(), Integer.class.getName(),
1466                                    OrderByComparator.class.getName()
1467                            });
1468            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1469                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1470                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
1471                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1472                            new String[] { Long.class.getName() },
1473                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
1474                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
1475                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
1476            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
1477                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
1478                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1479                            new String[] { Long.class.getName() });
1480    
1481            /**
1482             * Returns all the message boards categories where groupId = &#63;.
1483             *
1484             * @param groupId the group ID
1485             * @return the matching message boards categories
1486             * @throws SystemException if a system exception occurred
1487             */
1488            @Override
1489            public List<MBCategory> findByGroupId(long groupId)
1490                    throws SystemException {
1491                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1492            }
1493    
1494            /**
1495             * Returns a range of all the message boards categories where groupId = &#63;.
1496             *
1497             * <p>
1498             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1499             * </p>
1500             *
1501             * @param groupId the group ID
1502             * @param start the lower bound of the range of message boards categories
1503             * @param end the upper bound of the range of message boards categories (not inclusive)
1504             * @return the range of matching message boards categories
1505             * @throws SystemException if a system exception occurred
1506             */
1507            @Override
1508            public List<MBCategory> findByGroupId(long groupId, int start, int end)
1509                    throws SystemException {
1510                    return findByGroupId(groupId, start, end, null);
1511            }
1512    
1513            /**
1514             * Returns an ordered range of all the message boards categories where groupId = &#63;.
1515             *
1516             * <p>
1517             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1518             * </p>
1519             *
1520             * @param groupId the group ID
1521             * @param start the lower bound of the range of message boards categories
1522             * @param end the upper bound of the range of message boards categories (not inclusive)
1523             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1524             * @return the ordered range of matching message boards categories
1525             * @throws SystemException if a system exception occurred
1526             */
1527            @Override
1528            public List<MBCategory> findByGroupId(long groupId, int start, int end,
1529                    OrderByComparator orderByComparator) throws SystemException {
1530                    boolean pagination = true;
1531                    FinderPath finderPath = null;
1532                    Object[] finderArgs = null;
1533    
1534                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1535                                    (orderByComparator == null)) {
1536                            pagination = false;
1537                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1538                            finderArgs = new Object[] { groupId };
1539                    }
1540                    else {
1541                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1542                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1543                    }
1544    
1545                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
1546                                    finderArgs, this);
1547    
1548                    if ((list != null) && !list.isEmpty()) {
1549                            for (MBCategory mbCategory : list) {
1550                                    if ((groupId != mbCategory.getGroupId())) {
1551                                            list = null;
1552    
1553                                            break;
1554                                    }
1555                            }
1556                    }
1557    
1558                    if (list == null) {
1559                            StringBundler query = null;
1560    
1561                            if (orderByComparator != null) {
1562                                    query = new StringBundler(3 +
1563                                                    (orderByComparator.getOrderByFields().length * 3));
1564                            }
1565                            else {
1566                                    query = new StringBundler(3);
1567                            }
1568    
1569                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1570    
1571                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1572    
1573                            if (orderByComparator != null) {
1574                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1575                                            orderByComparator);
1576                            }
1577                            else
1578                             if (pagination) {
1579                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1580                            }
1581    
1582                            String sql = query.toString();
1583    
1584                            Session session = null;
1585    
1586                            try {
1587                                    session = openSession();
1588    
1589                                    Query q = session.createQuery(sql);
1590    
1591                                    QueryPos qPos = QueryPos.getInstance(q);
1592    
1593                                    qPos.add(groupId);
1594    
1595                                    if (!pagination) {
1596                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1597                                                            start, end, false);
1598    
1599                                            Collections.sort(list);
1600    
1601                                            list = new UnmodifiableList<MBCategory>(list);
1602                                    }
1603                                    else {
1604                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
1605                                                            start, end);
1606                                    }
1607    
1608                                    cacheResult(list);
1609    
1610                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1611                            }
1612                            catch (Exception e) {
1613                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1614    
1615                                    throw processException(e);
1616                            }
1617                            finally {
1618                                    closeSession(session);
1619                            }
1620                    }
1621    
1622                    return list;
1623            }
1624    
1625            /**
1626             * Returns the first message boards category in the ordered set where groupId = &#63;.
1627             *
1628             * @param groupId the group ID
1629             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1630             * @return the first matching message boards category
1631             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1632             * @throws SystemException if a system exception occurred
1633             */
1634            @Override
1635            public MBCategory findByGroupId_First(long groupId,
1636                    OrderByComparator orderByComparator)
1637                    throws NoSuchCategoryException, SystemException {
1638                    MBCategory mbCategory = fetchByGroupId_First(groupId, orderByComparator);
1639    
1640                    if (mbCategory != null) {
1641                            return mbCategory;
1642                    }
1643    
1644                    StringBundler msg = new StringBundler(4);
1645    
1646                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1647    
1648                    msg.append("groupId=");
1649                    msg.append(groupId);
1650    
1651                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1652    
1653                    throw new NoSuchCategoryException(msg.toString());
1654            }
1655    
1656            /**
1657             * Returns the first message boards category in the ordered set where groupId = &#63;.
1658             *
1659             * @param groupId the group ID
1660             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1661             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
1662             * @throws SystemException if a system exception occurred
1663             */
1664            @Override
1665            public MBCategory fetchByGroupId_First(long groupId,
1666                    OrderByComparator orderByComparator) throws SystemException {
1667                    List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1668    
1669                    if (!list.isEmpty()) {
1670                            return list.get(0);
1671                    }
1672    
1673                    return null;
1674            }
1675    
1676            /**
1677             * Returns the last message boards category in the ordered set where groupId = &#63;.
1678             *
1679             * @param groupId the group ID
1680             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1681             * @return the last matching message boards category
1682             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1683             * @throws SystemException if a system exception occurred
1684             */
1685            @Override
1686            public MBCategory findByGroupId_Last(long groupId,
1687                    OrderByComparator orderByComparator)
1688                    throws NoSuchCategoryException, SystemException {
1689                    MBCategory mbCategory = fetchByGroupId_Last(groupId, orderByComparator);
1690    
1691                    if (mbCategory != null) {
1692                            return mbCategory;
1693                    }
1694    
1695                    StringBundler msg = new StringBundler(4);
1696    
1697                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1698    
1699                    msg.append("groupId=");
1700                    msg.append(groupId);
1701    
1702                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1703    
1704                    throw new NoSuchCategoryException(msg.toString());
1705            }
1706    
1707            /**
1708             * Returns the last message boards category in the ordered set where groupId = &#63;.
1709             *
1710             * @param groupId the group ID
1711             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1712             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
1713             * @throws SystemException if a system exception occurred
1714             */
1715            @Override
1716            public MBCategory fetchByGroupId_Last(long groupId,
1717                    OrderByComparator orderByComparator) throws SystemException {
1718                    int count = countByGroupId(groupId);
1719    
1720                    if (count == 0) {
1721                            return null;
1722                    }
1723    
1724                    List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1725                                    orderByComparator);
1726    
1727                    if (!list.isEmpty()) {
1728                            return list.get(0);
1729                    }
1730    
1731                    return null;
1732            }
1733    
1734            /**
1735             * Returns the message boards categories before and after the current message boards category in the ordered set where groupId = &#63;.
1736             *
1737             * @param categoryId the primary key of the current message boards category
1738             * @param groupId the group ID
1739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1740             * @return the previous, current, and next message boards category
1741             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
1742             * @throws SystemException if a system exception occurred
1743             */
1744            @Override
1745            public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1746                    long groupId, OrderByComparator orderByComparator)
1747                    throws NoSuchCategoryException, SystemException {
1748                    MBCategory mbCategory = findByPrimaryKey(categoryId);
1749    
1750                    Session session = null;
1751    
1752                    try {
1753                            session = openSession();
1754    
1755                            MBCategory[] array = new MBCategoryImpl[3];
1756    
1757                            array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1758                                            orderByComparator, true);
1759    
1760                            array[1] = mbCategory;
1761    
1762                            array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1763                                            orderByComparator, false);
1764    
1765                            return array;
1766                    }
1767                    catch (Exception e) {
1768                            throw processException(e);
1769                    }
1770                    finally {
1771                            closeSession(session);
1772                    }
1773            }
1774    
1775            protected MBCategory getByGroupId_PrevAndNext(Session session,
1776                    MBCategory mbCategory, long groupId,
1777                    OrderByComparator orderByComparator, boolean previous) {
1778                    StringBundler query = null;
1779    
1780                    if (orderByComparator != null) {
1781                            query = new StringBundler(6 +
1782                                            (orderByComparator.getOrderByFields().length * 6));
1783                    }
1784                    else {
1785                            query = new StringBundler(3);
1786                    }
1787    
1788                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1789    
1790                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1791    
1792                    if (orderByComparator != null) {
1793                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1794    
1795                            if (orderByConditionFields.length > 0) {
1796                                    query.append(WHERE_AND);
1797                            }
1798    
1799                            for (int i = 0; i < orderByConditionFields.length; i++) {
1800                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1801                                    query.append(orderByConditionFields[i]);
1802    
1803                                    if ((i + 1) < orderByConditionFields.length) {
1804                                            if (orderByComparator.isAscending() ^ previous) {
1805                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1806                                            }
1807                                            else {
1808                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1809                                            }
1810                                    }
1811                                    else {
1812                                            if (orderByComparator.isAscending() ^ previous) {
1813                                                    query.append(WHERE_GREATER_THAN);
1814                                            }
1815                                            else {
1816                                                    query.append(WHERE_LESSER_THAN);
1817                                            }
1818                                    }
1819                            }
1820    
1821                            query.append(ORDER_BY_CLAUSE);
1822    
1823                            String[] orderByFields = orderByComparator.getOrderByFields();
1824    
1825                            for (int i = 0; i < orderByFields.length; i++) {
1826                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1827                                    query.append(orderByFields[i]);
1828    
1829                                    if ((i + 1) < orderByFields.length) {
1830                                            if (orderByComparator.isAscending() ^ previous) {
1831                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1832                                            }
1833                                            else {
1834                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1835                                            }
1836                                    }
1837                                    else {
1838                                            if (orderByComparator.isAscending() ^ previous) {
1839                                                    query.append(ORDER_BY_ASC);
1840                                            }
1841                                            else {
1842                                                    query.append(ORDER_BY_DESC);
1843                                            }
1844                                    }
1845                            }
1846                    }
1847                    else {
1848                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1849                    }
1850    
1851                    String sql = query.toString();
1852    
1853                    Query q = session.createQuery(sql);
1854    
1855                    q.setFirstResult(0);
1856                    q.setMaxResults(2);
1857    
1858                    QueryPos qPos = QueryPos.getInstance(q);
1859    
1860                    qPos.add(groupId);
1861    
1862                    if (orderByComparator != null) {
1863                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1864    
1865                            for (Object value : values) {
1866                                    qPos.add(value);
1867                            }
1868                    }
1869    
1870                    List<MBCategory> list = q.list();
1871    
1872                    if (list.size() == 2) {
1873                            return list.get(1);
1874                    }
1875                    else {
1876                            return null;
1877                    }
1878            }
1879    
1880            /**
1881             * Returns all the message boards categories that the user has permission to view where groupId = &#63;.
1882             *
1883             * @param groupId the group ID
1884             * @return the matching message boards categories that the user has permission to view
1885             * @throws SystemException if a system exception occurred
1886             */
1887            @Override
1888            public List<MBCategory> filterFindByGroupId(long groupId)
1889                    throws SystemException {
1890                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1891                            QueryUtil.ALL_POS, null);
1892            }
1893    
1894            /**
1895             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63;.
1896             *
1897             * <p>
1898             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1899             * </p>
1900             *
1901             * @param groupId the group ID
1902             * @param start the lower bound of the range of message boards categories
1903             * @param end the upper bound of the range of message boards categories (not inclusive)
1904             * @return the range of matching message boards categories that the user has permission to view
1905             * @throws SystemException if a system exception occurred
1906             */
1907            @Override
1908            public List<MBCategory> filterFindByGroupId(long groupId, int start, int end)
1909                    throws SystemException {
1910                    return filterFindByGroupId(groupId, start, end, null);
1911            }
1912    
1913            /**
1914             * Returns an ordered range of all the message boards categories that the user has permissions to view where groupId = &#63;.
1915             *
1916             * <p>
1917             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1918             * </p>
1919             *
1920             * @param groupId the group ID
1921             * @param start the lower bound of the range of message boards categories
1922             * @param end the upper bound of the range of message boards categories (not inclusive)
1923             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1924             * @return the ordered range of matching message boards categories that the user has permission to view
1925             * @throws SystemException if a system exception occurred
1926             */
1927            @Override
1928            public List<MBCategory> filterFindByGroupId(long groupId, int start,
1929                    int end, OrderByComparator orderByComparator) throws SystemException {
1930                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1931                            return findByGroupId(groupId, start, end, orderByComparator);
1932                    }
1933    
1934                    StringBundler query = null;
1935    
1936                    if (orderByComparator != null) {
1937                            query = new StringBundler(3 +
1938                                            (orderByComparator.getOrderByFields().length * 3));
1939                    }
1940                    else {
1941                            query = new StringBundler(3);
1942                    }
1943    
1944                    if (getDB().isSupportsInlineDistinct()) {
1945                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1946                    }
1947                    else {
1948                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1949                    }
1950    
1951                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1952    
1953                    if (!getDB().isSupportsInlineDistinct()) {
1954                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1955                    }
1956    
1957                    if (orderByComparator != null) {
1958                            if (getDB().isSupportsInlineDistinct()) {
1959                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1960                                            orderByComparator, true);
1961                            }
1962                            else {
1963                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1964                                            orderByComparator, true);
1965                            }
1966                    }
1967                    else {
1968                            if (getDB().isSupportsInlineDistinct()) {
1969                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1970                            }
1971                            else {
1972                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
1973                            }
1974                    }
1975    
1976                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1977                                    MBCategory.class.getName(),
1978                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1979    
1980                    Session session = null;
1981    
1982                    try {
1983                            session = openSession();
1984    
1985                            SQLQuery q = session.createSQLQuery(sql);
1986    
1987                            if (getDB().isSupportsInlineDistinct()) {
1988                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
1989                            }
1990                            else {
1991                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
1992                            }
1993    
1994                            QueryPos qPos = QueryPos.getInstance(q);
1995    
1996                            qPos.add(groupId);
1997    
1998                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
1999                    }
2000                    catch (Exception e) {
2001                            throw processException(e);
2002                    }
2003                    finally {
2004                            closeSession(session);
2005                    }
2006            }
2007    
2008            /**
2009             * 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;.
2010             *
2011             * @param categoryId the primary key of the current message boards category
2012             * @param groupId the group ID
2013             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2014             * @return the previous, current, and next message boards category
2015             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
2016             * @throws SystemException if a system exception occurred
2017             */
2018            @Override
2019            public MBCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
2020                    long groupId, OrderByComparator orderByComparator)
2021                    throws NoSuchCategoryException, SystemException {
2022                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2023                            return findByGroupId_PrevAndNext(categoryId, groupId,
2024                                    orderByComparator);
2025                    }
2026    
2027                    MBCategory mbCategory = findByPrimaryKey(categoryId);
2028    
2029                    Session session = null;
2030    
2031                    try {
2032                            session = openSession();
2033    
2034                            MBCategory[] array = new MBCategoryImpl[3];
2035    
2036                            array[0] = filterGetByGroupId_PrevAndNext(session, mbCategory,
2037                                            groupId, orderByComparator, true);
2038    
2039                            array[1] = mbCategory;
2040    
2041                            array[2] = filterGetByGroupId_PrevAndNext(session, mbCategory,
2042                                            groupId, orderByComparator, false);
2043    
2044                            return array;
2045                    }
2046                    catch (Exception e) {
2047                            throw processException(e);
2048                    }
2049                    finally {
2050                            closeSession(session);
2051                    }
2052            }
2053    
2054            protected MBCategory filterGetByGroupId_PrevAndNext(Session session,
2055                    MBCategory mbCategory, long groupId,
2056                    OrderByComparator orderByComparator, boolean previous) {
2057                    StringBundler query = null;
2058    
2059                    if (orderByComparator != null) {
2060                            query = new StringBundler(6 +
2061                                            (orderByComparator.getOrderByFields().length * 6));
2062                    }
2063                    else {
2064                            query = new StringBundler(3);
2065                    }
2066    
2067                    if (getDB().isSupportsInlineDistinct()) {
2068                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2069                    }
2070                    else {
2071                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2072                    }
2073    
2074                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2075    
2076                    if (!getDB().isSupportsInlineDistinct()) {
2077                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2078                    }
2079    
2080                    if (orderByComparator != null) {
2081                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2082    
2083                            if (orderByConditionFields.length > 0) {
2084                                    query.append(WHERE_AND);
2085                            }
2086    
2087                            for (int i = 0; i < orderByConditionFields.length; i++) {
2088                                    if (getDB().isSupportsInlineDistinct()) {
2089                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2090                                    }
2091                                    else {
2092                                            query.append(_ORDER_BY_ENTITY_TABLE);
2093                                    }
2094    
2095                                    query.append(orderByConditionFields[i]);
2096    
2097                                    if ((i + 1) < orderByConditionFields.length) {
2098                                            if (orderByComparator.isAscending() ^ previous) {
2099                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2100                                            }
2101                                            else {
2102                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2103                                            }
2104                                    }
2105                                    else {
2106                                            if (orderByComparator.isAscending() ^ previous) {
2107                                                    query.append(WHERE_GREATER_THAN);
2108                                            }
2109                                            else {
2110                                                    query.append(WHERE_LESSER_THAN);
2111                                            }
2112                                    }
2113                            }
2114    
2115                            query.append(ORDER_BY_CLAUSE);
2116    
2117                            String[] orderByFields = orderByComparator.getOrderByFields();
2118    
2119                            for (int i = 0; i < orderByFields.length; i++) {
2120                                    if (getDB().isSupportsInlineDistinct()) {
2121                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2122                                    }
2123                                    else {
2124                                            query.append(_ORDER_BY_ENTITY_TABLE);
2125                                    }
2126    
2127                                    query.append(orderByFields[i]);
2128    
2129                                    if ((i + 1) < orderByFields.length) {
2130                                            if (orderByComparator.isAscending() ^ previous) {
2131                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2132                                            }
2133                                            else {
2134                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2135                                            }
2136                                    }
2137                                    else {
2138                                            if (orderByComparator.isAscending() ^ previous) {
2139                                                    query.append(ORDER_BY_ASC);
2140                                            }
2141                                            else {
2142                                                    query.append(ORDER_BY_DESC);
2143                                            }
2144                                    }
2145                            }
2146                    }
2147                    else {
2148                            if (getDB().isSupportsInlineDistinct()) {
2149                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2150                            }
2151                            else {
2152                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2153                            }
2154                    }
2155    
2156                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2157                                    MBCategory.class.getName(),
2158                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2159    
2160                    SQLQuery q = session.createSQLQuery(sql);
2161    
2162                    q.setFirstResult(0);
2163                    q.setMaxResults(2);
2164    
2165                    if (getDB().isSupportsInlineDistinct()) {
2166                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2167                    }
2168                    else {
2169                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2170                    }
2171    
2172                    QueryPos qPos = QueryPos.getInstance(q);
2173    
2174                    qPos.add(groupId);
2175    
2176                    if (orderByComparator != null) {
2177                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2178    
2179                            for (Object value : values) {
2180                                    qPos.add(value);
2181                            }
2182                    }
2183    
2184                    List<MBCategory> list = q.list();
2185    
2186                    if (list.size() == 2) {
2187                            return list.get(1);
2188                    }
2189                    else {
2190                            return null;
2191                    }
2192            }
2193    
2194            /**
2195             * Removes all the message boards categories where groupId = &#63; from the database.
2196             *
2197             * @param groupId the group ID
2198             * @throws SystemException if a system exception occurred
2199             */
2200            @Override
2201            public void removeByGroupId(long groupId) throws SystemException {
2202                    for (MBCategory mbCategory : findByGroupId(groupId, QueryUtil.ALL_POS,
2203                                    QueryUtil.ALL_POS, null)) {
2204                            remove(mbCategory);
2205                    }
2206            }
2207    
2208            /**
2209             * Returns the number of message boards categories where groupId = &#63;.
2210             *
2211             * @param groupId the group ID
2212             * @return the number of matching message boards categories
2213             * @throws SystemException if a system exception occurred
2214             */
2215            @Override
2216            public int countByGroupId(long groupId) throws SystemException {
2217                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2218    
2219                    Object[] finderArgs = new Object[] { groupId };
2220    
2221                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2222                                    this);
2223    
2224                    if (count == null) {
2225                            StringBundler query = new StringBundler(2);
2226    
2227                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2228    
2229                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2230    
2231                            String sql = query.toString();
2232    
2233                            Session session = null;
2234    
2235                            try {
2236                                    session = openSession();
2237    
2238                                    Query q = session.createQuery(sql);
2239    
2240                                    QueryPos qPos = QueryPos.getInstance(q);
2241    
2242                                    qPos.add(groupId);
2243    
2244                                    count = (Long)q.uniqueResult();
2245    
2246                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2247                            }
2248                            catch (Exception e) {
2249                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2250    
2251                                    throw processException(e);
2252                            }
2253                            finally {
2254                                    closeSession(session);
2255                            }
2256                    }
2257    
2258                    return count.intValue();
2259            }
2260    
2261            /**
2262             * Returns the number of message boards categories that the user has permission to view where groupId = &#63;.
2263             *
2264             * @param groupId the group ID
2265             * @return the number of matching message boards categories that the user has permission to view
2266             * @throws SystemException if a system exception occurred
2267             */
2268            @Override
2269            public int filterCountByGroupId(long groupId) throws SystemException {
2270                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2271                            return countByGroupId(groupId);
2272                    }
2273    
2274                    StringBundler query = new StringBundler(2);
2275    
2276                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
2277    
2278                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2279    
2280                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2281                                    MBCategory.class.getName(),
2282                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2283    
2284                    Session session = null;
2285    
2286                    try {
2287                            session = openSession();
2288    
2289                            SQLQuery q = session.createSQLQuery(sql);
2290    
2291                            q.addScalar(COUNT_COLUMN_NAME,
2292                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2293    
2294                            QueryPos qPos = QueryPos.getInstance(q);
2295    
2296                            qPos.add(groupId);
2297    
2298                            Long count = (Long)q.uniqueResult();
2299    
2300                            return count.intValue();
2301                    }
2302                    catch (Exception e) {
2303                            throw processException(e);
2304                    }
2305                    finally {
2306                            closeSession(session);
2307                    }
2308            }
2309    
2310            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
2311            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2312                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2313                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2314                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2315                            new String[] {
2316                                    Long.class.getName(),
2317                                    
2318                            Integer.class.getName(), Integer.class.getName(),
2319                                    OrderByComparator.class.getName()
2320                            });
2321            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2322                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2323                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2324                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2325                            new String[] { Long.class.getName() },
2326                            MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
2327                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2328                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2329            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2330                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2331                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2332                            new String[] { Long.class.getName() });
2333    
2334            /**
2335             * Returns all the message boards categories where companyId = &#63;.
2336             *
2337             * @param companyId the company ID
2338             * @return the matching message boards categories
2339             * @throws SystemException if a system exception occurred
2340             */
2341            @Override
2342            public List<MBCategory> findByCompanyId(long companyId)
2343                    throws SystemException {
2344                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2345                            null);
2346            }
2347    
2348            /**
2349             * Returns a range of all the message boards categories where companyId = &#63;.
2350             *
2351             * <p>
2352             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2353             * </p>
2354             *
2355             * @param companyId the company ID
2356             * @param start the lower bound of the range of message boards categories
2357             * @param end the upper bound of the range of message boards categories (not inclusive)
2358             * @return the range of matching message boards categories
2359             * @throws SystemException if a system exception occurred
2360             */
2361            @Override
2362            public List<MBCategory> findByCompanyId(long companyId, int start, int end)
2363                    throws SystemException {
2364                    return findByCompanyId(companyId, start, end, null);
2365            }
2366    
2367            /**
2368             * Returns an ordered range of all the message boards categories where companyId = &#63;.
2369             *
2370             * <p>
2371             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2372             * </p>
2373             *
2374             * @param companyId the company ID
2375             * @param start the lower bound of the range of message boards categories
2376             * @param end the upper bound of the range of message boards categories (not inclusive)
2377             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2378             * @return the ordered range of matching message boards categories
2379             * @throws SystemException if a system exception occurred
2380             */
2381            @Override
2382            public List<MBCategory> findByCompanyId(long companyId, int start, int end,
2383                    OrderByComparator orderByComparator) throws SystemException {
2384                    boolean pagination = true;
2385                    FinderPath finderPath = null;
2386                    Object[] finderArgs = null;
2387    
2388                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2389                                    (orderByComparator == null)) {
2390                            pagination = false;
2391                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2392                            finderArgs = new Object[] { companyId };
2393                    }
2394                    else {
2395                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2396                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2397                    }
2398    
2399                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2400                                    finderArgs, this);
2401    
2402                    if ((list != null) && !list.isEmpty()) {
2403                            for (MBCategory mbCategory : list) {
2404                                    if ((companyId != mbCategory.getCompanyId())) {
2405                                            list = null;
2406    
2407                                            break;
2408                                    }
2409                            }
2410                    }
2411    
2412                    if (list == null) {
2413                            StringBundler query = null;
2414    
2415                            if (orderByComparator != null) {
2416                                    query = new StringBundler(3 +
2417                                                    (orderByComparator.getOrderByFields().length * 3));
2418                            }
2419                            else {
2420                                    query = new StringBundler(3);
2421                            }
2422    
2423                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2424    
2425                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2426    
2427                            if (orderByComparator != null) {
2428                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2429                                            orderByComparator);
2430                            }
2431                            else
2432                             if (pagination) {
2433                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2434                            }
2435    
2436                            String sql = query.toString();
2437    
2438                            Session session = null;
2439    
2440                            try {
2441                                    session = openSession();
2442    
2443                                    Query q = session.createQuery(sql);
2444    
2445                                    QueryPos qPos = QueryPos.getInstance(q);
2446    
2447                                    qPos.add(companyId);
2448    
2449                                    if (!pagination) {
2450                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2451                                                            start, end, false);
2452    
2453                                            Collections.sort(list);
2454    
2455                                            list = new UnmodifiableList<MBCategory>(list);
2456                                    }
2457                                    else {
2458                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2459                                                            start, end);
2460                                    }
2461    
2462                                    cacheResult(list);
2463    
2464                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2465                            }
2466                            catch (Exception e) {
2467                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2468    
2469                                    throw processException(e);
2470                            }
2471                            finally {
2472                                    closeSession(session);
2473                            }
2474                    }
2475    
2476                    return list;
2477            }
2478    
2479            /**
2480             * Returns the first message boards category in the ordered set where companyId = &#63;.
2481             *
2482             * @param companyId the company ID
2483             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2484             * @return the first matching message boards category
2485             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
2486             * @throws SystemException if a system exception occurred
2487             */
2488            @Override
2489            public MBCategory findByCompanyId_First(long companyId,
2490                    OrderByComparator orderByComparator)
2491                    throws NoSuchCategoryException, SystemException {
2492                    MBCategory mbCategory = fetchByCompanyId_First(companyId,
2493                                    orderByComparator);
2494    
2495                    if (mbCategory != null) {
2496                            return mbCategory;
2497                    }
2498    
2499                    StringBundler msg = new StringBundler(4);
2500    
2501                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2502    
2503                    msg.append("companyId=");
2504                    msg.append(companyId);
2505    
2506                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2507    
2508                    throw new NoSuchCategoryException(msg.toString());
2509            }
2510    
2511            /**
2512             * Returns the first message boards category in the ordered set where companyId = &#63;.
2513             *
2514             * @param companyId the company ID
2515             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2516             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
2517             * @throws SystemException if a system exception occurred
2518             */
2519            @Override
2520            public MBCategory fetchByCompanyId_First(long companyId,
2521                    OrderByComparator orderByComparator) throws SystemException {
2522                    List<MBCategory> list = findByCompanyId(companyId, 0, 1,
2523                                    orderByComparator);
2524    
2525                    if (!list.isEmpty()) {
2526                            return list.get(0);
2527                    }
2528    
2529                    return null;
2530            }
2531    
2532            /**
2533             * Returns the last message boards category in the ordered set where companyId = &#63;.
2534             *
2535             * @param companyId the company ID
2536             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2537             * @return the last matching message boards category
2538             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
2539             * @throws SystemException if a system exception occurred
2540             */
2541            @Override
2542            public MBCategory findByCompanyId_Last(long companyId,
2543                    OrderByComparator orderByComparator)
2544                    throws NoSuchCategoryException, SystemException {
2545                    MBCategory mbCategory = fetchByCompanyId_Last(companyId,
2546                                    orderByComparator);
2547    
2548                    if (mbCategory != null) {
2549                            return mbCategory;
2550                    }
2551    
2552                    StringBundler msg = new StringBundler(4);
2553    
2554                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2555    
2556                    msg.append("companyId=");
2557                    msg.append(companyId);
2558    
2559                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2560    
2561                    throw new NoSuchCategoryException(msg.toString());
2562            }
2563    
2564            /**
2565             * Returns the last message boards category in the ordered set where companyId = &#63;.
2566             *
2567             * @param companyId the company ID
2568             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2569             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
2570             * @throws SystemException if a system exception occurred
2571             */
2572            @Override
2573            public MBCategory fetchByCompanyId_Last(long companyId,
2574                    OrderByComparator orderByComparator) throws SystemException {
2575                    int count = countByCompanyId(companyId);
2576    
2577                    if (count == 0) {
2578                            return null;
2579                    }
2580    
2581                    List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
2582                                    orderByComparator);
2583    
2584                    if (!list.isEmpty()) {
2585                            return list.get(0);
2586                    }
2587    
2588                    return null;
2589            }
2590    
2591            /**
2592             * Returns the message boards categories before and after the current message boards category in the ordered set where companyId = &#63;.
2593             *
2594             * @param categoryId the primary key of the current message boards category
2595             * @param companyId the company ID
2596             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2597             * @return the previous, current, and next message boards category
2598             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
2599             * @throws SystemException if a system exception occurred
2600             */
2601            @Override
2602            public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
2603                    long companyId, OrderByComparator orderByComparator)
2604                    throws NoSuchCategoryException, SystemException {
2605                    MBCategory mbCategory = findByPrimaryKey(categoryId);
2606    
2607                    Session session = null;
2608    
2609                    try {
2610                            session = openSession();
2611    
2612                            MBCategory[] array = new MBCategoryImpl[3];
2613    
2614                            array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
2615                                            companyId, orderByComparator, true);
2616    
2617                            array[1] = mbCategory;
2618    
2619                            array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
2620                                            companyId, orderByComparator, false);
2621    
2622                            return array;
2623                    }
2624                    catch (Exception e) {
2625                            throw processException(e);
2626                    }
2627                    finally {
2628                            closeSession(session);
2629                    }
2630            }
2631    
2632            protected MBCategory getByCompanyId_PrevAndNext(Session session,
2633                    MBCategory mbCategory, long companyId,
2634                    OrderByComparator orderByComparator, boolean previous) {
2635                    StringBundler query = null;
2636    
2637                    if (orderByComparator != null) {
2638                            query = new StringBundler(6 +
2639                                            (orderByComparator.getOrderByFields().length * 6));
2640                    }
2641                    else {
2642                            query = new StringBundler(3);
2643                    }
2644    
2645                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2646    
2647                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2648    
2649                    if (orderByComparator != null) {
2650                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2651    
2652                            if (orderByConditionFields.length > 0) {
2653                                    query.append(WHERE_AND);
2654                            }
2655    
2656                            for (int i = 0; i < orderByConditionFields.length; i++) {
2657                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2658                                    query.append(orderByConditionFields[i]);
2659    
2660                                    if ((i + 1) < orderByConditionFields.length) {
2661                                            if (orderByComparator.isAscending() ^ previous) {
2662                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2663                                            }
2664                                            else {
2665                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2666                                            }
2667                                    }
2668                                    else {
2669                                            if (orderByComparator.isAscending() ^ previous) {
2670                                                    query.append(WHERE_GREATER_THAN);
2671                                            }
2672                                            else {
2673                                                    query.append(WHERE_LESSER_THAN);
2674                                            }
2675                                    }
2676                            }
2677    
2678                            query.append(ORDER_BY_CLAUSE);
2679    
2680                            String[] orderByFields = orderByComparator.getOrderByFields();
2681    
2682                            for (int i = 0; i < orderByFields.length; i++) {
2683                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2684                                    query.append(orderByFields[i]);
2685    
2686                                    if ((i + 1) < orderByFields.length) {
2687                                            if (orderByComparator.isAscending() ^ previous) {
2688                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2689                                            }
2690                                            else {
2691                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2692                                            }
2693                                    }
2694                                    else {
2695                                            if (orderByComparator.isAscending() ^ previous) {
2696                                                    query.append(ORDER_BY_ASC);
2697                                            }
2698                                            else {
2699                                                    query.append(ORDER_BY_DESC);
2700                                            }
2701                                    }
2702                            }
2703                    }
2704                    else {
2705                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2706                    }
2707    
2708                    String sql = query.toString();
2709    
2710                    Query q = session.createQuery(sql);
2711    
2712                    q.setFirstResult(0);
2713                    q.setMaxResults(2);
2714    
2715                    QueryPos qPos = QueryPos.getInstance(q);
2716    
2717                    qPos.add(companyId);
2718    
2719                    if (orderByComparator != null) {
2720                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2721    
2722                            for (Object value : values) {
2723                                    qPos.add(value);
2724                            }
2725                    }
2726    
2727                    List<MBCategory> list = q.list();
2728    
2729                    if (list.size() == 2) {
2730                            return list.get(1);
2731                    }
2732                    else {
2733                            return null;
2734                    }
2735            }
2736    
2737            /**
2738             * Removes all the message boards categories where companyId = &#63; from the database.
2739             *
2740             * @param companyId the company ID
2741             * @throws SystemException if a system exception occurred
2742             */
2743            @Override
2744            public void removeByCompanyId(long companyId) throws SystemException {
2745                    for (MBCategory mbCategory : findByCompanyId(companyId,
2746                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2747                            remove(mbCategory);
2748                    }
2749            }
2750    
2751            /**
2752             * Returns the number of message boards categories where companyId = &#63;.
2753             *
2754             * @param companyId the company ID
2755             * @return the number of matching message boards categories
2756             * @throws SystemException if a system exception occurred
2757             */
2758            @Override
2759            public int countByCompanyId(long companyId) throws SystemException {
2760                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2761    
2762                    Object[] finderArgs = new Object[] { companyId };
2763    
2764                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2765                                    this);
2766    
2767                    if (count == null) {
2768                            StringBundler query = new StringBundler(2);
2769    
2770                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2771    
2772                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2773    
2774                            String sql = query.toString();
2775    
2776                            Session session = null;
2777    
2778                            try {
2779                                    session = openSession();
2780    
2781                                    Query q = session.createQuery(sql);
2782    
2783                                    QueryPos qPos = QueryPos.getInstance(q);
2784    
2785                                    qPos.add(companyId);
2786    
2787                                    count = (Long)q.uniqueResult();
2788    
2789                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2790                            }
2791                            catch (Exception e) {
2792                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2793    
2794                                    throw processException(e);
2795                            }
2796                            finally {
2797                                    closeSession(session);
2798                            }
2799                    }
2800    
2801                    return count.intValue();
2802            }
2803    
2804            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
2805            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2806                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2807                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
2808                            new String[] {
2809                                    Long.class.getName(), Long.class.getName(),
2810                                    
2811                            Integer.class.getName(), Integer.class.getName(),
2812                                    OrderByComparator.class.getName()
2813                            });
2814            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2815                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
2816                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
2817                            new String[] { Long.class.getName(), Long.class.getName() },
2818                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
2819                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
2820                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
2821            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2822                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2823                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
2824                            new String[] { Long.class.getName(), Long.class.getName() });
2825            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
2826                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
2827                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P",
2828                            new String[] { Long.class.getName(), Long.class.getName() });
2829    
2830            /**
2831             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2832             *
2833             * @param groupId the group ID
2834             * @param parentCategoryId the parent category ID
2835             * @return the matching message boards categories
2836             * @throws SystemException if a system exception occurred
2837             */
2838            @Override
2839            public List<MBCategory> findByG_P(long groupId, long parentCategoryId)
2840                    throws SystemException {
2841                    return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2842                            QueryUtil.ALL_POS, null);
2843            }
2844    
2845            /**
2846             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2847             *
2848             * <p>
2849             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2850             * </p>
2851             *
2852             * @param groupId the group ID
2853             * @param parentCategoryId the parent category ID
2854             * @param start the lower bound of the range of message boards categories
2855             * @param end the upper bound of the range of message boards categories (not inclusive)
2856             * @return the range of matching message boards categories
2857             * @throws SystemException if a system exception occurred
2858             */
2859            @Override
2860            public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2861                    int start, int end) throws SystemException {
2862                    return findByG_P(groupId, parentCategoryId, start, end, null);
2863            }
2864    
2865            /**
2866             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2867             *
2868             * <p>
2869             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2870             * </p>
2871             *
2872             * @param groupId the group ID
2873             * @param parentCategoryId the parent category ID
2874             * @param start the lower bound of the range of message boards categories
2875             * @param end the upper bound of the range of message boards categories (not inclusive)
2876             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2877             * @return the ordered range of matching message boards categories
2878             * @throws SystemException if a system exception occurred
2879             */
2880            @Override
2881            public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2882                    int start, int end, OrderByComparator orderByComparator)
2883                    throws SystemException {
2884                    boolean pagination = true;
2885                    FinderPath finderPath = null;
2886                    Object[] finderArgs = null;
2887    
2888                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2889                                    (orderByComparator == null)) {
2890                            pagination = false;
2891                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2892                            finderArgs = new Object[] { groupId, parentCategoryId };
2893                    }
2894                    else {
2895                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2896                            finderArgs = new Object[] {
2897                                            groupId, parentCategoryId,
2898                                            
2899                                            start, end, orderByComparator
2900                                    };
2901                    }
2902    
2903                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2904                                    finderArgs, this);
2905    
2906                    if ((list != null) && !list.isEmpty()) {
2907                            for (MBCategory mbCategory : list) {
2908                                    if ((groupId != mbCategory.getGroupId()) ||
2909                                                    (parentCategoryId != mbCategory.getParentCategoryId())) {
2910                                            list = null;
2911    
2912                                            break;
2913                                    }
2914                            }
2915                    }
2916    
2917                    if (list == null) {
2918                            StringBundler query = null;
2919    
2920                            if (orderByComparator != null) {
2921                                    query = new StringBundler(4 +
2922                                                    (orderByComparator.getOrderByFields().length * 3));
2923                            }
2924                            else {
2925                                    query = new StringBundler(4);
2926                            }
2927    
2928                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2929    
2930                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2931    
2932                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2933    
2934                            if (orderByComparator != null) {
2935                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2936                                            orderByComparator);
2937                            }
2938                            else
2939                             if (pagination) {
2940                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2941                            }
2942    
2943                            String sql = query.toString();
2944    
2945                            Session session = null;
2946    
2947                            try {
2948                                    session = openSession();
2949    
2950                                    Query q = session.createQuery(sql);
2951    
2952                                    QueryPos qPos = QueryPos.getInstance(q);
2953    
2954                                    qPos.add(groupId);
2955    
2956                                    qPos.add(parentCategoryId);
2957    
2958                                    if (!pagination) {
2959                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2960                                                            start, end, false);
2961    
2962                                            Collections.sort(list);
2963    
2964                                            list = new UnmodifiableList<MBCategory>(list);
2965                                    }
2966                                    else {
2967                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2968                                                            start, end);
2969                                    }
2970    
2971                                    cacheResult(list);
2972    
2973                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2974                            }
2975                            catch (Exception e) {
2976                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2977    
2978                                    throw processException(e);
2979                            }
2980                            finally {
2981                                    closeSession(session);
2982                            }
2983                    }
2984    
2985                    return list;
2986            }
2987    
2988            /**
2989             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
2990             *
2991             * @param groupId the group ID
2992             * @param parentCategoryId the parent category ID
2993             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2994             * @return the first matching message boards category
2995             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
2996             * @throws SystemException if a system exception occurred
2997             */
2998            @Override
2999            public MBCategory findByG_P_First(long groupId, long parentCategoryId,
3000                    OrderByComparator orderByComparator)
3001                    throws NoSuchCategoryException, SystemException {
3002                    MBCategory mbCategory = fetchByG_P_First(groupId, parentCategoryId,
3003                                    orderByComparator);
3004    
3005                    if (mbCategory != null) {
3006                            return mbCategory;
3007                    }
3008    
3009                    StringBundler msg = new StringBundler(6);
3010    
3011                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3012    
3013                    msg.append("groupId=");
3014                    msg.append(groupId);
3015    
3016                    msg.append(", parentCategoryId=");
3017                    msg.append(parentCategoryId);
3018    
3019                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3020    
3021                    throw new NoSuchCategoryException(msg.toString());
3022            }
3023    
3024            /**
3025             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3026             *
3027             * @param groupId the group ID
3028             * @param parentCategoryId the parent category ID
3029             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3030             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
3031             * @throws SystemException if a system exception occurred
3032             */
3033            @Override
3034            public MBCategory fetchByG_P_First(long groupId, long parentCategoryId,
3035                    OrderByComparator orderByComparator) throws SystemException {
3036                    List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
3037                                    orderByComparator);
3038    
3039                    if (!list.isEmpty()) {
3040                            return list.get(0);
3041                    }
3042    
3043                    return null;
3044            }
3045    
3046            /**
3047             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3048             *
3049             * @param groupId the group ID
3050             * @param parentCategoryId the parent category ID
3051             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3052             * @return the last matching message boards category
3053             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
3054             * @throws SystemException if a system exception occurred
3055             */
3056            @Override
3057            public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
3058                    OrderByComparator orderByComparator)
3059                    throws NoSuchCategoryException, SystemException {
3060                    MBCategory mbCategory = fetchByG_P_Last(groupId, parentCategoryId,
3061                                    orderByComparator);
3062    
3063                    if (mbCategory != null) {
3064                            return mbCategory;
3065                    }
3066    
3067                    StringBundler msg = new StringBundler(6);
3068    
3069                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3070    
3071                    msg.append("groupId=");
3072                    msg.append(groupId);
3073    
3074                    msg.append(", parentCategoryId=");
3075                    msg.append(parentCategoryId);
3076    
3077                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3078    
3079                    throw new NoSuchCategoryException(msg.toString());
3080            }
3081    
3082            /**
3083             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3084             *
3085             * @param groupId the group ID
3086             * @param parentCategoryId the parent category ID
3087             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3088             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
3089             * @throws SystemException if a system exception occurred
3090             */
3091            @Override
3092            public MBCategory fetchByG_P_Last(long groupId, long parentCategoryId,
3093                    OrderByComparator orderByComparator) throws SystemException {
3094                    int count = countByG_P(groupId, parentCategoryId);
3095    
3096                    if (count == 0) {
3097                            return null;
3098                    }
3099    
3100                    List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
3101                                    count, orderByComparator);
3102    
3103                    if (!list.isEmpty()) {
3104                            return list.get(0);
3105                    }
3106    
3107                    return null;
3108            }
3109    
3110            /**
3111             * Returns the message boards categories before and after the current message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3112             *
3113             * @param categoryId the primary key of the current message boards category
3114             * @param groupId the group ID
3115             * @param parentCategoryId the parent category ID
3116             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3117             * @return the previous, current, and next message boards category
3118             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
3119             * @throws SystemException if a system exception occurred
3120             */
3121            @Override
3122            public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
3123                    long parentCategoryId, OrderByComparator orderByComparator)
3124                    throws NoSuchCategoryException, SystemException {
3125                    MBCategory mbCategory = findByPrimaryKey(categoryId);
3126    
3127                    Session session = null;
3128    
3129                    try {
3130                            session = openSession();
3131    
3132                            MBCategory[] array = new MBCategoryImpl[3];
3133    
3134                            array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3135                                            parentCategoryId, orderByComparator, true);
3136    
3137                            array[1] = mbCategory;
3138    
3139                            array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3140                                            parentCategoryId, orderByComparator, false);
3141    
3142                            return array;
3143                    }
3144                    catch (Exception e) {
3145                            throw processException(e);
3146                    }
3147                    finally {
3148                            closeSession(session);
3149                    }
3150            }
3151    
3152            protected MBCategory getByG_P_PrevAndNext(Session session,
3153                    MBCategory mbCategory, long groupId, long parentCategoryId,
3154                    OrderByComparator orderByComparator, boolean previous) {
3155                    StringBundler query = null;
3156    
3157                    if (orderByComparator != null) {
3158                            query = new StringBundler(6 +
3159                                            (orderByComparator.getOrderByFields().length * 6));
3160                    }
3161                    else {
3162                            query = new StringBundler(3);
3163                    }
3164    
3165                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3166    
3167                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3168    
3169                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3170    
3171                    if (orderByComparator != null) {
3172                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3173    
3174                            if (orderByConditionFields.length > 0) {
3175                                    query.append(WHERE_AND);
3176                            }
3177    
3178                            for (int i = 0; i < orderByConditionFields.length; i++) {
3179                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3180                                    query.append(orderByConditionFields[i]);
3181    
3182                                    if ((i + 1) < orderByConditionFields.length) {
3183                                            if (orderByComparator.isAscending() ^ previous) {
3184                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3185                                            }
3186                                            else {
3187                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3188                                            }
3189                                    }
3190                                    else {
3191                                            if (orderByComparator.isAscending() ^ previous) {
3192                                                    query.append(WHERE_GREATER_THAN);
3193                                            }
3194                                            else {
3195                                                    query.append(WHERE_LESSER_THAN);
3196                                            }
3197                                    }
3198                            }
3199    
3200                            query.append(ORDER_BY_CLAUSE);
3201    
3202                            String[] orderByFields = orderByComparator.getOrderByFields();
3203    
3204                            for (int i = 0; i < orderByFields.length; i++) {
3205                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3206                                    query.append(orderByFields[i]);
3207    
3208                                    if ((i + 1) < orderByFields.length) {
3209                                            if (orderByComparator.isAscending() ^ previous) {
3210                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3211                                            }
3212                                            else {
3213                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3214                                            }
3215                                    }
3216                                    else {
3217                                            if (orderByComparator.isAscending() ^ previous) {
3218                                                    query.append(ORDER_BY_ASC);
3219                                            }
3220                                            else {
3221                                                    query.append(ORDER_BY_DESC);
3222                                            }
3223                                    }
3224                            }
3225                    }
3226                    else {
3227                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3228                    }
3229    
3230                    String sql = query.toString();
3231    
3232                    Query q = session.createQuery(sql);
3233    
3234                    q.setFirstResult(0);
3235                    q.setMaxResults(2);
3236    
3237                    QueryPos qPos = QueryPos.getInstance(q);
3238    
3239                    qPos.add(groupId);
3240    
3241                    qPos.add(parentCategoryId);
3242    
3243                    if (orderByComparator != null) {
3244                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3245    
3246                            for (Object value : values) {
3247                                    qPos.add(value);
3248                            }
3249                    }
3250    
3251                    List<MBCategory> list = q.list();
3252    
3253                    if (list.size() == 2) {
3254                            return list.get(1);
3255                    }
3256                    else {
3257                            return null;
3258                    }
3259            }
3260    
3261            /**
3262             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
3263             *
3264             * @param groupId the group ID
3265             * @param parentCategoryId the parent category ID
3266             * @return the matching message boards categories that the user has permission to view
3267             * @throws SystemException if a system exception occurred
3268             */
3269            @Override
3270            public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId)
3271                    throws SystemException {
3272                    return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
3273                            QueryUtil.ALL_POS, null);
3274            }
3275    
3276            /**
3277             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
3278             *
3279             * <p>
3280             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3281             * </p>
3282             *
3283             * @param groupId the group ID
3284             * @param parentCategoryId the parent category ID
3285             * @param start the lower bound of the range of message boards categories
3286             * @param end the upper bound of the range of message boards categories (not inclusive)
3287             * @return the range of matching message boards categories that the user has permission to view
3288             * @throws SystemException if a system exception occurred
3289             */
3290            @Override
3291            public List<MBCategory> filterFindByG_P(long groupId,
3292                    long parentCategoryId, int start, int end) throws SystemException {
3293                    return filterFindByG_P(groupId, parentCategoryId, start, end, null);
3294            }
3295    
3296            /**
3297             * Returns an ordered range of all the message boards categories that the user has permissions to view where groupId = &#63; and parentCategoryId = &#63;.
3298             *
3299             * <p>
3300             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3301             * </p>
3302             *
3303             * @param groupId the group ID
3304             * @param parentCategoryId the parent category ID
3305             * @param start the lower bound of the range of message boards categories
3306             * @param end the upper bound of the range of message boards categories (not inclusive)
3307             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3308             * @return the ordered range of matching message boards categories that the user has permission to view
3309             * @throws SystemException if a system exception occurred
3310             */
3311            @Override
3312            public List<MBCategory> filterFindByG_P(long groupId,
3313                    long parentCategoryId, int start, int end,
3314                    OrderByComparator orderByComparator) throws SystemException {
3315                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3316                            return findByG_P(groupId, parentCategoryId, start, end,
3317                                    orderByComparator);
3318                    }
3319    
3320                    StringBundler query = null;
3321    
3322                    if (orderByComparator != null) {
3323                            query = new StringBundler(4 +
3324                                            (orderByComparator.getOrderByFields().length * 3));
3325                    }
3326                    else {
3327                            query = new StringBundler(4);
3328                    }
3329    
3330                    if (getDB().isSupportsInlineDistinct()) {
3331                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3332                    }
3333                    else {
3334                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3335                    }
3336    
3337                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3338    
3339                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3340    
3341                    if (!getDB().isSupportsInlineDistinct()) {
3342                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3343                    }
3344    
3345                    if (orderByComparator != null) {
3346                            if (getDB().isSupportsInlineDistinct()) {
3347                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3348                                            orderByComparator, true);
3349                            }
3350                            else {
3351                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3352                                            orderByComparator, true);
3353                            }
3354                    }
3355                    else {
3356                            if (getDB().isSupportsInlineDistinct()) {
3357                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3358                            }
3359                            else {
3360                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3361                            }
3362                    }
3363    
3364                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3365                                    MBCategory.class.getName(),
3366                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3367    
3368                    Session session = null;
3369    
3370                    try {
3371                            session = openSession();
3372    
3373                            SQLQuery q = session.createSQLQuery(sql);
3374    
3375                            if (getDB().isSupportsInlineDistinct()) {
3376                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3377                            }
3378                            else {
3379                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3380                            }
3381    
3382                            QueryPos qPos = QueryPos.getInstance(q);
3383    
3384                            qPos.add(groupId);
3385    
3386                            qPos.add(parentCategoryId);
3387    
3388                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3389                    }
3390                    catch (Exception e) {
3391                            throw processException(e);
3392                    }
3393                    finally {
3394                            closeSession(session);
3395                    }
3396            }
3397    
3398            /**
3399             * 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;.
3400             *
3401             * @param categoryId the primary key of the current message boards category
3402             * @param groupId the group ID
3403             * @param parentCategoryId the parent category ID
3404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3405             * @return the previous, current, and next message boards category
3406             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
3407             * @throws SystemException if a system exception occurred
3408             */
3409            @Override
3410            public MBCategory[] filterFindByG_P_PrevAndNext(long categoryId,
3411                    long groupId, long parentCategoryId, OrderByComparator orderByComparator)
3412                    throws NoSuchCategoryException, SystemException {
3413                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3414                            return findByG_P_PrevAndNext(categoryId, groupId, parentCategoryId,
3415                                    orderByComparator);
3416                    }
3417    
3418                    MBCategory mbCategory = findByPrimaryKey(categoryId);
3419    
3420                    Session session = null;
3421    
3422                    try {
3423                            session = openSession();
3424    
3425                            MBCategory[] array = new MBCategoryImpl[3];
3426    
3427                            array[0] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3428                                            parentCategoryId, orderByComparator, true);
3429    
3430                            array[1] = mbCategory;
3431    
3432                            array[2] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3433                                            parentCategoryId, orderByComparator, false);
3434    
3435                            return array;
3436                    }
3437                    catch (Exception e) {
3438                            throw processException(e);
3439                    }
3440                    finally {
3441                            closeSession(session);
3442                    }
3443            }
3444    
3445            protected MBCategory filterGetByG_P_PrevAndNext(Session session,
3446                    MBCategory mbCategory, long groupId, long parentCategoryId,
3447                    OrderByComparator orderByComparator, boolean previous) {
3448                    StringBundler query = null;
3449    
3450                    if (orderByComparator != null) {
3451                            query = new StringBundler(6 +
3452                                            (orderByComparator.getOrderByFields().length * 6));
3453                    }
3454                    else {
3455                            query = new StringBundler(3);
3456                    }
3457    
3458                    if (getDB().isSupportsInlineDistinct()) {
3459                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3460                    }
3461                    else {
3462                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3463                    }
3464    
3465                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3466    
3467                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3468    
3469                    if (!getDB().isSupportsInlineDistinct()) {
3470                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3471                    }
3472    
3473                    if (orderByComparator != null) {
3474                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3475    
3476                            if (orderByConditionFields.length > 0) {
3477                                    query.append(WHERE_AND);
3478                            }
3479    
3480                            for (int i = 0; i < orderByConditionFields.length; i++) {
3481                                    if (getDB().isSupportsInlineDistinct()) {
3482                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3483                                    }
3484                                    else {
3485                                            query.append(_ORDER_BY_ENTITY_TABLE);
3486                                    }
3487    
3488                                    query.append(orderByConditionFields[i]);
3489    
3490                                    if ((i + 1) < orderByConditionFields.length) {
3491                                            if (orderByComparator.isAscending() ^ previous) {
3492                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3493                                            }
3494                                            else {
3495                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3496                                            }
3497                                    }
3498                                    else {
3499                                            if (orderByComparator.isAscending() ^ previous) {
3500                                                    query.append(WHERE_GREATER_THAN);
3501                                            }
3502                                            else {
3503                                                    query.append(WHERE_LESSER_THAN);
3504                                            }
3505                                    }
3506                            }
3507    
3508                            query.append(ORDER_BY_CLAUSE);
3509    
3510                            String[] orderByFields = orderByComparator.getOrderByFields();
3511    
3512                            for (int i = 0; i < orderByFields.length; i++) {
3513                                    if (getDB().isSupportsInlineDistinct()) {
3514                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3515                                    }
3516                                    else {
3517                                            query.append(_ORDER_BY_ENTITY_TABLE);
3518                                    }
3519    
3520                                    query.append(orderByFields[i]);
3521    
3522                                    if ((i + 1) < orderByFields.length) {
3523                                            if (orderByComparator.isAscending() ^ previous) {
3524                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3525                                            }
3526                                            else {
3527                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3528                                            }
3529                                    }
3530                                    else {
3531                                            if (orderByComparator.isAscending() ^ previous) {
3532                                                    query.append(ORDER_BY_ASC);
3533                                            }
3534                                            else {
3535                                                    query.append(ORDER_BY_DESC);
3536                                            }
3537                                    }
3538                            }
3539                    }
3540                    else {
3541                            if (getDB().isSupportsInlineDistinct()) {
3542                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3543                            }
3544                            else {
3545                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3546                            }
3547                    }
3548    
3549                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3550                                    MBCategory.class.getName(),
3551                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3552    
3553                    SQLQuery q = session.createSQLQuery(sql);
3554    
3555                    q.setFirstResult(0);
3556                    q.setMaxResults(2);
3557    
3558                    if (getDB().isSupportsInlineDistinct()) {
3559                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3560                    }
3561                    else {
3562                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3563                    }
3564    
3565                    QueryPos qPos = QueryPos.getInstance(q);
3566    
3567                    qPos.add(groupId);
3568    
3569                    qPos.add(parentCategoryId);
3570    
3571                    if (orderByComparator != null) {
3572                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3573    
3574                            for (Object value : values) {
3575                                    qPos.add(value);
3576                            }
3577                    }
3578    
3579                    List<MBCategory> list = q.list();
3580    
3581                    if (list.size() == 2) {
3582                            return list.get(1);
3583                    }
3584                    else {
3585                            return null;
3586                    }
3587            }
3588    
3589            /**
3590             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
3591             *
3592             * @param groupId the group ID
3593             * @param parentCategoryIds the parent category IDs
3594             * @return the matching message boards categories that the user has permission to view
3595             * @throws SystemException if a system exception occurred
3596             */
3597            @Override
3598            public List<MBCategory> filterFindByG_P(long groupId,
3599                    long[] parentCategoryIds) throws SystemException {
3600                    return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3601                            QueryUtil.ALL_POS, null);
3602            }
3603    
3604            /**
3605             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
3606             *
3607             * <p>
3608             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3609             * </p>
3610             *
3611             * @param groupId the group ID
3612             * @param parentCategoryIds the parent category IDs
3613             * @param start the lower bound of the range of message boards categories
3614             * @param end the upper bound of the range of message boards categories (not inclusive)
3615             * @return the range of matching message boards categories that the user has permission to view
3616             * @throws SystemException if a system exception occurred
3617             */
3618            @Override
3619            public List<MBCategory> filterFindByG_P(long groupId,
3620                    long[] parentCategoryIds, int start, int end) throws SystemException {
3621                    return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
3622            }
3623    
3624            /**
3625             * Returns an ordered range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
3626             *
3627             * <p>
3628             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3629             * </p>
3630             *
3631             * @param groupId the group ID
3632             * @param parentCategoryIds the parent category IDs
3633             * @param start the lower bound of the range of message boards categories
3634             * @param end the upper bound of the range of message boards categories (not inclusive)
3635             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3636             * @return the ordered range of matching message boards categories that the user has permission to view
3637             * @throws SystemException if a system exception occurred
3638             */
3639            @Override
3640            public List<MBCategory> filterFindByG_P(long groupId,
3641                    long[] parentCategoryIds, int start, int end,
3642                    OrderByComparator orderByComparator) throws SystemException {
3643                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3644                            return findByG_P(groupId, parentCategoryIds, start, end,
3645                                    orderByComparator);
3646                    }
3647    
3648                    StringBundler query = new StringBundler();
3649    
3650                    if (getDB().isSupportsInlineDistinct()) {
3651                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3652                    }
3653                    else {
3654                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3655                    }
3656    
3657                    boolean conjunctionable = false;
3658    
3659                    if (conjunctionable) {
3660                            query.append(WHERE_AND);
3661                    }
3662    
3663                    query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3664    
3665                    conjunctionable = true;
3666    
3667                    if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3668                            if (conjunctionable) {
3669                                    query.append(WHERE_AND);
3670                            }
3671    
3672                            query.append(StringPool.OPEN_PARENTHESIS);
3673    
3674                            for (int i = 0; i < parentCategoryIds.length; i++) {
3675                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3676    
3677                                    if ((i + 1) < parentCategoryIds.length) {
3678                                            query.append(WHERE_OR);
3679                                    }
3680                            }
3681    
3682                            query.append(StringPool.CLOSE_PARENTHESIS);
3683    
3684                            conjunctionable = true;
3685                    }
3686    
3687                    if (!getDB().isSupportsInlineDistinct()) {
3688                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3689                    }
3690    
3691                    if (orderByComparator != null) {
3692                            if (getDB().isSupportsInlineDistinct()) {
3693                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3694                                            orderByComparator, true);
3695                            }
3696                            else {
3697                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3698                                            orderByComparator, true);
3699                            }
3700                    }
3701                    else {
3702                            if (getDB().isSupportsInlineDistinct()) {
3703                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3704                            }
3705                            else {
3706                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3707                            }
3708                    }
3709    
3710                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3711                                    MBCategory.class.getName(),
3712                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3713    
3714                    Session session = null;
3715    
3716                    try {
3717                            session = openSession();
3718    
3719                            SQLQuery q = session.createSQLQuery(sql);
3720    
3721                            if (getDB().isSupportsInlineDistinct()) {
3722                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3723                            }
3724                            else {
3725                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3726                            }
3727    
3728                            QueryPos qPos = QueryPos.getInstance(q);
3729    
3730                            qPos.add(groupId);
3731    
3732                            if (parentCategoryIds != null) {
3733                                    qPos.add(parentCategoryIds);
3734                            }
3735    
3736                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3737                    }
3738                    catch (Exception e) {
3739                            throw processException(e);
3740                    }
3741                    finally {
3742                            closeSession(session);
3743                    }
3744            }
3745    
3746            /**
3747             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3748             *
3749             * <p>
3750             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3751             * </p>
3752             *
3753             * @param groupId the group ID
3754             * @param parentCategoryIds the parent category IDs
3755             * @return the matching message boards categories
3756             * @throws SystemException if a system exception occurred
3757             */
3758            @Override
3759            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds)
3760                    throws SystemException {
3761                    return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3762                            QueryUtil.ALL_POS, null);
3763            }
3764    
3765            /**
3766             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3767             *
3768             * <p>
3769             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3770             * </p>
3771             *
3772             * @param groupId the group ID
3773             * @param parentCategoryIds the parent category IDs
3774             * @param start the lower bound of the range of message boards categories
3775             * @param end the upper bound of the range of message boards categories (not inclusive)
3776             * @return the range of matching message boards categories
3777             * @throws SystemException if a system exception occurred
3778             */
3779            @Override
3780            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3781                    int start, int end) throws SystemException {
3782                    return findByG_P(groupId, parentCategoryIds, start, end, null);
3783            }
3784    
3785            /**
3786             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3787             *
3788             * <p>
3789             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3790             * </p>
3791             *
3792             * @param groupId the group ID
3793             * @param parentCategoryIds the parent category IDs
3794             * @param start the lower bound of the range of message boards categories
3795             * @param end the upper bound of the range of message boards categories (not inclusive)
3796             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3797             * @return the ordered range of matching message boards categories
3798             * @throws SystemException if a system exception occurred
3799             */
3800            @Override
3801            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3802                    int start, int end, OrderByComparator orderByComparator)
3803                    throws SystemException {
3804                    if ((parentCategoryIds != null) && (parentCategoryIds.length == 1)) {
3805                            return findByG_P(groupId, parentCategoryIds[0], start, end,
3806                                    orderByComparator);
3807                    }
3808    
3809                    boolean pagination = true;
3810                    Object[] finderArgs = null;
3811    
3812                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3813                                    (orderByComparator == null)) {
3814                            pagination = false;
3815                            finderArgs = new Object[] {
3816                                            groupId, StringUtil.merge(parentCategoryIds)
3817                                    };
3818                    }
3819                    else {
3820                            finderArgs = new Object[] {
3821                                            groupId, StringUtil.merge(parentCategoryIds),
3822                                            
3823                                            start, end, orderByComparator
3824                                    };
3825                    }
3826    
3827                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3828                                    finderArgs, this);
3829    
3830                    if ((list != null) && !list.isEmpty()) {
3831                            for (MBCategory mbCategory : list) {
3832                                    if ((groupId != mbCategory.getGroupId()) ||
3833                                                    !ArrayUtil.contains(parentCategoryIds,
3834                                                            mbCategory.getParentCategoryId())) {
3835                                            list = null;
3836    
3837                                            break;
3838                                    }
3839                            }
3840                    }
3841    
3842                    if (list == null) {
3843                            StringBundler query = new StringBundler();
3844    
3845                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3846    
3847                            boolean conjunctionable = false;
3848    
3849                            if (conjunctionable) {
3850                                    query.append(WHERE_AND);
3851                            }
3852    
3853                            query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3854    
3855                            conjunctionable = true;
3856    
3857                            if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3858                                    if (conjunctionable) {
3859                                            query.append(WHERE_AND);
3860                                    }
3861    
3862                                    query.append(StringPool.OPEN_PARENTHESIS);
3863    
3864                                    for (int i = 0; i < parentCategoryIds.length; i++) {
3865                                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3866    
3867                                            if ((i + 1) < parentCategoryIds.length) {
3868                                                    query.append(WHERE_OR);
3869                                            }
3870                                    }
3871    
3872                                    query.append(StringPool.CLOSE_PARENTHESIS);
3873    
3874                                    conjunctionable = true;
3875                            }
3876    
3877                            if (orderByComparator != null) {
3878                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3879                                            orderByComparator);
3880                            }
3881                            else
3882                             if (pagination) {
3883                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3884                            }
3885    
3886                            String sql = query.toString();
3887    
3888                            Session session = null;
3889    
3890                            try {
3891                                    session = openSession();
3892    
3893                                    Query q = session.createQuery(sql);
3894    
3895                                    QueryPos qPos = QueryPos.getInstance(q);
3896    
3897                                    qPos.add(groupId);
3898    
3899                                    if (parentCategoryIds != null) {
3900                                            qPos.add(parentCategoryIds);
3901                                    }
3902    
3903                                    if (!pagination) {
3904                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3905                                                            start, end, false);
3906    
3907                                            Collections.sort(list);
3908    
3909                                            list = new UnmodifiableList<MBCategory>(list);
3910                                    }
3911                                    else {
3912                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3913                                                            start, end);
3914                                    }
3915    
3916                                    cacheResult(list);
3917    
3918                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3919                                            finderArgs, list);
3920                            }
3921                            catch (Exception e) {
3922                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P,
3923                                            finderArgs);
3924    
3925                                    throw processException(e);
3926                            }
3927                            finally {
3928                                    closeSession(session);
3929                            }
3930                    }
3931    
3932                    return list;
3933            }
3934    
3935            /**
3936             * Removes all the message boards categories where groupId = &#63; and parentCategoryId = &#63; from the database.
3937             *
3938             * @param groupId the group ID
3939             * @param parentCategoryId the parent category ID
3940             * @throws SystemException if a system exception occurred
3941             */
3942            @Override
3943            public void removeByG_P(long groupId, long parentCategoryId)
3944                    throws SystemException {
3945                    for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId,
3946                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3947                            remove(mbCategory);
3948                    }
3949            }
3950    
3951            /**
3952             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = &#63;.
3953             *
3954             * @param groupId the group ID
3955             * @param parentCategoryId the parent category ID
3956             * @return the number of matching message boards categories
3957             * @throws SystemException if a system exception occurred
3958             */
3959            @Override
3960            public int countByG_P(long groupId, long parentCategoryId)
3961                    throws SystemException {
3962                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P;
3963    
3964                    Object[] finderArgs = new Object[] { groupId, parentCategoryId };
3965    
3966                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3967                                    this);
3968    
3969                    if (count == null) {
3970                            StringBundler query = new StringBundler(3);
3971    
3972                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3973    
3974                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3975    
3976                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3977    
3978                            String sql = query.toString();
3979    
3980                            Session session = null;
3981    
3982                            try {
3983                                    session = openSession();
3984    
3985                                    Query q = session.createQuery(sql);
3986    
3987                                    QueryPos qPos = QueryPos.getInstance(q);
3988    
3989                                    qPos.add(groupId);
3990    
3991                                    qPos.add(parentCategoryId);
3992    
3993                                    count = (Long)q.uniqueResult();
3994    
3995                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3996                            }
3997                            catch (Exception e) {
3998                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3999    
4000                                    throw processException(e);
4001                            }
4002                            finally {
4003                                    closeSession(session);
4004                            }
4005                    }
4006    
4007                    return count.intValue();
4008            }
4009    
4010            /**
4011             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
4012             *
4013             * @param groupId the group ID
4014             * @param parentCategoryIds the parent category IDs
4015             * @return the number of matching message boards categories
4016             * @throws SystemException if a system exception occurred
4017             */
4018            @Override
4019            public int countByG_P(long groupId, long[] parentCategoryIds)
4020                    throws SystemException {
4021                    Object[] finderArgs = new Object[] {
4022                                    groupId, StringUtil.merge(parentCategoryIds)
4023                            };
4024    
4025                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
4026                                    finderArgs, this);
4027    
4028                    if (count == null) {
4029                            StringBundler query = new StringBundler();
4030    
4031                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4032    
4033                            boolean conjunctionable = false;
4034    
4035                            if (conjunctionable) {
4036                                    query.append(WHERE_AND);
4037                            }
4038    
4039                            query.append(_FINDER_COLUMN_G_P_GROUPID_5);
4040    
4041                            conjunctionable = true;
4042    
4043                            if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
4044                                    if (conjunctionable) {
4045                                            query.append(WHERE_AND);
4046                                    }
4047    
4048                                    query.append(StringPool.OPEN_PARENTHESIS);
4049    
4050                                    for (int i = 0; i < parentCategoryIds.length; i++) {
4051                                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
4052    
4053                                            if ((i + 1) < parentCategoryIds.length) {
4054                                                    query.append(WHERE_OR);
4055                                            }
4056                                    }
4057    
4058                                    query.append(StringPool.CLOSE_PARENTHESIS);
4059    
4060                                    conjunctionable = true;
4061                            }
4062    
4063                            String sql = query.toString();
4064    
4065                            Session session = null;
4066    
4067                            try {
4068                                    session = openSession();
4069    
4070                                    Query q = session.createQuery(sql);
4071    
4072                                    QueryPos qPos = QueryPos.getInstance(q);
4073    
4074                                    qPos.add(groupId);
4075    
4076                                    if (parentCategoryIds != null) {
4077                                            qPos.add(parentCategoryIds);
4078                                    }
4079    
4080                                    count = (Long)q.uniqueResult();
4081    
4082                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
4083                                            finderArgs, count);
4084                            }
4085                            catch (Exception e) {
4086                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
4087                                            finderArgs);
4088    
4089                                    throw processException(e);
4090                            }
4091                            finally {
4092                                    closeSession(session);
4093                            }
4094                    }
4095    
4096                    return count.intValue();
4097            }
4098    
4099            /**
4100             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
4101             *
4102             * @param groupId the group ID
4103             * @param parentCategoryId the parent category ID
4104             * @return the number of matching message boards categories that the user has permission to view
4105             * @throws SystemException if a system exception occurred
4106             */
4107            @Override
4108            public int filterCountByG_P(long groupId, long parentCategoryId)
4109                    throws SystemException {
4110                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4111                            return countByG_P(groupId, parentCategoryId);
4112                    }
4113    
4114                    StringBundler query = new StringBundler(3);
4115    
4116                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4117    
4118                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4119    
4120                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
4121    
4122                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4123                                    MBCategory.class.getName(),
4124                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4125    
4126                    Session session = null;
4127    
4128                    try {
4129                            session = openSession();
4130    
4131                            SQLQuery q = session.createSQLQuery(sql);
4132    
4133                            q.addScalar(COUNT_COLUMN_NAME,
4134                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4135    
4136                            QueryPos qPos = QueryPos.getInstance(q);
4137    
4138                            qPos.add(groupId);
4139    
4140                            qPos.add(parentCategoryId);
4141    
4142                            Long count = (Long)q.uniqueResult();
4143    
4144                            return count.intValue();
4145                    }
4146                    catch (Exception e) {
4147                            throw processException(e);
4148                    }
4149                    finally {
4150                            closeSession(session);
4151                    }
4152            }
4153    
4154            /**
4155             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
4156             *
4157             * @param groupId the group ID
4158             * @param parentCategoryIds the parent category IDs
4159             * @return the number of matching message boards categories that the user has permission to view
4160             * @throws SystemException if a system exception occurred
4161             */
4162            @Override
4163            public int filterCountByG_P(long groupId, long[] parentCategoryIds)
4164                    throws SystemException {
4165                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4166                            return countByG_P(groupId, parentCategoryIds);
4167                    }
4168    
4169                    StringBundler query = new StringBundler();
4170    
4171                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4172    
4173                    boolean conjunctionable = false;
4174    
4175                    if (conjunctionable) {
4176                            query.append(WHERE_AND);
4177                    }
4178    
4179                    query.append(_FINDER_COLUMN_G_P_GROUPID_5);
4180    
4181                    conjunctionable = true;
4182    
4183                    if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
4184                            if (conjunctionable) {
4185                                    query.append(WHERE_AND);
4186                            }
4187    
4188                            query.append(StringPool.OPEN_PARENTHESIS);
4189    
4190                            for (int i = 0; i < parentCategoryIds.length; i++) {
4191                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
4192    
4193                                    if ((i + 1) < parentCategoryIds.length) {
4194                                            query.append(WHERE_OR);
4195                                    }
4196                            }
4197    
4198                            query.append(StringPool.CLOSE_PARENTHESIS);
4199    
4200                            conjunctionable = true;
4201                    }
4202    
4203                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4204                                    MBCategory.class.getName(),
4205                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4206    
4207                    Session session = null;
4208    
4209                    try {
4210                            session = openSession();
4211    
4212                            SQLQuery q = session.createSQLQuery(sql);
4213    
4214                            q.addScalar(COUNT_COLUMN_NAME,
4215                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4216    
4217                            QueryPos qPos = QueryPos.getInstance(q);
4218    
4219                            qPos.add(groupId);
4220    
4221                            if (parentCategoryIds != null) {
4222                                    qPos.add(parentCategoryIds);
4223                            }
4224    
4225                            Long count = (Long)q.uniqueResult();
4226    
4227                            return count.intValue();
4228                    }
4229                    catch (Exception e) {
4230                            throw processException(e);
4231                    }
4232                    finally {
4233                            closeSession(session);
4234                    }
4235            }
4236    
4237            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
4238            private static final String _FINDER_COLUMN_G_P_GROUPID_5 = "(" +
4239                    removeConjunction(_FINDER_COLUMN_G_P_GROUPID_2) + ")";
4240            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
4241            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_5 = "(" +
4242                    removeConjunction(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2) + ")";
4243            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4244                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4245                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
4246                            new String[] {
4247                                    Long.class.getName(), Integer.class.getName(),
4248                                    
4249                            Integer.class.getName(), Integer.class.getName(),
4250                                    OrderByComparator.class.getName()
4251                            });
4252            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4253                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
4254                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
4255                            new String[] { Long.class.getName(), Integer.class.getName() },
4256                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
4257                            MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
4258                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
4259                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
4260            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
4261                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
4262                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
4263                            new String[] { Long.class.getName(), Integer.class.getName() });
4264    
4265            /**
4266             * Returns all the message boards categories where groupId = &#63; and status = &#63;.
4267             *
4268             * @param groupId the group ID
4269             * @param status the status
4270             * @return the matching message boards categories
4271             * @throws SystemException if a system exception occurred
4272             */
4273            @Override
4274            public List<MBCategory> findByG_S(long groupId, int status)
4275                    throws SystemException {
4276                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4277                            null);
4278            }
4279    
4280            /**
4281             * Returns a range of all the message boards categories where groupId = &#63; and status = &#63;.
4282             *
4283             * <p>
4284             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4285             * </p>
4286             *
4287             * @param groupId the group ID
4288             * @param status the status
4289             * @param start the lower bound of the range of message boards categories
4290             * @param end the upper bound of the range of message boards categories (not inclusive)
4291             * @return the range of matching message boards categories
4292             * @throws SystemException if a system exception occurred
4293             */
4294            @Override
4295            public List<MBCategory> findByG_S(long groupId, int status, int start,
4296                    int end) throws SystemException {
4297                    return findByG_S(groupId, status, start, end, null);
4298            }
4299    
4300            /**
4301             * Returns an ordered range of all the message boards categories where groupId = &#63; and status = &#63;.
4302             *
4303             * <p>
4304             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4305             * </p>
4306             *
4307             * @param groupId the group ID
4308             * @param status the status
4309             * @param start the lower bound of the range of message boards categories
4310             * @param end the upper bound of the range of message boards categories (not inclusive)
4311             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4312             * @return the ordered range of matching message boards categories
4313             * @throws SystemException if a system exception occurred
4314             */
4315            @Override
4316            public List<MBCategory> findByG_S(long groupId, int status, int start,
4317                    int end, OrderByComparator orderByComparator) throws SystemException {
4318                    boolean pagination = true;
4319                    FinderPath finderPath = null;
4320                    Object[] finderArgs = null;
4321    
4322                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4323                                    (orderByComparator == null)) {
4324                            pagination = false;
4325                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
4326                            finderArgs = new Object[] { groupId, status };
4327                    }
4328                    else {
4329                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
4330                            finderArgs = new Object[] {
4331                                            groupId, status,
4332                                            
4333                                            start, end, orderByComparator
4334                                    };
4335                    }
4336    
4337                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
4338                                    finderArgs, this);
4339    
4340                    if ((list != null) && !list.isEmpty()) {
4341                            for (MBCategory mbCategory : list) {
4342                                    if ((groupId != mbCategory.getGroupId()) ||
4343                                                    (status != mbCategory.getStatus())) {
4344                                            list = null;
4345    
4346                                            break;
4347                                    }
4348                            }
4349                    }
4350    
4351                    if (list == null) {
4352                            StringBundler query = null;
4353    
4354                            if (orderByComparator != null) {
4355                                    query = new StringBundler(4 +
4356                                                    (orderByComparator.getOrderByFields().length * 3));
4357                            }
4358                            else {
4359                                    query = new StringBundler(4);
4360                            }
4361    
4362                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4363    
4364                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4365    
4366                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
4367    
4368                            if (orderByComparator != null) {
4369                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4370                                            orderByComparator);
4371                            }
4372                            else
4373                             if (pagination) {
4374                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4375                            }
4376    
4377                            String sql = query.toString();
4378    
4379                            Session session = null;
4380    
4381                            try {
4382                                    session = openSession();
4383    
4384                                    Query q = session.createQuery(sql);
4385    
4386                                    QueryPos qPos = QueryPos.getInstance(q);
4387    
4388                                    qPos.add(groupId);
4389    
4390                                    qPos.add(status);
4391    
4392                                    if (!pagination) {
4393                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4394                                                            start, end, false);
4395    
4396                                            Collections.sort(list);
4397    
4398                                            list = new UnmodifiableList<MBCategory>(list);
4399                                    }
4400                                    else {
4401                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
4402                                                            start, end);
4403                                    }
4404    
4405                                    cacheResult(list);
4406    
4407                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4408                            }
4409                            catch (Exception e) {
4410                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4411    
4412                                    throw processException(e);
4413                            }
4414                            finally {
4415                                    closeSession(session);
4416                            }
4417                    }
4418    
4419                    return list;
4420            }
4421    
4422            /**
4423             * Returns the first message boards category in the ordered set where groupId = &#63; and status = &#63;.
4424             *
4425             * @param groupId the group ID
4426             * @param status the status
4427             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4428             * @return the first matching message boards category
4429             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
4430             * @throws SystemException if a system exception occurred
4431             */
4432            @Override
4433            public MBCategory findByG_S_First(long groupId, int status,
4434                    OrderByComparator orderByComparator)
4435                    throws NoSuchCategoryException, SystemException {
4436                    MBCategory mbCategory = fetchByG_S_First(groupId, status,
4437                                    orderByComparator);
4438    
4439                    if (mbCategory != null) {
4440                            return mbCategory;
4441                    }
4442    
4443                    StringBundler msg = new StringBundler(6);
4444    
4445                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4446    
4447                    msg.append("groupId=");
4448                    msg.append(groupId);
4449    
4450                    msg.append(", status=");
4451                    msg.append(status);
4452    
4453                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4454    
4455                    throw new NoSuchCategoryException(msg.toString());
4456            }
4457    
4458            /**
4459             * Returns the first message boards category in the ordered set where groupId = &#63; and status = &#63;.
4460             *
4461             * @param groupId the group ID
4462             * @param status the status
4463             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4464             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
4465             * @throws SystemException if a system exception occurred
4466             */
4467            @Override
4468            public MBCategory fetchByG_S_First(long groupId, int status,
4469                    OrderByComparator orderByComparator) throws SystemException {
4470                    List<MBCategory> list = findByG_S(groupId, status, 0, 1,
4471                                    orderByComparator);
4472    
4473                    if (!list.isEmpty()) {
4474                            return list.get(0);
4475                    }
4476    
4477                    return null;
4478            }
4479    
4480            /**
4481             * Returns the last message boards category in the ordered set where groupId = &#63; and status = &#63;.
4482             *
4483             * @param groupId the group ID
4484             * @param status the status
4485             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4486             * @return the last matching message boards category
4487             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
4488             * @throws SystemException if a system exception occurred
4489             */
4490            @Override
4491            public MBCategory findByG_S_Last(long groupId, int status,
4492                    OrderByComparator orderByComparator)
4493                    throws NoSuchCategoryException, SystemException {
4494                    MBCategory mbCategory = fetchByG_S_Last(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 last 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 last matching message boards category, or <code>null</code> if a matching message boards category could not be found
4523             * @throws SystemException if a system exception occurred
4524             */
4525            @Override
4526            public MBCategory fetchByG_S_Last(long groupId, int status,
4527                    OrderByComparator orderByComparator) throws SystemException {
4528                    int count = countByG_S(groupId, status);
4529    
4530                    if (count == 0) {
4531                            return null;
4532                    }
4533    
4534                    List<MBCategory> list = findByG_S(groupId, status, count - 1, count,
4535                                    orderByComparator);
4536    
4537                    if (!list.isEmpty()) {
4538                            return list.get(0);
4539                    }
4540    
4541                    return null;
4542            }
4543    
4544            /**
4545             * Returns the message boards categories before and after the current message boards category in the ordered set where groupId = &#63; and status = &#63;.
4546             *
4547             * @param categoryId the primary key of the current message boards category
4548             * @param groupId the group ID
4549             * @param status the status
4550             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4551             * @return the previous, current, and next message boards category
4552             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
4553             * @throws SystemException if a system exception occurred
4554             */
4555            @Override
4556            public MBCategory[] findByG_S_PrevAndNext(long categoryId, long groupId,
4557                    int status, OrderByComparator orderByComparator)
4558                    throws NoSuchCategoryException, SystemException {
4559                    MBCategory mbCategory = findByPrimaryKey(categoryId);
4560    
4561                    Session session = null;
4562    
4563                    try {
4564                            session = openSession();
4565    
4566                            MBCategory[] array = new MBCategoryImpl[3];
4567    
4568                            array[0] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4569                                            status, orderByComparator, true);
4570    
4571                            array[1] = mbCategory;
4572    
4573                            array[2] = getByG_S_PrevAndNext(session, mbCategory, groupId,
4574                                            status, orderByComparator, false);
4575    
4576                            return array;
4577                    }
4578                    catch (Exception e) {
4579                            throw processException(e);
4580                    }
4581                    finally {
4582                            closeSession(session);
4583                    }
4584            }
4585    
4586            protected MBCategory getByG_S_PrevAndNext(Session session,
4587                    MBCategory mbCategory, long groupId, int status,
4588                    OrderByComparator orderByComparator, boolean previous) {
4589                    StringBundler query = null;
4590    
4591                    if (orderByComparator != null) {
4592                            query = new StringBundler(6 +
4593                                            (orderByComparator.getOrderByFields().length * 6));
4594                    }
4595                    else {
4596                            query = new StringBundler(3);
4597                    }
4598    
4599                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
4600    
4601                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4602    
4603                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4604    
4605                    if (orderByComparator != null) {
4606                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4607    
4608                            if (orderByConditionFields.length > 0) {
4609                                    query.append(WHERE_AND);
4610                            }
4611    
4612                            for (int i = 0; i < orderByConditionFields.length; i++) {
4613                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4614                                    query.append(orderByConditionFields[i]);
4615    
4616                                    if ((i + 1) < orderByConditionFields.length) {
4617                                            if (orderByComparator.isAscending() ^ previous) {
4618                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4619                                            }
4620                                            else {
4621                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4622                                            }
4623                                    }
4624                                    else {
4625                                            if (orderByComparator.isAscending() ^ previous) {
4626                                                    query.append(WHERE_GREATER_THAN);
4627                                            }
4628                                            else {
4629                                                    query.append(WHERE_LESSER_THAN);
4630                                            }
4631                                    }
4632                            }
4633    
4634                            query.append(ORDER_BY_CLAUSE);
4635    
4636                            String[] orderByFields = orderByComparator.getOrderByFields();
4637    
4638                            for (int i = 0; i < orderByFields.length; i++) {
4639                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4640                                    query.append(orderByFields[i]);
4641    
4642                                    if ((i + 1) < orderByFields.length) {
4643                                            if (orderByComparator.isAscending() ^ previous) {
4644                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4645                                            }
4646                                            else {
4647                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4648                                            }
4649                                    }
4650                                    else {
4651                                            if (orderByComparator.isAscending() ^ previous) {
4652                                                    query.append(ORDER_BY_ASC);
4653                                            }
4654                                            else {
4655                                                    query.append(ORDER_BY_DESC);
4656                                            }
4657                                    }
4658                            }
4659                    }
4660                    else {
4661                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4662                    }
4663    
4664                    String sql = query.toString();
4665    
4666                    Query q = session.createQuery(sql);
4667    
4668                    q.setFirstResult(0);
4669                    q.setMaxResults(2);
4670    
4671                    QueryPos qPos = QueryPos.getInstance(q);
4672    
4673                    qPos.add(groupId);
4674    
4675                    qPos.add(status);
4676    
4677                    if (orderByComparator != null) {
4678                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
4679    
4680                            for (Object value : values) {
4681                                    qPos.add(value);
4682                            }
4683                    }
4684    
4685                    List<MBCategory> list = q.list();
4686    
4687                    if (list.size() == 2) {
4688                            return list.get(1);
4689                    }
4690                    else {
4691                            return null;
4692                    }
4693            }
4694    
4695            /**
4696             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and status = &#63;.
4697             *
4698             * @param groupId the group ID
4699             * @param status the status
4700             * @return the matching message boards categories that the user has permission to view
4701             * @throws SystemException if a system exception occurred
4702             */
4703            @Override
4704            public List<MBCategory> filterFindByG_S(long groupId, int status)
4705                    throws SystemException {
4706                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
4707                            QueryUtil.ALL_POS, null);
4708            }
4709    
4710            /**
4711             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and status = &#63;.
4712             *
4713             * <p>
4714             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4715             * </p>
4716             *
4717             * @param groupId the group ID
4718             * @param status the status
4719             * @param start the lower bound of the range of message boards categories
4720             * @param end the upper bound of the range of message boards categories (not inclusive)
4721             * @return the range of matching message boards categories that the user has permission to view
4722             * @throws SystemException if a system exception occurred
4723             */
4724            @Override
4725            public List<MBCategory> filterFindByG_S(long groupId, int status,
4726                    int start, int end) throws SystemException {
4727                    return filterFindByG_S(groupId, status, start, end, null);
4728            }
4729    
4730            /**
4731             * Returns an ordered range of all the message boards categories that the user has permissions to view where groupId = &#63; and status = &#63;.
4732             *
4733             * <p>
4734             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4735             * </p>
4736             *
4737             * @param groupId the group ID
4738             * @param status the status
4739             * @param start the lower bound of the range of message boards categories
4740             * @param end the upper bound of the range of message boards categories (not inclusive)
4741             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4742             * @return the ordered range of matching message boards categories that the user has permission to view
4743             * @throws SystemException if a system exception occurred
4744             */
4745            @Override
4746            public List<MBCategory> filterFindByG_S(long groupId, int status,
4747                    int start, int end, OrderByComparator orderByComparator)
4748                    throws SystemException {
4749                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4750                            return findByG_S(groupId, status, start, end, orderByComparator);
4751                    }
4752    
4753                    StringBundler query = null;
4754    
4755                    if (orderByComparator != null) {
4756                            query = new StringBundler(4 +
4757                                            (orderByComparator.getOrderByFields().length * 3));
4758                    }
4759                    else {
4760                            query = new StringBundler(4);
4761                    }
4762    
4763                    if (getDB().isSupportsInlineDistinct()) {
4764                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4765                    }
4766                    else {
4767                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4768                    }
4769    
4770                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4771    
4772                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4773    
4774                    if (!getDB().isSupportsInlineDistinct()) {
4775                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4776                    }
4777    
4778                    if (orderByComparator != null) {
4779                            if (getDB().isSupportsInlineDistinct()) {
4780                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4781                                            orderByComparator, true);
4782                            }
4783                            else {
4784                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4785                                            orderByComparator, true);
4786                            }
4787                    }
4788                    else {
4789                            if (getDB().isSupportsInlineDistinct()) {
4790                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4791                            }
4792                            else {
4793                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
4794                            }
4795                    }
4796    
4797                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4798                                    MBCategory.class.getName(),
4799                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4800    
4801                    Session session = null;
4802    
4803                    try {
4804                            session = openSession();
4805    
4806                            SQLQuery q = session.createSQLQuery(sql);
4807    
4808                            if (getDB().isSupportsInlineDistinct()) {
4809                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
4810                            }
4811                            else {
4812                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
4813                            }
4814    
4815                            QueryPos qPos = QueryPos.getInstance(q);
4816    
4817                            qPos.add(groupId);
4818    
4819                            qPos.add(status);
4820    
4821                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
4822                    }
4823                    catch (Exception e) {
4824                            throw processException(e);
4825                    }
4826                    finally {
4827                            closeSession(session);
4828                    }
4829            }
4830    
4831            /**
4832             * 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;.
4833             *
4834             * @param categoryId the primary key of the current message boards category
4835             * @param groupId the group ID
4836             * @param status the status
4837             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4838             * @return the previous, current, and next message boards category
4839             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
4840             * @throws SystemException if a system exception occurred
4841             */
4842            @Override
4843            public MBCategory[] filterFindByG_S_PrevAndNext(long categoryId,
4844                    long groupId, int status, OrderByComparator orderByComparator)
4845                    throws NoSuchCategoryException, SystemException {
4846                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4847                            return findByG_S_PrevAndNext(categoryId, groupId, status,
4848                                    orderByComparator);
4849                    }
4850    
4851                    MBCategory mbCategory = findByPrimaryKey(categoryId);
4852    
4853                    Session session = null;
4854    
4855                    try {
4856                            session = openSession();
4857    
4858                            MBCategory[] array = new MBCategoryImpl[3];
4859    
4860                            array[0] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4861                                            status, orderByComparator, true);
4862    
4863                            array[1] = mbCategory;
4864    
4865                            array[2] = filterGetByG_S_PrevAndNext(session, mbCategory, groupId,
4866                                            status, orderByComparator, false);
4867    
4868                            return array;
4869                    }
4870                    catch (Exception e) {
4871                            throw processException(e);
4872                    }
4873                    finally {
4874                            closeSession(session);
4875                    }
4876            }
4877    
4878            protected MBCategory filterGetByG_S_PrevAndNext(Session session,
4879                    MBCategory mbCategory, long groupId, int status,
4880                    OrderByComparator orderByComparator, boolean previous) {
4881                    StringBundler query = null;
4882    
4883                    if (orderByComparator != null) {
4884                            query = new StringBundler(6 +
4885                                            (orderByComparator.getOrderByFields().length * 6));
4886                    }
4887                    else {
4888                            query = new StringBundler(3);
4889                    }
4890    
4891                    if (getDB().isSupportsInlineDistinct()) {
4892                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
4893                    }
4894                    else {
4895                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
4896                    }
4897    
4898                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
4899    
4900                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
4901    
4902                    if (!getDB().isSupportsInlineDistinct()) {
4903                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
4904                    }
4905    
4906                    if (orderByComparator != null) {
4907                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4908    
4909                            if (orderByConditionFields.length > 0) {
4910                                    query.append(WHERE_AND);
4911                            }
4912    
4913                            for (int i = 0; i < orderByConditionFields.length; i++) {
4914                                    if (getDB().isSupportsInlineDistinct()) {
4915                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4916                                    }
4917                                    else {
4918                                            query.append(_ORDER_BY_ENTITY_TABLE);
4919                                    }
4920    
4921                                    query.append(orderByConditionFields[i]);
4922    
4923                                    if ((i + 1) < orderByConditionFields.length) {
4924                                            if (orderByComparator.isAscending() ^ previous) {
4925                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4926                                            }
4927                                            else {
4928                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4929                                            }
4930                                    }
4931                                    else {
4932                                            if (orderByComparator.isAscending() ^ previous) {
4933                                                    query.append(WHERE_GREATER_THAN);
4934                                            }
4935                                            else {
4936                                                    query.append(WHERE_LESSER_THAN);
4937                                            }
4938                                    }
4939                            }
4940    
4941                            query.append(ORDER_BY_CLAUSE);
4942    
4943                            String[] orderByFields = orderByComparator.getOrderByFields();
4944    
4945                            for (int i = 0; i < orderByFields.length; i++) {
4946                                    if (getDB().isSupportsInlineDistinct()) {
4947                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4948                                    }
4949                                    else {
4950                                            query.append(_ORDER_BY_ENTITY_TABLE);
4951                                    }
4952    
4953                                    query.append(orderByFields[i]);
4954    
4955                                    if ((i + 1) < orderByFields.length) {
4956                                            if (orderByComparator.isAscending() ^ previous) {
4957                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4958                                            }
4959                                            else {
4960                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4961                                            }
4962                                    }
4963                                    else {
4964                                            if (orderByComparator.isAscending() ^ previous) {
4965                                                    query.append(ORDER_BY_ASC);
4966                                            }
4967                                            else {
4968                                                    query.append(ORDER_BY_DESC);
4969                                            }
4970                                    }
4971                            }
4972                    }
4973                    else {
4974                            if (getDB().isSupportsInlineDistinct()) {
4975                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
4976                            }
4977                            else {
4978                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
4979                            }
4980                    }
4981    
4982                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4983                                    MBCategory.class.getName(),
4984                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4985    
4986                    SQLQuery q = session.createSQLQuery(sql);
4987    
4988                    q.setFirstResult(0);
4989                    q.setMaxResults(2);
4990    
4991                    if (getDB().isSupportsInlineDistinct()) {
4992                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
4993                    }
4994                    else {
4995                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
4996                    }
4997    
4998                    QueryPos qPos = QueryPos.getInstance(q);
4999    
5000                    qPos.add(groupId);
5001    
5002                    qPos.add(status);
5003    
5004                    if (orderByComparator != null) {
5005                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
5006    
5007                            for (Object value : values) {
5008                                    qPos.add(value);
5009                            }
5010                    }
5011    
5012                    List<MBCategory> list = q.list();
5013    
5014                    if (list.size() == 2) {
5015                            return list.get(1);
5016                    }
5017                    else {
5018                            return null;
5019                    }
5020            }
5021    
5022            /**
5023             * Removes all the message boards categories where groupId = &#63; and status = &#63; from the database.
5024             *
5025             * @param groupId the group ID
5026             * @param status the status
5027             * @throws SystemException if a system exception occurred
5028             */
5029            @Override
5030            public void removeByG_S(long groupId, int status) throws SystemException {
5031                    for (MBCategory mbCategory : findByG_S(groupId, status,
5032                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5033                            remove(mbCategory);
5034                    }
5035            }
5036    
5037            /**
5038             * Returns the number of message boards categories where groupId = &#63; and status = &#63;.
5039             *
5040             * @param groupId the group ID
5041             * @param status the status
5042             * @return the number of matching message boards categories
5043             * @throws SystemException if a system exception occurred
5044             */
5045            @Override
5046            public int countByG_S(long groupId, int status) throws SystemException {
5047                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
5048    
5049                    Object[] finderArgs = new Object[] { groupId, status };
5050    
5051                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5052                                    this);
5053    
5054                    if (count == null) {
5055                            StringBundler query = new StringBundler(3);
5056    
5057                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
5058    
5059                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5060    
5061                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
5062    
5063                            String sql = query.toString();
5064    
5065                            Session session = null;
5066    
5067                            try {
5068                                    session = openSession();
5069    
5070                                    Query q = session.createQuery(sql);
5071    
5072                                    QueryPos qPos = QueryPos.getInstance(q);
5073    
5074                                    qPos.add(groupId);
5075    
5076                                    qPos.add(status);
5077    
5078                                    count = (Long)q.uniqueResult();
5079    
5080                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5081                            }
5082                            catch (Exception e) {
5083                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5084    
5085                                    throw processException(e);
5086                            }
5087                            finally {
5088                                    closeSession(session);
5089                            }
5090                    }
5091    
5092                    return count.intValue();
5093            }
5094    
5095            /**
5096             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and status = &#63;.
5097             *
5098             * @param groupId the group ID
5099             * @param status the status
5100             * @return the number of matching message boards categories that the user has permission to view
5101             * @throws SystemException if a system exception occurred
5102             */
5103            @Override
5104            public int filterCountByG_S(long groupId, int status)
5105                    throws SystemException {
5106                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5107                            return countByG_S(groupId, status);
5108                    }
5109    
5110                    StringBundler query = new StringBundler(3);
5111    
5112                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
5113    
5114                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
5115    
5116                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
5117    
5118                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5119                                    MBCategory.class.getName(),
5120                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5121    
5122                    Session session = null;
5123    
5124                    try {
5125                            session = openSession();
5126    
5127                            SQLQuery q = session.createSQLQuery(sql);
5128    
5129                            q.addScalar(COUNT_COLUMN_NAME,
5130                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5131    
5132                            QueryPos qPos = QueryPos.getInstance(q);
5133    
5134                            qPos.add(groupId);
5135    
5136                            qPos.add(status);
5137    
5138                            Long count = (Long)q.uniqueResult();
5139    
5140                            return count.intValue();
5141                    }
5142                    catch (Exception e) {
5143                            throw processException(e);
5144                    }
5145                    finally {
5146                            closeSession(session);
5147                    }
5148            }
5149    
5150            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
5151            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbCategory.status = ?";
5152            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5153                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5154                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
5155                            new String[] {
5156                                    Long.class.getName(), Integer.class.getName(),
5157                                    
5158                            Integer.class.getName(), Integer.class.getName(),
5159                                    OrderByComparator.class.getName()
5160                            });
5161            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5162                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5163                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
5164                            new String[] { Long.class.getName(), Integer.class.getName() },
5165                            MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK |
5166                            MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
5167                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5168                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
5169            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5170                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5171                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
5172                            new String[] { Long.class.getName(), Integer.class.getName() });
5173    
5174            /**
5175             * Returns all the message boards categories where companyId = &#63; and status = &#63;.
5176             *
5177             * @param companyId the company ID
5178             * @param status the status
5179             * @return the matching message boards categories
5180             * @throws SystemException if a system exception occurred
5181             */
5182            @Override
5183            public List<MBCategory> findByC_S(long companyId, int status)
5184                    throws SystemException {
5185                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
5186                            QueryUtil.ALL_POS, null);
5187            }
5188    
5189            /**
5190             * Returns a range of all the message boards categories where companyId = &#63; and status = &#63;.
5191             *
5192             * <p>
5193             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5194             * </p>
5195             *
5196             * @param companyId the company ID
5197             * @param status the status
5198             * @param start the lower bound of the range of message boards categories
5199             * @param end the upper bound of the range of message boards categories (not inclusive)
5200             * @return the range of matching message boards categories
5201             * @throws SystemException if a system exception occurred
5202             */
5203            @Override
5204            public List<MBCategory> findByC_S(long companyId, int status, int start,
5205                    int end) throws SystemException {
5206                    return findByC_S(companyId, status, start, end, null);
5207            }
5208    
5209            /**
5210             * Returns an ordered range of all the message boards categories where companyId = &#63; and status = &#63;.
5211             *
5212             * <p>
5213             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5214             * </p>
5215             *
5216             * @param companyId the company ID
5217             * @param status the status
5218             * @param start the lower bound of the range of message boards categories
5219             * @param end the upper bound of the range of message boards categories (not inclusive)
5220             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5221             * @return the ordered range of matching message boards categories
5222             * @throws SystemException if a system exception occurred
5223             */
5224            @Override
5225            public List<MBCategory> findByC_S(long companyId, int status, int start,
5226                    int end, OrderByComparator orderByComparator) throws SystemException {
5227                    boolean pagination = true;
5228                    FinderPath finderPath = null;
5229                    Object[] finderArgs = null;
5230    
5231                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5232                                    (orderByComparator == null)) {
5233                            pagination = false;
5234                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
5235                            finderArgs = new Object[] { companyId, status };
5236                    }
5237                    else {
5238                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
5239                            finderArgs = new Object[] {
5240                                            companyId, status,
5241                                            
5242                                            start, end, orderByComparator
5243                                    };
5244                    }
5245    
5246                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
5247                                    finderArgs, this);
5248    
5249                    if ((list != null) && !list.isEmpty()) {
5250                            for (MBCategory mbCategory : list) {
5251                                    if ((companyId != mbCategory.getCompanyId()) ||
5252                                                    (status != mbCategory.getStatus())) {
5253                                            list = null;
5254    
5255                                            break;
5256                                    }
5257                            }
5258                    }
5259    
5260                    if (list == null) {
5261                            StringBundler query = null;
5262    
5263                            if (orderByComparator != null) {
5264                                    query = new StringBundler(4 +
5265                                                    (orderByComparator.getOrderByFields().length * 3));
5266                            }
5267                            else {
5268                                    query = new StringBundler(4);
5269                            }
5270    
5271                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5272    
5273                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5274    
5275                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
5276    
5277                            if (orderByComparator != null) {
5278                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5279                                            orderByComparator);
5280                            }
5281                            else
5282                             if (pagination) {
5283                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5284                            }
5285    
5286                            String sql = query.toString();
5287    
5288                            Session session = null;
5289    
5290                            try {
5291                                    session = openSession();
5292    
5293                                    Query q = session.createQuery(sql);
5294    
5295                                    QueryPos qPos = QueryPos.getInstance(q);
5296    
5297                                    qPos.add(companyId);
5298    
5299                                    qPos.add(status);
5300    
5301                                    if (!pagination) {
5302                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5303                                                            start, end, false);
5304    
5305                                            Collections.sort(list);
5306    
5307                                            list = new UnmodifiableList<MBCategory>(list);
5308                                    }
5309                                    else {
5310                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5311                                                            start, end);
5312                                    }
5313    
5314                                    cacheResult(list);
5315    
5316                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5317                            }
5318                            catch (Exception e) {
5319                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5320    
5321                                    throw processException(e);
5322                            }
5323                            finally {
5324                                    closeSession(session);
5325                            }
5326                    }
5327    
5328                    return list;
5329            }
5330    
5331            /**
5332             * Returns the first message boards category in the ordered set where companyId = &#63; and status = &#63;.
5333             *
5334             * @param companyId the company ID
5335             * @param status the status
5336             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5337             * @return the first matching message boards category
5338             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
5339             * @throws SystemException if a system exception occurred
5340             */
5341            @Override
5342            public MBCategory findByC_S_First(long companyId, int status,
5343                    OrderByComparator orderByComparator)
5344                    throws NoSuchCategoryException, SystemException {
5345                    MBCategory mbCategory = fetchByC_S_First(companyId, status,
5346                                    orderByComparator);
5347    
5348                    if (mbCategory != null) {
5349                            return mbCategory;
5350                    }
5351    
5352                    StringBundler msg = new StringBundler(6);
5353    
5354                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5355    
5356                    msg.append("companyId=");
5357                    msg.append(companyId);
5358    
5359                    msg.append(", status=");
5360                    msg.append(status);
5361    
5362                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5363    
5364                    throw new NoSuchCategoryException(msg.toString());
5365            }
5366    
5367            /**
5368             * Returns the first message boards category in the ordered set where companyId = &#63; and status = &#63;.
5369             *
5370             * @param companyId the company ID
5371             * @param status the status
5372             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5373             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
5374             * @throws SystemException if a system exception occurred
5375             */
5376            @Override
5377            public MBCategory fetchByC_S_First(long companyId, int status,
5378                    OrderByComparator orderByComparator) throws SystemException {
5379                    List<MBCategory> list = findByC_S(companyId, status, 0, 1,
5380                                    orderByComparator);
5381    
5382                    if (!list.isEmpty()) {
5383                            return list.get(0);
5384                    }
5385    
5386                    return null;
5387            }
5388    
5389            /**
5390             * Returns the last message boards category in the ordered set where companyId = &#63; and status = &#63;.
5391             *
5392             * @param companyId the company ID
5393             * @param status the status
5394             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5395             * @return the last matching message boards category
5396             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
5397             * @throws SystemException if a system exception occurred
5398             */
5399            @Override
5400            public MBCategory findByC_S_Last(long companyId, int status,
5401                    OrderByComparator orderByComparator)
5402                    throws NoSuchCategoryException, SystemException {
5403                    MBCategory mbCategory = fetchByC_S_Last(companyId, status,
5404                                    orderByComparator);
5405    
5406                    if (mbCategory != null) {
5407                            return mbCategory;
5408                    }
5409    
5410                    StringBundler msg = new StringBundler(6);
5411    
5412                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5413    
5414                    msg.append("companyId=");
5415                    msg.append(companyId);
5416    
5417                    msg.append(", status=");
5418                    msg.append(status);
5419    
5420                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5421    
5422                    throw new NoSuchCategoryException(msg.toString());
5423            }
5424    
5425            /**
5426             * Returns the last message boards category in the ordered set where companyId = &#63; and status = &#63;.
5427             *
5428             * @param companyId the company ID
5429             * @param status the status
5430             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5431             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
5432             * @throws SystemException if a system exception occurred
5433             */
5434            @Override
5435            public MBCategory fetchByC_S_Last(long companyId, int status,
5436                    OrderByComparator orderByComparator) throws SystemException {
5437                    int count = countByC_S(companyId, status);
5438    
5439                    if (count == 0) {
5440                            return null;
5441                    }
5442    
5443                    List<MBCategory> list = findByC_S(companyId, status, count - 1, count,
5444                                    orderByComparator);
5445    
5446                    if (!list.isEmpty()) {
5447                            return list.get(0);
5448                    }
5449    
5450                    return null;
5451            }
5452    
5453            /**
5454             * Returns the message boards categories before and after the current message boards category in the ordered set where companyId = &#63; and status = &#63;.
5455             *
5456             * @param categoryId the primary key of the current message boards category
5457             * @param companyId the company ID
5458             * @param status the status
5459             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5460             * @return the previous, current, and next message boards category
5461             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
5462             * @throws SystemException if a system exception occurred
5463             */
5464            @Override
5465            public MBCategory[] findByC_S_PrevAndNext(long categoryId, long companyId,
5466                    int status, OrderByComparator orderByComparator)
5467                    throws NoSuchCategoryException, SystemException {
5468                    MBCategory mbCategory = findByPrimaryKey(categoryId);
5469    
5470                    Session session = null;
5471    
5472                    try {
5473                            session = openSession();
5474    
5475                            MBCategory[] array = new MBCategoryImpl[3];
5476    
5477                            array[0] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5478                                            status, orderByComparator, true);
5479    
5480                            array[1] = mbCategory;
5481    
5482                            array[2] = getByC_S_PrevAndNext(session, mbCategory, companyId,
5483                                            status, orderByComparator, false);
5484    
5485                            return array;
5486                    }
5487                    catch (Exception e) {
5488                            throw processException(e);
5489                    }
5490                    finally {
5491                            closeSession(session);
5492                    }
5493            }
5494    
5495            protected MBCategory getByC_S_PrevAndNext(Session session,
5496                    MBCategory mbCategory, long companyId, int status,
5497                    OrderByComparator orderByComparator, boolean previous) {
5498                    StringBundler query = null;
5499    
5500                    if (orderByComparator != null) {
5501                            query = new StringBundler(6 +
5502                                            (orderByComparator.getOrderByFields().length * 6));
5503                    }
5504                    else {
5505                            query = new StringBundler(3);
5506                    }
5507    
5508                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5509    
5510                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5511    
5512                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
5513    
5514                    if (orderByComparator != null) {
5515                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5516    
5517                            if (orderByConditionFields.length > 0) {
5518                                    query.append(WHERE_AND);
5519                            }
5520    
5521                            for (int i = 0; i < orderByConditionFields.length; i++) {
5522                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5523                                    query.append(orderByConditionFields[i]);
5524    
5525                                    if ((i + 1) < orderByConditionFields.length) {
5526                                            if (orderByComparator.isAscending() ^ previous) {
5527                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5528                                            }
5529                                            else {
5530                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5531                                            }
5532                                    }
5533                                    else {
5534                                            if (orderByComparator.isAscending() ^ previous) {
5535                                                    query.append(WHERE_GREATER_THAN);
5536                                            }
5537                                            else {
5538                                                    query.append(WHERE_LESSER_THAN);
5539                                            }
5540                                    }
5541                            }
5542    
5543                            query.append(ORDER_BY_CLAUSE);
5544    
5545                            String[] orderByFields = orderByComparator.getOrderByFields();
5546    
5547                            for (int i = 0; i < orderByFields.length; i++) {
5548                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5549                                    query.append(orderByFields[i]);
5550    
5551                                    if ((i + 1) < orderByFields.length) {
5552                                            if (orderByComparator.isAscending() ^ previous) {
5553                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5554                                            }
5555                                            else {
5556                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5557                                            }
5558                                    }
5559                                    else {
5560                                            if (orderByComparator.isAscending() ^ previous) {
5561                                                    query.append(ORDER_BY_ASC);
5562                                            }
5563                                            else {
5564                                                    query.append(ORDER_BY_DESC);
5565                                            }
5566                                    }
5567                            }
5568                    }
5569                    else {
5570                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5571                    }
5572    
5573                    String sql = query.toString();
5574    
5575                    Query q = session.createQuery(sql);
5576    
5577                    q.setFirstResult(0);
5578                    q.setMaxResults(2);
5579    
5580                    QueryPos qPos = QueryPos.getInstance(q);
5581    
5582                    qPos.add(companyId);
5583    
5584                    qPos.add(status);
5585    
5586                    if (orderByComparator != null) {
5587                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
5588    
5589                            for (Object value : values) {
5590                                    qPos.add(value);
5591                            }
5592                    }
5593    
5594                    List<MBCategory> list = q.list();
5595    
5596                    if (list.size() == 2) {
5597                            return list.get(1);
5598                    }
5599                    else {
5600                            return null;
5601                    }
5602            }
5603    
5604            /**
5605             * Removes all the message boards categories where companyId = &#63; and status = &#63; from the database.
5606             *
5607             * @param companyId the company ID
5608             * @param status the status
5609             * @throws SystemException if a system exception occurred
5610             */
5611            @Override
5612            public void removeByC_S(long companyId, int status)
5613                    throws SystemException {
5614                    for (MBCategory mbCategory : findByC_S(companyId, status,
5615                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5616                            remove(mbCategory);
5617                    }
5618            }
5619    
5620            /**
5621             * Returns the number of message boards categories where companyId = &#63; and status = &#63;.
5622             *
5623             * @param companyId the company ID
5624             * @param status the status
5625             * @return the number of matching message boards categories
5626             * @throws SystemException if a system exception occurred
5627             */
5628            @Override
5629            public int countByC_S(long companyId, int status) throws SystemException {
5630                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
5631    
5632                    Object[] finderArgs = new Object[] { companyId, status };
5633    
5634                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5635                                    this);
5636    
5637                    if (count == null) {
5638                            StringBundler query = new StringBundler(3);
5639    
5640                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
5641    
5642                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
5643    
5644                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
5645    
5646                            String sql = query.toString();
5647    
5648                            Session session = null;
5649    
5650                            try {
5651                                    session = openSession();
5652    
5653                                    Query q = session.createQuery(sql);
5654    
5655                                    QueryPos qPos = QueryPos.getInstance(q);
5656    
5657                                    qPos.add(companyId);
5658    
5659                                    qPos.add(status);
5660    
5661                                    count = (Long)q.uniqueResult();
5662    
5663                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5664                            }
5665                            catch (Exception e) {
5666                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5667    
5668                                    throw processException(e);
5669                            }
5670                            finally {
5671                                    closeSession(session);
5672                            }
5673                    }
5674    
5675                    return count.intValue();
5676            }
5677    
5678            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbCategory.companyId = ? AND ";
5679            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbCategory.status = ?";
5680            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5681                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5682                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P_S",
5683                            new String[] {
5684                                    Long.class.getName(), Long.class.getName(),
5685                                    Integer.class.getName(),
5686                                    
5687                            Integer.class.getName(), Integer.class.getName(),
5688                                    OrderByComparator.class.getName()
5689                            });
5690            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5691                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
5692                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P_S",
5693                            new String[] {
5694                                    Long.class.getName(), Long.class.getName(),
5695                                    Integer.class.getName()
5696                            },
5697                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
5698                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK |
5699                            MBCategoryModelImpl.STATUS_COLUMN_BITMASK |
5700                            MBCategoryModelImpl.NAME_COLUMN_BITMASK);
5701            public static final FinderPath FINDER_PATH_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5702                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5703                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P_S",
5704                            new String[] {
5705                                    Long.class.getName(), Long.class.getName(),
5706                                    Integer.class.getName()
5707                            });
5708            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
5709                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
5710                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P_S",
5711                            new String[] {
5712                                    Long.class.getName(), Long.class.getName(),
5713                                    Integer.class.getName()
5714                            });
5715    
5716            /**
5717             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
5718             *
5719             * @param groupId the group ID
5720             * @param parentCategoryId the parent category ID
5721             * @param status the status
5722             * @return the matching message boards categories
5723             * @throws SystemException if a system exception occurred
5724             */
5725            @Override
5726            public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
5727                    int status) throws SystemException {
5728                    return findByG_P_S(groupId, parentCategoryId, status,
5729                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
5730            }
5731    
5732            /**
5733             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
5734             *
5735             * <p>
5736             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5737             * </p>
5738             *
5739             * @param groupId the group ID
5740             * @param parentCategoryId the parent category ID
5741             * @param status the status
5742             * @param start the lower bound of the range of message boards categories
5743             * @param end the upper bound of the range of message boards categories (not inclusive)
5744             * @return the range of matching message boards categories
5745             * @throws SystemException if a system exception occurred
5746             */
5747            @Override
5748            public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
5749                    int status, int start, int end) throws SystemException {
5750                    return findByG_P_S(groupId, parentCategoryId, status, start, end, null);
5751            }
5752    
5753            /**
5754             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
5755             *
5756             * <p>
5757             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5758             * </p>
5759             *
5760             * @param groupId the group ID
5761             * @param parentCategoryId the parent category ID
5762             * @param status the status
5763             * @param start the lower bound of the range of message boards categories
5764             * @param end the upper bound of the range of message boards categories (not inclusive)
5765             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5766             * @return the ordered range of matching message boards categories
5767             * @throws SystemException if a system exception occurred
5768             */
5769            @Override
5770            public List<MBCategory> findByG_P_S(long groupId, long parentCategoryId,
5771                    int status, int start, int end, OrderByComparator orderByComparator)
5772                    throws SystemException {
5773                    boolean pagination = true;
5774                    FinderPath finderPath = null;
5775                    Object[] finderArgs = null;
5776    
5777                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5778                                    (orderByComparator == null)) {
5779                            pagination = false;
5780                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S;
5781                            finderArgs = new Object[] { groupId, parentCategoryId, status };
5782                    }
5783                    else {
5784                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S;
5785                            finderArgs = new Object[] {
5786                                            groupId, parentCategoryId, status,
5787                                            
5788                                            start, end, orderByComparator
5789                                    };
5790                    }
5791    
5792                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
5793                                    finderArgs, this);
5794    
5795                    if ((list != null) && !list.isEmpty()) {
5796                            for (MBCategory mbCategory : list) {
5797                                    if ((groupId != mbCategory.getGroupId()) ||
5798                                                    (parentCategoryId != mbCategory.getParentCategoryId()) ||
5799                                                    (status != mbCategory.getStatus())) {
5800                                            list = null;
5801    
5802                                            break;
5803                                    }
5804                            }
5805                    }
5806    
5807                    if (list == null) {
5808                            StringBundler query = null;
5809    
5810                            if (orderByComparator != null) {
5811                                    query = new StringBundler(5 +
5812                                                    (orderByComparator.getOrderByFields().length * 3));
5813                            }
5814                            else {
5815                                    query = new StringBundler(5);
5816                            }
5817    
5818                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
5819    
5820                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
5821    
5822                            query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
5823    
5824                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
5825    
5826                            if (orderByComparator != null) {
5827                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5828                                            orderByComparator);
5829                            }
5830                            else
5831                             if (pagination) {
5832                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
5833                            }
5834    
5835                            String sql = query.toString();
5836    
5837                            Session session = null;
5838    
5839                            try {
5840                                    session = openSession();
5841    
5842                                    Query q = session.createQuery(sql);
5843    
5844                                    QueryPos qPos = QueryPos.getInstance(q);
5845    
5846                                    qPos.add(groupId);
5847    
5848                                    qPos.add(parentCategoryId);
5849    
5850                                    qPos.add(status);
5851    
5852                                    if (!pagination) {
5853                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5854                                                            start, end, false);
5855    
5856                                            Collections.sort(list);
5857    
5858                                            list = new UnmodifiableList<MBCategory>(list);
5859                                    }
5860                                    else {
5861                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
5862                                                            start, end);
5863                                    }
5864    
5865                                    cacheResult(list);
5866    
5867                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5868                            }
5869                            catch (Exception e) {
5870                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5871    
5872                                    throw processException(e);
5873                            }
5874                            finally {
5875                                    closeSession(session);
5876                            }
5877                    }
5878    
5879                    return list;
5880            }
5881    
5882            /**
5883             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
5884             *
5885             * @param groupId the group ID
5886             * @param parentCategoryId the parent category ID
5887             * @param status the status
5888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5889             * @return the first matching message boards category
5890             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
5891             * @throws SystemException if a system exception occurred
5892             */
5893            @Override
5894            public MBCategory findByG_P_S_First(long groupId, long parentCategoryId,
5895                    int status, OrderByComparator orderByComparator)
5896                    throws NoSuchCategoryException, SystemException {
5897                    MBCategory mbCategory = fetchByG_P_S_First(groupId, parentCategoryId,
5898                                    status, orderByComparator);
5899    
5900                    if (mbCategory != null) {
5901                            return mbCategory;
5902                    }
5903    
5904                    StringBundler msg = new StringBundler(8);
5905    
5906                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5907    
5908                    msg.append("groupId=");
5909                    msg.append(groupId);
5910    
5911                    msg.append(", parentCategoryId=");
5912                    msg.append(parentCategoryId);
5913    
5914                    msg.append(", status=");
5915                    msg.append(status);
5916    
5917                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5918    
5919                    throw new NoSuchCategoryException(msg.toString());
5920            }
5921    
5922            /**
5923             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
5924             *
5925             * @param groupId the group ID
5926             * @param parentCategoryId the parent category ID
5927             * @param status the status
5928             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5929             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
5930             * @throws SystemException if a system exception occurred
5931             */
5932            @Override
5933            public MBCategory fetchByG_P_S_First(long groupId, long parentCategoryId,
5934                    int status, OrderByComparator orderByComparator)
5935                    throws SystemException {
5936                    List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
5937                                    0, 1, orderByComparator);
5938    
5939                    if (!list.isEmpty()) {
5940                            return list.get(0);
5941                    }
5942    
5943                    return null;
5944            }
5945    
5946            /**
5947             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
5948             *
5949             * @param groupId the group ID
5950             * @param parentCategoryId the parent category ID
5951             * @param status the status
5952             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5953             * @return the last matching message boards category
5954             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
5955             * @throws SystemException if a system exception occurred
5956             */
5957            @Override
5958            public MBCategory findByG_P_S_Last(long groupId, long parentCategoryId,
5959                    int status, OrderByComparator orderByComparator)
5960                    throws NoSuchCategoryException, SystemException {
5961                    MBCategory mbCategory = fetchByG_P_S_Last(groupId, parentCategoryId,
5962                                    status, orderByComparator);
5963    
5964                    if (mbCategory != null) {
5965                            return mbCategory;
5966                    }
5967    
5968                    StringBundler msg = new StringBundler(8);
5969    
5970                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5971    
5972                    msg.append("groupId=");
5973                    msg.append(groupId);
5974    
5975                    msg.append(", parentCategoryId=");
5976                    msg.append(parentCategoryId);
5977    
5978                    msg.append(", status=");
5979                    msg.append(status);
5980    
5981                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5982    
5983                    throw new NoSuchCategoryException(msg.toString());
5984            }
5985    
5986            /**
5987             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
5988             *
5989             * @param groupId the group ID
5990             * @param parentCategoryId the parent category ID
5991             * @param status the status
5992             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5993             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
5994             * @throws SystemException if a system exception occurred
5995             */
5996            @Override
5997            public MBCategory fetchByG_P_S_Last(long groupId, long parentCategoryId,
5998                    int status, OrderByComparator orderByComparator)
5999                    throws SystemException {
6000                    int count = countByG_P_S(groupId, parentCategoryId, status);
6001    
6002                    if (count == 0) {
6003                            return null;
6004                    }
6005    
6006                    List<MBCategory> list = findByG_P_S(groupId, parentCategoryId, status,
6007                                    count - 1, count, orderByComparator);
6008    
6009                    if (!list.isEmpty()) {
6010                            return list.get(0);
6011                    }
6012    
6013                    return null;
6014            }
6015    
6016            /**
6017             * 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;.
6018             *
6019             * @param categoryId the primary key of the current message boards category
6020             * @param groupId the group ID
6021             * @param parentCategoryId the parent category ID
6022             * @param status the status
6023             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6024             * @return the previous, current, and next message boards category
6025             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
6026             * @throws SystemException if a system exception occurred
6027             */
6028            @Override
6029            public MBCategory[] findByG_P_S_PrevAndNext(long categoryId, long groupId,
6030                    long parentCategoryId, int status, OrderByComparator orderByComparator)
6031                    throws NoSuchCategoryException, SystemException {
6032                    MBCategory mbCategory = findByPrimaryKey(categoryId);
6033    
6034                    Session session = null;
6035    
6036                    try {
6037                            session = openSession();
6038    
6039                            MBCategory[] array = new MBCategoryImpl[3];
6040    
6041                            array[0] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
6042                                            parentCategoryId, status, orderByComparator, true);
6043    
6044                            array[1] = mbCategory;
6045    
6046                            array[2] = getByG_P_S_PrevAndNext(session, mbCategory, groupId,
6047                                            parentCategoryId, status, orderByComparator, false);
6048    
6049                            return array;
6050                    }
6051                    catch (Exception e) {
6052                            throw processException(e);
6053                    }
6054                    finally {
6055                            closeSession(session);
6056                    }
6057            }
6058    
6059            protected MBCategory getByG_P_S_PrevAndNext(Session session,
6060                    MBCategory mbCategory, long groupId, long parentCategoryId, int status,
6061                    OrderByComparator orderByComparator, boolean previous) {
6062                    StringBundler query = null;
6063    
6064                    if (orderByComparator != null) {
6065                            query = new StringBundler(6 +
6066                                            (orderByComparator.getOrderByFields().length * 6));
6067                    }
6068                    else {
6069                            query = new StringBundler(3);
6070                    }
6071    
6072                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
6073    
6074                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6075    
6076                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6077    
6078                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6079    
6080                    if (orderByComparator != null) {
6081                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6082    
6083                            if (orderByConditionFields.length > 0) {
6084                                    query.append(WHERE_AND);
6085                            }
6086    
6087                            for (int i = 0; i < orderByConditionFields.length; i++) {
6088                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6089                                    query.append(orderByConditionFields[i]);
6090    
6091                                    if ((i + 1) < orderByConditionFields.length) {
6092                                            if (orderByComparator.isAscending() ^ previous) {
6093                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6094                                            }
6095                                            else {
6096                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6097                                            }
6098                                    }
6099                                    else {
6100                                            if (orderByComparator.isAscending() ^ previous) {
6101                                                    query.append(WHERE_GREATER_THAN);
6102                                            }
6103                                            else {
6104                                                    query.append(WHERE_LESSER_THAN);
6105                                            }
6106                                    }
6107                            }
6108    
6109                            query.append(ORDER_BY_CLAUSE);
6110    
6111                            String[] orderByFields = orderByComparator.getOrderByFields();
6112    
6113                            for (int i = 0; i < orderByFields.length; i++) {
6114                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6115                                    query.append(orderByFields[i]);
6116    
6117                                    if ((i + 1) < orderByFields.length) {
6118                                            if (orderByComparator.isAscending() ^ previous) {
6119                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6120                                            }
6121                                            else {
6122                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6123                                            }
6124                                    }
6125                                    else {
6126                                            if (orderByComparator.isAscending() ^ previous) {
6127                                                    query.append(ORDER_BY_ASC);
6128                                            }
6129                                            else {
6130                                                    query.append(ORDER_BY_DESC);
6131                                            }
6132                                    }
6133                            }
6134                    }
6135                    else {
6136                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6137                    }
6138    
6139                    String sql = query.toString();
6140    
6141                    Query q = session.createQuery(sql);
6142    
6143                    q.setFirstResult(0);
6144                    q.setMaxResults(2);
6145    
6146                    QueryPos qPos = QueryPos.getInstance(q);
6147    
6148                    qPos.add(groupId);
6149    
6150                    qPos.add(parentCategoryId);
6151    
6152                    qPos.add(status);
6153    
6154                    if (orderByComparator != null) {
6155                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
6156    
6157                            for (Object value : values) {
6158                                    qPos.add(value);
6159                            }
6160                    }
6161    
6162                    List<MBCategory> list = q.list();
6163    
6164                    if (list.size() == 2) {
6165                            return list.get(1);
6166                    }
6167                    else {
6168                            return null;
6169                    }
6170            }
6171    
6172            /**
6173             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
6174             *
6175             * @param groupId the group ID
6176             * @param parentCategoryId the parent category ID
6177             * @param status the status
6178             * @return the matching message boards categories that the user has permission to view
6179             * @throws SystemException if a system exception occurred
6180             */
6181            @Override
6182            public List<MBCategory> filterFindByG_P_S(long groupId,
6183                    long parentCategoryId, int status) throws SystemException {
6184                    return filterFindByG_P_S(groupId, parentCategoryId, status,
6185                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6186            }
6187    
6188            /**
6189             * 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;.
6190             *
6191             * <p>
6192             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6193             * </p>
6194             *
6195             * @param groupId the group ID
6196             * @param parentCategoryId the parent category ID
6197             * @param status the status
6198             * @param start the lower bound of the range of message boards categories
6199             * @param end the upper bound of the range of message boards categories (not inclusive)
6200             * @return the range of matching message boards categories that the user has permission to view
6201             * @throws SystemException if a system exception occurred
6202             */
6203            @Override
6204            public List<MBCategory> filterFindByG_P_S(long groupId,
6205                    long parentCategoryId, int status, int start, int end)
6206                    throws SystemException {
6207                    return filterFindByG_P_S(groupId, parentCategoryId, status, start, end,
6208                            null);
6209            }
6210    
6211            /**
6212             * 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;.
6213             *
6214             * <p>
6215             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6216             * </p>
6217             *
6218             * @param groupId the group ID
6219             * @param parentCategoryId the parent category ID
6220             * @param status the status
6221             * @param start the lower bound of the range of message boards categories
6222             * @param end the upper bound of the range of message boards categories (not inclusive)
6223             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6224             * @return the ordered range of matching message boards categories that the user has permission to view
6225             * @throws SystemException if a system exception occurred
6226             */
6227            @Override
6228            public List<MBCategory> filterFindByG_P_S(long groupId,
6229                    long parentCategoryId, int status, int start, int end,
6230                    OrderByComparator orderByComparator) throws SystemException {
6231                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6232                            return findByG_P_S(groupId, parentCategoryId, status, start, end,
6233                                    orderByComparator);
6234                    }
6235    
6236                    StringBundler query = null;
6237    
6238                    if (orderByComparator != null) {
6239                            query = new StringBundler(5 +
6240                                            (orderByComparator.getOrderByFields().length * 3));
6241                    }
6242                    else {
6243                            query = new StringBundler(5);
6244                    }
6245    
6246                    if (getDB().isSupportsInlineDistinct()) {
6247                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6248                    }
6249                    else {
6250                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6251                    }
6252    
6253                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6254    
6255                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6256    
6257                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6258    
6259                    if (!getDB().isSupportsInlineDistinct()) {
6260                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6261                    }
6262    
6263                    if (orderByComparator != null) {
6264                            if (getDB().isSupportsInlineDistinct()) {
6265                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6266                                            orderByComparator, true);
6267                            }
6268                            else {
6269                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6270                                            orderByComparator, true);
6271                            }
6272                    }
6273                    else {
6274                            if (getDB().isSupportsInlineDistinct()) {
6275                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6276                            }
6277                            else {
6278                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6279                            }
6280                    }
6281    
6282                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6283                                    MBCategory.class.getName(),
6284                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6285    
6286                    Session session = null;
6287    
6288                    try {
6289                            session = openSession();
6290    
6291                            SQLQuery q = session.createSQLQuery(sql);
6292    
6293                            if (getDB().isSupportsInlineDistinct()) {
6294                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6295                            }
6296                            else {
6297                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6298                            }
6299    
6300                            QueryPos qPos = QueryPos.getInstance(q);
6301    
6302                            qPos.add(groupId);
6303    
6304                            qPos.add(parentCategoryId);
6305    
6306                            qPos.add(status);
6307    
6308                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
6309                    }
6310                    catch (Exception e) {
6311                            throw processException(e);
6312                    }
6313                    finally {
6314                            closeSession(session);
6315                    }
6316            }
6317    
6318            /**
6319             * 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;.
6320             *
6321             * @param categoryId the primary key of the current message boards category
6322             * @param groupId the group ID
6323             * @param parentCategoryId the parent category ID
6324             * @param status the status
6325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6326             * @return the previous, current, and next message boards category
6327             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
6328             * @throws SystemException if a system exception occurred
6329             */
6330            @Override
6331            public MBCategory[] filterFindByG_P_S_PrevAndNext(long categoryId,
6332                    long groupId, long parentCategoryId, int status,
6333                    OrderByComparator orderByComparator)
6334                    throws NoSuchCategoryException, SystemException {
6335                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6336                            return findByG_P_S_PrevAndNext(categoryId, groupId,
6337                                    parentCategoryId, status, orderByComparator);
6338                    }
6339    
6340                    MBCategory mbCategory = findByPrimaryKey(categoryId);
6341    
6342                    Session session = null;
6343    
6344                    try {
6345                            session = openSession();
6346    
6347                            MBCategory[] array = new MBCategoryImpl[3];
6348    
6349                            array[0] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
6350                                            groupId, parentCategoryId, status, orderByComparator, true);
6351    
6352                            array[1] = mbCategory;
6353    
6354                            array[2] = filterGetByG_P_S_PrevAndNext(session, mbCategory,
6355                                            groupId, parentCategoryId, status, orderByComparator, false);
6356    
6357                            return array;
6358                    }
6359                    catch (Exception e) {
6360                            throw processException(e);
6361                    }
6362                    finally {
6363                            closeSession(session);
6364                    }
6365            }
6366    
6367            protected MBCategory filterGetByG_P_S_PrevAndNext(Session session,
6368                    MBCategory mbCategory, long groupId, long parentCategoryId, int status,
6369                    OrderByComparator orderByComparator, boolean previous) {
6370                    StringBundler query = null;
6371    
6372                    if (orderByComparator != null) {
6373                            query = new StringBundler(6 +
6374                                            (orderByComparator.getOrderByFields().length * 6));
6375                    }
6376                    else {
6377                            query = new StringBundler(3);
6378                    }
6379    
6380                    if (getDB().isSupportsInlineDistinct()) {
6381                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6382                    }
6383                    else {
6384                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6385                    }
6386    
6387                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6388    
6389                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6390    
6391                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6392    
6393                    if (!getDB().isSupportsInlineDistinct()) {
6394                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6395                    }
6396    
6397                    if (orderByComparator != null) {
6398                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6399    
6400                            if (orderByConditionFields.length > 0) {
6401                                    query.append(WHERE_AND);
6402                            }
6403    
6404                            for (int i = 0; i < orderByConditionFields.length; i++) {
6405                                    if (getDB().isSupportsInlineDistinct()) {
6406                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6407                                    }
6408                                    else {
6409                                            query.append(_ORDER_BY_ENTITY_TABLE);
6410                                    }
6411    
6412                                    query.append(orderByConditionFields[i]);
6413    
6414                                    if ((i + 1) < orderByConditionFields.length) {
6415                                            if (orderByComparator.isAscending() ^ previous) {
6416                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6417                                            }
6418                                            else {
6419                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6420                                            }
6421                                    }
6422                                    else {
6423                                            if (orderByComparator.isAscending() ^ previous) {
6424                                                    query.append(WHERE_GREATER_THAN);
6425                                            }
6426                                            else {
6427                                                    query.append(WHERE_LESSER_THAN);
6428                                            }
6429                                    }
6430                            }
6431    
6432                            query.append(ORDER_BY_CLAUSE);
6433    
6434                            String[] orderByFields = orderByComparator.getOrderByFields();
6435    
6436                            for (int i = 0; i < orderByFields.length; i++) {
6437                                    if (getDB().isSupportsInlineDistinct()) {
6438                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6439                                    }
6440                                    else {
6441                                            query.append(_ORDER_BY_ENTITY_TABLE);
6442                                    }
6443    
6444                                    query.append(orderByFields[i]);
6445    
6446                                    if ((i + 1) < orderByFields.length) {
6447                                            if (orderByComparator.isAscending() ^ previous) {
6448                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6449                                            }
6450                                            else {
6451                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6452                                            }
6453                                    }
6454                                    else {
6455                                            if (orderByComparator.isAscending() ^ previous) {
6456                                                    query.append(ORDER_BY_ASC);
6457                                            }
6458                                            else {
6459                                                    query.append(ORDER_BY_DESC);
6460                                            }
6461                                    }
6462                            }
6463                    }
6464                    else {
6465                            if (getDB().isSupportsInlineDistinct()) {
6466                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6467                            }
6468                            else {
6469                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6470                            }
6471                    }
6472    
6473                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6474                                    MBCategory.class.getName(),
6475                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6476    
6477                    SQLQuery q = session.createSQLQuery(sql);
6478    
6479                    q.setFirstResult(0);
6480                    q.setMaxResults(2);
6481    
6482                    if (getDB().isSupportsInlineDistinct()) {
6483                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6484                    }
6485                    else {
6486                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6487                    }
6488    
6489                    QueryPos qPos = QueryPos.getInstance(q);
6490    
6491                    qPos.add(groupId);
6492    
6493                    qPos.add(parentCategoryId);
6494    
6495                    qPos.add(status);
6496    
6497                    if (orderByComparator != null) {
6498                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
6499    
6500                            for (Object value : values) {
6501                                    qPos.add(value);
6502                            }
6503                    }
6504    
6505                    List<MBCategory> list = q.list();
6506    
6507                    if (list.size() == 2) {
6508                            return list.get(1);
6509                    }
6510                    else {
6511                            return null;
6512                    }
6513            }
6514    
6515            /**
6516             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
6517             *
6518             * @param groupId the group ID
6519             * @param parentCategoryIds the parent category IDs
6520             * @param status the status
6521             * @return the matching message boards categories that the user has permission to view
6522             * @throws SystemException if a system exception occurred
6523             */
6524            @Override
6525            public List<MBCategory> filterFindByG_P_S(long groupId,
6526                    long[] parentCategoryIds, int status) throws SystemException {
6527                    return filterFindByG_P_S(groupId, parentCategoryIds, status,
6528                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6529            }
6530    
6531            /**
6532             * 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;.
6533             *
6534             * <p>
6535             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6536             * </p>
6537             *
6538             * @param groupId the group ID
6539             * @param parentCategoryIds the parent category IDs
6540             * @param status the status
6541             * @param start the lower bound of the range of message boards categories
6542             * @param end the upper bound of the range of message boards categories (not inclusive)
6543             * @return the range of matching message boards categories that the user has permission to view
6544             * @throws SystemException if a system exception occurred
6545             */
6546            @Override
6547            public List<MBCategory> filterFindByG_P_S(long groupId,
6548                    long[] parentCategoryIds, int status, int start, int end)
6549                    throws SystemException {
6550                    return filterFindByG_P_S(groupId, parentCategoryIds, status, start,
6551                            end, null);
6552            }
6553    
6554            /**
6555             * 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;.
6556             *
6557             * <p>
6558             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6559             * </p>
6560             *
6561             * @param groupId the group ID
6562             * @param parentCategoryIds the parent category IDs
6563             * @param status the status
6564             * @param start the lower bound of the range of message boards categories
6565             * @param end the upper bound of the range of message boards categories (not inclusive)
6566             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6567             * @return the ordered range of matching message boards categories that the user has permission to view
6568             * @throws SystemException if a system exception occurred
6569             */
6570            @Override
6571            public List<MBCategory> filterFindByG_P_S(long groupId,
6572                    long[] parentCategoryIds, int status, int start, int end,
6573                    OrderByComparator orderByComparator) throws SystemException {
6574                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6575                            return findByG_P_S(groupId, parentCategoryIds, status, start, end,
6576                                    orderByComparator);
6577                    }
6578    
6579                    StringBundler query = new StringBundler();
6580    
6581                    if (getDB().isSupportsInlineDistinct()) {
6582                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
6583                    }
6584                    else {
6585                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
6586                    }
6587    
6588                    boolean conjunctionable = false;
6589    
6590                    if (conjunctionable) {
6591                            query.append(WHERE_AND);
6592                    }
6593    
6594                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
6595    
6596                    conjunctionable = true;
6597    
6598                    if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
6599                            if (conjunctionable) {
6600                                    query.append(WHERE_AND);
6601                            }
6602    
6603                            query.append(StringPool.OPEN_PARENTHESIS);
6604    
6605                            for (int i = 0; i < parentCategoryIds.length; i++) {
6606                                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
6607    
6608                                    if ((i + 1) < parentCategoryIds.length) {
6609                                            query.append(WHERE_OR);
6610                                    }
6611                            }
6612    
6613                            query.append(StringPool.CLOSE_PARENTHESIS);
6614    
6615                            conjunctionable = true;
6616                    }
6617    
6618                    if (conjunctionable) {
6619                            query.append(WHERE_AND);
6620                    }
6621    
6622                    query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
6623    
6624                    conjunctionable = true;
6625    
6626                    if (!getDB().isSupportsInlineDistinct()) {
6627                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
6628                    }
6629    
6630                    if (orderByComparator != null) {
6631                            if (getDB().isSupportsInlineDistinct()) {
6632                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6633                                            orderByComparator, true);
6634                            }
6635                            else {
6636                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6637                                            orderByComparator, true);
6638                            }
6639                    }
6640                    else {
6641                            if (getDB().isSupportsInlineDistinct()) {
6642                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6643                            }
6644                            else {
6645                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
6646                            }
6647                    }
6648    
6649                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6650                                    MBCategory.class.getName(),
6651                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6652    
6653                    Session session = null;
6654    
6655                    try {
6656                            session = openSession();
6657    
6658                            SQLQuery q = session.createSQLQuery(sql);
6659    
6660                            if (getDB().isSupportsInlineDistinct()) {
6661                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
6662                            }
6663                            else {
6664                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
6665                            }
6666    
6667                            QueryPos qPos = QueryPos.getInstance(q);
6668    
6669                            qPos.add(groupId);
6670    
6671                            if (parentCategoryIds != null) {
6672                                    qPos.add(parentCategoryIds);
6673                            }
6674    
6675                            qPos.add(status);
6676    
6677                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
6678                    }
6679                    catch (Exception e) {
6680                            throw processException(e);
6681                    }
6682                    finally {
6683                            closeSession(session);
6684                    }
6685            }
6686    
6687            /**
6688             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
6689             *
6690             * <p>
6691             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6692             * </p>
6693             *
6694             * @param groupId the group ID
6695             * @param parentCategoryIds the parent category IDs
6696             * @param status the status
6697             * @return the matching message boards categories
6698             * @throws SystemException if a system exception occurred
6699             */
6700            @Override
6701            public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
6702                    int status) throws SystemException {
6703                    return findByG_P_S(groupId, parentCategoryIds, status,
6704                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
6705            }
6706    
6707            /**
6708             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
6709             *
6710             * <p>
6711             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6712             * </p>
6713             *
6714             * @param groupId the group ID
6715             * @param parentCategoryIds the parent category IDs
6716             * @param status the status
6717             * @param start the lower bound of the range of message boards categories
6718             * @param end the upper bound of the range of message boards categories (not inclusive)
6719             * @return the range of matching message boards categories
6720             * @throws SystemException if a system exception occurred
6721             */
6722            @Override
6723            public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
6724                    int status, int start, int end) throws SystemException {
6725                    return findByG_P_S(groupId, parentCategoryIds, status, start, end, null);
6726            }
6727    
6728            /**
6729             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
6730             *
6731             * <p>
6732             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6733             * </p>
6734             *
6735             * @param groupId the group ID
6736             * @param parentCategoryIds the parent category IDs
6737             * @param status the status
6738             * @param start the lower bound of the range of message boards categories
6739             * @param end the upper bound of the range of message boards categories (not inclusive)
6740             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6741             * @return the ordered range of matching message boards categories
6742             * @throws SystemException if a system exception occurred
6743             */
6744            @Override
6745            public List<MBCategory> findByG_P_S(long groupId, long[] parentCategoryIds,
6746                    int status, int start, int end, OrderByComparator orderByComparator)
6747                    throws SystemException {
6748                    if ((parentCategoryIds != null) && (parentCategoryIds.length == 1)) {
6749                            return findByG_P_S(groupId, parentCategoryIds[0], status, start,
6750                                    end, orderByComparator);
6751                    }
6752    
6753                    boolean pagination = true;
6754                    Object[] finderArgs = null;
6755    
6756                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6757                                    (orderByComparator == null)) {
6758                            pagination = false;
6759                            finderArgs = new Object[] {
6760                                            groupId, StringUtil.merge(parentCategoryIds), status
6761                                    };
6762                    }
6763                    else {
6764                            finderArgs = new Object[] {
6765                                            groupId, StringUtil.merge(parentCategoryIds), status,
6766                                            
6767                                            start, end, orderByComparator
6768                                    };
6769                    }
6770    
6771                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
6772                                    finderArgs, this);
6773    
6774                    if ((list != null) && !list.isEmpty()) {
6775                            for (MBCategory mbCategory : list) {
6776                                    if ((groupId != mbCategory.getGroupId()) ||
6777                                                    !ArrayUtil.contains(parentCategoryIds,
6778                                                            mbCategory.getParentCategoryId()) ||
6779                                                    (status != mbCategory.getStatus())) {
6780                                            list = null;
6781    
6782                                            break;
6783                                    }
6784                            }
6785                    }
6786    
6787                    if (list == null) {
6788                            StringBundler query = new StringBundler();
6789    
6790                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
6791    
6792                            boolean conjunctionable = false;
6793    
6794                            if (conjunctionable) {
6795                                    query.append(WHERE_AND);
6796                            }
6797    
6798                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
6799    
6800                            conjunctionable = true;
6801    
6802                            if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
6803                                    if (conjunctionable) {
6804                                            query.append(WHERE_AND);
6805                                    }
6806    
6807                                    query.append(StringPool.OPEN_PARENTHESIS);
6808    
6809                                    for (int i = 0; i < parentCategoryIds.length; i++) {
6810                                            query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
6811    
6812                                            if ((i + 1) < parentCategoryIds.length) {
6813                                                    query.append(WHERE_OR);
6814                                            }
6815                                    }
6816    
6817                                    query.append(StringPool.CLOSE_PARENTHESIS);
6818    
6819                                    conjunctionable = true;
6820                            }
6821    
6822                            if (conjunctionable) {
6823                                    query.append(WHERE_AND);
6824                            }
6825    
6826                            query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
6827    
6828                            conjunctionable = true;
6829    
6830                            if (orderByComparator != null) {
6831                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6832                                            orderByComparator);
6833                            }
6834                            else
6835                             if (pagination) {
6836                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
6837                            }
6838    
6839                            String sql = query.toString();
6840    
6841                            Session session = null;
6842    
6843                            try {
6844                                    session = openSession();
6845    
6846                                    Query q = session.createQuery(sql);
6847    
6848                                    QueryPos qPos = QueryPos.getInstance(q);
6849    
6850                                    qPos.add(groupId);
6851    
6852                                    if (parentCategoryIds != null) {
6853                                            qPos.add(parentCategoryIds);
6854                                    }
6855    
6856                                    qPos.add(status);
6857    
6858                                    if (!pagination) {
6859                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6860                                                            start, end, false);
6861    
6862                                            Collections.sort(list);
6863    
6864                                            list = new UnmodifiableList<MBCategory>(list);
6865                                    }
6866                                    else {
6867                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
6868                                                            start, end);
6869                                    }
6870    
6871                                    cacheResult(list);
6872    
6873                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
6874                                            finderArgs, list);
6875                            }
6876                            catch (Exception e) {
6877                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P_S,
6878                                            finderArgs);
6879    
6880                                    throw processException(e);
6881                            }
6882                            finally {
6883                                    closeSession(session);
6884                            }
6885                    }
6886    
6887                    return list;
6888            }
6889    
6890            /**
6891             * Removes all the message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63; from the database.
6892             *
6893             * @param groupId the group ID
6894             * @param parentCategoryId the parent category ID
6895             * @param status the status
6896             * @throws SystemException if a system exception occurred
6897             */
6898            @Override
6899            public void removeByG_P_S(long groupId, long parentCategoryId, int status)
6900                    throws SystemException {
6901                    for (MBCategory mbCategory : findByG_P_S(groupId, parentCategoryId,
6902                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6903                            remove(mbCategory);
6904                    }
6905            }
6906    
6907            /**
6908             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
6909             *
6910             * @param groupId the group ID
6911             * @param parentCategoryId the parent category ID
6912             * @param status the status
6913             * @return the number of matching message boards categories
6914             * @throws SystemException if a system exception occurred
6915             */
6916            @Override
6917            public int countByG_P_S(long groupId, long parentCategoryId, int status)
6918                    throws SystemException {
6919                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_P_S;
6920    
6921                    Object[] finderArgs = new Object[] { groupId, parentCategoryId, status };
6922    
6923                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6924                                    this);
6925    
6926                    if (count == null) {
6927                            StringBundler query = new StringBundler(4);
6928    
6929                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6930    
6931                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
6932    
6933                            query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
6934    
6935                            query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
6936    
6937                            String sql = query.toString();
6938    
6939                            Session session = null;
6940    
6941                            try {
6942                                    session = openSession();
6943    
6944                                    Query q = session.createQuery(sql);
6945    
6946                                    QueryPos qPos = QueryPos.getInstance(q);
6947    
6948                                    qPos.add(groupId);
6949    
6950                                    qPos.add(parentCategoryId);
6951    
6952                                    qPos.add(status);
6953    
6954                                    count = (Long)q.uniqueResult();
6955    
6956                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6957                            }
6958                            catch (Exception e) {
6959                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6960    
6961                                    throw processException(e);
6962                            }
6963                            finally {
6964                                    closeSession(session);
6965                            }
6966                    }
6967    
6968                    return count.intValue();
6969            }
6970    
6971            /**
6972             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
6973             *
6974             * @param groupId the group ID
6975             * @param parentCategoryIds the parent category IDs
6976             * @param status the status
6977             * @return the number of matching message boards categories
6978             * @throws SystemException if a system exception occurred
6979             */
6980            @Override
6981            public int countByG_P_S(long groupId, long[] parentCategoryIds, int status)
6982                    throws SystemException {
6983                    Object[] finderArgs = new Object[] {
6984                                    groupId, StringUtil.merge(parentCategoryIds), status
6985                            };
6986    
6987                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
6988                                    finderArgs, this);
6989    
6990                    if (count == null) {
6991                            StringBundler query = new StringBundler();
6992    
6993                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
6994    
6995                            boolean conjunctionable = false;
6996    
6997                            if (conjunctionable) {
6998                                    query.append(WHERE_AND);
6999                            }
7000    
7001                            query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
7002    
7003                            conjunctionable = true;
7004    
7005                            if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
7006                                    if (conjunctionable) {
7007                                            query.append(WHERE_AND);
7008                                    }
7009    
7010                                    query.append(StringPool.OPEN_PARENTHESIS);
7011    
7012                                    for (int i = 0; i < parentCategoryIds.length; i++) {
7013                                            query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
7014    
7015                                            if ((i + 1) < parentCategoryIds.length) {
7016                                                    query.append(WHERE_OR);
7017                                            }
7018                                    }
7019    
7020                                    query.append(StringPool.CLOSE_PARENTHESIS);
7021    
7022                                    conjunctionable = true;
7023                            }
7024    
7025                            if (conjunctionable) {
7026                                    query.append(WHERE_AND);
7027                            }
7028    
7029                            query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
7030    
7031                            conjunctionable = true;
7032    
7033                            String sql = query.toString();
7034    
7035                            Session session = null;
7036    
7037                            try {
7038                                    session = openSession();
7039    
7040                                    Query q = session.createQuery(sql);
7041    
7042                                    QueryPos qPos = QueryPos.getInstance(q);
7043    
7044                                    qPos.add(groupId);
7045    
7046                                    if (parentCategoryIds != null) {
7047                                            qPos.add(parentCategoryIds);
7048                                    }
7049    
7050                                    qPos.add(status);
7051    
7052                                    count = (Long)q.uniqueResult();
7053    
7054                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
7055                                            finderArgs, count);
7056                            }
7057                            catch (Exception e) {
7058                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P_S,
7059                                            finderArgs);
7060    
7061                                    throw processException(e);
7062                            }
7063                            finally {
7064                                    closeSession(session);
7065                            }
7066                    }
7067    
7068                    return count.intValue();
7069            }
7070    
7071            /**
7072             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63; and status = &#63;.
7073             *
7074             * @param groupId the group ID
7075             * @param parentCategoryId the parent category ID
7076             * @param status the status
7077             * @return the number of matching message boards categories that the user has permission to view
7078             * @throws SystemException if a system exception occurred
7079             */
7080            @Override
7081            public int filterCountByG_P_S(long groupId, long parentCategoryId,
7082                    int status) throws SystemException {
7083                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7084                            return countByG_P_S(groupId, parentCategoryId, status);
7085                    }
7086    
7087                    StringBundler query = new StringBundler(4);
7088    
7089                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
7090    
7091                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_2);
7092    
7093                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2);
7094    
7095                    query.append(_FINDER_COLUMN_G_P_S_STATUS_2);
7096    
7097                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7098                                    MBCategory.class.getName(),
7099                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7100    
7101                    Session session = null;
7102    
7103                    try {
7104                            session = openSession();
7105    
7106                            SQLQuery q = session.createSQLQuery(sql);
7107    
7108                            q.addScalar(COUNT_COLUMN_NAME,
7109                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7110    
7111                            QueryPos qPos = QueryPos.getInstance(q);
7112    
7113                            qPos.add(groupId);
7114    
7115                            qPos.add(parentCategoryId);
7116    
7117                            qPos.add(status);
7118    
7119                            Long count = (Long)q.uniqueResult();
7120    
7121                            return count.intValue();
7122                    }
7123                    catch (Exception e) {
7124                            throw processException(e);
7125                    }
7126                    finally {
7127                            closeSession(session);
7128                    }
7129            }
7130    
7131            /**
7132             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63; and status = &#63;.
7133             *
7134             * @param groupId the group ID
7135             * @param parentCategoryIds the parent category IDs
7136             * @param status the status
7137             * @return the number of matching message boards categories that the user has permission to view
7138             * @throws SystemException if a system exception occurred
7139             */
7140            @Override
7141            public int filterCountByG_P_S(long groupId, long[] parentCategoryIds,
7142                    int status) throws SystemException {
7143                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
7144                            return countByG_P_S(groupId, parentCategoryIds, status);
7145                    }
7146    
7147                    StringBundler query = new StringBundler();
7148    
7149                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
7150    
7151                    boolean conjunctionable = false;
7152    
7153                    if (conjunctionable) {
7154                            query.append(WHERE_AND);
7155                    }
7156    
7157                    query.append(_FINDER_COLUMN_G_P_S_GROUPID_5);
7158    
7159                    conjunctionable = true;
7160    
7161                    if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
7162                            if (conjunctionable) {
7163                                    query.append(WHERE_AND);
7164                            }
7165    
7166                            query.append(StringPool.OPEN_PARENTHESIS);
7167    
7168                            for (int i = 0; i < parentCategoryIds.length; i++) {
7169                                    query.append(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5);
7170    
7171                                    if ((i + 1) < parentCategoryIds.length) {
7172                                            query.append(WHERE_OR);
7173                                    }
7174                            }
7175    
7176                            query.append(StringPool.CLOSE_PARENTHESIS);
7177    
7178                            conjunctionable = true;
7179                    }
7180    
7181                    if (conjunctionable) {
7182                            query.append(WHERE_AND);
7183                    }
7184    
7185                    query.append(_FINDER_COLUMN_G_P_S_STATUS_5);
7186    
7187                    conjunctionable = true;
7188    
7189                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
7190                                    MBCategory.class.getName(),
7191                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
7192    
7193                    Session session = null;
7194    
7195                    try {
7196                            session = openSession();
7197    
7198                            SQLQuery q = session.createSQLQuery(sql);
7199    
7200                            q.addScalar(COUNT_COLUMN_NAME,
7201                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
7202    
7203                            QueryPos qPos = QueryPos.getInstance(q);
7204    
7205                            qPos.add(groupId);
7206    
7207                            if (parentCategoryIds != null) {
7208                                    qPos.add(parentCategoryIds);
7209                            }
7210    
7211                            qPos.add(status);
7212    
7213                            Long count = (Long)q.uniqueResult();
7214    
7215                            return count.intValue();
7216                    }
7217                    catch (Exception e) {
7218                            throw processException(e);
7219                    }
7220                    finally {
7221                            closeSession(session);
7222                    }
7223            }
7224    
7225            private static final String _FINDER_COLUMN_G_P_S_GROUPID_2 = "mbCategory.groupId = ? AND ";
7226            private static final String _FINDER_COLUMN_G_P_S_GROUPID_5 = "(" +
7227                    removeConjunction(_FINDER_COLUMN_G_P_S_GROUPID_2) + ")";
7228            private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ? AND ";
7229            private static final String _FINDER_COLUMN_G_P_S_PARENTCATEGORYID_5 = "(" +
7230                    removeConjunction(_FINDER_COLUMN_G_P_S_PARENTCATEGORYID_2) + ")";
7231            private static final String _FINDER_COLUMN_G_P_S_STATUS_2 = "mbCategory.status = ?";
7232            private static final String _FINDER_COLUMN_G_P_S_STATUS_5 = "(" +
7233                    removeConjunction(_FINDER_COLUMN_G_P_S_STATUS_2) + ")";
7234    
7235            public MBCategoryPersistenceImpl() {
7236                    setModelClass(MBCategory.class);
7237            }
7238    
7239            /**
7240             * Caches the message boards category in the entity cache if it is enabled.
7241             *
7242             * @param mbCategory the message boards category
7243             */
7244            @Override
7245            public void cacheResult(MBCategory mbCategory) {
7246                    EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7247                            MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
7248    
7249                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
7250                            new Object[] { mbCategory.getUuid(), mbCategory.getGroupId() },
7251                            mbCategory);
7252    
7253                    mbCategory.resetOriginalValues();
7254            }
7255    
7256            /**
7257             * Caches the message boards categories in the entity cache if it is enabled.
7258             *
7259             * @param mbCategories the message boards categories
7260             */
7261            @Override
7262            public void cacheResult(List<MBCategory> mbCategories) {
7263                    for (MBCategory mbCategory : mbCategories) {
7264                            if (EntityCacheUtil.getResult(
7265                                                    MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7266                                                    MBCategoryImpl.class, mbCategory.getPrimaryKey()) == null) {
7267                                    cacheResult(mbCategory);
7268                            }
7269                            else {
7270                                    mbCategory.resetOriginalValues();
7271                            }
7272                    }
7273            }
7274    
7275            /**
7276             * Clears the cache for all message boards categories.
7277             *
7278             * <p>
7279             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7280             * </p>
7281             */
7282            @Override
7283            public void clearCache() {
7284                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
7285                            CacheRegistryUtil.clear(MBCategoryImpl.class.getName());
7286                    }
7287    
7288                    EntityCacheUtil.clearCache(MBCategoryImpl.class.getName());
7289    
7290                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
7291                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7292                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7293            }
7294    
7295            /**
7296             * Clears the cache for the message boards category.
7297             *
7298             * <p>
7299             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
7300             * </p>
7301             */
7302            @Override
7303            public void clearCache(MBCategory mbCategory) {
7304                    EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7305                            MBCategoryImpl.class, mbCategory.getPrimaryKey());
7306    
7307                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7308                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7309    
7310                    clearUniqueFindersCache(mbCategory);
7311            }
7312    
7313            @Override
7314            public void clearCache(List<MBCategory> mbCategories) {
7315                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7316                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7317    
7318                    for (MBCategory mbCategory : mbCategories) {
7319                            EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7320                                    MBCategoryImpl.class, mbCategory.getPrimaryKey());
7321    
7322                            clearUniqueFindersCache(mbCategory);
7323                    }
7324            }
7325    
7326            protected void cacheUniqueFindersCache(MBCategory mbCategory) {
7327                    if (mbCategory.isNew()) {
7328                            Object[] args = new Object[] {
7329                                            mbCategory.getUuid(), mbCategory.getGroupId()
7330                                    };
7331    
7332                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7333                                    Long.valueOf(1));
7334                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7335                                    mbCategory);
7336                    }
7337                    else {
7338                            MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
7339    
7340                            if ((mbCategoryModelImpl.getColumnBitmask() &
7341                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7342                                    Object[] args = new Object[] {
7343                                                    mbCategory.getUuid(), mbCategory.getGroupId()
7344                                            };
7345    
7346                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
7347                                            Long.valueOf(1));
7348                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
7349                                            mbCategory);
7350                            }
7351                    }
7352            }
7353    
7354            protected void clearUniqueFindersCache(MBCategory mbCategory) {
7355                    MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
7356    
7357                    Object[] args = new Object[] {
7358                                    mbCategory.getUuid(), mbCategory.getGroupId()
7359                            };
7360    
7361                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7362                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7363    
7364                    if ((mbCategoryModelImpl.getColumnBitmask() &
7365                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
7366                            args = new Object[] {
7367                                            mbCategoryModelImpl.getOriginalUuid(),
7368                                            mbCategoryModelImpl.getOriginalGroupId()
7369                                    };
7370    
7371                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
7372                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
7373                    }
7374            }
7375    
7376            /**
7377             * Creates a new message boards category with the primary key. Does not add the message boards category to the database.
7378             *
7379             * @param categoryId the primary key for the new message boards category
7380             * @return the new message boards category
7381             */
7382            @Override
7383            public MBCategory create(long categoryId) {
7384                    MBCategory mbCategory = new MBCategoryImpl();
7385    
7386                    mbCategory.setNew(true);
7387                    mbCategory.setPrimaryKey(categoryId);
7388    
7389                    String uuid = PortalUUIDUtil.generate();
7390    
7391                    mbCategory.setUuid(uuid);
7392    
7393                    return mbCategory;
7394            }
7395    
7396            /**
7397             * Removes the message boards category with the primary key from the database. Also notifies the appropriate model listeners.
7398             *
7399             * @param categoryId the primary key of the message boards category
7400             * @return the message boards category that was removed
7401             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
7402             * @throws SystemException if a system exception occurred
7403             */
7404            @Override
7405            public MBCategory remove(long categoryId)
7406                    throws NoSuchCategoryException, SystemException {
7407                    return remove((Serializable)categoryId);
7408            }
7409    
7410            /**
7411             * Removes the message boards category with the primary key from the database. Also notifies the appropriate model listeners.
7412             *
7413             * @param primaryKey the primary key of the message boards category
7414             * @return the message boards category that was removed
7415             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
7416             * @throws SystemException if a system exception occurred
7417             */
7418            @Override
7419            public MBCategory remove(Serializable primaryKey)
7420                    throws NoSuchCategoryException, SystemException {
7421                    Session session = null;
7422    
7423                    try {
7424                            session = openSession();
7425    
7426                            MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
7427                                            primaryKey);
7428    
7429                            if (mbCategory == null) {
7430                                    if (_log.isWarnEnabled()) {
7431                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7432                                    }
7433    
7434                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7435                                            primaryKey);
7436                            }
7437    
7438                            return remove(mbCategory);
7439                    }
7440                    catch (NoSuchCategoryException nsee) {
7441                            throw nsee;
7442                    }
7443                    catch (Exception e) {
7444                            throw processException(e);
7445                    }
7446                    finally {
7447                            closeSession(session);
7448                    }
7449            }
7450    
7451            @Override
7452            protected MBCategory removeImpl(MBCategory mbCategory)
7453                    throws SystemException {
7454                    mbCategory = toUnwrappedModel(mbCategory);
7455    
7456                    Session session = null;
7457    
7458                    try {
7459                            session = openSession();
7460    
7461                            if (!session.contains(mbCategory)) {
7462                                    mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
7463                                                    mbCategory.getPrimaryKeyObj());
7464                            }
7465    
7466                            if (mbCategory != null) {
7467                                    session.delete(mbCategory);
7468                            }
7469                    }
7470                    catch (Exception e) {
7471                            throw processException(e);
7472                    }
7473                    finally {
7474                            closeSession(session);
7475                    }
7476    
7477                    if (mbCategory != null) {
7478                            clearCache(mbCategory);
7479                    }
7480    
7481                    return mbCategory;
7482            }
7483    
7484            @Override
7485            public MBCategory updateImpl(
7486                    com.liferay.portlet.messageboards.model.MBCategory mbCategory)
7487                    throws SystemException {
7488                    mbCategory = toUnwrappedModel(mbCategory);
7489    
7490                    boolean isNew = mbCategory.isNew();
7491    
7492                    MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
7493    
7494                    if (Validator.isNull(mbCategory.getUuid())) {
7495                            String uuid = PortalUUIDUtil.generate();
7496    
7497                            mbCategory.setUuid(uuid);
7498                    }
7499    
7500                    Session session = null;
7501    
7502                    try {
7503                            session = openSession();
7504    
7505                            if (mbCategory.isNew()) {
7506                                    session.save(mbCategory);
7507    
7508                                    mbCategory.setNew(false);
7509                            }
7510                            else {
7511                                    session.merge(mbCategory);
7512                            }
7513                    }
7514                    catch (Exception e) {
7515                            throw processException(e);
7516                    }
7517                    finally {
7518                            closeSession(session);
7519                    }
7520    
7521                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
7522    
7523                    if (isNew || !MBCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
7524                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
7525                    }
7526    
7527                    else {
7528                            if ((mbCategoryModelImpl.getColumnBitmask() &
7529                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
7530                                    Object[] args = new Object[] {
7531                                                    mbCategoryModelImpl.getOriginalUuid()
7532                                            };
7533    
7534                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7535                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7536                                            args);
7537    
7538                                    args = new Object[] { mbCategoryModelImpl.getUuid() };
7539    
7540                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
7541                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
7542                                            args);
7543                            }
7544    
7545                            if ((mbCategoryModelImpl.getColumnBitmask() &
7546                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
7547                                    Object[] args = new Object[] {
7548                                                    mbCategoryModelImpl.getOriginalUuid(),
7549                                                    mbCategoryModelImpl.getOriginalCompanyId()
7550                                            };
7551    
7552                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7553                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7554                                            args);
7555    
7556                                    args = new Object[] {
7557                                                    mbCategoryModelImpl.getUuid(),
7558                                                    mbCategoryModelImpl.getCompanyId()
7559                                            };
7560    
7561                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
7562                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
7563                                            args);
7564                            }
7565    
7566                            if ((mbCategoryModelImpl.getColumnBitmask() &
7567                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
7568                                    Object[] args = new Object[] {
7569                                                    mbCategoryModelImpl.getOriginalGroupId()
7570                                            };
7571    
7572                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7573                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7574                                            args);
7575    
7576                                    args = new Object[] { mbCategoryModelImpl.getGroupId() };
7577    
7578                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
7579                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
7580                                            args);
7581                            }
7582    
7583                            if ((mbCategoryModelImpl.getColumnBitmask() &
7584                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
7585                                    Object[] args = new Object[] {
7586                                                    mbCategoryModelImpl.getOriginalCompanyId()
7587                                            };
7588    
7589                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7590                                            args);
7591                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7592                                            args);
7593    
7594                                    args = new Object[] { mbCategoryModelImpl.getCompanyId() };
7595    
7596                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
7597                                            args);
7598                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
7599                                            args);
7600                            }
7601    
7602                            if ((mbCategoryModelImpl.getColumnBitmask() &
7603                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
7604                                    Object[] args = new Object[] {
7605                                                    mbCategoryModelImpl.getOriginalGroupId(),
7606                                                    mbCategoryModelImpl.getOriginalParentCategoryId()
7607                                            };
7608    
7609                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7610                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7611                                            args);
7612    
7613                                    args = new Object[] {
7614                                                    mbCategoryModelImpl.getGroupId(),
7615                                                    mbCategoryModelImpl.getParentCategoryId()
7616                                            };
7617    
7618                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
7619                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
7620                                            args);
7621                            }
7622    
7623                            if ((mbCategoryModelImpl.getColumnBitmask() &
7624                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
7625                                    Object[] args = new Object[] {
7626                                                    mbCategoryModelImpl.getOriginalGroupId(),
7627                                                    mbCategoryModelImpl.getOriginalStatus()
7628                                            };
7629    
7630                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
7631                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
7632                                            args);
7633    
7634                                    args = new Object[] {
7635                                                    mbCategoryModelImpl.getGroupId(),
7636                                                    mbCategoryModelImpl.getStatus()
7637                                            };
7638    
7639                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
7640                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
7641                                            args);
7642                            }
7643    
7644                            if ((mbCategoryModelImpl.getColumnBitmask() &
7645                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
7646                                    Object[] args = new Object[] {
7647                                                    mbCategoryModelImpl.getOriginalCompanyId(),
7648                                                    mbCategoryModelImpl.getOriginalStatus()
7649                                            };
7650    
7651                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
7652                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
7653                                            args);
7654    
7655                                    args = new Object[] {
7656                                                    mbCategoryModelImpl.getCompanyId(),
7657                                                    mbCategoryModelImpl.getStatus()
7658                                            };
7659    
7660                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
7661                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
7662                                            args);
7663                            }
7664    
7665                            if ((mbCategoryModelImpl.getColumnBitmask() &
7666                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S.getColumnBitmask()) != 0) {
7667                                    Object[] args = new Object[] {
7668                                                    mbCategoryModelImpl.getOriginalGroupId(),
7669                                                    mbCategoryModelImpl.getOriginalParentCategoryId(),
7670                                                    mbCategoryModelImpl.getOriginalStatus()
7671                                            };
7672    
7673                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7674                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7675                                            args);
7676    
7677                                    args = new Object[] {
7678                                                    mbCategoryModelImpl.getGroupId(),
7679                                                    mbCategoryModelImpl.getParentCategoryId(),
7680                                                    mbCategoryModelImpl.getStatus()
7681                                            };
7682    
7683                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P_S, args);
7684                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P_S,
7685                                            args);
7686                            }
7687                    }
7688    
7689                    EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7690                            MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
7691    
7692                    clearUniqueFindersCache(mbCategory);
7693                    cacheUniqueFindersCache(mbCategory);
7694    
7695                    return mbCategory;
7696            }
7697    
7698            protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
7699                    if (mbCategory instanceof MBCategoryImpl) {
7700                            return mbCategory;
7701                    }
7702    
7703                    MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
7704    
7705                    mbCategoryImpl.setNew(mbCategory.isNew());
7706                    mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
7707    
7708                    mbCategoryImpl.setUuid(mbCategory.getUuid());
7709                    mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
7710                    mbCategoryImpl.setGroupId(mbCategory.getGroupId());
7711                    mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
7712                    mbCategoryImpl.setUserId(mbCategory.getUserId());
7713                    mbCategoryImpl.setUserName(mbCategory.getUserName());
7714                    mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
7715                    mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
7716                    mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
7717                    mbCategoryImpl.setName(mbCategory.getName());
7718                    mbCategoryImpl.setDescription(mbCategory.getDescription());
7719                    mbCategoryImpl.setDisplayStyle(mbCategory.getDisplayStyle());
7720                    mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
7721                    mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
7722                    mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
7723                    mbCategoryImpl.setStatus(mbCategory.getStatus());
7724                    mbCategoryImpl.setStatusByUserId(mbCategory.getStatusByUserId());
7725                    mbCategoryImpl.setStatusByUserName(mbCategory.getStatusByUserName());
7726                    mbCategoryImpl.setStatusDate(mbCategory.getStatusDate());
7727    
7728                    return mbCategoryImpl;
7729            }
7730    
7731            /**
7732             * Returns the message boards category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
7733             *
7734             * @param primaryKey the primary key of the message boards category
7735             * @return the message boards category
7736             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
7737             * @throws SystemException if a system exception occurred
7738             */
7739            @Override
7740            public MBCategory findByPrimaryKey(Serializable primaryKey)
7741                    throws NoSuchCategoryException, SystemException {
7742                    MBCategory mbCategory = fetchByPrimaryKey(primaryKey);
7743    
7744                    if (mbCategory == null) {
7745                            if (_log.isWarnEnabled()) {
7746                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
7747                            }
7748    
7749                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
7750                                    primaryKey);
7751                    }
7752    
7753                    return mbCategory;
7754            }
7755    
7756            /**
7757             * Returns the message boards category with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchCategoryException} if it could not be found.
7758             *
7759             * @param categoryId the primary key of the message boards category
7760             * @return the message boards category
7761             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
7762             * @throws SystemException if a system exception occurred
7763             */
7764            @Override
7765            public MBCategory findByPrimaryKey(long categoryId)
7766                    throws NoSuchCategoryException, SystemException {
7767                    return findByPrimaryKey((Serializable)categoryId);
7768            }
7769    
7770            /**
7771             * Returns the message boards category with the primary key or returns <code>null</code> if it could not be found.
7772             *
7773             * @param primaryKey the primary key of the message boards category
7774             * @return the message boards category, or <code>null</code> if a message boards category with the primary key could not be found
7775             * @throws SystemException if a system exception occurred
7776             */
7777            @Override
7778            public MBCategory fetchByPrimaryKey(Serializable primaryKey)
7779                    throws SystemException {
7780                    MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7781                                    MBCategoryImpl.class, primaryKey);
7782    
7783                    if (mbCategory == _nullMBCategory) {
7784                            return null;
7785                    }
7786    
7787                    if (mbCategory == null) {
7788                            Session session = null;
7789    
7790                            try {
7791                                    session = openSession();
7792    
7793                                    mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
7794                                                    primaryKey);
7795    
7796                                    if (mbCategory != null) {
7797                                            cacheResult(mbCategory);
7798                                    }
7799                                    else {
7800                                            EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7801                                                    MBCategoryImpl.class, primaryKey, _nullMBCategory);
7802                                    }
7803                            }
7804                            catch (Exception e) {
7805                                    EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
7806                                            MBCategoryImpl.class, primaryKey);
7807    
7808                                    throw processException(e);
7809                            }
7810                            finally {
7811                                    closeSession(session);
7812                            }
7813                    }
7814    
7815                    return mbCategory;
7816            }
7817    
7818            /**
7819             * Returns the message boards category with the primary key or returns <code>null</code> if it could not be found.
7820             *
7821             * @param categoryId the primary key of the message boards category
7822             * @return the message boards category, or <code>null</code> if a message boards category with the primary key could not be found
7823             * @throws SystemException if a system exception occurred
7824             */
7825            @Override
7826            public MBCategory fetchByPrimaryKey(long categoryId)
7827                    throws SystemException {
7828                    return fetchByPrimaryKey((Serializable)categoryId);
7829            }
7830    
7831            /**
7832             * Returns all the message boards categories.
7833             *
7834             * @return the message boards categories
7835             * @throws SystemException if a system exception occurred
7836             */
7837            @Override
7838            public List<MBCategory> findAll() throws SystemException {
7839                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
7840            }
7841    
7842            /**
7843             * Returns a range of all the message boards categories.
7844             *
7845             * <p>
7846             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7847             * </p>
7848             *
7849             * @param start the lower bound of the range of message boards categories
7850             * @param end the upper bound of the range of message boards categories (not inclusive)
7851             * @return the range of message boards categories
7852             * @throws SystemException if a system exception occurred
7853             */
7854            @Override
7855            public List<MBCategory> findAll(int start, int end)
7856                    throws SystemException {
7857                    return findAll(start, end, null);
7858            }
7859    
7860            /**
7861             * Returns an ordered range of all the message boards categories.
7862             *
7863             * <p>
7864             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7865             * </p>
7866             *
7867             * @param start the lower bound of the range of message boards categories
7868             * @param end the upper bound of the range of message boards categories (not inclusive)
7869             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7870             * @return the ordered range of message boards categories
7871             * @throws SystemException if a system exception occurred
7872             */
7873            @Override
7874            public List<MBCategory> findAll(int start, int end,
7875                    OrderByComparator orderByComparator) throws SystemException {
7876                    boolean pagination = true;
7877                    FinderPath finderPath = null;
7878                    Object[] finderArgs = null;
7879    
7880                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7881                                    (orderByComparator == null)) {
7882                            pagination = false;
7883                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
7884                            finderArgs = FINDER_ARGS_EMPTY;
7885                    }
7886                    else {
7887                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
7888                            finderArgs = new Object[] { start, end, orderByComparator };
7889                    }
7890    
7891                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
7892                                    finderArgs, this);
7893    
7894                    if (list == null) {
7895                            StringBundler query = null;
7896                            String sql = null;
7897    
7898                            if (orderByComparator != null) {
7899                                    query = new StringBundler(2 +
7900                                                    (orderByComparator.getOrderByFields().length * 3));
7901    
7902                                    query.append(_SQL_SELECT_MBCATEGORY);
7903    
7904                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7905                                            orderByComparator);
7906    
7907                                    sql = query.toString();
7908                            }
7909                            else {
7910                                    sql = _SQL_SELECT_MBCATEGORY;
7911    
7912                                    if (pagination) {
7913                                            sql = sql.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
7914                                    }
7915                            }
7916    
7917                            Session session = null;
7918    
7919                            try {
7920                                    session = openSession();
7921    
7922                                    Query q = session.createQuery(sql);
7923    
7924                                    if (!pagination) {
7925                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7926                                                            start, end, false);
7927    
7928                                            Collections.sort(list);
7929    
7930                                            list = new UnmodifiableList<MBCategory>(list);
7931                                    }
7932                                    else {
7933                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
7934                                                            start, end);
7935                                    }
7936    
7937                                    cacheResult(list);
7938    
7939                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7940                            }
7941                            catch (Exception e) {
7942                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7943    
7944                                    throw processException(e);
7945                            }
7946                            finally {
7947                                    closeSession(session);
7948                            }
7949                    }
7950    
7951                    return list;
7952            }
7953    
7954            /**
7955             * Removes all the message boards categories from the database.
7956             *
7957             * @throws SystemException if a system exception occurred
7958             */
7959            @Override
7960            public void removeAll() throws SystemException {
7961                    for (MBCategory mbCategory : findAll()) {
7962                            remove(mbCategory);
7963                    }
7964            }
7965    
7966            /**
7967             * Returns the number of message boards categories.
7968             *
7969             * @return the number of message boards categories
7970             * @throws SystemException if a system exception occurred
7971             */
7972            @Override
7973            public int countAll() throws SystemException {
7974                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
7975                                    FINDER_ARGS_EMPTY, this);
7976    
7977                    if (count == null) {
7978                            Session session = null;
7979    
7980                            try {
7981                                    session = openSession();
7982    
7983                                    Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
7984    
7985                                    count = (Long)q.uniqueResult();
7986    
7987                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
7988                                            FINDER_ARGS_EMPTY, count);
7989                            }
7990                            catch (Exception e) {
7991                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
7992                                            FINDER_ARGS_EMPTY);
7993    
7994                                    throw processException(e);
7995                            }
7996                            finally {
7997                                    closeSession(session);
7998                            }
7999                    }
8000    
8001                    return count.intValue();
8002            }
8003    
8004            @Override
8005            protected Set<String> getBadColumnNames() {
8006                    return _badColumnNames;
8007            }
8008    
8009            /**
8010             * Initializes the message boards category persistence.
8011             */
8012            public void afterPropertiesSet() {
8013                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
8014                                            com.liferay.portal.util.PropsUtil.get(
8015                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
8016    
8017                    if (listenerClassNames.length > 0) {
8018                            try {
8019                                    List<ModelListener<MBCategory>> listenersList = new ArrayList<ModelListener<MBCategory>>();
8020    
8021                                    for (String listenerClassName : listenerClassNames) {
8022                                            listenersList.add((ModelListener<MBCategory>)InstanceFactory.newInstance(
8023                                                            getClassLoader(), listenerClassName));
8024                                    }
8025    
8026                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
8027                            }
8028                            catch (Exception e) {
8029                                    _log.error(e);
8030                            }
8031                    }
8032            }
8033    
8034            public void destroy() {
8035                    EntityCacheUtil.removeCache(MBCategoryImpl.class.getName());
8036                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
8037                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
8038                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
8039            }
8040    
8041            private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
8042            private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
8043            private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
8044            private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
8045            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbCategory.categoryId";
8046            private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
8047            private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
8048                    "SELECT {MBCategory.*} FROM (SELECT DISTINCT mbCategory.categoryId FROM MBCategory mbCategory WHERE ";
8049            private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
8050                    ") TEMP_TABLE INNER JOIN MBCategory ON TEMP_TABLE.categoryId = MBCategory.categoryId";
8051            private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
8052            private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
8053            private static final String _FILTER_ENTITY_TABLE = "MBCategory";
8054            private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
8055            private static final String _ORDER_BY_ENTITY_TABLE = "MBCategory.";
8056            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
8057            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
8058            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
8059            private static Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
8060            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
8061                                    "uuid"
8062                            });
8063            private static MBCategory _nullMBCategory = new MBCategoryImpl() {
8064                            @Override
8065                            public Object clone() {
8066                                    return this;
8067                            }
8068    
8069                            @Override
8070                            public CacheModel<MBCategory> toCacheModel() {
8071                                    return _nullMBCategoryCacheModel;
8072                            }
8073                    };
8074    
8075            private static CacheModel<MBCategory> _nullMBCategoryCacheModel = new CacheModel<MBCategory>() {
8076                            @Override
8077                            public MBCategory toEntityModel() {
8078                                    return _nullMBCategory;
8079                            }
8080                    };
8081    }