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