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