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