001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.NoSuchModelException;
018    import com.liferay.portal.kernel.bean.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.ArrayUtil;
032    import com.liferay.portal.kernel.util.GetterUtil;
033    import com.liferay.portal.kernel.util.InstanceFactory;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.kernel.util.StringBundler;
036    import com.liferay.portal.kernel.util.StringPool;
037    import com.liferay.portal.kernel.util.StringUtil;
038    import com.liferay.portal.kernel.util.Validator;
039    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.model.ModelListener;
042    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
043    import com.liferay.portal.service.persistence.GroupPersistence;
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     * Caching information and settings can be found in <code>portal.properties</code>
066     * </p>
067     *
068     * @author Brian Wing Shun Chan
069     * @see MBCategoryPersistence
070     * @see MBCategoryUtil
071     * @generated
072     */
073    public class MBCategoryPersistenceImpl extends BasePersistenceImpl<MBCategory>
074            implements MBCategoryPersistence {
075            /*
076             * NOTE FOR DEVELOPERS:
077             *
078             * 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.
079             */
080            public static final String FINDER_CLASS_NAME_ENTITY = MBCategoryImpl.class.getName();
081            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
082                    ".List1";
083            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
084                    ".List2";
085            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
086                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
087                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
088                            new String[] {
089                                    String.class.getName(),
090                                    
091                            "java.lang.Integer", "java.lang.Integer",
092                                    "com.liferay.portal.kernel.util.OrderByComparator"
093                            });
094            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
095                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
096                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
097                            new String[] { String.class.getName() },
098                            MBCategoryModelImpl.UUID_COLUMN_BITMASK);
099            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
100                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
101                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
102                            new String[] { String.class.getName() });
103            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
104                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
105                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
106                            new String[] { String.class.getName(), Long.class.getName() },
107                            MBCategoryModelImpl.UUID_COLUMN_BITMASK |
108                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK);
109            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
110                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
111                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
112                            new String[] { String.class.getName(), Long.class.getName() });
113            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
114                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
115                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
116                            new String[] {
117                                    String.class.getName(), Long.class.getName(),
118                                    
119                            "java.lang.Integer", "java.lang.Integer",
120                                    "com.liferay.portal.kernel.util.OrderByComparator"
121                            });
122            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
123                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
124                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
125                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
126                            new String[] { String.class.getName(), Long.class.getName() },
127                            MBCategoryModelImpl.UUID_COLUMN_BITMASK |
128                            MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK);
129            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
130                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
132                            new String[] { String.class.getName(), Long.class.getName() });
133            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
134                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
135                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
136                            new String[] {
137                                    Long.class.getName(),
138                                    
139                            "java.lang.Integer", "java.lang.Integer",
140                                    "com.liferay.portal.kernel.util.OrderByComparator"
141                            });
142            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
143                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
144                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
145                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
146                            new String[] { Long.class.getName() },
147                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK);
148            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
149                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
150                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
151                            new String[] { Long.class.getName() });
152            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
153                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
154                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
155                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
156                            new String[] {
157                                    Long.class.getName(),
158                                    
159                            "java.lang.Integer", "java.lang.Integer",
160                                    "com.liferay.portal.kernel.util.OrderByComparator"
161                            });
162            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
163                    new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
164                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
165                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
166                            new String[] { Long.class.getName() },
167                            MBCategoryModelImpl.COMPANYID_COLUMN_BITMASK);
168            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
169                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
170                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
171                            new String[] { Long.class.getName() });
172            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
173                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
174                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_P",
175                            new String[] {
176                                    Long.class.getName(), Long.class.getName(),
177                                    
178                            "java.lang.Integer", "java.lang.Integer",
179                                    "com.liferay.portal.kernel.util.OrderByComparator"
180                            });
181            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
182                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
183                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_P",
184                            new String[] { Long.class.getName(), Long.class.getName() },
185                            MBCategoryModelImpl.GROUPID_COLUMN_BITMASK |
186                            MBCategoryModelImpl.PARENTCATEGORYID_COLUMN_BITMASK);
187            public static final FinderPath FINDER_PATH_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
188                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
189                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_P",
190                            new String[] { Long.class.getName(), Long.class.getName() });
191            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
192                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
193                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_P",
194                            new String[] { Long.class.getName(), Long.class.getName() });
195            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
196                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
197                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
198            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
199                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, MBCategoryImpl.class,
200                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
201            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
202                            MBCategoryModelImpl.FINDER_CACHE_ENABLED, Long.class,
203                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
204    
205            /**
206             * Caches the message boards category in the entity cache if it is enabled.
207             *
208             * @param mbCategory the message boards category
209             */
210            public void cacheResult(MBCategory mbCategory) {
211                    EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
212                            MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
213    
214                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
215                            new Object[] {
216                                    mbCategory.getUuid(), Long.valueOf(mbCategory.getGroupId())
217                            }, mbCategory);
218    
219                    mbCategory.resetOriginalValues();
220            }
221    
222            /**
223             * Caches the message boards categories in the entity cache if it is enabled.
224             *
225             * @param mbCategories the message boards categories
226             */
227            public void cacheResult(List<MBCategory> mbCategories) {
228                    for (MBCategory mbCategory : mbCategories) {
229                            if (EntityCacheUtil.getResult(
230                                                    MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
231                                                    MBCategoryImpl.class, mbCategory.getPrimaryKey()) == null) {
232                                    cacheResult(mbCategory);
233                            }
234                            else {
235                                    mbCategory.resetOriginalValues();
236                            }
237                    }
238            }
239    
240            /**
241             * Clears the cache for all message boards categories.
242             *
243             * <p>
244             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
245             * </p>
246             */
247            @Override
248            public void clearCache() {
249                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
250                            CacheRegistryUtil.clear(MBCategoryImpl.class.getName());
251                    }
252    
253                    EntityCacheUtil.clearCache(MBCategoryImpl.class.getName());
254    
255                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
256                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
257                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
258            }
259    
260            /**
261             * Clears the cache for the message boards category.
262             *
263             * <p>
264             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
265             * </p>
266             */
267            @Override
268            public void clearCache(MBCategory mbCategory) {
269                    EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
270                            MBCategoryImpl.class, mbCategory.getPrimaryKey());
271    
272                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
273                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
274    
275                    clearUniqueFindersCache(mbCategory);
276            }
277    
278            @Override
279            public void clearCache(List<MBCategory> mbCategories) {
280                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
281                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
282    
283                    for (MBCategory mbCategory : mbCategories) {
284                            EntityCacheUtil.removeResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
285                                    MBCategoryImpl.class, mbCategory.getPrimaryKey());
286    
287                            clearUniqueFindersCache(mbCategory);
288                    }
289            }
290    
291            protected void clearUniqueFindersCache(MBCategory mbCategory) {
292                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
293                            new Object[] {
294                                    mbCategory.getUuid(), Long.valueOf(mbCategory.getGroupId())
295                            });
296            }
297    
298            /**
299             * Creates a new message boards category with the primary key. Does not add the message boards category to the database.
300             *
301             * @param categoryId the primary key for the new message boards category
302             * @return the new message boards category
303             */
304            public MBCategory create(long categoryId) {
305                    MBCategory mbCategory = new MBCategoryImpl();
306    
307                    mbCategory.setNew(true);
308                    mbCategory.setPrimaryKey(categoryId);
309    
310                    String uuid = PortalUUIDUtil.generate();
311    
312                    mbCategory.setUuid(uuid);
313    
314                    return mbCategory;
315            }
316    
317            /**
318             * Removes the message boards category with the primary key from the database. Also notifies the appropriate model listeners.
319             *
320             * @param categoryId the primary key of the message boards category
321             * @return the message boards category that was removed
322             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
323             * @throws SystemException if a system exception occurred
324             */
325            public MBCategory remove(long categoryId)
326                    throws NoSuchCategoryException, SystemException {
327                    return remove(Long.valueOf(categoryId));
328            }
329    
330            /**
331             * Removes the message boards category with the primary key from the database. Also notifies the appropriate model listeners.
332             *
333             * @param primaryKey the primary key of the message boards category
334             * @return the message boards category that was removed
335             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
336             * @throws SystemException if a system exception occurred
337             */
338            @Override
339            public MBCategory remove(Serializable primaryKey)
340                    throws NoSuchCategoryException, SystemException {
341                    Session session = null;
342    
343                    try {
344                            session = openSession();
345    
346                            MBCategory mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
347                                            primaryKey);
348    
349                            if (mbCategory == null) {
350                                    if (_log.isWarnEnabled()) {
351                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
352                                    }
353    
354                                    throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
355                                            primaryKey);
356                            }
357    
358                            return remove(mbCategory);
359                    }
360                    catch (NoSuchCategoryException nsee) {
361                            throw nsee;
362                    }
363                    catch (Exception e) {
364                            throw processException(e);
365                    }
366                    finally {
367                            closeSession(session);
368                    }
369            }
370    
371            @Override
372            protected MBCategory removeImpl(MBCategory mbCategory)
373                    throws SystemException {
374                    mbCategory = toUnwrappedModel(mbCategory);
375    
376                    Session session = null;
377    
378                    try {
379                            session = openSession();
380    
381                            if (mbCategory.isCachedModel()) {
382                                    mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
383                                                    mbCategory.getPrimaryKeyObj());
384                            }
385    
386                            session.delete(mbCategory);
387                    }
388                    catch (Exception e) {
389                            throw processException(e);
390                    }
391                    finally {
392                            closeSession(session);
393                    }
394    
395                    clearCache(mbCategory);
396    
397                    return mbCategory;
398            }
399    
400            @Override
401            public MBCategory updateImpl(
402                    com.liferay.portlet.messageboards.model.MBCategory mbCategory)
403                    throws SystemException {
404                    mbCategory = toUnwrappedModel(mbCategory);
405    
406                    boolean isNew = mbCategory.isNew();
407    
408                    MBCategoryModelImpl mbCategoryModelImpl = (MBCategoryModelImpl)mbCategory;
409    
410                    if (Validator.isNull(mbCategory.getUuid())) {
411                            String uuid = PortalUUIDUtil.generate();
412    
413                            mbCategory.setUuid(uuid);
414                    }
415    
416                    Session session = null;
417    
418                    try {
419                            session = openSession();
420    
421                            if (mbCategory.isNew()) {
422                                    session.save(mbCategory);
423    
424                                    mbCategory.setNew(false);
425                            }
426                            else {
427                                    session.merge(mbCategory);
428                            }
429                    }
430                    catch (Exception e) {
431                            throw processException(e);
432                    }
433                    finally {
434                            closeSession(session);
435                    }
436    
437                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
438    
439                    if (isNew || !MBCategoryModelImpl.COLUMN_BITMASK_ENABLED) {
440                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
441                    }
442    
443                    else {
444                            if ((mbCategoryModelImpl.getColumnBitmask() &
445                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
446                                    Object[] args = new Object[] {
447                                                    mbCategoryModelImpl.getOriginalUuid()
448                                            };
449    
450                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
451                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
452                                            args);
453    
454                                    args = new Object[] { mbCategoryModelImpl.getUuid() };
455    
456                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
457                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
458                                            args);
459                            }
460    
461                            if ((mbCategoryModelImpl.getColumnBitmask() &
462                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
463                                    Object[] args = new Object[] {
464                                                    mbCategoryModelImpl.getOriginalUuid(),
465                                                    Long.valueOf(mbCategoryModelImpl.getOriginalCompanyId())
466                                            };
467    
468                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
469                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
470                                            args);
471    
472                                    args = new Object[] {
473                                                    mbCategoryModelImpl.getUuid(),
474                                                    Long.valueOf(mbCategoryModelImpl.getCompanyId())
475                                            };
476    
477                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
478                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
479                                            args);
480                            }
481    
482                            if ((mbCategoryModelImpl.getColumnBitmask() &
483                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
484                                    Object[] args = new Object[] {
485                                                    Long.valueOf(mbCategoryModelImpl.getOriginalGroupId())
486                                            };
487    
488                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
489                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
490                                            args);
491    
492                                    args = new Object[] {
493                                                    Long.valueOf(mbCategoryModelImpl.getGroupId())
494                                            };
495    
496                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
497                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
498                                            args);
499                            }
500    
501                            if ((mbCategoryModelImpl.getColumnBitmask() &
502                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
503                                    Object[] args = new Object[] {
504                                                    Long.valueOf(mbCategoryModelImpl.getOriginalCompanyId())
505                                            };
506    
507                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
508                                            args);
509                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
510                                            args);
511    
512                                    args = new Object[] {
513                                                    Long.valueOf(mbCategoryModelImpl.getCompanyId())
514                                            };
515    
516                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
517                                            args);
518                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
519                                            args);
520                            }
521    
522                            if ((mbCategoryModelImpl.getColumnBitmask() &
523                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P.getColumnBitmask()) != 0) {
524                                    Object[] args = new Object[] {
525                                                    Long.valueOf(mbCategoryModelImpl.getOriginalGroupId()),
526                                                    Long.valueOf(mbCategoryModelImpl.getOriginalParentCategoryId())
527                                            };
528    
529                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
530                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
531                                            args);
532    
533                                    args = new Object[] {
534                                                    Long.valueOf(mbCategoryModelImpl.getGroupId()),
535                                                    Long.valueOf(mbCategoryModelImpl.getParentCategoryId())
536                                            };
537    
538                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_P, args);
539                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P,
540                                            args);
541                            }
542                    }
543    
544                    EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
545                            MBCategoryImpl.class, mbCategory.getPrimaryKey(), mbCategory);
546    
547                    if (isNew) {
548                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
549                                    new Object[] {
550                                            mbCategory.getUuid(), Long.valueOf(mbCategory.getGroupId())
551                                    }, mbCategory);
552                    }
553                    else {
554                            if ((mbCategoryModelImpl.getColumnBitmask() &
555                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
556                                    Object[] args = new Object[] {
557                                                    mbCategoryModelImpl.getOriginalUuid(),
558                                                    Long.valueOf(mbCategoryModelImpl.getOriginalGroupId())
559                                            };
560    
561                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
562    
563                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
564    
565                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
566                                            new Object[] {
567                                                    mbCategory.getUuid(),
568                                                    Long.valueOf(mbCategory.getGroupId())
569                                            }, mbCategory);
570                            }
571                    }
572    
573                    return mbCategory;
574            }
575    
576            protected MBCategory toUnwrappedModel(MBCategory mbCategory) {
577                    if (mbCategory instanceof MBCategoryImpl) {
578                            return mbCategory;
579                    }
580    
581                    MBCategoryImpl mbCategoryImpl = new MBCategoryImpl();
582    
583                    mbCategoryImpl.setNew(mbCategory.isNew());
584                    mbCategoryImpl.setPrimaryKey(mbCategory.getPrimaryKey());
585    
586                    mbCategoryImpl.setUuid(mbCategory.getUuid());
587                    mbCategoryImpl.setCategoryId(mbCategory.getCategoryId());
588                    mbCategoryImpl.setGroupId(mbCategory.getGroupId());
589                    mbCategoryImpl.setCompanyId(mbCategory.getCompanyId());
590                    mbCategoryImpl.setUserId(mbCategory.getUserId());
591                    mbCategoryImpl.setUserName(mbCategory.getUserName());
592                    mbCategoryImpl.setCreateDate(mbCategory.getCreateDate());
593                    mbCategoryImpl.setModifiedDate(mbCategory.getModifiedDate());
594                    mbCategoryImpl.setParentCategoryId(mbCategory.getParentCategoryId());
595                    mbCategoryImpl.setName(mbCategory.getName());
596                    mbCategoryImpl.setDescription(mbCategory.getDescription());
597                    mbCategoryImpl.setDisplayStyle(mbCategory.getDisplayStyle());
598                    mbCategoryImpl.setThreadCount(mbCategory.getThreadCount());
599                    mbCategoryImpl.setMessageCount(mbCategory.getMessageCount());
600                    mbCategoryImpl.setLastPostDate(mbCategory.getLastPostDate());
601    
602                    return mbCategoryImpl;
603            }
604    
605            /**
606             * Returns the message boards category with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
607             *
608             * @param primaryKey the primary key of the message boards category
609             * @return the message boards category
610             * @throws com.liferay.portal.NoSuchModelException if a message boards category with the primary key could not be found
611             * @throws SystemException if a system exception occurred
612             */
613            @Override
614            public MBCategory findByPrimaryKey(Serializable primaryKey)
615                    throws NoSuchModelException, SystemException {
616                    return findByPrimaryKey(((Long)primaryKey).longValue());
617            }
618    
619            /**
620             * Returns the message boards category with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchCategoryException} if it could not be found.
621             *
622             * @param categoryId the primary key of the message boards category
623             * @return the message boards category
624             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
625             * @throws SystemException if a system exception occurred
626             */
627            public MBCategory findByPrimaryKey(long categoryId)
628                    throws NoSuchCategoryException, SystemException {
629                    MBCategory mbCategory = fetchByPrimaryKey(categoryId);
630    
631                    if (mbCategory == null) {
632                            if (_log.isWarnEnabled()) {
633                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + categoryId);
634                            }
635    
636                            throw new NoSuchCategoryException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
637                                    categoryId);
638                    }
639    
640                    return mbCategory;
641            }
642    
643            /**
644             * Returns the message boards category with the primary key or returns <code>null</code> if it could not be found.
645             *
646             * @param primaryKey the primary key of the message boards category
647             * @return the message boards category, or <code>null</code> if a message boards category with the primary key could not be found
648             * @throws SystemException if a system exception occurred
649             */
650            @Override
651            public MBCategory fetchByPrimaryKey(Serializable primaryKey)
652                    throws SystemException {
653                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
654            }
655    
656            /**
657             * Returns the message boards category with the primary key or returns <code>null</code> if it could not be found.
658             *
659             * @param categoryId the primary key of the message boards category
660             * @return the message boards category, or <code>null</code> if a message boards category with the primary key could not be found
661             * @throws SystemException if a system exception occurred
662             */
663            public MBCategory fetchByPrimaryKey(long categoryId)
664                    throws SystemException {
665                    MBCategory mbCategory = (MBCategory)EntityCacheUtil.getResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
666                                    MBCategoryImpl.class, categoryId);
667    
668                    if (mbCategory == _nullMBCategory) {
669                            return null;
670                    }
671    
672                    if (mbCategory == null) {
673                            Session session = null;
674    
675                            boolean hasException = false;
676    
677                            try {
678                                    session = openSession();
679    
680                                    mbCategory = (MBCategory)session.get(MBCategoryImpl.class,
681                                                    Long.valueOf(categoryId));
682                            }
683                            catch (Exception e) {
684                                    hasException = true;
685    
686                                    throw processException(e);
687                            }
688                            finally {
689                                    if (mbCategory != null) {
690                                            cacheResult(mbCategory);
691                                    }
692                                    else if (!hasException) {
693                                            EntityCacheUtil.putResult(MBCategoryModelImpl.ENTITY_CACHE_ENABLED,
694                                                    MBCategoryImpl.class, categoryId, _nullMBCategory);
695                                    }
696    
697                                    closeSession(session);
698                            }
699                    }
700    
701                    return mbCategory;
702            }
703    
704            /**
705             * Returns all the message boards categories where uuid = &#63;.
706             *
707             * @param uuid the uuid
708             * @return the matching message boards categories
709             * @throws SystemException if a system exception occurred
710             */
711            public List<MBCategory> findByUuid(String uuid) throws SystemException {
712                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
713            }
714    
715            /**
716             * Returns a range of all the message boards categories where uuid = &#63;.
717             *
718             * <p>
719             * 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.
720             * </p>
721             *
722             * @param uuid the uuid
723             * @param start the lower bound of the range of message boards categories
724             * @param end the upper bound of the range of message boards categories (not inclusive)
725             * @return the range of matching message boards categories
726             * @throws SystemException if a system exception occurred
727             */
728            public List<MBCategory> findByUuid(String uuid, int start, int end)
729                    throws SystemException {
730                    return findByUuid(uuid, start, end, null);
731            }
732    
733            /**
734             * Returns an ordered range of all the message boards categories where uuid = &#63;.
735             *
736             * <p>
737             * 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.
738             * </p>
739             *
740             * @param uuid the uuid
741             * @param start the lower bound of the range of message boards categories
742             * @param end the upper bound of the range of message boards categories (not inclusive)
743             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
744             * @return the ordered range of matching message boards categories
745             * @throws SystemException if a system exception occurred
746             */
747            public List<MBCategory> findByUuid(String uuid, int start, int end,
748                    OrderByComparator orderByComparator) throws SystemException {
749                    FinderPath finderPath = null;
750                    Object[] finderArgs = null;
751    
752                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
753                                    (orderByComparator == null)) {
754                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
755                            finderArgs = new Object[] { uuid };
756                    }
757                    else {
758                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
759                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
760                    }
761    
762                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
763                                    finderArgs, this);
764    
765                    if ((list != null) && !list.isEmpty()) {
766                            for (MBCategory mbCategory : list) {
767                                    if (!Validator.equals(uuid, mbCategory.getUuid())) {
768                                            list = null;
769    
770                                            break;
771                                    }
772                            }
773                    }
774    
775                    if (list == null) {
776                            StringBundler query = null;
777    
778                            if (orderByComparator != null) {
779                                    query = new StringBundler(3 +
780                                                    (orderByComparator.getOrderByFields().length * 3));
781                            }
782                            else {
783                                    query = new StringBundler(3);
784                            }
785    
786                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
787    
788                            if (uuid == null) {
789                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
790                            }
791                            else {
792                                    if (uuid.equals(StringPool.BLANK)) {
793                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
794                                    }
795                                    else {
796                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
797                                    }
798                            }
799    
800                            if (orderByComparator != null) {
801                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
802                                            orderByComparator);
803                            }
804    
805                            else {
806                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
807                            }
808    
809                            String sql = query.toString();
810    
811                            Session session = null;
812    
813                            try {
814                                    session = openSession();
815    
816                                    Query q = session.createQuery(sql);
817    
818                                    QueryPos qPos = QueryPos.getInstance(q);
819    
820                                    if (uuid != null) {
821                                            qPos.add(uuid);
822                                    }
823    
824                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
825                                                    end);
826                            }
827                            catch (Exception e) {
828                                    throw processException(e);
829                            }
830                            finally {
831                                    if (list == null) {
832                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
833                                    }
834                                    else {
835                                            cacheResult(list);
836    
837                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
838                                    }
839    
840                                    closeSession(session);
841                            }
842                    }
843    
844                    return list;
845            }
846    
847            /**
848             * Returns the first message boards category in the ordered set where uuid = &#63;.
849             *
850             * @param uuid the uuid
851             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
852             * @return the first matching message boards category
853             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
854             * @throws SystemException if a system exception occurred
855             */
856            public MBCategory findByUuid_First(String uuid,
857                    OrderByComparator orderByComparator)
858                    throws NoSuchCategoryException, SystemException {
859                    MBCategory mbCategory = fetchByUuid_First(uuid, orderByComparator);
860    
861                    if (mbCategory != null) {
862                            return mbCategory;
863                    }
864    
865                    StringBundler msg = new StringBundler(4);
866    
867                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
868    
869                    msg.append("uuid=");
870                    msg.append(uuid);
871    
872                    msg.append(StringPool.CLOSE_CURLY_BRACE);
873    
874                    throw new NoSuchCategoryException(msg.toString());
875            }
876    
877            /**
878             * Returns the first message boards category in the ordered set where uuid = &#63;.
879             *
880             * @param uuid the uuid
881             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
882             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
883             * @throws SystemException if a system exception occurred
884             */
885            public MBCategory fetchByUuid_First(String uuid,
886                    OrderByComparator orderByComparator) throws SystemException {
887                    List<MBCategory> list = findByUuid(uuid, 0, 1, orderByComparator);
888    
889                    if (!list.isEmpty()) {
890                            return list.get(0);
891                    }
892    
893                    return null;
894            }
895    
896            /**
897             * Returns the last message boards category in the ordered set where uuid = &#63;.
898             *
899             * @param uuid the uuid
900             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
901             * @return the last matching message boards category
902             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
903             * @throws SystemException if a system exception occurred
904             */
905            public MBCategory findByUuid_Last(String uuid,
906                    OrderByComparator orderByComparator)
907                    throws NoSuchCategoryException, SystemException {
908                    MBCategory mbCategory = fetchByUuid_Last(uuid, orderByComparator);
909    
910                    if (mbCategory != null) {
911                            return mbCategory;
912                    }
913    
914                    StringBundler msg = new StringBundler(4);
915    
916                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
917    
918                    msg.append("uuid=");
919                    msg.append(uuid);
920    
921                    msg.append(StringPool.CLOSE_CURLY_BRACE);
922    
923                    throw new NoSuchCategoryException(msg.toString());
924            }
925    
926            /**
927             * Returns the last message boards category in the ordered set where uuid = &#63;.
928             *
929             * @param uuid the uuid
930             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
931             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
932             * @throws SystemException if a system exception occurred
933             */
934            public MBCategory fetchByUuid_Last(String uuid,
935                    OrderByComparator orderByComparator) throws SystemException {
936                    int count = countByUuid(uuid);
937    
938                    List<MBCategory> list = findByUuid(uuid, count - 1, count,
939                                    orderByComparator);
940    
941                    if (!list.isEmpty()) {
942                            return list.get(0);
943                    }
944    
945                    return null;
946            }
947    
948            /**
949             * Returns the message boards categories before and after the current message boards category in the ordered set where uuid = &#63;.
950             *
951             * @param categoryId the primary key of the current message boards category
952             * @param uuid the uuid
953             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
954             * @return the previous, current, and next message boards category
955             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
956             * @throws SystemException if a system exception occurred
957             */
958            public MBCategory[] findByUuid_PrevAndNext(long categoryId, String uuid,
959                    OrderByComparator orderByComparator)
960                    throws NoSuchCategoryException, SystemException {
961                    MBCategory mbCategory = findByPrimaryKey(categoryId);
962    
963                    Session session = null;
964    
965                    try {
966                            session = openSession();
967    
968                            MBCategory[] array = new MBCategoryImpl[3];
969    
970                            array[0] = getByUuid_PrevAndNext(session, mbCategory, uuid,
971                                            orderByComparator, true);
972    
973                            array[1] = mbCategory;
974    
975                            array[2] = getByUuid_PrevAndNext(session, mbCategory, uuid,
976                                            orderByComparator, false);
977    
978                            return array;
979                    }
980                    catch (Exception e) {
981                            throw processException(e);
982                    }
983                    finally {
984                            closeSession(session);
985                    }
986            }
987    
988            protected MBCategory getByUuid_PrevAndNext(Session session,
989                    MBCategory mbCategory, String uuid,
990                    OrderByComparator orderByComparator, boolean previous) {
991                    StringBundler query = null;
992    
993                    if (orderByComparator != null) {
994                            query = new StringBundler(6 +
995                                            (orderByComparator.getOrderByFields().length * 6));
996                    }
997                    else {
998                            query = new StringBundler(3);
999                    }
1000    
1001                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1002    
1003                    if (uuid == null) {
1004                            query.append(_FINDER_COLUMN_UUID_UUID_1);
1005                    }
1006                    else {
1007                            if (uuid.equals(StringPool.BLANK)) {
1008                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
1009                            }
1010                            else {
1011                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
1012                            }
1013                    }
1014    
1015                    if (orderByComparator != null) {
1016                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1017    
1018                            if (orderByConditionFields.length > 0) {
1019                                    query.append(WHERE_AND);
1020                            }
1021    
1022                            for (int i = 0; i < orderByConditionFields.length; i++) {
1023                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1024                                    query.append(orderByConditionFields[i]);
1025    
1026                                    if ((i + 1) < orderByConditionFields.length) {
1027                                            if (orderByComparator.isAscending() ^ previous) {
1028                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1029                                            }
1030                                            else {
1031                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1032                                            }
1033                                    }
1034                                    else {
1035                                            if (orderByComparator.isAscending() ^ previous) {
1036                                                    query.append(WHERE_GREATER_THAN);
1037                                            }
1038                                            else {
1039                                                    query.append(WHERE_LESSER_THAN);
1040                                            }
1041                                    }
1042                            }
1043    
1044                            query.append(ORDER_BY_CLAUSE);
1045    
1046                            String[] orderByFields = orderByComparator.getOrderByFields();
1047    
1048                            for (int i = 0; i < orderByFields.length; i++) {
1049                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1050                                    query.append(orderByFields[i]);
1051    
1052                                    if ((i + 1) < orderByFields.length) {
1053                                            if (orderByComparator.isAscending() ^ previous) {
1054                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1055                                            }
1056                                            else {
1057                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1058                                            }
1059                                    }
1060                                    else {
1061                                            if (orderByComparator.isAscending() ^ previous) {
1062                                                    query.append(ORDER_BY_ASC);
1063                                            }
1064                                            else {
1065                                                    query.append(ORDER_BY_DESC);
1066                                            }
1067                                    }
1068                            }
1069                    }
1070    
1071                    else {
1072                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1073                    }
1074    
1075                    String sql = query.toString();
1076    
1077                    Query q = session.createQuery(sql);
1078    
1079                    q.setFirstResult(0);
1080                    q.setMaxResults(2);
1081    
1082                    QueryPos qPos = QueryPos.getInstance(q);
1083    
1084                    if (uuid != null) {
1085                            qPos.add(uuid);
1086                    }
1087    
1088                    if (orderByComparator != null) {
1089                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1090    
1091                            for (Object value : values) {
1092                                    qPos.add(value);
1093                            }
1094                    }
1095    
1096                    List<MBCategory> list = q.list();
1097    
1098                    if (list.size() == 2) {
1099                            return list.get(1);
1100                    }
1101                    else {
1102                            return null;
1103                    }
1104            }
1105    
1106            /**
1107             * Returns the message boards category where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchCategoryException} if it could not be found.
1108             *
1109             * @param uuid the uuid
1110             * @param groupId the group ID
1111             * @return the matching message boards category
1112             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1113             * @throws SystemException if a system exception occurred
1114             */
1115            public MBCategory findByUUID_G(String uuid, long groupId)
1116                    throws NoSuchCategoryException, SystemException {
1117                    MBCategory mbCategory = fetchByUUID_G(uuid, groupId);
1118    
1119                    if (mbCategory == null) {
1120                            StringBundler msg = new StringBundler(6);
1121    
1122                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1123    
1124                            msg.append("uuid=");
1125                            msg.append(uuid);
1126    
1127                            msg.append(", groupId=");
1128                            msg.append(groupId);
1129    
1130                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1131    
1132                            if (_log.isWarnEnabled()) {
1133                                    _log.warn(msg.toString());
1134                            }
1135    
1136                            throw new NoSuchCategoryException(msg.toString());
1137                    }
1138    
1139                    return mbCategory;
1140            }
1141    
1142            /**
1143             * Returns the message boards category where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1144             *
1145             * @param uuid the uuid
1146             * @param groupId the group ID
1147             * @return the matching message boards category, or <code>null</code> if a matching message boards category could not be found
1148             * @throws SystemException if a system exception occurred
1149             */
1150            public MBCategory fetchByUUID_G(String uuid, long groupId)
1151                    throws SystemException {
1152                    return fetchByUUID_G(uuid, groupId, true);
1153            }
1154    
1155            /**
1156             * Returns the message boards category where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1157             *
1158             * @param uuid the uuid
1159             * @param groupId the group ID
1160             * @param retrieveFromCache whether to use the finder cache
1161             * @return the matching message boards category, or <code>null</code> if a matching message boards category could not be found
1162             * @throws SystemException if a system exception occurred
1163             */
1164            public MBCategory fetchByUUID_G(String uuid, long groupId,
1165                    boolean retrieveFromCache) throws SystemException {
1166                    Object[] finderArgs = new Object[] { uuid, groupId };
1167    
1168                    Object result = null;
1169    
1170                    if (retrieveFromCache) {
1171                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
1172                                            finderArgs, this);
1173                    }
1174    
1175                    if (result instanceof MBCategory) {
1176                            MBCategory mbCategory = (MBCategory)result;
1177    
1178                            if (!Validator.equals(uuid, mbCategory.getUuid()) ||
1179                                            (groupId != mbCategory.getGroupId())) {
1180                                    result = null;
1181                            }
1182                    }
1183    
1184                    if (result == null) {
1185                            StringBundler query = new StringBundler(4);
1186    
1187                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1188    
1189                            if (uuid == null) {
1190                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
1191                            }
1192                            else {
1193                                    if (uuid.equals(StringPool.BLANK)) {
1194                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
1195                                    }
1196                                    else {
1197                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
1198                                    }
1199                            }
1200    
1201                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
1202    
1203                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1204    
1205                            String sql = query.toString();
1206    
1207                            Session session = null;
1208    
1209                            try {
1210                                    session = openSession();
1211    
1212                                    Query q = session.createQuery(sql);
1213    
1214                                    QueryPos qPos = QueryPos.getInstance(q);
1215    
1216                                    if (uuid != null) {
1217                                            qPos.add(uuid);
1218                                    }
1219    
1220                                    qPos.add(groupId);
1221    
1222                                    List<MBCategory> list = q.list();
1223    
1224                                    result = list;
1225    
1226                                    MBCategory mbCategory = null;
1227    
1228                                    if (list.isEmpty()) {
1229                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1230                                                    finderArgs, list);
1231                                    }
1232                                    else {
1233                                            mbCategory = list.get(0);
1234    
1235                                            cacheResult(mbCategory);
1236    
1237                                            if ((mbCategory.getUuid() == null) ||
1238                                                            !mbCategory.getUuid().equals(uuid) ||
1239                                                            (mbCategory.getGroupId() != groupId)) {
1240                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
1241                                                            finderArgs, mbCategory);
1242                                            }
1243                                    }
1244    
1245                                    return mbCategory;
1246                            }
1247                            catch (Exception e) {
1248                                    throw processException(e);
1249                            }
1250                            finally {
1251                                    if (result == null) {
1252                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
1253                                                    finderArgs);
1254                                    }
1255    
1256                                    closeSession(session);
1257                            }
1258                    }
1259                    else {
1260                            if (result instanceof List<?>) {
1261                                    return null;
1262                            }
1263                            else {
1264                                    return (MBCategory)result;
1265                            }
1266                    }
1267            }
1268    
1269            /**
1270             * Returns all the message boards categories where uuid = &#63; and companyId = &#63;.
1271             *
1272             * @param uuid the uuid
1273             * @param companyId the company ID
1274             * @return the matching message boards categories
1275             * @throws SystemException if a system exception occurred
1276             */
1277            public List<MBCategory> findByUuid_C(String uuid, long companyId)
1278                    throws SystemException {
1279                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
1280                            QueryUtil.ALL_POS, null);
1281            }
1282    
1283            /**
1284             * Returns a range of all the message boards categories where uuid = &#63; and companyId = &#63;.
1285             *
1286             * <p>
1287             * 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.
1288             * </p>
1289             *
1290             * @param uuid the uuid
1291             * @param companyId the company ID
1292             * @param start the lower bound of the range of message boards categories
1293             * @param end the upper bound of the range of message boards categories (not inclusive)
1294             * @return the range of matching message boards categories
1295             * @throws SystemException if a system exception occurred
1296             */
1297            public List<MBCategory> findByUuid_C(String uuid, long companyId,
1298                    int start, int end) throws SystemException {
1299                    return findByUuid_C(uuid, companyId, start, end, null);
1300            }
1301    
1302            /**
1303             * Returns an ordered range of all the message boards categories where uuid = &#63; and companyId = &#63;.
1304             *
1305             * <p>
1306             * 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.
1307             * </p>
1308             *
1309             * @param uuid the uuid
1310             * @param companyId the company ID
1311             * @param start the lower bound of the range of message boards categories
1312             * @param end the upper bound of the range of message boards categories (not inclusive)
1313             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1314             * @return the ordered range of matching message boards categories
1315             * @throws SystemException if a system exception occurred
1316             */
1317            public List<MBCategory> findByUuid_C(String uuid, long companyId,
1318                    int start, int end, OrderByComparator orderByComparator)
1319                    throws SystemException {
1320                    FinderPath finderPath = null;
1321                    Object[] finderArgs = null;
1322    
1323                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1324                                    (orderByComparator == null)) {
1325                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
1326                            finderArgs = new Object[] { uuid, companyId };
1327                    }
1328                    else {
1329                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
1330                            finderArgs = new Object[] {
1331                                            uuid, companyId,
1332                                            
1333                                            start, end, orderByComparator
1334                                    };
1335                    }
1336    
1337                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
1338                                    finderArgs, this);
1339    
1340                    if ((list != null) && !list.isEmpty()) {
1341                            for (MBCategory mbCategory : list) {
1342                                    if (!Validator.equals(uuid, mbCategory.getUuid()) ||
1343                                                    (companyId != mbCategory.getCompanyId())) {
1344                                            list = null;
1345    
1346                                            break;
1347                                    }
1348                            }
1349                    }
1350    
1351                    if (list == null) {
1352                            StringBundler query = null;
1353    
1354                            if (orderByComparator != null) {
1355                                    query = new StringBundler(4 +
1356                                                    (orderByComparator.getOrderByFields().length * 3));
1357                            }
1358                            else {
1359                                    query = new StringBundler(4);
1360                            }
1361    
1362                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1363    
1364                            if (uuid == null) {
1365                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1366                            }
1367                            else {
1368                                    if (uuid.equals(StringPool.BLANK)) {
1369                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1370                                    }
1371                                    else {
1372                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1373                                    }
1374                            }
1375    
1376                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1377    
1378                            if (orderByComparator != null) {
1379                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1380                                            orderByComparator);
1381                            }
1382    
1383                            else {
1384                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1385                            }
1386    
1387                            String sql = query.toString();
1388    
1389                            Session session = null;
1390    
1391                            try {
1392                                    session = openSession();
1393    
1394                                    Query q = session.createQuery(sql);
1395    
1396                                    QueryPos qPos = QueryPos.getInstance(q);
1397    
1398                                    if (uuid != null) {
1399                                            qPos.add(uuid);
1400                                    }
1401    
1402                                    qPos.add(companyId);
1403    
1404                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1405                                                    end);
1406                            }
1407                            catch (Exception e) {
1408                                    throw processException(e);
1409                            }
1410                            finally {
1411                                    if (list == null) {
1412                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1413                                    }
1414                                    else {
1415                                            cacheResult(list);
1416    
1417                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1418                                    }
1419    
1420                                    closeSession(session);
1421                            }
1422                    }
1423    
1424                    return list;
1425            }
1426    
1427            /**
1428             * Returns the first message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1429             *
1430             * @param uuid the uuid
1431             * @param companyId the company ID
1432             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1433             * @return the first matching message boards category
1434             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1435             * @throws SystemException if a system exception occurred
1436             */
1437            public MBCategory findByUuid_C_First(String uuid, long companyId,
1438                    OrderByComparator orderByComparator)
1439                    throws NoSuchCategoryException, SystemException {
1440                    MBCategory mbCategory = fetchByUuid_C_First(uuid, companyId,
1441                                    orderByComparator);
1442    
1443                    if (mbCategory != null) {
1444                            return mbCategory;
1445                    }
1446    
1447                    StringBundler msg = new StringBundler(6);
1448    
1449                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1450    
1451                    msg.append("uuid=");
1452                    msg.append(uuid);
1453    
1454                    msg.append(", companyId=");
1455                    msg.append(companyId);
1456    
1457                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1458    
1459                    throw new NoSuchCategoryException(msg.toString());
1460            }
1461    
1462            /**
1463             * Returns the first message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1464             *
1465             * @param uuid the uuid
1466             * @param companyId the company ID
1467             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1468             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
1469             * @throws SystemException if a system exception occurred
1470             */
1471            public MBCategory fetchByUuid_C_First(String uuid, long companyId,
1472                    OrderByComparator orderByComparator) throws SystemException {
1473                    List<MBCategory> list = findByUuid_C(uuid, companyId, 0, 1,
1474                                    orderByComparator);
1475    
1476                    if (!list.isEmpty()) {
1477                            return list.get(0);
1478                    }
1479    
1480                    return null;
1481            }
1482    
1483            /**
1484             * Returns the last message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1485             *
1486             * @param uuid the uuid
1487             * @param companyId the company ID
1488             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1489             * @return the last matching message boards category
1490             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1491             * @throws SystemException if a system exception occurred
1492             */
1493            public MBCategory findByUuid_C_Last(String uuid, long companyId,
1494                    OrderByComparator orderByComparator)
1495                    throws NoSuchCategoryException, SystemException {
1496                    MBCategory mbCategory = fetchByUuid_C_Last(uuid, companyId,
1497                                    orderByComparator);
1498    
1499                    if (mbCategory != null) {
1500                            return mbCategory;
1501                    }
1502    
1503                    StringBundler msg = new StringBundler(6);
1504    
1505                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1506    
1507                    msg.append("uuid=");
1508                    msg.append(uuid);
1509    
1510                    msg.append(", companyId=");
1511                    msg.append(companyId);
1512    
1513                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1514    
1515                    throw new NoSuchCategoryException(msg.toString());
1516            }
1517    
1518            /**
1519             * Returns the last message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1520             *
1521             * @param uuid the uuid
1522             * @param companyId the company ID
1523             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1524             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
1525             * @throws SystemException if a system exception occurred
1526             */
1527            public MBCategory fetchByUuid_C_Last(String uuid, long companyId,
1528                    OrderByComparator orderByComparator) throws SystemException {
1529                    int count = countByUuid_C(uuid, companyId);
1530    
1531                    List<MBCategory> list = findByUuid_C(uuid, companyId, count - 1, count,
1532                                    orderByComparator);
1533    
1534                    if (!list.isEmpty()) {
1535                            return list.get(0);
1536                    }
1537    
1538                    return null;
1539            }
1540    
1541            /**
1542             * Returns the message boards categories before and after the current message boards category in the ordered set where uuid = &#63; and companyId = &#63;.
1543             *
1544             * @param categoryId the primary key of the current message boards category
1545             * @param uuid the uuid
1546             * @param companyId the company ID
1547             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1548             * @return the previous, current, and next message boards category
1549             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
1550             * @throws SystemException if a system exception occurred
1551             */
1552            public MBCategory[] findByUuid_C_PrevAndNext(long categoryId, String uuid,
1553                    long companyId, OrderByComparator orderByComparator)
1554                    throws NoSuchCategoryException, SystemException {
1555                    MBCategory mbCategory = findByPrimaryKey(categoryId);
1556    
1557                    Session session = null;
1558    
1559                    try {
1560                            session = openSession();
1561    
1562                            MBCategory[] array = new MBCategoryImpl[3];
1563    
1564                            array[0] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1565                                            companyId, orderByComparator, true);
1566    
1567                            array[1] = mbCategory;
1568    
1569                            array[2] = getByUuid_C_PrevAndNext(session, mbCategory, uuid,
1570                                            companyId, orderByComparator, false);
1571    
1572                            return array;
1573                    }
1574                    catch (Exception e) {
1575                            throw processException(e);
1576                    }
1577                    finally {
1578                            closeSession(session);
1579                    }
1580            }
1581    
1582            protected MBCategory getByUuid_C_PrevAndNext(Session session,
1583                    MBCategory mbCategory, String uuid, long companyId,
1584                    OrderByComparator orderByComparator, boolean previous) {
1585                    StringBundler query = null;
1586    
1587                    if (orderByComparator != null) {
1588                            query = new StringBundler(6 +
1589                                            (orderByComparator.getOrderByFields().length * 6));
1590                    }
1591                    else {
1592                            query = new StringBundler(3);
1593                    }
1594    
1595                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1596    
1597                    if (uuid == null) {
1598                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1599                    }
1600                    else {
1601                            if (uuid.equals(StringPool.BLANK)) {
1602                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1603                            }
1604                            else {
1605                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1606                            }
1607                    }
1608    
1609                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1610    
1611                    if (orderByComparator != null) {
1612                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1613    
1614                            if (orderByConditionFields.length > 0) {
1615                                    query.append(WHERE_AND);
1616                            }
1617    
1618                            for (int i = 0; i < orderByConditionFields.length; i++) {
1619                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1620                                    query.append(orderByConditionFields[i]);
1621    
1622                                    if ((i + 1) < orderByConditionFields.length) {
1623                                            if (orderByComparator.isAscending() ^ previous) {
1624                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1625                                            }
1626                                            else {
1627                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1628                                            }
1629                                    }
1630                                    else {
1631                                            if (orderByComparator.isAscending() ^ previous) {
1632                                                    query.append(WHERE_GREATER_THAN);
1633                                            }
1634                                            else {
1635                                                    query.append(WHERE_LESSER_THAN);
1636                                            }
1637                                    }
1638                            }
1639    
1640                            query.append(ORDER_BY_CLAUSE);
1641    
1642                            String[] orderByFields = orderByComparator.getOrderByFields();
1643    
1644                            for (int i = 0; i < orderByFields.length; i++) {
1645                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1646                                    query.append(orderByFields[i]);
1647    
1648                                    if ((i + 1) < orderByFields.length) {
1649                                            if (orderByComparator.isAscending() ^ previous) {
1650                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1651                                            }
1652                                            else {
1653                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1654                                            }
1655                                    }
1656                                    else {
1657                                            if (orderByComparator.isAscending() ^ previous) {
1658                                                    query.append(ORDER_BY_ASC);
1659                                            }
1660                                            else {
1661                                                    query.append(ORDER_BY_DESC);
1662                                            }
1663                                    }
1664                            }
1665                    }
1666    
1667                    else {
1668                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1669                    }
1670    
1671                    String sql = query.toString();
1672    
1673                    Query q = session.createQuery(sql);
1674    
1675                    q.setFirstResult(0);
1676                    q.setMaxResults(2);
1677    
1678                    QueryPos qPos = QueryPos.getInstance(q);
1679    
1680                    if (uuid != null) {
1681                            qPos.add(uuid);
1682                    }
1683    
1684                    qPos.add(companyId);
1685    
1686                    if (orderByComparator != null) {
1687                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
1688    
1689                            for (Object value : values) {
1690                                    qPos.add(value);
1691                            }
1692                    }
1693    
1694                    List<MBCategory> list = q.list();
1695    
1696                    if (list.size() == 2) {
1697                            return list.get(1);
1698                    }
1699                    else {
1700                            return null;
1701                    }
1702            }
1703    
1704            /**
1705             * Returns all the message boards categories where groupId = &#63;.
1706             *
1707             * @param groupId the group ID
1708             * @return the matching message boards categories
1709             * @throws SystemException if a system exception occurred
1710             */
1711            public List<MBCategory> findByGroupId(long groupId)
1712                    throws SystemException {
1713                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1714            }
1715    
1716            /**
1717             * Returns a range of all the message boards categories where groupId = &#63;.
1718             *
1719             * <p>
1720             * 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.
1721             * </p>
1722             *
1723             * @param groupId the group ID
1724             * @param start the lower bound of the range of message boards categories
1725             * @param end the upper bound of the range of message boards categories (not inclusive)
1726             * @return the range of matching message boards categories
1727             * @throws SystemException if a system exception occurred
1728             */
1729            public List<MBCategory> findByGroupId(long groupId, int start, int end)
1730                    throws SystemException {
1731                    return findByGroupId(groupId, start, end, null);
1732            }
1733    
1734            /**
1735             * Returns an ordered range of all the message boards categories where groupId = &#63;.
1736             *
1737             * <p>
1738             * 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.
1739             * </p>
1740             *
1741             * @param groupId the group ID
1742             * @param start the lower bound of the range of message boards categories
1743             * @param end the upper bound of the range of message boards categories (not inclusive)
1744             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1745             * @return the ordered range of matching message boards categories
1746             * @throws SystemException if a system exception occurred
1747             */
1748            public List<MBCategory> findByGroupId(long groupId, int start, int end,
1749                    OrderByComparator orderByComparator) throws SystemException {
1750                    FinderPath finderPath = null;
1751                    Object[] finderArgs = null;
1752    
1753                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1754                                    (orderByComparator == null)) {
1755                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1756                            finderArgs = new Object[] { groupId };
1757                    }
1758                    else {
1759                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1760                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1761                    }
1762    
1763                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
1764                                    finderArgs, this);
1765    
1766                    if ((list != null) && !list.isEmpty()) {
1767                            for (MBCategory mbCategory : list) {
1768                                    if ((groupId != mbCategory.getGroupId())) {
1769                                            list = null;
1770    
1771                                            break;
1772                                    }
1773                            }
1774                    }
1775    
1776                    if (list == null) {
1777                            StringBundler query = null;
1778    
1779                            if (orderByComparator != null) {
1780                                    query = new StringBundler(3 +
1781                                                    (orderByComparator.getOrderByFields().length * 3));
1782                            }
1783                            else {
1784                                    query = new StringBundler(3);
1785                            }
1786    
1787                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1788    
1789                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1790    
1791                            if (orderByComparator != null) {
1792                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1793                                            orderByComparator);
1794                            }
1795    
1796                            else {
1797                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
1798                            }
1799    
1800                            String sql = query.toString();
1801    
1802                            Session session = null;
1803    
1804                            try {
1805                                    session = openSession();
1806    
1807                                    Query q = session.createQuery(sql);
1808    
1809                                    QueryPos qPos = QueryPos.getInstance(q);
1810    
1811                                    qPos.add(groupId);
1812    
1813                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
1814                                                    end);
1815                            }
1816                            catch (Exception e) {
1817                                    throw processException(e);
1818                            }
1819                            finally {
1820                                    if (list == null) {
1821                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1822                                    }
1823                                    else {
1824                                            cacheResult(list);
1825    
1826                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1827                                    }
1828    
1829                                    closeSession(session);
1830                            }
1831                    }
1832    
1833                    return list;
1834            }
1835    
1836            /**
1837             * Returns the first message boards category in the ordered set where groupId = &#63;.
1838             *
1839             * @param groupId the group ID
1840             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1841             * @return the first matching message boards category
1842             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1843             * @throws SystemException if a system exception occurred
1844             */
1845            public MBCategory findByGroupId_First(long groupId,
1846                    OrderByComparator orderByComparator)
1847                    throws NoSuchCategoryException, SystemException {
1848                    MBCategory mbCategory = fetchByGroupId_First(groupId, orderByComparator);
1849    
1850                    if (mbCategory != null) {
1851                            return mbCategory;
1852                    }
1853    
1854                    StringBundler msg = new StringBundler(4);
1855    
1856                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1857    
1858                    msg.append("groupId=");
1859                    msg.append(groupId);
1860    
1861                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1862    
1863                    throw new NoSuchCategoryException(msg.toString());
1864            }
1865    
1866            /**
1867             * Returns the first message boards category in the ordered set where groupId = &#63;.
1868             *
1869             * @param groupId the group ID
1870             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1871             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
1872             * @throws SystemException if a system exception occurred
1873             */
1874            public MBCategory fetchByGroupId_First(long groupId,
1875                    OrderByComparator orderByComparator) throws SystemException {
1876                    List<MBCategory> list = findByGroupId(groupId, 0, 1, orderByComparator);
1877    
1878                    if (!list.isEmpty()) {
1879                            return list.get(0);
1880                    }
1881    
1882                    return null;
1883            }
1884    
1885            /**
1886             * Returns the last message boards category in the ordered set where groupId = &#63;.
1887             *
1888             * @param groupId the group ID
1889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1890             * @return the last matching message boards category
1891             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
1892             * @throws SystemException if a system exception occurred
1893             */
1894            public MBCategory findByGroupId_Last(long groupId,
1895                    OrderByComparator orderByComparator)
1896                    throws NoSuchCategoryException, SystemException {
1897                    MBCategory mbCategory = fetchByGroupId_Last(groupId, orderByComparator);
1898    
1899                    if (mbCategory != null) {
1900                            return mbCategory;
1901                    }
1902    
1903                    StringBundler msg = new StringBundler(4);
1904    
1905                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1906    
1907                    msg.append("groupId=");
1908                    msg.append(groupId);
1909    
1910                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1911    
1912                    throw new NoSuchCategoryException(msg.toString());
1913            }
1914    
1915            /**
1916             * Returns the last message boards category in the ordered set where groupId = &#63;.
1917             *
1918             * @param groupId the group ID
1919             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1920             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
1921             * @throws SystemException if a system exception occurred
1922             */
1923            public MBCategory fetchByGroupId_Last(long groupId,
1924                    OrderByComparator orderByComparator) throws SystemException {
1925                    int count = countByGroupId(groupId);
1926    
1927                    List<MBCategory> list = findByGroupId(groupId, count - 1, count,
1928                                    orderByComparator);
1929    
1930                    if (!list.isEmpty()) {
1931                            return list.get(0);
1932                    }
1933    
1934                    return null;
1935            }
1936    
1937            /**
1938             * Returns the message boards categories before and after the current message boards category in the ordered set where groupId = &#63;.
1939             *
1940             * @param categoryId the primary key of the current message boards category
1941             * @param groupId the group ID
1942             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1943             * @return the previous, current, and next message boards category
1944             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
1945             * @throws SystemException if a system exception occurred
1946             */
1947            public MBCategory[] findByGroupId_PrevAndNext(long categoryId,
1948                    long groupId, OrderByComparator orderByComparator)
1949                    throws NoSuchCategoryException, SystemException {
1950                    MBCategory mbCategory = findByPrimaryKey(categoryId);
1951    
1952                    Session session = null;
1953    
1954                    try {
1955                            session = openSession();
1956    
1957                            MBCategory[] array = new MBCategoryImpl[3];
1958    
1959                            array[0] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1960                                            orderByComparator, true);
1961    
1962                            array[1] = mbCategory;
1963    
1964                            array[2] = getByGroupId_PrevAndNext(session, mbCategory, groupId,
1965                                            orderByComparator, false);
1966    
1967                            return array;
1968                    }
1969                    catch (Exception e) {
1970                            throw processException(e);
1971                    }
1972                    finally {
1973                            closeSession(session);
1974                    }
1975            }
1976    
1977            protected MBCategory getByGroupId_PrevAndNext(Session session,
1978                    MBCategory mbCategory, long groupId,
1979                    OrderByComparator orderByComparator, boolean previous) {
1980                    StringBundler query = null;
1981    
1982                    if (orderByComparator != null) {
1983                            query = new StringBundler(6 +
1984                                            (orderByComparator.getOrderByFields().length * 6));
1985                    }
1986                    else {
1987                            query = new StringBundler(3);
1988                    }
1989    
1990                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
1991    
1992                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1993    
1994                    if (orderByComparator != null) {
1995                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1996    
1997                            if (orderByConditionFields.length > 0) {
1998                                    query.append(WHERE_AND);
1999                            }
2000    
2001                            for (int i = 0; i < orderByConditionFields.length; i++) {
2002                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2003                                    query.append(orderByConditionFields[i]);
2004    
2005                                    if ((i + 1) < orderByConditionFields.length) {
2006                                            if (orderByComparator.isAscending() ^ previous) {
2007                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2008                                            }
2009                                            else {
2010                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2011                                            }
2012                                    }
2013                                    else {
2014                                            if (orderByComparator.isAscending() ^ previous) {
2015                                                    query.append(WHERE_GREATER_THAN);
2016                                            }
2017                                            else {
2018                                                    query.append(WHERE_LESSER_THAN);
2019                                            }
2020                                    }
2021                            }
2022    
2023                            query.append(ORDER_BY_CLAUSE);
2024    
2025                            String[] orderByFields = orderByComparator.getOrderByFields();
2026    
2027                            for (int i = 0; i < orderByFields.length; i++) {
2028                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2029                                    query.append(orderByFields[i]);
2030    
2031                                    if ((i + 1) < orderByFields.length) {
2032                                            if (orderByComparator.isAscending() ^ previous) {
2033                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2034                                            }
2035                                            else {
2036                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2037                                            }
2038                                    }
2039                                    else {
2040                                            if (orderByComparator.isAscending() ^ previous) {
2041                                                    query.append(ORDER_BY_ASC);
2042                                            }
2043                                            else {
2044                                                    query.append(ORDER_BY_DESC);
2045                                            }
2046                                    }
2047                            }
2048                    }
2049    
2050                    else {
2051                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2052                    }
2053    
2054                    String sql = query.toString();
2055    
2056                    Query q = session.createQuery(sql);
2057    
2058                    q.setFirstResult(0);
2059                    q.setMaxResults(2);
2060    
2061                    QueryPos qPos = QueryPos.getInstance(q);
2062    
2063                    qPos.add(groupId);
2064    
2065                    if (orderByComparator != null) {
2066                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2067    
2068                            for (Object value : values) {
2069                                    qPos.add(value);
2070                            }
2071                    }
2072    
2073                    List<MBCategory> list = q.list();
2074    
2075                    if (list.size() == 2) {
2076                            return list.get(1);
2077                    }
2078                    else {
2079                            return null;
2080                    }
2081            }
2082    
2083            /**
2084             * Returns all the message boards categories that the user has permission to view where groupId = &#63;.
2085             *
2086             * @param groupId the group ID
2087             * @return the matching message boards categories that the user has permission to view
2088             * @throws SystemException if a system exception occurred
2089             */
2090            public List<MBCategory> filterFindByGroupId(long groupId)
2091                    throws SystemException {
2092                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
2093                            QueryUtil.ALL_POS, null);
2094            }
2095    
2096            /**
2097             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63;.
2098             *
2099             * <p>
2100             * 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.
2101             * </p>
2102             *
2103             * @param groupId the group ID
2104             * @param start the lower bound of the range of message boards categories
2105             * @param end the upper bound of the range of message boards categories (not inclusive)
2106             * @return the range of matching message boards categories that the user has permission to view
2107             * @throws SystemException if a system exception occurred
2108             */
2109            public List<MBCategory> filterFindByGroupId(long groupId, int start, int end)
2110                    throws SystemException {
2111                    return filterFindByGroupId(groupId, start, end, null);
2112            }
2113    
2114            /**
2115             * Returns an ordered range of all the message boards categories that the user has permissions to view where groupId = &#63;.
2116             *
2117             * <p>
2118             * 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.
2119             * </p>
2120             *
2121             * @param groupId the group ID
2122             * @param start the lower bound of the range of message boards categories
2123             * @param end the upper bound of the range of message boards categories (not inclusive)
2124             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2125             * @return the ordered range of matching message boards categories that the user has permission to view
2126             * @throws SystemException if a system exception occurred
2127             */
2128            public List<MBCategory> filterFindByGroupId(long groupId, int start,
2129                    int end, OrderByComparator orderByComparator) throws SystemException {
2130                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2131                            return findByGroupId(groupId, start, end, orderByComparator);
2132                    }
2133    
2134                    StringBundler query = null;
2135    
2136                    if (orderByComparator != null) {
2137                            query = new StringBundler(3 +
2138                                            (orderByComparator.getOrderByFields().length * 3));
2139                    }
2140                    else {
2141                            query = new StringBundler(3);
2142                    }
2143    
2144                    if (getDB().isSupportsInlineDistinct()) {
2145                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2146                    }
2147                    else {
2148                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2149                    }
2150    
2151                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2152    
2153                    if (!getDB().isSupportsInlineDistinct()) {
2154                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2155                    }
2156    
2157                    if (orderByComparator != null) {
2158                            if (getDB().isSupportsInlineDistinct()) {
2159                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2160                                            orderByComparator);
2161                            }
2162                            else {
2163                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
2164                                            orderByComparator);
2165                            }
2166                    }
2167    
2168                    else {
2169                            if (getDB().isSupportsInlineDistinct()) {
2170                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2171                            }
2172                            else {
2173                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2174                            }
2175                    }
2176    
2177                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2178                                    MBCategory.class.getName(),
2179                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2180    
2181                    Session session = null;
2182    
2183                    try {
2184                            session = openSession();
2185    
2186                            SQLQuery q = session.createSQLQuery(sql);
2187    
2188                            if (getDB().isSupportsInlineDistinct()) {
2189                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2190                            }
2191                            else {
2192                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2193                            }
2194    
2195                            QueryPos qPos = QueryPos.getInstance(q);
2196    
2197                            qPos.add(groupId);
2198    
2199                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
2200                    }
2201                    catch (Exception e) {
2202                            throw processException(e);
2203                    }
2204                    finally {
2205                            closeSession(session);
2206                    }
2207            }
2208    
2209            /**
2210             * Returns the message boards categories before and after the current message boards category in the ordered set of message boards categories that the user has permission to view where groupId = &#63;.
2211             *
2212             * @param categoryId the primary key of the current message boards category
2213             * @param groupId the group ID
2214             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2215             * @return the previous, current, and next message boards category
2216             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
2217             * @throws SystemException if a system exception occurred
2218             */
2219            public MBCategory[] filterFindByGroupId_PrevAndNext(long categoryId,
2220                    long groupId, OrderByComparator orderByComparator)
2221                    throws NoSuchCategoryException, SystemException {
2222                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2223                            return findByGroupId_PrevAndNext(categoryId, groupId,
2224                                    orderByComparator);
2225                    }
2226    
2227                    MBCategory mbCategory = findByPrimaryKey(categoryId);
2228    
2229                    Session session = null;
2230    
2231                    try {
2232                            session = openSession();
2233    
2234                            MBCategory[] array = new MBCategoryImpl[3];
2235    
2236                            array[0] = filterGetByGroupId_PrevAndNext(session, mbCategory,
2237                                            groupId, orderByComparator, true);
2238    
2239                            array[1] = mbCategory;
2240    
2241                            array[2] = filterGetByGroupId_PrevAndNext(session, mbCategory,
2242                                            groupId, orderByComparator, false);
2243    
2244                            return array;
2245                    }
2246                    catch (Exception e) {
2247                            throw processException(e);
2248                    }
2249                    finally {
2250                            closeSession(session);
2251                    }
2252            }
2253    
2254            protected MBCategory filterGetByGroupId_PrevAndNext(Session session,
2255                    MBCategory mbCategory, long groupId,
2256                    OrderByComparator orderByComparator, boolean previous) {
2257                    StringBundler query = null;
2258    
2259                    if (orderByComparator != null) {
2260                            query = new StringBundler(6 +
2261                                            (orderByComparator.getOrderByFields().length * 6));
2262                    }
2263                    else {
2264                            query = new StringBundler(3);
2265                    }
2266    
2267                    if (getDB().isSupportsInlineDistinct()) {
2268                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
2269                    }
2270                    else {
2271                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
2272                    }
2273    
2274                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2275    
2276                    if (!getDB().isSupportsInlineDistinct()) {
2277                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
2278                    }
2279    
2280                    if (orderByComparator != null) {
2281                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2282    
2283                            if (orderByConditionFields.length > 0) {
2284                                    query.append(WHERE_AND);
2285                            }
2286    
2287                            for (int i = 0; i < orderByConditionFields.length; i++) {
2288                                    if (getDB().isSupportsInlineDistinct()) {
2289                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2290                                    }
2291                                    else {
2292                                            query.append(_ORDER_BY_ENTITY_TABLE);
2293                                    }
2294    
2295                                    query.append(orderByConditionFields[i]);
2296    
2297                                    if ((i + 1) < orderByConditionFields.length) {
2298                                            if (orderByComparator.isAscending() ^ previous) {
2299                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2300                                            }
2301                                            else {
2302                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2303                                            }
2304                                    }
2305                                    else {
2306                                            if (orderByComparator.isAscending() ^ previous) {
2307                                                    query.append(WHERE_GREATER_THAN);
2308                                            }
2309                                            else {
2310                                                    query.append(WHERE_LESSER_THAN);
2311                                            }
2312                                    }
2313                            }
2314    
2315                            query.append(ORDER_BY_CLAUSE);
2316    
2317                            String[] orderByFields = orderByComparator.getOrderByFields();
2318    
2319                            for (int i = 0; i < orderByFields.length; i++) {
2320                                    if (getDB().isSupportsInlineDistinct()) {
2321                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2322                                    }
2323                                    else {
2324                                            query.append(_ORDER_BY_ENTITY_TABLE);
2325                                    }
2326    
2327                                    query.append(orderByFields[i]);
2328    
2329                                    if ((i + 1) < orderByFields.length) {
2330                                            if (orderByComparator.isAscending() ^ previous) {
2331                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2332                                            }
2333                                            else {
2334                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2335                                            }
2336                                    }
2337                                    else {
2338                                            if (orderByComparator.isAscending() ^ previous) {
2339                                                    query.append(ORDER_BY_ASC);
2340                                            }
2341                                            else {
2342                                                    query.append(ORDER_BY_DESC);
2343                                            }
2344                                    }
2345                            }
2346                    }
2347    
2348                    else {
2349                            if (getDB().isSupportsInlineDistinct()) {
2350                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2351                            }
2352                            else {
2353                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
2354                            }
2355                    }
2356    
2357                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2358                                    MBCategory.class.getName(),
2359                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2360    
2361                    SQLQuery q = session.createSQLQuery(sql);
2362    
2363                    q.setFirstResult(0);
2364                    q.setMaxResults(2);
2365    
2366                    if (getDB().isSupportsInlineDistinct()) {
2367                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
2368                    }
2369                    else {
2370                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
2371                    }
2372    
2373                    QueryPos qPos = QueryPos.getInstance(q);
2374    
2375                    qPos.add(groupId);
2376    
2377                    if (orderByComparator != null) {
2378                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2379    
2380                            for (Object value : values) {
2381                                    qPos.add(value);
2382                            }
2383                    }
2384    
2385                    List<MBCategory> list = q.list();
2386    
2387                    if (list.size() == 2) {
2388                            return list.get(1);
2389                    }
2390                    else {
2391                            return null;
2392                    }
2393            }
2394    
2395            /**
2396             * Returns all the message boards categories where companyId = &#63;.
2397             *
2398             * @param companyId the company ID
2399             * @return the matching message boards categories
2400             * @throws SystemException if a system exception occurred
2401             */
2402            public List<MBCategory> findByCompanyId(long companyId)
2403                    throws SystemException {
2404                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2405                            null);
2406            }
2407    
2408            /**
2409             * Returns a range of all the message boards categories where companyId = &#63;.
2410             *
2411             * <p>
2412             * 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.
2413             * </p>
2414             *
2415             * @param companyId the company ID
2416             * @param start the lower bound of the range of message boards categories
2417             * @param end the upper bound of the range of message boards categories (not inclusive)
2418             * @return the range of matching message boards categories
2419             * @throws SystemException if a system exception occurred
2420             */
2421            public List<MBCategory> findByCompanyId(long companyId, int start, int end)
2422                    throws SystemException {
2423                    return findByCompanyId(companyId, start, end, null);
2424            }
2425    
2426            /**
2427             * Returns an ordered range of all the message boards categories where companyId = &#63;.
2428             *
2429             * <p>
2430             * 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.
2431             * </p>
2432             *
2433             * @param companyId the company ID
2434             * @param start the lower bound of the range of message boards categories
2435             * @param end the upper bound of the range of message boards categories (not inclusive)
2436             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2437             * @return the ordered range of matching message boards categories
2438             * @throws SystemException if a system exception occurred
2439             */
2440            public List<MBCategory> findByCompanyId(long companyId, int start, int end,
2441                    OrderByComparator orderByComparator) throws SystemException {
2442                    FinderPath finderPath = null;
2443                    Object[] finderArgs = null;
2444    
2445                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2446                                    (orderByComparator == null)) {
2447                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2448                            finderArgs = new Object[] { companyId };
2449                    }
2450                    else {
2451                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2452                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2453                    }
2454    
2455                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2456                                    finderArgs, this);
2457    
2458                    if ((list != null) && !list.isEmpty()) {
2459                            for (MBCategory mbCategory : list) {
2460                                    if ((companyId != mbCategory.getCompanyId())) {
2461                                            list = null;
2462    
2463                                            break;
2464                                    }
2465                            }
2466                    }
2467    
2468                    if (list == null) {
2469                            StringBundler query = null;
2470    
2471                            if (orderByComparator != null) {
2472                                    query = new StringBundler(3 +
2473                                                    (orderByComparator.getOrderByFields().length * 3));
2474                            }
2475                            else {
2476                                    query = new StringBundler(3);
2477                            }
2478    
2479                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2480    
2481                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2482    
2483                            if (orderByComparator != null) {
2484                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2485                                            orderByComparator);
2486                            }
2487    
2488                            else {
2489                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2490                            }
2491    
2492                            String sql = query.toString();
2493    
2494                            Session session = null;
2495    
2496                            try {
2497                                    session = openSession();
2498    
2499                                    Query q = session.createQuery(sql);
2500    
2501                                    QueryPos qPos = QueryPos.getInstance(q);
2502    
2503                                    qPos.add(companyId);
2504    
2505                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
2506                                                    end);
2507                            }
2508                            catch (Exception e) {
2509                                    throw processException(e);
2510                            }
2511                            finally {
2512                                    if (list == null) {
2513                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2514                                    }
2515                                    else {
2516                                            cacheResult(list);
2517    
2518                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2519                                    }
2520    
2521                                    closeSession(session);
2522                            }
2523                    }
2524    
2525                    return list;
2526            }
2527    
2528            /**
2529             * Returns the first message boards category in the ordered set where companyId = &#63;.
2530             *
2531             * @param companyId the company ID
2532             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2533             * @return the first matching message boards category
2534             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
2535             * @throws SystemException if a system exception occurred
2536             */
2537            public MBCategory findByCompanyId_First(long companyId,
2538                    OrderByComparator orderByComparator)
2539                    throws NoSuchCategoryException, SystemException {
2540                    MBCategory mbCategory = fetchByCompanyId_First(companyId,
2541                                    orderByComparator);
2542    
2543                    if (mbCategory != null) {
2544                            return mbCategory;
2545                    }
2546    
2547                    StringBundler msg = new StringBundler(4);
2548    
2549                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2550    
2551                    msg.append("companyId=");
2552                    msg.append(companyId);
2553    
2554                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2555    
2556                    throw new NoSuchCategoryException(msg.toString());
2557            }
2558    
2559            /**
2560             * Returns the first message boards category in the ordered set where companyId = &#63;.
2561             *
2562             * @param companyId the company ID
2563             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2564             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
2565             * @throws SystemException if a system exception occurred
2566             */
2567            public MBCategory fetchByCompanyId_First(long companyId,
2568                    OrderByComparator orderByComparator) throws SystemException {
2569                    List<MBCategory> list = findByCompanyId(companyId, 0, 1,
2570                                    orderByComparator);
2571    
2572                    if (!list.isEmpty()) {
2573                            return list.get(0);
2574                    }
2575    
2576                    return null;
2577            }
2578    
2579            /**
2580             * Returns the last message boards category in the ordered set where companyId = &#63;.
2581             *
2582             * @param companyId the company ID
2583             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2584             * @return the last matching message boards category
2585             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
2586             * @throws SystemException if a system exception occurred
2587             */
2588            public MBCategory findByCompanyId_Last(long companyId,
2589                    OrderByComparator orderByComparator)
2590                    throws NoSuchCategoryException, SystemException {
2591                    MBCategory mbCategory = fetchByCompanyId_Last(companyId,
2592                                    orderByComparator);
2593    
2594                    if (mbCategory != null) {
2595                            return mbCategory;
2596                    }
2597    
2598                    StringBundler msg = new StringBundler(4);
2599    
2600                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2601    
2602                    msg.append("companyId=");
2603                    msg.append(companyId);
2604    
2605                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2606    
2607                    throw new NoSuchCategoryException(msg.toString());
2608            }
2609    
2610            /**
2611             * Returns the last message boards category in the ordered set where companyId = &#63;.
2612             *
2613             * @param companyId the company ID
2614             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2615             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
2616             * @throws SystemException if a system exception occurred
2617             */
2618            public MBCategory fetchByCompanyId_Last(long companyId,
2619                    OrderByComparator orderByComparator) throws SystemException {
2620                    int count = countByCompanyId(companyId);
2621    
2622                    List<MBCategory> list = findByCompanyId(companyId, count - 1, count,
2623                                    orderByComparator);
2624    
2625                    if (!list.isEmpty()) {
2626                            return list.get(0);
2627                    }
2628    
2629                    return null;
2630            }
2631    
2632            /**
2633             * Returns the message boards categories before and after the current message boards category in the ordered set where companyId = &#63;.
2634             *
2635             * @param categoryId the primary key of the current message boards category
2636             * @param companyId the company ID
2637             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2638             * @return the previous, current, and next message boards category
2639             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
2640             * @throws SystemException if a system exception occurred
2641             */
2642            public MBCategory[] findByCompanyId_PrevAndNext(long categoryId,
2643                    long companyId, OrderByComparator orderByComparator)
2644                    throws NoSuchCategoryException, SystemException {
2645                    MBCategory mbCategory = findByPrimaryKey(categoryId);
2646    
2647                    Session session = null;
2648    
2649                    try {
2650                            session = openSession();
2651    
2652                            MBCategory[] array = new MBCategoryImpl[3];
2653    
2654                            array[0] = getByCompanyId_PrevAndNext(session, mbCategory,
2655                                            companyId, orderByComparator, true);
2656    
2657                            array[1] = mbCategory;
2658    
2659                            array[2] = getByCompanyId_PrevAndNext(session, mbCategory,
2660                                            companyId, orderByComparator, false);
2661    
2662                            return array;
2663                    }
2664                    catch (Exception e) {
2665                            throw processException(e);
2666                    }
2667                    finally {
2668                            closeSession(session);
2669                    }
2670            }
2671    
2672            protected MBCategory getByCompanyId_PrevAndNext(Session session,
2673                    MBCategory mbCategory, long companyId,
2674                    OrderByComparator orderByComparator, boolean previous) {
2675                    StringBundler query = null;
2676    
2677                    if (orderByComparator != null) {
2678                            query = new StringBundler(6 +
2679                                            (orderByComparator.getOrderByFields().length * 6));
2680                    }
2681                    else {
2682                            query = new StringBundler(3);
2683                    }
2684    
2685                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2686    
2687                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2688    
2689                    if (orderByComparator != null) {
2690                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2691    
2692                            if (orderByConditionFields.length > 0) {
2693                                    query.append(WHERE_AND);
2694                            }
2695    
2696                            for (int i = 0; i < orderByConditionFields.length; i++) {
2697                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2698                                    query.append(orderByConditionFields[i]);
2699    
2700                                    if ((i + 1) < orderByConditionFields.length) {
2701                                            if (orderByComparator.isAscending() ^ previous) {
2702                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2703                                            }
2704                                            else {
2705                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2706                                            }
2707                                    }
2708                                    else {
2709                                            if (orderByComparator.isAscending() ^ previous) {
2710                                                    query.append(WHERE_GREATER_THAN);
2711                                            }
2712                                            else {
2713                                                    query.append(WHERE_LESSER_THAN);
2714                                            }
2715                                    }
2716                            }
2717    
2718                            query.append(ORDER_BY_CLAUSE);
2719    
2720                            String[] orderByFields = orderByComparator.getOrderByFields();
2721    
2722                            for (int i = 0; i < orderByFields.length; i++) {
2723                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2724                                    query.append(orderByFields[i]);
2725    
2726                                    if ((i + 1) < orderByFields.length) {
2727                                            if (orderByComparator.isAscending() ^ previous) {
2728                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2729                                            }
2730                                            else {
2731                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2732                                            }
2733                                    }
2734                                    else {
2735                                            if (orderByComparator.isAscending() ^ previous) {
2736                                                    query.append(ORDER_BY_ASC);
2737                                            }
2738                                            else {
2739                                                    query.append(ORDER_BY_DESC);
2740                                            }
2741                                    }
2742                            }
2743                    }
2744    
2745                    else {
2746                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2747                    }
2748    
2749                    String sql = query.toString();
2750    
2751                    Query q = session.createQuery(sql);
2752    
2753                    q.setFirstResult(0);
2754                    q.setMaxResults(2);
2755    
2756                    QueryPos qPos = QueryPos.getInstance(q);
2757    
2758                    qPos.add(companyId);
2759    
2760                    if (orderByComparator != null) {
2761                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
2762    
2763                            for (Object value : values) {
2764                                    qPos.add(value);
2765                            }
2766                    }
2767    
2768                    List<MBCategory> list = q.list();
2769    
2770                    if (list.size() == 2) {
2771                            return list.get(1);
2772                    }
2773                    else {
2774                            return null;
2775                    }
2776            }
2777    
2778            /**
2779             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2780             *
2781             * @param groupId the group ID
2782             * @param parentCategoryId the parent category ID
2783             * @return the matching message boards categories
2784             * @throws SystemException if a system exception occurred
2785             */
2786            public List<MBCategory> findByG_P(long groupId, long parentCategoryId)
2787                    throws SystemException {
2788                    return findByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
2789                            QueryUtil.ALL_POS, null);
2790            }
2791    
2792            /**
2793             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2794             *
2795             * <p>
2796             * 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.
2797             * </p>
2798             *
2799             * @param groupId the group ID
2800             * @param parentCategoryId the parent category ID
2801             * @param start the lower bound of the range of message boards categories
2802             * @param end the upper bound of the range of message boards categories (not inclusive)
2803             * @return the range of matching message boards categories
2804             * @throws SystemException if a system exception occurred
2805             */
2806            public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2807                    int start, int end) throws SystemException {
2808                    return findByG_P(groupId, parentCategoryId, start, end, null);
2809            }
2810    
2811            /**
2812             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = &#63;.
2813             *
2814             * <p>
2815             * 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.
2816             * </p>
2817             *
2818             * @param groupId the group ID
2819             * @param parentCategoryId the parent category ID
2820             * @param start the lower bound of the range of message boards categories
2821             * @param end the upper bound of the range of message boards categories (not inclusive)
2822             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2823             * @return the ordered range of matching message boards categories
2824             * @throws SystemException if a system exception occurred
2825             */
2826            public List<MBCategory> findByG_P(long groupId, long parentCategoryId,
2827                    int start, int end, OrderByComparator orderByComparator)
2828                    throws SystemException {
2829                    FinderPath finderPath = null;
2830                    Object[] finderArgs = null;
2831    
2832                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2833                                    (orderByComparator == null)) {
2834                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_P;
2835                            finderArgs = new Object[] { groupId, parentCategoryId };
2836                    }
2837                    else {
2838                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
2839                            finderArgs = new Object[] {
2840                                            groupId, parentCategoryId,
2841                                            
2842                                            start, end, orderByComparator
2843                                    };
2844                    }
2845    
2846                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
2847                                    finderArgs, this);
2848    
2849                    if ((list != null) && !list.isEmpty()) {
2850                            for (MBCategory mbCategory : list) {
2851                                    if ((groupId != mbCategory.getGroupId()) ||
2852                                                    (parentCategoryId != mbCategory.getParentCategoryId())) {
2853                                            list = null;
2854    
2855                                            break;
2856                                    }
2857                            }
2858                    }
2859    
2860                    if (list == null) {
2861                            StringBundler query = null;
2862    
2863                            if (orderByComparator != null) {
2864                                    query = new StringBundler(4 +
2865                                                    (orderByComparator.getOrderByFields().length * 3));
2866                            }
2867                            else {
2868                                    query = new StringBundler(4);
2869                            }
2870    
2871                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
2872    
2873                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
2874    
2875                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
2876    
2877                            if (orderByComparator != null) {
2878                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2879                                            orderByComparator);
2880                            }
2881    
2882                            else {
2883                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
2884                            }
2885    
2886                            String sql = query.toString();
2887    
2888                            Session session = null;
2889    
2890                            try {
2891                                    session = openSession();
2892    
2893                                    Query q = session.createQuery(sql);
2894    
2895                                    QueryPos qPos = QueryPos.getInstance(q);
2896    
2897                                    qPos.add(groupId);
2898    
2899                                    qPos.add(parentCategoryId);
2900    
2901                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
2902                                                    end);
2903                            }
2904                            catch (Exception e) {
2905                                    throw processException(e);
2906                            }
2907                            finally {
2908                                    if (list == null) {
2909                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
2910                                    }
2911                                    else {
2912                                            cacheResult(list);
2913    
2914                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
2915                                    }
2916    
2917                                    closeSession(session);
2918                            }
2919                    }
2920    
2921                    return list;
2922            }
2923    
2924            /**
2925             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
2926             *
2927             * @param groupId the group ID
2928             * @param parentCategoryId the parent category ID
2929             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2930             * @return the first matching message boards category
2931             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
2932             * @throws SystemException if a system exception occurred
2933             */
2934            public MBCategory findByG_P_First(long groupId, long parentCategoryId,
2935                    OrderByComparator orderByComparator)
2936                    throws NoSuchCategoryException, SystemException {
2937                    MBCategory mbCategory = fetchByG_P_First(groupId, parentCategoryId,
2938                                    orderByComparator);
2939    
2940                    if (mbCategory != null) {
2941                            return mbCategory;
2942                    }
2943    
2944                    StringBundler msg = new StringBundler(6);
2945    
2946                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2947    
2948                    msg.append("groupId=");
2949                    msg.append(groupId);
2950    
2951                    msg.append(", parentCategoryId=");
2952                    msg.append(parentCategoryId);
2953    
2954                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2955    
2956                    throw new NoSuchCategoryException(msg.toString());
2957            }
2958    
2959            /**
2960             * Returns the first message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
2961             *
2962             * @param groupId the group ID
2963             * @param parentCategoryId the parent category ID
2964             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2965             * @return the first matching message boards category, or <code>null</code> if a matching message boards category could not be found
2966             * @throws SystemException if a system exception occurred
2967             */
2968            public MBCategory fetchByG_P_First(long groupId, long parentCategoryId,
2969                    OrderByComparator orderByComparator) throws SystemException {
2970                    List<MBCategory> list = findByG_P(groupId, parentCategoryId, 0, 1,
2971                                    orderByComparator);
2972    
2973                    if (!list.isEmpty()) {
2974                            return list.get(0);
2975                    }
2976    
2977                    return null;
2978            }
2979    
2980            /**
2981             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
2982             *
2983             * @param groupId the group ID
2984             * @param parentCategoryId the parent category ID
2985             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2986             * @return the last matching message boards category
2987             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a matching message boards category could not be found
2988             * @throws SystemException if a system exception occurred
2989             */
2990            public MBCategory findByG_P_Last(long groupId, long parentCategoryId,
2991                    OrderByComparator orderByComparator)
2992                    throws NoSuchCategoryException, SystemException {
2993                    MBCategory mbCategory = fetchByG_P_Last(groupId, parentCategoryId,
2994                                    orderByComparator);
2995    
2996                    if (mbCategory != null) {
2997                            return mbCategory;
2998                    }
2999    
3000                    StringBundler msg = new StringBundler(6);
3001    
3002                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3003    
3004                    msg.append("groupId=");
3005                    msg.append(groupId);
3006    
3007                    msg.append(", parentCategoryId=");
3008                    msg.append(parentCategoryId);
3009    
3010                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3011    
3012                    throw new NoSuchCategoryException(msg.toString());
3013            }
3014    
3015            /**
3016             * Returns the last message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3017             *
3018             * @param groupId the group ID
3019             * @param parentCategoryId the parent category ID
3020             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3021             * @return the last matching message boards category, or <code>null</code> if a matching message boards category could not be found
3022             * @throws SystemException if a system exception occurred
3023             */
3024            public MBCategory fetchByG_P_Last(long groupId, long parentCategoryId,
3025                    OrderByComparator orderByComparator) throws SystemException {
3026                    int count = countByG_P(groupId, parentCategoryId);
3027    
3028                    List<MBCategory> list = findByG_P(groupId, parentCategoryId, count - 1,
3029                                    count, orderByComparator);
3030    
3031                    if (!list.isEmpty()) {
3032                            return list.get(0);
3033                    }
3034    
3035                    return null;
3036            }
3037    
3038            /**
3039             * Returns the message boards categories before and after the current message boards category in the ordered set where groupId = &#63; and parentCategoryId = &#63;.
3040             *
3041             * @param categoryId the primary key of the current message boards category
3042             * @param groupId the group ID
3043             * @param parentCategoryId the parent category ID
3044             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3045             * @return the previous, current, and next message boards category
3046             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
3047             * @throws SystemException if a system exception occurred
3048             */
3049            public MBCategory[] findByG_P_PrevAndNext(long categoryId, long groupId,
3050                    long parentCategoryId, OrderByComparator orderByComparator)
3051                    throws NoSuchCategoryException, SystemException {
3052                    MBCategory mbCategory = findByPrimaryKey(categoryId);
3053    
3054                    Session session = null;
3055    
3056                    try {
3057                            session = openSession();
3058    
3059                            MBCategory[] array = new MBCategoryImpl[3];
3060    
3061                            array[0] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3062                                            parentCategoryId, orderByComparator, true);
3063    
3064                            array[1] = mbCategory;
3065    
3066                            array[2] = getByG_P_PrevAndNext(session, mbCategory, groupId,
3067                                            parentCategoryId, orderByComparator, false);
3068    
3069                            return array;
3070                    }
3071                    catch (Exception e) {
3072                            throw processException(e);
3073                    }
3074                    finally {
3075                            closeSession(session);
3076                    }
3077            }
3078    
3079            protected MBCategory getByG_P_PrevAndNext(Session session,
3080                    MBCategory mbCategory, long groupId, long parentCategoryId,
3081                    OrderByComparator orderByComparator, boolean previous) {
3082                    StringBundler query = null;
3083    
3084                    if (orderByComparator != null) {
3085                            query = new StringBundler(6 +
3086                                            (orderByComparator.getOrderByFields().length * 6));
3087                    }
3088                    else {
3089                            query = new StringBundler(3);
3090                    }
3091    
3092                    query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3093    
3094                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3095    
3096                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3097    
3098                    if (orderByComparator != null) {
3099                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3100    
3101                            if (orderByConditionFields.length > 0) {
3102                                    query.append(WHERE_AND);
3103                            }
3104    
3105                            for (int i = 0; i < orderByConditionFields.length; i++) {
3106                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3107                                    query.append(orderByConditionFields[i]);
3108    
3109                                    if ((i + 1) < orderByConditionFields.length) {
3110                                            if (orderByComparator.isAscending() ^ previous) {
3111                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3112                                            }
3113                                            else {
3114                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3115                                            }
3116                                    }
3117                                    else {
3118                                            if (orderByComparator.isAscending() ^ previous) {
3119                                                    query.append(WHERE_GREATER_THAN);
3120                                            }
3121                                            else {
3122                                                    query.append(WHERE_LESSER_THAN);
3123                                            }
3124                                    }
3125                            }
3126    
3127                            query.append(ORDER_BY_CLAUSE);
3128    
3129                            String[] orderByFields = orderByComparator.getOrderByFields();
3130    
3131                            for (int i = 0; i < orderByFields.length; i++) {
3132                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3133                                    query.append(orderByFields[i]);
3134    
3135                                    if ((i + 1) < orderByFields.length) {
3136                                            if (orderByComparator.isAscending() ^ previous) {
3137                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3138                                            }
3139                                            else {
3140                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3141                                            }
3142                                    }
3143                                    else {
3144                                            if (orderByComparator.isAscending() ^ previous) {
3145                                                    query.append(ORDER_BY_ASC);
3146                                            }
3147                                            else {
3148                                                    query.append(ORDER_BY_DESC);
3149                                            }
3150                                    }
3151                            }
3152                    }
3153    
3154                    else {
3155                            query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3156                    }
3157    
3158                    String sql = query.toString();
3159    
3160                    Query q = session.createQuery(sql);
3161    
3162                    q.setFirstResult(0);
3163                    q.setMaxResults(2);
3164    
3165                    QueryPos qPos = QueryPos.getInstance(q);
3166    
3167                    qPos.add(groupId);
3168    
3169                    qPos.add(parentCategoryId);
3170    
3171                    if (orderByComparator != null) {
3172                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3173    
3174                            for (Object value : values) {
3175                                    qPos.add(value);
3176                            }
3177                    }
3178    
3179                    List<MBCategory> list = q.list();
3180    
3181                    if (list.size() == 2) {
3182                            return list.get(1);
3183                    }
3184                    else {
3185                            return null;
3186                    }
3187            }
3188    
3189            /**
3190             * Returns all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3191             *
3192             * <p>
3193             * 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.
3194             * </p>
3195             *
3196             * @param groupId the group ID
3197             * @param parentCategoryIds the parent category IDs
3198             * @return the matching message boards categories
3199             * @throws SystemException if a system exception occurred
3200             */
3201            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds)
3202                    throws SystemException {
3203                    return findByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3204                            QueryUtil.ALL_POS, null);
3205            }
3206    
3207            /**
3208             * Returns a range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3209             *
3210             * <p>
3211             * 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.
3212             * </p>
3213             *
3214             * @param groupId the group ID
3215             * @param parentCategoryIds the parent category IDs
3216             * @param start the lower bound of the range of message boards categories
3217             * @param end the upper bound of the range of message boards categories (not inclusive)
3218             * @return the range of matching message boards categories
3219             * @throws SystemException if a system exception occurred
3220             */
3221            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3222                    int start, int end) throws SystemException {
3223                    return findByG_P(groupId, parentCategoryIds, start, end, null);
3224            }
3225    
3226            /**
3227             * Returns an ordered range of all the message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
3228             *
3229             * <p>
3230             * 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.
3231             * </p>
3232             *
3233             * @param groupId the group ID
3234             * @param parentCategoryIds the parent category IDs
3235             * @param start the lower bound of the range of message boards categories
3236             * @param end the upper bound of the range of message boards categories (not inclusive)
3237             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3238             * @return the ordered range of matching message boards categories
3239             * @throws SystemException if a system exception occurred
3240             */
3241            public List<MBCategory> findByG_P(long groupId, long[] parentCategoryIds,
3242                    int start, int end, OrderByComparator orderByComparator)
3243                    throws SystemException {
3244                    FinderPath finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_P;
3245                    Object[] finderArgs = null;
3246    
3247                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3248                                    (orderByComparator == null)) {
3249                            finderArgs = new Object[] {
3250                                            groupId, StringUtil.merge(parentCategoryIds)
3251                                    };
3252                    }
3253                    else {
3254                            finderArgs = new Object[] {
3255                                            groupId, StringUtil.merge(parentCategoryIds),
3256                                            
3257                                            start, end, orderByComparator
3258                                    };
3259                    }
3260    
3261                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
3262                                    finderArgs, this);
3263    
3264                    if ((list != null) && !list.isEmpty()) {
3265                            for (MBCategory mbCategory : list) {
3266                                    if ((groupId != mbCategory.getGroupId()) ||
3267                                                    !ArrayUtil.contains(parentCategoryIds,
3268                                                            mbCategory.getParentCategoryId())) {
3269                                            list = null;
3270    
3271                                            break;
3272                                    }
3273                            }
3274                    }
3275    
3276                    if (list == null) {
3277                            StringBundler query = new StringBundler();
3278    
3279                            query.append(_SQL_SELECT_MBCATEGORY_WHERE);
3280    
3281                            boolean conjunctionable = false;
3282    
3283                            if (conjunctionable) {
3284                                    query.append(WHERE_AND);
3285                            }
3286    
3287                            query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3288    
3289                            conjunctionable = true;
3290    
3291                            if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3292                                    if (conjunctionable) {
3293                                            query.append(WHERE_AND);
3294                                    }
3295    
3296                                    query.append(StringPool.OPEN_PARENTHESIS);
3297    
3298                                    for (int i = 0; i < parentCategoryIds.length; i++) {
3299                                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3300    
3301                                            if ((i + 1) < parentCategoryIds.length) {
3302                                                    query.append(WHERE_OR);
3303                                            }
3304                                    }
3305    
3306                                    query.append(StringPool.CLOSE_PARENTHESIS);
3307    
3308                                    conjunctionable = true;
3309                            }
3310    
3311                            if (orderByComparator != null) {
3312                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3313                                            orderByComparator);
3314                            }
3315    
3316                            else {
3317                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3318                            }
3319    
3320                            String sql = query.toString();
3321    
3322                            Session session = null;
3323    
3324                            try {
3325                                    session = openSession();
3326    
3327                                    Query q = session.createQuery(sql);
3328    
3329                                    QueryPos qPos = QueryPos.getInstance(q);
3330    
3331                                    qPos.add(groupId);
3332    
3333                                    if (parentCategoryIds != null) {
3334                                            qPos.add(parentCategoryIds);
3335                                    }
3336    
3337                                    list = (List<MBCategory>)QueryUtil.list(q, getDialect(), start,
3338                                                    end);
3339                            }
3340                            catch (Exception e) {
3341                                    throw processException(e);
3342                            }
3343                            finally {
3344                                    if (list == null) {
3345                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3346                                    }
3347                                    else {
3348                                            cacheResult(list);
3349    
3350                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3351                                    }
3352    
3353                                    closeSession(session);
3354                            }
3355                    }
3356    
3357                    return list;
3358            }
3359    
3360            /**
3361             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
3362             *
3363             * @param groupId the group ID
3364             * @param parentCategoryId the parent category ID
3365             * @return the matching message boards categories that the user has permission to view
3366             * @throws SystemException if a system exception occurred
3367             */
3368            public List<MBCategory> filterFindByG_P(long groupId, long parentCategoryId)
3369                    throws SystemException {
3370                    return filterFindByG_P(groupId, parentCategoryId, QueryUtil.ALL_POS,
3371                            QueryUtil.ALL_POS, null);
3372            }
3373    
3374            /**
3375             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
3376             *
3377             * <p>
3378             * 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.
3379             * </p>
3380             *
3381             * @param groupId the group ID
3382             * @param parentCategoryId the parent category ID
3383             * @param start the lower bound of the range of message boards categories
3384             * @param end the upper bound of the range of message boards categories (not inclusive)
3385             * @return the range of matching message boards categories that the user has permission to view
3386             * @throws SystemException if a system exception occurred
3387             */
3388            public List<MBCategory> filterFindByG_P(long groupId,
3389                    long parentCategoryId, int start, int end) throws SystemException {
3390                    return filterFindByG_P(groupId, parentCategoryId, start, end, null);
3391            }
3392    
3393            /**
3394             * Returns an ordered range of all the message boards categories that the user has permissions to view where groupId = &#63; and parentCategoryId = &#63;.
3395             *
3396             * <p>
3397             * 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.
3398             * </p>
3399             *
3400             * @param groupId the group ID
3401             * @param parentCategoryId the parent category ID
3402             * @param start the lower bound of the range of message boards categories
3403             * @param end the upper bound of the range of message boards categories (not inclusive)
3404             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3405             * @return the ordered range of matching message boards categories that the user has permission to view
3406             * @throws SystemException if a system exception occurred
3407             */
3408            public List<MBCategory> filterFindByG_P(long groupId,
3409                    long parentCategoryId, int start, int end,
3410                    OrderByComparator orderByComparator) throws SystemException {
3411                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3412                            return findByG_P(groupId, parentCategoryId, start, end,
3413                                    orderByComparator);
3414                    }
3415    
3416                    StringBundler query = null;
3417    
3418                    if (orderByComparator != null) {
3419                            query = new StringBundler(4 +
3420                                            (orderByComparator.getOrderByFields().length * 3));
3421                    }
3422                    else {
3423                            query = new StringBundler(4);
3424                    }
3425    
3426                    if (getDB().isSupportsInlineDistinct()) {
3427                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3428                    }
3429                    else {
3430                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3431                    }
3432    
3433                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3434    
3435                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3436    
3437                    if (!getDB().isSupportsInlineDistinct()) {
3438                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3439                    }
3440    
3441                    if (orderByComparator != null) {
3442                            if (getDB().isSupportsInlineDistinct()) {
3443                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3444                                            orderByComparator);
3445                            }
3446                            else {
3447                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3448                                            orderByComparator);
3449                            }
3450                    }
3451    
3452                    else {
3453                            if (getDB().isSupportsInlineDistinct()) {
3454                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3455                            }
3456                            else {
3457                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3458                            }
3459                    }
3460    
3461                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3462                                    MBCategory.class.getName(),
3463                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3464    
3465                    Session session = null;
3466    
3467                    try {
3468                            session = openSession();
3469    
3470                            SQLQuery q = session.createSQLQuery(sql);
3471    
3472                            if (getDB().isSupportsInlineDistinct()) {
3473                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3474                            }
3475                            else {
3476                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3477                            }
3478    
3479                            QueryPos qPos = QueryPos.getInstance(q);
3480    
3481                            qPos.add(groupId);
3482    
3483                            qPos.add(parentCategoryId);
3484    
3485                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3486                    }
3487                    catch (Exception e) {
3488                            throw processException(e);
3489                    }
3490                    finally {
3491                            closeSession(session);
3492                    }
3493            }
3494    
3495            /**
3496             * Returns the message boards categories before and after the current message boards category in the ordered set of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
3497             *
3498             * @param categoryId the primary key of the current message boards category
3499             * @param groupId the group ID
3500             * @param parentCategoryId the parent category ID
3501             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3502             * @return the previous, current, and next message boards category
3503             * @throws com.liferay.portlet.messageboards.NoSuchCategoryException if a message boards category with the primary key could not be found
3504             * @throws SystemException if a system exception occurred
3505             */
3506            public MBCategory[] filterFindByG_P_PrevAndNext(long categoryId,
3507                    long groupId, long parentCategoryId, OrderByComparator orderByComparator)
3508                    throws NoSuchCategoryException, SystemException {
3509                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3510                            return findByG_P_PrevAndNext(categoryId, groupId, parentCategoryId,
3511                                    orderByComparator);
3512                    }
3513    
3514                    MBCategory mbCategory = findByPrimaryKey(categoryId);
3515    
3516                    Session session = null;
3517    
3518                    try {
3519                            session = openSession();
3520    
3521                            MBCategory[] array = new MBCategoryImpl[3];
3522    
3523                            array[0] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3524                                            parentCategoryId, orderByComparator, true);
3525    
3526                            array[1] = mbCategory;
3527    
3528                            array[2] = filterGetByG_P_PrevAndNext(session, mbCategory, groupId,
3529                                            parentCategoryId, orderByComparator, false);
3530    
3531                            return array;
3532                    }
3533                    catch (Exception e) {
3534                            throw processException(e);
3535                    }
3536                    finally {
3537                            closeSession(session);
3538                    }
3539            }
3540    
3541            protected MBCategory filterGetByG_P_PrevAndNext(Session session,
3542                    MBCategory mbCategory, long groupId, long parentCategoryId,
3543                    OrderByComparator orderByComparator, boolean previous) {
3544                    StringBundler query = null;
3545    
3546                    if (orderByComparator != null) {
3547                            query = new StringBundler(6 +
3548                                            (orderByComparator.getOrderByFields().length * 6));
3549                    }
3550                    else {
3551                            query = new StringBundler(3);
3552                    }
3553    
3554                    if (getDB().isSupportsInlineDistinct()) {
3555                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3556                    }
3557                    else {
3558                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3559                    }
3560    
3561                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
3562    
3563                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
3564    
3565                    if (!getDB().isSupportsInlineDistinct()) {
3566                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3567                    }
3568    
3569                    if (orderByComparator != null) {
3570                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3571    
3572                            if (orderByConditionFields.length > 0) {
3573                                    query.append(WHERE_AND);
3574                            }
3575    
3576                            for (int i = 0; i < orderByConditionFields.length; i++) {
3577                                    if (getDB().isSupportsInlineDistinct()) {
3578                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3579                                    }
3580                                    else {
3581                                            query.append(_ORDER_BY_ENTITY_TABLE);
3582                                    }
3583    
3584                                    query.append(orderByConditionFields[i]);
3585    
3586                                    if ((i + 1) < orderByConditionFields.length) {
3587                                            if (orderByComparator.isAscending() ^ previous) {
3588                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3589                                            }
3590                                            else {
3591                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3592                                            }
3593                                    }
3594                                    else {
3595                                            if (orderByComparator.isAscending() ^ previous) {
3596                                                    query.append(WHERE_GREATER_THAN);
3597                                            }
3598                                            else {
3599                                                    query.append(WHERE_LESSER_THAN);
3600                                            }
3601                                    }
3602                            }
3603    
3604                            query.append(ORDER_BY_CLAUSE);
3605    
3606                            String[] orderByFields = orderByComparator.getOrderByFields();
3607    
3608                            for (int i = 0; i < orderByFields.length; i++) {
3609                                    if (getDB().isSupportsInlineDistinct()) {
3610                                            query.append(_ORDER_BY_ENTITY_ALIAS);
3611                                    }
3612                                    else {
3613                                            query.append(_ORDER_BY_ENTITY_TABLE);
3614                                    }
3615    
3616                                    query.append(orderByFields[i]);
3617    
3618                                    if ((i + 1) < orderByFields.length) {
3619                                            if (orderByComparator.isAscending() ^ previous) {
3620                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3621                                            }
3622                                            else {
3623                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3624                                            }
3625                                    }
3626                                    else {
3627                                            if (orderByComparator.isAscending() ^ previous) {
3628                                                    query.append(ORDER_BY_ASC);
3629                                            }
3630                                            else {
3631                                                    query.append(ORDER_BY_DESC);
3632                                            }
3633                                    }
3634                            }
3635                    }
3636    
3637                    else {
3638                            if (getDB().isSupportsInlineDistinct()) {
3639                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3640                            }
3641                            else {
3642                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3643                            }
3644                    }
3645    
3646                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3647                                    MBCategory.class.getName(),
3648                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3649    
3650                    SQLQuery q = session.createSQLQuery(sql);
3651    
3652                    q.setFirstResult(0);
3653                    q.setMaxResults(2);
3654    
3655                    if (getDB().isSupportsInlineDistinct()) {
3656                            q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3657                    }
3658                    else {
3659                            q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3660                    }
3661    
3662                    QueryPos qPos = QueryPos.getInstance(q);
3663    
3664                    qPos.add(groupId);
3665    
3666                    qPos.add(parentCategoryId);
3667    
3668                    if (orderByComparator != null) {
3669                            Object[] values = orderByComparator.getOrderByConditionValues(mbCategory);
3670    
3671                            for (Object value : values) {
3672                                    qPos.add(value);
3673                            }
3674                    }
3675    
3676                    List<MBCategory> list = q.list();
3677    
3678                    if (list.size() == 2) {
3679                            return list.get(1);
3680                    }
3681                    else {
3682                            return null;
3683                    }
3684            }
3685    
3686            /**
3687             * Returns all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
3688             *
3689             * @param groupId the group ID
3690             * @param parentCategoryIds the parent category IDs
3691             * @return the matching message boards categories that the user has permission to view
3692             * @throws SystemException if a system exception occurred
3693             */
3694            public List<MBCategory> filterFindByG_P(long groupId,
3695                    long[] parentCategoryIds) throws SystemException {
3696                    return filterFindByG_P(groupId, parentCategoryIds, QueryUtil.ALL_POS,
3697                            QueryUtil.ALL_POS, null);
3698            }
3699    
3700            /**
3701             * Returns a range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
3702             *
3703             * <p>
3704             * 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.
3705             * </p>
3706             *
3707             * @param groupId the group ID
3708             * @param parentCategoryIds the parent category IDs
3709             * @param start the lower bound of the range of message boards categories
3710             * @param end the upper bound of the range of message boards categories (not inclusive)
3711             * @return the range of matching message boards categories that the user has permission to view
3712             * @throws SystemException if a system exception occurred
3713             */
3714            public List<MBCategory> filterFindByG_P(long groupId,
3715                    long[] parentCategoryIds, int start, int end) throws SystemException {
3716                    return filterFindByG_P(groupId, parentCategoryIds, start, end, null);
3717            }
3718    
3719            /**
3720             * Returns an ordered range of all the message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
3721             *
3722             * <p>
3723             * 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.
3724             * </p>
3725             *
3726             * @param groupId the group ID
3727             * @param parentCategoryIds the parent category IDs
3728             * @param start the lower bound of the range of message boards categories
3729             * @param end the upper bound of the range of message boards categories (not inclusive)
3730             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3731             * @return the ordered range of matching message boards categories that the user has permission to view
3732             * @throws SystemException if a system exception occurred
3733             */
3734            public List<MBCategory> filterFindByG_P(long groupId,
3735                    long[] parentCategoryIds, int start, int end,
3736                    OrderByComparator orderByComparator) throws SystemException {
3737                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
3738                            return findByG_P(groupId, parentCategoryIds, start, end,
3739                                    orderByComparator);
3740                    }
3741    
3742                    StringBundler query = new StringBundler();
3743    
3744                    if (getDB().isSupportsInlineDistinct()) {
3745                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_WHERE);
3746                    }
3747                    else {
3748                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1);
3749                    }
3750    
3751                    boolean conjunctionable = false;
3752    
3753                    if (conjunctionable) {
3754                            query.append(WHERE_AND);
3755                    }
3756    
3757                    query.append(_FINDER_COLUMN_G_P_GROUPID_5);
3758    
3759                    conjunctionable = true;
3760    
3761                    if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
3762                            if (conjunctionable) {
3763                                    query.append(WHERE_AND);
3764                            }
3765    
3766                            query.append(StringPool.OPEN_PARENTHESIS);
3767    
3768                            for (int i = 0; i < parentCategoryIds.length; i++) {
3769                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
3770    
3771                                    if ((i + 1) < parentCategoryIds.length) {
3772                                            query.append(WHERE_OR);
3773                                    }
3774                            }
3775    
3776                            query.append(StringPool.CLOSE_PARENTHESIS);
3777    
3778                            conjunctionable = true;
3779                    }
3780    
3781                    if (!getDB().isSupportsInlineDistinct()) {
3782                            query.append(_FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2);
3783                    }
3784    
3785                    if (orderByComparator != null) {
3786                            if (getDB().isSupportsInlineDistinct()) {
3787                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3788                                            orderByComparator);
3789                            }
3790                            else {
3791                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
3792                                            orderByComparator);
3793                            }
3794                    }
3795    
3796                    else {
3797                            if (getDB().isSupportsInlineDistinct()) {
3798                                    query.append(MBCategoryModelImpl.ORDER_BY_JPQL);
3799                            }
3800                            else {
3801                                    query.append(MBCategoryModelImpl.ORDER_BY_SQL);
3802                            }
3803                    }
3804    
3805                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
3806                                    MBCategory.class.getName(),
3807                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
3808    
3809                    Session session = null;
3810    
3811                    try {
3812                            session = openSession();
3813    
3814                            SQLQuery q = session.createSQLQuery(sql);
3815    
3816                            if (getDB().isSupportsInlineDistinct()) {
3817                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBCategoryImpl.class);
3818                            }
3819                            else {
3820                                    q.addEntity(_FILTER_ENTITY_TABLE, MBCategoryImpl.class);
3821                            }
3822    
3823                            QueryPos qPos = QueryPos.getInstance(q);
3824    
3825                            qPos.add(groupId);
3826    
3827                            if (parentCategoryIds != null) {
3828                                    qPos.add(parentCategoryIds);
3829                            }
3830    
3831                            return (List<MBCategory>)QueryUtil.list(q, getDialect(), start, end);
3832                    }
3833                    catch (Exception e) {
3834                            throw processException(e);
3835                    }
3836                    finally {
3837                            closeSession(session);
3838                    }
3839            }
3840    
3841            /**
3842             * Returns all the message boards categories.
3843             *
3844             * @return the message boards categories
3845             * @throws SystemException if a system exception occurred
3846             */
3847            public List<MBCategory> findAll() throws SystemException {
3848                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3849            }
3850    
3851            /**
3852             * Returns a range of all the message boards categories.
3853             *
3854             * <p>
3855             * 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.
3856             * </p>
3857             *
3858             * @param start the lower bound of the range of message boards categories
3859             * @param end the upper bound of the range of message boards categories (not inclusive)
3860             * @return the range of message boards categories
3861             * @throws SystemException if a system exception occurred
3862             */
3863            public List<MBCategory> findAll(int start, int end)
3864                    throws SystemException {
3865                    return findAll(start, end, null);
3866            }
3867    
3868            /**
3869             * Returns an ordered range of all the message boards categories.
3870             *
3871             * <p>
3872             * 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.
3873             * </p>
3874             *
3875             * @param start the lower bound of the range of message boards categories
3876             * @param end the upper bound of the range of message boards categories (not inclusive)
3877             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3878             * @return the ordered range of message boards categories
3879             * @throws SystemException if a system exception occurred
3880             */
3881            public List<MBCategory> findAll(int start, int end,
3882                    OrderByComparator orderByComparator) throws SystemException {
3883                    FinderPath finderPath = null;
3884                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
3885    
3886                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3887                                    (orderByComparator == null)) {
3888                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
3889                            finderArgs = FINDER_ARGS_EMPTY;
3890                    }
3891                    else {
3892                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
3893                            finderArgs = new Object[] { start, end, orderByComparator };
3894                    }
3895    
3896                    List<MBCategory> list = (List<MBCategory>)FinderCacheUtil.getResult(finderPath,
3897                                    finderArgs, this);
3898    
3899                    if (list == null) {
3900                            StringBundler query = null;
3901                            String sql = null;
3902    
3903                            if (orderByComparator != null) {
3904                                    query = new StringBundler(2 +
3905                                                    (orderByComparator.getOrderByFields().length * 3));
3906    
3907                                    query.append(_SQL_SELECT_MBCATEGORY);
3908    
3909                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3910                                            orderByComparator);
3911    
3912                                    sql = query.toString();
3913                            }
3914                            else {
3915                                    sql = _SQL_SELECT_MBCATEGORY.concat(MBCategoryModelImpl.ORDER_BY_JPQL);
3916                            }
3917    
3918                            Session session = null;
3919    
3920                            try {
3921                                    session = openSession();
3922    
3923                                    Query q = session.createQuery(sql);
3924    
3925                                    if (orderByComparator == null) {
3926                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3927                                                            start, end, false);
3928    
3929                                            Collections.sort(list);
3930                                    }
3931                                    else {
3932                                            list = (List<MBCategory>)QueryUtil.list(q, getDialect(),
3933                                                            start, end);
3934                                    }
3935                            }
3936                            catch (Exception e) {
3937                                    throw processException(e);
3938                            }
3939                            finally {
3940                                    if (list == null) {
3941                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
3942                                    }
3943                                    else {
3944                                            cacheResult(list);
3945    
3946                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
3947                                    }
3948    
3949                                    closeSession(session);
3950                            }
3951                    }
3952    
3953                    return list;
3954            }
3955    
3956            /**
3957             * Removes all the message boards categories where uuid = &#63; from the database.
3958             *
3959             * @param uuid the uuid
3960             * @throws SystemException if a system exception occurred
3961             */
3962            public void removeByUuid(String uuid) throws SystemException {
3963                    for (MBCategory mbCategory : findByUuid(uuid)) {
3964                            remove(mbCategory);
3965                    }
3966            }
3967    
3968            /**
3969             * Removes the message boards category where uuid = &#63; and groupId = &#63; from the database.
3970             *
3971             * @param uuid the uuid
3972             * @param groupId the group ID
3973             * @return the message boards category that was removed
3974             * @throws SystemException if a system exception occurred
3975             */
3976            public MBCategory removeByUUID_G(String uuid, long groupId)
3977                    throws NoSuchCategoryException, SystemException {
3978                    MBCategory mbCategory = findByUUID_G(uuid, groupId);
3979    
3980                    return remove(mbCategory);
3981            }
3982    
3983            /**
3984             * Removes all the message boards categories where uuid = &#63; and companyId = &#63; from the database.
3985             *
3986             * @param uuid the uuid
3987             * @param companyId the company ID
3988             * @throws SystemException if a system exception occurred
3989             */
3990            public void removeByUuid_C(String uuid, long companyId)
3991                    throws SystemException {
3992                    for (MBCategory mbCategory : findByUuid_C(uuid, companyId)) {
3993                            remove(mbCategory);
3994                    }
3995            }
3996    
3997            /**
3998             * Removes all the message boards categories where groupId = &#63; from the database.
3999             *
4000             * @param groupId the group ID
4001             * @throws SystemException if a system exception occurred
4002             */
4003            public void removeByGroupId(long groupId) throws SystemException {
4004                    for (MBCategory mbCategory : findByGroupId(groupId)) {
4005                            remove(mbCategory);
4006                    }
4007            }
4008    
4009            /**
4010             * Removes all the message boards categories where companyId = &#63; from the database.
4011             *
4012             * @param companyId the company ID
4013             * @throws SystemException if a system exception occurred
4014             */
4015            public void removeByCompanyId(long companyId) throws SystemException {
4016                    for (MBCategory mbCategory : findByCompanyId(companyId)) {
4017                            remove(mbCategory);
4018                    }
4019            }
4020    
4021            /**
4022             * Removes all the message boards categories where groupId = &#63; and parentCategoryId = &#63; from the database.
4023             *
4024             * @param groupId the group ID
4025             * @param parentCategoryId the parent category ID
4026             * @throws SystemException if a system exception occurred
4027             */
4028            public void removeByG_P(long groupId, long parentCategoryId)
4029                    throws SystemException {
4030                    for (MBCategory mbCategory : findByG_P(groupId, parentCategoryId)) {
4031                            remove(mbCategory);
4032                    }
4033            }
4034    
4035            /**
4036             * Removes all the message boards categories from the database.
4037             *
4038             * @throws SystemException if a system exception occurred
4039             */
4040            public void removeAll() throws SystemException {
4041                    for (MBCategory mbCategory : findAll()) {
4042                            remove(mbCategory);
4043                    }
4044            }
4045    
4046            /**
4047             * Returns the number of message boards categories where uuid = &#63;.
4048             *
4049             * @param uuid the uuid
4050             * @return the number of matching message boards categories
4051             * @throws SystemException if a system exception occurred
4052             */
4053            public int countByUuid(String uuid) throws SystemException {
4054                    Object[] finderArgs = new Object[] { uuid };
4055    
4056                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID,
4057                                    finderArgs, this);
4058    
4059                    if (count == null) {
4060                            StringBundler query = new StringBundler(2);
4061    
4062                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4063    
4064                            if (uuid == null) {
4065                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
4066                            }
4067                            else {
4068                                    if (uuid.equals(StringPool.BLANK)) {
4069                                            query.append(_FINDER_COLUMN_UUID_UUID_3);
4070                                    }
4071                                    else {
4072                                            query.append(_FINDER_COLUMN_UUID_UUID_2);
4073                                    }
4074                            }
4075    
4076                            String sql = query.toString();
4077    
4078                            Session session = null;
4079    
4080                            try {
4081                                    session = openSession();
4082    
4083                                    Query q = session.createQuery(sql);
4084    
4085                                    QueryPos qPos = QueryPos.getInstance(q);
4086    
4087                                    if (uuid != null) {
4088                                            qPos.add(uuid);
4089                                    }
4090    
4091                                    count = (Long)q.uniqueResult();
4092                            }
4093                            catch (Exception e) {
4094                                    throw processException(e);
4095                            }
4096                            finally {
4097                                    if (count == null) {
4098                                            count = Long.valueOf(0);
4099                                    }
4100    
4101                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID,
4102                                            finderArgs, count);
4103    
4104                                    closeSession(session);
4105                            }
4106                    }
4107    
4108                    return count.intValue();
4109            }
4110    
4111            /**
4112             * Returns the number of message boards categories where uuid = &#63; and groupId = &#63;.
4113             *
4114             * @param uuid the uuid
4115             * @param groupId the group ID
4116             * @return the number of matching message boards categories
4117             * @throws SystemException if a system exception occurred
4118             */
4119            public int countByUUID_G(String uuid, long groupId)
4120                    throws SystemException {
4121                    Object[] finderArgs = new Object[] { uuid, groupId };
4122    
4123                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_G,
4124                                    finderArgs, this);
4125    
4126                    if (count == null) {
4127                            StringBundler query = new StringBundler(3);
4128    
4129                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4130    
4131                            if (uuid == null) {
4132                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
4133                            }
4134                            else {
4135                                    if (uuid.equals(StringPool.BLANK)) {
4136                                            query.append(_FINDER_COLUMN_UUID_G_UUID_3);
4137                                    }
4138                                    else {
4139                                            query.append(_FINDER_COLUMN_UUID_G_UUID_2);
4140                                    }
4141                            }
4142    
4143                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
4144    
4145                            String sql = query.toString();
4146    
4147                            Session session = null;
4148    
4149                            try {
4150                                    session = openSession();
4151    
4152                                    Query q = session.createQuery(sql);
4153    
4154                                    QueryPos qPos = QueryPos.getInstance(q);
4155    
4156                                    if (uuid != null) {
4157                                            qPos.add(uuid);
4158                                    }
4159    
4160                                    qPos.add(groupId);
4161    
4162                                    count = (Long)q.uniqueResult();
4163                            }
4164                            catch (Exception e) {
4165                                    throw processException(e);
4166                            }
4167                            finally {
4168                                    if (count == null) {
4169                                            count = Long.valueOf(0);
4170                                    }
4171    
4172                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G,
4173                                            finderArgs, count);
4174    
4175                                    closeSession(session);
4176                            }
4177                    }
4178    
4179                    return count.intValue();
4180            }
4181    
4182            /**
4183             * Returns the number of message boards categories where uuid = &#63; and companyId = &#63;.
4184             *
4185             * @param uuid the uuid
4186             * @param companyId the company ID
4187             * @return the number of matching message boards categories
4188             * @throws SystemException if a system exception occurred
4189             */
4190            public int countByUuid_C(String uuid, long companyId)
4191                    throws SystemException {
4192                    Object[] finderArgs = new Object[] { uuid, companyId };
4193    
4194                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_UUID_C,
4195                                    finderArgs, this);
4196    
4197                    if (count == null) {
4198                            StringBundler query = new StringBundler(3);
4199    
4200                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4201    
4202                            if (uuid == null) {
4203                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
4204                            }
4205                            else {
4206                                    if (uuid.equals(StringPool.BLANK)) {
4207                                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
4208                                    }
4209                                    else {
4210                                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
4211                                    }
4212                            }
4213    
4214                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
4215    
4216                            String sql = query.toString();
4217    
4218                            Session session = null;
4219    
4220                            try {
4221                                    session = openSession();
4222    
4223                                    Query q = session.createQuery(sql);
4224    
4225                                    QueryPos qPos = QueryPos.getInstance(q);
4226    
4227                                    if (uuid != null) {
4228                                            qPos.add(uuid);
4229                                    }
4230    
4231                                    qPos.add(companyId);
4232    
4233                                    count = (Long)q.uniqueResult();
4234                            }
4235                            catch (Exception e) {
4236                                    throw processException(e);
4237                            }
4238                            finally {
4239                                    if (count == null) {
4240                                            count = Long.valueOf(0);
4241                                    }
4242    
4243                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_C,
4244                                            finderArgs, count);
4245    
4246                                    closeSession(session);
4247                            }
4248                    }
4249    
4250                    return count.intValue();
4251            }
4252    
4253            /**
4254             * Returns the number of message boards categories where groupId = &#63;.
4255             *
4256             * @param groupId the group ID
4257             * @return the number of matching message boards categories
4258             * @throws SystemException if a system exception occurred
4259             */
4260            public int countByGroupId(long groupId) throws SystemException {
4261                    Object[] finderArgs = new Object[] { groupId };
4262    
4263                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_GROUPID,
4264                                    finderArgs, this);
4265    
4266                    if (count == null) {
4267                            StringBundler query = new StringBundler(2);
4268    
4269                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4270    
4271                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4272    
4273                            String sql = query.toString();
4274    
4275                            Session session = null;
4276    
4277                            try {
4278                                    session = openSession();
4279    
4280                                    Query q = session.createQuery(sql);
4281    
4282                                    QueryPos qPos = QueryPos.getInstance(q);
4283    
4284                                    qPos.add(groupId);
4285    
4286                                    count = (Long)q.uniqueResult();
4287                            }
4288                            catch (Exception e) {
4289                                    throw processException(e);
4290                            }
4291                            finally {
4292                                    if (count == null) {
4293                                            count = Long.valueOf(0);
4294                                    }
4295    
4296                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_GROUPID,
4297                                            finderArgs, count);
4298    
4299                                    closeSession(session);
4300                            }
4301                    }
4302    
4303                    return count.intValue();
4304            }
4305    
4306            /**
4307             * Returns the number of message boards categories that the user has permission to view where groupId = &#63;.
4308             *
4309             * @param groupId the group ID
4310             * @return the number of matching message boards categories that the user has permission to view
4311             * @throws SystemException if a system exception occurred
4312             */
4313            public int filterCountByGroupId(long groupId) throws SystemException {
4314                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4315                            return countByGroupId(groupId);
4316                    }
4317    
4318                    StringBundler query = new StringBundler(2);
4319    
4320                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4321    
4322                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
4323    
4324                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4325                                    MBCategory.class.getName(),
4326                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4327    
4328                    Session session = null;
4329    
4330                    try {
4331                            session = openSession();
4332    
4333                            SQLQuery q = session.createSQLQuery(sql);
4334    
4335                            q.addScalar(COUNT_COLUMN_NAME,
4336                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4337    
4338                            QueryPos qPos = QueryPos.getInstance(q);
4339    
4340                            qPos.add(groupId);
4341    
4342                            Long count = (Long)q.uniqueResult();
4343    
4344                            return count.intValue();
4345                    }
4346                    catch (Exception e) {
4347                            throw processException(e);
4348                    }
4349                    finally {
4350                            closeSession(session);
4351                    }
4352            }
4353    
4354            /**
4355             * Returns the number of message boards categories where companyId = &#63;.
4356             *
4357             * @param companyId the company ID
4358             * @return the number of matching message boards categories
4359             * @throws SystemException if a system exception occurred
4360             */
4361            public int countByCompanyId(long companyId) throws SystemException {
4362                    Object[] finderArgs = new Object[] { companyId };
4363    
4364                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_COMPANYID,
4365                                    finderArgs, this);
4366    
4367                    if (count == null) {
4368                            StringBundler query = new StringBundler(2);
4369    
4370                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4371    
4372                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
4373    
4374                            String sql = query.toString();
4375    
4376                            Session session = null;
4377    
4378                            try {
4379                                    session = openSession();
4380    
4381                                    Query q = session.createQuery(sql);
4382    
4383                                    QueryPos qPos = QueryPos.getInstance(q);
4384    
4385                                    qPos.add(companyId);
4386    
4387                                    count = (Long)q.uniqueResult();
4388                            }
4389                            catch (Exception e) {
4390                                    throw processException(e);
4391                            }
4392                            finally {
4393                                    if (count == null) {
4394                                            count = Long.valueOf(0);
4395                                    }
4396    
4397                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_COMPANYID,
4398                                            finderArgs, count);
4399    
4400                                    closeSession(session);
4401                            }
4402                    }
4403    
4404                    return count.intValue();
4405            }
4406    
4407            /**
4408             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = &#63;.
4409             *
4410             * @param groupId the group ID
4411             * @param parentCategoryId the parent category ID
4412             * @return the number of matching message boards categories
4413             * @throws SystemException if a system exception occurred
4414             */
4415            public int countByG_P(long groupId, long parentCategoryId)
4416                    throws SystemException {
4417                    Object[] finderArgs = new Object[] { groupId, parentCategoryId };
4418    
4419                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_G_P,
4420                                    finderArgs, this);
4421    
4422                    if (count == null) {
4423                            StringBundler query = new StringBundler(3);
4424    
4425                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4426    
4427                            query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4428    
4429                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
4430    
4431                            String sql = query.toString();
4432    
4433                            Session session = null;
4434    
4435                            try {
4436                                    session = openSession();
4437    
4438                                    Query q = session.createQuery(sql);
4439    
4440                                    QueryPos qPos = QueryPos.getInstance(q);
4441    
4442                                    qPos.add(groupId);
4443    
4444                                    qPos.add(parentCategoryId);
4445    
4446                                    count = (Long)q.uniqueResult();
4447                            }
4448                            catch (Exception e) {
4449                                    throw processException(e);
4450                            }
4451                            finally {
4452                                    if (count == null) {
4453                                            count = Long.valueOf(0);
4454                                    }
4455    
4456                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_G_P, finderArgs,
4457                                            count);
4458    
4459                                    closeSession(session);
4460                            }
4461                    }
4462    
4463                    return count.intValue();
4464            }
4465    
4466            /**
4467             * Returns the number of message boards categories where groupId = &#63; and parentCategoryId = any &#63;.
4468             *
4469             * @param groupId the group ID
4470             * @param parentCategoryIds the parent category IDs
4471             * @return the number of matching message boards categories
4472             * @throws SystemException if a system exception occurred
4473             */
4474            public int countByG_P(long groupId, long[] parentCategoryIds)
4475                    throws SystemException {
4476                    Object[] finderArgs = new Object[] {
4477                                    groupId, StringUtil.merge(parentCategoryIds)
4478                            };
4479    
4480                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
4481                                    finderArgs, this);
4482    
4483                    if (count == null) {
4484                            StringBundler query = new StringBundler();
4485    
4486                            query.append(_SQL_COUNT_MBCATEGORY_WHERE);
4487    
4488                            boolean conjunctionable = false;
4489    
4490                            if (conjunctionable) {
4491                                    query.append(WHERE_AND);
4492                            }
4493    
4494                            query.append(_FINDER_COLUMN_G_P_GROUPID_5);
4495    
4496                            conjunctionable = true;
4497    
4498                            if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
4499                                    if (conjunctionable) {
4500                                            query.append(WHERE_AND);
4501                                    }
4502    
4503                                    query.append(StringPool.OPEN_PARENTHESIS);
4504    
4505                                    for (int i = 0; i < parentCategoryIds.length; i++) {
4506                                            query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
4507    
4508                                            if ((i + 1) < parentCategoryIds.length) {
4509                                                    query.append(WHERE_OR);
4510                                            }
4511                                    }
4512    
4513                                    query.append(StringPool.CLOSE_PARENTHESIS);
4514    
4515                                    conjunctionable = true;
4516                            }
4517    
4518                            String sql = query.toString();
4519    
4520                            Session session = null;
4521    
4522                            try {
4523                                    session = openSession();
4524    
4525                                    Query q = session.createQuery(sql);
4526    
4527                                    QueryPos qPos = QueryPos.getInstance(q);
4528    
4529                                    qPos.add(groupId);
4530    
4531                                    if (parentCategoryIds != null) {
4532                                            qPos.add(parentCategoryIds);
4533                                    }
4534    
4535                                    count = (Long)q.uniqueResult();
4536                            }
4537                            catch (Exception e) {
4538                                    throw processException(e);
4539                            }
4540                            finally {
4541                                    if (count == null) {
4542                                            count = Long.valueOf(0);
4543                                    }
4544    
4545                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_P,
4546                                            finderArgs, count);
4547    
4548                                    closeSession(session);
4549                            }
4550                    }
4551    
4552                    return count.intValue();
4553            }
4554    
4555            /**
4556             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = &#63;.
4557             *
4558             * @param groupId the group ID
4559             * @param parentCategoryId the parent category ID
4560             * @return the number of matching message boards categories that the user has permission to view
4561             * @throws SystemException if a system exception occurred
4562             */
4563            public int filterCountByG_P(long groupId, long parentCategoryId)
4564                    throws SystemException {
4565                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4566                            return countByG_P(groupId, parentCategoryId);
4567                    }
4568    
4569                    StringBundler query = new StringBundler(3);
4570    
4571                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4572    
4573                    query.append(_FINDER_COLUMN_G_P_GROUPID_2);
4574    
4575                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2);
4576    
4577                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4578                                    MBCategory.class.getName(),
4579                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4580    
4581                    Session session = null;
4582    
4583                    try {
4584                            session = openSession();
4585    
4586                            SQLQuery q = session.createSQLQuery(sql);
4587    
4588                            q.addScalar(COUNT_COLUMN_NAME,
4589                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4590    
4591                            QueryPos qPos = QueryPos.getInstance(q);
4592    
4593                            qPos.add(groupId);
4594    
4595                            qPos.add(parentCategoryId);
4596    
4597                            Long count = (Long)q.uniqueResult();
4598    
4599                            return count.intValue();
4600                    }
4601                    catch (Exception e) {
4602                            throw processException(e);
4603                    }
4604                    finally {
4605                            closeSession(session);
4606                    }
4607            }
4608    
4609            /**
4610             * Returns the number of message boards categories that the user has permission to view where groupId = &#63; and parentCategoryId = any &#63;.
4611             *
4612             * @param groupId the group ID
4613             * @param parentCategoryIds the parent category IDs
4614             * @return the number of matching message boards categories that the user has permission to view
4615             * @throws SystemException if a system exception occurred
4616             */
4617            public int filterCountByG_P(long groupId, long[] parentCategoryIds)
4618                    throws SystemException {
4619                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4620                            return countByG_P(groupId, parentCategoryIds);
4621                    }
4622    
4623                    StringBundler query = new StringBundler();
4624    
4625                    query.append(_FILTER_SQL_COUNT_MBCATEGORY_WHERE);
4626    
4627                    boolean conjunctionable = false;
4628    
4629                    if (conjunctionable) {
4630                            query.append(WHERE_AND);
4631                    }
4632    
4633                    query.append(_FINDER_COLUMN_G_P_GROUPID_5);
4634    
4635                    conjunctionable = true;
4636    
4637                    if ((parentCategoryIds == null) || (parentCategoryIds.length > 0)) {
4638                            if (conjunctionable) {
4639                                    query.append(WHERE_AND);
4640                            }
4641    
4642                            query.append(StringPool.OPEN_PARENTHESIS);
4643    
4644                            for (int i = 0; i < parentCategoryIds.length; i++) {
4645                                    query.append(_FINDER_COLUMN_G_P_PARENTCATEGORYID_5);
4646    
4647                                    if ((i + 1) < parentCategoryIds.length) {
4648                                            query.append(WHERE_OR);
4649                                    }
4650                            }
4651    
4652                            query.append(StringPool.CLOSE_PARENTHESIS);
4653    
4654                            conjunctionable = true;
4655                    }
4656    
4657                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4658                                    MBCategory.class.getName(),
4659                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4660    
4661                    Session session = null;
4662    
4663                    try {
4664                            session = openSession();
4665    
4666                            SQLQuery q = session.createSQLQuery(sql);
4667    
4668                            q.addScalar(COUNT_COLUMN_NAME,
4669                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
4670    
4671                            QueryPos qPos = QueryPos.getInstance(q);
4672    
4673                            qPos.add(groupId);
4674    
4675                            if (parentCategoryIds != null) {
4676                                    qPos.add(parentCategoryIds);
4677                            }
4678    
4679                            Long count = (Long)q.uniqueResult();
4680    
4681                            return count.intValue();
4682                    }
4683                    catch (Exception e) {
4684                            throw processException(e);
4685                    }
4686                    finally {
4687                            closeSession(session);
4688                    }
4689            }
4690    
4691            /**
4692             * Returns the number of message boards categories.
4693             *
4694             * @return the number of message boards categories
4695             * @throws SystemException if a system exception occurred
4696             */
4697            public int countAll() throws SystemException {
4698                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
4699                                    FINDER_ARGS_EMPTY, this);
4700    
4701                    if (count == null) {
4702                            Session session = null;
4703    
4704                            try {
4705                                    session = openSession();
4706    
4707                                    Query q = session.createQuery(_SQL_COUNT_MBCATEGORY);
4708    
4709                                    count = (Long)q.uniqueResult();
4710                            }
4711                            catch (Exception e) {
4712                                    throw processException(e);
4713                            }
4714                            finally {
4715                                    if (count == null) {
4716                                            count = Long.valueOf(0);
4717                                    }
4718    
4719                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
4720                                            FINDER_ARGS_EMPTY, count);
4721    
4722                                    closeSession(session);
4723                            }
4724                    }
4725    
4726                    return count.intValue();
4727            }
4728    
4729            /**
4730             * Initializes the message boards category persistence.
4731             */
4732            public void afterPropertiesSet() {
4733                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
4734                                            com.liferay.portal.util.PropsUtil.get(
4735                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBCategory")));
4736    
4737                    if (listenerClassNames.length > 0) {
4738                            try {
4739                                    List<ModelListener<MBCategory>> listenersList = new ArrayList<ModelListener<MBCategory>>();
4740    
4741                                    for (String listenerClassName : listenerClassNames) {
4742                                            listenersList.add((ModelListener<MBCategory>)InstanceFactory.newInstance(
4743                                                            listenerClassName));
4744                                    }
4745    
4746                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
4747                            }
4748                            catch (Exception e) {
4749                                    _log.error(e);
4750                            }
4751                    }
4752            }
4753    
4754            public void destroy() {
4755                    EntityCacheUtil.removeCache(MBCategoryImpl.class.getName());
4756                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
4757                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
4758            }
4759    
4760            @BeanReference(type = MBBanPersistence.class)
4761            protected MBBanPersistence mbBanPersistence;
4762            @BeanReference(type = MBCategoryPersistence.class)
4763            protected MBCategoryPersistence mbCategoryPersistence;
4764            @BeanReference(type = MBDiscussionPersistence.class)
4765            protected MBDiscussionPersistence mbDiscussionPersistence;
4766            @BeanReference(type = MBMailingListPersistence.class)
4767            protected MBMailingListPersistence mbMailingListPersistence;
4768            @BeanReference(type = MBMessagePersistence.class)
4769            protected MBMessagePersistence mbMessagePersistence;
4770            @BeanReference(type = MBStatsUserPersistence.class)
4771            protected MBStatsUserPersistence mbStatsUserPersistence;
4772            @BeanReference(type = MBThreadPersistence.class)
4773            protected MBThreadPersistence mbThreadPersistence;
4774            @BeanReference(type = MBThreadFlagPersistence.class)
4775            protected MBThreadFlagPersistence mbThreadFlagPersistence;
4776            @BeanReference(type = GroupPersistence.class)
4777            protected GroupPersistence groupPersistence;
4778            @BeanReference(type = SubscriptionPersistence.class)
4779            protected SubscriptionPersistence subscriptionPersistence;
4780            @BeanReference(type = UserPersistence.class)
4781            protected UserPersistence userPersistence;
4782            @BeanReference(type = AssetTagPersistence.class)
4783            protected AssetTagPersistence assetTagPersistence;
4784            @BeanReference(type = ExpandoValuePersistence.class)
4785            protected ExpandoValuePersistence expandoValuePersistence;
4786            private static final String _SQL_SELECT_MBCATEGORY = "SELECT mbCategory FROM MBCategory mbCategory";
4787            private static final String _SQL_SELECT_MBCATEGORY_WHERE = "SELECT mbCategory FROM MBCategory mbCategory WHERE ";
4788            private static final String _SQL_COUNT_MBCATEGORY = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory";
4789            private static final String _SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(mbCategory) FROM MBCategory mbCategory WHERE ";
4790            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbCategory.uuid IS NULL";
4791            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbCategory.uuid = ?";
4792            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?)";
4793            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbCategory.uuid IS NULL AND ";
4794            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbCategory.uuid = ? AND ";
4795            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?) AND ";
4796            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbCategory.groupId = ?";
4797            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbCategory.uuid IS NULL AND ";
4798            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbCategory.uuid = ? AND ";
4799            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbCategory.uuid IS NULL OR mbCategory.uuid = ?) AND ";
4800            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbCategory.companyId = ?";
4801            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbCategory.groupId = ?";
4802            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbCategory.companyId = ?";
4803            private static final String _FINDER_COLUMN_G_P_GROUPID_2 = "mbCategory.groupId = ? AND ";
4804            private static final String _FINDER_COLUMN_G_P_GROUPID_5 = "(" +
4805                    _removeConjunction(_FINDER_COLUMN_G_P_GROUPID_2) + ")";
4806            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_2 = "mbCategory.parentCategoryId = ?";
4807            private static final String _FINDER_COLUMN_G_P_PARENTCATEGORYID_5 = "(" +
4808                    _removeConjunction(_FINDER_COLUMN_G_P_PARENTCATEGORYID_2) + ")";
4809    
4810            private static String _removeConjunction(String sql) {
4811                    int pos = sql.indexOf(" AND ");
4812    
4813                    if (pos != -1) {
4814                            sql = sql.substring(0, pos);
4815                    }
4816    
4817                    return sql;
4818            }
4819    
4820            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbCategory.categoryId";
4821            private static final String _FILTER_SQL_SELECT_MBCATEGORY_WHERE = "SELECT DISTINCT {mbCategory.*} FROM MBCategory mbCategory WHERE ";
4822            private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_1 =
4823                    "SELECT {MBCategory.*} FROM (SELECT DISTINCT mbCategory.categoryId FROM MBCategory mbCategory WHERE ";
4824            private static final String _FILTER_SQL_SELECT_MBCATEGORY_NO_INLINE_DISTINCT_WHERE_2 =
4825                    ") TEMP_TABLE INNER JOIN MBCategory ON TEMP_TABLE.categoryId = MBCategory.categoryId";
4826            private static final String _FILTER_SQL_COUNT_MBCATEGORY_WHERE = "SELECT COUNT(DISTINCT mbCategory.categoryId) AS COUNT_VALUE FROM MBCategory mbCategory WHERE ";
4827            private static final String _FILTER_ENTITY_ALIAS = "mbCategory";
4828            private static final String _FILTER_ENTITY_TABLE = "MBCategory";
4829            private static final String _ORDER_BY_ENTITY_ALIAS = "mbCategory.";
4830            private static final String _ORDER_BY_ENTITY_TABLE = "MBCategory.";
4831            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBCategory exists with the primary key ";
4832            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBCategory exists with the key {";
4833            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
4834            private static Log _log = LogFactoryUtil.getLog(MBCategoryPersistenceImpl.class);
4835            private static MBCategory _nullMBCategory = new MBCategoryImpl() {
4836                            @Override
4837                            public Object clone() {
4838                                    return this;
4839                            }
4840    
4841                            @Override
4842                            public CacheModel<MBCategory> toCacheModel() {
4843                                    return _nullMBCategoryCacheModel;
4844                            }
4845                    };
4846    
4847            private static CacheModel<MBCategory> _nullMBCategoryCacheModel = new CacheModel<MBCategory>() {
4848                            public MBCategory toEntityModel() {
4849                                    return _nullMBCategory;
4850                            }
4851                    };
4852    }