001    /**
002     * Copyright (c) 2000-2011 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.NoSuchModelException;
018    import com.liferay.portal.kernel.annotation.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.SQLQuery;
027    import com.liferay.portal.kernel.dao.orm.Session;
028    import com.liferay.portal.kernel.exception.SystemException;
029    import com.liferay.portal.kernel.log.Log;
030    import com.liferay.portal.kernel.log.LogFactoryUtil;
031    import com.liferay.portal.kernel.util.GetterUtil;
032    import com.liferay.portal.kernel.util.InstanceFactory;
033    import com.liferay.portal.kernel.util.OrderByComparator;
034    import com.liferay.portal.kernel.util.StringBundler;
035    import com.liferay.portal.kernel.util.StringPool;
036    import com.liferay.portal.kernel.util.StringUtil;
037    import com.liferay.portal.kernel.util.Validator;
038    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
039    import com.liferay.portal.model.ModelListener;
040    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
041    import com.liferay.portal.service.persistence.BatchSessionUtil;
042    import com.liferay.portal.service.persistence.GroupPersistence;
043    import com.liferay.portal.service.persistence.ResourcePersistence;
044    import com.liferay.portal.service.persistence.SubscriptionPersistence;
045    import com.liferay.portal.service.persistence.UserPersistence;
046    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
047    
048    import com.liferay.portlet.asset.service.persistence.AssetTagPersistence;
049    import com.liferay.portlet.expando.service.persistence.ExpandoValuePersistence;
050    import com.liferay.portlet.messageboards.NoSuchCategoryException;
051    import com.liferay.portlet.messageboards.model.MBCategory;
052    import com.liferay.portlet.messageboards.model.impl.MBCategoryImpl;
053    import com.liferay.portlet.messageboards.model.impl.MBCategoryModelImpl;
054    
055    import java.io.Serializable;
056    
057    import java.util.ArrayList;
058    import java.util.Collections;
059    import java.util.List;
060    
061    /**
062     * The persistence implementation for the message boards category service.
063     *
064     * <p>
065     * 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.
066     * </p>
067     *
068     * <p>
069     * Caching information and settings can be found in <code>portal.properties</code>
070     * </p>
071     *
072     * @author Brian Wing Shun Chan
073     * @see MBCategoryPersistence
074     * @see MBCategoryUtil
075     * @generated
076     */
077    public class MBCategoryPersistenceImpl extends BasePersistenceImpl<MBCategory>
078            implements MBCategoryPersistence {
079            public static final String FINDER_CLASS_NAME_ENTITY = MBCategoryImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST = FINDER_CLASS_NAME_ENTITY +
081                    ".List";
082            public static final FinderPath FINDER_PATH_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
083                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
084                            "findByUuid",
085                            new String[] {
086                                    String.class.getName(),
087                                    
088                            "java.lang.Integer", "java.lang.Integer",
089                                    "com.liferay.portal.kernel.util.OrderByComparator"
090                            });
091            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
092                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
093                            "countByUuid", new String[] { String.class.getName() });
094            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
095                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_ENTITY,
096                            "fetchByUUID_G",
097                            new String[] { String.class.getName(), Long.class.getName() });
098            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
099                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
100                            "countByUUID_G",
101                            new String[] { String.class.getName(), Long.class.getName() });
102            public static final FinderPath FINDER_PATH_FIND_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
103                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
104                            "findByGroupId",
105                            new String[] {
106                                    Long.class.getName(),
107                                    
108                            "java.lang.Integer", "java.lang.Integer",
109                                    "com.liferay.portal.kernel.util.OrderByComparator"
110                            });
111            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
112                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
113                            "countByGroupId", new String[] { Long.class.getName() });
114            public static final FinderPath FINDER_PATH_FIND_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
115                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
116                            "findByCompanyId",
117                            new String[] {
118                                    Long.class.getName(),
119                                    
120                            "java.lang.Integer", "java.lang.Integer",
121                                    "com.liferay.portal.kernel.util.OrderByComparator"
122                            });
123            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
124                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
125                            "countByCompanyId", new String[] { Long.class.getName() });
126            public static final FinderPath FINDER_PATH_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
127                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
128                            "findByG_P",
129                            new String[] {
130                                    Long.class.getName(), Long.class.getName(),
131                                    
132                            "java.lang.Integer", "java.lang.Integer",
133                                    "com.liferay.portal.kernel.util.OrderByComparator"
134                            });
135            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
136                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
137                            "countByG_P",
138                            new String[] { Long.class.getName(), Long.class.getName() });
139            public static final FinderPath FINDER_PATH_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
140                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
141                            "findAll", new String[0]);
142            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
143                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, FINDER_CLASS_NAME_LIST,
144                            "countAll", new String[0]);
145    
146            /**
147             * Caches the message boards category in the entity cache if it is enabled.
148             *
149             * @param mbCategory the message boards category to cache
150             */
151            public void cacheResult(MBCategory mbCategory) {
152                    EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
153                            MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
154    
155                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
156                            new Object[] { mbCategory.getUuid(), new Long(
157                                            mbCategory.getGroupId()) }, mbCategory);
158            }
159    
160            /**
161             * Caches the message boards categories in the entity cache if it is enabled.
162             *
163             * @param mbCategories the message boards categories to cache
164             */
165            public void cacheResult(List<MBCategory> mbCategories) {
166                    for (MBCategory mbCategory : mbCategories) {
167                            if (EntityCacheUtil.getResult(
168                                                    MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
169                                                    MBCategoryImpl.class, mbCategory.getPrimaryKey(), this) == null) {
170                                    cacheResult(mbCategory);
171                            }
172                    }
173            }
174    
175            /**
176             * Clears the cache for all message boards categories.
177             *
178             * <p>
179             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
180             * </p>
181             */
182            public void clearCache() {
183                    CacheRegistryUtil.clear(MBCategoryImpl.class.getName());
184                    EntityCacheUtil.clearCache(MBCategoryImpl.class.getName());
185                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
186                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
187            }
188    
189            /**
190             * Clears the cache for the message boards category.
191             *
192             * <p>
193             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
194             * </p>
195             */
196            public void clearCache(MBCategory mbCategory) {
197                    EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
198                            MBCategoryImpl.class, mbCategory.getPrimaryKey());
199    
200                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
201                            new Object[] { mbCategory.getUuid(), new Long(
202                                            mbCategory.getGroupId()) });
203            }
204    
205            /**
206             * Creates a new message boards category with the primary key. Does not add the message boards category to the database.
207             *
208             * @param categoryId the primary key for the new message boards category
209             * @return the new message boards category
210             */
211            public MBCategory create(long categoryId) {
212                    MBCategory mbCategory = new MBCategoryImpl();
213    
214                    mbCategory.setNew(true);
215                    mbCategory.setPrimaryKey(categoryId);
216    
217                    String uuid = PortalUUIDUtil.generate();
218    
219                    mbCategory.setUuid(uuid);
220    
221                    return mbCategory;
222            }
223    
224            /**
225             * Removes the message boards category with the primary key from the database. Also notifies the appropriate model listeners.
226             *
227             * @param primaryKey the primary key of the message boards category to remove
228             * @return the message boards category that was removed
229             * @throws com.liferay.portal.NoSuchModelException if a message boards category with the primary key could not be found
230             * @throws SystemException if a system exception occurred
231             */
232            public MBCategory remove(Serializable primaryKey)
233                    throws NoSuchModelException, SystemException {
234                    return remove(((Long)primaryKey).longValue());
235            }
236    
237            /**
238             * Removes the message boards category with the primary key from the database. Also notifies the appropriate model listeners.
239             *
240             * @param categoryId the primary key of the message boards category to remove
241             * @return the message boards category that was removed
242             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
243             * @throws SystemException if a system exception occurred
244             */
245            public MBCategory remove(long categoryId)
246                    throws NoSuchCategoryException, SystemException {
247                    Session session = null;
248    
249                    try {
250                            session = openSession();
251    
252                            MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
253                                            new Long(categoryId));
254    
255                            if (mbCategory == null) {
256                                    if (_log.isWarnEnabled()) {
257                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
258                                    }
259    
260                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
261                                            categoryId);
262                            }
263    
264                            return remove(mbCategory);
265                    }
266                    catch (NoSuchCategoryException nsee) {
267                            throw nsee;
268                    }
269                    catch (Exception e) {
270                            throw processException(e);
271                    }
272                    finally {
273                            closeSession(session);
274                    }
275            }
276    
277            protected MBCategory removeImpl(MBCategory mbCategory)
278                    throws SystemException {
279                    mbCategory = toUnwrappedModel(mbCategory);
280    
281                    Session session = null;
282    
283                    try {
284                            session = openSession();
285    
286                            BatchSessionUtil.delete(session, mbCategory);
287                    }
288                    catch (Exception e) {
289                            throw processException(e);
290                    }
291                    finally {
292                            closeSession(session);
293                    }
294    
295                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
296    
297                    MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
298    
299                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
300                            new Object[] {
301                                    mbCategoryModelImpl.getUuid(),
302                                    new Long(mbCategoryModelImpl.getGroupId())
303                            });
304    
305                    EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
306                            MBCategoryImpl.class, mbCategory.getPrimaryKey());
307    
308                    return mbCategory;
309            }
310    
311            public MBCategory updateImpl(
312                    com.liferay.portlet.messageboards.model.MBCategory mbCategory,
313                    boolean merge) throws SystemException {
314                    mbCategory = toUnwrappedModel(mbCategory);
315    
316                    boolean isNew = mbCategory.isNew();
317    
318                    MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
319    
320                    if (Validator.isNull(mbCategory.getUuid())) {
321                            String uuid = PortalUUIDUtil.generate();
322    
323                            mbCategory.setUuid(uuid);
324                    }
325    
326                    Session session = null;
327    
328                    try {
329                            session = openSession();
330    
331                            BatchSessionUtil.update(session, mbCategory, merge);
332    
333                            mbCategory.setNew(false);
334                    }
335                    catch (Exception e) {
336                            throw processException(e);
337                    }
338                    finally {
339                            closeSession(session);
340                    }
341    
342                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST);
343    
344                    EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
345                            MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
346    
347                    if (!isNew &&
348                                    (!Validator.equals(mbCategory.getUuid(),
349                                            mbCategoryModelImpl.getOriginalUuid()) ||
350                                    (mbCategory.getGroupId() != mbCategoryModelImpl.getOriginalGroupId()))) {
351                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
352                                    new Object[] {
353                                            mbCategoryModelImpl.getOriginalUuid(),
354                                            new Long(mbCategoryModelImpl.getOriginalGroupId())
355                                    });
356                    }
357    
358                    if (isNew ||
359                                    (!Validator.equals(mbCategory.getUuid(),
360                                            mbCategoryModelImpl.getOriginalUuid()) ||
361                                    (mbCategory.getGroupId() != mbCategoryModelImpl.getOriginalGroupId()))) {
362                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
363                                    new Object[] {
364                                            mbCategory.getUuid(), new Long(mbCategory.getGroupId())
365                                    }, mbCategory);
366                    }
367    
368                    return mbCategory;
369            }
370    
371            protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
372                    if (mbCategory instanceof MBCategoryImpl) {
373                            return mbCategory;
374                    }
375    
376                    MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
377    
378                    mbCategoryImpl.setNew(mbCategory.isNew());
379                    mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
380    
381                    mbCategoryImpl.setUuid(mbCategory.getUuid());
382                    mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
383                    mbCategoryImpl.setGroupId(mbCategory.getGroupId());
384                    mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
385                    mbCategoryImpl.setUserId(mbCategory.getUserId());
386                    mbCategoryImpl.setUserName(mbCategory.getUserName());
387                    mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
388                    mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
389                    mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
390                    mbCategoryImpl.setName(mbCategory.getName());
391                    mbCategoryImpl.setDescription(mbCategory.getDescription());
392                    mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
393                    mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
394                    mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
395    
396                    return mbCategoryImpl;
397            }
398    
399            /**
400             * Finds the message boards category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
401             *
402             * @param primaryKey the primary key of the message boards category to find
403             * @return the message boards category
404             * @throws com.liferay.portal.NoSuchModelException if a message boards category with the primary key could not be found
405             * @throws SystemException if a system exception occurred
406             */
407            public MBCategory findByPrimaryKey(Serializable primaryKey)
408                    throws NoSuchModelException, SystemException {
409                    return findByPrimaryKey(((Long)primaryKey).longValue());
410            }
411    
412            /**
413             * Finds the message boards category with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchCategoryException} if it could not be found.
414             *
415             * @param categoryId the primary key of the message boards category to find
416             * @return the message boards category
417             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
418             * @throws SystemException if a system exception occurred
419             */
420            public MBCategory findByPrimaryKey(long categoryId)
421                    throws NoSuchCategoryException, SystemException {
422                    MBCategory mbCategory = fetchByPrimaryKey(categoryId);
423    
424                    if (mbCategory == null) {
425                            if (_log.isWarnEnabled()) {
426                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
427                            }
428    
429                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
430                                    categoryId);
431                    }
432    
433                    return mbCategory;
434            }
435    
436            /**
437             * Finds the message boards category with the primary key or returns <code>null</code> if it could not be found.
438             *
439             * @param primaryKey the primary key of the message boards category to find
440             * @return the message boards category, or <code>null</code> if a message boards category with the primary key could not be found
441             * @throws SystemException if a system exception occurred
442             */
443            public MBCategory fetchByPrimaryKey(Serializable primaryKey)
444                    throws SystemException {
445                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
446            }
447    
448            /**
449             * Finds the message boards category with the primary key or returns <code>null</code> if it could not be found.
450             *
451             * @param categoryId the primary key of the message boards category to find
452             * @return the message boards category, or <code>null</code> if a message boards category with the primary key could not be found
453             * @throws SystemException if a system exception occurred
454             */
455            public MBCategory fetchByPrimaryKey(long categoryId)
456                    throws SystemException {
457                    MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
458                                    MBCategoryImpl.class, categoryId, this);
459    
460                    if (mbCategory == null) {
461                            Session session = null;
462    
463                            try {
464                                    session = openSession();
465    
466                                    mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
467                                                    new Long(categoryId));
468                            }
469                            catch (Exception e) {
470                                    throw processException(e);
471                            }
472                            finally {
473                                    if (mbCategory != null) {
474                                            cacheResult(mbCategory);
475                                    }
476    
477                                    closeSession(session);
478                            }
479                    }
480    
481                    return mbCategory;
482            }
483    
484            /**
485             * Finds all the message boards categories where uuid = &#63;.
486             *
487             * @param uuid the uuid to search with
488             * @return the matching message boards categories
489             * @throws SystemException if a system exception occurred
490             */
491            public List<MBCategory> findByUuid(String uuid) throws SystemException {
492                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
493            }
494    
495            /**
496             * Finds a range of all the message boards categories where uuid = &#63;.
497             *
498             * <p>
499             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
500             * </p>
501             *
502             * @param uuid the uuid to search with
503             * @param start the lower bound of the range of message boards categories to return
504             * @param end the upper bound of the range of message boards categories to return (not inclusive)
505             * @return the range of matching message boards categories
506             * @throws SystemException if a system exception occurred
507             */
508            public List<MBCategory> findByUuid(String uuid, int start, int end)
509                    throws SystemException {
510                    return findByUuid(uuid, start, end, null);
511            }
512    
513            /**
514             * Finds an ordered range of all the message boards categories where uuid = &#63;.
515             *
516             * <p>
517             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
518             * </p>
519             *
520             * @param uuid the uuid to search with
521             * @param start the lower bound of the range of message boards categories to return
522             * @param end the upper bound of the range of message boards categories to return (not inclusive)
523             * @param orderByComparator the comparator to order the results by
524             * @return the ordered range of matching message boards categories
525             * @throws SystemException if a system exception occurred
526             */
527            public List<MBCategory> findByUuid(String uuid, int start, int end,
528                    OrderByComparator orderByComparator) throws SystemException {
529                    Object[] finderArgs = new Object[] {
530                                    uuid,
531                                    
532                                    String.valueOf(start), String.valueOf(end),
533                                    String.valueOf(orderByComparator)
534                            };
535    
536                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_UUID,
537                                    finderArgs, this);
538    
539                    if (list == null) {
540                            StringBundler query = null;
541    
542                            if (orderByComparator != null) {
543                                    query = new StringBundler(3 +
544                                                    (orderByComparator.getOrderByFields().length * 3));
545                            }
546                            else {
547                                    query = new StringBundler(3);
548                            }
549    
550                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
551    
552                            if (uuid == null) {
553                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
554                            }
555                            else {
556                                    if (uuid.equals(StringPool.BLANK)) {
557                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
558                                    }
559                                    else {
560                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
561                                    }
562                            }
563    
564                            if (orderByComparator != null) {
565                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
566                                            orderByComparator);
567                            }
568    
569                            else {
570                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
571                            }
572    
573                            String sql = query.toString();
574    
575                            Session session = null;
576    
577                            try {
578                                    session = openSession();
579    
580                                    Query q = session.createQuery(sql);
581    
582                                    QueryPos qPos = QueryPos.getInstance(q);
583    
584                                    if (uuid != null) {
585                                            qPos.add(uuid);
586                                    }
587    
588                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
589                                                    end);
590                            }
591                            catch (Exception e) {
592                                    throw processException(e);
593                            }
594                            finally {
595                                    if (list == null) {
596                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_UUID,
597                                                    finderArgs);
598                                    }
599                                    else {
600                                            cacheResult(list);
601    
602                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_UUID,
603                                                    finderArgs, list);
604                                    }
605    
606                                    closeSession(session);
607                            }
608                    }
609    
610                    return list;
611            }
612    
613            /**
614             * Finds the first message boards category in the ordered set where uuid = &#63;.
615             *
616             * <p>
617             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
618             * </p>
619             *
620             * @param uuid the uuid to search with
621             * @param orderByComparator the comparator to order the set by
622             * @return the first matching message boards category
623             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
624             * @throws SystemException if a system exception occurred
625             */
626            public MBCategory findByUuid_First(String uuid,
627                    OrderByComparator orderByComparator)
628                    throws NoSuchCategoryException, SystemException {
629                    List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
630    
631                    if (list.isEmpty()) {
632                            StringBundler msg = new StringBundler(4);
633    
634                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
635    
636                            msg.append("uuid=");
637                            msg.append(uuid);
638    
639                            msg.append(StringPool.CLOSE_CURLY_BRACE);
640    
641                            throw new NoSuchCategoryException(msg.toString());
642                    }
643                    else {
644                            return list.get(0);
645                    }
646            }
647    
648            /**
649             * Finds the last message boards category in the ordered set where uuid = &#63;.
650             *
651             * <p>
652             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
653             * </p>
654             *
655             * @param uuid the uuid to search with
656             * @param orderByComparator the comparator to order the set by
657             * @return the last matching message boards category
658             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
659             * @throws SystemException if a system exception occurred
660             */
661            public MBCategory findByUuid_Last(String uuid,
662                    OrderByComparator orderByComparator)
663                    throws NoSuchCategoryException, SystemException {
664                    int count = countByUuid(uuid);
665    
666                    List<MBCategory> list = findByUuid(uuid, count - 1, count,
667                                    orderByComparator);
668    
669                    if (list.isEmpty()) {
670                            StringBundler msg = new StringBundler(4);
671    
672                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
673    
674                            msg.append("uuid=");
675                            msg.append(uuid);
676    
677                            msg.append(StringPool.CLOSE_CURLY_BRACE);
678    
679                            throw new NoSuchCategoryException(msg.toString());
680                    }
681                    else {
682                            return list.get(0);
683                    }
684            }
685    
686            /**
687             * Finds the message boards categories before and after the current message boards category in the ordered set where uuid = &#63;.
688             *
689             * <p>
690             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
691             * </p>
692             *
693             * @param categoryId the primary key of the current message boards category
694             * @param uuid the uuid to search with
695             * @param orderByComparator the comparator to order the set by
696             * @return the previous, current, and next message boards category
697             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
698             * @throws SystemException if a system exception occurred
699             */
700            public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
701                    OrderByComparator orderByComparator)
702                    throws NoSuchCategoryException, SystemException {
703                    MBCategory mbCategory = findByPrimaryKey(categoryId);
704    
705                    Session session = null;
706    
707                    try {
708                            session = openSession();
709    
710                            MBCategory[] array = new MBCategoryImpl[3];
711    
712                            array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
713                                            orderByComparator, true);
714    
715                            array[1] = mbCategory;
716    
717                            array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
718                                            orderByComparator, false);
719    
720                            return array;
721                    }
722                    catch (Exception e) {
723                            throw processException(e);
724                    }
725                    finally {
726                            closeSession(session);
727                    }
728            }
729    
730            protected MBCategory getByUuid_PrevAndNext(Session session,
731                    MBCategory mbCategory, String uuid,
732                    OrderByComparator orderByComparator, boolean previous) {
733                    StringBundler query = null;
734    
735                    if (orderByComparator != null) {
736                            query = new StringBundler(6 +
737                                            (orderByComparator.getOrderByFields().length * 6));
738                    }
739                    else {
740                            query = new StringBundler(3);
741                    }
742    
743                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
744    
745                    if (uuid == null) {
746                            query.append(_FINDER_COLUMN_UUID_UUID_1);
747                    }
748                    else {
749                            if (uuid.equals(StringPool.BLANK)) {
750                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
751                            }
752                            else {
753                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
754                            }
755                    }
756    
757                    if (orderByComparator != null) {
758                            String[] orderByFields = orderByComparator.getOrderByFields();
759    
760                            if (orderByFields.length > 0) {
761                                    query.append(WHERE_AND);
762                            }
763    
764                            for (int i = 0; i < orderByFields.length; i++) {
765                                    query.append(_ORDER_BY_ENTITY_ALIAS);
766                                    query.append(orderByFields[i]);
767    
768                                    if ((i + 1) < orderByFields.length) {
769                                            if (orderByComparator.isAscending() ^ previous) {
770                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
771                                            }
772                                            else {
773                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
774                                            }
775                                    }
776                                    else {
777                                            if (orderByComparator.isAscending() ^ previous) {
778                                                    query.append(WHERE_GREATER_THAN);
779                                            }
780                                            else {
781                                                    query.append(WHERE_LESSER_THAN);
782                                            }
783                                    }
784                            }
785    
786                            query.append(ORDER_BY_CLAUSE);
787    
788                            for (int i = 0; i < orderByFields.length; i++) {
789                                    query.append(_ORDER_BY_ENTITY_ALIAS);
790                                    query.append(orderByFields[i]);
791    
792                                    if ((i + 1) < orderByFields.length) {
793                                            if (orderByComparator.isAscending() ^ previous) {
794                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
795                                            }
796                                            else {
797                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
798                                            }
799                                    }
800                                    else {
801                                            if (orderByComparator.isAscending() ^ previous) {
802                                                    query.append(ORDER_BY_ASC);
803                                            }
804                                            else {
805                                                    query.append(ORDER_BY_DESC);
806                                            }
807                                    }
808                            }
809                    }
810    
811                    else {
812                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
813                    }
814    
815                    String sql = query.toString();
816    
817                    Query q = session.createQuery(sql);
818    
819                    q.setFirstResult(0);
820                    q.setMaxResults(2);
821    
822                    QueryPos qPos = QueryPos.getInstance(q);
823    
824                    if (uuid != null) {
825                            qPos.add(uuid);
826                    }
827    
828                    if (orderByComparator != null) {
829                            Object[] values = orderByComparator.getOrderByValues(mbCategory);
830    
831                            for (Object value : values) {
832                                    qPos.add(value);
833                            }
834                    }
835    
836                    List<MBCategory> list = q.list();
837    
838                    if (list.size() == 2) {
839                            return list.get(1);
840                    }
841                    else {
842                            return null;
843                    }
844            }
845    
846            /**
847             * Finds 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.
848             *
849             * @param uuid the uuid to search with
850             * @param groupId the group id to search with
851             * @return the matching message boards category
852             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
853             * @throws SystemException if a system exception occurred
854             */
855            public MBCategory findByUUID_G(String uuid, long groupId)
856                    throws NoSuchCategoryException, SystemException {
857                    MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
858    
859                    if (mbCategory == null) {
860                            StringBundler msg = new StringBundler(6);
861    
862                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
863    
864                            msg.append("uuid=");
865                            msg.append(uuid);
866    
867                            msg.append(", groupId=");
868                            msg.append(groupId);
869    
870                            msg.append(StringPool.CLOSE_CURLY_BRACE);
871    
872                            if (_log.isWarnEnabled()) {
873                                    _log.warn(msg.toString());
874                            }
875    
876                            throw new NoSuchCategoryException(msg.toString());
877                    }
878    
879                    return mbCategory;
880            }
881    
882            /**
883             * Finds 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.
884             *
885             * @param uuid the uuid to search with
886             * @param groupId the group id to search with
887             * @return the matching message boards category, or <code>null</code> if a matching message boards category could not be found
888             * @throws SystemException if a system exception occurred
889             */
890            public MBCategory fetchByUUID_G(String uuid, long groupId)
891                    throws SystemException {
892                    return fetchByUUID_G(uuid, groupId, true);
893            }
894    
895            /**
896             * Finds 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.
897             *
898             * @param uuid the uuid to search with
899             * @param groupId the group id to search with
900             * @return the matching message boards category, or <code>null</code> if a matching message boards category could not be found
901             * @throws SystemException if a system exception occurred
902             */
903            public MBCategory fetchByUUID_G(String uuid, long groupId,
904                    boolean retrieveFromCache) throws SystemException {
905                    Object[] finderArgs = new Object[] { uuid, groupId };
906    
907                    Object result = null;
908    
909                    if (retrieveFromCache) {
910                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
911                                            finderArgs, this);
912                    }
913    
914                    if (result == null) {
915                            StringBundler query = new StringBundler(4);
916    
917                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
918    
919                            if (uuid == null) {
920                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
921                            }
922                            else {
923                                    if (uuid.equals(StringPool.BLANK)) {
924                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
925                                    }
926                                    else {
927                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
928                                    }
929                            }
930    
931                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
932    
933                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
934    
935                            String sql = query.toString();
936    
937                            Session session = null;
938    
939                            try {
940                                    session = openSession();
941    
942                                    Query q = session.createQuery(sql);
943    
944                                    QueryPos qPos = QueryPos.getInstance(q);
945    
946                                    if (uuid != null) {
947                                            qPos.add(uuid);
948                                    }
949    
950                                    qPos.add(groupId);
951    
952                                    List<MBCategory> list = q.list();
953    
954                                    result = list;
955    
956                                    MBCategory mbCategory = null;
957    
958                                    if (list.isEmpty()) {
959                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
960                                                    finderArgs, list);
961                                    }
962                                    else {
963                                            mbCategory = list.get(0);
964    
965                                            cacheResult(mbCategory);
966    
967                                            if ((mbCategory.getUuid() == null) ||
968                                                            !mbCategory.getUuid().equals(uuid) ||
969                                                            (mbCategory.getGroupId() != groupId)) {
970                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
971                                                            finderArgs, mbCategory);
972                                            }
973                                    }
974    
975                                    return mbCategory;
976                            }
977                            catch (Exception e) {
978                                    throw processException(e);
979                            }
980                            finally {
981                                    if (result == null) {
982                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
983                                                    finderArgs);
984                                    }
985    
986                                    closeSession(session);
987                            }
988                    }
989                    else {
990                            if (result instanceof List<?>) {
991                                    return null;
992                            }
993                            else {
994                                    return (MBCategory)result;
995                            }
996                    }
997            }
998    
999            /**
1000             * Finds all the message boards categories where groupId = &#63;.
1001             *
1002             * @param groupId the group id to search with
1003             * @return the matching message boards categories
1004             * @throws SystemException if a system exception occurred
1005             */
1006            public List<MBCategory> findByGroupId(long groupId)
1007                    throws SystemException {
1008                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1009            }
1010    
1011            /**
1012             * Finds a range of all the message boards categories where groupId = &#63;.
1013             *
1014             * <p>
1015             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1016             * </p>
1017             *
1018             * @param groupId the group id to search with
1019             * @param start the lower bound of the range of message boards categories to return
1020             * @param end the upper bound of the range of message boards categories to return (not inclusive)
1021             * @return the range of matching message boards categories
1022             * @throws SystemException if a system exception occurred
1023             */
1024            public List<MBCategory> findByGroupId(long groupId, int start, int end)
1025                    throws SystemException {
1026                    return findByGroupId(groupId, start, end, null);
1027            }
1028    
1029            /**
1030             * Finds an ordered range of all the message boards categories where groupId = &#63;.
1031             *
1032             * <p>
1033             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1034             * </p>
1035             *
1036             * @param groupId the group id to search with
1037             * @param start the lower bound of the range of message boards categories to return
1038             * @param end the upper bound of the range of message boards categories to return (not inclusive)
1039             * @param orderByComparator the comparator to order the results by
1040             * @return the ordered range of matching message boards categories
1041             * @throws SystemException if a system exception occurred
1042             */
1043            public List<MBCategory> findByGroupId(long groupId, int start, int end,
1044                    OrderByComparator orderByComparator) throws SystemException {
1045                    Object[] finderArgs = new Object[] {
1046                                    groupId,
1047                                    
1048                                    String.valueOf(start), String.valueOf(end),
1049                                    String.valueOf(orderByComparator)
1050                            };
1051    
1052                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_GROUPID,
1053                                    finderArgs, this);
1054    
1055                    if (list == null) {
1056                            StringBundler query = null;
1057    
1058                            if (orderByComparator != null) {
1059                                    query = new StringBundler(3 +
1060                                                    (orderByComparator.getOrderByFields().length * 3));
1061                            }
1062                            else {
1063                                    query = new StringBundler(3);
1064                            }
1065    
1066                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1067    
1068                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1069    
1070                            if (orderByComparator != null) {
1071                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1072                                            orderByComparator);
1073                            }
1074    
1075                            else {
1076                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1077                            }
1078    
1079                            String sql = query.toString();
1080    
1081                            Session session = null;
1082    
1083                            try {
1084                                    session = openSession();
1085    
1086                                    Query q = session.createQuery(sql);
1087    
1088                                    QueryPos qPos = QueryPos.getInstance(q);
1089    
1090                                    qPos.add(groupId);
1091    
1092                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1093                                                    end);
1094                            }
1095                            catch (Exception e) {
1096                                    throw processException(e);
1097                            }
1098                            finally {
1099                                    if (list == null) {
1100                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_GROUPID,
1101                                                    finderArgs);
1102                                    }
1103                                    else {
1104                                            cacheResult(list);
1105    
1106                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_GROUPID,
1107                                                    finderArgs, list);
1108                                    }
1109    
1110                                    closeSession(session);
1111                            }
1112                    }
1113    
1114                    return list;
1115            }
1116    
1117            /**
1118             * Finds the first message boards category in the ordered set where groupId = &#63;.
1119             *
1120             * <p>
1121             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1122             * </p>
1123             *
1124             * @param groupId the group id to search with
1125             * @param orderByComparator the comparator to order the set by
1126             * @return the first matching message boards category
1127             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1128             * @throws SystemException if a system exception occurred
1129             */
1130            public MBCategory findByGroupId_First(long groupId,
1131                    OrderByComparator orderByComparator)
1132                    throws NoSuchCategoryException, SystemException {
1133                    List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1134    
1135                    if (list.isEmpty()) {
1136                            StringBundler msg = new StringBundler(4);
1137    
1138                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1139    
1140                            msg.append("groupId=");
1141                            msg.append(groupId);
1142    
1143                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1144    
1145                            throw new NoSuchCategoryException(msg.toString());
1146                    }
1147                    else {
1148                            return list.get(0);
1149                    }
1150            }
1151    
1152            /**
1153             * Finds the last message boards category in the ordered set where groupId = &#63;.
1154             *
1155             * <p>
1156             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1157             * </p>
1158             *
1159             * @param groupId the group id to search with
1160             * @param orderByComparator the comparator to order the set by
1161             * @return the last matching message boards category
1162             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1163             * @throws SystemException if a system exception occurred
1164             */
1165            public MBCategory findByGroupId_Last(long groupId,
1166                    OrderByComparator orderByComparator)
1167                    throws NoSuchCategoryException, SystemException {
1168                    int count = countByGroupId(groupId);
1169    
1170                    List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1171                                    orderByComparator);
1172    
1173                    if (list.isEmpty()) {
1174                            StringBundler msg = new StringBundler(4);
1175    
1176                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1177    
1178                            msg.append("groupId=");
1179                            msg.append(groupId);
1180    
1181                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1182    
1183                            throw new NoSuchCategoryException(msg.toString());
1184                    }
1185                    else {
1186                            return list.get(0);
1187                    }
1188            }
1189    
1190            /**
1191             * Finds the message boards categories before and after the current message boards category in the ordered set where groupId = &#63;.
1192             *
1193             * <p>
1194             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1195             * </p>
1196             *
1197             * @param categoryId the primary key of the current message boards category
1198             * @param groupId the group id to search with
1199             * @param orderByComparator the comparator to order the set by
1200             * @return the previous, current, and next message boards category
1201             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
1202             * @throws SystemException if a system exception occurred
1203             */
1204            public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1205                    long groupId, OrderByComparator orderByComparator)
1206                    throws NoSuchCategoryException, SystemException {
1207                    MBCategory mbCategory = findByPrimaryKey(categoryId);
1208    
1209                    Session session = null;
1210    
1211                    try {
1212                            session = openSession();
1213    
1214                            MBCategory[] array = new MBCategoryImpl[3];
1215    
1216                            array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1217                                            orderByComparator, true);
1218    
1219                            array[1] = mbCategory;
1220    
1221                            array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1222                                            orderByComparator, false);
1223    
1224                            return array;
1225                    }
1226                    catch (Exception e) {
1227                            throw processException(e);
1228                    }
1229                    finally {
1230                            closeSession(session);
1231                    }
1232            }
1233    
1234            protected MBCategory getByGroupId_PrevAndNext(Session session,
1235                    MBCategory mbCategory, long groupId,
1236                    OrderByComparator orderByComparator, boolean previous) {
1237                    StringBundler query = null;
1238    
1239                    if (orderByComparator != null) {
1240                            query = new StringBundler(6 +
1241                                            (orderByComparator.getOrderByFields().length * 6));
1242                    }
1243                    else {
1244                            query = new StringBundler(3);
1245                    }
1246    
1247                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1248    
1249                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1250    
1251                    if (orderByComparator != null) {
1252                            String[] orderByFields = orderByComparator.getOrderByFields();
1253    
1254                            if (orderByFields.length > 0) {
1255                                    query.append(WHERE_AND);
1256                            }
1257    
1258                            for (int i = 0; i < orderByFields.length; i++) {
1259                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1260                                    query.append(orderByFields[i]);
1261    
1262                                    if ((i + 1) < orderByFields.length) {
1263                                            if (orderByComparator.isAscending() ^ previous) {
1264                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1265                                            }
1266                                            else {
1267                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1268                                            }
1269                                    }
1270                                    else {
1271                                            if (orderByComparator.isAscending() ^ previous) {
1272                                                    query.append(WHERE_GREATER_THAN);
1273                                            }
1274                                            else {
1275                                                    query.append(WHERE_LESSER_THAN);
1276                                            }
1277                                    }
1278                            }
1279    
1280                            query.append(ORDER_BY_CLAUSE);
1281    
1282                            for (int i = 0; i < orderByFields.length; i++) {
1283                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1284                                    query.append(orderByFields[i]);
1285    
1286                                    if ((i + 1) < orderByFields.length) {
1287                                            if (orderByComparator.isAscending() ^ previous) {
1288                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1289                                            }
1290                                            else {
1291                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1292                                            }
1293                                    }
1294                                    else {
1295                                            if (orderByComparator.isAscending() ^ previous) {
1296                                                    query.append(ORDER_BY_ASC);
1297                                            }
1298                                            else {
1299                                                    query.append(ORDER_BY_DESC);
1300                                            }
1301                                    }
1302                            }
1303                    }
1304    
1305                    else {
1306                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1307                    }
1308    
1309                    String sql = query.toString();
1310    
1311                    Query q = session.createQuery(sql);
1312    
1313                    q.setFirstResult(0);
1314                    q.setMaxResults(2);
1315    
1316                    QueryPos qPos = QueryPos.getInstance(q);
1317    
1318                    qPos.add(groupId);
1319    
1320                    if (orderByComparator != null) {
1321                            Object[] values = orderByComparator.getOrderByValues(mbCategory);
1322    
1323                            for (Object value : values) {
1324                                    qPos.add(value);
1325                            }
1326                    }
1327    
1328                    List<MBCategory> list = q.list();
1329    
1330                    if (list.size() == 2) {
1331                            return list.get(1);
1332                    }
1333                    else {
1334                            return null;
1335                    }
1336            }
1337    
1338            /**
1339             * Filters by the user's permissions and finds all the message boards categories where groupId = &#63;.
1340             *
1341             * @param groupId the group id to search with
1342             * @return the matching message boards categories that the user has permission to view
1343             * @throws SystemException if a system exception occurred
1344             */
1345            public List<MBCategory> filterFindByGroupId(long groupId)
1346                    throws SystemException {
1347                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1348                            QueryUtil.ALL_POS, null);
1349            }
1350    
1351            /**
1352             * Filters by the user's permissions and finds a range of all the message boards categories where groupId = &#63;.
1353             *
1354             * <p>
1355             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1356             * </p>
1357             *
1358             * @param groupId the group id to search with
1359             * @param start the lower bound of the range of message boards categories to return
1360             * @param end the upper bound of the range of message boards categories to return (not inclusive)
1361             * @return the range of matching message boards categories that the user has permission to view
1362             * @throws SystemException if a system exception occurred
1363             */
1364            public List<MBCategory> filterFindByGroupId(long groupId, int start, int end)
1365                    throws SystemException {
1366                    return filterFindByGroupId(groupId, start, end, null);
1367            }
1368    
1369            /**
1370             * Filters by the user's permissions and finds an ordered range of all the message boards categories where groupId = &#63;.
1371             *
1372             * <p>
1373             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1374             * </p>
1375             *
1376             * @param groupId the group id to search with
1377             * @param start the lower bound of the range of message boards categories to return
1378             * @param end the upper bound of the range of message boards categories to return (not inclusive)
1379             * @param orderByComparator the comparator to order the results by
1380             * @return the ordered range of matching message boards categories that the user has permission to view
1381             * @throws SystemException if a system exception occurred
1382             */
1383            public List<MBCategory> filterFindByGroupId(long groupId, int start,
1384                    int end, OrderByComparator orderByComparator) throws SystemException {
1385                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1386                            return findByGroupId(groupId, start, end, orderByComparator);
1387                    }
1388    
1389                    StringBundler query = null;
1390    
1391                    if (orderByComparator != null) {
1392                            query = new StringBundler(3 +
1393                                            (orderByComparator.getOrderByFields().length * 3));
1394                    }
1395                    else {
1396                            query = new StringBundler(3);
1397                    }
1398    
1399                    if (getDB().isSupportsInlineDistinct()) {
1400                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
1401                    }
1402                    else {
1403                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
1404                    }
1405    
1406                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1407    
1408                    if (!getDB().isSupportsInlineDistinct()) {
1409                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
1410                    }
1411    
1412                    if (orderByComparator != null) {
1413                            if (getDB().isSupportsInlineDistinct()) {
1414                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1415                                            orderByComparator);
1416                            }
1417                            else {
1418                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1419                                            orderByComparator);
1420                            }
1421                    }
1422    
1423                    else {
1424                            if (getDB().isSupportsInlineDistinct()) {
1425                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1426                            }
1427                            else {
1428                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
1429                            }
1430                    }
1431    
1432                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1433                                    MBCategory.class.getName(), _FILTER_COLUMN_PK,
1434                                    _FILTER_COLUMN_USERID, groupId);
1435    
1436                    Session session = null;
1437    
1438                    try {
1439                            session = openSession();
1440    
1441                            SQLQuery q = session.createSQLQuery(sql);
1442    
1443                            if (getDB().isSupportsInlineDistinct()) {
1444                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
1445                            }
1446                            else {
1447                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
1448                            }
1449    
1450                            QueryPos qPos = QueryPos.getInstance(q);
1451    
1452                            qPos.add(groupId);
1453    
1454                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
1455                    }
1456                    catch (Exception e) {
1457                            throw processException(e);
1458                    }
1459                    finally {
1460                            closeSession(session);
1461                    }
1462            }
1463    
1464            /**
1465             * Finds all the message boards categories where companyId = &#63;.
1466             *
1467             * @param companyId the company id to search with
1468             * @return the matching message boards categories
1469             * @throws SystemException if a system exception occurred
1470             */
1471            public List<MBCategory> findByCompanyId(long companyId)
1472                    throws SystemException {
1473                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1474                            null);
1475            }
1476    
1477            /**
1478             * Finds a range of all the message boards categories where companyId = &#63;.
1479             *
1480             * <p>
1481             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1482             * </p>
1483             *
1484             * @param companyId the company id to search with
1485             * @param start the lower bound of the range of message boards categories to return
1486             * @param end the upper bound of the range of message boards categories to return (not inclusive)
1487             * @return the range of matching message boards categories
1488             * @throws SystemException if a system exception occurred
1489             */
1490            public List<MBCategory> findByCompanyId(long companyId, int start, int end)
1491                    throws SystemException {
1492                    return findByCompanyId(companyId, start, end, null);
1493            }
1494    
1495            /**
1496             * Finds an ordered range of all the message boards categories where companyId = &#63;.
1497             *
1498             * <p>
1499             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1500             * </p>
1501             *
1502             * @param companyId the company id to search with
1503             * @param start the lower bound of the range of message boards categories to return
1504             * @param end the upper bound of the range of message boards categories to return (not inclusive)
1505             * @param orderByComparator the comparator to order the results by
1506             * @return the ordered range of matching message boards categories
1507             * @throws SystemException if a system exception occurred
1508             */
1509            public List<MBCategory> findByCompanyId(long companyId, int start, int end,
1510                    OrderByComparator orderByComparator) throws SystemException {
1511                    Object[] finderArgs = new Object[] {
1512                                    companyId,
1513                                    
1514                                    String.valueOf(start), String.valueOf(end),
1515                                    String.valueOf(orderByComparator)
1516                            };
1517    
1518                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_COMPANYID,
1519                                    finderArgs, this);
1520    
1521                    if (list == null) {
1522                            StringBundler query = null;
1523    
1524                            if (orderByComparator != null) {
1525                                    query = new StringBundler(3 +
1526                                                    (orderByComparator.getOrderByFields().length * 3));
1527                            }
1528                            else {
1529                                    query = new StringBundler(3);
1530                            }
1531    
1532                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1533    
1534                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1535    
1536                            if (orderByComparator != null) {
1537                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1538                                            orderByComparator);
1539                            }
1540    
1541                            else {
1542                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1543                            }
1544    
1545                            String sql = query.toString();
1546    
1547                            Session session = null;
1548    
1549                            try {
1550                                    session = openSession();
1551    
1552                                    Query q = session.createQuery(sql);
1553    
1554                                    QueryPos qPos = QueryPos.getInstance(q);
1555    
1556                                    qPos.add(companyId);
1557    
1558                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1559                                                    end);
1560                            }
1561                            catch (Exception e) {
1562                                    throw processException(e);
1563                            }
1564                            finally {
1565                                    if (list == null) {
1566                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_COMPANYID,
1567                                                    finderArgs);
1568                                    }
1569                                    else {
1570                                            cacheResult(list);
1571    
1572                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_COMPANYID,
1573                                                    finderArgs, list);
1574                                    }
1575    
1576                                    closeSession(session);
1577                            }
1578                    }
1579    
1580                    return list;
1581            }
1582    
1583            /**
1584             * Finds the first message boards category in the ordered set where companyId = &#63;.
1585             *
1586             * <p>
1587             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1588             * </p>
1589             *
1590             * @param companyId the company id to search with
1591             * @param orderByComparator the comparator to order the set by
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 findByCompanyId_First(long companyId,
1597                    OrderByComparator orderByComparator)
1598                    throws NoSuchCategoryException, SystemException {
1599                    List<MBCategory> list = findByCompanyId(companyId, 0, 1,
1600                                    orderByComparator);
1601    
1602                    if (list.isEmpty()) {
1603                            StringBundler msg = new StringBundler(4);
1604    
1605                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1606    
1607                            msg.append("companyId=");
1608                            msg.append(companyId);
1609    
1610                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1611    
1612                            throw new NoSuchCategoryException(msg.toString());
1613                    }
1614                    else {
1615                            return list.get(0);
1616                    }
1617            }
1618    
1619            /**
1620             * Finds the last message boards category in the ordered set where companyId = &#63;.
1621             *
1622             * <p>
1623             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1624             * </p>
1625             *
1626             * @param companyId the company id to search with
1627             * @param orderByComparator the comparator to order the set by
1628             * @return the last matching message boards category
1629             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1630             * @throws SystemException if a system exception occurred
1631             */
1632            public MBCategory findByCompanyId_Last(long companyId,
1633                    OrderByComparator orderByComparator)
1634                    throws NoSuchCategoryException, SystemException {
1635                    int count = countByCompanyId(companyId);
1636    
1637                    List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
1638                                    orderByComparator);
1639    
1640                    if (list.isEmpty()) {
1641                            StringBundler msg = new StringBundler(4);
1642    
1643                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1644    
1645                            msg.append("companyId=");
1646                            msg.append(companyId);
1647    
1648                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1649    
1650                            throw new NoSuchCategoryException(msg.toString());
1651                    }
1652                    else {
1653                            return list.get(0);
1654                    }
1655            }
1656    
1657            /**
1658             * Finds the message boards categories before and after the current message boards category in the ordered set where companyId = &#63;.
1659             *
1660             * <p>
1661             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1662             * </p>
1663             *
1664             * @param categoryId the primary key of the current message boards category
1665             * @param companyId the company id to search with
1666             * @param orderByComparator the comparator to order the set by
1667             * @return the previous, current, and next message boards category
1668             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
1669             * @throws SystemException if a system exception occurred
1670             */
1671            public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
1672                    long companyId, OrderByComparator orderByComparator)
1673                    throws NoSuchCategoryException, SystemException {
1674                    MBCategory mbCategory = findByPrimaryKey(categoryId);
1675    
1676                    Session session = null;
1677    
1678                    try {
1679                            session = openSession();
1680    
1681                            MBCategory[] array = new MBCategoryImpl[3];
1682    
1683                            array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
1684                                            companyId, orderByComparator, true);
1685    
1686                            array[1] = mbCategory;
1687    
1688                            array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
1689                                            companyId, orderByComparator, false);
1690    
1691                            return array;
1692                    }
1693                    catch (Exception e) {
1694                            throw processException(e);
1695                    }
1696                    finally {
1697                            closeSession(session);
1698                    }
1699            }
1700    
1701            protected MBCategory getByCompanyId_PrevAndNext(Session session,
1702                    MBCategory mbCategory, long companyId,
1703                    OrderByComparator orderByComparator, boolean previous) {
1704                    StringBundler query = null;
1705    
1706                    if (orderByComparator != null) {
1707                            query = new StringBundler(6 +
1708                                            (orderByComparator.getOrderByFields().length * 6));
1709                    }
1710                    else {
1711                            query = new StringBundler(3);
1712                    }
1713    
1714                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1715    
1716                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
1717    
1718                    if (orderByComparator != null) {
1719                            String[] orderByFields = orderByComparator.getOrderByFields();
1720    
1721                            if (orderByFields.length > 0) {
1722                                    query.append(WHERE_AND);
1723                            }
1724    
1725                            for (int i = 0; i < orderByFields.length; i++) {
1726                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1727                                    query.append(orderByFields[i]);
1728    
1729                                    if ((i + 1) < orderByFields.length) {
1730                                            if (orderByComparator.isAscending() ^ previous) {
1731                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1732                                            }
1733                                            else {
1734                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1735                                            }
1736                                    }
1737                                    else {
1738                                            if (orderByComparator.isAscending() ^ previous) {
1739                                                    query.append(WHERE_GREATER_THAN);
1740                                            }
1741                                            else {
1742                                                    query.append(WHERE_LESSER_THAN);
1743                                            }
1744                                    }
1745                            }
1746    
1747                            query.append(ORDER_BY_CLAUSE);
1748    
1749                            for (int i = 0; i < orderByFields.length; i++) {
1750                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1751                                    query.append(orderByFields[i]);
1752    
1753                                    if ((i + 1) < orderByFields.length) {
1754                                            if (orderByComparator.isAscending() ^ previous) {
1755                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1756                                            }
1757                                            else {
1758                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1759                                            }
1760                                    }
1761                                    else {
1762                                            if (orderByComparator.isAscending() ^ previous) {
1763                                                    query.append(ORDER_BY_ASC);
1764                                            }
1765                                            else {
1766                                                    query.append(ORDER_BY_DESC);
1767                                            }
1768                                    }
1769                            }
1770                    }
1771    
1772                    else {
1773                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1774                    }
1775    
1776                    String sql = query.toString();
1777    
1778                    Query q = session.createQuery(sql);
1779    
1780                    q.setFirstResult(0);
1781                    q.setMaxResults(2);
1782    
1783                    QueryPos qPos = QueryPos.getInstance(q);
1784    
1785                    qPos.add(companyId);
1786    
1787                    if (orderByComparator != null) {
1788                            Object[] values = orderByComparator.getOrderByValues(mbCategory);
1789    
1790                            for (Object value : values) {
1791                                    qPos.add(value);
1792                            }
1793                    }
1794    
1795                    List<MBCategory> list = q.list();
1796    
1797                    if (list.size() == 2) {
1798                            return list.get(1);
1799                    }
1800                    else {
1801                            return null;
1802                    }
1803            }
1804    
1805            /**
1806             * Finds all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
1807             *
1808             * @param groupId the group id to search with
1809             * @param parentCategoryId the parent category id to search with
1810             * @return the matching message boards categories
1811             * @throws SystemException if a system exception occurred
1812             */
1813            public List<MBCategory> findByG_P(long groupId, long parentCategoryId)
1814                    throws SystemException {
1815                    return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
1816                            QueryUtil.ALL_POS, null);
1817            }
1818    
1819            /**
1820             * Finds a range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
1821             *
1822             * <p>
1823             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1824             * </p>
1825             *
1826             * @param groupId the group id to search with
1827             * @param parentCategoryId the parent category id to search with
1828             * @param start the lower bound of the range of message boards categories to return
1829             * @param end the upper bound of the range of message boards categories to return (not inclusive)
1830             * @return the range of matching message boards categories
1831             * @throws SystemException if a system exception occurred
1832             */
1833            public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
1834                    int start, int end) throws SystemException {
1835                    return findByG_P(groupId, parentCategoryId, start, end, null);
1836            }
1837    
1838            /**
1839             * Finds an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
1840             *
1841             * <p>
1842             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1843             * </p>
1844             *
1845             * @param groupId the group id to search with
1846             * @param parentCategoryId the parent category id to search with
1847             * @param start the lower bound of the range of message boards categories to return
1848             * @param end the upper bound of the range of message boards categories to return (not inclusive)
1849             * @param orderByComparator the comparator to order the results by
1850             * @return the ordered range of matching message boards categories
1851             * @throws SystemException if a system exception occurred
1852             */
1853            public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
1854                    int start, int end, OrderByComparator orderByComparator)
1855                    throws SystemException {
1856                    Object[] finderArgs = new Object[] {
1857                                    groupId, parentCategoryId,
1858                                    
1859                                    String.valueOf(start), String.valueOf(end),
1860                                    String.valueOf(orderByComparator)
1861                            };
1862    
1863                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
1864                                    finderArgs, this);
1865    
1866                    if (list == null) {
1867                            StringBundler query = null;
1868    
1869                            if (orderByComparator != null) {
1870                                    query = new StringBundler(4 +
1871                                                    (orderByComparator.getOrderByFields().length * 3));
1872                            }
1873                            else {
1874                                    query = new StringBundler(4);
1875                            }
1876    
1877                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1878    
1879                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
1880    
1881                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
1882    
1883                            if (orderByComparator != null) {
1884                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1885                                            orderByComparator);
1886                            }
1887    
1888                            else {
1889                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1890                            }
1891    
1892                            String sql = query.toString();
1893    
1894                            Session session = null;
1895    
1896                            try {
1897                                    session = openSession();
1898    
1899                                    Query q = session.createQuery(sql);
1900    
1901                                    QueryPos qPos = QueryPos.getInstance(q);
1902    
1903                                    qPos.add(groupId);
1904    
1905                                    qPos.add(parentCategoryId);
1906    
1907                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1908                                                    end);
1909                            }
1910                            catch (Exception e) {
1911                                    throw processException(e);
1912                            }
1913                            finally {
1914                                    if (list == null) {
1915                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_P,
1916                                                    finderArgs);
1917                                    }
1918                                    else {
1919                                            cacheResult(list);
1920    
1921                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P,
1922                                                    finderArgs, list);
1923                                    }
1924    
1925                                    closeSession(session);
1926                            }
1927                    }
1928    
1929                    return list;
1930            }
1931    
1932            /**
1933             * Finds the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1934             *
1935             * <p>
1936             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1937             * </p>
1938             *
1939             * @param groupId the group id to search with
1940             * @param parentCategoryId the parent category id to search with
1941             * @param orderByComparator the comparator to order the set by
1942             * @return the first matching message boards category
1943             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1944             * @throws SystemException if a system exception occurred
1945             */
1946            public MBCategory findByG_P_First(long groupId, long parentCategoryId,
1947                    OrderByComparator orderByComparator)
1948                    throws NoSuchCategoryException, SystemException {
1949                    List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
1950                                    orderByComparator);
1951    
1952                    if (list.isEmpty()) {
1953                            StringBundler msg = new StringBundler(6);
1954    
1955                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1956    
1957                            msg.append("groupId=");
1958                            msg.append(groupId);
1959    
1960                            msg.append(", parentCategoryId=");
1961                            msg.append(parentCategoryId);
1962    
1963                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1964    
1965                            throw new NoSuchCategoryException(msg.toString());
1966                    }
1967                    else {
1968                            return list.get(0);
1969                    }
1970            }
1971    
1972            /**
1973             * Finds the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
1974             *
1975             * <p>
1976             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
1977             * </p>
1978             *
1979             * @param groupId the group id to search with
1980             * @param parentCategoryId the parent category id to search with
1981             * @param orderByComparator the comparator to order the set by
1982             * @return the last matching message boards category
1983             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1984             * @throws SystemException if a system exception occurred
1985             */
1986            public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
1987                    OrderByComparator orderByComparator)
1988                    throws NoSuchCategoryException, SystemException {
1989                    int count = countByG_P(groupId, parentCategoryId);
1990    
1991                    List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
1992                                    count, orderByComparator);
1993    
1994                    if (list.isEmpty()) {
1995                            StringBundler msg = new StringBundler(6);
1996    
1997                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1998    
1999                            msg.append("groupId=");
2000                            msg.append(groupId);
2001    
2002                            msg.append(", parentCategoryId=");
2003                            msg.append(parentCategoryId);
2004    
2005                            msg.append(StringPool.CLOSE_CURLY_BRACE);
2006    
2007                            throw new NoSuchCategoryException(msg.toString());
2008                    }
2009                    else {
2010                            return list.get(0);
2011                    }
2012            }
2013    
2014            /**
2015             * Finds the message boards categories before and after the current message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
2016             *
2017             * <p>
2018             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2019             * </p>
2020             *
2021             * @param categoryId the primary key of the current message boards category
2022             * @param groupId the group id to search with
2023             * @param parentCategoryId the parent category id to search with
2024             * @param orderByComparator the comparator to order the set by
2025             * @return the previous, current, and next message boards category
2026             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
2027             * @throws SystemException if a system exception occurred
2028             */
2029            public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
2030                    long parentCategoryId, OrderByComparator orderByComparator)
2031                    throws NoSuchCategoryException, SystemException {
2032                    MBCategory mbCategory = findByPrimaryKey(categoryId);
2033    
2034                    Session session = null;
2035    
2036                    try {
2037                            session = openSession();
2038    
2039                            MBCategory[] array = new MBCategoryImpl[3];
2040    
2041                            array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
2042                                            parentCategoryId, orderByComparator, true);
2043    
2044                            array[1] = mbCategory;
2045    
2046                            array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
2047                                            parentCategoryId, orderByComparator, false);
2048    
2049                            return array;
2050                    }
2051                    catch (Exception e) {
2052                            throw processException(e);
2053                    }
2054                    finally {
2055                            closeSession(session);
2056                    }
2057            }
2058    
2059            protected MBCategory getByG_P_PrevAndNext(Session session,
2060                    MBCategory mbCategory, long groupId, long parentCategoryId,
2061                    OrderByComparator orderByComparator, boolean previous) {
2062                    StringBundler query = null;
2063    
2064                    if (orderByComparator != null) {
2065                            query = new StringBundler(6 +
2066                                            (orderByComparator.getOrderByFields().length * 6));
2067                    }
2068                    else {
2069                            query = new StringBundler(3);
2070                    }
2071    
2072                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2073    
2074                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2075    
2076                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2077    
2078                    if (orderByComparator != null) {
2079                            String[] orderByFields = orderByComparator.getOrderByFields();
2080    
2081                            if (orderByFields.length > 0) {
2082                                    query.append(WHERE_AND);
2083                            }
2084    
2085                            for (int i = 0; i < orderByFields.length; i++) {
2086                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2087                                    query.append(orderByFields[i]);
2088    
2089                                    if ((i + 1) < orderByFields.length) {
2090                                            if (orderByComparator.isAscending() ^ previous) {
2091                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2092                                            }
2093                                            else {
2094                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2095                                            }
2096                                    }
2097                                    else {
2098                                            if (orderByComparator.isAscending() ^ previous) {
2099                                                    query.append(WHERE_GREATER_THAN);
2100                                            }
2101                                            else {
2102                                                    query.append(WHERE_LESSER_THAN);
2103                                            }
2104                                    }
2105                            }
2106    
2107                            query.append(ORDER_BY_CLAUSE);
2108    
2109                            for (int i = 0; i < orderByFields.length; i++) {
2110                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2111                                    query.append(orderByFields[i]);
2112    
2113                                    if ((i + 1) < orderByFields.length) {
2114                                            if (orderByComparator.isAscending() ^ previous) {
2115                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2116                                            }
2117                                            else {
2118                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2119                                            }
2120                                    }
2121                                    else {
2122                                            if (orderByComparator.isAscending() ^ previous) {
2123                                                    query.append(ORDER_BY_ASC);
2124                                            }
2125                                            else {
2126                                                    query.append(ORDER_BY_DESC);
2127                                            }
2128                                    }
2129                            }
2130                    }
2131    
2132                    else {
2133                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2134                    }
2135    
2136                    String sql = query.toString();
2137    
2138                    Query q = session.createQuery(sql);
2139    
2140                    q.setFirstResult(0);
2141                    q.setMaxResults(2);
2142    
2143                    QueryPos qPos = QueryPos.getInstance(q);
2144    
2145                    qPos.add(groupId);
2146    
2147                    qPos.add(parentCategoryId);
2148    
2149                    if (orderByComparator != null) {
2150                            Object[] values = orderByComparator.getOrderByValues(mbCategory);
2151    
2152                            for (Object value : values) {
2153                                    qPos.add(value);
2154                            }
2155                    }
2156    
2157                    List<MBCategory> list = q.list();
2158    
2159                    if (list.size() == 2) {
2160                            return list.get(1);
2161                    }
2162                    else {
2163                            return null;
2164                    }
2165            }
2166    
2167            /**
2168             * Finds all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
2169             *
2170             * <p>
2171             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2172             * </p>
2173             *
2174             * @param groupId the group id to search with
2175             * @param parentCategoryIds the parent category ids to search with
2176             * @return the matching message boards categories
2177             * @throws SystemException if a system exception occurred
2178             */
2179            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds)
2180                    throws SystemException {
2181                    return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
2182                            QueryUtil.ALL_POS, null);
2183            }
2184    
2185            /**
2186             * Finds a range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
2187             *
2188             * <p>
2189             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2190             * </p>
2191             *
2192             * @param groupId the group id to search with
2193             * @param parentCategoryIds the parent category ids to search with
2194             * @param start the lower bound of the range of message boards categories to return
2195             * @param end the upper bound of the range of message boards categories to return (not inclusive)
2196             * @return the range of matching message boards categories
2197             * @throws SystemException if a system exception occurred
2198             */
2199            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
2200                    int start, int end) throws SystemException {
2201                    return findByG_P(groupId, parentCategoryIds, start, end, null);
2202            }
2203    
2204            /**
2205             * Finds an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
2206             *
2207             * <p>
2208             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2209             * </p>
2210             *
2211             * @param groupId the group id to search with
2212             * @param parentCategoryIds the parent category ids to search with
2213             * @param start the lower bound of the range of message boards categories to return
2214             * @param end the upper bound of the range of message boards categories to return (not inclusive)
2215             * @param orderByComparator the comparator to order the results by
2216             * @return the ordered range of matching message boards categories
2217             * @throws SystemException if a system exception occurred
2218             */
2219            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
2220                    int start, int end, OrderByComparator orderByComparator)
2221                    throws SystemException {
2222                    Object[] finderArgs = new Object[] {
2223                                    groupId, StringUtil.merge(parentCategoryIds),
2224                                    
2225                                    String.valueOf(start), String.valueOf(end),
2226                                    String.valueOf(orderByComparator)
2227                            };
2228    
2229                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_BY_G_P,
2230                                    finderArgs, this);
2231    
2232                    if (list == null) {
2233                            StringBundler query = new StringBundler();
2234    
2235                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2236    
2237                            boolean conjunctionable = false;
2238    
2239                            if (conjunctionable) {
2240                                    query.append(WHERE_AND);
2241                            }
2242    
2243                            query.append(_FINDER_COLUMN_G_P_GROUPID_5);
2244    
2245                            conjunctionable = true;
2246    
2247                            if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
2248                                    if (conjunctionable) {
2249                                            query.append(WHERE_AND);
2250                                    }
2251    
2252                                    query.append(StringPool.OPEN_PARENTHESIS);
2253    
2254                                    for (int i = 0; i < parentCategoryIds.length; i++) {
2255                                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
2256    
2257                                            if ((i + 1) < parentCategoryIds.length) {
2258                                                    query.append(WHERE_OR);
2259                                            }
2260                                    }
2261    
2262                                    query.append(StringPool.CLOSE_PARENTHESIS);
2263    
2264                                    conjunctionable = true;
2265                            }
2266    
2267                            if (orderByComparator != null) {
2268                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2269                                            orderByComparator);
2270                            }
2271    
2272                            else {
2273                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2274                            }
2275    
2276                            String sql = query.toString();
2277    
2278                            Session session = null;
2279    
2280                            try {
2281                                    session = openSession();
2282    
2283                                    Query q = session.createQuery(sql);
2284    
2285                                    QueryPos qPos = QueryPos.getInstance(q);
2286    
2287                                    qPos.add(groupId);
2288    
2289                                    if (parentCategoryIds != null) {
2290                                            qPos.add(parentCategoryIds);
2291                                    }
2292    
2293                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
2294                                                    end);
2295                            }
2296                            catch (Exception e) {
2297                                    throw processException(e);
2298                            }
2299                            finally {
2300                                    if (list == null) {
2301                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_BY_G_P,
2302                                                    finderArgs);
2303                                    }
2304                                    else {
2305                                            cacheResult(list);
2306    
2307                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_BY_G_P,
2308                                                    finderArgs, list);
2309                                    }
2310    
2311                                    closeSession(session);
2312                            }
2313                    }
2314    
2315                    return list;
2316            }
2317    
2318            /**
2319             * Filters by the user's permissions and finds all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2320             *
2321             * @param groupId the group id to search with
2322             * @param parentCategoryId the parent category id to search with
2323             * @return the matching message boards categories that the user has permission to view
2324             * @throws SystemException if a system exception occurred
2325             */
2326            public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId)
2327                    throws SystemException {
2328                    return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2329                            QueryUtil.ALL_POS, null);
2330            }
2331    
2332            /**
2333             * Filters by the user's permissions and finds a range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2334             *
2335             * <p>
2336             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2337             * </p>
2338             *
2339             * @param groupId the group id to search with
2340             * @param parentCategoryId the parent category id to search with
2341             * @param start the lower bound of the range of message boards categories to return
2342             * @param end the upper bound of the range of message boards categories to return (not inclusive)
2343             * @return the range of matching message boards categories that the user has permission to view
2344             * @throws SystemException if a system exception occurred
2345             */
2346            public List<MBCategory> filterFindByG_P(long groupId,
2347                    long parentCategoryId, int start, int end) throws SystemException {
2348                    return filterFindByG_P(groupId, parentCategoryId, start, end, null);
2349            }
2350    
2351            /**
2352             * Filters by the user's permissions and finds an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2353             *
2354             * <p>
2355             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2356             * </p>
2357             *
2358             * @param groupId the group id to search with
2359             * @param parentCategoryId the parent category id to search with
2360             * @param start the lower bound of the range of message boards categories to return
2361             * @param end the upper bound of the range of message boards categories to return (not inclusive)
2362             * @param orderByComparator the comparator to order the results by
2363             * @return the ordered range of matching message boards categories that the user has permission to view
2364             * @throws SystemException if a system exception occurred
2365             */
2366            public List<MBCategory> filterFindByG_P(long groupId,
2367                    long parentCategoryId, int start, int end,
2368                    OrderByComparator orderByComparator) throws SystemException {
2369                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2370                            return findByG_P(groupId, parentCategoryId, start, end,
2371                                    orderByComparator);
2372                    }
2373    
2374                    StringBundler query = null;
2375    
2376                    if (orderByComparator != null) {
2377                            query = new StringBundler(4 +
2378                                            (orderByComparator.getOrderByFields().length * 3));
2379                    }
2380                    else {
2381                            query = new StringBundler(4);
2382                    }
2383    
2384                    if (getDB().isSupportsInlineDistinct()) {
2385                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2386                    }
2387                    else {
2388                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2389                    }
2390    
2391                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2392    
2393                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2394    
2395                    if (!getDB().isSupportsInlineDistinct()) {
2396                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2397                    }
2398    
2399                    if (orderByComparator != null) {
2400                            if (getDB().isSupportsInlineDistinct()) {
2401                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2402                                            orderByComparator);
2403                            }
2404                            else {
2405                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2406                                            orderByComparator);
2407                            }
2408                    }
2409    
2410                    else {
2411                            if (getDB().isSupportsInlineDistinct()) {
2412                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2413                            }
2414                            else {
2415                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2416                            }
2417                    }
2418    
2419                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2420                                    MBCategory.class.getName(), _FILTER_COLUMN_PK,
2421                                    _FILTER_COLUMN_USERID, groupId);
2422    
2423                    Session session = null;
2424    
2425                    try {
2426                            session = openSession();
2427    
2428                            SQLQuery q = session.createSQLQuery(sql);
2429    
2430                            if (getDB().isSupportsInlineDistinct()) {
2431                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2432                            }
2433                            else {
2434                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2435                            }
2436    
2437                            QueryPos qPos = QueryPos.getInstance(q);
2438    
2439                            qPos.add(groupId);
2440    
2441                            qPos.add(parentCategoryId);
2442    
2443                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
2444                    }
2445                    catch (Exception e) {
2446                            throw processException(e);
2447                    }
2448                    finally {
2449                            closeSession(session);
2450                    }
2451            }
2452    
2453            /**
2454             * Filters by the user's permissions and finds all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
2455             *
2456             * <p>
2457             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2458             * </p>
2459             *
2460             * @param groupId the group id to search with
2461             * @param parentCategoryIds the parent category ids to search with
2462             * @return the matching message boards categories that the user has permission to view
2463             * @throws SystemException if a system exception occurred
2464             */
2465            public List<MBCategory> filterFindByG_P(long groupId,
2466                    long[] parentCategoryIds) throws SystemException {
2467                    return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
2468                            QueryUtil.ALL_POS, null);
2469            }
2470    
2471            /**
2472             * Filters by the user's permissions and finds a range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
2473             *
2474             * <p>
2475             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2476             * </p>
2477             *
2478             * @param groupId the group id to search with
2479             * @param parentCategoryIds the parent category ids to search with
2480             * @param start the lower bound of the range of message boards categories to return
2481             * @param end the upper bound of the range of message boards categories to return (not inclusive)
2482             * @return the range of matching message boards categories that the user has permission to view
2483             * @throws SystemException if a system exception occurred
2484             */
2485            public List<MBCategory> filterFindByG_P(long groupId,
2486                    long[] parentCategoryIds, int start, int end) throws SystemException {
2487                    return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
2488            }
2489    
2490            /**
2491             * Filters by the user's permissions and finds an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
2492             *
2493             * <p>
2494             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2495             * </p>
2496             *
2497             * @param groupId the group id to search with
2498             * @param parentCategoryIds the parent category ids to search with
2499             * @param start the lower bound of the range of message boards categories to return
2500             * @param end the upper bound of the range of message boards categories to return (not inclusive)
2501             * @param orderByComparator the comparator to order the results by
2502             * @return the ordered range of matching message boards categories that the user has permission to view
2503             * @throws SystemException if a system exception occurred
2504             */
2505            public List<MBCategory> filterFindByG_P(long groupId,
2506                    long[] parentCategoryIds, int start, int end,
2507                    OrderByComparator orderByComparator) throws SystemException {
2508                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2509                            return findByG_P(groupId, parentCategoryIds, start, end,
2510                                    orderByComparator);
2511                    }
2512    
2513                    StringBundler query = new StringBundler();
2514    
2515                    if (getDB().isSupportsInlineDistinct()) {
2516                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2517                    }
2518                    else {
2519                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2520                    }
2521    
2522                    boolean conjunctionable = false;
2523    
2524                    if (conjunctionable) {
2525                            query.append(WHERE_AND);
2526                    }
2527    
2528                    query.append(_FINDER_COLUMN_G_P_GROUPID_5);
2529    
2530                    conjunctionable = true;
2531    
2532                    if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
2533                            if (conjunctionable) {
2534                                    query.append(WHERE_AND);
2535                            }
2536    
2537                            query.append(StringPool.OPEN_PARENTHESIS);
2538    
2539                            for (int i = 0; i < parentCategoryIds.length; i++) {
2540                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
2541    
2542                                    if ((i + 1) < parentCategoryIds.length) {
2543                                            query.append(WHERE_OR);
2544                                    }
2545                            }
2546    
2547                            query.append(StringPool.CLOSE_PARENTHESIS);
2548    
2549                            conjunctionable = true;
2550                    }
2551    
2552                    if (!getDB().isSupportsInlineDistinct()) {
2553                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2554                    }
2555    
2556                    if (orderByComparator != null) {
2557                            if (getDB().isSupportsInlineDistinct()) {
2558                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2559                                            orderByComparator);
2560                            }
2561                            else {
2562                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2563                                            orderByComparator);
2564                            }
2565                    }
2566    
2567                    else {
2568                            if (getDB().isSupportsInlineDistinct()) {
2569                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2570                            }
2571                            else {
2572                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2573                            }
2574                    }
2575    
2576                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2577                                    MBCategory.class.getName(), _FILTER_COLUMN_PK,
2578                                    _FILTER_COLUMN_USERID, groupId);
2579    
2580                    Session session = null;
2581    
2582                    try {
2583                            session = openSession();
2584    
2585                            SQLQuery q = session.createSQLQuery(sql);
2586    
2587                            if (getDB().isSupportsInlineDistinct()) {
2588                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2589                            }
2590                            else {
2591                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2592                            }
2593    
2594                            QueryPos qPos = QueryPos.getInstance(q);
2595    
2596                            qPos.add(groupId);
2597    
2598                            if (parentCategoryIds != null) {
2599                                    qPos.add(parentCategoryIds);
2600                            }
2601    
2602                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
2603                    }
2604                    catch (Exception e) {
2605                            throw processException(e);
2606                    }
2607                    finally {
2608                            closeSession(session);
2609                    }
2610            }
2611    
2612            /**
2613             * Finds all the message boards categories.
2614             *
2615             * @return the message boards categories
2616             * @throws SystemException if a system exception occurred
2617             */
2618            public List<MBCategory> findAll() throws SystemException {
2619                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2620            }
2621    
2622            /**
2623             * Finds a range of all the message boards categories.
2624             *
2625             * <p>
2626             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2627             * </p>
2628             *
2629             * @param start the lower bound of the range of message boards categories to return
2630             * @param end the upper bound of the range of message boards categories to return (not inclusive)
2631             * @return the range of message boards categories
2632             * @throws SystemException if a system exception occurred
2633             */
2634            public List<MBCategory> findAll(int start, int end)
2635                    throws SystemException {
2636                    return findAll(start, end, null);
2637            }
2638    
2639            /**
2640             * Finds an ordered range of all the message boards categories.
2641             *
2642             * <p>
2643             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result 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.
2644             * </p>
2645             *
2646             * @param start the lower bound of the range of message boards categories to return
2647             * @param end the upper bound of the range of message boards categories to return (not inclusive)
2648             * @param orderByComparator the comparator to order the results by
2649             * @return the ordered range of message boards categories
2650             * @throws SystemException if a system exception occurred
2651             */
2652            public List<MBCategory> findAll(int start, int end,
2653                    OrderByComparator orderByComparator) throws SystemException {
2654                    Object[] finderArgs = new Object[] {
2655                                    String.valueOf(start), String.valueOf(end),
2656                                    String.valueOf(orderByComparator)
2657                            };
2658    
2659                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(FINDER_PATH_FIND_ALL,
2660                                    finderArgs, this);
2661    
2662                    if (list == null) {
2663                            StringBundler query = null;
2664                            String sql = null;
2665    
2666                            if (orderByComparator != null) {
2667                                    query = new StringBundler(2 +
2668                                                    (orderByComparator.getOrderByFields().length * 3));
2669    
2670                                    query.append(_SQL_SELECT_MBCATEGORY);
2671    
2672                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2673                                            orderByComparator);
2674    
2675                                    sql = query.toString();
2676                            }
2677                            else {
2678                                    sql = _SQL_SELECT_MBCATEGORY.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
2679                            }
2680    
2681                            Session session = null;
2682    
2683                            try {
2684                                    session = openSession();
2685    
2686                                    Query q = session.createQuery(sql);
2687    
2688                                    if (orderByComparator == null) {
2689                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2690                                                            start, end, false);
2691    
2692                                            Collections.sort(list);
2693                                    }
2694                                    else {
2695                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
2696                                                            start, end);
2697                                    }
2698                            }
2699                            catch (Exception e) {
2700                                    throw processException(e);
2701                            }
2702                            finally {
2703                                    if (list == null) {
2704                                            FinderCacheUtil.removeResult(FINDER_PATH_FIND_ALL,
2705                                                    finderArgs);
2706                                    }
2707                                    else {
2708                                            cacheResult(list);
2709    
2710                                            FinderCacheUtil.putResult(FINDER_PATH_FIND_ALL, finderArgs,
2711                                                    list);
2712                                    }
2713    
2714                                    closeSession(session);
2715                            }
2716                    }
2717    
2718                    return list;
2719            }
2720    
2721            /**
2722             * Removes all the message boards categories where uuid = &#63; from the database.
2723             *
2724             * @param uuid the uuid to search with
2725             * @throws SystemException if a system exception occurred
2726             */
2727            public void removeByUuid(String uuid) throws SystemException {
2728                    for (MBCategory mbCategory : findByUuid(uuid)) {
2729                            remove(mbCategory);
2730                    }
2731            }
2732    
2733            /**
2734             * Removes the message boards category where uuid = &#63; and groupId = &#63; from the database.
2735             *
2736             * @param uuid the uuid to search with
2737             * @param groupId the group id to search with
2738             * @throws SystemException if a system exception occurred
2739             */
2740            public void removeByUUID_G(String uuid, long groupId)
2741                    throws NoSuchCategoryException, SystemException {
2742                    MBCategory mbCategory = findByUUID_G(uuid, groupId);
2743    
2744                    remove(mbCategory);
2745            }
2746    
2747            /**
2748             * Removes all the message boards categories where groupId = &#63; from the database.
2749             *
2750             * @param groupId the group id to search with
2751             * @throws SystemException if a system exception occurred
2752             */
2753            public void removeByGroupId(long groupId) throws SystemException {
2754                    for (MBCategory mbCategory : findByGroupId(groupId)) {
2755                            remove(mbCategory);
2756                    }
2757            }
2758    
2759            /**
2760             * Removes all the message boards categories where companyId = &#63; from the database.
2761             *
2762             * @param companyId the company id to search with
2763             * @throws SystemException if a system exception occurred
2764             */
2765            public void removeByCompanyId(long companyId) throws SystemException {
2766                    for (MBCategory mbCategory : findByCompanyId(companyId)) {
2767                            remove(mbCategory);
2768                    }
2769            }
2770    
2771            /**
2772             * Removes all the message boards categories where groupId = &#63; and parentCategoryId = &#63; from the database.
2773             *
2774             * @param groupId the group id to search with
2775             * @param parentCategoryId the parent category id to search with
2776             * @throws SystemException if a system exception occurred
2777             */
2778            public void removeByG_P(long groupId, long parentCategoryId)
2779                    throws SystemException {
2780                    for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId)) {
2781                            remove(mbCategory);
2782                    }
2783            }
2784    
2785            /**
2786             * Removes all the message boards categories from the database.
2787             *
2788             * @throws SystemException if a system exception occurred
2789             */
2790            public void removeAll() throws SystemException {
2791                    for (MBCategory mbCategory : findAll()) {
2792                            remove(mbCategory);
2793                    }
2794            }
2795    
2796            /**
2797             * Counts all the message boards categories where uuid = &#63;.
2798             *
2799             * @param uuid the uuid to search with
2800             * @return the number of matching message boards categories
2801             * @throws SystemException if a system exception occurred
2802             */
2803            public int countByUuid(String uuid) throws SystemException {
2804                    Object[] finderArgs = new Object[] { uuid };
2805    
2806                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
2807                                    finderArgs, this);
2808    
2809                    if (count == null) {
2810                            StringBundler query = new StringBundler(2);
2811    
2812                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2813    
2814                            if (uuid == null) {
2815                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
2816                            }
2817                            else {
2818                                    if (uuid.equals(StringPool.BLANK)) {
2819                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
2820                                    }
2821                                    else {
2822                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
2823                                    }
2824                            }
2825    
2826                            String sql = query.toString();
2827    
2828                            Session session = null;
2829    
2830                            try {
2831                                    session = openSession();
2832    
2833                                    Query q = session.createQuery(sql);
2834    
2835                                    QueryPos qPos = QueryPos.getInstance(q);
2836    
2837                                    if (uuid != null) {
2838                                            qPos.add(uuid);
2839                                    }
2840    
2841                                    count = (Long)q.uniqueResult();
2842                            }
2843                            catch (Exception e) {
2844                                    throw processException(e);
2845                            }
2846                            finally {
2847                                    if (count == null) {
2848                                            count = Long.valueOf(0);
2849                                    }
2850    
2851                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
2852                                            finderArgs, count);
2853    
2854                                    closeSession(session);
2855                            }
2856                    }
2857    
2858                    return count.intValue();
2859            }
2860    
2861            /**
2862             * Counts all the message boards categories where uuid = &#63; and groupId = &#63;.
2863             *
2864             * @param uuid the uuid to search with
2865             * @param groupId the group id to search with
2866             * @return the number of matching message boards categories
2867             * @throws SystemException if a system exception occurred
2868             */
2869            public int countByUUID_G(String uuid, long groupId)
2870                    throws SystemException {
2871                    Object[] finderArgs = new Object[] { uuid, groupId };
2872    
2873                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
2874                                    finderArgs, this);
2875    
2876                    if (count == null) {
2877                            StringBundler query = new StringBundler(3);
2878    
2879                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2880    
2881                            if (uuid == null) {
2882                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
2883                            }
2884                            else {
2885                                    if (uuid.equals(StringPool.BLANK)) {
2886                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
2887                                    }
2888                                    else {
2889                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
2890                                    }
2891                            }
2892    
2893                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
2894    
2895                            String sql = query.toString();
2896    
2897                            Session session = null;
2898    
2899                            try {
2900                                    session = openSession();
2901    
2902                                    Query q = session.createQuery(sql);
2903    
2904                                    QueryPos qPos = QueryPos.getInstance(q);
2905    
2906                                    if (uuid != null) {
2907                                            qPos.add(uuid);
2908                                    }
2909    
2910                                    qPos.add(groupId);
2911    
2912                                    count = (Long)q.uniqueResult();
2913                            }
2914                            catch (Exception e) {
2915                                    throw processException(e);
2916                            }
2917                            finally {
2918                                    if (count == null) {
2919                                            count = Long.valueOf(0);
2920                                    }
2921    
2922                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
2923                                            finderArgs, count);
2924    
2925                                    closeSession(session);
2926                            }
2927                    }
2928    
2929                    return count.intValue();
2930            }
2931    
2932            /**
2933             * Counts all the message boards categories where groupId = &#63;.
2934             *
2935             * @param groupId the group id to search with
2936             * @return the number of matching message boards categories
2937             * @throws SystemException if a system exception occurred
2938             */
2939            public int countByGroupId(long groupId) throws SystemException {
2940                    Object[] finderArgs = new Object[] { groupId };
2941    
2942                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
2943                                    finderArgs, this);
2944    
2945                    if (count == null) {
2946                            StringBundler query = new StringBundler(2);
2947    
2948                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
2949    
2950                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2951    
2952                            String sql = query.toString();
2953    
2954                            Session session = null;
2955    
2956                            try {
2957                                    session = openSession();
2958    
2959                                    Query q = session.createQuery(sql);
2960    
2961                                    QueryPos qPos = QueryPos.getInstance(q);
2962    
2963                                    qPos.add(groupId);
2964    
2965                                    count = (Long)q.uniqueResult();
2966                            }
2967                            catch (Exception e) {
2968                                    throw processException(e);
2969                            }
2970                            finally {
2971                                    if (count == null) {
2972                                            count = Long.valueOf(0);
2973                                    }
2974    
2975                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
2976                                            finderArgs, count);
2977    
2978                                    closeSession(session);
2979                            }
2980                    }
2981    
2982                    return count.intValue();
2983            }
2984    
2985            /**
2986             * Filters by the user's permissions and counts all the message boards categories where groupId = &#63;.
2987             *
2988             * @param groupId the group id to search with
2989             * @return the number of matching message boards categories that the user has permission to view
2990             * @throws SystemException if a system exception occurred
2991             */
2992            public int filterCountByGroupId(long groupId) throws SystemException {
2993                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2994                            return countByGroupId(groupId);
2995                    }
2996    
2997                    StringBundler query = new StringBundler(2);
2998    
2999                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3000    
3001                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
3002    
3003                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3004                                    MBCategory.class.getName(), _FILTER_COLUMN_PK,
3005                                    _FILTER_COLUMN_USERID, groupId);
3006    
3007                    Session session = null;
3008    
3009                    try {
3010                            session = openSession();
3011    
3012                            SQLQuery q = session.createSQLQuery(sql);
3013    
3014                            q.addScalar(COUNT_COLUMN_NAME,
3015                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3016    
3017                            QueryPos qPos = QueryPos.getInstance(q);
3018    
3019                            qPos.add(groupId);
3020    
3021                            Long count = (Long)q.uniqueResult();
3022    
3023                            return count.intValue();
3024                    }
3025                    catch (Exception e) {
3026                            throw processException(e);
3027                    }
3028                    finally {
3029                            closeSession(session);
3030                    }
3031            }
3032    
3033            /**
3034             * Counts all the message boards categories where companyId = &#63;.
3035             *
3036             * @param companyId the company id to search with
3037             * @return the number of matching message boards categories
3038             * @throws SystemException if a system exception occurred
3039             */
3040            public int countByCompanyId(long companyId) throws SystemException {
3041                    Object[] finderArgs = new Object[] { companyId };
3042    
3043                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
3044                                    finderArgs, this);
3045    
3046                    if (count == null) {
3047                            StringBundler query = new StringBundler(2);
3048    
3049                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3050    
3051                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
3052    
3053                            String sql = query.toString();
3054    
3055                            Session session = null;
3056    
3057                            try {
3058                                    session = openSession();
3059    
3060                                    Query q = session.createQuery(sql);
3061    
3062                                    QueryPos qPos = QueryPos.getInstance(q);
3063    
3064                                    qPos.add(companyId);
3065    
3066                                    count = (Long)q.uniqueResult();
3067                            }
3068                            catch (Exception e) {
3069                                    throw processException(e);
3070                            }
3071                            finally {
3072                                    if (count == null) {
3073                                            count = Long.valueOf(0);
3074                                    }
3075    
3076                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
3077                                            finderArgs, count);
3078    
3079                                    closeSession(session);
3080                            }
3081                    }
3082    
3083                    return count.intValue();
3084            }
3085    
3086            /**
3087             * Counts all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
3088             *
3089             * @param groupId the group id to search with
3090             * @param parentCategoryId the parent category id to search with
3091             * @return the number of matching message boards categories
3092             * @throws SystemException if a system exception occurred
3093             */
3094            public int countByG_P(long groupId, long parentCategoryId)
3095                    throws SystemException {
3096                    Object[] finderArgs = new Object[] { groupId, parentCategoryId };
3097    
3098                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
3099                                    finderArgs, this);
3100    
3101                    if (count == null) {
3102                            StringBundler query = new StringBundler(3);
3103    
3104                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3105    
3106                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3107    
3108                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3109    
3110                            String sql = query.toString();
3111    
3112                            Session session = null;
3113    
3114                            try {
3115                                    session = openSession();
3116    
3117                                    Query q = session.createQuery(sql);
3118    
3119                                    QueryPos qPos = QueryPos.getInstance(q);
3120    
3121                                    qPos.add(groupId);
3122    
3123                                    qPos.add(parentCategoryId);
3124    
3125                                    count = (Long)q.uniqueResult();
3126                            }
3127                            catch (Exception e) {
3128                                    throw processException(e);
3129                            }
3130                            finally {
3131                                    if (count == null) {
3132                                            count = Long.valueOf(0);
3133                                    }
3134    
3135                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
3136                                            count);
3137    
3138                                    closeSession(session);
3139                            }
3140                    }
3141    
3142                    return count.intValue();
3143            }
3144    
3145            /**
3146             * Counts all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3147             *
3148             * @param groupId the group id to search with
3149             * @param parentCategoryIds the parent category ids to search with
3150             * @return the number of matching message boards categories
3151             * @throws SystemException if a system exception occurred
3152             */
3153            public int countByG_P(long groupId, long[] parentCategoryIds)
3154                    throws SystemException {
3155                    Object[] finderArgs = new Object[] {
3156                                    groupId, StringUtil.merge(parentCategoryIds)
3157                            };
3158    
3159                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
3160                                    finderArgs, this);
3161    
3162                    if (count == null) {
3163                            StringBundler query = new StringBundler();
3164    
3165                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
3166    
3167                            boolean conjunctionable = false;
3168    
3169                            if (conjunctionable) {
3170                                    query.append(WHERE_AND);
3171                            }
3172    
3173                            query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3174    
3175                            conjunctionable = true;
3176    
3177                            if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3178                                    if (conjunctionable) {
3179                                            query.append(WHERE_AND);
3180                                    }
3181    
3182                                    query.append(StringPool.OPEN_PARENTHESIS);
3183    
3184                                    for (int i = 0; i < parentCategoryIds.length; i++) {
3185                                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3186    
3187                                            if ((i + 1) < parentCategoryIds.length) {
3188                                                    query.append(WHERE_OR);
3189                                            }
3190                                    }
3191    
3192                                    query.append(StringPool.CLOSE_PARENTHESIS);
3193    
3194                                    conjunctionable = true;
3195                            }
3196    
3197                            String sql = query.toString();
3198    
3199                            Session session = null;
3200    
3201                            try {
3202                                    session = openSession();
3203    
3204                                    Query q = session.createQuery(sql);
3205    
3206                                    QueryPos qPos = QueryPos.getInstance(q);
3207    
3208                                    qPos.add(groupId);
3209    
3210                                    if (parentCategoryIds != null) {
3211                                            qPos.add(parentCategoryIds);
3212                                    }
3213    
3214                                    count = (Long)q.uniqueResult();
3215                            }
3216                            catch (Exception e) {
3217                                    throw processException(e);
3218                            }
3219                            finally {
3220                                    if (count == null) {
3221                                            count = Long.valueOf(0);
3222                                    }
3223    
3224                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
3225                                            count);
3226    
3227                                    closeSession(session);
3228                            }
3229                    }
3230    
3231                    return count.intValue();
3232            }
3233    
3234            /**
3235             * Filters by the user's permissions and counts all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
3236             *
3237             * @param groupId the group id to search with
3238             * @param parentCategoryId the parent category id to search with
3239             * @return the number of matching message boards categories that the user has permission to view
3240             * @throws SystemException if a system exception occurred
3241             */
3242            public int filterCountByG_P(long groupId, long parentCategoryId)
3243                    throws SystemException {
3244                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3245                            return countByG_P(groupId, parentCategoryId);
3246                    }
3247    
3248                    StringBundler query = new StringBundler(3);
3249    
3250                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3251    
3252                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3253    
3254                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3255    
3256                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3257                                    MBCategory.class.getName(), _FILTER_COLUMN_PK,
3258                                    _FILTER_COLUMN_USERID, groupId);
3259    
3260                    Session session = null;
3261    
3262                    try {
3263                            session = openSession();
3264    
3265                            SQLQuery q = session.createSQLQuery(sql);
3266    
3267                            q.addScalar(COUNT_COLUMN_NAME,
3268                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3269    
3270                            QueryPos qPos = QueryPos.getInstance(q);
3271    
3272                            qPos.add(groupId);
3273    
3274                            qPos.add(parentCategoryId);
3275    
3276                            Long count = (Long)q.uniqueResult();
3277    
3278                            return count.intValue();
3279                    }
3280                    catch (Exception e) {
3281                            throw processException(e);
3282                    }
3283                    finally {
3284                            closeSession(session);
3285                    }
3286            }
3287    
3288            /**
3289             * Filters by the user's permissions and counts all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3290             *
3291             * @param groupId the group id to search with
3292             * @param parentCategoryIds the parent category ids to search with
3293             * @return the number of matching message boards categories that the user has permission to view
3294             * @throws SystemException if a system exception occurred
3295             */
3296            public int filterCountByG_P(long groupId, long[] parentCategoryIds)
3297                    throws SystemException {
3298                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3299                            return countByG_P(groupId, parentCategoryIds);
3300                    }
3301    
3302                    StringBundler query = new StringBundler();
3303    
3304                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
3305    
3306                    boolean conjunctionable = false;
3307    
3308                    if (conjunctionable) {
3309                            query.append(WHERE_AND);
3310                    }
3311    
3312                    query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3313    
3314                    conjunctionable = true;
3315    
3316                    if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3317                            if (conjunctionable) {
3318                                    query.append(WHERE_AND);
3319                            }
3320    
3321                            query.append(StringPool.OPEN_PARENTHESIS);
3322    
3323                            for (int i = 0; i < parentCategoryIds.length; i++) {
3324                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3325    
3326                                    if ((i + 1) < parentCategoryIds.length) {
3327                                            query.append(WHERE_OR);
3328                                    }
3329                            }
3330    
3331                            query.append(StringPool.CLOSE_PARENTHESIS);
3332    
3333                            conjunctionable = true;
3334                    }
3335    
3336                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3337                                    MBCategory.class.getName(), _FILTER_COLUMN_PK,
3338                                    _FILTER_COLUMN_USERID, groupId);
3339    
3340                    Session session = null;
3341    
3342                    try {
3343                            session = openSession();
3344    
3345                            SQLQuery q = session.createSQLQuery(sql);
3346    
3347                            q.addScalar(COUNT_COLUMN_NAME,
3348                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
3349    
3350                            QueryPos qPos = QueryPos.getInstance(q);
3351    
3352                            qPos.add(groupId);
3353    
3354                            if (parentCategoryIds != null) {
3355                                    qPos.add(parentCategoryIds);
3356                            }
3357    
3358                            Long count = (Long)q.uniqueResult();
3359    
3360                            return count.intValue();
3361                    }
3362                    catch (Exception e) {
3363                            throw processException(e);
3364                    }
3365                    finally {
3366                            closeSession(session);
3367                    }
3368            }
3369    
3370            /**
3371             * Counts all the message boards categories.
3372             *
3373             * @return the number of message boards categories
3374             * @throws SystemException if a system exception occurred
3375             */
3376            public int countAll() throws SystemException {
3377                    Object[] finderArgs = new Object[0];
3378    
3379                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
3380                                    finderArgs, this);
3381    
3382                    if (count == null) {
3383                            Session session = null;
3384    
3385                            try {
3386                                    session = openSession();
3387    
3388                                    Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
3389    
3390                                    count = (Long)q.uniqueResult();
3391                            }
3392                            catch (Exception e) {
3393                                    throw processException(e);
3394                            }
3395                            finally {
3396                                    if (count == null) {
3397                                            count = Long.valueOf(0);
3398                                    }
3399    
3400                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL, finderArgs,
3401                                            count);
3402    
3403                                    closeSession(session);
3404                            }
3405                    }
3406    
3407                    return count.intValue();
3408            }
3409    
3410            /**
3411             * Initializes the message boards category persistence.
3412             */
3413            public void afterPropertiesSet() {
3414                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
3415                                            com.liferay.portal.util.PropsUtil.get(
3416                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
3417    
3418                    if (listenerClassNames.length > 0) {
3419                            try {
3420                                    List<ModelListener<MBCategory>> listenersList = new ArrayList<ModelListener<MBCategory>>();
3421    
3422                                    for (String listenerClassName : listenerClassNames) {
3423                                            listenersList.add((ModelListener<MBCategory>)InstanceFactory.newInstance(
3424                                                            listenerClassName));
3425                                    }
3426    
3427                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
3428                            }
3429                            catch (Exception e) {
3430                                    _log.error(e);
3431                            }
3432                    }
3433            }
3434    
3435            public void destroy() {
3436                    EntityCacheUtil.removeCache(MBCategoryImpl.class.getName());
3437                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
3438                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST);
3439            }
3440    
3441            @BeanReference(type = MBBanPersistence.class)
3442            protected MBBanPersistence mbBanPersistence;
3443            @BeanReference(type = MBCategoryPersistence.class)
3444            protected MBCategoryPersistence mbCategoryPersistence;
3445            @BeanReference(type = MBDiscussionPersistence.class)
3446            protected MBDiscussionPersistence mbDiscussionPersistence;
3447            @BeanReference(type = MBMailingListPersistence.class)
3448            protected MBMailingListPersistence mbMailingListPersistence;
3449            @BeanReference(type = MBMessagePersistence.class)
3450            protected MBMessagePersistence mbMessagePersistence;
3451            @BeanReference(type = MBMessageFlagPersistence.class)
3452            protected MBMessageFlagPersistence mbMessageFlagPersistence;
3453            @BeanReference(type = MBStatsUserPersistence.class)
3454            protected MBStatsUserPersistence mbStatsUserPersistence;
3455            @BeanReference(type = MBThreadPersistence.class)
3456            protected MBThreadPersistence mbThreadPersistence;
3457            @BeanReference(type = GroupPersistence.class)
3458            protected GroupPersistence groupPersistence;
3459            @BeanReference(type = ResourcePersistence.class)
3460            protected ResourcePersistence resourcePersistence;
3461            @BeanReference(type = SubscriptionPersistence.class)
3462            protected SubscriptionPersistence subscriptionPersistence;
3463            @BeanReference(type = UserPersistence.class)
3464            protected UserPersistence userPersistence;
3465            @BeanReference(type = AssetTagPersistence.class)
3466            protected AssetTagPersistence assetTagPersistence;
3467            @BeanReference(type = ExpandoValuePersistence.class)
3468            protected ExpandoValuePersistence expandoValuePersistence;
3469            private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
3470            private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
3471            private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
3472            private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
3473            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
3474            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
3475            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?)";
3476            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
3477            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
3478            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?) AND ";
3479            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
3480            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
3481            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
3482            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
3483            private static final String _FINDER_COLUMN_G_P_GROUPID_5 = "(" +
3484                    _removeConjunction(_FINDER_COLUMN_G_P_GROUPID_2) + ")";
3485            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
3486            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_5 = "(" +
3487                    _removeConjunction(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2) + ")";
3488    
3489            private static String _removeConjunction(String sql) {
3490                    int pos = sql.indexOf(" AND ");
3491    
3492                    if (pos != -1) {
3493                            sql = sql.substring(0, pos);
3494                    }
3495    
3496                    return sql;
3497            }
3498    
3499            private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
3500            private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
3501                    "SELECT {MBCategory.*} FROM (SELECT DISTINCT mbCategory.categoryId FROM MBCategory mbCategory WHERE ";
3502            private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
3503                    ") TEMP_TABLE INNER JOIN MBCategory ON TEMP_TABLE.categoryId = MBCategory.categoryId";
3504            private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
3505            private static final String _FILTER_COLUMN_PK = "mbCategory.categoryId";
3506            private static final String _FILTER_COLUMN_USERID = "mbCategory.userId";
3507            private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
3508            private static final String _FILTER_ENTITY_TABLE = "MBCategory";
3509            private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
3510            private static final String _ORDER_BY_ENTITY_TABLE = "MBCategory.";
3511            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
3512            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
3513            private static Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
3514    }