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