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