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