001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
018    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
019    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
020    import com.liferay.portal.kernel.dao.orm.FinderPath;
021    import com.liferay.portal.kernel.dao.orm.Query;
022    import com.liferay.portal.kernel.dao.orm.QueryPos;
023    import com.liferay.portal.kernel.dao.orm.QueryUtil;
024    import com.liferay.portal.kernel.dao.orm.SQLQuery;
025    import com.liferay.portal.kernel.dao.orm.Session;
026    import com.liferay.portal.kernel.exception.SystemException;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.sanitizer.Sanitizer;
030    import com.liferay.portal.kernel.sanitizer.SanitizerException;
031    import com.liferay.portal.kernel.sanitizer.SanitizerUtil;
032    import com.liferay.portal.kernel.util.ArrayUtil;
033    import com.liferay.portal.kernel.util.ContentTypes;
034    import com.liferay.portal.kernel.util.GetterUtil;
035    import com.liferay.portal.kernel.util.InstanceFactory;
036    import com.liferay.portal.kernel.util.OrderByComparator;
037    import com.liferay.portal.kernel.util.StringBundler;
038    import com.liferay.portal.kernel.util.StringPool;
039    import com.liferay.portal.kernel.util.StringUtil;
040    import com.liferay.portal.kernel.util.UnmodifiableList;
041    import com.liferay.portal.kernel.util.Validator;
042    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
043    import com.liferay.portal.model.CacheModel;
044    import com.liferay.portal.model.ModelListener;
045    import com.liferay.portal.security.auth.PrincipalThreadLocal;
046    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
047    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
048    
049    import com.liferay.portlet.messageboards.NoSuchMessageException;
050    import com.liferay.portlet.messageboards.model.MBMessage;
051    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
052    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
053    
054    import java.io.Serializable;
055    
056    import java.util.ArrayList;
057    import java.util.Collections;
058    import java.util.List;
059    
060    /**
061     * The persistence implementation for the message-boards message service.
062     *
063     * <p>
064     * Caching information and settings can be found in <code>portal.properties</code>
065     * </p>
066     *
067     * @author Brian Wing Shun Chan
068     * @see MBMessagePersistence
069     * @see MBMessageUtil
070     * @generated
071     */
072    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
073            implements MBMessagePersistence {
074            /*
075             * NOTE FOR DEVELOPERS:
076             *
077             * Never modify or reference this class directly. Always use {@link MBMessageUtil} to access the message-boards message persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
078             */
079            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
080            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
081                    ".List1";
082            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List2";
084            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
085                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
086                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
087            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
088                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
089                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
090            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
091                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
092                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
093            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
094                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
095                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
096                            new String[] {
097                                    String.class.getName(),
098                                    
099                            Integer.class.getName(), Integer.class.getName(),
100                                    OrderByComparator.class.getName()
101                            });
102            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
103                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
104                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
105                            new String[] { String.class.getName() },
106                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
107                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
108            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
109                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
110                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
111                            new String[] { String.class.getName() });
112    
113            /**
114             * Returns all the message-boards messages where uuid = &#63;.
115             *
116             * @param uuid the uuid
117             * @return the matching message-boards messages
118             * @throws SystemException if a system exception occurred
119             */
120            public List<MBMessage> findByUuid(String uuid) throws SystemException {
121                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
122            }
123    
124            /**
125             * Returns a range of all the message-boards messages where uuid = &#63;.
126             *
127             * <p>
128             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
129             * </p>
130             *
131             * @param uuid the uuid
132             * @param start the lower bound of the range of message-boards messages
133             * @param end the upper bound of the range of message-boards messages (not inclusive)
134             * @return the range of matching message-boards messages
135             * @throws SystemException if a system exception occurred
136             */
137            public List<MBMessage> findByUuid(String uuid, int start, int end)
138                    throws SystemException {
139                    return findByUuid(uuid, start, end, null);
140            }
141    
142            /**
143             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
144             *
145             * <p>
146             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
147             * </p>
148             *
149             * @param uuid the uuid
150             * @param start the lower bound of the range of message-boards messages
151             * @param end the upper bound of the range of message-boards messages (not inclusive)
152             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
153             * @return the ordered range of matching message-boards messages
154             * @throws SystemException if a system exception occurred
155             */
156            public List<MBMessage> findByUuid(String uuid, int start, int end,
157                    OrderByComparator orderByComparator) throws SystemException {
158                    boolean pagination = true;
159                    FinderPath finderPath = null;
160                    Object[] finderArgs = null;
161    
162                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
163                                    (orderByComparator == null)) {
164                            pagination = false;
165                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
166                            finderArgs = new Object[] { uuid };
167                    }
168                    else {
169                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
170                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
171                    }
172    
173                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
174                                    finderArgs, this);
175    
176                    if ((list != null) && !list.isEmpty()) {
177                            for (MBMessage mbMessage : list) {
178                                    if (!Validator.equals(uuid, mbMessage.getUuid())) {
179                                            list = null;
180    
181                                            break;
182                                    }
183                            }
184                    }
185    
186                    if (list == null) {
187                            StringBundler query = null;
188    
189                            if (orderByComparator != null) {
190                                    query = new StringBundler(3 +
191                                                    (orderByComparator.getOrderByFields().length * 3));
192                            }
193                            else {
194                                    query = new StringBundler(3);
195                            }
196    
197                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
198    
199                            boolean bindUuid = false;
200    
201                            if (uuid == null) {
202                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
203                            }
204                            else if (uuid.equals(StringPool.BLANK)) {
205                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
206                            }
207                            else {
208                                    bindUuid = true;
209    
210                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
211                            }
212    
213                            if (orderByComparator != null) {
214                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
215                                            orderByComparator);
216                            }
217                            else
218                             if (pagination) {
219                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
220                            }
221    
222                            String sql = query.toString();
223    
224                            Session session = null;
225    
226                            try {
227                                    session = openSession();
228    
229                                    Query q = session.createQuery(sql);
230    
231                                    QueryPos qPos = QueryPos.getInstance(q);
232    
233                                    if (bindUuid) {
234                                            qPos.add(uuid);
235                                    }
236    
237                                    if (!pagination) {
238                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
239                                                            start, end, false);
240    
241                                            Collections.sort(list);
242    
243                                            list = new UnmodifiableList<MBMessage>(list);
244                                    }
245                                    else {
246                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
247                                                            start, end);
248                                    }
249    
250                                    cacheResult(list);
251    
252                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
253                            }
254                            catch (Exception e) {
255                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
256    
257                                    throw processException(e);
258                            }
259                            finally {
260                                    closeSession(session);
261                            }
262                    }
263    
264                    return list;
265            }
266    
267            /**
268             * Returns the first message-boards message in the ordered set where uuid = &#63;.
269             *
270             * @param uuid the uuid
271             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
272             * @return the first matching message-boards message
273             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
274             * @throws SystemException if a system exception occurred
275             */
276            public MBMessage findByUuid_First(String uuid,
277                    OrderByComparator orderByComparator)
278                    throws NoSuchMessageException, SystemException {
279                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
280    
281                    if (mbMessage != null) {
282                            return mbMessage;
283                    }
284    
285                    StringBundler msg = new StringBundler(4);
286    
287                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
288    
289                    msg.append("uuid=");
290                    msg.append(uuid);
291    
292                    msg.append(StringPool.CLOSE_CURLY_BRACE);
293    
294                    throw new NoSuchMessageException(msg.toString());
295            }
296    
297            /**
298             * Returns the first message-boards message in the ordered set where uuid = &#63;.
299             *
300             * @param uuid the uuid
301             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
302             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
303             * @throws SystemException if a system exception occurred
304             */
305            public MBMessage fetchByUuid_First(String uuid,
306                    OrderByComparator orderByComparator) throws SystemException {
307                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
308    
309                    if (!list.isEmpty()) {
310                            return list.get(0);
311                    }
312    
313                    return null;
314            }
315    
316            /**
317             * Returns the last message-boards message in the ordered set where uuid = &#63;.
318             *
319             * @param uuid the uuid
320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
321             * @return the last matching message-boards message
322             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
323             * @throws SystemException if a system exception occurred
324             */
325            public MBMessage findByUuid_Last(String uuid,
326                    OrderByComparator orderByComparator)
327                    throws NoSuchMessageException, SystemException {
328                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
329    
330                    if (mbMessage != null) {
331                            return mbMessage;
332                    }
333    
334                    StringBundler msg = new StringBundler(4);
335    
336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
337    
338                    msg.append("uuid=");
339                    msg.append(uuid);
340    
341                    msg.append(StringPool.CLOSE_CURLY_BRACE);
342    
343                    throw new NoSuchMessageException(msg.toString());
344            }
345    
346            /**
347             * Returns the last message-boards message in the ordered set where uuid = &#63;.
348             *
349             * @param uuid the uuid
350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
351             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
352             * @throws SystemException if a system exception occurred
353             */
354            public MBMessage fetchByUuid_Last(String uuid,
355                    OrderByComparator orderByComparator) throws SystemException {
356                    int count = countByUuid(uuid);
357    
358                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
359                                    orderByComparator);
360    
361                    if (!list.isEmpty()) {
362                            return list.get(0);
363                    }
364    
365                    return null;
366            }
367    
368            /**
369             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
370             *
371             * @param messageId the primary key of the current message-boards message
372             * @param uuid the uuid
373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
374             * @return the previous, current, and next message-boards message
375             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
376             * @throws SystemException if a system exception occurred
377             */
378            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
379                    OrderByComparator orderByComparator)
380                    throws NoSuchMessageException, SystemException {
381                    MBMessage mbMessage = findByPrimaryKey(messageId);
382    
383                    Session session = null;
384    
385                    try {
386                            session = openSession();
387    
388                            MBMessage[] array = new MBMessageImpl[3];
389    
390                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
391                                            orderByComparator, true);
392    
393                            array[1] = mbMessage;
394    
395                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
396                                            orderByComparator, false);
397    
398                            return array;
399                    }
400                    catch (Exception e) {
401                            throw processException(e);
402                    }
403                    finally {
404                            closeSession(session);
405                    }
406            }
407    
408            protected MBMessage getByUuid_PrevAndNext(Session session,
409                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
410                    boolean previous) {
411                    StringBundler query = null;
412    
413                    if (orderByComparator != null) {
414                            query = new StringBundler(6 +
415                                            (orderByComparator.getOrderByFields().length * 6));
416                    }
417                    else {
418                            query = new StringBundler(3);
419                    }
420    
421                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
422    
423                    boolean bindUuid = false;
424    
425                    if (uuid == null) {
426                            query.append(_FINDER_COLUMN_UUID_UUID_1);
427                    }
428                    else if (uuid.equals(StringPool.BLANK)) {
429                            query.append(_FINDER_COLUMN_UUID_UUID_3);
430                    }
431                    else {
432                            bindUuid = true;
433    
434                            query.append(_FINDER_COLUMN_UUID_UUID_2);
435                    }
436    
437                    if (orderByComparator != null) {
438                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
439    
440                            if (orderByConditionFields.length > 0) {
441                                    query.append(WHERE_AND);
442                            }
443    
444                            for (int i = 0; i < orderByConditionFields.length; i++) {
445                                    query.append(_ORDER_BY_ENTITY_ALIAS);
446                                    query.append(orderByConditionFields[i]);
447    
448                                    if ((i + 1) < orderByConditionFields.length) {
449                                            if (orderByComparator.isAscending() ^ previous) {
450                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
451                                            }
452                                            else {
453                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
454                                            }
455                                    }
456                                    else {
457                                            if (orderByComparator.isAscending() ^ previous) {
458                                                    query.append(WHERE_GREATER_THAN);
459                                            }
460                                            else {
461                                                    query.append(WHERE_LESSER_THAN);
462                                            }
463                                    }
464                            }
465    
466                            query.append(ORDER_BY_CLAUSE);
467    
468                            String[] orderByFields = orderByComparator.getOrderByFields();
469    
470                            for (int i = 0; i < orderByFields.length; i++) {
471                                    query.append(_ORDER_BY_ENTITY_ALIAS);
472                                    query.append(orderByFields[i]);
473    
474                                    if ((i + 1) < orderByFields.length) {
475                                            if (orderByComparator.isAscending() ^ previous) {
476                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
477                                            }
478                                            else {
479                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
480                                            }
481                                    }
482                                    else {
483                                            if (orderByComparator.isAscending() ^ previous) {
484                                                    query.append(ORDER_BY_ASC);
485                                            }
486                                            else {
487                                                    query.append(ORDER_BY_DESC);
488                                            }
489                                    }
490                            }
491                    }
492                    else {
493                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
494                    }
495    
496                    String sql = query.toString();
497    
498                    Query q = session.createQuery(sql);
499    
500                    q.setFirstResult(0);
501                    q.setMaxResults(2);
502    
503                    QueryPos qPos = QueryPos.getInstance(q);
504    
505                    if (bindUuid) {
506                            qPos.add(uuid);
507                    }
508    
509                    if (orderByComparator != null) {
510                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
511    
512                            for (Object value : values) {
513                                    qPos.add(value);
514                            }
515                    }
516    
517                    List<MBMessage> list = q.list();
518    
519                    if (list.size() == 2) {
520                            return list.get(1);
521                    }
522                    else {
523                            return null;
524                    }
525            }
526    
527            /**
528             * Removes all the message-boards messages where uuid = &#63; from the database.
529             *
530             * @param uuid the uuid
531             * @throws SystemException if a system exception occurred
532             */
533            public void removeByUuid(String uuid) throws SystemException {
534                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
535                                    QueryUtil.ALL_POS, null)) {
536                            remove(mbMessage);
537                    }
538            }
539    
540            /**
541             * Returns the number of message-boards messages where uuid = &#63;.
542             *
543             * @param uuid the uuid
544             * @return the number of matching message-boards messages
545             * @throws SystemException if a system exception occurred
546             */
547            public int countByUuid(String uuid) throws SystemException {
548                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
549    
550                    Object[] finderArgs = new Object[] { uuid };
551    
552                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
553                                    this);
554    
555                    if (count == null) {
556                            StringBundler query = new StringBundler(2);
557    
558                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
559    
560                            boolean bindUuid = false;
561    
562                            if (uuid == null) {
563                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
564                            }
565                            else if (uuid.equals(StringPool.BLANK)) {
566                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
567                            }
568                            else {
569                                    bindUuid = true;
570    
571                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
572                            }
573    
574                            String sql = query.toString();
575    
576                            Session session = null;
577    
578                            try {
579                                    session = openSession();
580    
581                                    Query q = session.createQuery(sql);
582    
583                                    QueryPos qPos = QueryPos.getInstance(q);
584    
585                                    if (bindUuid) {
586                                            qPos.add(uuid);
587                                    }
588    
589                                    count = (Long)q.uniqueResult();
590    
591                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
592                            }
593                            catch (Exception e) {
594                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
595    
596                                    throw processException(e);
597                            }
598                            finally {
599                                    closeSession(session);
600                            }
601                    }
602    
603                    return count.intValue();
604            }
605    
606            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
607            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
608            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
609            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
610                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
611                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
612                            new String[] { String.class.getName(), Long.class.getName() },
613                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
614                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
615            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
616                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
617                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
618                            new String[] { String.class.getName(), Long.class.getName() });
619    
620            /**
621             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
622             *
623             * @param uuid the uuid
624             * @param groupId the group ID
625             * @return the matching message-boards message
626             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
627             * @throws SystemException if a system exception occurred
628             */
629            public MBMessage findByUUID_G(String uuid, long groupId)
630                    throws NoSuchMessageException, SystemException {
631                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
632    
633                    if (mbMessage == null) {
634                            StringBundler msg = new StringBundler(6);
635    
636                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
637    
638                            msg.append("uuid=");
639                            msg.append(uuid);
640    
641                            msg.append(", groupId=");
642                            msg.append(groupId);
643    
644                            msg.append(StringPool.CLOSE_CURLY_BRACE);
645    
646                            if (_log.isWarnEnabled()) {
647                                    _log.warn(msg.toString());
648                            }
649    
650                            throw new NoSuchMessageException(msg.toString());
651                    }
652    
653                    return mbMessage;
654            }
655    
656            /**
657             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
658             *
659             * @param uuid the uuid
660             * @param groupId the group ID
661             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
662             * @throws SystemException if a system exception occurred
663             */
664            public MBMessage fetchByUUID_G(String uuid, long groupId)
665                    throws SystemException {
666                    return fetchByUUID_G(uuid, groupId, true);
667            }
668    
669            /**
670             * Returns the message-boards message where uuid = &#63; and groupId = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
671             *
672             * @param uuid the uuid
673             * @param groupId the group ID
674             * @param retrieveFromCache whether to use the finder cache
675             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
676             * @throws SystemException if a system exception occurred
677             */
678            public MBMessage fetchByUUID_G(String uuid, long groupId,
679                    boolean retrieveFromCache) throws SystemException {
680                    Object[] finderArgs = new Object[] { uuid, groupId };
681    
682                    Object result = null;
683    
684                    if (retrieveFromCache) {
685                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
686                                            finderArgs, this);
687                    }
688    
689                    if (result instanceof MBMessage) {
690                            MBMessage mbMessage = (MBMessage)result;
691    
692                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
693                                            (groupId != mbMessage.getGroupId())) {
694                                    result = null;
695                            }
696                    }
697    
698                    if (result == null) {
699                            StringBundler query = new StringBundler(4);
700    
701                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
702    
703                            boolean bindUuid = false;
704    
705                            if (uuid == null) {
706                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
707                            }
708                            else if (uuid.equals(StringPool.BLANK)) {
709                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
710                            }
711                            else {
712                                    bindUuid = true;
713    
714                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
715                            }
716    
717                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
718    
719                            String sql = query.toString();
720    
721                            Session session = null;
722    
723                            try {
724                                    session = openSession();
725    
726                                    Query q = session.createQuery(sql);
727    
728                                    QueryPos qPos = QueryPos.getInstance(q);
729    
730                                    if (bindUuid) {
731                                            qPos.add(uuid);
732                                    }
733    
734                                    qPos.add(groupId);
735    
736                                    List<MBMessage> list = q.list();
737    
738                                    if (list.isEmpty()) {
739                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
740                                                    finderArgs, list);
741                                    }
742                                    else {
743                                            MBMessage mbMessage = list.get(0);
744    
745                                            result = mbMessage;
746    
747                                            cacheResult(mbMessage);
748    
749                                            if ((mbMessage.getUuid() == null) ||
750                                                            !mbMessage.getUuid().equals(uuid) ||
751                                                            (mbMessage.getGroupId() != groupId)) {
752                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
753                                                            finderArgs, mbMessage);
754                                            }
755                                    }
756                            }
757                            catch (Exception e) {
758                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
759                                            finderArgs);
760    
761                                    throw processException(e);
762                            }
763                            finally {
764                                    closeSession(session);
765                            }
766                    }
767    
768                    if (result instanceof List<?>) {
769                            return null;
770                    }
771                    else {
772                            return (MBMessage)result;
773                    }
774            }
775    
776            /**
777             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
778             *
779             * @param uuid the uuid
780             * @param groupId the group ID
781             * @return the message-boards message that was removed
782             * @throws SystemException if a system exception occurred
783             */
784            public MBMessage removeByUUID_G(String uuid, long groupId)
785                    throws NoSuchMessageException, SystemException {
786                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
787    
788                    return remove(mbMessage);
789            }
790    
791            /**
792             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
793             *
794             * @param uuid the uuid
795             * @param groupId the group ID
796             * @return the number of matching message-boards messages
797             * @throws SystemException if a system exception occurred
798             */
799            public int countByUUID_G(String uuid, long groupId)
800                    throws SystemException {
801                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
802    
803                    Object[] finderArgs = new Object[] { uuid, groupId };
804    
805                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
806                                    this);
807    
808                    if (count == null) {
809                            StringBundler query = new StringBundler(3);
810    
811                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
812    
813                            boolean bindUuid = false;
814    
815                            if (uuid == null) {
816                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
817                            }
818                            else if (uuid.equals(StringPool.BLANK)) {
819                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
820                            }
821                            else {
822                                    bindUuid = true;
823    
824                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
825                            }
826    
827                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
828    
829                            String sql = query.toString();
830    
831                            Session session = null;
832    
833                            try {
834                                    session = openSession();
835    
836                                    Query q = session.createQuery(sql);
837    
838                                    QueryPos qPos = QueryPos.getInstance(q);
839    
840                                    if (bindUuid) {
841                                            qPos.add(uuid);
842                                    }
843    
844                                    qPos.add(groupId);
845    
846                                    count = (Long)q.uniqueResult();
847    
848                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
849                            }
850                            catch (Exception e) {
851                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
852    
853                                    throw processException(e);
854                            }
855                            finally {
856                                    closeSession(session);
857                            }
858                    }
859    
860                    return count.intValue();
861            }
862    
863            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
864            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
865            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
866            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
867            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
868                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
869                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
870                            new String[] {
871                                    String.class.getName(), Long.class.getName(),
872                                    
873                            Integer.class.getName(), Integer.class.getName(),
874                                    OrderByComparator.class.getName()
875                            });
876            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
877                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
878                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
879                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
880                            new String[] { String.class.getName(), Long.class.getName() },
881                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
882                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
883                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
884            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
885                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
886                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
887                            new String[] { String.class.getName(), Long.class.getName() });
888    
889            /**
890             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
891             *
892             * @param uuid the uuid
893             * @param companyId the company ID
894             * @return the matching message-boards messages
895             * @throws SystemException if a system exception occurred
896             */
897            public List<MBMessage> findByUuid_C(String uuid, long companyId)
898                    throws SystemException {
899                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
900                            QueryUtil.ALL_POS, null);
901            }
902    
903            /**
904             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
905             *
906             * <p>
907             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
908             * </p>
909             *
910             * @param uuid the uuid
911             * @param companyId the company ID
912             * @param start the lower bound of the range of message-boards messages
913             * @param end the upper bound of the range of message-boards messages (not inclusive)
914             * @return the range of matching message-boards messages
915             * @throws SystemException if a system exception occurred
916             */
917            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
918                    int end) throws SystemException {
919                    return findByUuid_C(uuid, companyId, start, end, null);
920            }
921    
922            /**
923             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
924             *
925             * <p>
926             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
927             * </p>
928             *
929             * @param uuid the uuid
930             * @param companyId the company ID
931             * @param start the lower bound of the range of message-boards messages
932             * @param end the upper bound of the range of message-boards messages (not inclusive)
933             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
934             * @return the ordered range of matching message-boards messages
935             * @throws SystemException if a system exception occurred
936             */
937            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
938                    int end, OrderByComparator orderByComparator) throws SystemException {
939                    boolean pagination = true;
940                    FinderPath finderPath = null;
941                    Object[] finderArgs = null;
942    
943                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
944                                    (orderByComparator == null)) {
945                            pagination = false;
946                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
947                            finderArgs = new Object[] { uuid, companyId };
948                    }
949                    else {
950                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
951                            finderArgs = new Object[] {
952                                            uuid, companyId,
953                                            
954                                            start, end, orderByComparator
955                                    };
956                    }
957    
958                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
959                                    finderArgs, this);
960    
961                    if ((list != null) && !list.isEmpty()) {
962                            for (MBMessage mbMessage : list) {
963                                    if (!Validator.equals(uuid, mbMessage.getUuid()) ||
964                                                    (companyId != mbMessage.getCompanyId())) {
965                                            list = null;
966    
967                                            break;
968                                    }
969                            }
970                    }
971    
972                    if (list == null) {
973                            StringBundler query = null;
974    
975                            if (orderByComparator != null) {
976                                    query = new StringBundler(4 +
977                                                    (orderByComparator.getOrderByFields().length * 3));
978                            }
979                            else {
980                                    query = new StringBundler(4);
981                            }
982    
983                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
984    
985                            boolean bindUuid = false;
986    
987                            if (uuid == null) {
988                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
989                            }
990                            else if (uuid.equals(StringPool.BLANK)) {
991                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
992                            }
993                            else {
994                                    bindUuid = true;
995    
996                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
997                            }
998    
999                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1000    
1001                            if (orderByComparator != null) {
1002                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1003                                            orderByComparator);
1004                            }
1005                            else
1006                             if (pagination) {
1007                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1008                            }
1009    
1010                            String sql = query.toString();
1011    
1012                            Session session = null;
1013    
1014                            try {
1015                                    session = openSession();
1016    
1017                                    Query q = session.createQuery(sql);
1018    
1019                                    QueryPos qPos = QueryPos.getInstance(q);
1020    
1021                                    if (bindUuid) {
1022                                            qPos.add(uuid);
1023                                    }
1024    
1025                                    qPos.add(companyId);
1026    
1027                                    if (!pagination) {
1028                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1029                                                            start, end, false);
1030    
1031                                            Collections.sort(list);
1032    
1033                                            list = new UnmodifiableList<MBMessage>(list);
1034                                    }
1035                                    else {
1036                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1037                                                            start, end);
1038                                    }
1039    
1040                                    cacheResult(list);
1041    
1042                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1043                            }
1044                            catch (Exception e) {
1045                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1046    
1047                                    throw processException(e);
1048                            }
1049                            finally {
1050                                    closeSession(session);
1051                            }
1052                    }
1053    
1054                    return list;
1055            }
1056    
1057            /**
1058             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1059             *
1060             * @param uuid the uuid
1061             * @param companyId the company ID
1062             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1063             * @return the first matching message-boards message
1064             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1065             * @throws SystemException if a system exception occurred
1066             */
1067            public MBMessage findByUuid_C_First(String uuid, long companyId,
1068                    OrderByComparator orderByComparator)
1069                    throws NoSuchMessageException, SystemException {
1070                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1071                                    orderByComparator);
1072    
1073                    if (mbMessage != null) {
1074                            return mbMessage;
1075                    }
1076    
1077                    StringBundler msg = new StringBundler(6);
1078    
1079                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1080    
1081                    msg.append("uuid=");
1082                    msg.append(uuid);
1083    
1084                    msg.append(", companyId=");
1085                    msg.append(companyId);
1086    
1087                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1088    
1089                    throw new NoSuchMessageException(msg.toString());
1090            }
1091    
1092            /**
1093             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1094             *
1095             * @param uuid the uuid
1096             * @param companyId the company ID
1097             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1098             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1099             * @throws SystemException if a system exception occurred
1100             */
1101            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1102                    OrderByComparator orderByComparator) throws SystemException {
1103                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1104                                    orderByComparator);
1105    
1106                    if (!list.isEmpty()) {
1107                            return list.get(0);
1108                    }
1109    
1110                    return null;
1111            }
1112    
1113            /**
1114             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1115             *
1116             * @param uuid the uuid
1117             * @param companyId the company ID
1118             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1119             * @return the last matching message-boards message
1120             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1121             * @throws SystemException if a system exception occurred
1122             */
1123            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1124                    OrderByComparator orderByComparator)
1125                    throws NoSuchMessageException, SystemException {
1126                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1127                                    orderByComparator);
1128    
1129                    if (mbMessage != null) {
1130                            return mbMessage;
1131                    }
1132    
1133                    StringBundler msg = new StringBundler(6);
1134    
1135                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1136    
1137                    msg.append("uuid=");
1138                    msg.append(uuid);
1139    
1140                    msg.append(", companyId=");
1141                    msg.append(companyId);
1142    
1143                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1144    
1145                    throw new NoSuchMessageException(msg.toString());
1146            }
1147    
1148            /**
1149             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1150             *
1151             * @param uuid the uuid
1152             * @param companyId the company ID
1153             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1154             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1155             * @throws SystemException if a system exception occurred
1156             */
1157            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1158                    OrderByComparator orderByComparator) throws SystemException {
1159                    int count = countByUuid_C(uuid, companyId);
1160    
1161                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1162                                    orderByComparator);
1163    
1164                    if (!list.isEmpty()) {
1165                            return list.get(0);
1166                    }
1167    
1168                    return null;
1169            }
1170    
1171            /**
1172             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1173             *
1174             * @param messageId the primary key of the current message-boards message
1175             * @param uuid the uuid
1176             * @param companyId the company ID
1177             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1178             * @return the previous, current, and next message-boards message
1179             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1180             * @throws SystemException if a system exception occurred
1181             */
1182            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1183                    long companyId, OrderByComparator orderByComparator)
1184                    throws NoSuchMessageException, SystemException {
1185                    MBMessage mbMessage = findByPrimaryKey(messageId);
1186    
1187                    Session session = null;
1188    
1189                    try {
1190                            session = openSession();
1191    
1192                            MBMessage[] array = new MBMessageImpl[3];
1193    
1194                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1195                                            companyId, orderByComparator, true);
1196    
1197                            array[1] = mbMessage;
1198    
1199                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1200                                            companyId, orderByComparator, false);
1201    
1202                            return array;
1203                    }
1204                    catch (Exception e) {
1205                            throw processException(e);
1206                    }
1207                    finally {
1208                            closeSession(session);
1209                    }
1210            }
1211    
1212            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1213                    MBMessage mbMessage, String uuid, long companyId,
1214                    OrderByComparator orderByComparator, boolean previous) {
1215                    StringBundler query = null;
1216    
1217                    if (orderByComparator != null) {
1218                            query = new StringBundler(6 +
1219                                            (orderByComparator.getOrderByFields().length * 6));
1220                    }
1221                    else {
1222                            query = new StringBundler(3);
1223                    }
1224    
1225                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1226    
1227                    boolean bindUuid = false;
1228    
1229                    if (uuid == null) {
1230                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1231                    }
1232                    else if (uuid.equals(StringPool.BLANK)) {
1233                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1234                    }
1235                    else {
1236                            bindUuid = true;
1237    
1238                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1239                    }
1240    
1241                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1242    
1243                    if (orderByComparator != null) {
1244                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1245    
1246                            if (orderByConditionFields.length > 0) {
1247                                    query.append(WHERE_AND);
1248                            }
1249    
1250                            for (int i = 0; i < orderByConditionFields.length; i++) {
1251                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1252                                    query.append(orderByConditionFields[i]);
1253    
1254                                    if ((i + 1) < orderByConditionFields.length) {
1255                                            if (orderByComparator.isAscending() ^ previous) {
1256                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1257                                            }
1258                                            else {
1259                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1260                                            }
1261                                    }
1262                                    else {
1263                                            if (orderByComparator.isAscending() ^ previous) {
1264                                                    query.append(WHERE_GREATER_THAN);
1265                                            }
1266                                            else {
1267                                                    query.append(WHERE_LESSER_THAN);
1268                                            }
1269                                    }
1270                            }
1271    
1272                            query.append(ORDER_BY_CLAUSE);
1273    
1274                            String[] orderByFields = orderByComparator.getOrderByFields();
1275    
1276                            for (int i = 0; i < orderByFields.length; i++) {
1277                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1278                                    query.append(orderByFields[i]);
1279    
1280                                    if ((i + 1) < orderByFields.length) {
1281                                            if (orderByComparator.isAscending() ^ previous) {
1282                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1283                                            }
1284                                            else {
1285                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1286                                            }
1287                                    }
1288                                    else {
1289                                            if (orderByComparator.isAscending() ^ previous) {
1290                                                    query.append(ORDER_BY_ASC);
1291                                            }
1292                                            else {
1293                                                    query.append(ORDER_BY_DESC);
1294                                            }
1295                                    }
1296                            }
1297                    }
1298                    else {
1299                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1300                    }
1301    
1302                    String sql = query.toString();
1303    
1304                    Query q = session.createQuery(sql);
1305    
1306                    q.setFirstResult(0);
1307                    q.setMaxResults(2);
1308    
1309                    QueryPos qPos = QueryPos.getInstance(q);
1310    
1311                    if (bindUuid) {
1312                            qPos.add(uuid);
1313                    }
1314    
1315                    qPos.add(companyId);
1316    
1317                    if (orderByComparator != null) {
1318                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1319    
1320                            for (Object value : values) {
1321                                    qPos.add(value);
1322                            }
1323                    }
1324    
1325                    List<MBMessage> list = q.list();
1326    
1327                    if (list.size() == 2) {
1328                            return list.get(1);
1329                    }
1330                    else {
1331                            return null;
1332                    }
1333            }
1334    
1335            /**
1336             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1337             *
1338             * @param uuid the uuid
1339             * @param companyId the company ID
1340             * @throws SystemException if a system exception occurred
1341             */
1342            public void removeByUuid_C(String uuid, long companyId)
1343                    throws SystemException {
1344                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1345                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1346                            remove(mbMessage);
1347                    }
1348            }
1349    
1350            /**
1351             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1352             *
1353             * @param uuid the uuid
1354             * @param companyId the company ID
1355             * @return the number of matching message-boards messages
1356             * @throws SystemException if a system exception occurred
1357             */
1358            public int countByUuid_C(String uuid, long companyId)
1359                    throws SystemException {
1360                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1361    
1362                    Object[] finderArgs = new Object[] { uuid, companyId };
1363    
1364                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1365                                    this);
1366    
1367                    if (count == null) {
1368                            StringBundler query = new StringBundler(3);
1369    
1370                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1371    
1372                            boolean bindUuid = false;
1373    
1374                            if (uuid == null) {
1375                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1376                            }
1377                            else if (uuid.equals(StringPool.BLANK)) {
1378                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1379                            }
1380                            else {
1381                                    bindUuid = true;
1382    
1383                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1384                            }
1385    
1386                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1387    
1388                            String sql = query.toString();
1389    
1390                            Session session = null;
1391    
1392                            try {
1393                                    session = openSession();
1394    
1395                                    Query q = session.createQuery(sql);
1396    
1397                                    QueryPos qPos = QueryPos.getInstance(q);
1398    
1399                                    if (bindUuid) {
1400                                            qPos.add(uuid);
1401                                    }
1402    
1403                                    qPos.add(companyId);
1404    
1405                                    count = (Long)q.uniqueResult();
1406    
1407                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1408                            }
1409                            catch (Exception e) {
1410                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1411    
1412                                    throw processException(e);
1413                            }
1414                            finally {
1415                                    closeSession(session);
1416                            }
1417                    }
1418    
1419                    return count.intValue();
1420            }
1421    
1422            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1423            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1424            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1425            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1426            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1427                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1428                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1429                            new String[] {
1430                                    Long.class.getName(),
1431                                    
1432                            Integer.class.getName(), Integer.class.getName(),
1433                                    OrderByComparator.class.getName()
1434                            });
1435            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1436                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1437                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1438                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1439                            new String[] { Long.class.getName() },
1440                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1441                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1442            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1443                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1444                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1445                            new String[] { Long.class.getName() });
1446    
1447            /**
1448             * Returns all the message-boards messages where groupId = &#63;.
1449             *
1450             * @param groupId the group ID
1451             * @return the matching message-boards messages
1452             * @throws SystemException if a system exception occurred
1453             */
1454            public List<MBMessage> findByGroupId(long groupId)
1455                    throws SystemException {
1456                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1457            }
1458    
1459            /**
1460             * Returns a range of all the message-boards messages where groupId = &#63;.
1461             *
1462             * <p>
1463             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1464             * </p>
1465             *
1466             * @param groupId the group ID
1467             * @param start the lower bound of the range of message-boards messages
1468             * @param end the upper bound of the range of message-boards messages (not inclusive)
1469             * @return the range of matching message-boards messages
1470             * @throws SystemException if a system exception occurred
1471             */
1472            public List<MBMessage> findByGroupId(long groupId, int start, int end)
1473                    throws SystemException {
1474                    return findByGroupId(groupId, start, end, null);
1475            }
1476    
1477            /**
1478             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1479             *
1480             * <p>
1481             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1482             * </p>
1483             *
1484             * @param groupId the group ID
1485             * @param start the lower bound of the range of message-boards messages
1486             * @param end the upper bound of the range of message-boards messages (not inclusive)
1487             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1488             * @return the ordered range of matching message-boards messages
1489             * @throws SystemException if a system exception occurred
1490             */
1491            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1492                    OrderByComparator orderByComparator) throws SystemException {
1493                    boolean pagination = true;
1494                    FinderPath finderPath = null;
1495                    Object[] finderArgs = null;
1496    
1497                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1498                                    (orderByComparator == null)) {
1499                            pagination = false;
1500                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1501                            finderArgs = new Object[] { groupId };
1502                    }
1503                    else {
1504                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1505                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1506                    }
1507    
1508                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1509                                    finderArgs, this);
1510    
1511                    if ((list != null) && !list.isEmpty()) {
1512                            for (MBMessage mbMessage : list) {
1513                                    if ((groupId != mbMessage.getGroupId())) {
1514                                            list = null;
1515    
1516                                            break;
1517                                    }
1518                            }
1519                    }
1520    
1521                    if (list == null) {
1522                            StringBundler query = null;
1523    
1524                            if (orderByComparator != null) {
1525                                    query = new StringBundler(3 +
1526                                                    (orderByComparator.getOrderByFields().length * 3));
1527                            }
1528                            else {
1529                                    query = new StringBundler(3);
1530                            }
1531    
1532                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1533    
1534                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1535    
1536                            if (orderByComparator != null) {
1537                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1538                                            orderByComparator);
1539                            }
1540                            else
1541                             if (pagination) {
1542                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1543                            }
1544    
1545                            String sql = query.toString();
1546    
1547                            Session session = null;
1548    
1549                            try {
1550                                    session = openSession();
1551    
1552                                    Query q = session.createQuery(sql);
1553    
1554                                    QueryPos qPos = QueryPos.getInstance(q);
1555    
1556                                    qPos.add(groupId);
1557    
1558                                    if (!pagination) {
1559                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1560                                                            start, end, false);
1561    
1562                                            Collections.sort(list);
1563    
1564                                            list = new UnmodifiableList<MBMessage>(list);
1565                                    }
1566                                    else {
1567                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1568                                                            start, end);
1569                                    }
1570    
1571                                    cacheResult(list);
1572    
1573                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1574                            }
1575                            catch (Exception e) {
1576                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1577    
1578                                    throw processException(e);
1579                            }
1580                            finally {
1581                                    closeSession(session);
1582                            }
1583                    }
1584    
1585                    return list;
1586            }
1587    
1588            /**
1589             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1590             *
1591             * @param groupId the group ID
1592             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1593             * @return the first matching message-boards message
1594             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1595             * @throws SystemException if a system exception occurred
1596             */
1597            public MBMessage findByGroupId_First(long groupId,
1598                    OrderByComparator orderByComparator)
1599                    throws NoSuchMessageException, SystemException {
1600                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1601    
1602                    if (mbMessage != null) {
1603                            return mbMessage;
1604                    }
1605    
1606                    StringBundler msg = new StringBundler(4);
1607    
1608                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1609    
1610                    msg.append("groupId=");
1611                    msg.append(groupId);
1612    
1613                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1614    
1615                    throw new NoSuchMessageException(msg.toString());
1616            }
1617    
1618            /**
1619             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1620             *
1621             * @param groupId the group ID
1622             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1623             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1624             * @throws SystemException if a system exception occurred
1625             */
1626            public MBMessage fetchByGroupId_First(long groupId,
1627                    OrderByComparator orderByComparator) throws SystemException {
1628                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1629    
1630                    if (!list.isEmpty()) {
1631                            return list.get(0);
1632                    }
1633    
1634                    return null;
1635            }
1636    
1637            /**
1638             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1639             *
1640             * @param groupId the group ID
1641             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1642             * @return the last matching message-boards message
1643             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1644             * @throws SystemException if a system exception occurred
1645             */
1646            public MBMessage findByGroupId_Last(long groupId,
1647                    OrderByComparator orderByComparator)
1648                    throws NoSuchMessageException, SystemException {
1649                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1650    
1651                    if (mbMessage != null) {
1652                            return mbMessage;
1653                    }
1654    
1655                    StringBundler msg = new StringBundler(4);
1656    
1657                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1658    
1659                    msg.append("groupId=");
1660                    msg.append(groupId);
1661    
1662                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1663    
1664                    throw new NoSuchMessageException(msg.toString());
1665            }
1666    
1667            /**
1668             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1669             *
1670             * @param groupId the group ID
1671             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1672             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1673             * @throws SystemException if a system exception occurred
1674             */
1675            public MBMessage fetchByGroupId_Last(long groupId,
1676                    OrderByComparator orderByComparator) throws SystemException {
1677                    int count = countByGroupId(groupId);
1678    
1679                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1680                                    orderByComparator);
1681    
1682                    if (!list.isEmpty()) {
1683                            return list.get(0);
1684                    }
1685    
1686                    return null;
1687            }
1688    
1689            /**
1690             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1691             *
1692             * @param messageId the primary key of the current message-boards message
1693             * @param groupId the group ID
1694             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1695             * @return the previous, current, and next message-boards message
1696             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1697             * @throws SystemException if a system exception occurred
1698             */
1699            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1700                    OrderByComparator orderByComparator)
1701                    throws NoSuchMessageException, SystemException {
1702                    MBMessage mbMessage = findByPrimaryKey(messageId);
1703    
1704                    Session session = null;
1705    
1706                    try {
1707                            session = openSession();
1708    
1709                            MBMessage[] array = new MBMessageImpl[3];
1710    
1711                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1712                                            orderByComparator, true);
1713    
1714                            array[1] = mbMessage;
1715    
1716                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1717                                            orderByComparator, false);
1718    
1719                            return array;
1720                    }
1721                    catch (Exception e) {
1722                            throw processException(e);
1723                    }
1724                    finally {
1725                            closeSession(session);
1726                    }
1727            }
1728    
1729            protected MBMessage getByGroupId_PrevAndNext(Session session,
1730                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1731                    boolean previous) {
1732                    StringBundler query = null;
1733    
1734                    if (orderByComparator != null) {
1735                            query = new StringBundler(6 +
1736                                            (orderByComparator.getOrderByFields().length * 6));
1737                    }
1738                    else {
1739                            query = new StringBundler(3);
1740                    }
1741    
1742                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1743    
1744                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1745    
1746                    if (orderByComparator != null) {
1747                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1748    
1749                            if (orderByConditionFields.length > 0) {
1750                                    query.append(WHERE_AND);
1751                            }
1752    
1753                            for (int i = 0; i < orderByConditionFields.length; i++) {
1754                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1755                                    query.append(orderByConditionFields[i]);
1756    
1757                                    if ((i + 1) < orderByConditionFields.length) {
1758                                            if (orderByComparator.isAscending() ^ previous) {
1759                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1760                                            }
1761                                            else {
1762                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1763                                            }
1764                                    }
1765                                    else {
1766                                            if (orderByComparator.isAscending() ^ previous) {
1767                                                    query.append(WHERE_GREATER_THAN);
1768                                            }
1769                                            else {
1770                                                    query.append(WHERE_LESSER_THAN);
1771                                            }
1772                                    }
1773                            }
1774    
1775                            query.append(ORDER_BY_CLAUSE);
1776    
1777                            String[] orderByFields = orderByComparator.getOrderByFields();
1778    
1779                            for (int i = 0; i < orderByFields.length; i++) {
1780                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1781                                    query.append(orderByFields[i]);
1782    
1783                                    if ((i + 1) < orderByFields.length) {
1784                                            if (orderByComparator.isAscending() ^ previous) {
1785                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1786                                            }
1787                                            else {
1788                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1789                                            }
1790                                    }
1791                                    else {
1792                                            if (orderByComparator.isAscending() ^ previous) {
1793                                                    query.append(ORDER_BY_ASC);
1794                                            }
1795                                            else {
1796                                                    query.append(ORDER_BY_DESC);
1797                                            }
1798                                    }
1799                            }
1800                    }
1801                    else {
1802                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1803                    }
1804    
1805                    String sql = query.toString();
1806    
1807                    Query q = session.createQuery(sql);
1808    
1809                    q.setFirstResult(0);
1810                    q.setMaxResults(2);
1811    
1812                    QueryPos qPos = QueryPos.getInstance(q);
1813    
1814                    qPos.add(groupId);
1815    
1816                    if (orderByComparator != null) {
1817                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1818    
1819                            for (Object value : values) {
1820                                    qPos.add(value);
1821                            }
1822                    }
1823    
1824                    List<MBMessage> list = q.list();
1825    
1826                    if (list.size() == 2) {
1827                            return list.get(1);
1828                    }
1829                    else {
1830                            return null;
1831                    }
1832            }
1833    
1834            /**
1835             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1836             *
1837             * @param groupId the group ID
1838             * @return the matching message-boards messages that the user has permission to view
1839             * @throws SystemException if a system exception occurred
1840             */
1841            public List<MBMessage> filterFindByGroupId(long groupId)
1842                    throws SystemException {
1843                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1844                            QueryUtil.ALL_POS, null);
1845            }
1846    
1847            /**
1848             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1849             *
1850             * <p>
1851             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1852             * </p>
1853             *
1854             * @param groupId the group ID
1855             * @param start the lower bound of the range of message-boards messages
1856             * @param end the upper bound of the range of message-boards messages (not inclusive)
1857             * @return the range of matching message-boards messages that the user has permission to view
1858             * @throws SystemException if a system exception occurred
1859             */
1860            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
1861                    throws SystemException {
1862                    return filterFindByGroupId(groupId, start, end, null);
1863            }
1864    
1865            /**
1866             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1867             *
1868             * <p>
1869             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
1870             * </p>
1871             *
1872             * @param groupId the group ID
1873             * @param start the lower bound of the range of message-boards messages
1874             * @param end the upper bound of the range of message-boards messages (not inclusive)
1875             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1876             * @return the ordered range of matching message-boards messages that the user has permission to view
1877             * @throws SystemException if a system exception occurred
1878             */
1879            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1880                    int end, OrderByComparator orderByComparator) throws SystemException {
1881                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1882                            return findByGroupId(groupId, start, end, orderByComparator);
1883                    }
1884    
1885                    StringBundler query = null;
1886    
1887                    if (orderByComparator != null) {
1888                            query = new StringBundler(3 +
1889                                            (orderByComparator.getOrderByFields().length * 3));
1890                    }
1891                    else {
1892                            query = new StringBundler(3);
1893                    }
1894    
1895                    if (getDB().isSupportsInlineDistinct()) {
1896                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1897                    }
1898                    else {
1899                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1900                    }
1901    
1902                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1903    
1904                    if (!getDB().isSupportsInlineDistinct()) {
1905                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1906                    }
1907    
1908                    if (orderByComparator != null) {
1909                            if (getDB().isSupportsInlineDistinct()) {
1910                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1911                                            orderByComparator);
1912                            }
1913                            else {
1914                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1915                                            orderByComparator);
1916                            }
1917                    }
1918                    else {
1919                            if (getDB().isSupportsInlineDistinct()) {
1920                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1921                            }
1922                            else {
1923                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
1924                            }
1925                    }
1926    
1927                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1928                                    MBMessage.class.getName(),
1929                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1930    
1931                    Session session = null;
1932    
1933                    try {
1934                            session = openSession();
1935    
1936                            SQLQuery q = session.createSQLQuery(sql);
1937    
1938                            if (getDB().isSupportsInlineDistinct()) {
1939                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
1940                            }
1941                            else {
1942                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
1943                            }
1944    
1945                            QueryPos qPos = QueryPos.getInstance(q);
1946    
1947                            qPos.add(groupId);
1948    
1949                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
1950                    }
1951                    catch (Exception e) {
1952                            throw processException(e);
1953                    }
1954                    finally {
1955                            closeSession(session);
1956                    }
1957            }
1958    
1959            /**
1960             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63;.
1961             *
1962             * @param messageId the primary key of the current message-boards message
1963             * @param groupId the group ID
1964             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1965             * @return the previous, current, and next message-boards message
1966             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1967             * @throws SystemException if a system exception occurred
1968             */
1969            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
1970                    long groupId, OrderByComparator orderByComparator)
1971                    throws NoSuchMessageException, SystemException {
1972                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1973                            return findByGroupId_PrevAndNext(messageId, groupId,
1974                                    orderByComparator);
1975                    }
1976    
1977                    MBMessage mbMessage = findByPrimaryKey(messageId);
1978    
1979                    Session session = null;
1980    
1981                    try {
1982                            session = openSession();
1983    
1984                            MBMessage[] array = new MBMessageImpl[3];
1985    
1986                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1987                                            groupId, orderByComparator, true);
1988    
1989                            array[1] = mbMessage;
1990    
1991                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1992                                            groupId, orderByComparator, false);
1993    
1994                            return array;
1995                    }
1996                    catch (Exception e) {
1997                            throw processException(e);
1998                    }
1999                    finally {
2000                            closeSession(session);
2001                    }
2002            }
2003    
2004            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2005                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2006                    boolean previous) {
2007                    StringBundler query = null;
2008    
2009                    if (orderByComparator != null) {
2010                            query = new StringBundler(6 +
2011                                            (orderByComparator.getOrderByFields().length * 6));
2012                    }
2013                    else {
2014                            query = new StringBundler(3);
2015                    }
2016    
2017                    if (getDB().isSupportsInlineDistinct()) {
2018                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2019                    }
2020                    else {
2021                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2022                    }
2023    
2024                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2025    
2026                    if (!getDB().isSupportsInlineDistinct()) {
2027                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2028                    }
2029    
2030                    if (orderByComparator != null) {
2031                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2032    
2033                            if (orderByConditionFields.length > 0) {
2034                                    query.append(WHERE_AND);
2035                            }
2036    
2037                            for (int i = 0; i < orderByConditionFields.length; i++) {
2038                                    if (getDB().isSupportsInlineDistinct()) {
2039                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2040                                    }
2041                                    else {
2042                                            query.append(_ORDER_BY_ENTITY_TABLE);
2043                                    }
2044    
2045                                    query.append(orderByConditionFields[i]);
2046    
2047                                    if ((i + 1) < orderByConditionFields.length) {
2048                                            if (orderByComparator.isAscending() ^ previous) {
2049                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2050                                            }
2051                                            else {
2052                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2053                                            }
2054                                    }
2055                                    else {
2056                                            if (orderByComparator.isAscending() ^ previous) {
2057                                                    query.append(WHERE_GREATER_THAN);
2058                                            }
2059                                            else {
2060                                                    query.append(WHERE_LESSER_THAN);
2061                                            }
2062                                    }
2063                            }
2064    
2065                            query.append(ORDER_BY_CLAUSE);
2066    
2067                            String[] orderByFields = orderByComparator.getOrderByFields();
2068    
2069                            for (int i = 0; i < orderByFields.length; i++) {
2070                                    if (getDB().isSupportsInlineDistinct()) {
2071                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2072                                    }
2073                                    else {
2074                                            query.append(_ORDER_BY_ENTITY_TABLE);
2075                                    }
2076    
2077                                    query.append(orderByFields[i]);
2078    
2079                                    if ((i + 1) < orderByFields.length) {
2080                                            if (orderByComparator.isAscending() ^ previous) {
2081                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2082                                            }
2083                                            else {
2084                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2085                                            }
2086                                    }
2087                                    else {
2088                                            if (orderByComparator.isAscending() ^ previous) {
2089                                                    query.append(ORDER_BY_ASC);
2090                                            }
2091                                            else {
2092                                                    query.append(ORDER_BY_DESC);
2093                                            }
2094                                    }
2095                            }
2096                    }
2097                    else {
2098                            if (getDB().isSupportsInlineDistinct()) {
2099                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2100                            }
2101                            else {
2102                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2103                            }
2104                    }
2105    
2106                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2107                                    MBMessage.class.getName(),
2108                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2109    
2110                    SQLQuery q = session.createSQLQuery(sql);
2111    
2112                    q.setFirstResult(0);
2113                    q.setMaxResults(2);
2114    
2115                    if (getDB().isSupportsInlineDistinct()) {
2116                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2117                    }
2118                    else {
2119                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2120                    }
2121    
2122                    QueryPos qPos = QueryPos.getInstance(q);
2123    
2124                    qPos.add(groupId);
2125    
2126                    if (orderByComparator != null) {
2127                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2128    
2129                            for (Object value : values) {
2130                                    qPos.add(value);
2131                            }
2132                    }
2133    
2134                    List<MBMessage> list = q.list();
2135    
2136                    if (list.size() == 2) {
2137                            return list.get(1);
2138                    }
2139                    else {
2140                            return null;
2141                    }
2142            }
2143    
2144            /**
2145             * Removes all the message-boards messages where groupId = &#63; from the database.
2146             *
2147             * @param groupId the group ID
2148             * @throws SystemException if a system exception occurred
2149             */
2150            public void removeByGroupId(long groupId) throws SystemException {
2151                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2152                                    QueryUtil.ALL_POS, null)) {
2153                            remove(mbMessage);
2154                    }
2155            }
2156    
2157            /**
2158             * Returns the number of message-boards messages where groupId = &#63;.
2159             *
2160             * @param groupId the group ID
2161             * @return the number of matching message-boards messages
2162             * @throws SystemException if a system exception occurred
2163             */
2164            public int countByGroupId(long groupId) throws SystemException {
2165                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2166    
2167                    Object[] finderArgs = new Object[] { groupId };
2168    
2169                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2170                                    this);
2171    
2172                    if (count == null) {
2173                            StringBundler query = new StringBundler(2);
2174    
2175                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2176    
2177                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2178    
2179                            String sql = query.toString();
2180    
2181                            Session session = null;
2182    
2183                            try {
2184                                    session = openSession();
2185    
2186                                    Query q = session.createQuery(sql);
2187    
2188                                    QueryPos qPos = QueryPos.getInstance(q);
2189    
2190                                    qPos.add(groupId);
2191    
2192                                    count = (Long)q.uniqueResult();
2193    
2194                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2195                            }
2196                            catch (Exception e) {
2197                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2198    
2199                                    throw processException(e);
2200                            }
2201                            finally {
2202                                    closeSession(session);
2203                            }
2204                    }
2205    
2206                    return count.intValue();
2207            }
2208    
2209            /**
2210             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2211             *
2212             * @param groupId the group ID
2213             * @return the number of matching message-boards messages that the user has permission to view
2214             * @throws SystemException if a system exception occurred
2215             */
2216            public int filterCountByGroupId(long groupId) throws SystemException {
2217                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2218                            return countByGroupId(groupId);
2219                    }
2220    
2221                    StringBundler query = new StringBundler(2);
2222    
2223                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2224    
2225                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2226    
2227                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2228                                    MBMessage.class.getName(),
2229                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2230    
2231                    Session session = null;
2232    
2233                    try {
2234                            session = openSession();
2235    
2236                            SQLQuery q = session.createSQLQuery(sql);
2237    
2238                            q.addScalar(COUNT_COLUMN_NAME,
2239                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2240    
2241                            QueryPos qPos = QueryPos.getInstance(q);
2242    
2243                            qPos.add(groupId);
2244    
2245                            Long count = (Long)q.uniqueResult();
2246    
2247                            return count.intValue();
2248                    }
2249                    catch (Exception e) {
2250                            throw processException(e);
2251                    }
2252                    finally {
2253                            closeSession(session);
2254                    }
2255            }
2256    
2257            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2258            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2259                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2260                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2261                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2262                            new String[] {
2263                                    Long.class.getName(),
2264                                    
2265                            Integer.class.getName(), Integer.class.getName(),
2266                                    OrderByComparator.class.getName()
2267                            });
2268            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2269                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2270                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2271                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2272                            new String[] { Long.class.getName() },
2273                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2274                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2275            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2276                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2277                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2278                            new String[] { Long.class.getName() });
2279    
2280            /**
2281             * Returns all the message-boards messages where companyId = &#63;.
2282             *
2283             * @param companyId the company ID
2284             * @return the matching message-boards messages
2285             * @throws SystemException if a system exception occurred
2286             */
2287            public List<MBMessage> findByCompanyId(long companyId)
2288                    throws SystemException {
2289                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2290                            null);
2291            }
2292    
2293            /**
2294             * Returns a range of all the message-boards messages where companyId = &#63;.
2295             *
2296             * <p>
2297             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2298             * </p>
2299             *
2300             * @param companyId the company ID
2301             * @param start the lower bound of the range of message-boards messages
2302             * @param end the upper bound of the range of message-boards messages (not inclusive)
2303             * @return the range of matching message-boards messages
2304             * @throws SystemException if a system exception occurred
2305             */
2306            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
2307                    throws SystemException {
2308                    return findByCompanyId(companyId, start, end, null);
2309            }
2310    
2311            /**
2312             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2313             *
2314             * <p>
2315             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2316             * </p>
2317             *
2318             * @param companyId the company ID
2319             * @param start the lower bound of the range of message-boards messages
2320             * @param end the upper bound of the range of message-boards messages (not inclusive)
2321             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2322             * @return the ordered range of matching message-boards messages
2323             * @throws SystemException if a system exception occurred
2324             */
2325            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2326                    OrderByComparator orderByComparator) throws SystemException {
2327                    boolean pagination = true;
2328                    FinderPath finderPath = null;
2329                    Object[] finderArgs = null;
2330    
2331                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2332                                    (orderByComparator == null)) {
2333                            pagination = false;
2334                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2335                            finderArgs = new Object[] { companyId };
2336                    }
2337                    else {
2338                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2339                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2340                    }
2341    
2342                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2343                                    finderArgs, this);
2344    
2345                    if ((list != null) && !list.isEmpty()) {
2346                            for (MBMessage mbMessage : list) {
2347                                    if ((companyId != mbMessage.getCompanyId())) {
2348                                            list = null;
2349    
2350                                            break;
2351                                    }
2352                            }
2353                    }
2354    
2355                    if (list == null) {
2356                            StringBundler query = null;
2357    
2358                            if (orderByComparator != null) {
2359                                    query = new StringBundler(3 +
2360                                                    (orderByComparator.getOrderByFields().length * 3));
2361                            }
2362                            else {
2363                                    query = new StringBundler(3);
2364                            }
2365    
2366                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2367    
2368                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2369    
2370                            if (orderByComparator != null) {
2371                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2372                                            orderByComparator);
2373                            }
2374                            else
2375                             if (pagination) {
2376                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2377                            }
2378    
2379                            String sql = query.toString();
2380    
2381                            Session session = null;
2382    
2383                            try {
2384                                    session = openSession();
2385    
2386                                    Query q = session.createQuery(sql);
2387    
2388                                    QueryPos qPos = QueryPos.getInstance(q);
2389    
2390                                    qPos.add(companyId);
2391    
2392                                    if (!pagination) {
2393                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2394                                                            start, end, false);
2395    
2396                                            Collections.sort(list);
2397    
2398                                            list = new UnmodifiableList<MBMessage>(list);
2399                                    }
2400                                    else {
2401                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2402                                                            start, end);
2403                                    }
2404    
2405                                    cacheResult(list);
2406    
2407                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2408                            }
2409                            catch (Exception e) {
2410                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2411    
2412                                    throw processException(e);
2413                            }
2414                            finally {
2415                                    closeSession(session);
2416                            }
2417                    }
2418    
2419                    return list;
2420            }
2421    
2422            /**
2423             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2424             *
2425             * @param companyId the company ID
2426             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2427             * @return the first matching message-boards message
2428             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2429             * @throws SystemException if a system exception occurred
2430             */
2431            public MBMessage findByCompanyId_First(long companyId,
2432                    OrderByComparator orderByComparator)
2433                    throws NoSuchMessageException, SystemException {
2434                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2435                                    orderByComparator);
2436    
2437                    if (mbMessage != null) {
2438                            return mbMessage;
2439                    }
2440    
2441                    StringBundler msg = new StringBundler(4);
2442    
2443                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2444    
2445                    msg.append("companyId=");
2446                    msg.append(companyId);
2447    
2448                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2449    
2450                    throw new NoSuchMessageException(msg.toString());
2451            }
2452    
2453            /**
2454             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2455             *
2456             * @param companyId the company ID
2457             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2458             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2459             * @throws SystemException if a system exception occurred
2460             */
2461            public MBMessage fetchByCompanyId_First(long companyId,
2462                    OrderByComparator orderByComparator) throws SystemException {
2463                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2464                                    orderByComparator);
2465    
2466                    if (!list.isEmpty()) {
2467                            return list.get(0);
2468                    }
2469    
2470                    return null;
2471            }
2472    
2473            /**
2474             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2475             *
2476             * @param companyId the company ID
2477             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2478             * @return the last matching message-boards message
2479             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2480             * @throws SystemException if a system exception occurred
2481             */
2482            public MBMessage findByCompanyId_Last(long companyId,
2483                    OrderByComparator orderByComparator)
2484                    throws NoSuchMessageException, SystemException {
2485                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2486    
2487                    if (mbMessage != null) {
2488                            return mbMessage;
2489                    }
2490    
2491                    StringBundler msg = new StringBundler(4);
2492    
2493                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2494    
2495                    msg.append("companyId=");
2496                    msg.append(companyId);
2497    
2498                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2499    
2500                    throw new NoSuchMessageException(msg.toString());
2501            }
2502    
2503            /**
2504             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2505             *
2506             * @param companyId the company ID
2507             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2508             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2509             * @throws SystemException if a system exception occurred
2510             */
2511            public MBMessage fetchByCompanyId_Last(long companyId,
2512                    OrderByComparator orderByComparator) throws SystemException {
2513                    int count = countByCompanyId(companyId);
2514    
2515                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2516                                    orderByComparator);
2517    
2518                    if (!list.isEmpty()) {
2519                            return list.get(0);
2520                    }
2521    
2522                    return null;
2523            }
2524    
2525            /**
2526             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2527             *
2528             * @param messageId the primary key of the current message-boards message
2529             * @param companyId the company ID
2530             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2531             * @return the previous, current, and next message-boards message
2532             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2533             * @throws SystemException if a system exception occurred
2534             */
2535            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2536                    long companyId, OrderByComparator orderByComparator)
2537                    throws NoSuchMessageException, SystemException {
2538                    MBMessage mbMessage = findByPrimaryKey(messageId);
2539    
2540                    Session session = null;
2541    
2542                    try {
2543                            session = openSession();
2544    
2545                            MBMessage[] array = new MBMessageImpl[3];
2546    
2547                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2548                                            companyId, orderByComparator, true);
2549    
2550                            array[1] = mbMessage;
2551    
2552                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2553                                            companyId, orderByComparator, false);
2554    
2555                            return array;
2556                    }
2557                    catch (Exception e) {
2558                            throw processException(e);
2559                    }
2560                    finally {
2561                            closeSession(session);
2562                    }
2563            }
2564    
2565            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2566                    MBMessage mbMessage, long companyId,
2567                    OrderByComparator orderByComparator, boolean previous) {
2568                    StringBundler query = null;
2569    
2570                    if (orderByComparator != null) {
2571                            query = new StringBundler(6 +
2572                                            (orderByComparator.getOrderByFields().length * 6));
2573                    }
2574                    else {
2575                            query = new StringBundler(3);
2576                    }
2577    
2578                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2579    
2580                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2581    
2582                    if (orderByComparator != null) {
2583                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2584    
2585                            if (orderByConditionFields.length > 0) {
2586                                    query.append(WHERE_AND);
2587                            }
2588    
2589                            for (int i = 0; i < orderByConditionFields.length; i++) {
2590                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2591                                    query.append(orderByConditionFields[i]);
2592    
2593                                    if ((i + 1) < orderByConditionFields.length) {
2594                                            if (orderByComparator.isAscending() ^ previous) {
2595                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2596                                            }
2597                                            else {
2598                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2599                                            }
2600                                    }
2601                                    else {
2602                                            if (orderByComparator.isAscending() ^ previous) {
2603                                                    query.append(WHERE_GREATER_THAN);
2604                                            }
2605                                            else {
2606                                                    query.append(WHERE_LESSER_THAN);
2607                                            }
2608                                    }
2609                            }
2610    
2611                            query.append(ORDER_BY_CLAUSE);
2612    
2613                            String[] orderByFields = orderByComparator.getOrderByFields();
2614    
2615                            for (int i = 0; i < orderByFields.length; i++) {
2616                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2617                                    query.append(orderByFields[i]);
2618    
2619                                    if ((i + 1) < orderByFields.length) {
2620                                            if (orderByComparator.isAscending() ^ previous) {
2621                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2622                                            }
2623                                            else {
2624                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2625                                            }
2626                                    }
2627                                    else {
2628                                            if (orderByComparator.isAscending() ^ previous) {
2629                                                    query.append(ORDER_BY_ASC);
2630                                            }
2631                                            else {
2632                                                    query.append(ORDER_BY_DESC);
2633                                            }
2634                                    }
2635                            }
2636                    }
2637                    else {
2638                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2639                    }
2640    
2641                    String sql = query.toString();
2642    
2643                    Query q = session.createQuery(sql);
2644    
2645                    q.setFirstResult(0);
2646                    q.setMaxResults(2);
2647    
2648                    QueryPos qPos = QueryPos.getInstance(q);
2649    
2650                    qPos.add(companyId);
2651    
2652                    if (orderByComparator != null) {
2653                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2654    
2655                            for (Object value : values) {
2656                                    qPos.add(value);
2657                            }
2658                    }
2659    
2660                    List<MBMessage> list = q.list();
2661    
2662                    if (list.size() == 2) {
2663                            return list.get(1);
2664                    }
2665                    else {
2666                            return null;
2667                    }
2668            }
2669    
2670            /**
2671             * Removes all the message-boards messages where companyId = &#63; from the database.
2672             *
2673             * @param companyId the company ID
2674             * @throws SystemException if a system exception occurred
2675             */
2676            public void removeByCompanyId(long companyId) throws SystemException {
2677                    for (MBMessage mbMessage : findByCompanyId(companyId,
2678                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2679                            remove(mbMessage);
2680                    }
2681            }
2682    
2683            /**
2684             * Returns the number of message-boards messages where companyId = &#63;.
2685             *
2686             * @param companyId the company ID
2687             * @return the number of matching message-boards messages
2688             * @throws SystemException if a system exception occurred
2689             */
2690            public int countByCompanyId(long companyId) throws SystemException {
2691                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2692    
2693                    Object[] finderArgs = new Object[] { companyId };
2694    
2695                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2696                                    this);
2697    
2698                    if (count == null) {
2699                            StringBundler query = new StringBundler(2);
2700    
2701                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2702    
2703                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2704    
2705                            String sql = query.toString();
2706    
2707                            Session session = null;
2708    
2709                            try {
2710                                    session = openSession();
2711    
2712                                    Query q = session.createQuery(sql);
2713    
2714                                    QueryPos qPos = QueryPos.getInstance(q);
2715    
2716                                    qPos.add(companyId);
2717    
2718                                    count = (Long)q.uniqueResult();
2719    
2720                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2721                            }
2722                            catch (Exception e) {
2723                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2724    
2725                                    throw processException(e);
2726                            }
2727                            finally {
2728                                    closeSession(session);
2729                            }
2730                    }
2731    
2732                    return count.intValue();
2733            }
2734    
2735            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2736            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2737                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2738                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
2739                            new String[] {
2740                                    Long.class.getName(),
2741                                    
2742                            Integer.class.getName(), Integer.class.getName(),
2743                                    OrderByComparator.class.getName()
2744                            });
2745            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
2746                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2747                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2748                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
2749                            new String[] { Long.class.getName() },
2750                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
2751                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2752            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2753                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2754                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
2755                            new String[] { Long.class.getName() });
2756    
2757            /**
2758             * Returns all the message-boards messages where threadId = &#63;.
2759             *
2760             * @param threadId the thread ID
2761             * @return the matching message-boards messages
2762             * @throws SystemException if a system exception occurred
2763             */
2764            public List<MBMessage> findByThreadId(long threadId)
2765                    throws SystemException {
2766                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2767                            null);
2768            }
2769    
2770            /**
2771             * Returns a range of all the message-boards messages where threadId = &#63;.
2772             *
2773             * <p>
2774             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2775             * </p>
2776             *
2777             * @param threadId the thread ID
2778             * @param start the lower bound of the range of message-boards messages
2779             * @param end the upper bound of the range of message-boards messages (not inclusive)
2780             * @return the range of matching message-boards messages
2781             * @throws SystemException if a system exception occurred
2782             */
2783            public List<MBMessage> findByThreadId(long threadId, int start, int end)
2784                    throws SystemException {
2785                    return findByThreadId(threadId, start, end, null);
2786            }
2787    
2788            /**
2789             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
2790             *
2791             * <p>
2792             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
2793             * </p>
2794             *
2795             * @param threadId the thread ID
2796             * @param start the lower bound of the range of message-boards messages
2797             * @param end the upper bound of the range of message-boards messages (not inclusive)
2798             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2799             * @return the ordered range of matching message-boards messages
2800             * @throws SystemException if a system exception occurred
2801             */
2802            public List<MBMessage> findByThreadId(long threadId, int start, int end,
2803                    OrderByComparator orderByComparator) throws SystemException {
2804                    boolean pagination = true;
2805                    FinderPath finderPath = null;
2806                    Object[] finderArgs = null;
2807    
2808                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2809                                    (orderByComparator == null)) {
2810                            pagination = false;
2811                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
2812                            finderArgs = new Object[] { threadId };
2813                    }
2814                    else {
2815                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
2816                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
2817                    }
2818    
2819                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2820                                    finderArgs, this);
2821    
2822                    if ((list != null) && !list.isEmpty()) {
2823                            for (MBMessage mbMessage : list) {
2824                                    if ((threadId != mbMessage.getThreadId())) {
2825                                            list = null;
2826    
2827                                            break;
2828                                    }
2829                            }
2830                    }
2831    
2832                    if (list == null) {
2833                            StringBundler query = null;
2834    
2835                            if (orderByComparator != null) {
2836                                    query = new StringBundler(3 +
2837                                                    (orderByComparator.getOrderByFields().length * 3));
2838                            }
2839                            else {
2840                                    query = new StringBundler(3);
2841                            }
2842    
2843                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2844    
2845                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2846    
2847                            if (orderByComparator != null) {
2848                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2849                                            orderByComparator);
2850                            }
2851                            else
2852                             if (pagination) {
2853                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2854                            }
2855    
2856                            String sql = query.toString();
2857    
2858                            Session session = null;
2859    
2860                            try {
2861                                    session = openSession();
2862    
2863                                    Query q = session.createQuery(sql);
2864    
2865                                    QueryPos qPos = QueryPos.getInstance(q);
2866    
2867                                    qPos.add(threadId);
2868    
2869                                    if (!pagination) {
2870                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2871                                                            start, end, false);
2872    
2873                                            Collections.sort(list);
2874    
2875                                            list = new UnmodifiableList<MBMessage>(list);
2876                                    }
2877                                    else {
2878                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2879                                                            start, end);
2880                                    }
2881    
2882                                    cacheResult(list);
2883    
2884                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2885                            }
2886                            catch (Exception e) {
2887                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2888    
2889                                    throw processException(e);
2890                            }
2891                            finally {
2892                                    closeSession(session);
2893                            }
2894                    }
2895    
2896                    return list;
2897            }
2898    
2899            /**
2900             * Returns the first message-boards message in the ordered set where threadId = &#63;.
2901             *
2902             * @param threadId the thread ID
2903             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2904             * @return the first matching message-boards message
2905             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2906             * @throws SystemException if a system exception occurred
2907             */
2908            public MBMessage findByThreadId_First(long threadId,
2909                    OrderByComparator orderByComparator)
2910                    throws NoSuchMessageException, SystemException {
2911                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
2912    
2913                    if (mbMessage != null) {
2914                            return mbMessage;
2915                    }
2916    
2917                    StringBundler msg = new StringBundler(4);
2918    
2919                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2920    
2921                    msg.append("threadId=");
2922                    msg.append(threadId);
2923    
2924                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2925    
2926                    throw new NoSuchMessageException(msg.toString());
2927            }
2928    
2929            /**
2930             * Returns the first message-boards message in the ordered set where threadId = &#63;.
2931             *
2932             * @param threadId the thread ID
2933             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2934             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2935             * @throws SystemException if a system exception occurred
2936             */
2937            public MBMessage fetchByThreadId_First(long threadId,
2938                    OrderByComparator orderByComparator) throws SystemException {
2939                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
2940    
2941                    if (!list.isEmpty()) {
2942                            return list.get(0);
2943                    }
2944    
2945                    return null;
2946            }
2947    
2948            /**
2949             * Returns the last message-boards message in the ordered set where threadId = &#63;.
2950             *
2951             * @param threadId the thread ID
2952             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2953             * @return the last matching message-boards message
2954             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2955             * @throws SystemException if a system exception occurred
2956             */
2957            public MBMessage findByThreadId_Last(long threadId,
2958                    OrderByComparator orderByComparator)
2959                    throws NoSuchMessageException, SystemException {
2960                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
2961    
2962                    if (mbMessage != null) {
2963                            return mbMessage;
2964                    }
2965    
2966                    StringBundler msg = new StringBundler(4);
2967    
2968                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2969    
2970                    msg.append("threadId=");
2971                    msg.append(threadId);
2972    
2973                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2974    
2975                    throw new NoSuchMessageException(msg.toString());
2976            }
2977    
2978            /**
2979             * Returns the last message-boards message in the ordered set where threadId = &#63;.
2980             *
2981             * @param threadId the thread ID
2982             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2983             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2984             * @throws SystemException if a system exception occurred
2985             */
2986            public MBMessage fetchByThreadId_Last(long threadId,
2987                    OrderByComparator orderByComparator) throws SystemException {
2988                    int count = countByThreadId(threadId);
2989    
2990                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
2991                                    orderByComparator);
2992    
2993                    if (!list.isEmpty()) {
2994                            return list.get(0);
2995                    }
2996    
2997                    return null;
2998            }
2999    
3000            /**
3001             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3002             *
3003             * @param messageId the primary key of the current message-boards message
3004             * @param threadId the thread ID
3005             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3006             * @return the previous, current, and next message-boards message
3007             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3008             * @throws SystemException if a system exception occurred
3009             */
3010            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3011                    long threadId, OrderByComparator orderByComparator)
3012                    throws NoSuchMessageException, SystemException {
3013                    MBMessage mbMessage = findByPrimaryKey(messageId);
3014    
3015                    Session session = null;
3016    
3017                    try {
3018                            session = openSession();
3019    
3020                            MBMessage[] array = new MBMessageImpl[3];
3021    
3022                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3023                                            orderByComparator, true);
3024    
3025                            array[1] = mbMessage;
3026    
3027                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3028                                            orderByComparator, false);
3029    
3030                            return array;
3031                    }
3032                    catch (Exception e) {
3033                            throw processException(e);
3034                    }
3035                    finally {
3036                            closeSession(session);
3037                    }
3038            }
3039    
3040            protected MBMessage getByThreadId_PrevAndNext(Session session,
3041                    MBMessage mbMessage, long threadId,
3042                    OrderByComparator orderByComparator, boolean previous) {
3043                    StringBundler query = null;
3044    
3045                    if (orderByComparator != null) {
3046                            query = new StringBundler(6 +
3047                                            (orderByComparator.getOrderByFields().length * 6));
3048                    }
3049                    else {
3050                            query = new StringBundler(3);
3051                    }
3052    
3053                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3054    
3055                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3056    
3057                    if (orderByComparator != null) {
3058                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3059    
3060                            if (orderByConditionFields.length > 0) {
3061                                    query.append(WHERE_AND);
3062                            }
3063    
3064                            for (int i = 0; i < orderByConditionFields.length; i++) {
3065                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3066                                    query.append(orderByConditionFields[i]);
3067    
3068                                    if ((i + 1) < orderByConditionFields.length) {
3069                                            if (orderByComparator.isAscending() ^ previous) {
3070                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3071                                            }
3072                                            else {
3073                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3074                                            }
3075                                    }
3076                                    else {
3077                                            if (orderByComparator.isAscending() ^ previous) {
3078                                                    query.append(WHERE_GREATER_THAN);
3079                                            }
3080                                            else {
3081                                                    query.append(WHERE_LESSER_THAN);
3082                                            }
3083                                    }
3084                            }
3085    
3086                            query.append(ORDER_BY_CLAUSE);
3087    
3088                            String[] orderByFields = orderByComparator.getOrderByFields();
3089    
3090                            for (int i = 0; i < orderByFields.length; i++) {
3091                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3092                                    query.append(orderByFields[i]);
3093    
3094                                    if ((i + 1) < orderByFields.length) {
3095                                            if (orderByComparator.isAscending() ^ previous) {
3096                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3097                                            }
3098                                            else {
3099                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3100                                            }
3101                                    }
3102                                    else {
3103                                            if (orderByComparator.isAscending() ^ previous) {
3104                                                    query.append(ORDER_BY_ASC);
3105                                            }
3106                                            else {
3107                                                    query.append(ORDER_BY_DESC);
3108                                            }
3109                                    }
3110                            }
3111                    }
3112                    else {
3113                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3114                    }
3115    
3116                    String sql = query.toString();
3117    
3118                    Query q = session.createQuery(sql);
3119    
3120                    q.setFirstResult(0);
3121                    q.setMaxResults(2);
3122    
3123                    QueryPos qPos = QueryPos.getInstance(q);
3124    
3125                    qPos.add(threadId);
3126    
3127                    if (orderByComparator != null) {
3128                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3129    
3130                            for (Object value : values) {
3131                                    qPos.add(value);
3132                            }
3133                    }
3134    
3135                    List<MBMessage> list = q.list();
3136    
3137                    if (list.size() == 2) {
3138                            return list.get(1);
3139                    }
3140                    else {
3141                            return null;
3142                    }
3143            }
3144    
3145            /**
3146             * Removes all the message-boards messages where threadId = &#63; from the database.
3147             *
3148             * @param threadId the thread ID
3149             * @throws SystemException if a system exception occurred
3150             */
3151            public void removeByThreadId(long threadId) throws SystemException {
3152                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3153                                    QueryUtil.ALL_POS, null)) {
3154                            remove(mbMessage);
3155                    }
3156            }
3157    
3158            /**
3159             * Returns the number of message-boards messages where threadId = &#63;.
3160             *
3161             * @param threadId the thread ID
3162             * @return the number of matching message-boards messages
3163             * @throws SystemException if a system exception occurred
3164             */
3165            public int countByThreadId(long threadId) throws SystemException {
3166                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3167    
3168                    Object[] finderArgs = new Object[] { threadId };
3169    
3170                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3171                                    this);
3172    
3173                    if (count == null) {
3174                            StringBundler query = new StringBundler(2);
3175    
3176                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3177    
3178                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3179    
3180                            String sql = query.toString();
3181    
3182                            Session session = null;
3183    
3184                            try {
3185                                    session = openSession();
3186    
3187                                    Query q = session.createQuery(sql);
3188    
3189                                    QueryPos qPos = QueryPos.getInstance(q);
3190    
3191                                    qPos.add(threadId);
3192    
3193                                    count = (Long)q.uniqueResult();
3194    
3195                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3196                            }
3197                            catch (Exception e) {
3198                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3199    
3200                                    throw processException(e);
3201                            }
3202                            finally {
3203                                    closeSession(session);
3204                            }
3205                    }
3206    
3207                    return count.intValue();
3208            }
3209    
3210            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3211            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3212                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3213                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3214                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3215                            new String[] {
3216                                    Long.class.getName(),
3217                                    
3218                            Integer.class.getName(), Integer.class.getName(),
3219                                    OrderByComparator.class.getName()
3220                            });
3221            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3222                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3223                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3224                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3225                            new String[] { Long.class.getName() },
3226                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3227                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3228            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3229                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3230                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3231                            new String[] { Long.class.getName() });
3232    
3233            /**
3234             * Returns all the message-boards messages where threadId = &#63;.
3235             *
3236             * @param threadId the thread ID
3237             * @return the matching message-boards messages
3238             * @throws SystemException if a system exception occurred
3239             */
3240            public List<MBMessage> findByThreadReplies(long threadId)
3241                    throws SystemException {
3242                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3243                            QueryUtil.ALL_POS, null);
3244            }
3245    
3246            /**
3247             * Returns a range of all the message-boards messages where threadId = &#63;.
3248             *
3249             * <p>
3250             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3251             * </p>
3252             *
3253             * @param threadId the thread ID
3254             * @param start the lower bound of the range of message-boards messages
3255             * @param end the upper bound of the range of message-boards messages (not inclusive)
3256             * @return the range of matching message-boards messages
3257             * @throws SystemException if a system exception occurred
3258             */
3259            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
3260                    throws SystemException {
3261                    return findByThreadReplies(threadId, start, end, null);
3262            }
3263    
3264            /**
3265             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3266             *
3267             * <p>
3268             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3269             * </p>
3270             *
3271             * @param threadId the thread ID
3272             * @param start the lower bound of the range of message-boards messages
3273             * @param end the upper bound of the range of message-boards messages (not inclusive)
3274             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3275             * @return the ordered range of matching message-boards messages
3276             * @throws SystemException if a system exception occurred
3277             */
3278            public List<MBMessage> findByThreadReplies(long threadId, int start,
3279                    int end, OrderByComparator orderByComparator) throws SystemException {
3280                    boolean pagination = true;
3281                    FinderPath finderPath = null;
3282                    Object[] finderArgs = null;
3283    
3284                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3285                                    (orderByComparator == null)) {
3286                            pagination = false;
3287                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3288                            finderArgs = new Object[] { threadId };
3289                    }
3290                    else {
3291                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3292                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3293                    }
3294    
3295                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3296                                    finderArgs, this);
3297    
3298                    if ((list != null) && !list.isEmpty()) {
3299                            for (MBMessage mbMessage : list) {
3300                                    if ((threadId != mbMessage.getThreadId())) {
3301                                            list = null;
3302    
3303                                            break;
3304                                    }
3305                            }
3306                    }
3307    
3308                    if (list == null) {
3309                            StringBundler query = null;
3310    
3311                            if (orderByComparator != null) {
3312                                    query = new StringBundler(3 +
3313                                                    (orderByComparator.getOrderByFields().length * 3));
3314                            }
3315                            else {
3316                                    query = new StringBundler(3);
3317                            }
3318    
3319                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3320    
3321                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3322    
3323                            if (orderByComparator != null) {
3324                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3325                                            orderByComparator);
3326                            }
3327                            else
3328                             if (pagination) {
3329                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3330                            }
3331    
3332                            String sql = query.toString();
3333    
3334                            Session session = null;
3335    
3336                            try {
3337                                    session = openSession();
3338    
3339                                    Query q = session.createQuery(sql);
3340    
3341                                    QueryPos qPos = QueryPos.getInstance(q);
3342    
3343                                    qPos.add(threadId);
3344    
3345                                    if (!pagination) {
3346                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3347                                                            start, end, false);
3348    
3349                                            Collections.sort(list);
3350    
3351                                            list = new UnmodifiableList<MBMessage>(list);
3352                                    }
3353                                    else {
3354                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3355                                                            start, end);
3356                                    }
3357    
3358                                    cacheResult(list);
3359    
3360                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3361                            }
3362                            catch (Exception e) {
3363                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3364    
3365                                    throw processException(e);
3366                            }
3367                            finally {
3368                                    closeSession(session);
3369                            }
3370                    }
3371    
3372                    return list;
3373            }
3374    
3375            /**
3376             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3377             *
3378             * @param threadId the thread ID
3379             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3380             * @return the first matching message-boards message
3381             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3382             * @throws SystemException if a system exception occurred
3383             */
3384            public MBMessage findByThreadReplies_First(long threadId,
3385                    OrderByComparator orderByComparator)
3386                    throws NoSuchMessageException, SystemException {
3387                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
3388                                    orderByComparator);
3389    
3390                    if (mbMessage != null) {
3391                            return mbMessage;
3392                    }
3393    
3394                    StringBundler msg = new StringBundler(4);
3395    
3396                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3397    
3398                    msg.append("threadId=");
3399                    msg.append(threadId);
3400    
3401                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3402    
3403                    throw new NoSuchMessageException(msg.toString());
3404            }
3405    
3406            /**
3407             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3408             *
3409             * @param threadId the thread ID
3410             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3411             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3412             * @throws SystemException if a system exception occurred
3413             */
3414            public MBMessage fetchByThreadReplies_First(long threadId,
3415                    OrderByComparator orderByComparator) throws SystemException {
3416                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3417                                    orderByComparator);
3418    
3419                    if (!list.isEmpty()) {
3420                            return list.get(0);
3421                    }
3422    
3423                    return null;
3424            }
3425    
3426            /**
3427             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3428             *
3429             * @param threadId the thread ID
3430             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3431             * @return the last matching message-boards message
3432             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3433             * @throws SystemException if a system exception occurred
3434             */
3435            public MBMessage findByThreadReplies_Last(long threadId,
3436                    OrderByComparator orderByComparator)
3437                    throws NoSuchMessageException, SystemException {
3438                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
3439                                    orderByComparator);
3440    
3441                    if (mbMessage != null) {
3442                            return mbMessage;
3443                    }
3444    
3445                    StringBundler msg = new StringBundler(4);
3446    
3447                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3448    
3449                    msg.append("threadId=");
3450                    msg.append(threadId);
3451    
3452                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3453    
3454                    throw new NoSuchMessageException(msg.toString());
3455            }
3456    
3457            /**
3458             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3459             *
3460             * @param threadId the thread ID
3461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3462             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3463             * @throws SystemException if a system exception occurred
3464             */
3465            public MBMessage fetchByThreadReplies_Last(long threadId,
3466                    OrderByComparator orderByComparator) throws SystemException {
3467                    int count = countByThreadReplies(threadId);
3468    
3469                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3470                                    orderByComparator);
3471    
3472                    if (!list.isEmpty()) {
3473                            return list.get(0);
3474                    }
3475    
3476                    return null;
3477            }
3478    
3479            /**
3480             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3481             *
3482             * @param messageId the primary key of the current message-boards message
3483             * @param threadId the thread ID
3484             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3485             * @return the previous, current, and next message-boards message
3486             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3487             * @throws SystemException if a system exception occurred
3488             */
3489            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3490                    long threadId, OrderByComparator orderByComparator)
3491                    throws NoSuchMessageException, SystemException {
3492                    MBMessage mbMessage = findByPrimaryKey(messageId);
3493    
3494                    Session session = null;
3495    
3496                    try {
3497                            session = openSession();
3498    
3499                            MBMessage[] array = new MBMessageImpl[3];
3500    
3501                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3502                                            threadId, orderByComparator, true);
3503    
3504                            array[1] = mbMessage;
3505    
3506                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3507                                            threadId, orderByComparator, false);
3508    
3509                            return array;
3510                    }
3511                    catch (Exception e) {
3512                            throw processException(e);
3513                    }
3514                    finally {
3515                            closeSession(session);
3516                    }
3517            }
3518    
3519            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
3520                    MBMessage mbMessage, long threadId,
3521                    OrderByComparator orderByComparator, boolean previous) {
3522                    StringBundler query = null;
3523    
3524                    if (orderByComparator != null) {
3525                            query = new StringBundler(6 +
3526                                            (orderByComparator.getOrderByFields().length * 6));
3527                    }
3528                    else {
3529                            query = new StringBundler(3);
3530                    }
3531    
3532                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3533    
3534                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3535    
3536                    if (orderByComparator != null) {
3537                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3538    
3539                            if (orderByConditionFields.length > 0) {
3540                                    query.append(WHERE_AND);
3541                            }
3542    
3543                            for (int i = 0; i < orderByConditionFields.length; i++) {
3544                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3545                                    query.append(orderByConditionFields[i]);
3546    
3547                                    if ((i + 1) < orderByConditionFields.length) {
3548                                            if (orderByComparator.isAscending() ^ previous) {
3549                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3550                                            }
3551                                            else {
3552                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3553                                            }
3554                                    }
3555                                    else {
3556                                            if (orderByComparator.isAscending() ^ previous) {
3557                                                    query.append(WHERE_GREATER_THAN);
3558                                            }
3559                                            else {
3560                                                    query.append(WHERE_LESSER_THAN);
3561                                            }
3562                                    }
3563                            }
3564    
3565                            query.append(ORDER_BY_CLAUSE);
3566    
3567                            String[] orderByFields = orderByComparator.getOrderByFields();
3568    
3569                            for (int i = 0; i < orderByFields.length; i++) {
3570                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3571                                    query.append(orderByFields[i]);
3572    
3573                                    if ((i + 1) < orderByFields.length) {
3574                                            if (orderByComparator.isAscending() ^ previous) {
3575                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3576                                            }
3577                                            else {
3578                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3579                                            }
3580                                    }
3581                                    else {
3582                                            if (orderByComparator.isAscending() ^ previous) {
3583                                                    query.append(ORDER_BY_ASC);
3584                                            }
3585                                            else {
3586                                                    query.append(ORDER_BY_DESC);
3587                                            }
3588                                    }
3589                            }
3590                    }
3591                    else {
3592                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3593                    }
3594    
3595                    String sql = query.toString();
3596    
3597                    Query q = session.createQuery(sql);
3598    
3599                    q.setFirstResult(0);
3600                    q.setMaxResults(2);
3601    
3602                    QueryPos qPos = QueryPos.getInstance(q);
3603    
3604                    qPos.add(threadId);
3605    
3606                    if (orderByComparator != null) {
3607                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3608    
3609                            for (Object value : values) {
3610                                    qPos.add(value);
3611                            }
3612                    }
3613    
3614                    List<MBMessage> list = q.list();
3615    
3616                    if (list.size() == 2) {
3617                            return list.get(1);
3618                    }
3619                    else {
3620                            return null;
3621                    }
3622            }
3623    
3624            /**
3625             * Removes all the message-boards messages where threadId = &#63; from the database.
3626             *
3627             * @param threadId the thread ID
3628             * @throws SystemException if a system exception occurred
3629             */
3630            public void removeByThreadReplies(long threadId) throws SystemException {
3631                    for (MBMessage mbMessage : findByThreadReplies(threadId,
3632                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3633                            remove(mbMessage);
3634                    }
3635            }
3636    
3637            /**
3638             * Returns the number of message-boards messages where threadId = &#63;.
3639             *
3640             * @param threadId the thread ID
3641             * @return the number of matching message-boards messages
3642             * @throws SystemException if a system exception occurred
3643             */
3644            public int countByThreadReplies(long threadId) throws SystemException {
3645                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
3646    
3647                    Object[] finderArgs = new Object[] { threadId };
3648    
3649                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3650                                    this);
3651    
3652                    if (count == null) {
3653                            StringBundler query = new StringBundler(2);
3654    
3655                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3656    
3657                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3658    
3659                            String sql = query.toString();
3660    
3661                            Session session = null;
3662    
3663                            try {
3664                                    session = openSession();
3665    
3666                                    Query q = session.createQuery(sql);
3667    
3668                                    QueryPos qPos = QueryPos.getInstance(q);
3669    
3670                                    qPos.add(threadId);
3671    
3672                                    count = (Long)q.uniqueResult();
3673    
3674                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3675                            }
3676                            catch (Exception e) {
3677                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3678    
3679                                    throw processException(e);
3680                            }
3681                            finally {
3682                                    closeSession(session);
3683                            }
3684                    }
3685    
3686                    return count.intValue();
3687            }
3688    
3689            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
3690            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3691                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3692                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
3693                            new String[] {
3694                                    Long.class.getName(),
3695                                    
3696                            Integer.class.getName(), Integer.class.getName(),
3697                                    OrderByComparator.class.getName()
3698                            });
3699            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
3700                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3701                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3702                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
3703                            new String[] { Long.class.getName() },
3704                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
3705                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3706            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3707                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3708                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
3709                            new String[] { Long.class.getName() });
3710    
3711            /**
3712             * Returns all the message-boards messages where userId = &#63;.
3713             *
3714             * @param userId the user ID
3715             * @return the matching message-boards messages
3716             * @throws SystemException if a system exception occurred
3717             */
3718            public List<MBMessage> findByUserId(long userId) throws SystemException {
3719                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3720            }
3721    
3722            /**
3723             * Returns a range of all the message-boards messages where userId = &#63;.
3724             *
3725             * <p>
3726             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3727             * </p>
3728             *
3729             * @param userId the user ID
3730             * @param start the lower bound of the range of message-boards messages
3731             * @param end the upper bound of the range of message-boards messages (not inclusive)
3732             * @return the range of matching message-boards messages
3733             * @throws SystemException if a system exception occurred
3734             */
3735            public List<MBMessage> findByUserId(long userId, int start, int end)
3736                    throws SystemException {
3737                    return findByUserId(userId, start, end, null);
3738            }
3739    
3740            /**
3741             * Returns an ordered range of all the message-boards messages where userId = &#63;.
3742             *
3743             * <p>
3744             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
3745             * </p>
3746             *
3747             * @param userId the user ID
3748             * @param start the lower bound of the range of message-boards messages
3749             * @param end the upper bound of the range of message-boards messages (not inclusive)
3750             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3751             * @return the ordered range of matching message-boards messages
3752             * @throws SystemException if a system exception occurred
3753             */
3754            public List<MBMessage> findByUserId(long userId, int start, int end,
3755                    OrderByComparator orderByComparator) throws SystemException {
3756                    boolean pagination = true;
3757                    FinderPath finderPath = null;
3758                    Object[] finderArgs = null;
3759    
3760                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3761                                    (orderByComparator == null)) {
3762                            pagination = false;
3763                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
3764                            finderArgs = new Object[] { userId };
3765                    }
3766                    else {
3767                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
3768                            finderArgs = new Object[] { userId, start, end, orderByComparator };
3769                    }
3770    
3771                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3772                                    finderArgs, this);
3773    
3774                    if ((list != null) && !list.isEmpty()) {
3775                            for (MBMessage mbMessage : list) {
3776                                    if ((userId != mbMessage.getUserId())) {
3777                                            list = null;
3778    
3779                                            break;
3780                                    }
3781                            }
3782                    }
3783    
3784                    if (list == null) {
3785                            StringBundler query = null;
3786    
3787                            if (orderByComparator != null) {
3788                                    query = new StringBundler(3 +
3789                                                    (orderByComparator.getOrderByFields().length * 3));
3790                            }
3791                            else {
3792                                    query = new StringBundler(3);
3793                            }
3794    
3795                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3796    
3797                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3798    
3799                            if (orderByComparator != null) {
3800                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3801                                            orderByComparator);
3802                            }
3803                            else
3804                             if (pagination) {
3805                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3806                            }
3807    
3808                            String sql = query.toString();
3809    
3810                            Session session = null;
3811    
3812                            try {
3813                                    session = openSession();
3814    
3815                                    Query q = session.createQuery(sql);
3816    
3817                                    QueryPos qPos = QueryPos.getInstance(q);
3818    
3819                                    qPos.add(userId);
3820    
3821                                    if (!pagination) {
3822                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3823                                                            start, end, false);
3824    
3825                                            Collections.sort(list);
3826    
3827                                            list = new UnmodifiableList<MBMessage>(list);
3828                                    }
3829                                    else {
3830                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3831                                                            start, end);
3832                                    }
3833    
3834                                    cacheResult(list);
3835    
3836                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3837                            }
3838                            catch (Exception e) {
3839                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3840    
3841                                    throw processException(e);
3842                            }
3843                            finally {
3844                                    closeSession(session);
3845                            }
3846                    }
3847    
3848                    return list;
3849            }
3850    
3851            /**
3852             * Returns the first message-boards message in the ordered set where userId = &#63;.
3853             *
3854             * @param userId the user ID
3855             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3856             * @return the first matching message-boards message
3857             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3858             * @throws SystemException if a system exception occurred
3859             */
3860            public MBMessage findByUserId_First(long userId,
3861                    OrderByComparator orderByComparator)
3862                    throws NoSuchMessageException, SystemException {
3863                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3864    
3865                    if (mbMessage != null) {
3866                            return mbMessage;
3867                    }
3868    
3869                    StringBundler msg = new StringBundler(4);
3870    
3871                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3872    
3873                    msg.append("userId=");
3874                    msg.append(userId);
3875    
3876                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3877    
3878                    throw new NoSuchMessageException(msg.toString());
3879            }
3880    
3881            /**
3882             * Returns the first message-boards message in the ordered set where userId = &#63;.
3883             *
3884             * @param userId the user ID
3885             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3886             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3887             * @throws SystemException if a system exception occurred
3888             */
3889            public MBMessage fetchByUserId_First(long userId,
3890                    OrderByComparator orderByComparator) throws SystemException {
3891                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3892    
3893                    if (!list.isEmpty()) {
3894                            return list.get(0);
3895                    }
3896    
3897                    return null;
3898            }
3899    
3900            /**
3901             * Returns the last message-boards message in the ordered set where userId = &#63;.
3902             *
3903             * @param userId the user ID
3904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3905             * @return the last matching message-boards message
3906             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3907             * @throws SystemException if a system exception occurred
3908             */
3909            public MBMessage findByUserId_Last(long userId,
3910                    OrderByComparator orderByComparator)
3911                    throws NoSuchMessageException, SystemException {
3912                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3913    
3914                    if (mbMessage != null) {
3915                            return mbMessage;
3916                    }
3917    
3918                    StringBundler msg = new StringBundler(4);
3919    
3920                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3921    
3922                    msg.append("userId=");
3923                    msg.append(userId);
3924    
3925                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3926    
3927                    throw new NoSuchMessageException(msg.toString());
3928            }
3929    
3930            /**
3931             * Returns the last message-boards message in the ordered set where userId = &#63;.
3932             *
3933             * @param userId the user ID
3934             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3935             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3936             * @throws SystemException if a system exception occurred
3937             */
3938            public MBMessage fetchByUserId_Last(long userId,
3939                    OrderByComparator orderByComparator) throws SystemException {
3940                    int count = countByUserId(userId);
3941    
3942                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3943                                    orderByComparator);
3944    
3945                    if (!list.isEmpty()) {
3946                            return list.get(0);
3947                    }
3948    
3949                    return null;
3950            }
3951    
3952            /**
3953             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3954             *
3955             * @param messageId the primary key of the current message-boards message
3956             * @param userId the user ID
3957             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3958             * @return the previous, current, and next message-boards message
3959             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3960             * @throws SystemException if a system exception occurred
3961             */
3962            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3963                    OrderByComparator orderByComparator)
3964                    throws NoSuchMessageException, SystemException {
3965                    MBMessage mbMessage = findByPrimaryKey(messageId);
3966    
3967                    Session session = null;
3968    
3969                    try {
3970                            session = openSession();
3971    
3972                            MBMessage[] array = new MBMessageImpl[3];
3973    
3974                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3975                                            orderByComparator, true);
3976    
3977                            array[1] = mbMessage;
3978    
3979                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3980                                            orderByComparator, false);
3981    
3982                            return array;
3983                    }
3984                    catch (Exception e) {
3985                            throw processException(e);
3986                    }
3987                    finally {
3988                            closeSession(session);
3989                    }
3990            }
3991    
3992            protected MBMessage getByUserId_PrevAndNext(Session session,
3993                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
3994                    boolean previous) {
3995                    StringBundler query = null;
3996    
3997                    if (orderByComparator != null) {
3998                            query = new StringBundler(6 +
3999                                            (orderByComparator.getOrderByFields().length * 6));
4000                    }
4001                    else {
4002                            query = new StringBundler(3);
4003                    }
4004    
4005                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4006    
4007                    query.append(_FINDER_COLUMN_USERID_USERID_2);
4008    
4009                    if (orderByComparator != null) {
4010                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4011    
4012                            if (orderByConditionFields.length > 0) {
4013                                    query.append(WHERE_AND);
4014                            }
4015    
4016                            for (int i = 0; i < orderByConditionFields.length; i++) {
4017                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4018                                    query.append(orderByConditionFields[i]);
4019    
4020                                    if ((i + 1) < orderByConditionFields.length) {
4021                                            if (orderByComparator.isAscending() ^ previous) {
4022                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4023                                            }
4024                                            else {
4025                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4026                                            }
4027                                    }
4028                                    else {
4029                                            if (orderByComparator.isAscending() ^ previous) {
4030                                                    query.append(WHERE_GREATER_THAN);
4031                                            }
4032                                            else {
4033                                                    query.append(WHERE_LESSER_THAN);
4034                                            }
4035                                    }
4036                            }
4037    
4038                            query.append(ORDER_BY_CLAUSE);
4039    
4040                            String[] orderByFields = orderByComparator.getOrderByFields();
4041    
4042                            for (int i = 0; i < orderByFields.length; i++) {
4043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4044                                    query.append(orderByFields[i]);
4045    
4046                                    if ((i + 1) < orderByFields.length) {
4047                                            if (orderByComparator.isAscending() ^ previous) {
4048                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4049                                            }
4050                                            else {
4051                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4052                                            }
4053                                    }
4054                                    else {
4055                                            if (orderByComparator.isAscending() ^ previous) {
4056                                                    query.append(ORDER_BY_ASC);
4057                                            }
4058                                            else {
4059                                                    query.append(ORDER_BY_DESC);
4060                                            }
4061                                    }
4062                            }
4063                    }
4064                    else {
4065                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4066                    }
4067    
4068                    String sql = query.toString();
4069    
4070                    Query q = session.createQuery(sql);
4071    
4072                    q.setFirstResult(0);
4073                    q.setMaxResults(2);
4074    
4075                    QueryPos qPos = QueryPos.getInstance(q);
4076    
4077                    qPos.add(userId);
4078    
4079                    if (orderByComparator != null) {
4080                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4081    
4082                            for (Object value : values) {
4083                                    qPos.add(value);
4084                            }
4085                    }
4086    
4087                    List<MBMessage> list = q.list();
4088    
4089                    if (list.size() == 2) {
4090                            return list.get(1);
4091                    }
4092                    else {
4093                            return null;
4094                    }
4095            }
4096    
4097            /**
4098             * Removes all the message-boards messages where userId = &#63; from the database.
4099             *
4100             * @param userId the user ID
4101             * @throws SystemException if a system exception occurred
4102             */
4103            public void removeByUserId(long userId) throws SystemException {
4104                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
4105                                    QueryUtil.ALL_POS, null)) {
4106                            remove(mbMessage);
4107                    }
4108            }
4109    
4110            /**
4111             * Returns the number of message-boards messages where userId = &#63;.
4112             *
4113             * @param userId the user ID
4114             * @return the number of matching message-boards messages
4115             * @throws SystemException if a system exception occurred
4116             */
4117            public int countByUserId(long userId) throws SystemException {
4118                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
4119    
4120                    Object[] finderArgs = new Object[] { userId };
4121    
4122                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4123                                    this);
4124    
4125                    if (count == null) {
4126                            StringBundler query = new StringBundler(2);
4127    
4128                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4129    
4130                            query.append(_FINDER_COLUMN_USERID_USERID_2);
4131    
4132                            String sql = query.toString();
4133    
4134                            Session session = null;
4135    
4136                            try {
4137                                    session = openSession();
4138    
4139                                    Query q = session.createQuery(sql);
4140    
4141                                    QueryPos qPos = QueryPos.getInstance(q);
4142    
4143                                    qPos.add(userId);
4144    
4145                                    count = (Long)q.uniqueResult();
4146    
4147                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4148                            }
4149                            catch (Exception e) {
4150                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4151    
4152                                    throw processException(e);
4153                            }
4154                            finally {
4155                                    closeSession(session);
4156                            }
4157                    }
4158    
4159                    return count.intValue();
4160            }
4161    
4162            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
4163            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4164                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4165                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4166                            new String[] {
4167                                    Long.class.getName(), Long.class.getName(),
4168                                    
4169                            Integer.class.getName(), Integer.class.getName(),
4170                                    OrderByComparator.class.getName()
4171                            });
4172            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4173                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4174                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4175                            new String[] { Long.class.getName(), Long.class.getName() },
4176                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4177                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4178                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4179            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4180                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4181                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4182                            new String[] { Long.class.getName(), Long.class.getName() });
4183    
4184            /**
4185             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4186             *
4187             * @param groupId the group ID
4188             * @param userId the user ID
4189             * @return the matching message-boards messages
4190             * @throws SystemException if a system exception occurred
4191             */
4192            public List<MBMessage> findByG_U(long groupId, long userId)
4193                    throws SystemException {
4194                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4195                            null);
4196            }
4197    
4198            /**
4199             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4200             *
4201             * <p>
4202             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4203             * </p>
4204             *
4205             * @param groupId the group ID
4206             * @param userId the user ID
4207             * @param start the lower bound of the range of message-boards messages
4208             * @param end the upper bound of the range of message-boards messages (not inclusive)
4209             * @return the range of matching message-boards messages
4210             * @throws SystemException if a system exception occurred
4211             */
4212            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4213                    int end) throws SystemException {
4214                    return findByG_U(groupId, userId, start, end, null);
4215            }
4216    
4217            /**
4218             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4219             *
4220             * <p>
4221             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4222             * </p>
4223             *
4224             * @param groupId the group ID
4225             * @param userId the user ID
4226             * @param start the lower bound of the range of message-boards messages
4227             * @param end the upper bound of the range of message-boards messages (not inclusive)
4228             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4229             * @return the ordered range of matching message-boards messages
4230             * @throws SystemException if a system exception occurred
4231             */
4232            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4233                    int end, OrderByComparator orderByComparator) throws SystemException {
4234                    boolean pagination = true;
4235                    FinderPath finderPath = null;
4236                    Object[] finderArgs = null;
4237    
4238                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4239                                    (orderByComparator == null)) {
4240                            pagination = false;
4241                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4242                            finderArgs = new Object[] { groupId, userId };
4243                    }
4244                    else {
4245                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4246                            finderArgs = new Object[] {
4247                                            groupId, userId,
4248                                            
4249                                            start, end, orderByComparator
4250                                    };
4251                    }
4252    
4253                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4254                                    finderArgs, this);
4255    
4256                    if ((list != null) && !list.isEmpty()) {
4257                            for (MBMessage mbMessage : list) {
4258                                    if ((groupId != mbMessage.getGroupId()) ||
4259                                                    (userId != mbMessage.getUserId())) {
4260                                            list = null;
4261    
4262                                            break;
4263                                    }
4264                            }
4265                    }
4266    
4267                    if (list == null) {
4268                            StringBundler query = null;
4269    
4270                            if (orderByComparator != null) {
4271                                    query = new StringBundler(4 +
4272                                                    (orderByComparator.getOrderByFields().length * 3));
4273                            }
4274                            else {
4275                                    query = new StringBundler(4);
4276                            }
4277    
4278                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4279    
4280                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4281    
4282                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4283    
4284                            if (orderByComparator != null) {
4285                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4286                                            orderByComparator);
4287                            }
4288                            else
4289                             if (pagination) {
4290                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4291                            }
4292    
4293                            String sql = query.toString();
4294    
4295                            Session session = null;
4296    
4297                            try {
4298                                    session = openSession();
4299    
4300                                    Query q = session.createQuery(sql);
4301    
4302                                    QueryPos qPos = QueryPos.getInstance(q);
4303    
4304                                    qPos.add(groupId);
4305    
4306                                    qPos.add(userId);
4307    
4308                                    if (!pagination) {
4309                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4310                                                            start, end, false);
4311    
4312                                            Collections.sort(list);
4313    
4314                                            list = new UnmodifiableList<MBMessage>(list);
4315                                    }
4316                                    else {
4317                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4318                                                            start, end);
4319                                    }
4320    
4321                                    cacheResult(list);
4322    
4323                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4324                            }
4325                            catch (Exception e) {
4326                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4327    
4328                                    throw processException(e);
4329                            }
4330                            finally {
4331                                    closeSession(session);
4332                            }
4333                    }
4334    
4335                    return list;
4336            }
4337    
4338            /**
4339             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4340             *
4341             * @param groupId the group ID
4342             * @param userId the user ID
4343             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4344             * @return the first matching message-boards message
4345             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4346             * @throws SystemException if a system exception occurred
4347             */
4348            public MBMessage findByG_U_First(long groupId, long userId,
4349                    OrderByComparator orderByComparator)
4350                    throws NoSuchMessageException, SystemException {
4351                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4352                                    orderByComparator);
4353    
4354                    if (mbMessage != null) {
4355                            return mbMessage;
4356                    }
4357    
4358                    StringBundler msg = new StringBundler(6);
4359    
4360                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4361    
4362                    msg.append("groupId=");
4363                    msg.append(groupId);
4364    
4365                    msg.append(", userId=");
4366                    msg.append(userId);
4367    
4368                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4369    
4370                    throw new NoSuchMessageException(msg.toString());
4371            }
4372    
4373            /**
4374             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4375             *
4376             * @param groupId the group ID
4377             * @param userId the user ID
4378             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4379             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4380             * @throws SystemException if a system exception occurred
4381             */
4382            public MBMessage fetchByG_U_First(long groupId, long userId,
4383                    OrderByComparator orderByComparator) throws SystemException {
4384                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4385                                    orderByComparator);
4386    
4387                    if (!list.isEmpty()) {
4388                            return list.get(0);
4389                    }
4390    
4391                    return null;
4392            }
4393    
4394            /**
4395             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4396             *
4397             * @param groupId the group ID
4398             * @param userId the user ID
4399             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4400             * @return the last matching message-boards message
4401             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4402             * @throws SystemException if a system exception occurred
4403             */
4404            public MBMessage findByG_U_Last(long groupId, long userId,
4405                    OrderByComparator orderByComparator)
4406                    throws NoSuchMessageException, SystemException {
4407                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4408    
4409                    if (mbMessage != null) {
4410                            return mbMessage;
4411                    }
4412    
4413                    StringBundler msg = new StringBundler(6);
4414    
4415                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4416    
4417                    msg.append("groupId=");
4418                    msg.append(groupId);
4419    
4420                    msg.append(", userId=");
4421                    msg.append(userId);
4422    
4423                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4424    
4425                    throw new NoSuchMessageException(msg.toString());
4426            }
4427    
4428            /**
4429             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4430             *
4431             * @param groupId the group ID
4432             * @param userId the user ID
4433             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4434             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4435             * @throws SystemException if a system exception occurred
4436             */
4437            public MBMessage fetchByG_U_Last(long groupId, long userId,
4438                    OrderByComparator orderByComparator) throws SystemException {
4439                    int count = countByG_U(groupId, userId);
4440    
4441                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4442                                    orderByComparator);
4443    
4444                    if (!list.isEmpty()) {
4445                            return list.get(0);
4446                    }
4447    
4448                    return null;
4449            }
4450    
4451            /**
4452             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4453             *
4454             * @param messageId the primary key of the current message-boards message
4455             * @param groupId the group ID
4456             * @param userId the user ID
4457             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4458             * @return the previous, current, and next message-boards message
4459             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4460             * @throws SystemException if a system exception occurred
4461             */
4462            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4463                    long userId, OrderByComparator orderByComparator)
4464                    throws NoSuchMessageException, SystemException {
4465                    MBMessage mbMessage = findByPrimaryKey(messageId);
4466    
4467                    Session session = null;
4468    
4469                    try {
4470                            session = openSession();
4471    
4472                            MBMessage[] array = new MBMessageImpl[3];
4473    
4474                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4475                                            userId, orderByComparator, true);
4476    
4477                            array[1] = mbMessage;
4478    
4479                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4480                                            userId, orderByComparator, false);
4481    
4482                            return array;
4483                    }
4484                    catch (Exception e) {
4485                            throw processException(e);
4486                    }
4487                    finally {
4488                            closeSession(session);
4489                    }
4490            }
4491    
4492            protected MBMessage getByG_U_PrevAndNext(Session session,
4493                    MBMessage mbMessage, long groupId, long userId,
4494                    OrderByComparator orderByComparator, boolean previous) {
4495                    StringBundler query = null;
4496    
4497                    if (orderByComparator != null) {
4498                            query = new StringBundler(6 +
4499                                            (orderByComparator.getOrderByFields().length * 6));
4500                    }
4501                    else {
4502                            query = new StringBundler(3);
4503                    }
4504    
4505                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4506    
4507                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4508    
4509                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4510    
4511                    if (orderByComparator != null) {
4512                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4513    
4514                            if (orderByConditionFields.length > 0) {
4515                                    query.append(WHERE_AND);
4516                            }
4517    
4518                            for (int i = 0; i < orderByConditionFields.length; i++) {
4519                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4520                                    query.append(orderByConditionFields[i]);
4521    
4522                                    if ((i + 1) < orderByConditionFields.length) {
4523                                            if (orderByComparator.isAscending() ^ previous) {
4524                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4525                                            }
4526                                            else {
4527                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4528                                            }
4529                                    }
4530                                    else {
4531                                            if (orderByComparator.isAscending() ^ previous) {
4532                                                    query.append(WHERE_GREATER_THAN);
4533                                            }
4534                                            else {
4535                                                    query.append(WHERE_LESSER_THAN);
4536                                            }
4537                                    }
4538                            }
4539    
4540                            query.append(ORDER_BY_CLAUSE);
4541    
4542                            String[] orderByFields = orderByComparator.getOrderByFields();
4543    
4544                            for (int i = 0; i < orderByFields.length; i++) {
4545                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4546                                    query.append(orderByFields[i]);
4547    
4548                                    if ((i + 1) < orderByFields.length) {
4549                                            if (orderByComparator.isAscending() ^ previous) {
4550                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4551                                            }
4552                                            else {
4553                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4554                                            }
4555                                    }
4556                                    else {
4557                                            if (orderByComparator.isAscending() ^ previous) {
4558                                                    query.append(ORDER_BY_ASC);
4559                                            }
4560                                            else {
4561                                                    query.append(ORDER_BY_DESC);
4562                                            }
4563                                    }
4564                            }
4565                    }
4566                    else {
4567                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4568                    }
4569    
4570                    String sql = query.toString();
4571    
4572                    Query q = session.createQuery(sql);
4573    
4574                    q.setFirstResult(0);
4575                    q.setMaxResults(2);
4576    
4577                    QueryPos qPos = QueryPos.getInstance(q);
4578    
4579                    qPos.add(groupId);
4580    
4581                    qPos.add(userId);
4582    
4583                    if (orderByComparator != null) {
4584                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4585    
4586                            for (Object value : values) {
4587                                    qPos.add(value);
4588                            }
4589                    }
4590    
4591                    List<MBMessage> list = q.list();
4592    
4593                    if (list.size() == 2) {
4594                            return list.get(1);
4595                    }
4596                    else {
4597                            return null;
4598                    }
4599            }
4600    
4601            /**
4602             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4603             *
4604             * @param groupId the group ID
4605             * @param userId the user ID
4606             * @return the matching message-boards messages that the user has permission to view
4607             * @throws SystemException if a system exception occurred
4608             */
4609            public List<MBMessage> filterFindByG_U(long groupId, long userId)
4610                    throws SystemException {
4611                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4612                            QueryUtil.ALL_POS, null);
4613            }
4614    
4615            /**
4616             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4617             *
4618             * <p>
4619             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4620             * </p>
4621             *
4622             * @param groupId the group ID
4623             * @param userId the user ID
4624             * @param start the lower bound of the range of message-boards messages
4625             * @param end the upper bound of the range of message-boards messages (not inclusive)
4626             * @return the range of matching message-boards messages that the user has permission to view
4627             * @throws SystemException if a system exception occurred
4628             */
4629            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4630                    int start, int end) throws SystemException {
4631                    return filterFindByG_U(groupId, userId, start, end, null);
4632            }
4633    
4634            /**
4635             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4636             *
4637             * <p>
4638             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
4639             * </p>
4640             *
4641             * @param groupId the group ID
4642             * @param userId the user ID
4643             * @param start the lower bound of the range of message-boards messages
4644             * @param end the upper bound of the range of message-boards messages (not inclusive)
4645             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4646             * @return the ordered range of matching message-boards messages that the user has permission to view
4647             * @throws SystemException if a system exception occurred
4648             */
4649            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4650                    int start, int end, OrderByComparator orderByComparator)
4651                    throws SystemException {
4652                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4653                            return findByG_U(groupId, userId, start, end, orderByComparator);
4654                    }
4655    
4656                    StringBundler query = null;
4657    
4658                    if (orderByComparator != null) {
4659                            query = new StringBundler(4 +
4660                                            (orderByComparator.getOrderByFields().length * 3));
4661                    }
4662                    else {
4663                            query = new StringBundler(4);
4664                    }
4665    
4666                    if (getDB().isSupportsInlineDistinct()) {
4667                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4668                    }
4669                    else {
4670                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4671                    }
4672    
4673                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4674    
4675                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4676    
4677                    if (!getDB().isSupportsInlineDistinct()) {
4678                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4679                    }
4680    
4681                    if (orderByComparator != null) {
4682                            if (getDB().isSupportsInlineDistinct()) {
4683                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4684                                            orderByComparator);
4685                            }
4686                            else {
4687                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4688                                            orderByComparator);
4689                            }
4690                    }
4691                    else {
4692                            if (getDB().isSupportsInlineDistinct()) {
4693                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4694                            }
4695                            else {
4696                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4697                            }
4698                    }
4699    
4700                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4701                                    MBMessage.class.getName(),
4702                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4703    
4704                    Session session = null;
4705    
4706                    try {
4707                            session = openSession();
4708    
4709                            SQLQuery q = session.createSQLQuery(sql);
4710    
4711                            if (getDB().isSupportsInlineDistinct()) {
4712                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4713                            }
4714                            else {
4715                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4716                            }
4717    
4718                            QueryPos qPos = QueryPos.getInstance(q);
4719    
4720                            qPos.add(groupId);
4721    
4722                            qPos.add(userId);
4723    
4724                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4725                    }
4726                    catch (Exception e) {
4727                            throw processException(e);
4728                    }
4729                    finally {
4730                            closeSession(session);
4731                    }
4732            }
4733    
4734            /**
4735             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4736             *
4737             * @param messageId the primary key of the current message-boards message
4738             * @param groupId the group ID
4739             * @param userId the user ID
4740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4741             * @return the previous, current, and next message-boards message
4742             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4743             * @throws SystemException if a system exception occurred
4744             */
4745            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4746                    long groupId, long userId, OrderByComparator orderByComparator)
4747                    throws NoSuchMessageException, SystemException {
4748                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4749                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4750                                    orderByComparator);
4751                    }
4752    
4753                    MBMessage mbMessage = findByPrimaryKey(messageId);
4754    
4755                    Session session = null;
4756    
4757                    try {
4758                            session = openSession();
4759    
4760                            MBMessage[] array = new MBMessageImpl[3];
4761    
4762                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4763                                            userId, orderByComparator, true);
4764    
4765                            array[1] = mbMessage;
4766    
4767                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4768                                            userId, orderByComparator, false);
4769    
4770                            return array;
4771                    }
4772                    catch (Exception e) {
4773                            throw processException(e);
4774                    }
4775                    finally {
4776                            closeSession(session);
4777                    }
4778            }
4779    
4780            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4781                    MBMessage mbMessage, long groupId, long userId,
4782                    OrderByComparator orderByComparator, boolean previous) {
4783                    StringBundler query = null;
4784    
4785                    if (orderByComparator != null) {
4786                            query = new StringBundler(6 +
4787                                            (orderByComparator.getOrderByFields().length * 6));
4788                    }
4789                    else {
4790                            query = new StringBundler(3);
4791                    }
4792    
4793                    if (getDB().isSupportsInlineDistinct()) {
4794                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4795                    }
4796                    else {
4797                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4798                    }
4799    
4800                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4801    
4802                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4803    
4804                    if (!getDB().isSupportsInlineDistinct()) {
4805                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4806                    }
4807    
4808                    if (orderByComparator != null) {
4809                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4810    
4811                            if (orderByConditionFields.length > 0) {
4812                                    query.append(WHERE_AND);
4813                            }
4814    
4815                            for (int i = 0; i < orderByConditionFields.length; i++) {
4816                                    if (getDB().isSupportsInlineDistinct()) {
4817                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4818                                    }
4819                                    else {
4820                                            query.append(_ORDER_BY_ENTITY_TABLE);
4821                                    }
4822    
4823                                    query.append(orderByConditionFields[i]);
4824    
4825                                    if ((i + 1) < orderByConditionFields.length) {
4826                                            if (orderByComparator.isAscending() ^ previous) {
4827                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4828                                            }
4829                                            else {
4830                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4831                                            }
4832                                    }
4833                                    else {
4834                                            if (orderByComparator.isAscending() ^ previous) {
4835                                                    query.append(WHERE_GREATER_THAN);
4836                                            }
4837                                            else {
4838                                                    query.append(WHERE_LESSER_THAN);
4839                                            }
4840                                    }
4841                            }
4842    
4843                            query.append(ORDER_BY_CLAUSE);
4844    
4845                            String[] orderByFields = orderByComparator.getOrderByFields();
4846    
4847                            for (int i = 0; i < orderByFields.length; i++) {
4848                                    if (getDB().isSupportsInlineDistinct()) {
4849                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4850                                    }
4851                                    else {
4852                                            query.append(_ORDER_BY_ENTITY_TABLE);
4853                                    }
4854    
4855                                    query.append(orderByFields[i]);
4856    
4857                                    if ((i + 1) < orderByFields.length) {
4858                                            if (orderByComparator.isAscending() ^ previous) {
4859                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4860                                            }
4861                                            else {
4862                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4863                                            }
4864                                    }
4865                                    else {
4866                                            if (orderByComparator.isAscending() ^ previous) {
4867                                                    query.append(ORDER_BY_ASC);
4868                                            }
4869                                            else {
4870                                                    query.append(ORDER_BY_DESC);
4871                                            }
4872                                    }
4873                            }
4874                    }
4875                    else {
4876                            if (getDB().isSupportsInlineDistinct()) {
4877                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4878                            }
4879                            else {
4880                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4881                            }
4882                    }
4883    
4884                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4885                                    MBMessage.class.getName(),
4886                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4887    
4888                    SQLQuery q = session.createSQLQuery(sql);
4889    
4890                    q.setFirstResult(0);
4891                    q.setMaxResults(2);
4892    
4893                    if (getDB().isSupportsInlineDistinct()) {
4894                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4895                    }
4896                    else {
4897                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4898                    }
4899    
4900                    QueryPos qPos = QueryPos.getInstance(q);
4901    
4902                    qPos.add(groupId);
4903    
4904                    qPos.add(userId);
4905    
4906                    if (orderByComparator != null) {
4907                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4908    
4909                            for (Object value : values) {
4910                                    qPos.add(value);
4911                            }
4912                    }
4913    
4914                    List<MBMessage> list = q.list();
4915    
4916                    if (list.size() == 2) {
4917                            return list.get(1);
4918                    }
4919                    else {
4920                            return null;
4921                    }
4922            }
4923    
4924            /**
4925             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
4926             *
4927             * @param groupId the group ID
4928             * @param userId the user ID
4929             * @throws SystemException if a system exception occurred
4930             */
4931            public void removeByG_U(long groupId, long userId)
4932                    throws SystemException {
4933                    for (MBMessage mbMessage : findByG_U(groupId, userId,
4934                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4935                            remove(mbMessage);
4936                    }
4937            }
4938    
4939            /**
4940             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
4941             *
4942             * @param groupId the group ID
4943             * @param userId the user ID
4944             * @return the number of matching message-boards messages
4945             * @throws SystemException if a system exception occurred
4946             */
4947            public int countByG_U(long groupId, long userId) throws SystemException {
4948                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
4949    
4950                    Object[] finderArgs = new Object[] { groupId, userId };
4951    
4952                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4953                                    this);
4954    
4955                    if (count == null) {
4956                            StringBundler query = new StringBundler(3);
4957    
4958                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4959    
4960                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4961    
4962                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4963    
4964                            String sql = query.toString();
4965    
4966                            Session session = null;
4967    
4968                            try {
4969                                    session = openSession();
4970    
4971                                    Query q = session.createQuery(sql);
4972    
4973                                    QueryPos qPos = QueryPos.getInstance(q);
4974    
4975                                    qPos.add(groupId);
4976    
4977                                    qPos.add(userId);
4978    
4979                                    count = (Long)q.uniqueResult();
4980    
4981                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4982                            }
4983                            catch (Exception e) {
4984                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4985    
4986                                    throw processException(e);
4987                            }
4988                            finally {
4989                                    closeSession(session);
4990                            }
4991                    }
4992    
4993                    return count.intValue();
4994            }
4995    
4996            /**
4997             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4998             *
4999             * @param groupId the group ID
5000             * @param userId the user ID
5001             * @return the number of matching message-boards messages that the user has permission to view
5002             * @throws SystemException if a system exception occurred
5003             */
5004            public int filterCountByG_U(long groupId, long userId)
5005                    throws SystemException {
5006                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5007                            return countByG_U(groupId, userId);
5008                    }
5009    
5010                    StringBundler query = new StringBundler(3);
5011    
5012                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5013    
5014                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5015    
5016                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5017    
5018                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5019                                    MBMessage.class.getName(),
5020                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5021    
5022                    Session session = null;
5023    
5024                    try {
5025                            session = openSession();
5026    
5027                            SQLQuery q = session.createSQLQuery(sql);
5028    
5029                            q.addScalar(COUNT_COLUMN_NAME,
5030                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5031    
5032                            QueryPos qPos = QueryPos.getInstance(q);
5033    
5034                            qPos.add(groupId);
5035    
5036                            qPos.add(userId);
5037    
5038                            Long count = (Long)q.uniqueResult();
5039    
5040                            return count.intValue();
5041                    }
5042                    catch (Exception e) {
5043                            throw processException(e);
5044                    }
5045                    finally {
5046                            closeSession(session);
5047                    }
5048            }
5049    
5050            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5051            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5052            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5053                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5054                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5055                            new String[] {
5056                                    Long.class.getName(), Long.class.getName(),
5057                                    
5058                            Integer.class.getName(), Integer.class.getName(),
5059                                    OrderByComparator.class.getName()
5060                            });
5061            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5062                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5063                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5064                            new String[] { Long.class.getName(), Long.class.getName() },
5065                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5066                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5067                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5068            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5069                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5070                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5071                            new String[] { Long.class.getName(), Long.class.getName() });
5072    
5073            /**
5074             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5075             *
5076             * @param groupId the group ID
5077             * @param categoryId the category ID
5078             * @return the matching message-boards messages
5079             * @throws SystemException if a system exception occurred
5080             */
5081            public List<MBMessage> findByG_C(long groupId, long categoryId)
5082                    throws SystemException {
5083                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5084                            QueryUtil.ALL_POS, null);
5085            }
5086    
5087            /**
5088             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5089             *
5090             * <p>
5091             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5092             * </p>
5093             *
5094             * @param groupId the group ID
5095             * @param categoryId the category ID
5096             * @param start the lower bound of the range of message-boards messages
5097             * @param end the upper bound of the range of message-boards messages (not inclusive)
5098             * @return the range of matching message-boards messages
5099             * @throws SystemException if a system exception occurred
5100             */
5101            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5102                    int end) throws SystemException {
5103                    return findByG_C(groupId, categoryId, start, end, null);
5104            }
5105    
5106            /**
5107             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5108             *
5109             * <p>
5110             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5111             * </p>
5112             *
5113             * @param groupId the group ID
5114             * @param categoryId the category ID
5115             * @param start the lower bound of the range of message-boards messages
5116             * @param end the upper bound of the range of message-boards messages (not inclusive)
5117             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5118             * @return the ordered range of matching message-boards messages
5119             * @throws SystemException if a system exception occurred
5120             */
5121            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5122                    int end, OrderByComparator orderByComparator) throws SystemException {
5123                    boolean pagination = true;
5124                    FinderPath finderPath = null;
5125                    Object[] finderArgs = null;
5126    
5127                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5128                                    (orderByComparator == null)) {
5129                            pagination = false;
5130                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5131                            finderArgs = new Object[] { groupId, categoryId };
5132                    }
5133                    else {
5134                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5135                            finderArgs = new Object[] {
5136                                            groupId, categoryId,
5137                                            
5138                                            start, end, orderByComparator
5139                                    };
5140                    }
5141    
5142                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5143                                    finderArgs, this);
5144    
5145                    if ((list != null) && !list.isEmpty()) {
5146                            for (MBMessage mbMessage : list) {
5147                                    if ((groupId != mbMessage.getGroupId()) ||
5148                                                    (categoryId != mbMessage.getCategoryId())) {
5149                                            list = null;
5150    
5151                                            break;
5152                                    }
5153                            }
5154                    }
5155    
5156                    if (list == null) {
5157                            StringBundler query = null;
5158    
5159                            if (orderByComparator != null) {
5160                                    query = new StringBundler(4 +
5161                                                    (orderByComparator.getOrderByFields().length * 3));
5162                            }
5163                            else {
5164                                    query = new StringBundler(4);
5165                            }
5166    
5167                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5168    
5169                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5170    
5171                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5172    
5173                            if (orderByComparator != null) {
5174                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5175                                            orderByComparator);
5176                            }
5177                            else
5178                             if (pagination) {
5179                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5180                            }
5181    
5182                            String sql = query.toString();
5183    
5184                            Session session = null;
5185    
5186                            try {
5187                                    session = openSession();
5188    
5189                                    Query q = session.createQuery(sql);
5190    
5191                                    QueryPos qPos = QueryPos.getInstance(q);
5192    
5193                                    qPos.add(groupId);
5194    
5195                                    qPos.add(categoryId);
5196    
5197                                    if (!pagination) {
5198                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5199                                                            start, end, false);
5200    
5201                                            Collections.sort(list);
5202    
5203                                            list = new UnmodifiableList<MBMessage>(list);
5204                                    }
5205                                    else {
5206                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5207                                                            start, end);
5208                                    }
5209    
5210                                    cacheResult(list);
5211    
5212                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5213                            }
5214                            catch (Exception e) {
5215                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5216    
5217                                    throw processException(e);
5218                            }
5219                            finally {
5220                                    closeSession(session);
5221                            }
5222                    }
5223    
5224                    return list;
5225            }
5226    
5227            /**
5228             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5229             *
5230             * @param groupId the group ID
5231             * @param categoryId the category ID
5232             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5233             * @return the first matching message-boards message
5234             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5235             * @throws SystemException if a system exception occurred
5236             */
5237            public MBMessage findByG_C_First(long groupId, long categoryId,
5238                    OrderByComparator orderByComparator)
5239                    throws NoSuchMessageException, SystemException {
5240                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5241                                    orderByComparator);
5242    
5243                    if (mbMessage != null) {
5244                            return mbMessage;
5245                    }
5246    
5247                    StringBundler msg = new StringBundler(6);
5248    
5249                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5250    
5251                    msg.append("groupId=");
5252                    msg.append(groupId);
5253    
5254                    msg.append(", categoryId=");
5255                    msg.append(categoryId);
5256    
5257                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5258    
5259                    throw new NoSuchMessageException(msg.toString());
5260            }
5261    
5262            /**
5263             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5264             *
5265             * @param groupId the group ID
5266             * @param categoryId the category ID
5267             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5268             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5269             * @throws SystemException if a system exception occurred
5270             */
5271            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5272                    OrderByComparator orderByComparator) throws SystemException {
5273                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5274                                    orderByComparator);
5275    
5276                    if (!list.isEmpty()) {
5277                            return list.get(0);
5278                    }
5279    
5280                    return null;
5281            }
5282    
5283            /**
5284             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5285             *
5286             * @param groupId the group ID
5287             * @param categoryId the category ID
5288             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5289             * @return the last matching message-boards message
5290             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5291             * @throws SystemException if a system exception occurred
5292             */
5293            public MBMessage findByG_C_Last(long groupId, long categoryId,
5294                    OrderByComparator orderByComparator)
5295                    throws NoSuchMessageException, SystemException {
5296                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5297                                    orderByComparator);
5298    
5299                    if (mbMessage != null) {
5300                            return mbMessage;
5301                    }
5302    
5303                    StringBundler msg = new StringBundler(6);
5304    
5305                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5306    
5307                    msg.append("groupId=");
5308                    msg.append(groupId);
5309    
5310                    msg.append(", categoryId=");
5311                    msg.append(categoryId);
5312    
5313                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5314    
5315                    throw new NoSuchMessageException(msg.toString());
5316            }
5317    
5318            /**
5319             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5320             *
5321             * @param groupId the group ID
5322             * @param categoryId the category ID
5323             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5324             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5325             * @throws SystemException if a system exception occurred
5326             */
5327            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5328                    OrderByComparator orderByComparator) throws SystemException {
5329                    int count = countByG_C(groupId, categoryId);
5330    
5331                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5332                                    orderByComparator);
5333    
5334                    if (!list.isEmpty()) {
5335                            return list.get(0);
5336                    }
5337    
5338                    return null;
5339            }
5340    
5341            /**
5342             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5343             *
5344             * @param messageId the primary key of the current message-boards message
5345             * @param groupId the group ID
5346             * @param categoryId the category ID
5347             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5348             * @return the previous, current, and next message-boards message
5349             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5350             * @throws SystemException if a system exception occurred
5351             */
5352            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5353                    long categoryId, OrderByComparator orderByComparator)
5354                    throws NoSuchMessageException, SystemException {
5355                    MBMessage mbMessage = findByPrimaryKey(messageId);
5356    
5357                    Session session = null;
5358    
5359                    try {
5360                            session = openSession();
5361    
5362                            MBMessage[] array = new MBMessageImpl[3];
5363    
5364                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5365                                            categoryId, orderByComparator, true);
5366    
5367                            array[1] = mbMessage;
5368    
5369                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5370                                            categoryId, orderByComparator, false);
5371    
5372                            return array;
5373                    }
5374                    catch (Exception e) {
5375                            throw processException(e);
5376                    }
5377                    finally {
5378                            closeSession(session);
5379                    }
5380            }
5381    
5382            protected MBMessage getByG_C_PrevAndNext(Session session,
5383                    MBMessage mbMessage, long groupId, long categoryId,
5384                    OrderByComparator orderByComparator, boolean previous) {
5385                    StringBundler query = null;
5386    
5387                    if (orderByComparator != null) {
5388                            query = new StringBundler(6 +
5389                                            (orderByComparator.getOrderByFields().length * 6));
5390                    }
5391                    else {
5392                            query = new StringBundler(3);
5393                    }
5394    
5395                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5396    
5397                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5398    
5399                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5400    
5401                    if (orderByComparator != null) {
5402                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5403    
5404                            if (orderByConditionFields.length > 0) {
5405                                    query.append(WHERE_AND);
5406                            }
5407    
5408                            for (int i = 0; i < orderByConditionFields.length; i++) {
5409                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5410                                    query.append(orderByConditionFields[i]);
5411    
5412                                    if ((i + 1) < orderByConditionFields.length) {
5413                                            if (orderByComparator.isAscending() ^ previous) {
5414                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5415                                            }
5416                                            else {
5417                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5418                                            }
5419                                    }
5420                                    else {
5421                                            if (orderByComparator.isAscending() ^ previous) {
5422                                                    query.append(WHERE_GREATER_THAN);
5423                                            }
5424                                            else {
5425                                                    query.append(WHERE_LESSER_THAN);
5426                                            }
5427                                    }
5428                            }
5429    
5430                            query.append(ORDER_BY_CLAUSE);
5431    
5432                            String[] orderByFields = orderByComparator.getOrderByFields();
5433    
5434                            for (int i = 0; i < orderByFields.length; i++) {
5435                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5436                                    query.append(orderByFields[i]);
5437    
5438                                    if ((i + 1) < orderByFields.length) {
5439                                            if (orderByComparator.isAscending() ^ previous) {
5440                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5441                                            }
5442                                            else {
5443                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5444                                            }
5445                                    }
5446                                    else {
5447                                            if (orderByComparator.isAscending() ^ previous) {
5448                                                    query.append(ORDER_BY_ASC);
5449                                            }
5450                                            else {
5451                                                    query.append(ORDER_BY_DESC);
5452                                            }
5453                                    }
5454                            }
5455                    }
5456                    else {
5457                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5458                    }
5459    
5460                    String sql = query.toString();
5461    
5462                    Query q = session.createQuery(sql);
5463    
5464                    q.setFirstResult(0);
5465                    q.setMaxResults(2);
5466    
5467                    QueryPos qPos = QueryPos.getInstance(q);
5468    
5469                    qPos.add(groupId);
5470    
5471                    qPos.add(categoryId);
5472    
5473                    if (orderByComparator != null) {
5474                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5475    
5476                            for (Object value : values) {
5477                                    qPos.add(value);
5478                            }
5479                    }
5480    
5481                    List<MBMessage> list = q.list();
5482    
5483                    if (list.size() == 2) {
5484                            return list.get(1);
5485                    }
5486                    else {
5487                            return null;
5488                    }
5489            }
5490    
5491            /**
5492             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5493             *
5494             * @param groupId the group ID
5495             * @param categoryId the category ID
5496             * @return the matching message-boards messages that the user has permission to view
5497             * @throws SystemException if a system exception occurred
5498             */
5499            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
5500                    throws SystemException {
5501                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5502                            QueryUtil.ALL_POS, null);
5503            }
5504    
5505            /**
5506             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5507             *
5508             * <p>
5509             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5510             * </p>
5511             *
5512             * @param groupId the group ID
5513             * @param categoryId the category ID
5514             * @param start the lower bound of the range of message-boards messages
5515             * @param end the upper bound of the range of message-boards messages (not inclusive)
5516             * @return the range of matching message-boards messages that the user has permission to view
5517             * @throws SystemException if a system exception occurred
5518             */
5519            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5520                    int start, int end) throws SystemException {
5521                    return filterFindByG_C(groupId, categoryId, start, end, null);
5522            }
5523    
5524            /**
5525             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5526             *
5527             * <p>
5528             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5529             * </p>
5530             *
5531             * @param groupId the group ID
5532             * @param categoryId the category ID
5533             * @param start the lower bound of the range of message-boards messages
5534             * @param end the upper bound of the range of message-boards messages (not inclusive)
5535             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5536             * @return the ordered range of matching message-boards messages that the user has permission to view
5537             * @throws SystemException if a system exception occurred
5538             */
5539            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5540                    int start, int end, OrderByComparator orderByComparator)
5541                    throws SystemException {
5542                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5543                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5544                    }
5545    
5546                    StringBundler query = null;
5547    
5548                    if (orderByComparator != null) {
5549                            query = new StringBundler(4 +
5550                                            (orderByComparator.getOrderByFields().length * 3));
5551                    }
5552                    else {
5553                            query = new StringBundler(4);
5554                    }
5555    
5556                    if (getDB().isSupportsInlineDistinct()) {
5557                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5558                    }
5559                    else {
5560                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5561                    }
5562    
5563                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5564    
5565                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5566    
5567                    if (!getDB().isSupportsInlineDistinct()) {
5568                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5569                    }
5570    
5571                    if (orderByComparator != null) {
5572                            if (getDB().isSupportsInlineDistinct()) {
5573                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5574                                            orderByComparator);
5575                            }
5576                            else {
5577                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5578                                            orderByComparator);
5579                            }
5580                    }
5581                    else {
5582                            if (getDB().isSupportsInlineDistinct()) {
5583                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5584                            }
5585                            else {
5586                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5587                            }
5588                    }
5589    
5590                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5591                                    MBMessage.class.getName(),
5592                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5593    
5594                    Session session = null;
5595    
5596                    try {
5597                            session = openSession();
5598    
5599                            SQLQuery q = session.createSQLQuery(sql);
5600    
5601                            if (getDB().isSupportsInlineDistinct()) {
5602                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5603                            }
5604                            else {
5605                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5606                            }
5607    
5608                            QueryPos qPos = QueryPos.getInstance(q);
5609    
5610                            qPos.add(groupId);
5611    
5612                            qPos.add(categoryId);
5613    
5614                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5615                    }
5616                    catch (Exception e) {
5617                            throw processException(e);
5618                    }
5619                    finally {
5620                            closeSession(session);
5621                    }
5622            }
5623    
5624            /**
5625             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5626             *
5627             * @param messageId the primary key of the current message-boards message
5628             * @param groupId the group ID
5629             * @param categoryId the category ID
5630             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5631             * @return the previous, current, and next message-boards message
5632             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5633             * @throws SystemException if a system exception occurred
5634             */
5635            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5636                    long groupId, long categoryId, OrderByComparator orderByComparator)
5637                    throws NoSuchMessageException, SystemException {
5638                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5639                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5640                                    orderByComparator);
5641                    }
5642    
5643                    MBMessage mbMessage = findByPrimaryKey(messageId);
5644    
5645                    Session session = null;
5646    
5647                    try {
5648                            session = openSession();
5649    
5650                            MBMessage[] array = new MBMessageImpl[3];
5651    
5652                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5653                                            categoryId, orderByComparator, true);
5654    
5655                            array[1] = mbMessage;
5656    
5657                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5658                                            categoryId, orderByComparator, false);
5659    
5660                            return array;
5661                    }
5662                    catch (Exception e) {
5663                            throw processException(e);
5664                    }
5665                    finally {
5666                            closeSession(session);
5667                    }
5668            }
5669    
5670            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5671                    MBMessage mbMessage, long groupId, long categoryId,
5672                    OrderByComparator orderByComparator, boolean previous) {
5673                    StringBundler query = null;
5674    
5675                    if (orderByComparator != null) {
5676                            query = new StringBundler(6 +
5677                                            (orderByComparator.getOrderByFields().length * 6));
5678                    }
5679                    else {
5680                            query = new StringBundler(3);
5681                    }
5682    
5683                    if (getDB().isSupportsInlineDistinct()) {
5684                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5685                    }
5686                    else {
5687                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5688                    }
5689    
5690                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5691    
5692                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5693    
5694                    if (!getDB().isSupportsInlineDistinct()) {
5695                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5696                    }
5697    
5698                    if (orderByComparator != null) {
5699                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5700    
5701                            if (orderByConditionFields.length > 0) {
5702                                    query.append(WHERE_AND);
5703                            }
5704    
5705                            for (int i = 0; i < orderByConditionFields.length; i++) {
5706                                    if (getDB().isSupportsInlineDistinct()) {
5707                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5708                                    }
5709                                    else {
5710                                            query.append(_ORDER_BY_ENTITY_TABLE);
5711                                    }
5712    
5713                                    query.append(orderByConditionFields[i]);
5714    
5715                                    if ((i + 1) < orderByConditionFields.length) {
5716                                            if (orderByComparator.isAscending() ^ previous) {
5717                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5718                                            }
5719                                            else {
5720                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5721                                            }
5722                                    }
5723                                    else {
5724                                            if (orderByComparator.isAscending() ^ previous) {
5725                                                    query.append(WHERE_GREATER_THAN);
5726                                            }
5727                                            else {
5728                                                    query.append(WHERE_LESSER_THAN);
5729                                            }
5730                                    }
5731                            }
5732    
5733                            query.append(ORDER_BY_CLAUSE);
5734    
5735                            String[] orderByFields = orderByComparator.getOrderByFields();
5736    
5737                            for (int i = 0; i < orderByFields.length; i++) {
5738                                    if (getDB().isSupportsInlineDistinct()) {
5739                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5740                                    }
5741                                    else {
5742                                            query.append(_ORDER_BY_ENTITY_TABLE);
5743                                    }
5744    
5745                                    query.append(orderByFields[i]);
5746    
5747                                    if ((i + 1) < orderByFields.length) {
5748                                            if (orderByComparator.isAscending() ^ previous) {
5749                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5750                                            }
5751                                            else {
5752                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5753                                            }
5754                                    }
5755                                    else {
5756                                            if (orderByComparator.isAscending() ^ previous) {
5757                                                    query.append(ORDER_BY_ASC);
5758                                            }
5759                                            else {
5760                                                    query.append(ORDER_BY_DESC);
5761                                            }
5762                                    }
5763                            }
5764                    }
5765                    else {
5766                            if (getDB().isSupportsInlineDistinct()) {
5767                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5768                            }
5769                            else {
5770                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5771                            }
5772                    }
5773    
5774                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5775                                    MBMessage.class.getName(),
5776                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5777    
5778                    SQLQuery q = session.createSQLQuery(sql);
5779    
5780                    q.setFirstResult(0);
5781                    q.setMaxResults(2);
5782    
5783                    if (getDB().isSupportsInlineDistinct()) {
5784                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5785                    }
5786                    else {
5787                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5788                    }
5789    
5790                    QueryPos qPos = QueryPos.getInstance(q);
5791    
5792                    qPos.add(groupId);
5793    
5794                    qPos.add(categoryId);
5795    
5796                    if (orderByComparator != null) {
5797                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5798    
5799                            for (Object value : values) {
5800                                    qPos.add(value);
5801                            }
5802                    }
5803    
5804                    List<MBMessage> list = q.list();
5805    
5806                    if (list.size() == 2) {
5807                            return list.get(1);
5808                    }
5809                    else {
5810                            return null;
5811                    }
5812            }
5813    
5814            /**
5815             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
5816             *
5817             * @param groupId the group ID
5818             * @param categoryId the category ID
5819             * @throws SystemException if a system exception occurred
5820             */
5821            public void removeByG_C(long groupId, long categoryId)
5822                    throws SystemException {
5823                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
5824                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5825                            remove(mbMessage);
5826                    }
5827            }
5828    
5829            /**
5830             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
5831             *
5832             * @param groupId the group ID
5833             * @param categoryId the category ID
5834             * @return the number of matching message-boards messages
5835             * @throws SystemException if a system exception occurred
5836             */
5837            public int countByG_C(long groupId, long categoryId)
5838                    throws SystemException {
5839                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
5840    
5841                    Object[] finderArgs = new Object[] { groupId, categoryId };
5842    
5843                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5844                                    this);
5845    
5846                    if (count == null) {
5847                            StringBundler query = new StringBundler(3);
5848    
5849                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5850    
5851                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5852    
5853                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5854    
5855                            String sql = query.toString();
5856    
5857                            Session session = null;
5858    
5859                            try {
5860                                    session = openSession();
5861    
5862                                    Query q = session.createQuery(sql);
5863    
5864                                    QueryPos qPos = QueryPos.getInstance(q);
5865    
5866                                    qPos.add(groupId);
5867    
5868                                    qPos.add(categoryId);
5869    
5870                                    count = (Long)q.uniqueResult();
5871    
5872                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5873                            }
5874                            catch (Exception e) {
5875                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5876    
5877                                    throw processException(e);
5878                            }
5879                            finally {
5880                                    closeSession(session);
5881                            }
5882                    }
5883    
5884                    return count.intValue();
5885            }
5886    
5887            /**
5888             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5889             *
5890             * @param groupId the group ID
5891             * @param categoryId the category ID
5892             * @return the number of matching message-boards messages that the user has permission to view
5893             * @throws SystemException if a system exception occurred
5894             */
5895            public int filterCountByG_C(long groupId, long categoryId)
5896                    throws SystemException {
5897                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5898                            return countByG_C(groupId, categoryId);
5899                    }
5900    
5901                    StringBundler query = new StringBundler(3);
5902    
5903                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5904    
5905                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5906    
5907                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5908    
5909                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5910                                    MBMessage.class.getName(),
5911                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5912    
5913                    Session session = null;
5914    
5915                    try {
5916                            session = openSession();
5917    
5918                            SQLQuery q = session.createSQLQuery(sql);
5919    
5920                            q.addScalar(COUNT_COLUMN_NAME,
5921                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5922    
5923                            QueryPos qPos = QueryPos.getInstance(q);
5924    
5925                            qPos.add(groupId);
5926    
5927                            qPos.add(categoryId);
5928    
5929                            Long count = (Long)q.uniqueResult();
5930    
5931                            return count.intValue();
5932                    }
5933                    catch (Exception e) {
5934                            throw processException(e);
5935                    }
5936                    finally {
5937                            closeSession(session);
5938                    }
5939            }
5940    
5941            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
5942            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
5943            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5944                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5945                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
5946                            new String[] {
5947                                    Long.class.getName(), Integer.class.getName(),
5948                                    
5949                            Integer.class.getName(), Integer.class.getName(),
5950                                    OrderByComparator.class.getName()
5951                            });
5952            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5953                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5954                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
5955                            new String[] { Long.class.getName(), Integer.class.getName() },
5956                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5957                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
5958                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5959            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5960                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5961                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
5962                            new String[] { Long.class.getName(), Integer.class.getName() });
5963    
5964            /**
5965             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
5966             *
5967             * @param groupId the group ID
5968             * @param status the status
5969             * @return the matching message-boards messages
5970             * @throws SystemException if a system exception occurred
5971             */
5972            public List<MBMessage> findByG_S(long groupId, int status)
5973                    throws SystemException {
5974                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5975                            null);
5976            }
5977    
5978            /**
5979             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
5980             *
5981             * <p>
5982             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
5983             * </p>
5984             *
5985             * @param groupId the group ID
5986             * @param status the status
5987             * @param start the lower bound of the range of message-boards messages
5988             * @param end the upper bound of the range of message-boards messages (not inclusive)
5989             * @return the range of matching message-boards messages
5990             * @throws SystemException if a system exception occurred
5991             */
5992            public List<MBMessage> findByG_S(long groupId, int status, int start,
5993                    int end) throws SystemException {
5994                    return findByG_S(groupId, status, start, end, null);
5995            }
5996    
5997            /**
5998             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
5999             *
6000             * <p>
6001             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6002             * </p>
6003             *
6004             * @param groupId the group ID
6005             * @param status the status
6006             * @param start the lower bound of the range of message-boards messages
6007             * @param end the upper bound of the range of message-boards messages (not inclusive)
6008             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6009             * @return the ordered range of matching message-boards messages
6010             * @throws SystemException if a system exception occurred
6011             */
6012            public List<MBMessage> findByG_S(long groupId, int status, int start,
6013                    int end, OrderByComparator orderByComparator) throws SystemException {
6014                    boolean pagination = true;
6015                    FinderPath finderPath = null;
6016                    Object[] finderArgs = null;
6017    
6018                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6019                                    (orderByComparator == null)) {
6020                            pagination = false;
6021                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6022                            finderArgs = new Object[] { groupId, status };
6023                    }
6024                    else {
6025                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6026                            finderArgs = new Object[] {
6027                                            groupId, status,
6028                                            
6029                                            start, end, orderByComparator
6030                                    };
6031                    }
6032    
6033                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6034                                    finderArgs, this);
6035    
6036                    if ((list != null) && !list.isEmpty()) {
6037                            for (MBMessage mbMessage : list) {
6038                                    if ((groupId != mbMessage.getGroupId()) ||
6039                                                    (status != mbMessage.getStatus())) {
6040                                            list = null;
6041    
6042                                            break;
6043                                    }
6044                            }
6045                    }
6046    
6047                    if (list == null) {
6048                            StringBundler query = null;
6049    
6050                            if (orderByComparator != null) {
6051                                    query = new StringBundler(4 +
6052                                                    (orderByComparator.getOrderByFields().length * 3));
6053                            }
6054                            else {
6055                                    query = new StringBundler(4);
6056                            }
6057    
6058                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6059    
6060                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6061    
6062                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6063    
6064                            if (orderByComparator != null) {
6065                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6066                                            orderByComparator);
6067                            }
6068                            else
6069                             if (pagination) {
6070                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6071                            }
6072    
6073                            String sql = query.toString();
6074    
6075                            Session session = null;
6076    
6077                            try {
6078                                    session = openSession();
6079    
6080                                    Query q = session.createQuery(sql);
6081    
6082                                    QueryPos qPos = QueryPos.getInstance(q);
6083    
6084                                    qPos.add(groupId);
6085    
6086                                    qPos.add(status);
6087    
6088                                    if (!pagination) {
6089                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6090                                                            start, end, false);
6091    
6092                                            Collections.sort(list);
6093    
6094                                            list = new UnmodifiableList<MBMessage>(list);
6095                                    }
6096                                    else {
6097                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6098                                                            start, end);
6099                                    }
6100    
6101                                    cacheResult(list);
6102    
6103                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6104                            }
6105                            catch (Exception e) {
6106                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6107    
6108                                    throw processException(e);
6109                            }
6110                            finally {
6111                                    closeSession(session);
6112                            }
6113                    }
6114    
6115                    return list;
6116            }
6117    
6118            /**
6119             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6120             *
6121             * @param groupId the group ID
6122             * @param status the status
6123             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6124             * @return the first matching message-boards message
6125             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6126             * @throws SystemException if a system exception occurred
6127             */
6128            public MBMessage findByG_S_First(long groupId, int status,
6129                    OrderByComparator orderByComparator)
6130                    throws NoSuchMessageException, SystemException {
6131                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6132                                    orderByComparator);
6133    
6134                    if (mbMessage != null) {
6135                            return mbMessage;
6136                    }
6137    
6138                    StringBundler msg = new StringBundler(6);
6139    
6140                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6141    
6142                    msg.append("groupId=");
6143                    msg.append(groupId);
6144    
6145                    msg.append(", status=");
6146                    msg.append(status);
6147    
6148                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6149    
6150                    throw new NoSuchMessageException(msg.toString());
6151            }
6152    
6153            /**
6154             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6155             *
6156             * @param groupId the group ID
6157             * @param status the status
6158             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6159             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6160             * @throws SystemException if a system exception occurred
6161             */
6162            public MBMessage fetchByG_S_First(long groupId, int status,
6163                    OrderByComparator orderByComparator) throws SystemException {
6164                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6165                                    orderByComparator);
6166    
6167                    if (!list.isEmpty()) {
6168                            return list.get(0);
6169                    }
6170    
6171                    return null;
6172            }
6173    
6174            /**
6175             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6176             *
6177             * @param groupId the group ID
6178             * @param status the status
6179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6180             * @return the last matching message-boards message
6181             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6182             * @throws SystemException if a system exception occurred
6183             */
6184            public MBMessage findByG_S_Last(long groupId, int status,
6185                    OrderByComparator orderByComparator)
6186                    throws NoSuchMessageException, SystemException {
6187                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6188    
6189                    if (mbMessage != null) {
6190                            return mbMessage;
6191                    }
6192    
6193                    StringBundler msg = new StringBundler(6);
6194    
6195                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6196    
6197                    msg.append("groupId=");
6198                    msg.append(groupId);
6199    
6200                    msg.append(", status=");
6201                    msg.append(status);
6202    
6203                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6204    
6205                    throw new NoSuchMessageException(msg.toString());
6206            }
6207    
6208            /**
6209             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6210             *
6211             * @param groupId the group ID
6212             * @param status the status
6213             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6214             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6215             * @throws SystemException if a system exception occurred
6216             */
6217            public MBMessage fetchByG_S_Last(long groupId, int status,
6218                    OrderByComparator orderByComparator) throws SystemException {
6219                    int count = countByG_S(groupId, status);
6220    
6221                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6222                                    orderByComparator);
6223    
6224                    if (!list.isEmpty()) {
6225                            return list.get(0);
6226                    }
6227    
6228                    return null;
6229            }
6230    
6231            /**
6232             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6233             *
6234             * @param messageId the primary key of the current message-boards message
6235             * @param groupId the group ID
6236             * @param status the status
6237             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6238             * @return the previous, current, and next message-boards message
6239             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6240             * @throws SystemException if a system exception occurred
6241             */
6242            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6243                    int status, OrderByComparator orderByComparator)
6244                    throws NoSuchMessageException, SystemException {
6245                    MBMessage mbMessage = findByPrimaryKey(messageId);
6246    
6247                    Session session = null;
6248    
6249                    try {
6250                            session = openSession();
6251    
6252                            MBMessage[] array = new MBMessageImpl[3];
6253    
6254                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6255                                            status, orderByComparator, true);
6256    
6257                            array[1] = mbMessage;
6258    
6259                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6260                                            status, orderByComparator, false);
6261    
6262                            return array;
6263                    }
6264                    catch (Exception e) {
6265                            throw processException(e);
6266                    }
6267                    finally {
6268                            closeSession(session);
6269                    }
6270            }
6271    
6272            protected MBMessage getByG_S_PrevAndNext(Session session,
6273                    MBMessage mbMessage, long groupId, int status,
6274                    OrderByComparator orderByComparator, boolean previous) {
6275                    StringBundler query = null;
6276    
6277                    if (orderByComparator != null) {
6278                            query = new StringBundler(6 +
6279                                            (orderByComparator.getOrderByFields().length * 6));
6280                    }
6281                    else {
6282                            query = new StringBundler(3);
6283                    }
6284    
6285                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6286    
6287                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6288    
6289                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6290    
6291                    if (orderByComparator != null) {
6292                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6293    
6294                            if (orderByConditionFields.length > 0) {
6295                                    query.append(WHERE_AND);
6296                            }
6297    
6298                            for (int i = 0; i < orderByConditionFields.length; i++) {
6299                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6300                                    query.append(orderByConditionFields[i]);
6301    
6302                                    if ((i + 1) < orderByConditionFields.length) {
6303                                            if (orderByComparator.isAscending() ^ previous) {
6304                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6305                                            }
6306                                            else {
6307                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6308                                            }
6309                                    }
6310                                    else {
6311                                            if (orderByComparator.isAscending() ^ previous) {
6312                                                    query.append(WHERE_GREATER_THAN);
6313                                            }
6314                                            else {
6315                                                    query.append(WHERE_LESSER_THAN);
6316                                            }
6317                                    }
6318                            }
6319    
6320                            query.append(ORDER_BY_CLAUSE);
6321    
6322                            String[] orderByFields = orderByComparator.getOrderByFields();
6323    
6324                            for (int i = 0; i < orderByFields.length; i++) {
6325                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6326                                    query.append(orderByFields[i]);
6327    
6328                                    if ((i + 1) < orderByFields.length) {
6329                                            if (orderByComparator.isAscending() ^ previous) {
6330                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6331                                            }
6332                                            else {
6333                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6334                                            }
6335                                    }
6336                                    else {
6337                                            if (orderByComparator.isAscending() ^ previous) {
6338                                                    query.append(ORDER_BY_ASC);
6339                                            }
6340                                            else {
6341                                                    query.append(ORDER_BY_DESC);
6342                                            }
6343                                    }
6344                            }
6345                    }
6346                    else {
6347                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6348                    }
6349    
6350                    String sql = query.toString();
6351    
6352                    Query q = session.createQuery(sql);
6353    
6354                    q.setFirstResult(0);
6355                    q.setMaxResults(2);
6356    
6357                    QueryPos qPos = QueryPos.getInstance(q);
6358    
6359                    qPos.add(groupId);
6360    
6361                    qPos.add(status);
6362    
6363                    if (orderByComparator != null) {
6364                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6365    
6366                            for (Object value : values) {
6367                                    qPos.add(value);
6368                            }
6369                    }
6370    
6371                    List<MBMessage> list = q.list();
6372    
6373                    if (list.size() == 2) {
6374                            return list.get(1);
6375                    }
6376                    else {
6377                            return null;
6378                    }
6379            }
6380    
6381            /**
6382             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6383             *
6384             * @param groupId the group ID
6385             * @param status the status
6386             * @return the matching message-boards messages that the user has permission to view
6387             * @throws SystemException if a system exception occurred
6388             */
6389            public List<MBMessage> filterFindByG_S(long groupId, int status)
6390                    throws SystemException {
6391                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6392                            QueryUtil.ALL_POS, null);
6393            }
6394    
6395            /**
6396             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6397             *
6398             * <p>
6399             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6400             * </p>
6401             *
6402             * @param groupId the group ID
6403             * @param status the status
6404             * @param start the lower bound of the range of message-boards messages
6405             * @param end the upper bound of the range of message-boards messages (not inclusive)
6406             * @return the range of matching message-boards messages that the user has permission to view
6407             * @throws SystemException if a system exception occurred
6408             */
6409            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6410                    int end) throws SystemException {
6411                    return filterFindByG_S(groupId, status, start, end, null);
6412            }
6413    
6414            /**
6415             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6416             *
6417             * <p>
6418             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6419             * </p>
6420             *
6421             * @param groupId the group ID
6422             * @param status the status
6423             * @param start the lower bound of the range of message-boards messages
6424             * @param end the upper bound of the range of message-boards messages (not inclusive)
6425             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6426             * @return the ordered range of matching message-boards messages that the user has permission to view
6427             * @throws SystemException if a system exception occurred
6428             */
6429            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6430                    int end, OrderByComparator orderByComparator) throws SystemException {
6431                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6432                            return findByG_S(groupId, status, start, end, orderByComparator);
6433                    }
6434    
6435                    StringBundler query = null;
6436    
6437                    if (orderByComparator != null) {
6438                            query = new StringBundler(4 +
6439                                            (orderByComparator.getOrderByFields().length * 3));
6440                    }
6441                    else {
6442                            query = new StringBundler(4);
6443                    }
6444    
6445                    if (getDB().isSupportsInlineDistinct()) {
6446                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6447                    }
6448                    else {
6449                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6450                    }
6451    
6452                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6453    
6454                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6455    
6456                    if (!getDB().isSupportsInlineDistinct()) {
6457                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6458                    }
6459    
6460                    if (orderByComparator != null) {
6461                            if (getDB().isSupportsInlineDistinct()) {
6462                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6463                                            orderByComparator);
6464                            }
6465                            else {
6466                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6467                                            orderByComparator);
6468                            }
6469                    }
6470                    else {
6471                            if (getDB().isSupportsInlineDistinct()) {
6472                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6473                            }
6474                            else {
6475                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6476                            }
6477                    }
6478    
6479                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6480                                    MBMessage.class.getName(),
6481                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6482    
6483                    Session session = null;
6484    
6485                    try {
6486                            session = openSession();
6487    
6488                            SQLQuery q = session.createSQLQuery(sql);
6489    
6490                            if (getDB().isSupportsInlineDistinct()) {
6491                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6492                            }
6493                            else {
6494                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6495                            }
6496    
6497                            QueryPos qPos = QueryPos.getInstance(q);
6498    
6499                            qPos.add(groupId);
6500    
6501                            qPos.add(status);
6502    
6503                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6504                    }
6505                    catch (Exception e) {
6506                            throw processException(e);
6507                    }
6508                    finally {
6509                            closeSession(session);
6510                    }
6511            }
6512    
6513            /**
6514             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6515             *
6516             * @param messageId the primary key of the current message-boards message
6517             * @param groupId the group ID
6518             * @param status the status
6519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6520             * @return the previous, current, and next message-boards message
6521             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6522             * @throws SystemException if a system exception occurred
6523             */
6524            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6525                    long groupId, int status, OrderByComparator orderByComparator)
6526                    throws NoSuchMessageException, SystemException {
6527                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6528                            return findByG_S_PrevAndNext(messageId, groupId, status,
6529                                    orderByComparator);
6530                    }
6531    
6532                    MBMessage mbMessage = findByPrimaryKey(messageId);
6533    
6534                    Session session = null;
6535    
6536                    try {
6537                            session = openSession();
6538    
6539                            MBMessage[] array = new MBMessageImpl[3];
6540    
6541                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6542                                            status, orderByComparator, true);
6543    
6544                            array[1] = mbMessage;
6545    
6546                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6547                                            status, orderByComparator, false);
6548    
6549                            return array;
6550                    }
6551                    catch (Exception e) {
6552                            throw processException(e);
6553                    }
6554                    finally {
6555                            closeSession(session);
6556                    }
6557            }
6558    
6559            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6560                    MBMessage mbMessage, long groupId, int status,
6561                    OrderByComparator orderByComparator, boolean previous) {
6562                    StringBundler query = null;
6563    
6564                    if (orderByComparator != null) {
6565                            query = new StringBundler(6 +
6566                                            (orderByComparator.getOrderByFields().length * 6));
6567                    }
6568                    else {
6569                            query = new StringBundler(3);
6570                    }
6571    
6572                    if (getDB().isSupportsInlineDistinct()) {
6573                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6574                    }
6575                    else {
6576                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6577                    }
6578    
6579                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6580    
6581                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6582    
6583                    if (!getDB().isSupportsInlineDistinct()) {
6584                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6585                    }
6586    
6587                    if (orderByComparator != null) {
6588                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6589    
6590                            if (orderByConditionFields.length > 0) {
6591                                    query.append(WHERE_AND);
6592                            }
6593    
6594                            for (int i = 0; i < orderByConditionFields.length; i++) {
6595                                    if (getDB().isSupportsInlineDistinct()) {
6596                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6597                                    }
6598                                    else {
6599                                            query.append(_ORDER_BY_ENTITY_TABLE);
6600                                    }
6601    
6602                                    query.append(orderByConditionFields[i]);
6603    
6604                                    if ((i + 1) < orderByConditionFields.length) {
6605                                            if (orderByComparator.isAscending() ^ previous) {
6606                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6607                                            }
6608                                            else {
6609                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6610                                            }
6611                                    }
6612                                    else {
6613                                            if (orderByComparator.isAscending() ^ previous) {
6614                                                    query.append(WHERE_GREATER_THAN);
6615                                            }
6616                                            else {
6617                                                    query.append(WHERE_LESSER_THAN);
6618                                            }
6619                                    }
6620                            }
6621    
6622                            query.append(ORDER_BY_CLAUSE);
6623    
6624                            String[] orderByFields = orderByComparator.getOrderByFields();
6625    
6626                            for (int i = 0; i < orderByFields.length; i++) {
6627                                    if (getDB().isSupportsInlineDistinct()) {
6628                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6629                                    }
6630                                    else {
6631                                            query.append(_ORDER_BY_ENTITY_TABLE);
6632                                    }
6633    
6634                                    query.append(orderByFields[i]);
6635    
6636                                    if ((i + 1) < orderByFields.length) {
6637                                            if (orderByComparator.isAscending() ^ previous) {
6638                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6639                                            }
6640                                            else {
6641                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6642                                            }
6643                                    }
6644                                    else {
6645                                            if (orderByComparator.isAscending() ^ previous) {
6646                                                    query.append(ORDER_BY_ASC);
6647                                            }
6648                                            else {
6649                                                    query.append(ORDER_BY_DESC);
6650                                            }
6651                                    }
6652                            }
6653                    }
6654                    else {
6655                            if (getDB().isSupportsInlineDistinct()) {
6656                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6657                            }
6658                            else {
6659                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6660                            }
6661                    }
6662    
6663                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6664                                    MBMessage.class.getName(),
6665                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6666    
6667                    SQLQuery q = session.createSQLQuery(sql);
6668    
6669                    q.setFirstResult(0);
6670                    q.setMaxResults(2);
6671    
6672                    if (getDB().isSupportsInlineDistinct()) {
6673                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6674                    }
6675                    else {
6676                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6677                    }
6678    
6679                    QueryPos qPos = QueryPos.getInstance(q);
6680    
6681                    qPos.add(groupId);
6682    
6683                    qPos.add(status);
6684    
6685                    if (orderByComparator != null) {
6686                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6687    
6688                            for (Object value : values) {
6689                                    qPos.add(value);
6690                            }
6691                    }
6692    
6693                    List<MBMessage> list = q.list();
6694    
6695                    if (list.size() == 2) {
6696                            return list.get(1);
6697                    }
6698                    else {
6699                            return null;
6700                    }
6701            }
6702    
6703            /**
6704             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6705             *
6706             * @param groupId the group ID
6707             * @param status the status
6708             * @throws SystemException if a system exception occurred
6709             */
6710            public void removeByG_S(long groupId, int status) throws SystemException {
6711                    for (MBMessage mbMessage : findByG_S(groupId, status,
6712                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6713                            remove(mbMessage);
6714                    }
6715            }
6716    
6717            /**
6718             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
6719             *
6720             * @param groupId the group ID
6721             * @param status the status
6722             * @return the number of matching message-boards messages
6723             * @throws SystemException if a system exception occurred
6724             */
6725            public int countByG_S(long groupId, int status) throws SystemException {
6726                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6727    
6728                    Object[] finderArgs = new Object[] { groupId, status };
6729    
6730                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6731                                    this);
6732    
6733                    if (count == null) {
6734                            StringBundler query = new StringBundler(3);
6735    
6736                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6737    
6738                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6739    
6740                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6741    
6742                            String sql = query.toString();
6743    
6744                            Session session = null;
6745    
6746                            try {
6747                                    session = openSession();
6748    
6749                                    Query q = session.createQuery(sql);
6750    
6751                                    QueryPos qPos = QueryPos.getInstance(q);
6752    
6753                                    qPos.add(groupId);
6754    
6755                                    qPos.add(status);
6756    
6757                                    count = (Long)q.uniqueResult();
6758    
6759                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6760                            }
6761                            catch (Exception e) {
6762                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6763    
6764                                    throw processException(e);
6765                            }
6766                            finally {
6767                                    closeSession(session);
6768                            }
6769                    }
6770    
6771                    return count.intValue();
6772            }
6773    
6774            /**
6775             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6776             *
6777             * @param groupId the group ID
6778             * @param status the status
6779             * @return the number of matching message-boards messages that the user has permission to view
6780             * @throws SystemException if a system exception occurred
6781             */
6782            public int filterCountByG_S(long groupId, int status)
6783                    throws SystemException {
6784                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6785                            return countByG_S(groupId, status);
6786                    }
6787    
6788                    StringBundler query = new StringBundler(3);
6789    
6790                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6791    
6792                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6793    
6794                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6795    
6796                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6797                                    MBMessage.class.getName(),
6798                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6799    
6800                    Session session = null;
6801    
6802                    try {
6803                            session = openSession();
6804    
6805                            SQLQuery q = session.createSQLQuery(sql);
6806    
6807                            q.addScalar(COUNT_COLUMN_NAME,
6808                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6809    
6810                            QueryPos qPos = QueryPos.getInstance(q);
6811    
6812                            qPos.add(groupId);
6813    
6814                            qPos.add(status);
6815    
6816                            Long count = (Long)q.uniqueResult();
6817    
6818                            return count.intValue();
6819                    }
6820                    catch (Exception e) {
6821                            throw processException(e);
6822                    }
6823                    finally {
6824                            closeSession(session);
6825                    }
6826            }
6827    
6828            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
6829            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
6830            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6831                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6832                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
6833                            new String[] {
6834                                    Long.class.getName(), Integer.class.getName(),
6835                                    
6836                            Integer.class.getName(), Integer.class.getName(),
6837                                    OrderByComparator.class.getName()
6838                            });
6839            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6840                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6841                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
6842                            new String[] { Long.class.getName(), Integer.class.getName() },
6843                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
6844                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6845                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6846            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6847                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6848                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
6849                            new String[] { Long.class.getName(), Integer.class.getName() });
6850    
6851            /**
6852             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
6853             *
6854             * @param companyId the company ID
6855             * @param status the status
6856             * @return the matching message-boards messages
6857             * @throws SystemException if a system exception occurred
6858             */
6859            public List<MBMessage> findByC_S(long companyId, int status)
6860                    throws SystemException {
6861                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
6862                            QueryUtil.ALL_POS, null);
6863            }
6864    
6865            /**
6866             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
6867             *
6868             * <p>
6869             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6870             * </p>
6871             *
6872             * @param companyId the company ID
6873             * @param status the status
6874             * @param start the lower bound of the range of message-boards messages
6875             * @param end the upper bound of the range of message-boards messages (not inclusive)
6876             * @return the range of matching message-boards messages
6877             * @throws SystemException if a system exception occurred
6878             */
6879            public List<MBMessage> findByC_S(long companyId, int status, int start,
6880                    int end) throws SystemException {
6881                    return findByC_S(companyId, status, start, end, null);
6882            }
6883    
6884            /**
6885             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
6886             *
6887             * <p>
6888             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
6889             * </p>
6890             *
6891             * @param companyId the company ID
6892             * @param status the status
6893             * @param start the lower bound of the range of message-boards messages
6894             * @param end the upper bound of the range of message-boards messages (not inclusive)
6895             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6896             * @return the ordered range of matching message-boards messages
6897             * @throws SystemException if a system exception occurred
6898             */
6899            public List<MBMessage> findByC_S(long companyId, int status, int start,
6900                    int end, OrderByComparator orderByComparator) throws SystemException {
6901                    boolean pagination = true;
6902                    FinderPath finderPath = null;
6903                    Object[] finderArgs = null;
6904    
6905                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6906                                    (orderByComparator == null)) {
6907                            pagination = false;
6908                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6909                            finderArgs = new Object[] { companyId, status };
6910                    }
6911                    else {
6912                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6913                            finderArgs = new Object[] {
6914                                            companyId, status,
6915                                            
6916                                            start, end, orderByComparator
6917                                    };
6918                    }
6919    
6920                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6921                                    finderArgs, this);
6922    
6923                    if ((list != null) && !list.isEmpty()) {
6924                            for (MBMessage mbMessage : list) {
6925                                    if ((companyId != mbMessage.getCompanyId()) ||
6926                                                    (status != mbMessage.getStatus())) {
6927                                            list = null;
6928    
6929                                            break;
6930                                    }
6931                            }
6932                    }
6933    
6934                    if (list == null) {
6935                            StringBundler query = null;
6936    
6937                            if (orderByComparator != null) {
6938                                    query = new StringBundler(4 +
6939                                                    (orderByComparator.getOrderByFields().length * 3));
6940                            }
6941                            else {
6942                                    query = new StringBundler(4);
6943                            }
6944    
6945                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6946    
6947                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6948    
6949                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
6950    
6951                            if (orderByComparator != null) {
6952                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6953                                            orderByComparator);
6954                            }
6955                            else
6956                             if (pagination) {
6957                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6958                            }
6959    
6960                            String sql = query.toString();
6961    
6962                            Session session = null;
6963    
6964                            try {
6965                                    session = openSession();
6966    
6967                                    Query q = session.createQuery(sql);
6968    
6969                                    QueryPos qPos = QueryPos.getInstance(q);
6970    
6971                                    qPos.add(companyId);
6972    
6973                                    qPos.add(status);
6974    
6975                                    if (!pagination) {
6976                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6977                                                            start, end, false);
6978    
6979                                            Collections.sort(list);
6980    
6981                                            list = new UnmodifiableList<MBMessage>(list);
6982                                    }
6983                                    else {
6984                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6985                                                            start, end);
6986                                    }
6987    
6988                                    cacheResult(list);
6989    
6990                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6991                            }
6992                            catch (Exception e) {
6993                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6994    
6995                                    throw processException(e);
6996                            }
6997                            finally {
6998                                    closeSession(session);
6999                            }
7000                    }
7001    
7002                    return list;
7003            }
7004    
7005            /**
7006             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7007             *
7008             * @param companyId the company ID
7009             * @param status the status
7010             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7011             * @return the first matching message-boards message
7012             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7013             * @throws SystemException if a system exception occurred
7014             */
7015            public MBMessage findByC_S_First(long companyId, int status,
7016                    OrderByComparator orderByComparator)
7017                    throws NoSuchMessageException, SystemException {
7018                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7019                                    orderByComparator);
7020    
7021                    if (mbMessage != null) {
7022                            return mbMessage;
7023                    }
7024    
7025                    StringBundler msg = new StringBundler(6);
7026    
7027                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7028    
7029                    msg.append("companyId=");
7030                    msg.append(companyId);
7031    
7032                    msg.append(", status=");
7033                    msg.append(status);
7034    
7035                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7036    
7037                    throw new NoSuchMessageException(msg.toString());
7038            }
7039    
7040            /**
7041             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7042             *
7043             * @param companyId the company ID
7044             * @param status the status
7045             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7046             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7047             * @throws SystemException if a system exception occurred
7048             */
7049            public MBMessage fetchByC_S_First(long companyId, int status,
7050                    OrderByComparator orderByComparator) throws SystemException {
7051                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7052                                    orderByComparator);
7053    
7054                    if (!list.isEmpty()) {
7055                            return list.get(0);
7056                    }
7057    
7058                    return null;
7059            }
7060    
7061            /**
7062             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7063             *
7064             * @param companyId the company ID
7065             * @param status the status
7066             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7067             * @return the last matching message-boards message
7068             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7069             * @throws SystemException if a system exception occurred
7070             */
7071            public MBMessage findByC_S_Last(long companyId, int status,
7072                    OrderByComparator orderByComparator)
7073                    throws NoSuchMessageException, SystemException {
7074                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7075                                    orderByComparator);
7076    
7077                    if (mbMessage != null) {
7078                            return mbMessage;
7079                    }
7080    
7081                    StringBundler msg = new StringBundler(6);
7082    
7083                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7084    
7085                    msg.append("companyId=");
7086                    msg.append(companyId);
7087    
7088                    msg.append(", status=");
7089                    msg.append(status);
7090    
7091                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7092    
7093                    throw new NoSuchMessageException(msg.toString());
7094            }
7095    
7096            /**
7097             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7098             *
7099             * @param companyId the company ID
7100             * @param status the status
7101             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7102             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7103             * @throws SystemException if a system exception occurred
7104             */
7105            public MBMessage fetchByC_S_Last(long companyId, int status,
7106                    OrderByComparator orderByComparator) throws SystemException {
7107                    int count = countByC_S(companyId, status);
7108    
7109                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7110                                    orderByComparator);
7111    
7112                    if (!list.isEmpty()) {
7113                            return list.get(0);
7114                    }
7115    
7116                    return null;
7117            }
7118    
7119            /**
7120             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7121             *
7122             * @param messageId the primary key of the current message-boards message
7123             * @param companyId the company ID
7124             * @param status the status
7125             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7126             * @return the previous, current, and next message-boards message
7127             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7128             * @throws SystemException if a system exception occurred
7129             */
7130            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7131                    int status, OrderByComparator orderByComparator)
7132                    throws NoSuchMessageException, SystemException {
7133                    MBMessage mbMessage = findByPrimaryKey(messageId);
7134    
7135                    Session session = null;
7136    
7137                    try {
7138                            session = openSession();
7139    
7140                            MBMessage[] array = new MBMessageImpl[3];
7141    
7142                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7143                                            status, orderByComparator, true);
7144    
7145                            array[1] = mbMessage;
7146    
7147                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7148                                            status, orderByComparator, false);
7149    
7150                            return array;
7151                    }
7152                    catch (Exception e) {
7153                            throw processException(e);
7154                    }
7155                    finally {
7156                            closeSession(session);
7157                    }
7158            }
7159    
7160            protected MBMessage getByC_S_PrevAndNext(Session session,
7161                    MBMessage mbMessage, long companyId, int status,
7162                    OrderByComparator orderByComparator, boolean previous) {
7163                    StringBundler query = null;
7164    
7165                    if (orderByComparator != null) {
7166                            query = new StringBundler(6 +
7167                                            (orderByComparator.getOrderByFields().length * 6));
7168                    }
7169                    else {
7170                            query = new StringBundler(3);
7171                    }
7172    
7173                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7174    
7175                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7176    
7177                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7178    
7179                    if (orderByComparator != null) {
7180                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7181    
7182                            if (orderByConditionFields.length > 0) {
7183                                    query.append(WHERE_AND);
7184                            }
7185    
7186                            for (int i = 0; i < orderByConditionFields.length; i++) {
7187                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7188                                    query.append(orderByConditionFields[i]);
7189    
7190                                    if ((i + 1) < orderByConditionFields.length) {
7191                                            if (orderByComparator.isAscending() ^ previous) {
7192                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7193                                            }
7194                                            else {
7195                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7196                                            }
7197                                    }
7198                                    else {
7199                                            if (orderByComparator.isAscending() ^ previous) {
7200                                                    query.append(WHERE_GREATER_THAN);
7201                                            }
7202                                            else {
7203                                                    query.append(WHERE_LESSER_THAN);
7204                                            }
7205                                    }
7206                            }
7207    
7208                            query.append(ORDER_BY_CLAUSE);
7209    
7210                            String[] orderByFields = orderByComparator.getOrderByFields();
7211    
7212                            for (int i = 0; i < orderByFields.length; i++) {
7213                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7214                                    query.append(orderByFields[i]);
7215    
7216                                    if ((i + 1) < orderByFields.length) {
7217                                            if (orderByComparator.isAscending() ^ previous) {
7218                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7219                                            }
7220                                            else {
7221                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7222                                            }
7223                                    }
7224                                    else {
7225                                            if (orderByComparator.isAscending() ^ previous) {
7226                                                    query.append(ORDER_BY_ASC);
7227                                            }
7228                                            else {
7229                                                    query.append(ORDER_BY_DESC);
7230                                            }
7231                                    }
7232                            }
7233                    }
7234                    else {
7235                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7236                    }
7237    
7238                    String sql = query.toString();
7239    
7240                    Query q = session.createQuery(sql);
7241    
7242                    q.setFirstResult(0);
7243                    q.setMaxResults(2);
7244    
7245                    QueryPos qPos = QueryPos.getInstance(q);
7246    
7247                    qPos.add(companyId);
7248    
7249                    qPos.add(status);
7250    
7251                    if (orderByComparator != null) {
7252                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7253    
7254                            for (Object value : values) {
7255                                    qPos.add(value);
7256                            }
7257                    }
7258    
7259                    List<MBMessage> list = q.list();
7260    
7261                    if (list.size() == 2) {
7262                            return list.get(1);
7263                    }
7264                    else {
7265                            return null;
7266                    }
7267            }
7268    
7269            /**
7270             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7271             *
7272             * @param companyId the company ID
7273             * @param status the status
7274             * @throws SystemException if a system exception occurred
7275             */
7276            public void removeByC_S(long companyId, int status)
7277                    throws SystemException {
7278                    for (MBMessage mbMessage : findByC_S(companyId, status,
7279                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7280                            remove(mbMessage);
7281                    }
7282            }
7283    
7284            /**
7285             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7286             *
7287             * @param companyId the company ID
7288             * @param status the status
7289             * @return the number of matching message-boards messages
7290             * @throws SystemException if a system exception occurred
7291             */
7292            public int countByC_S(long companyId, int status) throws SystemException {
7293                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7294    
7295                    Object[] finderArgs = new Object[] { companyId, status };
7296    
7297                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7298                                    this);
7299    
7300                    if (count == null) {
7301                            StringBundler query = new StringBundler(3);
7302    
7303                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7304    
7305                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7306    
7307                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7308    
7309                            String sql = query.toString();
7310    
7311                            Session session = null;
7312    
7313                            try {
7314                                    session = openSession();
7315    
7316                                    Query q = session.createQuery(sql);
7317    
7318                                    QueryPos qPos = QueryPos.getInstance(q);
7319    
7320                                    qPos.add(companyId);
7321    
7322                                    qPos.add(status);
7323    
7324                                    count = (Long)q.uniqueResult();
7325    
7326                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7327                            }
7328                            catch (Exception e) {
7329                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7330    
7331                                    throw processException(e);
7332                            }
7333                            finally {
7334                                    closeSession(session);
7335                            }
7336                    }
7337    
7338                    return count.intValue();
7339            }
7340    
7341            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7342            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7343            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7344                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7345                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7346                            new String[] {
7347                                    Long.class.getName(), Long.class.getName(),
7348                                    
7349                            Integer.class.getName(), Integer.class.getName(),
7350                                    OrderByComparator.class.getName()
7351                            });
7352            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7353                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7354                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7355                            new String[] { Long.class.getName(), Long.class.getName() },
7356                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7357                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7358                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7359            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7360                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7361                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7362                            new String[] { Long.class.getName(), Long.class.getName() });
7363            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7364                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7365                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7366                            new String[] { Long.class.getName(), Long.class.getName() });
7367    
7368            /**
7369             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7370             *
7371             * @param userId the user ID
7372             * @param classNameId the class name ID
7373             * @return the matching message-boards messages
7374             * @throws SystemException if a system exception occurred
7375             */
7376            public List<MBMessage> findByU_C(long userId, long classNameId)
7377                    throws SystemException {
7378                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7379                            QueryUtil.ALL_POS, null);
7380            }
7381    
7382            /**
7383             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7384             *
7385             * <p>
7386             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7387             * </p>
7388             *
7389             * @param userId the user ID
7390             * @param classNameId the class name ID
7391             * @param start the lower bound of the range of message-boards messages
7392             * @param end the upper bound of the range of message-boards messages (not inclusive)
7393             * @return the range of matching message-boards messages
7394             * @throws SystemException if a system exception occurred
7395             */
7396            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7397                    int end) throws SystemException {
7398                    return findByU_C(userId, classNameId, start, end, null);
7399            }
7400    
7401            /**
7402             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7403             *
7404             * <p>
7405             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7406             * </p>
7407             *
7408             * @param userId the user ID
7409             * @param classNameId the class name ID
7410             * @param start the lower bound of the range of message-boards messages
7411             * @param end the upper bound of the range of message-boards messages (not inclusive)
7412             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7413             * @return the ordered range of matching message-boards messages
7414             * @throws SystemException if a system exception occurred
7415             */
7416            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7417                    int end, OrderByComparator orderByComparator) throws SystemException {
7418                    boolean pagination = true;
7419                    FinderPath finderPath = null;
7420                    Object[] finderArgs = null;
7421    
7422                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7423                                    (orderByComparator == null)) {
7424                            pagination = false;
7425                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7426                            finderArgs = new Object[] { userId, classNameId };
7427                    }
7428                    else {
7429                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7430                            finderArgs = new Object[] {
7431                                            userId, classNameId,
7432                                            
7433                                            start, end, orderByComparator
7434                                    };
7435                    }
7436    
7437                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7438                                    finderArgs, this);
7439    
7440                    if ((list != null) && !list.isEmpty()) {
7441                            for (MBMessage mbMessage : list) {
7442                                    if ((userId != mbMessage.getUserId()) ||
7443                                                    (classNameId != mbMessage.getClassNameId())) {
7444                                            list = null;
7445    
7446                                            break;
7447                                    }
7448                            }
7449                    }
7450    
7451                    if (list == null) {
7452                            StringBundler query = null;
7453    
7454                            if (orderByComparator != null) {
7455                                    query = new StringBundler(4 +
7456                                                    (orderByComparator.getOrderByFields().length * 3));
7457                            }
7458                            else {
7459                                    query = new StringBundler(4);
7460                            }
7461    
7462                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7463    
7464                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7465    
7466                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7467    
7468                            if (orderByComparator != null) {
7469                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7470                                            orderByComparator);
7471                            }
7472                            else
7473                             if (pagination) {
7474                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7475                            }
7476    
7477                            String sql = query.toString();
7478    
7479                            Session session = null;
7480    
7481                            try {
7482                                    session = openSession();
7483    
7484                                    Query q = session.createQuery(sql);
7485    
7486                                    QueryPos qPos = QueryPos.getInstance(q);
7487    
7488                                    qPos.add(userId);
7489    
7490                                    qPos.add(classNameId);
7491    
7492                                    if (!pagination) {
7493                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7494                                                            start, end, false);
7495    
7496                                            Collections.sort(list);
7497    
7498                                            list = new UnmodifiableList<MBMessage>(list);
7499                                    }
7500                                    else {
7501                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7502                                                            start, end);
7503                                    }
7504    
7505                                    cacheResult(list);
7506    
7507                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7508                            }
7509                            catch (Exception e) {
7510                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7511    
7512                                    throw processException(e);
7513                            }
7514                            finally {
7515                                    closeSession(session);
7516                            }
7517                    }
7518    
7519                    return list;
7520            }
7521    
7522            /**
7523             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7524             *
7525             * @param userId the user ID
7526             * @param classNameId the class name ID
7527             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7528             * @return the first matching message-boards message
7529             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7530             * @throws SystemException if a system exception occurred
7531             */
7532            public MBMessage findByU_C_First(long userId, long classNameId,
7533                    OrderByComparator orderByComparator)
7534                    throws NoSuchMessageException, SystemException {
7535                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7536                                    orderByComparator);
7537    
7538                    if (mbMessage != null) {
7539                            return mbMessage;
7540                    }
7541    
7542                    StringBundler msg = new StringBundler(6);
7543    
7544                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7545    
7546                    msg.append("userId=");
7547                    msg.append(userId);
7548    
7549                    msg.append(", classNameId=");
7550                    msg.append(classNameId);
7551    
7552                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7553    
7554                    throw new NoSuchMessageException(msg.toString());
7555            }
7556    
7557            /**
7558             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7559             *
7560             * @param userId the user ID
7561             * @param classNameId the class name ID
7562             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7563             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7564             * @throws SystemException if a system exception occurred
7565             */
7566            public MBMessage fetchByU_C_First(long userId, long classNameId,
7567                    OrderByComparator orderByComparator) throws SystemException {
7568                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7569                                    orderByComparator);
7570    
7571                    if (!list.isEmpty()) {
7572                            return list.get(0);
7573                    }
7574    
7575                    return null;
7576            }
7577    
7578            /**
7579             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7580             *
7581             * @param userId the user ID
7582             * @param classNameId the class name ID
7583             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7584             * @return the last matching message-boards message
7585             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7586             * @throws SystemException if a system exception occurred
7587             */
7588            public MBMessage findByU_C_Last(long userId, long classNameId,
7589                    OrderByComparator orderByComparator)
7590                    throws NoSuchMessageException, SystemException {
7591                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7592                                    orderByComparator);
7593    
7594                    if (mbMessage != null) {
7595                            return mbMessage;
7596                    }
7597    
7598                    StringBundler msg = new StringBundler(6);
7599    
7600                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7601    
7602                    msg.append("userId=");
7603                    msg.append(userId);
7604    
7605                    msg.append(", classNameId=");
7606                    msg.append(classNameId);
7607    
7608                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7609    
7610                    throw new NoSuchMessageException(msg.toString());
7611            }
7612    
7613            /**
7614             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7615             *
7616             * @param userId the user ID
7617             * @param classNameId the class name ID
7618             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7619             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7620             * @throws SystemException if a system exception occurred
7621             */
7622            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7623                    OrderByComparator orderByComparator) throws SystemException {
7624                    int count = countByU_C(userId, classNameId);
7625    
7626                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7627                                    orderByComparator);
7628    
7629                    if (!list.isEmpty()) {
7630                            return list.get(0);
7631                    }
7632    
7633                    return null;
7634            }
7635    
7636            /**
7637             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7638             *
7639             * @param messageId the primary key of the current message-boards message
7640             * @param userId the user ID
7641             * @param classNameId the class name ID
7642             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7643             * @return the previous, current, and next message-boards message
7644             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7645             * @throws SystemException if a system exception occurred
7646             */
7647            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7648                    long classNameId, OrderByComparator orderByComparator)
7649                    throws NoSuchMessageException, SystemException {
7650                    MBMessage mbMessage = findByPrimaryKey(messageId);
7651    
7652                    Session session = null;
7653    
7654                    try {
7655                            session = openSession();
7656    
7657                            MBMessage[] array = new MBMessageImpl[3];
7658    
7659                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7660                                            classNameId, orderByComparator, true);
7661    
7662                            array[1] = mbMessage;
7663    
7664                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7665                                            classNameId, orderByComparator, false);
7666    
7667                            return array;
7668                    }
7669                    catch (Exception e) {
7670                            throw processException(e);
7671                    }
7672                    finally {
7673                            closeSession(session);
7674                    }
7675            }
7676    
7677            protected MBMessage getByU_C_PrevAndNext(Session session,
7678                    MBMessage mbMessage, long userId, long classNameId,
7679                    OrderByComparator orderByComparator, boolean previous) {
7680                    StringBundler query = null;
7681    
7682                    if (orderByComparator != null) {
7683                            query = new StringBundler(6 +
7684                                            (orderByComparator.getOrderByFields().length * 6));
7685                    }
7686                    else {
7687                            query = new StringBundler(3);
7688                    }
7689    
7690                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7691    
7692                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7693    
7694                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7695    
7696                    if (orderByComparator != null) {
7697                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7698    
7699                            if (orderByConditionFields.length > 0) {
7700                                    query.append(WHERE_AND);
7701                            }
7702    
7703                            for (int i = 0; i < orderByConditionFields.length; i++) {
7704                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7705                                    query.append(orderByConditionFields[i]);
7706    
7707                                    if ((i + 1) < orderByConditionFields.length) {
7708                                            if (orderByComparator.isAscending() ^ previous) {
7709                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7710                                            }
7711                                            else {
7712                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7713                                            }
7714                                    }
7715                                    else {
7716                                            if (orderByComparator.isAscending() ^ previous) {
7717                                                    query.append(WHERE_GREATER_THAN);
7718                                            }
7719                                            else {
7720                                                    query.append(WHERE_LESSER_THAN);
7721                                            }
7722                                    }
7723                            }
7724    
7725                            query.append(ORDER_BY_CLAUSE);
7726    
7727                            String[] orderByFields = orderByComparator.getOrderByFields();
7728    
7729                            for (int i = 0; i < orderByFields.length; i++) {
7730                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7731                                    query.append(orderByFields[i]);
7732    
7733                                    if ((i + 1) < orderByFields.length) {
7734                                            if (orderByComparator.isAscending() ^ previous) {
7735                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7736                                            }
7737                                            else {
7738                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7739                                            }
7740                                    }
7741                                    else {
7742                                            if (orderByComparator.isAscending() ^ previous) {
7743                                                    query.append(ORDER_BY_ASC);
7744                                            }
7745                                            else {
7746                                                    query.append(ORDER_BY_DESC);
7747                                            }
7748                                    }
7749                            }
7750                    }
7751                    else {
7752                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7753                    }
7754    
7755                    String sql = query.toString();
7756    
7757                    Query q = session.createQuery(sql);
7758    
7759                    q.setFirstResult(0);
7760                    q.setMaxResults(2);
7761    
7762                    QueryPos qPos = QueryPos.getInstance(q);
7763    
7764                    qPos.add(userId);
7765    
7766                    qPos.add(classNameId);
7767    
7768                    if (orderByComparator != null) {
7769                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7770    
7771                            for (Object value : values) {
7772                                    qPos.add(value);
7773                            }
7774                    }
7775    
7776                    List<MBMessage> list = q.list();
7777    
7778                    if (list.size() == 2) {
7779                            return list.get(1);
7780                    }
7781                    else {
7782                            return null;
7783                    }
7784            }
7785    
7786            /**
7787             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7788             *
7789             * <p>
7790             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7791             * </p>
7792             *
7793             * @param userId the user ID
7794             * @param classNameIds the class name IDs
7795             * @return the matching message-boards messages
7796             * @throws SystemException if a system exception occurred
7797             */
7798            public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7799                    throws SystemException {
7800                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7801                            QueryUtil.ALL_POS, null);
7802            }
7803    
7804            /**
7805             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7806             *
7807             * <p>
7808             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7809             * </p>
7810             *
7811             * @param userId the user ID
7812             * @param classNameIds the class name IDs
7813             * @param start the lower bound of the range of message-boards messages
7814             * @param end the upper bound of the range of message-boards messages (not inclusive)
7815             * @return the range of matching message-boards messages
7816             * @throws SystemException if a system exception occurred
7817             */
7818            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7819                    int start, int end) throws SystemException {
7820                    return findByU_C(userId, classNameIds, start, end, null);
7821            }
7822    
7823            /**
7824             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7825             *
7826             * <p>
7827             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
7828             * </p>
7829             *
7830             * @param userId the user ID
7831             * @param classNameIds the class name IDs
7832             * @param start the lower bound of the range of message-boards messages
7833             * @param end the upper bound of the range of message-boards messages (not inclusive)
7834             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7835             * @return the ordered range of matching message-boards messages
7836             * @throws SystemException if a system exception occurred
7837             */
7838            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7839                    int start, int end, OrderByComparator orderByComparator)
7840                    throws SystemException {
7841                    if ((classNameIds != null) && (classNameIds.length == 1)) {
7842                            return findByU_C(userId, classNameIds[0], start, end,
7843                                    orderByComparator);
7844                    }
7845    
7846                    boolean pagination = true;
7847                    Object[] finderArgs = null;
7848    
7849                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7850                                    (orderByComparator == null)) {
7851                            pagination = false;
7852                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7853                    }
7854                    else {
7855                            finderArgs = new Object[] {
7856                                            userId, StringUtil.merge(classNameIds),
7857                                            
7858                                            start, end, orderByComparator
7859                                    };
7860                    }
7861    
7862                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7863                                    finderArgs, this);
7864    
7865                    if ((list != null) && !list.isEmpty()) {
7866                            for (MBMessage mbMessage : list) {
7867                                    if ((userId != mbMessage.getUserId()) ||
7868                                                    !ArrayUtil.contains(classNameIds,
7869                                                            mbMessage.getClassNameId())) {
7870                                            list = null;
7871    
7872                                            break;
7873                                    }
7874                            }
7875                    }
7876    
7877                    if (list == null) {
7878                            StringBundler query = new StringBundler();
7879    
7880                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7881    
7882                            boolean conjunctionable = false;
7883    
7884                            if (conjunctionable) {
7885                                    query.append(WHERE_AND);
7886                            }
7887    
7888                            query.append(_FINDER_COLUMN_U_C_USERID_5);
7889    
7890                            conjunctionable = true;
7891    
7892                            if ((classNameIds == null) || (classNameIds.length > 0)) {
7893                                    if (conjunctionable) {
7894                                            query.append(WHERE_AND);
7895                                    }
7896    
7897                                    query.append(StringPool.OPEN_PARENTHESIS);
7898    
7899                                    for (int i = 0; i < classNameIds.length; i++) {
7900                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
7901    
7902                                            if ((i + 1) < classNameIds.length) {
7903                                                    query.append(WHERE_OR);
7904                                            }
7905                                    }
7906    
7907                                    query.append(StringPool.CLOSE_PARENTHESIS);
7908    
7909                                    conjunctionable = true;
7910                            }
7911    
7912                            if (orderByComparator != null) {
7913                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7914                                            orderByComparator);
7915                            }
7916                            else
7917                             if (pagination) {
7918                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7919                            }
7920    
7921                            String sql = query.toString();
7922    
7923                            Session session = null;
7924    
7925                            try {
7926                                    session = openSession();
7927    
7928                                    Query q = session.createQuery(sql);
7929    
7930                                    QueryPos qPos = QueryPos.getInstance(q);
7931    
7932                                    qPos.add(userId);
7933    
7934                                    if (classNameIds != null) {
7935                                            qPos.add(classNameIds);
7936                                    }
7937    
7938                                    if (!pagination) {
7939                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7940                                                            start, end, false);
7941    
7942                                            Collections.sort(list);
7943    
7944                                            list = new UnmodifiableList<MBMessage>(list);
7945                                    }
7946                                    else {
7947                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7948                                                            start, end);
7949                                    }
7950    
7951                                    cacheResult(list);
7952    
7953                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7954                                            finderArgs, list);
7955                            }
7956                            catch (Exception e) {
7957                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7958                                            finderArgs);
7959    
7960                                    throw processException(e);
7961                            }
7962                            finally {
7963                                    closeSession(session);
7964                            }
7965                    }
7966    
7967                    return list;
7968            }
7969    
7970            /**
7971             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
7972             *
7973             * @param userId the user ID
7974             * @param classNameId the class name ID
7975             * @throws SystemException if a system exception occurred
7976             */
7977            public void removeByU_C(long userId, long classNameId)
7978                    throws SystemException {
7979                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
7980                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7981                            remove(mbMessage);
7982                    }
7983            }
7984    
7985            /**
7986             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
7987             *
7988             * @param userId the user ID
7989             * @param classNameId the class name ID
7990             * @return the number of matching message-boards messages
7991             * @throws SystemException if a system exception occurred
7992             */
7993            public int countByU_C(long userId, long classNameId)
7994                    throws SystemException {
7995                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
7996    
7997                    Object[] finderArgs = new Object[] { userId, classNameId };
7998    
7999                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8000                                    this);
8001    
8002                    if (count == null) {
8003                            StringBundler query = new StringBundler(3);
8004    
8005                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8006    
8007                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8008    
8009                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8010    
8011                            String sql = query.toString();
8012    
8013                            Session session = null;
8014    
8015                            try {
8016                                    session = openSession();
8017    
8018                                    Query q = session.createQuery(sql);
8019    
8020                                    QueryPos qPos = QueryPos.getInstance(q);
8021    
8022                                    qPos.add(userId);
8023    
8024                                    qPos.add(classNameId);
8025    
8026                                    count = (Long)q.uniqueResult();
8027    
8028                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8029                            }
8030                            catch (Exception e) {
8031                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8032    
8033                                    throw processException(e);
8034                            }
8035                            finally {
8036                                    closeSession(session);
8037                            }
8038                    }
8039    
8040                    return count.intValue();
8041            }
8042    
8043            /**
8044             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8045             *
8046             * @param userId the user ID
8047             * @param classNameIds the class name IDs
8048             * @return the number of matching message-boards messages
8049             * @throws SystemException if a system exception occurred
8050             */
8051            public int countByU_C(long userId, long[] classNameIds)
8052                    throws SystemException {
8053                    Object[] finderArgs = new Object[] {
8054                                    userId, StringUtil.merge(classNameIds)
8055                            };
8056    
8057                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8058                                    finderArgs, this);
8059    
8060                    if (count == null) {
8061                            StringBundler query = new StringBundler();
8062    
8063                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8064    
8065                            boolean conjunctionable = false;
8066    
8067                            if (conjunctionable) {
8068                                    query.append(WHERE_AND);
8069                            }
8070    
8071                            query.append(_FINDER_COLUMN_U_C_USERID_5);
8072    
8073                            conjunctionable = true;
8074    
8075                            if ((classNameIds == null) || (classNameIds.length > 0)) {
8076                                    if (conjunctionable) {
8077                                            query.append(WHERE_AND);
8078                                    }
8079    
8080                                    query.append(StringPool.OPEN_PARENTHESIS);
8081    
8082                                    for (int i = 0; i < classNameIds.length; i++) {
8083                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
8084    
8085                                            if ((i + 1) < classNameIds.length) {
8086                                                    query.append(WHERE_OR);
8087                                            }
8088                                    }
8089    
8090                                    query.append(StringPool.CLOSE_PARENTHESIS);
8091    
8092                                    conjunctionable = true;
8093                            }
8094    
8095                            String sql = query.toString();
8096    
8097                            Session session = null;
8098    
8099                            try {
8100                                    session = openSession();
8101    
8102                                    Query q = session.createQuery(sql);
8103    
8104                                    QueryPos qPos = QueryPos.getInstance(q);
8105    
8106                                    qPos.add(userId);
8107    
8108                                    if (classNameIds != null) {
8109                                            qPos.add(classNameIds);
8110                                    }
8111    
8112                                    count = (Long)q.uniqueResult();
8113    
8114                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8115                                            finderArgs, count);
8116                            }
8117                            catch (Exception e) {
8118                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8119                                            finderArgs);
8120    
8121                                    throw processException(e);
8122                            }
8123                            finally {
8124                                    closeSession(session);
8125                            }
8126                    }
8127    
8128                    return count.intValue();
8129            }
8130    
8131            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8132            private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
8133                    removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
8134            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8135            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
8136                    removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
8137            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8138                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8139                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8140                            new String[] {
8141                                    Long.class.getName(), Long.class.getName(),
8142                                    
8143                            Integer.class.getName(), Integer.class.getName(),
8144                                    OrderByComparator.class.getName()
8145                            });
8146            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8147                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8148                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8149                            new String[] { Long.class.getName(), Long.class.getName() },
8150                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8151                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8152                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8153            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8154                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8155                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8156                            new String[] { Long.class.getName(), Long.class.getName() });
8157    
8158            /**
8159             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8160             *
8161             * @param classNameId the class name ID
8162             * @param classPK the class p k
8163             * @return the matching message-boards messages
8164             * @throws SystemException if a system exception occurred
8165             */
8166            public List<MBMessage> findByC_C(long classNameId, long classPK)
8167                    throws SystemException {
8168                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8169                            QueryUtil.ALL_POS, null);
8170            }
8171    
8172            /**
8173             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8174             *
8175             * <p>
8176             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8177             * </p>
8178             *
8179             * @param classNameId the class name ID
8180             * @param classPK the class p k
8181             * @param start the lower bound of the range of message-boards messages
8182             * @param end the upper bound of the range of message-boards messages (not inclusive)
8183             * @return the range of matching message-boards messages
8184             * @throws SystemException if a system exception occurred
8185             */
8186            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8187                    int end) throws SystemException {
8188                    return findByC_C(classNameId, classPK, start, end, null);
8189            }
8190    
8191            /**
8192             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8193             *
8194             * <p>
8195             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8196             * </p>
8197             *
8198             * @param classNameId the class name ID
8199             * @param classPK the class p k
8200             * @param start the lower bound of the range of message-boards messages
8201             * @param end the upper bound of the range of message-boards messages (not inclusive)
8202             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8203             * @return the ordered range of matching message-boards messages
8204             * @throws SystemException if a system exception occurred
8205             */
8206            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8207                    int end, OrderByComparator orderByComparator) throws SystemException {
8208                    boolean pagination = true;
8209                    FinderPath finderPath = null;
8210                    Object[] finderArgs = null;
8211    
8212                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8213                                    (orderByComparator == null)) {
8214                            pagination = false;
8215                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8216                            finderArgs = new Object[] { classNameId, classPK };
8217                    }
8218                    else {
8219                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8220                            finderArgs = new Object[] {
8221                                            classNameId, classPK,
8222                                            
8223                                            start, end, orderByComparator
8224                                    };
8225                    }
8226    
8227                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8228                                    finderArgs, this);
8229    
8230                    if ((list != null) && !list.isEmpty()) {
8231                            for (MBMessage mbMessage : list) {
8232                                    if ((classNameId != mbMessage.getClassNameId()) ||
8233                                                    (classPK != mbMessage.getClassPK())) {
8234                                            list = null;
8235    
8236                                            break;
8237                                    }
8238                            }
8239                    }
8240    
8241                    if (list == null) {
8242                            StringBundler query = null;
8243    
8244                            if (orderByComparator != null) {
8245                                    query = new StringBundler(4 +
8246                                                    (orderByComparator.getOrderByFields().length * 3));
8247                            }
8248                            else {
8249                                    query = new StringBundler(4);
8250                            }
8251    
8252                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8253    
8254                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8255    
8256                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8257    
8258                            if (orderByComparator != null) {
8259                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8260                                            orderByComparator);
8261                            }
8262                            else
8263                             if (pagination) {
8264                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8265                            }
8266    
8267                            String sql = query.toString();
8268    
8269                            Session session = null;
8270    
8271                            try {
8272                                    session = openSession();
8273    
8274                                    Query q = session.createQuery(sql);
8275    
8276                                    QueryPos qPos = QueryPos.getInstance(q);
8277    
8278                                    qPos.add(classNameId);
8279    
8280                                    qPos.add(classPK);
8281    
8282                                    if (!pagination) {
8283                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8284                                                            start, end, false);
8285    
8286                                            Collections.sort(list);
8287    
8288                                            list = new UnmodifiableList<MBMessage>(list);
8289                                    }
8290                                    else {
8291                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8292                                                            start, end);
8293                                    }
8294    
8295                                    cacheResult(list);
8296    
8297                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8298                            }
8299                            catch (Exception e) {
8300                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8301    
8302                                    throw processException(e);
8303                            }
8304                            finally {
8305                                    closeSession(session);
8306                            }
8307                    }
8308    
8309                    return list;
8310            }
8311    
8312            /**
8313             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8314             *
8315             * @param classNameId the class name ID
8316             * @param classPK the class p k
8317             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8318             * @return the first matching message-boards message
8319             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8320             * @throws SystemException if a system exception occurred
8321             */
8322            public MBMessage findByC_C_First(long classNameId, long classPK,
8323                    OrderByComparator orderByComparator)
8324                    throws NoSuchMessageException, SystemException {
8325                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8326                                    orderByComparator);
8327    
8328                    if (mbMessage != null) {
8329                            return mbMessage;
8330                    }
8331    
8332                    StringBundler msg = new StringBundler(6);
8333    
8334                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8335    
8336                    msg.append("classNameId=");
8337                    msg.append(classNameId);
8338    
8339                    msg.append(", classPK=");
8340                    msg.append(classPK);
8341    
8342                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8343    
8344                    throw new NoSuchMessageException(msg.toString());
8345            }
8346    
8347            /**
8348             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8349             *
8350             * @param classNameId the class name ID
8351             * @param classPK the class p k
8352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8353             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8354             * @throws SystemException if a system exception occurred
8355             */
8356            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8357                    OrderByComparator orderByComparator) throws SystemException {
8358                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8359                                    orderByComparator);
8360    
8361                    if (!list.isEmpty()) {
8362                            return list.get(0);
8363                    }
8364    
8365                    return null;
8366            }
8367    
8368            /**
8369             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8370             *
8371             * @param classNameId the class name ID
8372             * @param classPK the class p k
8373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8374             * @return the last matching message-boards message
8375             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8376             * @throws SystemException if a system exception occurred
8377             */
8378            public MBMessage findByC_C_Last(long classNameId, long classPK,
8379                    OrderByComparator orderByComparator)
8380                    throws NoSuchMessageException, SystemException {
8381                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8382                                    orderByComparator);
8383    
8384                    if (mbMessage != null) {
8385                            return mbMessage;
8386                    }
8387    
8388                    StringBundler msg = new StringBundler(6);
8389    
8390                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8391    
8392                    msg.append("classNameId=");
8393                    msg.append(classNameId);
8394    
8395                    msg.append(", classPK=");
8396                    msg.append(classPK);
8397    
8398                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8399    
8400                    throw new NoSuchMessageException(msg.toString());
8401            }
8402    
8403            /**
8404             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8405             *
8406             * @param classNameId the class name ID
8407             * @param classPK the class p k
8408             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8409             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8410             * @throws SystemException if a system exception occurred
8411             */
8412            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8413                    OrderByComparator orderByComparator) throws SystemException {
8414                    int count = countByC_C(classNameId, classPK);
8415    
8416                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8417                                    count, orderByComparator);
8418    
8419                    if (!list.isEmpty()) {
8420                            return list.get(0);
8421                    }
8422    
8423                    return null;
8424            }
8425    
8426            /**
8427             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8428             *
8429             * @param messageId the primary key of the current message-boards message
8430             * @param classNameId the class name ID
8431             * @param classPK the class p k
8432             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8433             * @return the previous, current, and next message-boards message
8434             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8435             * @throws SystemException if a system exception occurred
8436             */
8437            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8438                    long classPK, OrderByComparator orderByComparator)
8439                    throws NoSuchMessageException, SystemException {
8440                    MBMessage mbMessage = findByPrimaryKey(messageId);
8441    
8442                    Session session = null;
8443    
8444                    try {
8445                            session = openSession();
8446    
8447                            MBMessage[] array = new MBMessageImpl[3];
8448    
8449                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8450                                            classPK, orderByComparator, true);
8451    
8452                            array[1] = mbMessage;
8453    
8454                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8455                                            classPK, orderByComparator, false);
8456    
8457                            return array;
8458                    }
8459                    catch (Exception e) {
8460                            throw processException(e);
8461                    }
8462                    finally {
8463                            closeSession(session);
8464                    }
8465            }
8466    
8467            protected MBMessage getByC_C_PrevAndNext(Session session,
8468                    MBMessage mbMessage, long classNameId, long classPK,
8469                    OrderByComparator orderByComparator, boolean previous) {
8470                    StringBundler query = null;
8471    
8472                    if (orderByComparator != null) {
8473                            query = new StringBundler(6 +
8474                                            (orderByComparator.getOrderByFields().length * 6));
8475                    }
8476                    else {
8477                            query = new StringBundler(3);
8478                    }
8479    
8480                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8481    
8482                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8483    
8484                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8485    
8486                    if (orderByComparator != null) {
8487                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8488    
8489                            if (orderByConditionFields.length > 0) {
8490                                    query.append(WHERE_AND);
8491                            }
8492    
8493                            for (int i = 0; i < orderByConditionFields.length; i++) {
8494                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8495                                    query.append(orderByConditionFields[i]);
8496    
8497                                    if ((i + 1) < orderByConditionFields.length) {
8498                                            if (orderByComparator.isAscending() ^ previous) {
8499                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8500                                            }
8501                                            else {
8502                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8503                                            }
8504                                    }
8505                                    else {
8506                                            if (orderByComparator.isAscending() ^ previous) {
8507                                                    query.append(WHERE_GREATER_THAN);
8508                                            }
8509                                            else {
8510                                                    query.append(WHERE_LESSER_THAN);
8511                                            }
8512                                    }
8513                            }
8514    
8515                            query.append(ORDER_BY_CLAUSE);
8516    
8517                            String[] orderByFields = orderByComparator.getOrderByFields();
8518    
8519                            for (int i = 0; i < orderByFields.length; i++) {
8520                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8521                                    query.append(orderByFields[i]);
8522    
8523                                    if ((i + 1) < orderByFields.length) {
8524                                            if (orderByComparator.isAscending() ^ previous) {
8525                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8526                                            }
8527                                            else {
8528                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8529                                            }
8530                                    }
8531                                    else {
8532                                            if (orderByComparator.isAscending() ^ previous) {
8533                                                    query.append(ORDER_BY_ASC);
8534                                            }
8535                                            else {
8536                                                    query.append(ORDER_BY_DESC);
8537                                            }
8538                                    }
8539                            }
8540                    }
8541                    else {
8542                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8543                    }
8544    
8545                    String sql = query.toString();
8546    
8547                    Query q = session.createQuery(sql);
8548    
8549                    q.setFirstResult(0);
8550                    q.setMaxResults(2);
8551    
8552                    QueryPos qPos = QueryPos.getInstance(q);
8553    
8554                    qPos.add(classNameId);
8555    
8556                    qPos.add(classPK);
8557    
8558                    if (orderByComparator != null) {
8559                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8560    
8561                            for (Object value : values) {
8562                                    qPos.add(value);
8563                            }
8564                    }
8565    
8566                    List<MBMessage> list = q.list();
8567    
8568                    if (list.size() == 2) {
8569                            return list.get(1);
8570                    }
8571                    else {
8572                            return null;
8573                    }
8574            }
8575    
8576            /**
8577             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8578             *
8579             * @param classNameId the class name ID
8580             * @param classPK the class p k
8581             * @throws SystemException if a system exception occurred
8582             */
8583            public void removeByC_C(long classNameId, long classPK)
8584                    throws SystemException {
8585                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8586                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8587                            remove(mbMessage);
8588                    }
8589            }
8590    
8591            /**
8592             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8593             *
8594             * @param classNameId the class name ID
8595             * @param classPK the class p k
8596             * @return the number of matching message-boards messages
8597             * @throws SystemException if a system exception occurred
8598             */
8599            public int countByC_C(long classNameId, long classPK)
8600                    throws SystemException {
8601                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8602    
8603                    Object[] finderArgs = new Object[] { classNameId, classPK };
8604    
8605                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8606                                    this);
8607    
8608                    if (count == null) {
8609                            StringBundler query = new StringBundler(3);
8610    
8611                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8612    
8613                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8614    
8615                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8616    
8617                            String sql = query.toString();
8618    
8619                            Session session = null;
8620    
8621                            try {
8622                                    session = openSession();
8623    
8624                                    Query q = session.createQuery(sql);
8625    
8626                                    QueryPos qPos = QueryPos.getInstance(q);
8627    
8628                                    qPos.add(classNameId);
8629    
8630                                    qPos.add(classPK);
8631    
8632                                    count = (Long)q.uniqueResult();
8633    
8634                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8635                            }
8636                            catch (Exception e) {
8637                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8638    
8639                                    throw processException(e);
8640                            }
8641                            finally {
8642                                    closeSession(session);
8643                            }
8644                    }
8645    
8646                    return count.intValue();
8647            }
8648    
8649            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
8650            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
8651            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8652                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8653                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
8654                            new String[] {
8655                                    Long.class.getName(), Long.class.getName(),
8656                                    
8657                            Integer.class.getName(), Integer.class.getName(),
8658                                    OrderByComparator.class.getName()
8659                            });
8660            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8661                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8662                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
8663                            new String[] { Long.class.getName(), Long.class.getName() },
8664                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
8665                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
8666                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8667            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8668                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8669                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
8670                            new String[] { Long.class.getName(), Long.class.getName() });
8671    
8672            /**
8673             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8674             *
8675             * @param threadId the thread ID
8676             * @param parentMessageId the parent message ID
8677             * @return the matching message-boards messages
8678             * @throws SystemException if a system exception occurred
8679             */
8680            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
8681                    throws SystemException {
8682                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8683                            QueryUtil.ALL_POS, null);
8684            }
8685    
8686            /**
8687             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8688             *
8689             * <p>
8690             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8691             * </p>
8692             *
8693             * @param threadId the thread ID
8694             * @param parentMessageId the parent message ID
8695             * @param start the lower bound of the range of message-boards messages
8696             * @param end the upper bound of the range of message-boards messages (not inclusive)
8697             * @return the range of matching message-boards messages
8698             * @throws SystemException if a system exception occurred
8699             */
8700            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8701                    int start, int end) throws SystemException {
8702                    return findByT_P(threadId, parentMessageId, start, end, null);
8703            }
8704    
8705            /**
8706             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8707             *
8708             * <p>
8709             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
8710             * </p>
8711             *
8712             * @param threadId the thread ID
8713             * @param parentMessageId the parent message ID
8714             * @param start the lower bound of the range of message-boards messages
8715             * @param end the upper bound of the range of message-boards messages (not inclusive)
8716             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8717             * @return the ordered range of matching message-boards messages
8718             * @throws SystemException if a system exception occurred
8719             */
8720            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8721                    int start, int end, OrderByComparator orderByComparator)
8722                    throws SystemException {
8723                    boolean pagination = true;
8724                    FinderPath finderPath = null;
8725                    Object[] finderArgs = null;
8726    
8727                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8728                                    (orderByComparator == null)) {
8729                            pagination = false;
8730                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8731                            finderArgs = new Object[] { threadId, parentMessageId };
8732                    }
8733                    else {
8734                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8735                            finderArgs = new Object[] {
8736                                            threadId, parentMessageId,
8737                                            
8738                                            start, end, orderByComparator
8739                                    };
8740                    }
8741    
8742                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8743                                    finderArgs, this);
8744    
8745                    if ((list != null) && !list.isEmpty()) {
8746                            for (MBMessage mbMessage : list) {
8747                                    if ((threadId != mbMessage.getThreadId()) ||
8748                                                    (parentMessageId != mbMessage.getParentMessageId())) {
8749                                            list = null;
8750    
8751                                            break;
8752                                    }
8753                            }
8754                    }
8755    
8756                    if (list == null) {
8757                            StringBundler query = null;
8758    
8759                            if (orderByComparator != null) {
8760                                    query = new StringBundler(4 +
8761                                                    (orderByComparator.getOrderByFields().length * 3));
8762                            }
8763                            else {
8764                                    query = new StringBundler(4);
8765                            }
8766    
8767                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8768    
8769                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
8770    
8771                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8772    
8773                            if (orderByComparator != null) {
8774                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8775                                            orderByComparator);
8776                            }
8777                            else
8778                             if (pagination) {
8779                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8780                            }
8781    
8782                            String sql = query.toString();
8783    
8784                            Session session = null;
8785    
8786                            try {
8787                                    session = openSession();
8788    
8789                                    Query q = session.createQuery(sql);
8790    
8791                                    QueryPos qPos = QueryPos.getInstance(q);
8792    
8793                                    qPos.add(threadId);
8794    
8795                                    qPos.add(parentMessageId);
8796    
8797                                    if (!pagination) {
8798                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8799                                                            start, end, false);
8800    
8801                                            Collections.sort(list);
8802    
8803                                            list = new UnmodifiableList<MBMessage>(list);
8804                                    }
8805                                    else {
8806                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8807                                                            start, end);
8808                                    }
8809    
8810                                    cacheResult(list);
8811    
8812                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8813                            }
8814                            catch (Exception e) {
8815                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8816    
8817                                    throw processException(e);
8818                            }
8819                            finally {
8820                                    closeSession(session);
8821                            }
8822                    }
8823    
8824                    return list;
8825            }
8826    
8827            /**
8828             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8829             *
8830             * @param threadId the thread ID
8831             * @param parentMessageId the parent message ID
8832             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8833             * @return the first matching message-boards message
8834             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8835             * @throws SystemException if a system exception occurred
8836             */
8837            public MBMessage findByT_P_First(long threadId, long parentMessageId,
8838                    OrderByComparator orderByComparator)
8839                    throws NoSuchMessageException, SystemException {
8840                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
8841                                    orderByComparator);
8842    
8843                    if (mbMessage != null) {
8844                            return mbMessage;
8845                    }
8846    
8847                    StringBundler msg = new StringBundler(6);
8848    
8849                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8850    
8851                    msg.append("threadId=");
8852                    msg.append(threadId);
8853    
8854                    msg.append(", parentMessageId=");
8855                    msg.append(parentMessageId);
8856    
8857                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8858    
8859                    throw new NoSuchMessageException(msg.toString());
8860            }
8861    
8862            /**
8863             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8864             *
8865             * @param threadId the thread ID
8866             * @param parentMessageId the parent message ID
8867             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8868             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8869             * @throws SystemException if a system exception occurred
8870             */
8871            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
8872                    OrderByComparator orderByComparator) throws SystemException {
8873                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
8874                                    orderByComparator);
8875    
8876                    if (!list.isEmpty()) {
8877                            return list.get(0);
8878                    }
8879    
8880                    return null;
8881            }
8882    
8883            /**
8884             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8885             *
8886             * @param threadId the thread ID
8887             * @param parentMessageId the parent message ID
8888             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8889             * @return the last matching message-boards message
8890             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8891             * @throws SystemException if a system exception occurred
8892             */
8893            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
8894                    OrderByComparator orderByComparator)
8895                    throws NoSuchMessageException, SystemException {
8896                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
8897                                    orderByComparator);
8898    
8899                    if (mbMessage != null) {
8900                            return mbMessage;
8901                    }
8902    
8903                    StringBundler msg = new StringBundler(6);
8904    
8905                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8906    
8907                    msg.append("threadId=");
8908                    msg.append(threadId);
8909    
8910                    msg.append(", parentMessageId=");
8911                    msg.append(parentMessageId);
8912    
8913                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8914    
8915                    throw new NoSuchMessageException(msg.toString());
8916            }
8917    
8918            /**
8919             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8920             *
8921             * @param threadId the thread ID
8922             * @param parentMessageId the parent message ID
8923             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8924             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8925             * @throws SystemException if a system exception occurred
8926             */
8927            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
8928                    OrderByComparator orderByComparator) throws SystemException {
8929                    int count = countByT_P(threadId, parentMessageId);
8930    
8931                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
8932                                    count, orderByComparator);
8933    
8934                    if (!list.isEmpty()) {
8935                            return list.get(0);
8936                    }
8937    
8938                    return null;
8939            }
8940    
8941            /**
8942             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8943             *
8944             * @param messageId the primary key of the current message-boards message
8945             * @param threadId the thread ID
8946             * @param parentMessageId the parent message ID
8947             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8948             * @return the previous, current, and next message-boards message
8949             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8950             * @throws SystemException if a system exception occurred
8951             */
8952            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
8953                    long parentMessageId, OrderByComparator orderByComparator)
8954                    throws NoSuchMessageException, SystemException {
8955                    MBMessage mbMessage = findByPrimaryKey(messageId);
8956    
8957                    Session session = null;
8958    
8959                    try {
8960                            session = openSession();
8961    
8962                            MBMessage[] array = new MBMessageImpl[3];
8963    
8964                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8965                                            parentMessageId, orderByComparator, true);
8966    
8967                            array[1] = mbMessage;
8968    
8969                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8970                                            parentMessageId, orderByComparator, false);
8971    
8972                            return array;
8973                    }
8974                    catch (Exception e) {
8975                            throw processException(e);
8976                    }
8977                    finally {
8978                            closeSession(session);
8979                    }
8980            }
8981    
8982            protected MBMessage getByT_P_PrevAndNext(Session session,
8983                    MBMessage mbMessage, long threadId, long parentMessageId,
8984                    OrderByComparator orderByComparator, boolean previous) {
8985                    StringBundler query = null;
8986    
8987                    if (orderByComparator != null) {
8988                            query = new StringBundler(6 +
8989                                            (orderByComparator.getOrderByFields().length * 6));
8990                    }
8991                    else {
8992                            query = new StringBundler(3);
8993                    }
8994    
8995                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8996    
8997                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
8998    
8999                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9000    
9001                    if (orderByComparator != null) {
9002                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9003    
9004                            if (orderByConditionFields.length > 0) {
9005                                    query.append(WHERE_AND);
9006                            }
9007    
9008                            for (int i = 0; i < orderByConditionFields.length; i++) {
9009                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9010                                    query.append(orderByConditionFields[i]);
9011    
9012                                    if ((i + 1) < orderByConditionFields.length) {
9013                                            if (orderByComparator.isAscending() ^ previous) {
9014                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9015                                            }
9016                                            else {
9017                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9018                                            }
9019                                    }
9020                                    else {
9021                                            if (orderByComparator.isAscending() ^ previous) {
9022                                                    query.append(WHERE_GREATER_THAN);
9023                                            }
9024                                            else {
9025                                                    query.append(WHERE_LESSER_THAN);
9026                                            }
9027                                    }
9028                            }
9029    
9030                            query.append(ORDER_BY_CLAUSE);
9031    
9032                            String[] orderByFields = orderByComparator.getOrderByFields();
9033    
9034                            for (int i = 0; i < orderByFields.length; i++) {
9035                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9036                                    query.append(orderByFields[i]);
9037    
9038                                    if ((i + 1) < orderByFields.length) {
9039                                            if (orderByComparator.isAscending() ^ previous) {
9040                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9041                                            }
9042                                            else {
9043                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9044                                            }
9045                                    }
9046                                    else {
9047                                            if (orderByComparator.isAscending() ^ previous) {
9048                                                    query.append(ORDER_BY_ASC);
9049                                            }
9050                                            else {
9051                                                    query.append(ORDER_BY_DESC);
9052                                            }
9053                                    }
9054                            }
9055                    }
9056                    else {
9057                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9058                    }
9059    
9060                    String sql = query.toString();
9061    
9062                    Query q = session.createQuery(sql);
9063    
9064                    q.setFirstResult(0);
9065                    q.setMaxResults(2);
9066    
9067                    QueryPos qPos = QueryPos.getInstance(q);
9068    
9069                    qPos.add(threadId);
9070    
9071                    qPos.add(parentMessageId);
9072    
9073                    if (orderByComparator != null) {
9074                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9075    
9076                            for (Object value : values) {
9077                                    qPos.add(value);
9078                            }
9079                    }
9080    
9081                    List<MBMessage> list = q.list();
9082    
9083                    if (list.size() == 2) {
9084                            return list.get(1);
9085                    }
9086                    else {
9087                            return null;
9088                    }
9089            }
9090    
9091            /**
9092             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9093             *
9094             * @param threadId the thread ID
9095             * @param parentMessageId the parent message ID
9096             * @throws SystemException if a system exception occurred
9097             */
9098            public void removeByT_P(long threadId, long parentMessageId)
9099                    throws SystemException {
9100                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9101                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9102                            remove(mbMessage);
9103                    }
9104            }
9105    
9106            /**
9107             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9108             *
9109             * @param threadId the thread ID
9110             * @param parentMessageId the parent message ID
9111             * @return the number of matching message-boards messages
9112             * @throws SystemException if a system exception occurred
9113             */
9114            public int countByT_P(long threadId, long parentMessageId)
9115                    throws SystemException {
9116                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9117    
9118                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9119    
9120                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9121                                    this);
9122    
9123                    if (count == null) {
9124                            StringBundler query = new StringBundler(3);
9125    
9126                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9127    
9128                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9129    
9130                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9131    
9132                            String sql = query.toString();
9133    
9134                            Session session = null;
9135    
9136                            try {
9137                                    session = openSession();
9138    
9139                                    Query q = session.createQuery(sql);
9140    
9141                                    QueryPos qPos = QueryPos.getInstance(q);
9142    
9143                                    qPos.add(threadId);
9144    
9145                                    qPos.add(parentMessageId);
9146    
9147                                    count = (Long)q.uniqueResult();
9148    
9149                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9150                            }
9151                            catch (Exception e) {
9152                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9153    
9154                                    throw processException(e);
9155                            }
9156                            finally {
9157                                    closeSession(session);
9158                            }
9159                    }
9160    
9161                    return count.intValue();
9162            }
9163    
9164            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9165            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9166            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9167                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9168                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9169                            new String[] {
9170                                    Long.class.getName(), Boolean.class.getName(),
9171                                    
9172                            Integer.class.getName(), Integer.class.getName(),
9173                                    OrderByComparator.class.getName()
9174                            });
9175            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9176                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9177                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9178                            new String[] { Long.class.getName(), Boolean.class.getName() },
9179                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9180                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9181                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9182            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9183                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9184                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9185                            new String[] { Long.class.getName(), Boolean.class.getName() });
9186    
9187            /**
9188             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9189             *
9190             * @param threadId the thread ID
9191             * @param answer the answer
9192             * @return the matching message-boards messages
9193             * @throws SystemException if a system exception occurred
9194             */
9195            public List<MBMessage> findByT_A(long threadId, boolean answer)
9196                    throws SystemException {
9197                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9198                            QueryUtil.ALL_POS, null);
9199            }
9200    
9201            /**
9202             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9203             *
9204             * <p>
9205             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9206             * </p>
9207             *
9208             * @param threadId the thread ID
9209             * @param answer the answer
9210             * @param start the lower bound of the range of message-boards messages
9211             * @param end the upper bound of the range of message-boards messages (not inclusive)
9212             * @return the range of matching message-boards messages
9213             * @throws SystemException if a system exception occurred
9214             */
9215            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9216                    int end) throws SystemException {
9217                    return findByT_A(threadId, answer, start, end, null);
9218            }
9219    
9220            /**
9221             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9222             *
9223             * <p>
9224             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9225             * </p>
9226             *
9227             * @param threadId the thread ID
9228             * @param answer the answer
9229             * @param start the lower bound of the range of message-boards messages
9230             * @param end the upper bound of the range of message-boards messages (not inclusive)
9231             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9232             * @return the ordered range of matching message-boards messages
9233             * @throws SystemException if a system exception occurred
9234             */
9235            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9236                    int end, OrderByComparator orderByComparator) throws SystemException {
9237                    boolean pagination = true;
9238                    FinderPath finderPath = null;
9239                    Object[] finderArgs = null;
9240    
9241                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9242                                    (orderByComparator == null)) {
9243                            pagination = false;
9244                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9245                            finderArgs = new Object[] { threadId, answer };
9246                    }
9247                    else {
9248                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9249                            finderArgs = new Object[] {
9250                                            threadId, answer,
9251                                            
9252                                            start, end, orderByComparator
9253                                    };
9254                    }
9255    
9256                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9257                                    finderArgs, this);
9258    
9259                    if ((list != null) && !list.isEmpty()) {
9260                            for (MBMessage mbMessage : list) {
9261                                    if ((threadId != mbMessage.getThreadId()) ||
9262                                                    (answer != mbMessage.getAnswer())) {
9263                                            list = null;
9264    
9265                                            break;
9266                                    }
9267                            }
9268                    }
9269    
9270                    if (list == null) {
9271                            StringBundler query = null;
9272    
9273                            if (orderByComparator != null) {
9274                                    query = new StringBundler(4 +
9275                                                    (orderByComparator.getOrderByFields().length * 3));
9276                            }
9277                            else {
9278                                    query = new StringBundler(4);
9279                            }
9280    
9281                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9282    
9283                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9284    
9285                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9286    
9287                            if (orderByComparator != null) {
9288                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9289                                            orderByComparator);
9290                            }
9291                            else
9292                             if (pagination) {
9293                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9294                            }
9295    
9296                            String sql = query.toString();
9297    
9298                            Session session = null;
9299    
9300                            try {
9301                                    session = openSession();
9302    
9303                                    Query q = session.createQuery(sql);
9304    
9305                                    QueryPos qPos = QueryPos.getInstance(q);
9306    
9307                                    qPos.add(threadId);
9308    
9309                                    qPos.add(answer);
9310    
9311                                    if (!pagination) {
9312                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9313                                                            start, end, false);
9314    
9315                                            Collections.sort(list);
9316    
9317                                            list = new UnmodifiableList<MBMessage>(list);
9318                                    }
9319                                    else {
9320                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9321                                                            start, end);
9322                                    }
9323    
9324                                    cacheResult(list);
9325    
9326                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9327                            }
9328                            catch (Exception e) {
9329                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9330    
9331                                    throw processException(e);
9332                            }
9333                            finally {
9334                                    closeSession(session);
9335                            }
9336                    }
9337    
9338                    return list;
9339            }
9340    
9341            /**
9342             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9343             *
9344             * @param threadId the thread ID
9345             * @param answer the answer
9346             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9347             * @return the first matching message-boards message
9348             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9349             * @throws SystemException if a system exception occurred
9350             */
9351            public MBMessage findByT_A_First(long threadId, boolean answer,
9352                    OrderByComparator orderByComparator)
9353                    throws NoSuchMessageException, SystemException {
9354                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9355                                    orderByComparator);
9356    
9357                    if (mbMessage != null) {
9358                            return mbMessage;
9359                    }
9360    
9361                    StringBundler msg = new StringBundler(6);
9362    
9363                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9364    
9365                    msg.append("threadId=");
9366                    msg.append(threadId);
9367    
9368                    msg.append(", answer=");
9369                    msg.append(answer);
9370    
9371                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9372    
9373                    throw new NoSuchMessageException(msg.toString());
9374            }
9375    
9376            /**
9377             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9378             *
9379             * @param threadId the thread ID
9380             * @param answer the answer
9381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9382             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9383             * @throws SystemException if a system exception occurred
9384             */
9385            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9386                    OrderByComparator orderByComparator) throws SystemException {
9387                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9388                                    orderByComparator);
9389    
9390                    if (!list.isEmpty()) {
9391                            return list.get(0);
9392                    }
9393    
9394                    return null;
9395            }
9396    
9397            /**
9398             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9399             *
9400             * @param threadId the thread ID
9401             * @param answer the answer
9402             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9403             * @return the last matching message-boards message
9404             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9405             * @throws SystemException if a system exception occurred
9406             */
9407            public MBMessage findByT_A_Last(long threadId, boolean answer,
9408                    OrderByComparator orderByComparator)
9409                    throws NoSuchMessageException, SystemException {
9410                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9411                                    orderByComparator);
9412    
9413                    if (mbMessage != null) {
9414                            return mbMessage;
9415                    }
9416    
9417                    StringBundler msg = new StringBundler(6);
9418    
9419                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9420    
9421                    msg.append("threadId=");
9422                    msg.append(threadId);
9423    
9424                    msg.append(", answer=");
9425                    msg.append(answer);
9426    
9427                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9428    
9429                    throw new NoSuchMessageException(msg.toString());
9430            }
9431    
9432            /**
9433             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9434             *
9435             * @param threadId the thread ID
9436             * @param answer the answer
9437             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9438             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9439             * @throws SystemException if a system exception occurred
9440             */
9441            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9442                    OrderByComparator orderByComparator) throws SystemException {
9443                    int count = countByT_A(threadId, answer);
9444    
9445                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9446                                    orderByComparator);
9447    
9448                    if (!list.isEmpty()) {
9449                            return list.get(0);
9450                    }
9451    
9452                    return null;
9453            }
9454    
9455            /**
9456             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9457             *
9458             * @param messageId the primary key of the current message-boards message
9459             * @param threadId the thread ID
9460             * @param answer the answer
9461             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9462             * @return the previous, current, and next message-boards message
9463             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9464             * @throws SystemException if a system exception occurred
9465             */
9466            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9467                    boolean answer, OrderByComparator orderByComparator)
9468                    throws NoSuchMessageException, SystemException {
9469                    MBMessage mbMessage = findByPrimaryKey(messageId);
9470    
9471                    Session session = null;
9472    
9473                    try {
9474                            session = openSession();
9475    
9476                            MBMessage[] array = new MBMessageImpl[3];
9477    
9478                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9479                                            answer, orderByComparator, true);
9480    
9481                            array[1] = mbMessage;
9482    
9483                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9484                                            answer, orderByComparator, false);
9485    
9486                            return array;
9487                    }
9488                    catch (Exception e) {
9489                            throw processException(e);
9490                    }
9491                    finally {
9492                            closeSession(session);
9493                    }
9494            }
9495    
9496            protected MBMessage getByT_A_PrevAndNext(Session session,
9497                    MBMessage mbMessage, long threadId, boolean answer,
9498                    OrderByComparator orderByComparator, boolean previous) {
9499                    StringBundler query = null;
9500    
9501                    if (orderByComparator != null) {
9502                            query = new StringBundler(6 +
9503                                            (orderByComparator.getOrderByFields().length * 6));
9504                    }
9505                    else {
9506                            query = new StringBundler(3);
9507                    }
9508    
9509                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9510    
9511                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9512    
9513                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9514    
9515                    if (orderByComparator != null) {
9516                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9517    
9518                            if (orderByConditionFields.length > 0) {
9519                                    query.append(WHERE_AND);
9520                            }
9521    
9522                            for (int i = 0; i < orderByConditionFields.length; i++) {
9523                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9524                                    query.append(orderByConditionFields[i]);
9525    
9526                                    if ((i + 1) < orderByConditionFields.length) {
9527                                            if (orderByComparator.isAscending() ^ previous) {
9528                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9529                                            }
9530                                            else {
9531                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9532                                            }
9533                                    }
9534                                    else {
9535                                            if (orderByComparator.isAscending() ^ previous) {
9536                                                    query.append(WHERE_GREATER_THAN);
9537                                            }
9538                                            else {
9539                                                    query.append(WHERE_LESSER_THAN);
9540                                            }
9541                                    }
9542                            }
9543    
9544                            query.append(ORDER_BY_CLAUSE);
9545    
9546                            String[] orderByFields = orderByComparator.getOrderByFields();
9547    
9548                            for (int i = 0; i < orderByFields.length; i++) {
9549                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9550                                    query.append(orderByFields[i]);
9551    
9552                                    if ((i + 1) < orderByFields.length) {
9553                                            if (orderByComparator.isAscending() ^ previous) {
9554                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9555                                            }
9556                                            else {
9557                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9558                                            }
9559                                    }
9560                                    else {
9561                                            if (orderByComparator.isAscending() ^ previous) {
9562                                                    query.append(ORDER_BY_ASC);
9563                                            }
9564                                            else {
9565                                                    query.append(ORDER_BY_DESC);
9566                                            }
9567                                    }
9568                            }
9569                    }
9570                    else {
9571                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9572                    }
9573    
9574                    String sql = query.toString();
9575    
9576                    Query q = session.createQuery(sql);
9577    
9578                    q.setFirstResult(0);
9579                    q.setMaxResults(2);
9580    
9581                    QueryPos qPos = QueryPos.getInstance(q);
9582    
9583                    qPos.add(threadId);
9584    
9585                    qPos.add(answer);
9586    
9587                    if (orderByComparator != null) {
9588                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9589    
9590                            for (Object value : values) {
9591                                    qPos.add(value);
9592                            }
9593                    }
9594    
9595                    List<MBMessage> list = q.list();
9596    
9597                    if (list.size() == 2) {
9598                            return list.get(1);
9599                    }
9600                    else {
9601                            return null;
9602                    }
9603            }
9604    
9605            /**
9606             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
9607             *
9608             * @param threadId the thread ID
9609             * @param answer the answer
9610             * @throws SystemException if a system exception occurred
9611             */
9612            public void removeByT_A(long threadId, boolean answer)
9613                    throws SystemException {
9614                    for (MBMessage mbMessage : findByT_A(threadId, answer,
9615                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9616                            remove(mbMessage);
9617                    }
9618            }
9619    
9620            /**
9621             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
9622             *
9623             * @param threadId the thread ID
9624             * @param answer the answer
9625             * @return the number of matching message-boards messages
9626             * @throws SystemException if a system exception occurred
9627             */
9628            public int countByT_A(long threadId, boolean answer)
9629                    throws SystemException {
9630                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
9631    
9632                    Object[] finderArgs = new Object[] { threadId, answer };
9633    
9634                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9635                                    this);
9636    
9637                    if (count == null) {
9638                            StringBundler query = new StringBundler(3);
9639    
9640                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9641    
9642                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9643    
9644                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9645    
9646                            String sql = query.toString();
9647    
9648                            Session session = null;
9649    
9650                            try {
9651                                    session = openSession();
9652    
9653                                    Query q = session.createQuery(sql);
9654    
9655                                    QueryPos qPos = QueryPos.getInstance(q);
9656    
9657                                    qPos.add(threadId);
9658    
9659                                    qPos.add(answer);
9660    
9661                                    count = (Long)q.uniqueResult();
9662    
9663                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9664                            }
9665                            catch (Exception e) {
9666                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9667    
9668                                    throw processException(e);
9669                            }
9670                            finally {
9671                                    closeSession(session);
9672                            }
9673                    }
9674    
9675                    return count.intValue();
9676            }
9677    
9678            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
9679            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
9680            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9681                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9682                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
9683                            new String[] {
9684                                    Long.class.getName(), Integer.class.getName(),
9685                                    
9686                            Integer.class.getName(), Integer.class.getName(),
9687                                    OrderByComparator.class.getName()
9688                            });
9689            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9690                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9691                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
9692                            new String[] { Long.class.getName(), Integer.class.getName() },
9693                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9694                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
9695                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9696            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9697                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9698                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
9699                            new String[] { Long.class.getName(), Integer.class.getName() });
9700    
9701            /**
9702             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9703             *
9704             * @param threadId the thread ID
9705             * @param status the status
9706             * @return the matching message-boards messages
9707             * @throws SystemException if a system exception occurred
9708             */
9709            public List<MBMessage> findByT_S(long threadId, int status)
9710                    throws SystemException {
9711                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
9712                            QueryUtil.ALL_POS, null);
9713            }
9714    
9715            /**
9716             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9717             *
9718             * <p>
9719             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9720             * </p>
9721             *
9722             * @param threadId the thread ID
9723             * @param status the status
9724             * @param start the lower bound of the range of message-boards messages
9725             * @param end the upper bound of the range of message-boards messages (not inclusive)
9726             * @return the range of matching message-boards messages
9727             * @throws SystemException if a system exception occurred
9728             */
9729            public List<MBMessage> findByT_S(long threadId, int status, int start,
9730                    int end) throws SystemException {
9731                    return findByT_S(threadId, status, start, end, null);
9732            }
9733    
9734            /**
9735             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9736             *
9737             * <p>
9738             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
9739             * </p>
9740             *
9741             * @param threadId the thread ID
9742             * @param status the status
9743             * @param start the lower bound of the range of message-boards messages
9744             * @param end the upper bound of the range of message-boards messages (not inclusive)
9745             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9746             * @return the ordered range of matching message-boards messages
9747             * @throws SystemException if a system exception occurred
9748             */
9749            public List<MBMessage> findByT_S(long threadId, int status, int start,
9750                    int end, OrderByComparator orderByComparator) throws SystemException {
9751                    boolean pagination = true;
9752                    FinderPath finderPath = null;
9753                    Object[] finderArgs = null;
9754    
9755                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9756                                    (orderByComparator == null)) {
9757                            pagination = false;
9758                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
9759                            finderArgs = new Object[] { threadId, status };
9760                    }
9761                    else {
9762                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
9763                            finderArgs = new Object[] {
9764                                            threadId, status,
9765                                            
9766                                            start, end, orderByComparator
9767                                    };
9768                    }
9769    
9770                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9771                                    finderArgs, this);
9772    
9773                    if ((list != null) && !list.isEmpty()) {
9774                            for (MBMessage mbMessage : list) {
9775                                    if ((threadId != mbMessage.getThreadId()) ||
9776                                                    (status != mbMessage.getStatus())) {
9777                                            list = null;
9778    
9779                                            break;
9780                                    }
9781                            }
9782                    }
9783    
9784                    if (list == null) {
9785                            StringBundler query = null;
9786    
9787                            if (orderByComparator != null) {
9788                                    query = new StringBundler(4 +
9789                                                    (orderByComparator.getOrderByFields().length * 3));
9790                            }
9791                            else {
9792                                    query = new StringBundler(4);
9793                            }
9794    
9795                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9796    
9797                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
9798    
9799                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
9800    
9801                            if (orderByComparator != null) {
9802                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9803                                            orderByComparator);
9804                            }
9805                            else
9806                             if (pagination) {
9807                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9808                            }
9809    
9810                            String sql = query.toString();
9811    
9812                            Session session = null;
9813    
9814                            try {
9815                                    session = openSession();
9816    
9817                                    Query q = session.createQuery(sql);
9818    
9819                                    QueryPos qPos = QueryPos.getInstance(q);
9820    
9821                                    qPos.add(threadId);
9822    
9823                                    qPos.add(status);
9824    
9825                                    if (!pagination) {
9826                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9827                                                            start, end, false);
9828    
9829                                            Collections.sort(list);
9830    
9831                                            list = new UnmodifiableList<MBMessage>(list);
9832                                    }
9833                                    else {
9834                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9835                                                            start, end);
9836                                    }
9837    
9838                                    cacheResult(list);
9839    
9840                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9841                            }
9842                            catch (Exception e) {
9843                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9844    
9845                                    throw processException(e);
9846                            }
9847                            finally {
9848                                    closeSession(session);
9849                            }
9850                    }
9851    
9852                    return list;
9853            }
9854    
9855            /**
9856             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9857             *
9858             * @param threadId the thread ID
9859             * @param status the status
9860             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9861             * @return the first matching message-boards message
9862             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9863             * @throws SystemException if a system exception occurred
9864             */
9865            public MBMessage findByT_S_First(long threadId, int status,
9866                    OrderByComparator orderByComparator)
9867                    throws NoSuchMessageException, SystemException {
9868                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
9869                                    orderByComparator);
9870    
9871                    if (mbMessage != null) {
9872                            return mbMessage;
9873                    }
9874    
9875                    StringBundler msg = new StringBundler(6);
9876    
9877                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9878    
9879                    msg.append("threadId=");
9880                    msg.append(threadId);
9881    
9882                    msg.append(", status=");
9883                    msg.append(status);
9884    
9885                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9886    
9887                    throw new NoSuchMessageException(msg.toString());
9888            }
9889    
9890            /**
9891             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9892             *
9893             * @param threadId the thread ID
9894             * @param status the status
9895             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9896             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9897             * @throws SystemException if a system exception occurred
9898             */
9899            public MBMessage fetchByT_S_First(long threadId, int status,
9900                    OrderByComparator orderByComparator) throws SystemException {
9901                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
9902                                    orderByComparator);
9903    
9904                    if (!list.isEmpty()) {
9905                            return list.get(0);
9906                    }
9907    
9908                    return null;
9909            }
9910    
9911            /**
9912             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9913             *
9914             * @param threadId the thread ID
9915             * @param status the status
9916             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9917             * @return the last matching message-boards message
9918             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9919             * @throws SystemException if a system exception occurred
9920             */
9921            public MBMessage findByT_S_Last(long threadId, int status,
9922                    OrderByComparator orderByComparator)
9923                    throws NoSuchMessageException, SystemException {
9924                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
9925                                    orderByComparator);
9926    
9927                    if (mbMessage != null) {
9928                            return mbMessage;
9929                    }
9930    
9931                    StringBundler msg = new StringBundler(6);
9932    
9933                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9934    
9935                    msg.append("threadId=");
9936                    msg.append(threadId);
9937    
9938                    msg.append(", status=");
9939                    msg.append(status);
9940    
9941                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9942    
9943                    throw new NoSuchMessageException(msg.toString());
9944            }
9945    
9946            /**
9947             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9948             *
9949             * @param threadId the thread ID
9950             * @param status the status
9951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9952             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9953             * @throws SystemException if a system exception occurred
9954             */
9955            public MBMessage fetchByT_S_Last(long threadId, int status,
9956                    OrderByComparator orderByComparator) throws SystemException {
9957                    int count = countByT_S(threadId, status);
9958    
9959                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
9960                                    orderByComparator);
9961    
9962                    if (!list.isEmpty()) {
9963                            return list.get(0);
9964                    }
9965    
9966                    return null;
9967            }
9968    
9969            /**
9970             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9971             *
9972             * @param messageId the primary key of the current message-boards message
9973             * @param threadId the thread ID
9974             * @param status the status
9975             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9976             * @return the previous, current, and next message-boards message
9977             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9978             * @throws SystemException if a system exception occurred
9979             */
9980            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
9981                    int status, OrderByComparator orderByComparator)
9982                    throws NoSuchMessageException, SystemException {
9983                    MBMessage mbMessage = findByPrimaryKey(messageId);
9984    
9985                    Session session = null;
9986    
9987                    try {
9988                            session = openSession();
9989    
9990                            MBMessage[] array = new MBMessageImpl[3];
9991    
9992                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9993                                            status, orderByComparator, true);
9994    
9995                            array[1] = mbMessage;
9996    
9997                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9998                                            status, orderByComparator, false);
9999    
10000                            return array;
10001                    }
10002                    catch (Exception e) {
10003                            throw processException(e);
10004                    }
10005                    finally {
10006                            closeSession(session);
10007                    }
10008            }
10009    
10010            protected MBMessage getByT_S_PrevAndNext(Session session,
10011                    MBMessage mbMessage, long threadId, int status,
10012                    OrderByComparator orderByComparator, boolean previous) {
10013                    StringBundler query = null;
10014    
10015                    if (orderByComparator != null) {
10016                            query = new StringBundler(6 +
10017                                            (orderByComparator.getOrderByFields().length * 6));
10018                    }
10019                    else {
10020                            query = new StringBundler(3);
10021                    }
10022    
10023                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10024    
10025                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10026    
10027                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10028    
10029                    if (orderByComparator != null) {
10030                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10031    
10032                            if (orderByConditionFields.length > 0) {
10033                                    query.append(WHERE_AND);
10034                            }
10035    
10036                            for (int i = 0; i < orderByConditionFields.length; i++) {
10037                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10038                                    query.append(orderByConditionFields[i]);
10039    
10040                                    if ((i + 1) < orderByConditionFields.length) {
10041                                            if (orderByComparator.isAscending() ^ previous) {
10042                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10043                                            }
10044                                            else {
10045                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10046                                            }
10047                                    }
10048                                    else {
10049                                            if (orderByComparator.isAscending() ^ previous) {
10050                                                    query.append(WHERE_GREATER_THAN);
10051                                            }
10052                                            else {
10053                                                    query.append(WHERE_LESSER_THAN);
10054                                            }
10055                                    }
10056                            }
10057    
10058                            query.append(ORDER_BY_CLAUSE);
10059    
10060                            String[] orderByFields = orderByComparator.getOrderByFields();
10061    
10062                            for (int i = 0; i < orderByFields.length; i++) {
10063                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10064                                    query.append(orderByFields[i]);
10065    
10066                                    if ((i + 1) < orderByFields.length) {
10067                                            if (orderByComparator.isAscending() ^ previous) {
10068                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10069                                            }
10070                                            else {
10071                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10072                                            }
10073                                    }
10074                                    else {
10075                                            if (orderByComparator.isAscending() ^ previous) {
10076                                                    query.append(ORDER_BY_ASC);
10077                                            }
10078                                            else {
10079                                                    query.append(ORDER_BY_DESC);
10080                                            }
10081                                    }
10082                            }
10083                    }
10084                    else {
10085                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10086                    }
10087    
10088                    String sql = query.toString();
10089    
10090                    Query q = session.createQuery(sql);
10091    
10092                    q.setFirstResult(0);
10093                    q.setMaxResults(2);
10094    
10095                    QueryPos qPos = QueryPos.getInstance(q);
10096    
10097                    qPos.add(threadId);
10098    
10099                    qPos.add(status);
10100    
10101                    if (orderByComparator != null) {
10102                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10103    
10104                            for (Object value : values) {
10105                                    qPos.add(value);
10106                            }
10107                    }
10108    
10109                    List<MBMessage> list = q.list();
10110    
10111                    if (list.size() == 2) {
10112                            return list.get(1);
10113                    }
10114                    else {
10115                            return null;
10116                    }
10117            }
10118    
10119            /**
10120             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10121             *
10122             * @param threadId the thread ID
10123             * @param status the status
10124             * @throws SystemException if a system exception occurred
10125             */
10126            public void removeByT_S(long threadId, int status)
10127                    throws SystemException {
10128                    for (MBMessage mbMessage : findByT_S(threadId, status,
10129                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10130                            remove(mbMessage);
10131                    }
10132            }
10133    
10134            /**
10135             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10136             *
10137             * @param threadId the thread ID
10138             * @param status the status
10139             * @return the number of matching message-boards messages
10140             * @throws SystemException if a system exception occurred
10141             */
10142            public int countByT_S(long threadId, int status) throws SystemException {
10143                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10144    
10145                    Object[] finderArgs = new Object[] { threadId, status };
10146    
10147                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10148                                    this);
10149    
10150                    if (count == null) {
10151                            StringBundler query = new StringBundler(3);
10152    
10153                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10154    
10155                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10156    
10157                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10158    
10159                            String sql = query.toString();
10160    
10161                            Session session = null;
10162    
10163                            try {
10164                                    session = openSession();
10165    
10166                                    Query q = session.createQuery(sql);
10167    
10168                                    QueryPos qPos = QueryPos.getInstance(q);
10169    
10170                                    qPos.add(threadId);
10171    
10172                                    qPos.add(status);
10173    
10174                                    count = (Long)q.uniqueResult();
10175    
10176                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10177                            }
10178                            catch (Exception e) {
10179                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10180    
10181                                    throw processException(e);
10182                            }
10183                            finally {
10184                                    closeSession(session);
10185                            }
10186                    }
10187    
10188                    return count.intValue();
10189            }
10190    
10191            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10192            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10193            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10194                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10195                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10196                            new String[] {
10197                                    Long.class.getName(), Integer.class.getName(),
10198                                    
10199                            Integer.class.getName(), Integer.class.getName(),
10200                                    OrderByComparator.class.getName()
10201                            });
10202            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10203                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10204                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10205                            new String[] { Long.class.getName(), Integer.class.getName() },
10206                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10207                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10208                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10209            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10210                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10211                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10212                            new String[] { Long.class.getName(), Integer.class.getName() });
10213    
10214            /**
10215             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10216             *
10217             * @param threadId the thread ID
10218             * @param status the status
10219             * @return the matching message-boards messages
10220             * @throws SystemException if a system exception occurred
10221             */
10222            public List<MBMessage> findByTR_S(long threadId, int status)
10223                    throws SystemException {
10224                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10225                            QueryUtil.ALL_POS, null);
10226            }
10227    
10228            /**
10229             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10230             *
10231             * <p>
10232             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10233             * </p>
10234             *
10235             * @param threadId the thread ID
10236             * @param status the status
10237             * @param start the lower bound of the range of message-boards messages
10238             * @param end the upper bound of the range of message-boards messages (not inclusive)
10239             * @return the range of matching message-boards messages
10240             * @throws SystemException if a system exception occurred
10241             */
10242            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10243                    int end) throws SystemException {
10244                    return findByTR_S(threadId, status, start, end, null);
10245            }
10246    
10247            /**
10248             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10249             *
10250             * <p>
10251             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10252             * </p>
10253             *
10254             * @param threadId the thread ID
10255             * @param status the status
10256             * @param start the lower bound of the range of message-boards messages
10257             * @param end the upper bound of the range of message-boards messages (not inclusive)
10258             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10259             * @return the ordered range of matching message-boards messages
10260             * @throws SystemException if a system exception occurred
10261             */
10262            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10263                    int end, OrderByComparator orderByComparator) throws SystemException {
10264                    boolean pagination = true;
10265                    FinderPath finderPath = null;
10266                    Object[] finderArgs = null;
10267    
10268                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10269                                    (orderByComparator == null)) {
10270                            pagination = false;
10271                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10272                            finderArgs = new Object[] { threadId, status };
10273                    }
10274                    else {
10275                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10276                            finderArgs = new Object[] {
10277                                            threadId, status,
10278                                            
10279                                            start, end, orderByComparator
10280                                    };
10281                    }
10282    
10283                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10284                                    finderArgs, this);
10285    
10286                    if ((list != null) && !list.isEmpty()) {
10287                            for (MBMessage mbMessage : list) {
10288                                    if ((threadId != mbMessage.getThreadId()) ||
10289                                                    (status != mbMessage.getStatus())) {
10290                                            list = null;
10291    
10292                                            break;
10293                                    }
10294                            }
10295                    }
10296    
10297                    if (list == null) {
10298                            StringBundler query = null;
10299    
10300                            if (orderByComparator != null) {
10301                                    query = new StringBundler(4 +
10302                                                    (orderByComparator.getOrderByFields().length * 3));
10303                            }
10304                            else {
10305                                    query = new StringBundler(4);
10306                            }
10307    
10308                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10309    
10310                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10311    
10312                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10313    
10314                            if (orderByComparator != null) {
10315                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10316                                            orderByComparator);
10317                            }
10318                            else
10319                             if (pagination) {
10320                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10321                            }
10322    
10323                            String sql = query.toString();
10324    
10325                            Session session = null;
10326    
10327                            try {
10328                                    session = openSession();
10329    
10330                                    Query q = session.createQuery(sql);
10331    
10332                                    QueryPos qPos = QueryPos.getInstance(q);
10333    
10334                                    qPos.add(threadId);
10335    
10336                                    qPos.add(status);
10337    
10338                                    if (!pagination) {
10339                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10340                                                            start, end, false);
10341    
10342                                            Collections.sort(list);
10343    
10344                                            list = new UnmodifiableList<MBMessage>(list);
10345                                    }
10346                                    else {
10347                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10348                                                            start, end);
10349                                    }
10350    
10351                                    cacheResult(list);
10352    
10353                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10354                            }
10355                            catch (Exception e) {
10356                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10357    
10358                                    throw processException(e);
10359                            }
10360                            finally {
10361                                    closeSession(session);
10362                            }
10363                    }
10364    
10365                    return list;
10366            }
10367    
10368            /**
10369             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10370             *
10371             * @param threadId the thread ID
10372             * @param status the status
10373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10374             * @return the first matching message-boards message
10375             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10376             * @throws SystemException if a system exception occurred
10377             */
10378            public MBMessage findByTR_S_First(long threadId, int status,
10379                    OrderByComparator orderByComparator)
10380                    throws NoSuchMessageException, SystemException {
10381                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10382                                    orderByComparator);
10383    
10384                    if (mbMessage != null) {
10385                            return mbMessage;
10386                    }
10387    
10388                    StringBundler msg = new StringBundler(6);
10389    
10390                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10391    
10392                    msg.append("threadId=");
10393                    msg.append(threadId);
10394    
10395                    msg.append(", status=");
10396                    msg.append(status);
10397    
10398                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10399    
10400                    throw new NoSuchMessageException(msg.toString());
10401            }
10402    
10403            /**
10404             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10405             *
10406             * @param threadId the thread ID
10407             * @param status the status
10408             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10409             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10410             * @throws SystemException if a system exception occurred
10411             */
10412            public MBMessage fetchByTR_S_First(long threadId, int status,
10413                    OrderByComparator orderByComparator) throws SystemException {
10414                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10415                                    orderByComparator);
10416    
10417                    if (!list.isEmpty()) {
10418                            return list.get(0);
10419                    }
10420    
10421                    return null;
10422            }
10423    
10424            /**
10425             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10426             *
10427             * @param threadId the thread ID
10428             * @param status the status
10429             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10430             * @return the last matching message-boards message
10431             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10432             * @throws SystemException if a system exception occurred
10433             */
10434            public MBMessage findByTR_S_Last(long threadId, int status,
10435                    OrderByComparator orderByComparator)
10436                    throws NoSuchMessageException, SystemException {
10437                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10438                                    orderByComparator);
10439    
10440                    if (mbMessage != null) {
10441                            return mbMessage;
10442                    }
10443    
10444                    StringBundler msg = new StringBundler(6);
10445    
10446                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10447    
10448                    msg.append("threadId=");
10449                    msg.append(threadId);
10450    
10451                    msg.append(", status=");
10452                    msg.append(status);
10453    
10454                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10455    
10456                    throw new NoSuchMessageException(msg.toString());
10457            }
10458    
10459            /**
10460             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10461             *
10462             * @param threadId the thread ID
10463             * @param status the status
10464             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10465             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10466             * @throws SystemException if a system exception occurred
10467             */
10468            public MBMessage fetchByTR_S_Last(long threadId, int status,
10469                    OrderByComparator orderByComparator) throws SystemException {
10470                    int count = countByTR_S(threadId, status);
10471    
10472                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10473                                    orderByComparator);
10474    
10475                    if (!list.isEmpty()) {
10476                            return list.get(0);
10477                    }
10478    
10479                    return null;
10480            }
10481    
10482            /**
10483             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10484             *
10485             * @param messageId the primary key of the current message-boards message
10486             * @param threadId the thread ID
10487             * @param status the status
10488             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10489             * @return the previous, current, and next message-boards message
10490             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10491             * @throws SystemException if a system exception occurred
10492             */
10493            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10494                    int status, OrderByComparator orderByComparator)
10495                    throws NoSuchMessageException, SystemException {
10496                    MBMessage mbMessage = findByPrimaryKey(messageId);
10497    
10498                    Session session = null;
10499    
10500                    try {
10501                            session = openSession();
10502    
10503                            MBMessage[] array = new MBMessageImpl[3];
10504    
10505                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10506                                            status, orderByComparator, true);
10507    
10508                            array[1] = mbMessage;
10509    
10510                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10511                                            status, orderByComparator, false);
10512    
10513                            return array;
10514                    }
10515                    catch (Exception e) {
10516                            throw processException(e);
10517                    }
10518                    finally {
10519                            closeSession(session);
10520                    }
10521            }
10522    
10523            protected MBMessage getByTR_S_PrevAndNext(Session session,
10524                    MBMessage mbMessage, long threadId, int status,
10525                    OrderByComparator orderByComparator, boolean previous) {
10526                    StringBundler query = null;
10527    
10528                    if (orderByComparator != null) {
10529                            query = new StringBundler(6 +
10530                                            (orderByComparator.getOrderByFields().length * 6));
10531                    }
10532                    else {
10533                            query = new StringBundler(3);
10534                    }
10535    
10536                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10537    
10538                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10539    
10540                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10541    
10542                    if (orderByComparator != null) {
10543                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10544    
10545                            if (orderByConditionFields.length > 0) {
10546                                    query.append(WHERE_AND);
10547                            }
10548    
10549                            for (int i = 0; i < orderByConditionFields.length; i++) {
10550                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10551                                    query.append(orderByConditionFields[i]);
10552    
10553                                    if ((i + 1) < orderByConditionFields.length) {
10554                                            if (orderByComparator.isAscending() ^ previous) {
10555                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10556                                            }
10557                                            else {
10558                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10559                                            }
10560                                    }
10561                                    else {
10562                                            if (orderByComparator.isAscending() ^ previous) {
10563                                                    query.append(WHERE_GREATER_THAN);
10564                                            }
10565                                            else {
10566                                                    query.append(WHERE_LESSER_THAN);
10567                                            }
10568                                    }
10569                            }
10570    
10571                            query.append(ORDER_BY_CLAUSE);
10572    
10573                            String[] orderByFields = orderByComparator.getOrderByFields();
10574    
10575                            for (int i = 0; i < orderByFields.length; i++) {
10576                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10577                                    query.append(orderByFields[i]);
10578    
10579                                    if ((i + 1) < orderByFields.length) {
10580                                            if (orderByComparator.isAscending() ^ previous) {
10581                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10582                                            }
10583                                            else {
10584                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10585                                            }
10586                                    }
10587                                    else {
10588                                            if (orderByComparator.isAscending() ^ previous) {
10589                                                    query.append(ORDER_BY_ASC);
10590                                            }
10591                                            else {
10592                                                    query.append(ORDER_BY_DESC);
10593                                            }
10594                                    }
10595                            }
10596                    }
10597                    else {
10598                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10599                    }
10600    
10601                    String sql = query.toString();
10602    
10603                    Query q = session.createQuery(sql);
10604    
10605                    q.setFirstResult(0);
10606                    q.setMaxResults(2);
10607    
10608                    QueryPos qPos = QueryPos.getInstance(q);
10609    
10610                    qPos.add(threadId);
10611    
10612                    qPos.add(status);
10613    
10614                    if (orderByComparator != null) {
10615                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10616    
10617                            for (Object value : values) {
10618                                    qPos.add(value);
10619                            }
10620                    }
10621    
10622                    List<MBMessage> list = q.list();
10623    
10624                    if (list.size() == 2) {
10625                            return list.get(1);
10626                    }
10627                    else {
10628                            return null;
10629                    }
10630            }
10631    
10632            /**
10633             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10634             *
10635             * @param threadId the thread ID
10636             * @param status the status
10637             * @throws SystemException if a system exception occurred
10638             */
10639            public void removeByTR_S(long threadId, int status)
10640                    throws SystemException {
10641                    for (MBMessage mbMessage : findByTR_S(threadId, status,
10642                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10643                            remove(mbMessage);
10644                    }
10645            }
10646    
10647            /**
10648             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10649             *
10650             * @param threadId the thread ID
10651             * @param status the status
10652             * @return the number of matching message-boards messages
10653             * @throws SystemException if a system exception occurred
10654             */
10655            public int countByTR_S(long threadId, int status) throws SystemException {
10656                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
10657    
10658                    Object[] finderArgs = new Object[] { threadId, status };
10659    
10660                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10661                                    this);
10662    
10663                    if (count == null) {
10664                            StringBundler query = new StringBundler(3);
10665    
10666                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10667    
10668                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10669    
10670                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10671    
10672                            String sql = query.toString();
10673    
10674                            Session session = null;
10675    
10676                            try {
10677                                    session = openSession();
10678    
10679                                    Query q = session.createQuery(sql);
10680    
10681                                    QueryPos qPos = QueryPos.getInstance(q);
10682    
10683                                    qPos.add(threadId);
10684    
10685                                    qPos.add(status);
10686    
10687                                    count = (Long)q.uniqueResult();
10688    
10689                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10690                            }
10691                            catch (Exception e) {
10692                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10693    
10694                                    throw processException(e);
10695                            }
10696                            finally {
10697                                    closeSession(session);
10698                            }
10699                    }
10700    
10701                    return count.intValue();
10702            }
10703    
10704            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10705            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
10706            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10707                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10708                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
10709                            new String[] {
10710                                    Long.class.getName(), Long.class.getName(),
10711                                    Integer.class.getName(),
10712                                    
10713                            Integer.class.getName(), Integer.class.getName(),
10714                                    OrderByComparator.class.getName()
10715                            });
10716            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10717                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10718                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
10719                            new String[] {
10720                                    Long.class.getName(), Long.class.getName(),
10721                                    Integer.class.getName()
10722                            },
10723                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
10724                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
10725                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10726                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10727            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10728                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10729                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
10730                            new String[] {
10731                                    Long.class.getName(), Long.class.getName(),
10732                                    Integer.class.getName()
10733                            });
10734    
10735            /**
10736             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10737             *
10738             * @param groupId the group ID
10739             * @param userId the user ID
10740             * @param status the status
10741             * @return the matching message-boards messages
10742             * @throws SystemException if a system exception occurred
10743             */
10744            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
10745                    throws SystemException {
10746                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10747                            QueryUtil.ALL_POS, null);
10748            }
10749    
10750            /**
10751             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10752             *
10753             * <p>
10754             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10755             * </p>
10756             *
10757             * @param groupId the group ID
10758             * @param userId the user ID
10759             * @param status the status
10760             * @param start the lower bound of the range of message-boards messages
10761             * @param end the upper bound of the range of message-boards messages (not inclusive)
10762             * @return the range of matching message-boards messages
10763             * @throws SystemException if a system exception occurred
10764             */
10765            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10766                    int start, int end) throws SystemException {
10767                    return findByG_U_S(groupId, userId, status, start, end, null);
10768            }
10769    
10770            /**
10771             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10772             *
10773             * <p>
10774             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
10775             * </p>
10776             *
10777             * @param groupId the group ID
10778             * @param userId the user ID
10779             * @param status the status
10780             * @param start the lower bound of the range of message-boards messages
10781             * @param end the upper bound of the range of message-boards messages (not inclusive)
10782             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10783             * @return the ordered range of matching message-boards messages
10784             * @throws SystemException if a system exception occurred
10785             */
10786            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10787                    int start, int end, OrderByComparator orderByComparator)
10788                    throws SystemException {
10789                    boolean pagination = true;
10790                    FinderPath finderPath = null;
10791                    Object[] finderArgs = null;
10792    
10793                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10794                                    (orderByComparator == null)) {
10795                            pagination = false;
10796                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
10797                            finderArgs = new Object[] { groupId, userId, status };
10798                    }
10799                    else {
10800                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
10801                            finderArgs = new Object[] {
10802                                            groupId, userId, status,
10803                                            
10804                                            start, end, orderByComparator
10805                                    };
10806                    }
10807    
10808                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10809                                    finderArgs, this);
10810    
10811                    if ((list != null) && !list.isEmpty()) {
10812                            for (MBMessage mbMessage : list) {
10813                                    if ((groupId != mbMessage.getGroupId()) ||
10814                                                    (userId != mbMessage.getUserId()) ||
10815                                                    (status != mbMessage.getStatus())) {
10816                                            list = null;
10817    
10818                                            break;
10819                                    }
10820                            }
10821                    }
10822    
10823                    if (list == null) {
10824                            StringBundler query = null;
10825    
10826                            if (orderByComparator != null) {
10827                                    query = new StringBundler(5 +
10828                                                    (orderByComparator.getOrderByFields().length * 3));
10829                            }
10830                            else {
10831                                    query = new StringBundler(5);
10832                            }
10833    
10834                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10835    
10836                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10837    
10838                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10839    
10840                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10841    
10842                            if (orderByComparator != null) {
10843                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10844                                            orderByComparator);
10845                            }
10846                            else
10847                             if (pagination) {
10848                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10849                            }
10850    
10851                            String sql = query.toString();
10852    
10853                            Session session = null;
10854    
10855                            try {
10856                                    session = openSession();
10857    
10858                                    Query q = session.createQuery(sql);
10859    
10860                                    QueryPos qPos = QueryPos.getInstance(q);
10861    
10862                                    qPos.add(groupId);
10863    
10864                                    qPos.add(userId);
10865    
10866                                    qPos.add(status);
10867    
10868                                    if (!pagination) {
10869                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10870                                                            start, end, false);
10871    
10872                                            Collections.sort(list);
10873    
10874                                            list = new UnmodifiableList<MBMessage>(list);
10875                                    }
10876                                    else {
10877                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10878                                                            start, end);
10879                                    }
10880    
10881                                    cacheResult(list);
10882    
10883                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10884                            }
10885                            catch (Exception e) {
10886                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10887    
10888                                    throw processException(e);
10889                            }
10890                            finally {
10891                                    closeSession(session);
10892                            }
10893                    }
10894    
10895                    return list;
10896            }
10897    
10898            /**
10899             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10900             *
10901             * @param groupId the group ID
10902             * @param userId the user ID
10903             * @param status the status
10904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10905             * @return the first matching message-boards message
10906             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10907             * @throws SystemException if a system exception occurred
10908             */
10909            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
10910                    OrderByComparator orderByComparator)
10911                    throws NoSuchMessageException, SystemException {
10912                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
10913                                    orderByComparator);
10914    
10915                    if (mbMessage != null) {
10916                            return mbMessage;
10917                    }
10918    
10919                    StringBundler msg = new StringBundler(8);
10920    
10921                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10922    
10923                    msg.append("groupId=");
10924                    msg.append(groupId);
10925    
10926                    msg.append(", userId=");
10927                    msg.append(userId);
10928    
10929                    msg.append(", status=");
10930                    msg.append(status);
10931    
10932                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10933    
10934                    throw new NoSuchMessageException(msg.toString());
10935            }
10936    
10937            /**
10938             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10939             *
10940             * @param groupId the group ID
10941             * @param userId the user ID
10942             * @param status the status
10943             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10944             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10945             * @throws SystemException if a system exception occurred
10946             */
10947            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
10948                    OrderByComparator orderByComparator) throws SystemException {
10949                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
10950                                    orderByComparator);
10951    
10952                    if (!list.isEmpty()) {
10953                            return list.get(0);
10954                    }
10955    
10956                    return null;
10957            }
10958    
10959            /**
10960             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10961             *
10962             * @param groupId the group ID
10963             * @param userId the user ID
10964             * @param status the status
10965             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10966             * @return the last matching message-boards message
10967             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10968             * @throws SystemException if a system exception occurred
10969             */
10970            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
10971                    OrderByComparator orderByComparator)
10972                    throws NoSuchMessageException, SystemException {
10973                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
10974                                    orderByComparator);
10975    
10976                    if (mbMessage != null) {
10977                            return mbMessage;
10978                    }
10979    
10980                    StringBundler msg = new StringBundler(8);
10981    
10982                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10983    
10984                    msg.append("groupId=");
10985                    msg.append(groupId);
10986    
10987                    msg.append(", userId=");
10988                    msg.append(userId);
10989    
10990                    msg.append(", status=");
10991                    msg.append(status);
10992    
10993                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10994    
10995                    throw new NoSuchMessageException(msg.toString());
10996            }
10997    
10998            /**
10999             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11000             *
11001             * @param groupId the group ID
11002             * @param userId the user ID
11003             * @param status the status
11004             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11005             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11006             * @throws SystemException if a system exception occurred
11007             */
11008            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11009                    OrderByComparator orderByComparator) throws SystemException {
11010                    int count = countByG_U_S(groupId, userId, status);
11011    
11012                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11013                                    count, orderByComparator);
11014    
11015                    if (!list.isEmpty()) {
11016                            return list.get(0);
11017                    }
11018    
11019                    return null;
11020            }
11021    
11022            /**
11023             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11024             *
11025             * @param messageId the primary key of the current message-boards message
11026             * @param groupId the group ID
11027             * @param userId the user ID
11028             * @param status the status
11029             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11030             * @return the previous, current, and next message-boards message
11031             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11032             * @throws SystemException if a system exception occurred
11033             */
11034            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11035                    long userId, int status, OrderByComparator orderByComparator)
11036                    throws NoSuchMessageException, SystemException {
11037                    MBMessage mbMessage = findByPrimaryKey(messageId);
11038    
11039                    Session session = null;
11040    
11041                    try {
11042                            session = openSession();
11043    
11044                            MBMessage[] array = new MBMessageImpl[3];
11045    
11046                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11047                                            userId, status, orderByComparator, true);
11048    
11049                            array[1] = mbMessage;
11050    
11051                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11052                                            userId, status, orderByComparator, false);
11053    
11054                            return array;
11055                    }
11056                    catch (Exception e) {
11057                            throw processException(e);
11058                    }
11059                    finally {
11060                            closeSession(session);
11061                    }
11062            }
11063    
11064            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11065                    MBMessage mbMessage, long groupId, long userId, int status,
11066                    OrderByComparator orderByComparator, boolean previous) {
11067                    StringBundler query = null;
11068    
11069                    if (orderByComparator != null) {
11070                            query = new StringBundler(6 +
11071                                            (orderByComparator.getOrderByFields().length * 6));
11072                    }
11073                    else {
11074                            query = new StringBundler(3);
11075                    }
11076    
11077                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11078    
11079                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11080    
11081                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11082    
11083                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11084    
11085                    if (orderByComparator != null) {
11086                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11087    
11088                            if (orderByConditionFields.length > 0) {
11089                                    query.append(WHERE_AND);
11090                            }
11091    
11092                            for (int i = 0; i < orderByConditionFields.length; i++) {
11093                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11094                                    query.append(orderByConditionFields[i]);
11095    
11096                                    if ((i + 1) < orderByConditionFields.length) {
11097                                            if (orderByComparator.isAscending() ^ previous) {
11098                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11099                                            }
11100                                            else {
11101                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11102                                            }
11103                                    }
11104                                    else {
11105                                            if (orderByComparator.isAscending() ^ previous) {
11106                                                    query.append(WHERE_GREATER_THAN);
11107                                            }
11108                                            else {
11109                                                    query.append(WHERE_LESSER_THAN);
11110                                            }
11111                                    }
11112                            }
11113    
11114                            query.append(ORDER_BY_CLAUSE);
11115    
11116                            String[] orderByFields = orderByComparator.getOrderByFields();
11117    
11118                            for (int i = 0; i < orderByFields.length; i++) {
11119                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11120                                    query.append(orderByFields[i]);
11121    
11122                                    if ((i + 1) < orderByFields.length) {
11123                                            if (orderByComparator.isAscending() ^ previous) {
11124                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11125                                            }
11126                                            else {
11127                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11128                                            }
11129                                    }
11130                                    else {
11131                                            if (orderByComparator.isAscending() ^ previous) {
11132                                                    query.append(ORDER_BY_ASC);
11133                                            }
11134                                            else {
11135                                                    query.append(ORDER_BY_DESC);
11136                                            }
11137                                    }
11138                            }
11139                    }
11140                    else {
11141                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11142                    }
11143    
11144                    String sql = query.toString();
11145    
11146                    Query q = session.createQuery(sql);
11147    
11148                    q.setFirstResult(0);
11149                    q.setMaxResults(2);
11150    
11151                    QueryPos qPos = QueryPos.getInstance(q);
11152    
11153                    qPos.add(groupId);
11154    
11155                    qPos.add(userId);
11156    
11157                    qPos.add(status);
11158    
11159                    if (orderByComparator != null) {
11160                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11161    
11162                            for (Object value : values) {
11163                                    qPos.add(value);
11164                            }
11165                    }
11166    
11167                    List<MBMessage> list = q.list();
11168    
11169                    if (list.size() == 2) {
11170                            return list.get(1);
11171                    }
11172                    else {
11173                            return null;
11174                    }
11175            }
11176    
11177            /**
11178             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11179             *
11180             * @param groupId the group ID
11181             * @param userId the user ID
11182             * @param status the status
11183             * @return the matching message-boards messages that the user has permission to view
11184             * @throws SystemException if a system exception occurred
11185             */
11186            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11187                    int status) throws SystemException {
11188                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11189                            QueryUtil.ALL_POS, null);
11190            }
11191    
11192            /**
11193             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11194             *
11195             * <p>
11196             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11197             * </p>
11198             *
11199             * @param groupId the group ID
11200             * @param userId the user ID
11201             * @param status the status
11202             * @param start the lower bound of the range of message-boards messages
11203             * @param end the upper bound of the range of message-boards messages (not inclusive)
11204             * @return the range of matching message-boards messages that the user has permission to view
11205             * @throws SystemException if a system exception occurred
11206             */
11207            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11208                    int status, int start, int end) throws SystemException {
11209                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11210            }
11211    
11212            /**
11213             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63; and status = &#63;.
11214             *
11215             * <p>
11216             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11217             * </p>
11218             *
11219             * @param groupId the group ID
11220             * @param userId the user ID
11221             * @param status the status
11222             * @param start the lower bound of the range of message-boards messages
11223             * @param end the upper bound of the range of message-boards messages (not inclusive)
11224             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11225             * @return the ordered range of matching message-boards messages that the user has permission to view
11226             * @throws SystemException if a system exception occurred
11227             */
11228            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11229                    int status, int start, int end, OrderByComparator orderByComparator)
11230                    throws SystemException {
11231                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11232                            return findByG_U_S(groupId, userId, status, start, end,
11233                                    orderByComparator);
11234                    }
11235    
11236                    StringBundler query = null;
11237    
11238                    if (orderByComparator != null) {
11239                            query = new StringBundler(5 +
11240                                            (orderByComparator.getOrderByFields().length * 3));
11241                    }
11242                    else {
11243                            query = new StringBundler(5);
11244                    }
11245    
11246                    if (getDB().isSupportsInlineDistinct()) {
11247                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11248                    }
11249                    else {
11250                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11251                    }
11252    
11253                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11254    
11255                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11256    
11257                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11258    
11259                    if (!getDB().isSupportsInlineDistinct()) {
11260                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11261                    }
11262    
11263                    if (orderByComparator != null) {
11264                            if (getDB().isSupportsInlineDistinct()) {
11265                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11266                                            orderByComparator);
11267                            }
11268                            else {
11269                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11270                                            orderByComparator);
11271                            }
11272                    }
11273                    else {
11274                            if (getDB().isSupportsInlineDistinct()) {
11275                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11276                            }
11277                            else {
11278                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11279                            }
11280                    }
11281    
11282                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11283                                    MBMessage.class.getName(),
11284                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11285    
11286                    Session session = null;
11287    
11288                    try {
11289                            session = openSession();
11290    
11291                            SQLQuery q = session.createSQLQuery(sql);
11292    
11293                            if (getDB().isSupportsInlineDistinct()) {
11294                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11295                            }
11296                            else {
11297                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11298                            }
11299    
11300                            QueryPos qPos = QueryPos.getInstance(q);
11301    
11302                            qPos.add(groupId);
11303    
11304                            qPos.add(userId);
11305    
11306                            qPos.add(status);
11307    
11308                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11309                    }
11310                    catch (Exception e) {
11311                            throw processException(e);
11312                    }
11313                    finally {
11314                            closeSession(session);
11315                    }
11316            }
11317    
11318            /**
11319             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11320             *
11321             * @param messageId the primary key of the current message-boards message
11322             * @param groupId the group ID
11323             * @param userId the user ID
11324             * @param status the status
11325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11326             * @return the previous, current, and next message-boards message
11327             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11328             * @throws SystemException if a system exception occurred
11329             */
11330            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11331                    long groupId, long userId, int status,
11332                    OrderByComparator orderByComparator)
11333                    throws NoSuchMessageException, SystemException {
11334                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11335                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11336                                    orderByComparator);
11337                    }
11338    
11339                    MBMessage mbMessage = findByPrimaryKey(messageId);
11340    
11341                    Session session = null;
11342    
11343                    try {
11344                            session = openSession();
11345    
11346                            MBMessage[] array = new MBMessageImpl[3];
11347    
11348                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11349                                            groupId, userId, status, orderByComparator, true);
11350    
11351                            array[1] = mbMessage;
11352    
11353                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11354                                            groupId, userId, status, orderByComparator, false);
11355    
11356                            return array;
11357                    }
11358                    catch (Exception e) {
11359                            throw processException(e);
11360                    }
11361                    finally {
11362                            closeSession(session);
11363                    }
11364            }
11365    
11366            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11367                    MBMessage mbMessage, long groupId, long userId, int status,
11368                    OrderByComparator orderByComparator, boolean previous) {
11369                    StringBundler query = null;
11370    
11371                    if (orderByComparator != null) {
11372                            query = new StringBundler(6 +
11373                                            (orderByComparator.getOrderByFields().length * 6));
11374                    }
11375                    else {
11376                            query = new StringBundler(3);
11377                    }
11378    
11379                    if (getDB().isSupportsInlineDistinct()) {
11380                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11381                    }
11382                    else {
11383                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11384                    }
11385    
11386                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11387    
11388                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11389    
11390                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11391    
11392                    if (!getDB().isSupportsInlineDistinct()) {
11393                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11394                    }
11395    
11396                    if (orderByComparator != null) {
11397                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11398    
11399                            if (orderByConditionFields.length > 0) {
11400                                    query.append(WHERE_AND);
11401                            }
11402    
11403                            for (int i = 0; i < orderByConditionFields.length; i++) {
11404                                    if (getDB().isSupportsInlineDistinct()) {
11405                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11406                                    }
11407                                    else {
11408                                            query.append(_ORDER_BY_ENTITY_TABLE);
11409                                    }
11410    
11411                                    query.append(orderByConditionFields[i]);
11412    
11413                                    if ((i + 1) < orderByConditionFields.length) {
11414                                            if (orderByComparator.isAscending() ^ previous) {
11415                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11416                                            }
11417                                            else {
11418                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11419                                            }
11420                                    }
11421                                    else {
11422                                            if (orderByComparator.isAscending() ^ previous) {
11423                                                    query.append(WHERE_GREATER_THAN);
11424                                            }
11425                                            else {
11426                                                    query.append(WHERE_LESSER_THAN);
11427                                            }
11428                                    }
11429                            }
11430    
11431                            query.append(ORDER_BY_CLAUSE);
11432    
11433                            String[] orderByFields = orderByComparator.getOrderByFields();
11434    
11435                            for (int i = 0; i < orderByFields.length; i++) {
11436                                    if (getDB().isSupportsInlineDistinct()) {
11437                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11438                                    }
11439                                    else {
11440                                            query.append(_ORDER_BY_ENTITY_TABLE);
11441                                    }
11442    
11443                                    query.append(orderByFields[i]);
11444    
11445                                    if ((i + 1) < orderByFields.length) {
11446                                            if (orderByComparator.isAscending() ^ previous) {
11447                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11448                                            }
11449                                            else {
11450                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11451                                            }
11452                                    }
11453                                    else {
11454                                            if (orderByComparator.isAscending() ^ previous) {
11455                                                    query.append(ORDER_BY_ASC);
11456                                            }
11457                                            else {
11458                                                    query.append(ORDER_BY_DESC);
11459                                            }
11460                                    }
11461                            }
11462                    }
11463                    else {
11464                            if (getDB().isSupportsInlineDistinct()) {
11465                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11466                            }
11467                            else {
11468                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11469                            }
11470                    }
11471    
11472                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11473                                    MBMessage.class.getName(),
11474                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11475    
11476                    SQLQuery q = session.createSQLQuery(sql);
11477    
11478                    q.setFirstResult(0);
11479                    q.setMaxResults(2);
11480    
11481                    if (getDB().isSupportsInlineDistinct()) {
11482                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11483                    }
11484                    else {
11485                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11486                    }
11487    
11488                    QueryPos qPos = QueryPos.getInstance(q);
11489    
11490                    qPos.add(groupId);
11491    
11492                    qPos.add(userId);
11493    
11494                    qPos.add(status);
11495    
11496                    if (orderByComparator != null) {
11497                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11498    
11499                            for (Object value : values) {
11500                                    qPos.add(value);
11501                            }
11502                    }
11503    
11504                    List<MBMessage> list = q.list();
11505    
11506                    if (list.size() == 2) {
11507                            return list.get(1);
11508                    }
11509                    else {
11510                            return null;
11511                    }
11512            }
11513    
11514            /**
11515             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
11516             *
11517             * @param groupId the group ID
11518             * @param userId the user ID
11519             * @param status the status
11520             * @throws SystemException if a system exception occurred
11521             */
11522            public void removeByG_U_S(long groupId, long userId, int status)
11523                    throws SystemException {
11524                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
11525                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11526                            remove(mbMessage);
11527                    }
11528            }
11529    
11530            /**
11531             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11532             *
11533             * @param groupId the group ID
11534             * @param userId the user ID
11535             * @param status the status
11536             * @return the number of matching message-boards messages
11537             * @throws SystemException if a system exception occurred
11538             */
11539            public int countByG_U_S(long groupId, long userId, int status)
11540                    throws SystemException {
11541                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
11542    
11543                    Object[] finderArgs = new Object[] { groupId, userId, status };
11544    
11545                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11546                                    this);
11547    
11548                    if (count == null) {
11549                            StringBundler query = new StringBundler(4);
11550    
11551                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11552    
11553                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11554    
11555                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11556    
11557                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11558    
11559                            String sql = query.toString();
11560    
11561                            Session session = null;
11562    
11563                            try {
11564                                    session = openSession();
11565    
11566                                    Query q = session.createQuery(sql);
11567    
11568                                    QueryPos qPos = QueryPos.getInstance(q);
11569    
11570                                    qPos.add(groupId);
11571    
11572                                    qPos.add(userId);
11573    
11574                                    qPos.add(status);
11575    
11576                                    count = (Long)q.uniqueResult();
11577    
11578                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11579                            }
11580                            catch (Exception e) {
11581                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11582    
11583                                    throw processException(e);
11584                            }
11585                            finally {
11586                                    closeSession(session);
11587                            }
11588                    }
11589    
11590                    return count.intValue();
11591            }
11592    
11593            /**
11594             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11595             *
11596             * @param groupId the group ID
11597             * @param userId the user ID
11598             * @param status the status
11599             * @return the number of matching message-boards messages that the user has permission to view
11600             * @throws SystemException if a system exception occurred
11601             */
11602            public int filterCountByG_U_S(long groupId, long userId, int status)
11603                    throws SystemException {
11604                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11605                            return countByG_U_S(groupId, userId, status);
11606                    }
11607    
11608                    StringBundler query = new StringBundler(4);
11609    
11610                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
11611    
11612                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11613    
11614                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11615    
11616                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11617    
11618                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11619                                    MBMessage.class.getName(),
11620                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11621    
11622                    Session session = null;
11623    
11624                    try {
11625                            session = openSession();
11626    
11627                            SQLQuery q = session.createSQLQuery(sql);
11628    
11629                            q.addScalar(COUNT_COLUMN_NAME,
11630                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11631    
11632                            QueryPos qPos = QueryPos.getInstance(q);
11633    
11634                            qPos.add(groupId);
11635    
11636                            qPos.add(userId);
11637    
11638                            qPos.add(status);
11639    
11640                            Long count = (Long)q.uniqueResult();
11641    
11642                            return count.intValue();
11643                    }
11644                    catch (Exception e) {
11645                            throw processException(e);
11646                    }
11647                    finally {
11648                            closeSession(session);
11649                    }
11650            }
11651    
11652            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11653            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
11654            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
11655            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11656                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11657                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
11658                            new String[] {
11659                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
11660                                    
11661                            Integer.class.getName(), Integer.class.getName(),
11662                                    OrderByComparator.class.getName()
11663                            });
11664            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11665                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11666                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
11667                            new String[] {
11668                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11669                            },
11670                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11671                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
11672                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
11673                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11674            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11675                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11676                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
11677                            new String[] {
11678                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11679                            });
11680    
11681            /**
11682             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11683             *
11684             * @param groupId the group ID
11685             * @param categoryId the category ID
11686             * @param threadId the thread ID
11687             * @return the matching message-boards messages
11688             * @throws SystemException if a system exception occurred
11689             */
11690            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11691                    long threadId) throws SystemException {
11692                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
11693                            QueryUtil.ALL_POS, null);
11694            }
11695    
11696            /**
11697             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11698             *
11699             * <p>
11700             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11701             * </p>
11702             *
11703             * @param groupId the group ID
11704             * @param categoryId the category ID
11705             * @param threadId the thread ID
11706             * @param start the lower bound of the range of message-boards messages
11707             * @param end the upper bound of the range of message-boards messages (not inclusive)
11708             * @return the range of matching message-boards messages
11709             * @throws SystemException if a system exception occurred
11710             */
11711            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11712                    long threadId, int start, int end) throws SystemException {
11713                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
11714            }
11715    
11716            /**
11717             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11718             *
11719             * <p>
11720             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
11721             * </p>
11722             *
11723             * @param groupId the group ID
11724             * @param categoryId the category ID
11725             * @param threadId the thread ID
11726             * @param start the lower bound of the range of message-boards messages
11727             * @param end the upper bound of the range of message-boards messages (not inclusive)
11728             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11729             * @return the ordered range of matching message-boards messages
11730             * @throws SystemException if a system exception occurred
11731             */
11732            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11733                    long threadId, int start, int end, OrderByComparator orderByComparator)
11734                    throws SystemException {
11735                    boolean pagination = true;
11736                    FinderPath finderPath = null;
11737                    Object[] finderArgs = null;
11738    
11739                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11740                                    (orderByComparator == null)) {
11741                            pagination = false;
11742                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
11743                            finderArgs = new Object[] { groupId, categoryId, threadId };
11744                    }
11745                    else {
11746                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
11747                            finderArgs = new Object[] {
11748                                            groupId, categoryId, threadId,
11749                                            
11750                                            start, end, orderByComparator
11751                                    };
11752                    }
11753    
11754                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11755                                    finderArgs, this);
11756    
11757                    if ((list != null) && !list.isEmpty()) {
11758                            for (MBMessage mbMessage : list) {
11759                                    if ((groupId != mbMessage.getGroupId()) ||
11760                                                    (categoryId != mbMessage.getCategoryId()) ||
11761                                                    (threadId != mbMessage.getThreadId())) {
11762                                            list = null;
11763    
11764                                            break;
11765                                    }
11766                            }
11767                    }
11768    
11769                    if (list == null) {
11770                            StringBundler query = null;
11771    
11772                            if (orderByComparator != null) {
11773                                    query = new StringBundler(5 +
11774                                                    (orderByComparator.getOrderByFields().length * 3));
11775                            }
11776                            else {
11777                                    query = new StringBundler(5);
11778                            }
11779    
11780                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11781    
11782                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11783    
11784                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11785    
11786                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11787    
11788                            if (orderByComparator != null) {
11789                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11790                                            orderByComparator);
11791                            }
11792                            else
11793                             if (pagination) {
11794                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11795                            }
11796    
11797                            String sql = query.toString();
11798    
11799                            Session session = null;
11800    
11801                            try {
11802                                    session = openSession();
11803    
11804                                    Query q = session.createQuery(sql);
11805    
11806                                    QueryPos qPos = QueryPos.getInstance(q);
11807    
11808                                    qPos.add(groupId);
11809    
11810                                    qPos.add(categoryId);
11811    
11812                                    qPos.add(threadId);
11813    
11814                                    if (!pagination) {
11815                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11816                                                            start, end, false);
11817    
11818                                            Collections.sort(list);
11819    
11820                                            list = new UnmodifiableList<MBMessage>(list);
11821                                    }
11822                                    else {
11823                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11824                                                            start, end);
11825                                    }
11826    
11827                                    cacheResult(list);
11828    
11829                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11830                            }
11831                            catch (Exception e) {
11832                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11833    
11834                                    throw processException(e);
11835                            }
11836                            finally {
11837                                    closeSession(session);
11838                            }
11839                    }
11840    
11841                    return list;
11842            }
11843    
11844            /**
11845             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11846             *
11847             * @param groupId the group ID
11848             * @param categoryId the category ID
11849             * @param threadId the thread ID
11850             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11851             * @return the first matching message-boards message
11852             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11853             * @throws SystemException if a system exception occurred
11854             */
11855            public MBMessage findByG_C_T_First(long groupId, long categoryId,
11856                    long threadId, OrderByComparator orderByComparator)
11857                    throws NoSuchMessageException, SystemException {
11858                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
11859                                    orderByComparator);
11860    
11861                    if (mbMessage != null) {
11862                            return mbMessage;
11863                    }
11864    
11865                    StringBundler msg = new StringBundler(8);
11866    
11867                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11868    
11869                    msg.append("groupId=");
11870                    msg.append(groupId);
11871    
11872                    msg.append(", categoryId=");
11873                    msg.append(categoryId);
11874    
11875                    msg.append(", threadId=");
11876                    msg.append(threadId);
11877    
11878                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11879    
11880                    throw new NoSuchMessageException(msg.toString());
11881            }
11882    
11883            /**
11884             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11885             *
11886             * @param groupId the group ID
11887             * @param categoryId the category ID
11888             * @param threadId the thread ID
11889             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11890             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11891             * @throws SystemException if a system exception occurred
11892             */
11893            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
11894                    long threadId, OrderByComparator orderByComparator)
11895                    throws SystemException {
11896                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
11897                                    orderByComparator);
11898    
11899                    if (!list.isEmpty()) {
11900                            return list.get(0);
11901                    }
11902    
11903                    return null;
11904            }
11905    
11906            /**
11907             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11908             *
11909             * @param groupId the group ID
11910             * @param categoryId the category ID
11911             * @param threadId the thread ID
11912             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11913             * @return the last matching message-boards message
11914             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11915             * @throws SystemException if a system exception occurred
11916             */
11917            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
11918                    long threadId, OrderByComparator orderByComparator)
11919                    throws NoSuchMessageException, SystemException {
11920                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
11921                                    orderByComparator);
11922    
11923                    if (mbMessage != null) {
11924                            return mbMessage;
11925                    }
11926    
11927                    StringBundler msg = new StringBundler(8);
11928    
11929                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11930    
11931                    msg.append("groupId=");
11932                    msg.append(groupId);
11933    
11934                    msg.append(", categoryId=");
11935                    msg.append(categoryId);
11936    
11937                    msg.append(", threadId=");
11938                    msg.append(threadId);
11939    
11940                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11941    
11942                    throw new NoSuchMessageException(msg.toString());
11943            }
11944    
11945            /**
11946             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11947             *
11948             * @param groupId the group ID
11949             * @param categoryId the category ID
11950             * @param threadId the thread ID
11951             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11952             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11953             * @throws SystemException if a system exception occurred
11954             */
11955            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
11956                    long threadId, OrderByComparator orderByComparator)
11957                    throws SystemException {
11958                    int count = countByG_C_T(groupId, categoryId, threadId);
11959    
11960                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
11961                                    count - 1, count, orderByComparator);
11962    
11963                    if (!list.isEmpty()) {
11964                            return list.get(0);
11965                    }
11966    
11967                    return null;
11968            }
11969    
11970            /**
11971             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11972             *
11973             * @param messageId the primary key of the current message-boards message
11974             * @param groupId the group ID
11975             * @param categoryId the category ID
11976             * @param threadId the thread ID
11977             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11978             * @return the previous, current, and next message-boards message
11979             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11980             * @throws SystemException if a system exception occurred
11981             */
11982            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
11983                    long categoryId, long threadId, OrderByComparator orderByComparator)
11984                    throws NoSuchMessageException, SystemException {
11985                    MBMessage mbMessage = findByPrimaryKey(messageId);
11986    
11987                    Session session = null;
11988    
11989                    try {
11990                            session = openSession();
11991    
11992                            MBMessage[] array = new MBMessageImpl[3];
11993    
11994                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11995                                            categoryId, threadId, orderByComparator, true);
11996    
11997                            array[1] = mbMessage;
11998    
11999                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12000                                            categoryId, threadId, orderByComparator, false);
12001    
12002                            return array;
12003                    }
12004                    catch (Exception e) {
12005                            throw processException(e);
12006                    }
12007                    finally {
12008                            closeSession(session);
12009                    }
12010            }
12011    
12012            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12013                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12014                    OrderByComparator orderByComparator, boolean previous) {
12015                    StringBundler query = null;
12016    
12017                    if (orderByComparator != null) {
12018                            query = new StringBundler(6 +
12019                                            (orderByComparator.getOrderByFields().length * 6));
12020                    }
12021                    else {
12022                            query = new StringBundler(3);
12023                    }
12024    
12025                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12026    
12027                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12028    
12029                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12030    
12031                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12032    
12033                    if (orderByComparator != null) {
12034                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12035    
12036                            if (orderByConditionFields.length > 0) {
12037                                    query.append(WHERE_AND);
12038                            }
12039    
12040                            for (int i = 0; i < orderByConditionFields.length; i++) {
12041                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12042                                    query.append(orderByConditionFields[i]);
12043    
12044                                    if ((i + 1) < orderByConditionFields.length) {
12045                                            if (orderByComparator.isAscending() ^ previous) {
12046                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12047                                            }
12048                                            else {
12049                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12050                                            }
12051                                    }
12052                                    else {
12053                                            if (orderByComparator.isAscending() ^ previous) {
12054                                                    query.append(WHERE_GREATER_THAN);
12055                                            }
12056                                            else {
12057                                                    query.append(WHERE_LESSER_THAN);
12058                                            }
12059                                    }
12060                            }
12061    
12062                            query.append(ORDER_BY_CLAUSE);
12063    
12064                            String[] orderByFields = orderByComparator.getOrderByFields();
12065    
12066                            for (int i = 0; i < orderByFields.length; i++) {
12067                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12068                                    query.append(orderByFields[i]);
12069    
12070                                    if ((i + 1) < orderByFields.length) {
12071                                            if (orderByComparator.isAscending() ^ previous) {
12072                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12073                                            }
12074                                            else {
12075                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12076                                            }
12077                                    }
12078                                    else {
12079                                            if (orderByComparator.isAscending() ^ previous) {
12080                                                    query.append(ORDER_BY_ASC);
12081                                            }
12082                                            else {
12083                                                    query.append(ORDER_BY_DESC);
12084                                            }
12085                                    }
12086                            }
12087                    }
12088                    else {
12089                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12090                    }
12091    
12092                    String sql = query.toString();
12093    
12094                    Query q = session.createQuery(sql);
12095    
12096                    q.setFirstResult(0);
12097                    q.setMaxResults(2);
12098    
12099                    QueryPos qPos = QueryPos.getInstance(q);
12100    
12101                    qPos.add(groupId);
12102    
12103                    qPos.add(categoryId);
12104    
12105                    qPos.add(threadId);
12106    
12107                    if (orderByComparator != null) {
12108                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12109    
12110                            for (Object value : values) {
12111                                    qPos.add(value);
12112                            }
12113                    }
12114    
12115                    List<MBMessage> list = q.list();
12116    
12117                    if (list.size() == 2) {
12118                            return list.get(1);
12119                    }
12120                    else {
12121                            return null;
12122                    }
12123            }
12124    
12125            /**
12126             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12127             *
12128             * @param groupId the group ID
12129             * @param categoryId the category ID
12130             * @param threadId the thread ID
12131             * @return the matching message-boards messages that the user has permission to view
12132             * @throws SystemException if a system exception occurred
12133             */
12134            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12135                    long threadId) throws SystemException {
12136                    return filterFindByG_C_T(groupId, categoryId, threadId,
12137                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12138            }
12139    
12140            /**
12141             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12142             *
12143             * <p>
12144             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12145             * </p>
12146             *
12147             * @param groupId the group ID
12148             * @param categoryId the category ID
12149             * @param threadId the thread ID
12150             * @param start the lower bound of the range of message-boards messages
12151             * @param end the upper bound of the range of message-boards messages (not inclusive)
12152             * @return the range of matching message-boards messages that the user has permission to view
12153             * @throws SystemException if a system exception occurred
12154             */
12155            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12156                    long threadId, int start, int end) throws SystemException {
12157                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12158            }
12159    
12160            /**
12161             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12162             *
12163             * <p>
12164             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12165             * </p>
12166             *
12167             * @param groupId the group ID
12168             * @param categoryId the category ID
12169             * @param threadId the thread ID
12170             * @param start the lower bound of the range of message-boards messages
12171             * @param end the upper bound of the range of message-boards messages (not inclusive)
12172             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12173             * @return the ordered range of matching message-boards messages that the user has permission to view
12174             * @throws SystemException if a system exception occurred
12175             */
12176            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12177                    long threadId, int start, int end, OrderByComparator orderByComparator)
12178                    throws SystemException {
12179                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12180                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12181                                    orderByComparator);
12182                    }
12183    
12184                    StringBundler query = null;
12185    
12186                    if (orderByComparator != null) {
12187                            query = new StringBundler(5 +
12188                                            (orderByComparator.getOrderByFields().length * 3));
12189                    }
12190                    else {
12191                            query = new StringBundler(5);
12192                    }
12193    
12194                    if (getDB().isSupportsInlineDistinct()) {
12195                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12196                    }
12197                    else {
12198                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12199                    }
12200    
12201                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12202    
12203                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12204    
12205                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12206    
12207                    if (!getDB().isSupportsInlineDistinct()) {
12208                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12209                    }
12210    
12211                    if (orderByComparator != null) {
12212                            if (getDB().isSupportsInlineDistinct()) {
12213                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12214                                            orderByComparator);
12215                            }
12216                            else {
12217                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12218                                            orderByComparator);
12219                            }
12220                    }
12221                    else {
12222                            if (getDB().isSupportsInlineDistinct()) {
12223                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12224                            }
12225                            else {
12226                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12227                            }
12228                    }
12229    
12230                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12231                                    MBMessage.class.getName(),
12232                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12233    
12234                    Session session = null;
12235    
12236                    try {
12237                            session = openSession();
12238    
12239                            SQLQuery q = session.createSQLQuery(sql);
12240    
12241                            if (getDB().isSupportsInlineDistinct()) {
12242                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12243                            }
12244                            else {
12245                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12246                            }
12247    
12248                            QueryPos qPos = QueryPos.getInstance(q);
12249    
12250                            qPos.add(groupId);
12251    
12252                            qPos.add(categoryId);
12253    
12254                            qPos.add(threadId);
12255    
12256                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12257                    }
12258                    catch (Exception e) {
12259                            throw processException(e);
12260                    }
12261                    finally {
12262                            closeSession(session);
12263                    }
12264            }
12265    
12266            /**
12267             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12268             *
12269             * @param messageId the primary key of the current message-boards message
12270             * @param groupId the group ID
12271             * @param categoryId the category ID
12272             * @param threadId the thread ID
12273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12274             * @return the previous, current, and next message-boards message
12275             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12276             * @throws SystemException if a system exception occurred
12277             */
12278            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12279                    long groupId, long categoryId, long threadId,
12280                    OrderByComparator orderByComparator)
12281                    throws NoSuchMessageException, SystemException {
12282                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12283                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12284                                    threadId, orderByComparator);
12285                    }
12286    
12287                    MBMessage mbMessage = findByPrimaryKey(messageId);
12288    
12289                    Session session = null;
12290    
12291                    try {
12292                            session = openSession();
12293    
12294                            MBMessage[] array = new MBMessageImpl[3];
12295    
12296                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12297                                            groupId, categoryId, threadId, orderByComparator, true);
12298    
12299                            array[1] = mbMessage;
12300    
12301                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12302                                            groupId, categoryId, threadId, orderByComparator, false);
12303    
12304                            return array;
12305                    }
12306                    catch (Exception e) {
12307                            throw processException(e);
12308                    }
12309                    finally {
12310                            closeSession(session);
12311                    }
12312            }
12313    
12314            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12315                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12316                    OrderByComparator orderByComparator, boolean previous) {
12317                    StringBundler query = null;
12318    
12319                    if (orderByComparator != null) {
12320                            query = new StringBundler(6 +
12321                                            (orderByComparator.getOrderByFields().length * 6));
12322                    }
12323                    else {
12324                            query = new StringBundler(3);
12325                    }
12326    
12327                    if (getDB().isSupportsInlineDistinct()) {
12328                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12329                    }
12330                    else {
12331                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12332                    }
12333    
12334                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12335    
12336                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12337    
12338                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12339    
12340                    if (!getDB().isSupportsInlineDistinct()) {
12341                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12342                    }
12343    
12344                    if (orderByComparator != null) {
12345                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12346    
12347                            if (orderByConditionFields.length > 0) {
12348                                    query.append(WHERE_AND);
12349                            }
12350    
12351                            for (int i = 0; i < orderByConditionFields.length; i++) {
12352                                    if (getDB().isSupportsInlineDistinct()) {
12353                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12354                                    }
12355                                    else {
12356                                            query.append(_ORDER_BY_ENTITY_TABLE);
12357                                    }
12358    
12359                                    query.append(orderByConditionFields[i]);
12360    
12361                                    if ((i + 1) < orderByConditionFields.length) {
12362                                            if (orderByComparator.isAscending() ^ previous) {
12363                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12364                                            }
12365                                            else {
12366                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12367                                            }
12368                                    }
12369                                    else {
12370                                            if (orderByComparator.isAscending() ^ previous) {
12371                                                    query.append(WHERE_GREATER_THAN);
12372                                            }
12373                                            else {
12374                                                    query.append(WHERE_LESSER_THAN);
12375                                            }
12376                                    }
12377                            }
12378    
12379                            query.append(ORDER_BY_CLAUSE);
12380    
12381                            String[] orderByFields = orderByComparator.getOrderByFields();
12382    
12383                            for (int i = 0; i < orderByFields.length; i++) {
12384                                    if (getDB().isSupportsInlineDistinct()) {
12385                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12386                                    }
12387                                    else {
12388                                            query.append(_ORDER_BY_ENTITY_TABLE);
12389                                    }
12390    
12391                                    query.append(orderByFields[i]);
12392    
12393                                    if ((i + 1) < orderByFields.length) {
12394                                            if (orderByComparator.isAscending() ^ previous) {
12395                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12396                                            }
12397                                            else {
12398                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12399                                            }
12400                                    }
12401                                    else {
12402                                            if (orderByComparator.isAscending() ^ previous) {
12403                                                    query.append(ORDER_BY_ASC);
12404                                            }
12405                                            else {
12406                                                    query.append(ORDER_BY_DESC);
12407                                            }
12408                                    }
12409                            }
12410                    }
12411                    else {
12412                            if (getDB().isSupportsInlineDistinct()) {
12413                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12414                            }
12415                            else {
12416                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12417                            }
12418                    }
12419    
12420                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12421                                    MBMessage.class.getName(),
12422                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12423    
12424                    SQLQuery q = session.createSQLQuery(sql);
12425    
12426                    q.setFirstResult(0);
12427                    q.setMaxResults(2);
12428    
12429                    if (getDB().isSupportsInlineDistinct()) {
12430                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12431                    }
12432                    else {
12433                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12434                    }
12435    
12436                    QueryPos qPos = QueryPos.getInstance(q);
12437    
12438                    qPos.add(groupId);
12439    
12440                    qPos.add(categoryId);
12441    
12442                    qPos.add(threadId);
12443    
12444                    if (orderByComparator != null) {
12445                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12446    
12447                            for (Object value : values) {
12448                                    qPos.add(value);
12449                            }
12450                    }
12451    
12452                    List<MBMessage> list = q.list();
12453    
12454                    if (list.size() == 2) {
12455                            return list.get(1);
12456                    }
12457                    else {
12458                            return null;
12459                    }
12460            }
12461    
12462            /**
12463             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
12464             *
12465             * @param groupId the group ID
12466             * @param categoryId the category ID
12467             * @param threadId the thread ID
12468             * @throws SystemException if a system exception occurred
12469             */
12470            public void removeByG_C_T(long groupId, long categoryId, long threadId)
12471                    throws SystemException {
12472                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12473                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12474                            remove(mbMessage);
12475                    }
12476            }
12477    
12478            /**
12479             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12480             *
12481             * @param groupId the group ID
12482             * @param categoryId the category ID
12483             * @param threadId the thread ID
12484             * @return the number of matching message-boards messages
12485             * @throws SystemException if a system exception occurred
12486             */
12487            public int countByG_C_T(long groupId, long categoryId, long threadId)
12488                    throws SystemException {
12489                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
12490    
12491                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
12492    
12493                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12494                                    this);
12495    
12496                    if (count == null) {
12497                            StringBundler query = new StringBundler(4);
12498    
12499                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12500    
12501                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12502    
12503                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12504    
12505                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12506    
12507                            String sql = query.toString();
12508    
12509                            Session session = null;
12510    
12511                            try {
12512                                    session = openSession();
12513    
12514                                    Query q = session.createQuery(sql);
12515    
12516                                    QueryPos qPos = QueryPos.getInstance(q);
12517    
12518                                    qPos.add(groupId);
12519    
12520                                    qPos.add(categoryId);
12521    
12522                                    qPos.add(threadId);
12523    
12524                                    count = (Long)q.uniqueResult();
12525    
12526                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12527                            }
12528                            catch (Exception e) {
12529                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12530    
12531                                    throw processException(e);
12532                            }
12533                            finally {
12534                                    closeSession(session);
12535                            }
12536                    }
12537    
12538                    return count.intValue();
12539            }
12540    
12541            /**
12542             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12543             *
12544             * @param groupId the group ID
12545             * @param categoryId the category ID
12546             * @param threadId the thread ID
12547             * @return the number of matching message-boards messages that the user has permission to view
12548             * @throws SystemException if a system exception occurred
12549             */
12550            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
12551                    throws SystemException {
12552                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12553                            return countByG_C_T(groupId, categoryId, threadId);
12554                    }
12555    
12556                    StringBundler query = new StringBundler(4);
12557    
12558                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12559    
12560                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12561    
12562                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12563    
12564                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12565    
12566                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12567                                    MBMessage.class.getName(),
12568                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12569    
12570                    Session session = null;
12571    
12572                    try {
12573                            session = openSession();
12574    
12575                            SQLQuery q = session.createSQLQuery(sql);
12576    
12577                            q.addScalar(COUNT_COLUMN_NAME,
12578                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12579    
12580                            QueryPos qPos = QueryPos.getInstance(q);
12581    
12582                            qPos.add(groupId);
12583    
12584                            qPos.add(categoryId);
12585    
12586                            qPos.add(threadId);
12587    
12588                            Long count = (Long)q.uniqueResult();
12589    
12590                            return count.intValue();
12591                    }
12592                    catch (Exception e) {
12593                            throw processException(e);
12594                    }
12595                    finally {
12596                            closeSession(session);
12597                    }
12598            }
12599    
12600            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
12601            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
12602            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
12603            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12604                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12605                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
12606                            new String[] {
12607                                    Long.class.getName(), Long.class.getName(),
12608                                    Integer.class.getName(),
12609                                    
12610                            Integer.class.getName(), Integer.class.getName(),
12611                                    OrderByComparator.class.getName()
12612                            });
12613            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12614                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12615                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
12616                            new String[] {
12617                                    Long.class.getName(), Long.class.getName(),
12618                                    Integer.class.getName()
12619                            },
12620                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12621                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12622                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
12623                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12624            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12625                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12626                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
12627                            new String[] {
12628                                    Long.class.getName(), Long.class.getName(),
12629                                    Integer.class.getName()
12630                            });
12631    
12632            /**
12633             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12634             *
12635             * @param groupId the group ID
12636             * @param categoryId the category ID
12637             * @param status the status
12638             * @return the matching message-boards messages
12639             * @throws SystemException if a system exception occurred
12640             */
12641            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
12642                    throws SystemException {
12643                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
12644                            QueryUtil.ALL_POS, null);
12645            }
12646    
12647            /**
12648             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12649             *
12650             * <p>
12651             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12652             * </p>
12653             *
12654             * @param groupId the group ID
12655             * @param categoryId the category ID
12656             * @param status the status
12657             * @param start the lower bound of the range of message-boards messages
12658             * @param end the upper bound of the range of message-boards messages (not inclusive)
12659             * @return the range of matching message-boards messages
12660             * @throws SystemException if a system exception occurred
12661             */
12662            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12663                    int status, int start, int end) throws SystemException {
12664                    return findByG_C_S(groupId, categoryId, status, start, end, null);
12665            }
12666    
12667            /**
12668             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12669             *
12670             * <p>
12671             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
12672             * </p>
12673             *
12674             * @param groupId the group ID
12675             * @param categoryId the category ID
12676             * @param status the status
12677             * @param start the lower bound of the range of message-boards messages
12678             * @param end the upper bound of the range of message-boards messages (not inclusive)
12679             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12680             * @return the ordered range of matching message-boards messages
12681             * @throws SystemException if a system exception occurred
12682             */
12683            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12684                    int status, int start, int end, OrderByComparator orderByComparator)
12685                    throws SystemException {
12686                    boolean pagination = true;
12687                    FinderPath finderPath = null;
12688                    Object[] finderArgs = null;
12689    
12690                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12691                                    (orderByComparator == null)) {
12692                            pagination = false;
12693                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
12694                            finderArgs = new Object[] { groupId, categoryId, status };
12695                    }
12696                    else {
12697                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
12698                            finderArgs = new Object[] {
12699                                            groupId, categoryId, status,
12700                                            
12701                                            start, end, orderByComparator
12702                                    };
12703                    }
12704    
12705                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12706                                    finderArgs, this);
12707    
12708                    if ((list != null) && !list.isEmpty()) {
12709                            for (MBMessage mbMessage : list) {
12710                                    if ((groupId != mbMessage.getGroupId()) ||
12711                                                    (categoryId != mbMessage.getCategoryId()) ||
12712                                                    (status != mbMessage.getStatus())) {
12713                                            list = null;
12714    
12715                                            break;
12716                                    }
12717                            }
12718                    }
12719    
12720                    if (list == null) {
12721                            StringBundler query = null;
12722    
12723                            if (orderByComparator != null) {
12724                                    query = new StringBundler(5 +
12725                                                    (orderByComparator.getOrderByFields().length * 3));
12726                            }
12727                            else {
12728                                    query = new StringBundler(5);
12729                            }
12730    
12731                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12732    
12733                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12734    
12735                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12736    
12737                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12738    
12739                            if (orderByComparator != null) {
12740                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12741                                            orderByComparator);
12742                            }
12743                            else
12744                             if (pagination) {
12745                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12746                            }
12747    
12748                            String sql = query.toString();
12749    
12750                            Session session = null;
12751    
12752                            try {
12753                                    session = openSession();
12754    
12755                                    Query q = session.createQuery(sql);
12756    
12757                                    QueryPos qPos = QueryPos.getInstance(q);
12758    
12759                                    qPos.add(groupId);
12760    
12761                                    qPos.add(categoryId);
12762    
12763                                    qPos.add(status);
12764    
12765                                    if (!pagination) {
12766                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12767                                                            start, end, false);
12768    
12769                                            Collections.sort(list);
12770    
12771                                            list = new UnmodifiableList<MBMessage>(list);
12772                                    }
12773                                    else {
12774                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12775                                                            start, end);
12776                                    }
12777    
12778                                    cacheResult(list);
12779    
12780                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12781                            }
12782                            catch (Exception e) {
12783                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12784    
12785                                    throw processException(e);
12786                            }
12787                            finally {
12788                                    closeSession(session);
12789                            }
12790                    }
12791    
12792                    return list;
12793            }
12794    
12795            /**
12796             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12797             *
12798             * @param groupId the group ID
12799             * @param categoryId the category ID
12800             * @param status the status
12801             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12802             * @return the first matching message-boards message
12803             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12804             * @throws SystemException if a system exception occurred
12805             */
12806            public MBMessage findByG_C_S_First(long groupId, long categoryId,
12807                    int status, OrderByComparator orderByComparator)
12808                    throws NoSuchMessageException, SystemException {
12809                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
12810                                    orderByComparator);
12811    
12812                    if (mbMessage != null) {
12813                            return mbMessage;
12814                    }
12815    
12816                    StringBundler msg = new StringBundler(8);
12817    
12818                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12819    
12820                    msg.append("groupId=");
12821                    msg.append(groupId);
12822    
12823                    msg.append(", categoryId=");
12824                    msg.append(categoryId);
12825    
12826                    msg.append(", status=");
12827                    msg.append(status);
12828    
12829                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12830    
12831                    throw new NoSuchMessageException(msg.toString());
12832            }
12833    
12834            /**
12835             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12836             *
12837             * @param groupId the group ID
12838             * @param categoryId the category ID
12839             * @param status the status
12840             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12841             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12842             * @throws SystemException if a system exception occurred
12843             */
12844            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
12845                    int status, OrderByComparator orderByComparator)
12846                    throws SystemException {
12847                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
12848                                    orderByComparator);
12849    
12850                    if (!list.isEmpty()) {
12851                            return list.get(0);
12852                    }
12853    
12854                    return null;
12855            }
12856    
12857            /**
12858             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12859             *
12860             * @param groupId the group ID
12861             * @param categoryId the category ID
12862             * @param status the status
12863             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12864             * @return the last matching message-boards message
12865             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12866             * @throws SystemException if a system exception occurred
12867             */
12868            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
12869                    int status, OrderByComparator orderByComparator)
12870                    throws NoSuchMessageException, SystemException {
12871                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
12872                                    orderByComparator);
12873    
12874                    if (mbMessage != null) {
12875                            return mbMessage;
12876                    }
12877    
12878                    StringBundler msg = new StringBundler(8);
12879    
12880                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12881    
12882                    msg.append("groupId=");
12883                    msg.append(groupId);
12884    
12885                    msg.append(", categoryId=");
12886                    msg.append(categoryId);
12887    
12888                    msg.append(", status=");
12889                    msg.append(status);
12890    
12891                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12892    
12893                    throw new NoSuchMessageException(msg.toString());
12894            }
12895    
12896            /**
12897             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12898             *
12899             * @param groupId the group ID
12900             * @param categoryId the category ID
12901             * @param status the status
12902             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12903             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12904             * @throws SystemException if a system exception occurred
12905             */
12906            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
12907                    int status, OrderByComparator orderByComparator)
12908                    throws SystemException {
12909                    int count = countByG_C_S(groupId, categoryId, status);
12910    
12911                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
12912                                    count - 1, count, orderByComparator);
12913    
12914                    if (!list.isEmpty()) {
12915                            return list.get(0);
12916                    }
12917    
12918                    return null;
12919            }
12920    
12921            /**
12922             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12923             *
12924             * @param messageId the primary key of the current message-boards message
12925             * @param groupId the group ID
12926             * @param categoryId the category ID
12927             * @param status the status
12928             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12929             * @return the previous, current, and next message-boards message
12930             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12931             * @throws SystemException if a system exception occurred
12932             */
12933            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
12934                    long categoryId, int status, OrderByComparator orderByComparator)
12935                    throws NoSuchMessageException, SystemException {
12936                    MBMessage mbMessage = findByPrimaryKey(messageId);
12937    
12938                    Session session = null;
12939    
12940                    try {
12941                            session = openSession();
12942    
12943                            MBMessage[] array = new MBMessageImpl[3];
12944    
12945                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12946                                            categoryId, status, orderByComparator, true);
12947    
12948                            array[1] = mbMessage;
12949    
12950                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12951                                            categoryId, status, orderByComparator, false);
12952    
12953                            return array;
12954                    }
12955                    catch (Exception e) {
12956                            throw processException(e);
12957                    }
12958                    finally {
12959                            closeSession(session);
12960                    }
12961            }
12962    
12963            protected MBMessage getByG_C_S_PrevAndNext(Session session,
12964                    MBMessage mbMessage, long groupId, long categoryId, int status,
12965                    OrderByComparator orderByComparator, boolean previous) {
12966                    StringBundler query = null;
12967    
12968                    if (orderByComparator != null) {
12969                            query = new StringBundler(6 +
12970                                            (orderByComparator.getOrderByFields().length * 6));
12971                    }
12972                    else {
12973                            query = new StringBundler(3);
12974                    }
12975    
12976                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12977    
12978                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12979    
12980                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12981    
12982                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12983    
12984                    if (orderByComparator != null) {
12985                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12986    
12987                            if (orderByConditionFields.length > 0) {
12988                                    query.append(WHERE_AND);
12989                            }
12990    
12991                            for (int i = 0; i < orderByConditionFields.length; i++) {
12992                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12993                                    query.append(orderByConditionFields[i]);
12994    
12995                                    if ((i + 1) < orderByConditionFields.length) {
12996                                            if (orderByComparator.isAscending() ^ previous) {
12997                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12998                                            }
12999                                            else {
13000                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13001                                            }
13002                                    }
13003                                    else {
13004                                            if (orderByComparator.isAscending() ^ previous) {
13005                                                    query.append(WHERE_GREATER_THAN);
13006                                            }
13007                                            else {
13008                                                    query.append(WHERE_LESSER_THAN);
13009                                            }
13010                                    }
13011                            }
13012    
13013                            query.append(ORDER_BY_CLAUSE);
13014    
13015                            String[] orderByFields = orderByComparator.getOrderByFields();
13016    
13017                            for (int i = 0; i < orderByFields.length; i++) {
13018                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13019                                    query.append(orderByFields[i]);
13020    
13021                                    if ((i + 1) < orderByFields.length) {
13022                                            if (orderByComparator.isAscending() ^ previous) {
13023                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13024                                            }
13025                                            else {
13026                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13027                                            }
13028                                    }
13029                                    else {
13030                                            if (orderByComparator.isAscending() ^ previous) {
13031                                                    query.append(ORDER_BY_ASC);
13032                                            }
13033                                            else {
13034                                                    query.append(ORDER_BY_DESC);
13035                                            }
13036                                    }
13037                            }
13038                    }
13039                    else {
13040                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13041                    }
13042    
13043                    String sql = query.toString();
13044    
13045                    Query q = session.createQuery(sql);
13046    
13047                    q.setFirstResult(0);
13048                    q.setMaxResults(2);
13049    
13050                    QueryPos qPos = QueryPos.getInstance(q);
13051    
13052                    qPos.add(groupId);
13053    
13054                    qPos.add(categoryId);
13055    
13056                    qPos.add(status);
13057    
13058                    if (orderByComparator != null) {
13059                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13060    
13061                            for (Object value : values) {
13062                                    qPos.add(value);
13063                            }
13064                    }
13065    
13066                    List<MBMessage> list = q.list();
13067    
13068                    if (list.size() == 2) {
13069                            return list.get(1);
13070                    }
13071                    else {
13072                            return null;
13073                    }
13074            }
13075    
13076            /**
13077             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13078             *
13079             * @param groupId the group ID
13080             * @param categoryId the category ID
13081             * @param status the status
13082             * @return the matching message-boards messages that the user has permission to view
13083             * @throws SystemException if a system exception occurred
13084             */
13085            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13086                    int status) throws SystemException {
13087                    return filterFindByG_C_S(groupId, categoryId, status,
13088                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13089            }
13090    
13091            /**
13092             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13093             *
13094             * <p>
13095             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13096             * </p>
13097             *
13098             * @param groupId the group ID
13099             * @param categoryId the category ID
13100             * @param status the status
13101             * @param start the lower bound of the range of message-boards messages
13102             * @param end the upper bound of the range of message-boards messages (not inclusive)
13103             * @return the range of matching message-boards messages that the user has permission to view
13104             * @throws SystemException if a system exception occurred
13105             */
13106            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13107                    int status, int start, int end) throws SystemException {
13108                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13109            }
13110    
13111            /**
13112             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13113             *
13114             * <p>
13115             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13116             * </p>
13117             *
13118             * @param groupId the group ID
13119             * @param categoryId the category ID
13120             * @param status the status
13121             * @param start the lower bound of the range of message-boards messages
13122             * @param end the upper bound of the range of message-boards messages (not inclusive)
13123             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13124             * @return the ordered range of matching message-boards messages that the user has permission to view
13125             * @throws SystemException if a system exception occurred
13126             */
13127            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13128                    int status, int start, int end, OrderByComparator orderByComparator)
13129                    throws SystemException {
13130                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13131                            return findByG_C_S(groupId, categoryId, status, start, end,
13132                                    orderByComparator);
13133                    }
13134    
13135                    StringBundler query = null;
13136    
13137                    if (orderByComparator != null) {
13138                            query = new StringBundler(5 +
13139                                            (orderByComparator.getOrderByFields().length * 3));
13140                    }
13141                    else {
13142                            query = new StringBundler(5);
13143                    }
13144    
13145                    if (getDB().isSupportsInlineDistinct()) {
13146                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13147                    }
13148                    else {
13149                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13150                    }
13151    
13152                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13153    
13154                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13155    
13156                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13157    
13158                    if (!getDB().isSupportsInlineDistinct()) {
13159                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13160                    }
13161    
13162                    if (orderByComparator != null) {
13163                            if (getDB().isSupportsInlineDistinct()) {
13164                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13165                                            orderByComparator);
13166                            }
13167                            else {
13168                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13169                                            orderByComparator);
13170                            }
13171                    }
13172                    else {
13173                            if (getDB().isSupportsInlineDistinct()) {
13174                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13175                            }
13176                            else {
13177                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13178                            }
13179                    }
13180    
13181                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13182                                    MBMessage.class.getName(),
13183                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13184    
13185                    Session session = null;
13186    
13187                    try {
13188                            session = openSession();
13189    
13190                            SQLQuery q = session.createSQLQuery(sql);
13191    
13192                            if (getDB().isSupportsInlineDistinct()) {
13193                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13194                            }
13195                            else {
13196                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13197                            }
13198    
13199                            QueryPos qPos = QueryPos.getInstance(q);
13200    
13201                            qPos.add(groupId);
13202    
13203                            qPos.add(categoryId);
13204    
13205                            qPos.add(status);
13206    
13207                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13208                    }
13209                    catch (Exception e) {
13210                            throw processException(e);
13211                    }
13212                    finally {
13213                            closeSession(session);
13214                    }
13215            }
13216    
13217            /**
13218             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13219             *
13220             * @param messageId the primary key of the current message-boards message
13221             * @param groupId the group ID
13222             * @param categoryId the category ID
13223             * @param status the status
13224             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13225             * @return the previous, current, and next message-boards message
13226             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13227             * @throws SystemException if a system exception occurred
13228             */
13229            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13230                    long groupId, long categoryId, int status,
13231                    OrderByComparator orderByComparator)
13232                    throws NoSuchMessageException, SystemException {
13233                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13234                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13235                                    status, orderByComparator);
13236                    }
13237    
13238                    MBMessage mbMessage = findByPrimaryKey(messageId);
13239    
13240                    Session session = null;
13241    
13242                    try {
13243                            session = openSession();
13244    
13245                            MBMessage[] array = new MBMessageImpl[3];
13246    
13247                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13248                                            groupId, categoryId, status, orderByComparator, true);
13249    
13250                            array[1] = mbMessage;
13251    
13252                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13253                                            groupId, categoryId, status, orderByComparator, false);
13254    
13255                            return array;
13256                    }
13257                    catch (Exception e) {
13258                            throw processException(e);
13259                    }
13260                    finally {
13261                            closeSession(session);
13262                    }
13263            }
13264    
13265            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13266                    MBMessage mbMessage, long groupId, long categoryId, int status,
13267                    OrderByComparator orderByComparator, boolean previous) {
13268                    StringBundler query = null;
13269    
13270                    if (orderByComparator != null) {
13271                            query = new StringBundler(6 +
13272                                            (orderByComparator.getOrderByFields().length * 6));
13273                    }
13274                    else {
13275                            query = new StringBundler(3);
13276                    }
13277    
13278                    if (getDB().isSupportsInlineDistinct()) {
13279                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13280                    }
13281                    else {
13282                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13283                    }
13284    
13285                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13286    
13287                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13288    
13289                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13290    
13291                    if (!getDB().isSupportsInlineDistinct()) {
13292                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13293                    }
13294    
13295                    if (orderByComparator != null) {
13296                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13297    
13298                            if (orderByConditionFields.length > 0) {
13299                                    query.append(WHERE_AND);
13300                            }
13301    
13302                            for (int i = 0; i < orderByConditionFields.length; i++) {
13303                                    if (getDB().isSupportsInlineDistinct()) {
13304                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13305                                    }
13306                                    else {
13307                                            query.append(_ORDER_BY_ENTITY_TABLE);
13308                                    }
13309    
13310                                    query.append(orderByConditionFields[i]);
13311    
13312                                    if ((i + 1) < orderByConditionFields.length) {
13313                                            if (orderByComparator.isAscending() ^ previous) {
13314                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13315                                            }
13316                                            else {
13317                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13318                                            }
13319                                    }
13320                                    else {
13321                                            if (orderByComparator.isAscending() ^ previous) {
13322                                                    query.append(WHERE_GREATER_THAN);
13323                                            }
13324                                            else {
13325                                                    query.append(WHERE_LESSER_THAN);
13326                                            }
13327                                    }
13328                            }
13329    
13330                            query.append(ORDER_BY_CLAUSE);
13331    
13332                            String[] orderByFields = orderByComparator.getOrderByFields();
13333    
13334                            for (int i = 0; i < orderByFields.length; i++) {
13335                                    if (getDB().isSupportsInlineDistinct()) {
13336                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13337                                    }
13338                                    else {
13339                                            query.append(_ORDER_BY_ENTITY_TABLE);
13340                                    }
13341    
13342                                    query.append(orderByFields[i]);
13343    
13344                                    if ((i + 1) < orderByFields.length) {
13345                                            if (orderByComparator.isAscending() ^ previous) {
13346                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13347                                            }
13348                                            else {
13349                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13350                                            }
13351                                    }
13352                                    else {
13353                                            if (orderByComparator.isAscending() ^ previous) {
13354                                                    query.append(ORDER_BY_ASC);
13355                                            }
13356                                            else {
13357                                                    query.append(ORDER_BY_DESC);
13358                                            }
13359                                    }
13360                            }
13361                    }
13362                    else {
13363                            if (getDB().isSupportsInlineDistinct()) {
13364                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13365                            }
13366                            else {
13367                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13368                            }
13369                    }
13370    
13371                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13372                                    MBMessage.class.getName(),
13373                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13374    
13375                    SQLQuery q = session.createSQLQuery(sql);
13376    
13377                    q.setFirstResult(0);
13378                    q.setMaxResults(2);
13379    
13380                    if (getDB().isSupportsInlineDistinct()) {
13381                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13382                    }
13383                    else {
13384                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13385                    }
13386    
13387                    QueryPos qPos = QueryPos.getInstance(q);
13388    
13389                    qPos.add(groupId);
13390    
13391                    qPos.add(categoryId);
13392    
13393                    qPos.add(status);
13394    
13395                    if (orderByComparator != null) {
13396                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13397    
13398                            for (Object value : values) {
13399                                    qPos.add(value);
13400                            }
13401                    }
13402    
13403                    List<MBMessage> list = q.list();
13404    
13405                    if (list.size() == 2) {
13406                            return list.get(1);
13407                    }
13408                    else {
13409                            return null;
13410                    }
13411            }
13412    
13413            /**
13414             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13415             *
13416             * @param groupId the group ID
13417             * @param categoryId the category ID
13418             * @param status the status
13419             * @throws SystemException if a system exception occurred
13420             */
13421            public void removeByG_C_S(long groupId, long categoryId, int status)
13422                    throws SystemException {
13423                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13424                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13425                            remove(mbMessage);
13426                    }
13427            }
13428    
13429            /**
13430             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13431             *
13432             * @param groupId the group ID
13433             * @param categoryId the category ID
13434             * @param status the status
13435             * @return the number of matching message-boards messages
13436             * @throws SystemException if a system exception occurred
13437             */
13438            public int countByG_C_S(long groupId, long categoryId, int status)
13439                    throws SystemException {
13440                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13441    
13442                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
13443    
13444                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13445                                    this);
13446    
13447                    if (count == null) {
13448                            StringBundler query = new StringBundler(4);
13449    
13450                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13451    
13452                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13453    
13454                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13455    
13456                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13457    
13458                            String sql = query.toString();
13459    
13460                            Session session = null;
13461    
13462                            try {
13463                                    session = openSession();
13464    
13465                                    Query q = session.createQuery(sql);
13466    
13467                                    QueryPos qPos = QueryPos.getInstance(q);
13468    
13469                                    qPos.add(groupId);
13470    
13471                                    qPos.add(categoryId);
13472    
13473                                    qPos.add(status);
13474    
13475                                    count = (Long)q.uniqueResult();
13476    
13477                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13478                            }
13479                            catch (Exception e) {
13480                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13481    
13482                                    throw processException(e);
13483                            }
13484                            finally {
13485                                    closeSession(session);
13486                            }
13487                    }
13488    
13489                    return count.intValue();
13490            }
13491    
13492            /**
13493             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13494             *
13495             * @param groupId the group ID
13496             * @param categoryId the category ID
13497             * @param status the status
13498             * @return the number of matching message-boards messages that the user has permission to view
13499             * @throws SystemException if a system exception occurred
13500             */
13501            public int filterCountByG_C_S(long groupId, long categoryId, int status)
13502                    throws SystemException {
13503                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13504                            return countByG_C_S(groupId, categoryId, status);
13505                    }
13506    
13507                    StringBundler query = new StringBundler(4);
13508    
13509                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13510    
13511                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13512    
13513                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13514    
13515                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13516    
13517                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13518                                    MBMessage.class.getName(),
13519                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13520    
13521                    Session session = null;
13522    
13523                    try {
13524                            session = openSession();
13525    
13526                            SQLQuery q = session.createSQLQuery(sql);
13527    
13528                            q.addScalar(COUNT_COLUMN_NAME,
13529                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13530    
13531                            QueryPos qPos = QueryPos.getInstance(q);
13532    
13533                            qPos.add(groupId);
13534    
13535                            qPos.add(categoryId);
13536    
13537                            qPos.add(status);
13538    
13539                            Long count = (Long)q.uniqueResult();
13540    
13541                            return count.intValue();
13542                    }
13543                    catch (Exception e) {
13544                            throw processException(e);
13545                    }
13546                    finally {
13547                            closeSession(session);
13548                    }
13549            }
13550    
13551            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
13552            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13553            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
13554            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13555                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13556                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
13557                            new String[] {
13558                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13559                                    
13560                            Integer.class.getName(), Integer.class.getName(),
13561                                    OrderByComparator.class.getName()
13562                            });
13563            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13564                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13565                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
13566                            new String[] {
13567                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13568                            },
13569                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
13570                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
13571                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
13572                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13573            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13574                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13575                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
13576                            new String[] {
13577                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13578                            });
13579    
13580            /**
13581             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13582             *
13583             * @param userId the user ID
13584             * @param classNameId the class name ID
13585             * @param classPK the class p k
13586             * @return the matching message-boards messages
13587             * @throws SystemException if a system exception occurred
13588             */
13589            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13590                    long classPK) throws SystemException {
13591                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
13592                            QueryUtil.ALL_POS, null);
13593            }
13594    
13595            /**
13596             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13597             *
13598             * <p>
13599             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13600             * </p>
13601             *
13602             * @param userId the user ID
13603             * @param classNameId the class name ID
13604             * @param classPK the class p k
13605             * @param start the lower bound of the range of message-boards messages
13606             * @param end the upper bound of the range of message-boards messages (not inclusive)
13607             * @return the range of matching message-boards messages
13608             * @throws SystemException if a system exception occurred
13609             */
13610            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13611                    long classPK, int start, int end) throws SystemException {
13612                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
13613            }
13614    
13615            /**
13616             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13617             *
13618             * <p>
13619             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
13620             * </p>
13621             *
13622             * @param userId the user ID
13623             * @param classNameId the class name ID
13624             * @param classPK the class p k
13625             * @param start the lower bound of the range of message-boards messages
13626             * @param end the upper bound of the range of message-boards messages (not inclusive)
13627             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13628             * @return the ordered range of matching message-boards messages
13629             * @throws SystemException if a system exception occurred
13630             */
13631            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13632                    long classPK, int start, int end, OrderByComparator orderByComparator)
13633                    throws SystemException {
13634                    boolean pagination = true;
13635                    FinderPath finderPath = null;
13636                    Object[] finderArgs = null;
13637    
13638                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13639                                    (orderByComparator == null)) {
13640                            pagination = false;
13641                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
13642                            finderArgs = new Object[] { userId, classNameId, classPK };
13643                    }
13644                    else {
13645                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
13646                            finderArgs = new Object[] {
13647                                            userId, classNameId, classPK,
13648                                            
13649                                            start, end, orderByComparator
13650                                    };
13651                    }
13652    
13653                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13654                                    finderArgs, this);
13655    
13656                    if ((list != null) && !list.isEmpty()) {
13657                            for (MBMessage mbMessage : list) {
13658                                    if ((userId != mbMessage.getUserId()) ||
13659                                                    (classNameId != mbMessage.getClassNameId()) ||
13660                                                    (classPK != mbMessage.getClassPK())) {
13661                                            list = null;
13662    
13663                                            break;
13664                                    }
13665                            }
13666                    }
13667    
13668                    if (list == null) {
13669                            StringBundler query = null;
13670    
13671                            if (orderByComparator != null) {
13672                                    query = new StringBundler(5 +
13673                                                    (orderByComparator.getOrderByFields().length * 3));
13674                            }
13675                            else {
13676                                    query = new StringBundler(5);
13677                            }
13678    
13679                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13680    
13681                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13682    
13683                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13684    
13685                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13686    
13687                            if (orderByComparator != null) {
13688                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13689                                            orderByComparator);
13690                            }
13691                            else
13692                             if (pagination) {
13693                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13694                            }
13695    
13696                            String sql = query.toString();
13697    
13698                            Session session = null;
13699    
13700                            try {
13701                                    session = openSession();
13702    
13703                                    Query q = session.createQuery(sql);
13704    
13705                                    QueryPos qPos = QueryPos.getInstance(q);
13706    
13707                                    qPos.add(userId);
13708    
13709                                    qPos.add(classNameId);
13710    
13711                                    qPos.add(classPK);
13712    
13713                                    if (!pagination) {
13714                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13715                                                            start, end, false);
13716    
13717                                            Collections.sort(list);
13718    
13719                                            list = new UnmodifiableList<MBMessage>(list);
13720                                    }
13721                                    else {
13722                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13723                                                            start, end);
13724                                    }
13725    
13726                                    cacheResult(list);
13727    
13728                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13729                            }
13730                            catch (Exception e) {
13731                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13732    
13733                                    throw processException(e);
13734                            }
13735                            finally {
13736                                    closeSession(session);
13737                            }
13738                    }
13739    
13740                    return list;
13741            }
13742    
13743            /**
13744             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13745             *
13746             * @param userId the user ID
13747             * @param classNameId the class name ID
13748             * @param classPK the class p k
13749             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13750             * @return the first matching message-boards message
13751             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13752             * @throws SystemException if a system exception occurred
13753             */
13754            public MBMessage findByU_C_C_First(long userId, long classNameId,
13755                    long classPK, OrderByComparator orderByComparator)
13756                    throws NoSuchMessageException, SystemException {
13757                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
13758                                    orderByComparator);
13759    
13760                    if (mbMessage != null) {
13761                            return mbMessage;
13762                    }
13763    
13764                    StringBundler msg = new StringBundler(8);
13765    
13766                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13767    
13768                    msg.append("userId=");
13769                    msg.append(userId);
13770    
13771                    msg.append(", classNameId=");
13772                    msg.append(classNameId);
13773    
13774                    msg.append(", classPK=");
13775                    msg.append(classPK);
13776    
13777                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13778    
13779                    throw new NoSuchMessageException(msg.toString());
13780            }
13781    
13782            /**
13783             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13784             *
13785             * @param userId the user ID
13786             * @param classNameId the class name ID
13787             * @param classPK the class p k
13788             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13789             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13790             * @throws SystemException if a system exception occurred
13791             */
13792            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
13793                    long classPK, OrderByComparator orderByComparator)
13794                    throws SystemException {
13795                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
13796                                    orderByComparator);
13797    
13798                    if (!list.isEmpty()) {
13799                            return list.get(0);
13800                    }
13801    
13802                    return null;
13803            }
13804    
13805            /**
13806             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13807             *
13808             * @param userId the user ID
13809             * @param classNameId the class name ID
13810             * @param classPK the class p k
13811             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13812             * @return the last matching message-boards message
13813             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13814             * @throws SystemException if a system exception occurred
13815             */
13816            public MBMessage findByU_C_C_Last(long userId, long classNameId,
13817                    long classPK, OrderByComparator orderByComparator)
13818                    throws NoSuchMessageException, SystemException {
13819                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
13820                                    orderByComparator);
13821    
13822                    if (mbMessage != null) {
13823                            return mbMessage;
13824                    }
13825    
13826                    StringBundler msg = new StringBundler(8);
13827    
13828                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13829    
13830                    msg.append("userId=");
13831                    msg.append(userId);
13832    
13833                    msg.append(", classNameId=");
13834                    msg.append(classNameId);
13835    
13836                    msg.append(", classPK=");
13837                    msg.append(classPK);
13838    
13839                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13840    
13841                    throw new NoSuchMessageException(msg.toString());
13842            }
13843    
13844            /**
13845             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13846             *
13847             * @param userId the user ID
13848             * @param classNameId the class name ID
13849             * @param classPK the class p k
13850             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13851             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13852             * @throws SystemException if a system exception occurred
13853             */
13854            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
13855                    long classPK, OrderByComparator orderByComparator)
13856                    throws SystemException {
13857                    int count = countByU_C_C(userId, classNameId, classPK);
13858    
13859                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
13860                                    count - 1, count, orderByComparator);
13861    
13862                    if (!list.isEmpty()) {
13863                            return list.get(0);
13864                    }
13865    
13866                    return null;
13867            }
13868    
13869            /**
13870             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13871             *
13872             * @param messageId the primary key of the current message-boards message
13873             * @param userId the user ID
13874             * @param classNameId the class name ID
13875             * @param classPK the class p k
13876             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13877             * @return the previous, current, and next message-boards message
13878             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13879             * @throws SystemException if a system exception occurred
13880             */
13881            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
13882                    long classNameId, long classPK, OrderByComparator orderByComparator)
13883                    throws NoSuchMessageException, SystemException {
13884                    MBMessage mbMessage = findByPrimaryKey(messageId);
13885    
13886                    Session session = null;
13887    
13888                    try {
13889                            session = openSession();
13890    
13891                            MBMessage[] array = new MBMessageImpl[3];
13892    
13893                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13894                                            classNameId, classPK, orderByComparator, true);
13895    
13896                            array[1] = mbMessage;
13897    
13898                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13899                                            classNameId, classPK, orderByComparator, false);
13900    
13901                            return array;
13902                    }
13903                    catch (Exception e) {
13904                            throw processException(e);
13905                    }
13906                    finally {
13907                            closeSession(session);
13908                    }
13909            }
13910    
13911            protected MBMessage getByU_C_C_PrevAndNext(Session session,
13912                    MBMessage mbMessage, long userId, long classNameId, long classPK,
13913                    OrderByComparator orderByComparator, boolean previous) {
13914                    StringBundler query = null;
13915    
13916                    if (orderByComparator != null) {
13917                            query = new StringBundler(6 +
13918                                            (orderByComparator.getOrderByFields().length * 6));
13919                    }
13920                    else {
13921                            query = new StringBundler(3);
13922                    }
13923    
13924                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13925    
13926                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13927    
13928                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13929    
13930                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13931    
13932                    if (orderByComparator != null) {
13933                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13934    
13935                            if (orderByConditionFields.length > 0) {
13936                                    query.append(WHERE_AND);
13937                            }
13938    
13939                            for (int i = 0; i < orderByConditionFields.length; i++) {
13940                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13941                                    query.append(orderByConditionFields[i]);
13942    
13943                                    if ((i + 1) < orderByConditionFields.length) {
13944                                            if (orderByComparator.isAscending() ^ previous) {
13945                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13946                                            }
13947                                            else {
13948                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13949                                            }
13950                                    }
13951                                    else {
13952                                            if (orderByComparator.isAscending() ^ previous) {
13953                                                    query.append(WHERE_GREATER_THAN);
13954                                            }
13955                                            else {
13956                                                    query.append(WHERE_LESSER_THAN);
13957                                            }
13958                                    }
13959                            }
13960    
13961                            query.append(ORDER_BY_CLAUSE);
13962    
13963                            String[] orderByFields = orderByComparator.getOrderByFields();
13964    
13965                            for (int i = 0; i < orderByFields.length; i++) {
13966                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13967                                    query.append(orderByFields[i]);
13968    
13969                                    if ((i + 1) < orderByFields.length) {
13970                                            if (orderByComparator.isAscending() ^ previous) {
13971                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13972                                            }
13973                                            else {
13974                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13975                                            }
13976                                    }
13977                                    else {
13978                                            if (orderByComparator.isAscending() ^ previous) {
13979                                                    query.append(ORDER_BY_ASC);
13980                                            }
13981                                            else {
13982                                                    query.append(ORDER_BY_DESC);
13983                                            }
13984                                    }
13985                            }
13986                    }
13987                    else {
13988                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13989                    }
13990    
13991                    String sql = query.toString();
13992    
13993                    Query q = session.createQuery(sql);
13994    
13995                    q.setFirstResult(0);
13996                    q.setMaxResults(2);
13997    
13998                    QueryPos qPos = QueryPos.getInstance(q);
13999    
14000                    qPos.add(userId);
14001    
14002                    qPos.add(classNameId);
14003    
14004                    qPos.add(classPK);
14005    
14006                    if (orderByComparator != null) {
14007                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14008    
14009                            for (Object value : values) {
14010                                    qPos.add(value);
14011                            }
14012                    }
14013    
14014                    List<MBMessage> list = q.list();
14015    
14016                    if (list.size() == 2) {
14017                            return list.get(1);
14018                    }
14019                    else {
14020                            return null;
14021                    }
14022            }
14023    
14024            /**
14025             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14026             *
14027             * @param userId the user ID
14028             * @param classNameId the class name ID
14029             * @param classPK the class p k
14030             * @throws SystemException if a system exception occurred
14031             */
14032            public void removeByU_C_C(long userId, long classNameId, long classPK)
14033                    throws SystemException {
14034                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14035                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14036                            remove(mbMessage);
14037                    }
14038            }
14039    
14040            /**
14041             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14042             *
14043             * @param userId the user ID
14044             * @param classNameId the class name ID
14045             * @param classPK the class p k
14046             * @return the number of matching message-boards messages
14047             * @throws SystemException if a system exception occurred
14048             */
14049            public int countByU_C_C(long userId, long classNameId, long classPK)
14050                    throws SystemException {
14051                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14052    
14053                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14054    
14055                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14056                                    this);
14057    
14058                    if (count == null) {
14059                            StringBundler query = new StringBundler(4);
14060    
14061                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14062    
14063                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14064    
14065                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14066    
14067                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14068    
14069                            String sql = query.toString();
14070    
14071                            Session session = null;
14072    
14073                            try {
14074                                    session = openSession();
14075    
14076                                    Query q = session.createQuery(sql);
14077    
14078                                    QueryPos qPos = QueryPos.getInstance(q);
14079    
14080                                    qPos.add(userId);
14081    
14082                                    qPos.add(classNameId);
14083    
14084                                    qPos.add(classPK);
14085    
14086                                    count = (Long)q.uniqueResult();
14087    
14088                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14089                            }
14090                            catch (Exception e) {
14091                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14092    
14093                                    throw processException(e);
14094                            }
14095                            finally {
14096                                    closeSession(session);
14097                            }
14098                    }
14099    
14100                    return count.intValue();
14101            }
14102    
14103            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14104            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14105            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14106            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14107                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14108                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14109                            new String[] {
14110                                    Long.class.getName(), Long.class.getName(),
14111                                    Integer.class.getName(),
14112                                    
14113                            Integer.class.getName(), Integer.class.getName(),
14114                                    OrderByComparator.class.getName()
14115                            });
14116            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14117                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14119                            new String[] {
14120                                    Long.class.getName(), Long.class.getName(),
14121                                    Integer.class.getName()
14122                            },
14123                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14124                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14125                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14126                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14127            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14128                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14129                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14130                            new String[] {
14131                                    Long.class.getName(), Long.class.getName(),
14132                                    Integer.class.getName()
14133                            });
14134            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14135                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14136                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14137                            new String[] {
14138                                    Long.class.getName(), Long.class.getName(),
14139                                    Integer.class.getName()
14140                            });
14141    
14142            /**
14143             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14144             *
14145             * @param userId the user ID
14146             * @param classNameId the class name ID
14147             * @param status the status
14148             * @return the matching message-boards messages
14149             * @throws SystemException if a system exception occurred
14150             */
14151            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
14152                    throws SystemException {
14153                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14154                            QueryUtil.ALL_POS, null);
14155            }
14156    
14157            /**
14158             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14159             *
14160             * <p>
14161             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14162             * </p>
14163             *
14164             * @param userId the user ID
14165             * @param classNameId the class name ID
14166             * @param status the status
14167             * @param start the lower bound of the range of message-boards messages
14168             * @param end the upper bound of the range of message-boards messages (not inclusive)
14169             * @return the range of matching message-boards messages
14170             * @throws SystemException if a system exception occurred
14171             */
14172            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14173                    int status, int start, int end) throws SystemException {
14174                    return findByU_C_S(userId, classNameId, status, start, end, null);
14175            }
14176    
14177            /**
14178             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14179             *
14180             * <p>
14181             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14182             * </p>
14183             *
14184             * @param userId the user ID
14185             * @param classNameId the class name ID
14186             * @param status the status
14187             * @param start the lower bound of the range of message-boards messages
14188             * @param end the upper bound of the range of message-boards messages (not inclusive)
14189             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14190             * @return the ordered range of matching message-boards messages
14191             * @throws SystemException if a system exception occurred
14192             */
14193            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14194                    int status, int start, int end, OrderByComparator orderByComparator)
14195                    throws SystemException {
14196                    boolean pagination = true;
14197                    FinderPath finderPath = null;
14198                    Object[] finderArgs = null;
14199    
14200                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14201                                    (orderByComparator == null)) {
14202                            pagination = false;
14203                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14204                            finderArgs = new Object[] { userId, classNameId, status };
14205                    }
14206                    else {
14207                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14208                            finderArgs = new Object[] {
14209                                            userId, classNameId, status,
14210                                            
14211                                            start, end, orderByComparator
14212                                    };
14213                    }
14214    
14215                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14216                                    finderArgs, this);
14217    
14218                    if ((list != null) && !list.isEmpty()) {
14219                            for (MBMessage mbMessage : list) {
14220                                    if ((userId != mbMessage.getUserId()) ||
14221                                                    (classNameId != mbMessage.getClassNameId()) ||
14222                                                    (status != mbMessage.getStatus())) {
14223                                            list = null;
14224    
14225                                            break;
14226                                    }
14227                            }
14228                    }
14229    
14230                    if (list == null) {
14231                            StringBundler query = null;
14232    
14233                            if (orderByComparator != null) {
14234                                    query = new StringBundler(5 +
14235                                                    (orderByComparator.getOrderByFields().length * 3));
14236                            }
14237                            else {
14238                                    query = new StringBundler(5);
14239                            }
14240    
14241                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14242    
14243                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14244    
14245                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14246    
14247                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14248    
14249                            if (orderByComparator != null) {
14250                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14251                                            orderByComparator);
14252                            }
14253                            else
14254                             if (pagination) {
14255                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14256                            }
14257    
14258                            String sql = query.toString();
14259    
14260                            Session session = null;
14261    
14262                            try {
14263                                    session = openSession();
14264    
14265                                    Query q = session.createQuery(sql);
14266    
14267                                    QueryPos qPos = QueryPos.getInstance(q);
14268    
14269                                    qPos.add(userId);
14270    
14271                                    qPos.add(classNameId);
14272    
14273                                    qPos.add(status);
14274    
14275                                    if (!pagination) {
14276                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14277                                                            start, end, false);
14278    
14279                                            Collections.sort(list);
14280    
14281                                            list = new UnmodifiableList<MBMessage>(list);
14282                                    }
14283                                    else {
14284                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14285                                                            start, end);
14286                                    }
14287    
14288                                    cacheResult(list);
14289    
14290                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14291                            }
14292                            catch (Exception e) {
14293                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14294    
14295                                    throw processException(e);
14296                            }
14297                            finally {
14298                                    closeSession(session);
14299                            }
14300                    }
14301    
14302                    return list;
14303            }
14304    
14305            /**
14306             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14307             *
14308             * @param userId the user ID
14309             * @param classNameId the class name ID
14310             * @param status the status
14311             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14312             * @return the first matching message-boards message
14313             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14314             * @throws SystemException if a system exception occurred
14315             */
14316            public MBMessage findByU_C_S_First(long userId, long classNameId,
14317                    int status, OrderByComparator orderByComparator)
14318                    throws NoSuchMessageException, SystemException {
14319                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14320                                    orderByComparator);
14321    
14322                    if (mbMessage != null) {
14323                            return mbMessage;
14324                    }
14325    
14326                    StringBundler msg = new StringBundler(8);
14327    
14328                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14329    
14330                    msg.append("userId=");
14331                    msg.append(userId);
14332    
14333                    msg.append(", classNameId=");
14334                    msg.append(classNameId);
14335    
14336                    msg.append(", status=");
14337                    msg.append(status);
14338    
14339                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14340    
14341                    throw new NoSuchMessageException(msg.toString());
14342            }
14343    
14344            /**
14345             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14346             *
14347             * @param userId the user ID
14348             * @param classNameId the class name ID
14349             * @param status the status
14350             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14351             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14352             * @throws SystemException if a system exception occurred
14353             */
14354            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14355                    int status, OrderByComparator orderByComparator)
14356                    throws SystemException {
14357                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14358                                    orderByComparator);
14359    
14360                    if (!list.isEmpty()) {
14361                            return list.get(0);
14362                    }
14363    
14364                    return null;
14365            }
14366    
14367            /**
14368             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14369             *
14370             * @param userId the user ID
14371             * @param classNameId the class name ID
14372             * @param status the status
14373             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14374             * @return the last matching message-boards message
14375             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14376             * @throws SystemException if a system exception occurred
14377             */
14378            public MBMessage findByU_C_S_Last(long userId, long classNameId,
14379                    int status, OrderByComparator orderByComparator)
14380                    throws NoSuchMessageException, SystemException {
14381                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14382                                    orderByComparator);
14383    
14384                    if (mbMessage != null) {
14385                            return mbMessage;
14386                    }
14387    
14388                    StringBundler msg = new StringBundler(8);
14389    
14390                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14391    
14392                    msg.append("userId=");
14393                    msg.append(userId);
14394    
14395                    msg.append(", classNameId=");
14396                    msg.append(classNameId);
14397    
14398                    msg.append(", status=");
14399                    msg.append(status);
14400    
14401                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14402    
14403                    throw new NoSuchMessageException(msg.toString());
14404            }
14405    
14406            /**
14407             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14408             *
14409             * @param userId the user ID
14410             * @param classNameId the class name ID
14411             * @param status the status
14412             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14413             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14414             * @throws SystemException if a system exception occurred
14415             */
14416            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
14417                    int status, OrderByComparator orderByComparator)
14418                    throws SystemException {
14419                    int count = countByU_C_S(userId, classNameId, status);
14420    
14421                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
14422                                    count - 1, count, orderByComparator);
14423    
14424                    if (!list.isEmpty()) {
14425                            return list.get(0);
14426                    }
14427    
14428                    return null;
14429            }
14430    
14431            /**
14432             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14433             *
14434             * @param messageId the primary key of the current message-boards message
14435             * @param userId the user ID
14436             * @param classNameId the class name ID
14437             * @param status the status
14438             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14439             * @return the previous, current, and next message-boards message
14440             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14441             * @throws SystemException if a system exception occurred
14442             */
14443            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
14444                    long classNameId, int status, OrderByComparator orderByComparator)
14445                    throws NoSuchMessageException, SystemException {
14446                    MBMessage mbMessage = findByPrimaryKey(messageId);
14447    
14448                    Session session = null;
14449    
14450                    try {
14451                            session = openSession();
14452    
14453                            MBMessage[] array = new MBMessageImpl[3];
14454    
14455                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14456                                            classNameId, status, orderByComparator, true);
14457    
14458                            array[1] = mbMessage;
14459    
14460                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14461                                            classNameId, status, orderByComparator, false);
14462    
14463                            return array;
14464                    }
14465                    catch (Exception e) {
14466                            throw processException(e);
14467                    }
14468                    finally {
14469                            closeSession(session);
14470                    }
14471            }
14472    
14473            protected MBMessage getByU_C_S_PrevAndNext(Session session,
14474                    MBMessage mbMessage, long userId, long classNameId, int status,
14475                    OrderByComparator orderByComparator, boolean previous) {
14476                    StringBundler query = null;
14477    
14478                    if (orderByComparator != null) {
14479                            query = new StringBundler(6 +
14480                                            (orderByComparator.getOrderByFields().length * 6));
14481                    }
14482                    else {
14483                            query = new StringBundler(3);
14484                    }
14485    
14486                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14487    
14488                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14489    
14490                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14491    
14492                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14493    
14494                    if (orderByComparator != null) {
14495                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14496    
14497                            if (orderByConditionFields.length > 0) {
14498                                    query.append(WHERE_AND);
14499                            }
14500    
14501                            for (int i = 0; i < orderByConditionFields.length; i++) {
14502                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14503                                    query.append(orderByConditionFields[i]);
14504    
14505                                    if ((i + 1) < orderByConditionFields.length) {
14506                                            if (orderByComparator.isAscending() ^ previous) {
14507                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14508                                            }
14509                                            else {
14510                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14511                                            }
14512                                    }
14513                                    else {
14514                                            if (orderByComparator.isAscending() ^ previous) {
14515                                                    query.append(WHERE_GREATER_THAN);
14516                                            }
14517                                            else {
14518                                                    query.append(WHERE_LESSER_THAN);
14519                                            }
14520                                    }
14521                            }
14522    
14523                            query.append(ORDER_BY_CLAUSE);
14524    
14525                            String[] orderByFields = orderByComparator.getOrderByFields();
14526    
14527                            for (int i = 0; i < orderByFields.length; i++) {
14528                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14529                                    query.append(orderByFields[i]);
14530    
14531                                    if ((i + 1) < orderByFields.length) {
14532                                            if (orderByComparator.isAscending() ^ previous) {
14533                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14534                                            }
14535                                            else {
14536                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14537                                            }
14538                                    }
14539                                    else {
14540                                            if (orderByComparator.isAscending() ^ previous) {
14541                                                    query.append(ORDER_BY_ASC);
14542                                            }
14543                                            else {
14544                                                    query.append(ORDER_BY_DESC);
14545                                            }
14546                                    }
14547                            }
14548                    }
14549                    else {
14550                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14551                    }
14552    
14553                    String sql = query.toString();
14554    
14555                    Query q = session.createQuery(sql);
14556    
14557                    q.setFirstResult(0);
14558                    q.setMaxResults(2);
14559    
14560                    QueryPos qPos = QueryPos.getInstance(q);
14561    
14562                    qPos.add(userId);
14563    
14564                    qPos.add(classNameId);
14565    
14566                    qPos.add(status);
14567    
14568                    if (orderByComparator != null) {
14569                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14570    
14571                            for (Object value : values) {
14572                                    qPos.add(value);
14573                            }
14574                    }
14575    
14576                    List<MBMessage> list = q.list();
14577    
14578                    if (list.size() == 2) {
14579                            return list.get(1);
14580                    }
14581                    else {
14582                            return null;
14583                    }
14584            }
14585    
14586            /**
14587             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14588             *
14589             * <p>
14590             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14591             * </p>
14592             *
14593             * @param userId the user ID
14594             * @param classNameIds the class name IDs
14595             * @param status the status
14596             * @return the matching message-boards messages
14597             * @throws SystemException if a system exception occurred
14598             */
14599            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14600                    int status) throws SystemException {
14601                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
14602                            QueryUtil.ALL_POS, null);
14603            }
14604    
14605            /**
14606             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14607             *
14608             * <p>
14609             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14610             * </p>
14611             *
14612             * @param userId the user ID
14613             * @param classNameIds the class name IDs
14614             * @param status the status
14615             * @param start the lower bound of the range of message-boards messages
14616             * @param end the upper bound of the range of message-boards messages (not inclusive)
14617             * @return the range of matching message-boards messages
14618             * @throws SystemException if a system exception occurred
14619             */
14620            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14621                    int status, int start, int end) throws SystemException {
14622                    return findByU_C_S(userId, classNameIds, status, start, end, null);
14623            }
14624    
14625            /**
14626             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14627             *
14628             * <p>
14629             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
14630             * </p>
14631             *
14632             * @param userId the user ID
14633             * @param classNameIds the class name IDs
14634             * @param status the status
14635             * @param start the lower bound of the range of message-boards messages
14636             * @param end the upper bound of the range of message-boards messages (not inclusive)
14637             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14638             * @return the ordered range of matching message-boards messages
14639             * @throws SystemException if a system exception occurred
14640             */
14641            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14642                    int status, int start, int end, OrderByComparator orderByComparator)
14643                    throws SystemException {
14644                    if ((classNameIds != null) && (classNameIds.length == 1)) {
14645                            return findByU_C_S(userId, classNameIds[0], status, start, end,
14646                                    orderByComparator);
14647                    }
14648    
14649                    boolean pagination = true;
14650                    Object[] finderArgs = null;
14651    
14652                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14653                                    (orderByComparator == null)) {
14654                            pagination = false;
14655                            finderArgs = new Object[] {
14656                                            userId, StringUtil.merge(classNameIds), status
14657                                    };
14658                    }
14659                    else {
14660                            finderArgs = new Object[] {
14661                                            userId, StringUtil.merge(classNameIds), status,
14662                                            
14663                                            start, end, orderByComparator
14664                                    };
14665                    }
14666    
14667                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14668                                    finderArgs, this);
14669    
14670                    if ((list != null) && !list.isEmpty()) {
14671                            for (MBMessage mbMessage : list) {
14672                                    if ((userId != mbMessage.getUserId()) ||
14673                                                    !ArrayUtil.contains(classNameIds,
14674                                                            mbMessage.getClassNameId()) ||
14675                                                    (status != mbMessage.getStatus())) {
14676                                            list = null;
14677    
14678                                            break;
14679                                    }
14680                            }
14681                    }
14682    
14683                    if (list == null) {
14684                            StringBundler query = new StringBundler();
14685    
14686                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14687    
14688                            boolean conjunctionable = false;
14689    
14690                            if (conjunctionable) {
14691                                    query.append(WHERE_AND);
14692                            }
14693    
14694                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
14695    
14696                            conjunctionable = true;
14697    
14698                            if ((classNameIds == null) || (classNameIds.length > 0)) {
14699                                    if (conjunctionable) {
14700                                            query.append(WHERE_AND);
14701                                    }
14702    
14703                                    query.append(StringPool.OPEN_PARENTHESIS);
14704    
14705                                    for (int i = 0; i < classNameIds.length; i++) {
14706                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
14707    
14708                                            if ((i + 1) < classNameIds.length) {
14709                                                    query.append(WHERE_OR);
14710                                            }
14711                                    }
14712    
14713                                    query.append(StringPool.CLOSE_PARENTHESIS);
14714    
14715                                    conjunctionable = true;
14716                            }
14717    
14718                            if (conjunctionable) {
14719                                    query.append(WHERE_AND);
14720                            }
14721    
14722                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
14723    
14724                            conjunctionable = true;
14725    
14726                            if (orderByComparator != null) {
14727                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14728                                            orderByComparator);
14729                            }
14730                            else
14731                             if (pagination) {
14732                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14733                            }
14734    
14735                            String sql = query.toString();
14736    
14737                            Session session = null;
14738    
14739                            try {
14740                                    session = openSession();
14741    
14742                                    Query q = session.createQuery(sql);
14743    
14744                                    QueryPos qPos = QueryPos.getInstance(q);
14745    
14746                                    qPos.add(userId);
14747    
14748                                    if (classNameIds != null) {
14749                                            qPos.add(classNameIds);
14750                                    }
14751    
14752                                    qPos.add(status);
14753    
14754                                    if (!pagination) {
14755                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14756                                                            start, end, false);
14757    
14758                                            Collections.sort(list);
14759    
14760                                            list = new UnmodifiableList<MBMessage>(list);
14761                                    }
14762                                    else {
14763                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14764                                                            start, end);
14765                                    }
14766    
14767                                    cacheResult(list);
14768    
14769                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14770                                            finderArgs, list);
14771                            }
14772                            catch (Exception e) {
14773                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14774                                            finderArgs);
14775    
14776                                    throw processException(e);
14777                            }
14778                            finally {
14779                                    closeSession(session);
14780                            }
14781                    }
14782    
14783                    return list;
14784            }
14785    
14786            /**
14787             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
14788             *
14789             * @param userId the user ID
14790             * @param classNameId the class name ID
14791             * @param status the status
14792             * @throws SystemException if a system exception occurred
14793             */
14794            public void removeByU_C_S(long userId, long classNameId, int status)
14795                    throws SystemException {
14796                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
14797                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14798                            remove(mbMessage);
14799                    }
14800            }
14801    
14802            /**
14803             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14804             *
14805             * @param userId the user ID
14806             * @param classNameId the class name ID
14807             * @param status the status
14808             * @return the number of matching message-boards messages
14809             * @throws SystemException if a system exception occurred
14810             */
14811            public int countByU_C_S(long userId, long classNameId, int status)
14812                    throws SystemException {
14813                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
14814    
14815                    Object[] finderArgs = new Object[] { userId, classNameId, status };
14816    
14817                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14818                                    this);
14819    
14820                    if (count == null) {
14821                            StringBundler query = new StringBundler(4);
14822    
14823                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14824    
14825                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14826    
14827                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14828    
14829                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14830    
14831                            String sql = query.toString();
14832    
14833                            Session session = null;
14834    
14835                            try {
14836                                    session = openSession();
14837    
14838                                    Query q = session.createQuery(sql);
14839    
14840                                    QueryPos qPos = QueryPos.getInstance(q);
14841    
14842                                    qPos.add(userId);
14843    
14844                                    qPos.add(classNameId);
14845    
14846                                    qPos.add(status);
14847    
14848                                    count = (Long)q.uniqueResult();
14849    
14850                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14851                            }
14852                            catch (Exception e) {
14853                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14854    
14855                                    throw processException(e);
14856                            }
14857                            finally {
14858                                    closeSession(session);
14859                            }
14860                    }
14861    
14862                    return count.intValue();
14863            }
14864    
14865            /**
14866             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14867             *
14868             * @param userId the user ID
14869             * @param classNameIds the class name IDs
14870             * @param status the status
14871             * @return the number of matching message-boards messages
14872             * @throws SystemException if a system exception occurred
14873             */
14874            public int countByU_C_S(long userId, long[] classNameIds, int status)
14875                    throws SystemException {
14876                    Object[] finderArgs = new Object[] {
14877                                    userId, StringUtil.merge(classNameIds), status
14878                            };
14879    
14880                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14881                                    finderArgs, this);
14882    
14883                    if (count == null) {
14884                            StringBundler query = new StringBundler();
14885    
14886                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14887    
14888                            boolean conjunctionable = false;
14889    
14890                            if (conjunctionable) {
14891                                    query.append(WHERE_AND);
14892                            }
14893    
14894                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
14895    
14896                            conjunctionable = true;
14897    
14898                            if ((classNameIds == null) || (classNameIds.length > 0)) {
14899                                    if (conjunctionable) {
14900                                            query.append(WHERE_AND);
14901                                    }
14902    
14903                                    query.append(StringPool.OPEN_PARENTHESIS);
14904    
14905                                    for (int i = 0; i < classNameIds.length; i++) {
14906                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
14907    
14908                                            if ((i + 1) < classNameIds.length) {
14909                                                    query.append(WHERE_OR);
14910                                            }
14911                                    }
14912    
14913                                    query.append(StringPool.CLOSE_PARENTHESIS);
14914    
14915                                    conjunctionable = true;
14916                            }
14917    
14918                            if (conjunctionable) {
14919                                    query.append(WHERE_AND);
14920                            }
14921    
14922                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
14923    
14924                            conjunctionable = true;
14925    
14926                            String sql = query.toString();
14927    
14928                            Session session = null;
14929    
14930                            try {
14931                                    session = openSession();
14932    
14933                                    Query q = session.createQuery(sql);
14934    
14935                                    QueryPos qPos = QueryPos.getInstance(q);
14936    
14937                                    qPos.add(userId);
14938    
14939                                    if (classNameIds != null) {
14940                                            qPos.add(classNameIds);
14941                                    }
14942    
14943                                    qPos.add(status);
14944    
14945                                    count = (Long)q.uniqueResult();
14946    
14947                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14948                                            finderArgs, count);
14949                            }
14950                            catch (Exception e) {
14951                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14952                                            finderArgs);
14953    
14954                                    throw processException(e);
14955                            }
14956                            finally {
14957                                    closeSession(session);
14958                            }
14959                    }
14960    
14961                    return count.intValue();
14962            }
14963    
14964            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
14965            private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
14966                    removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
14967            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14968            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
14969                    removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
14970            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
14971            private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
14972                    removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
14973            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14974                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14975                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
14976                            new String[] {
14977                                    Long.class.getName(), Long.class.getName(),
14978                                    Integer.class.getName(),
14979                                    
14980                            Integer.class.getName(), Integer.class.getName(),
14981                                    OrderByComparator.class.getName()
14982                            });
14983            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14984                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14985                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
14986                            new String[] {
14987                                    Long.class.getName(), Long.class.getName(),
14988                                    Integer.class.getName()
14989                            },
14990                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14991                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14992                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14993                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14994            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14995                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14996                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
14997                            new String[] {
14998                                    Long.class.getName(), Long.class.getName(),
14999                                    Integer.class.getName()
15000                            });
15001    
15002            /**
15003             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15004             *
15005             * @param classNameId the class name ID
15006             * @param classPK the class p k
15007             * @param status the status
15008             * @return the matching message-boards messages
15009             * @throws SystemException if a system exception occurred
15010             */
15011            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15012                    int status) throws SystemException {
15013                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
15014                            QueryUtil.ALL_POS, null);
15015            }
15016    
15017            /**
15018             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15019             *
15020             * <p>
15021             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15022             * </p>
15023             *
15024             * @param classNameId the class name ID
15025             * @param classPK the class p k
15026             * @param status the status
15027             * @param start the lower bound of the range of message-boards messages
15028             * @param end the upper bound of the range of message-boards messages (not inclusive)
15029             * @return the range of matching message-boards messages
15030             * @throws SystemException if a system exception occurred
15031             */
15032            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15033                    int status, int start, int end) throws SystemException {
15034                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15035            }
15036    
15037            /**
15038             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15039             *
15040             * <p>
15041             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15042             * </p>
15043             *
15044             * @param classNameId the class name ID
15045             * @param classPK the class p k
15046             * @param status the status
15047             * @param start the lower bound of the range of message-boards messages
15048             * @param end the upper bound of the range of message-boards messages (not inclusive)
15049             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15050             * @return the ordered range of matching message-boards messages
15051             * @throws SystemException if a system exception occurred
15052             */
15053            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15054                    int status, int start, int end, OrderByComparator orderByComparator)
15055                    throws SystemException {
15056                    boolean pagination = true;
15057                    FinderPath finderPath = null;
15058                    Object[] finderArgs = null;
15059    
15060                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15061                                    (orderByComparator == null)) {
15062                            pagination = false;
15063                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15064                            finderArgs = new Object[] { classNameId, classPK, status };
15065                    }
15066                    else {
15067                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15068                            finderArgs = new Object[] {
15069                                            classNameId, classPK, status,
15070                                            
15071                                            start, end, orderByComparator
15072                                    };
15073                    }
15074    
15075                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15076                                    finderArgs, this);
15077    
15078                    if ((list != null) && !list.isEmpty()) {
15079                            for (MBMessage mbMessage : list) {
15080                                    if ((classNameId != mbMessage.getClassNameId()) ||
15081                                                    (classPK != mbMessage.getClassPK()) ||
15082                                                    (status != mbMessage.getStatus())) {
15083                                            list = null;
15084    
15085                                            break;
15086                                    }
15087                            }
15088                    }
15089    
15090                    if (list == null) {
15091                            StringBundler query = null;
15092    
15093                            if (orderByComparator != null) {
15094                                    query = new StringBundler(5 +
15095                                                    (orderByComparator.getOrderByFields().length * 3));
15096                            }
15097                            else {
15098                                    query = new StringBundler(5);
15099                            }
15100    
15101                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15102    
15103                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15104    
15105                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15106    
15107                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15108    
15109                            if (orderByComparator != null) {
15110                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15111                                            orderByComparator);
15112                            }
15113                            else
15114                             if (pagination) {
15115                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15116                            }
15117    
15118                            String sql = query.toString();
15119    
15120                            Session session = null;
15121    
15122                            try {
15123                                    session = openSession();
15124    
15125                                    Query q = session.createQuery(sql);
15126    
15127                                    QueryPos qPos = QueryPos.getInstance(q);
15128    
15129                                    qPos.add(classNameId);
15130    
15131                                    qPos.add(classPK);
15132    
15133                                    qPos.add(status);
15134    
15135                                    if (!pagination) {
15136                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15137                                                            start, end, false);
15138    
15139                                            Collections.sort(list);
15140    
15141                                            list = new UnmodifiableList<MBMessage>(list);
15142                                    }
15143                                    else {
15144                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15145                                                            start, end);
15146                                    }
15147    
15148                                    cacheResult(list);
15149    
15150                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15151                            }
15152                            catch (Exception e) {
15153                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15154    
15155                                    throw processException(e);
15156                            }
15157                            finally {
15158                                    closeSession(session);
15159                            }
15160                    }
15161    
15162                    return list;
15163            }
15164    
15165            /**
15166             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15167             *
15168             * @param classNameId the class name ID
15169             * @param classPK the class p k
15170             * @param status the status
15171             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15172             * @return the first matching message-boards message
15173             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15174             * @throws SystemException if a system exception occurred
15175             */
15176            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15177                    int status, OrderByComparator orderByComparator)
15178                    throws NoSuchMessageException, SystemException {
15179                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15180                                    orderByComparator);
15181    
15182                    if (mbMessage != null) {
15183                            return mbMessage;
15184                    }
15185    
15186                    StringBundler msg = new StringBundler(8);
15187    
15188                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15189    
15190                    msg.append("classNameId=");
15191                    msg.append(classNameId);
15192    
15193                    msg.append(", classPK=");
15194                    msg.append(classPK);
15195    
15196                    msg.append(", status=");
15197                    msg.append(status);
15198    
15199                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15200    
15201                    throw new NoSuchMessageException(msg.toString());
15202            }
15203    
15204            /**
15205             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15206             *
15207             * @param classNameId the class name ID
15208             * @param classPK the class p k
15209             * @param status the status
15210             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15211             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15212             * @throws SystemException if a system exception occurred
15213             */
15214            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15215                    int status, OrderByComparator orderByComparator)
15216                    throws SystemException {
15217                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15218                                    orderByComparator);
15219    
15220                    if (!list.isEmpty()) {
15221                            return list.get(0);
15222                    }
15223    
15224                    return null;
15225            }
15226    
15227            /**
15228             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15229             *
15230             * @param classNameId the class name ID
15231             * @param classPK the class p k
15232             * @param status the status
15233             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15234             * @return the last matching message-boards message
15235             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15236             * @throws SystemException if a system exception occurred
15237             */
15238            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15239                    int status, OrderByComparator orderByComparator)
15240                    throws NoSuchMessageException, SystemException {
15241                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15242                                    orderByComparator);
15243    
15244                    if (mbMessage != null) {
15245                            return mbMessage;
15246                    }
15247    
15248                    StringBundler msg = new StringBundler(8);
15249    
15250                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15251    
15252                    msg.append("classNameId=");
15253                    msg.append(classNameId);
15254    
15255                    msg.append(", classPK=");
15256                    msg.append(classPK);
15257    
15258                    msg.append(", status=");
15259                    msg.append(status);
15260    
15261                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15262    
15263                    throw new NoSuchMessageException(msg.toString());
15264            }
15265    
15266            /**
15267             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15268             *
15269             * @param classNameId the class name ID
15270             * @param classPK the class p k
15271             * @param status the status
15272             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15273             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15274             * @throws SystemException if a system exception occurred
15275             */
15276            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15277                    int status, OrderByComparator orderByComparator)
15278                    throws SystemException {
15279                    int count = countByC_C_S(classNameId, classPK, status);
15280    
15281                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15282                                    count - 1, count, orderByComparator);
15283    
15284                    if (!list.isEmpty()) {
15285                            return list.get(0);
15286                    }
15287    
15288                    return null;
15289            }
15290    
15291            /**
15292             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15293             *
15294             * @param messageId the primary key of the current message-boards message
15295             * @param classNameId the class name ID
15296             * @param classPK the class p k
15297             * @param status the status
15298             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15299             * @return the previous, current, and next message-boards message
15300             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15301             * @throws SystemException if a system exception occurred
15302             */
15303            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15304                    long classNameId, long classPK, int status,
15305                    OrderByComparator orderByComparator)
15306                    throws NoSuchMessageException, SystemException {
15307                    MBMessage mbMessage = findByPrimaryKey(messageId);
15308    
15309                    Session session = null;
15310    
15311                    try {
15312                            session = openSession();
15313    
15314                            MBMessage[] array = new MBMessageImpl[3];
15315    
15316                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15317                                            classPK, status, orderByComparator, true);
15318    
15319                            array[1] = mbMessage;
15320    
15321                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15322                                            classPK, status, orderByComparator, false);
15323    
15324                            return array;
15325                    }
15326                    catch (Exception e) {
15327                            throw processException(e);
15328                    }
15329                    finally {
15330                            closeSession(session);
15331                    }
15332            }
15333    
15334            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15335                    MBMessage mbMessage, long classNameId, long classPK, int status,
15336                    OrderByComparator orderByComparator, boolean previous) {
15337                    StringBundler query = null;
15338    
15339                    if (orderByComparator != null) {
15340                            query = new StringBundler(6 +
15341                                            (orderByComparator.getOrderByFields().length * 6));
15342                    }
15343                    else {
15344                            query = new StringBundler(3);
15345                    }
15346    
15347                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15348    
15349                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15350    
15351                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15352    
15353                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15354    
15355                    if (orderByComparator != null) {
15356                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15357    
15358                            if (orderByConditionFields.length > 0) {
15359                                    query.append(WHERE_AND);
15360                            }
15361    
15362                            for (int i = 0; i < orderByConditionFields.length; i++) {
15363                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15364                                    query.append(orderByConditionFields[i]);
15365    
15366                                    if ((i + 1) < orderByConditionFields.length) {
15367                                            if (orderByComparator.isAscending() ^ previous) {
15368                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15369                                            }
15370                                            else {
15371                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15372                                            }
15373                                    }
15374                                    else {
15375                                            if (orderByComparator.isAscending() ^ previous) {
15376                                                    query.append(WHERE_GREATER_THAN);
15377                                            }
15378                                            else {
15379                                                    query.append(WHERE_LESSER_THAN);
15380                                            }
15381                                    }
15382                            }
15383    
15384                            query.append(ORDER_BY_CLAUSE);
15385    
15386                            String[] orderByFields = orderByComparator.getOrderByFields();
15387    
15388                            for (int i = 0; i < orderByFields.length; i++) {
15389                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15390                                    query.append(orderByFields[i]);
15391    
15392                                    if ((i + 1) < orderByFields.length) {
15393                                            if (orderByComparator.isAscending() ^ previous) {
15394                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15395                                            }
15396                                            else {
15397                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15398                                            }
15399                                    }
15400                                    else {
15401                                            if (orderByComparator.isAscending() ^ previous) {
15402                                                    query.append(ORDER_BY_ASC);
15403                                            }
15404                                            else {
15405                                                    query.append(ORDER_BY_DESC);
15406                                            }
15407                                    }
15408                            }
15409                    }
15410                    else {
15411                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15412                    }
15413    
15414                    String sql = query.toString();
15415    
15416                    Query q = session.createQuery(sql);
15417    
15418                    q.setFirstResult(0);
15419                    q.setMaxResults(2);
15420    
15421                    QueryPos qPos = QueryPos.getInstance(q);
15422    
15423                    qPos.add(classNameId);
15424    
15425                    qPos.add(classPK);
15426    
15427                    qPos.add(status);
15428    
15429                    if (orderByComparator != null) {
15430                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15431    
15432                            for (Object value : values) {
15433                                    qPos.add(value);
15434                            }
15435                    }
15436    
15437                    List<MBMessage> list = q.list();
15438    
15439                    if (list.size() == 2) {
15440                            return list.get(1);
15441                    }
15442                    else {
15443                            return null;
15444                    }
15445            }
15446    
15447            /**
15448             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
15449             *
15450             * @param classNameId the class name ID
15451             * @param classPK the class p k
15452             * @param status the status
15453             * @throws SystemException if a system exception occurred
15454             */
15455            public void removeByC_C_S(long classNameId, long classPK, int status)
15456                    throws SystemException {
15457                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
15458                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15459                            remove(mbMessage);
15460                    }
15461            }
15462    
15463            /**
15464             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15465             *
15466             * @param classNameId the class name ID
15467             * @param classPK the class p k
15468             * @param status the status
15469             * @return the number of matching message-boards messages
15470             * @throws SystemException if a system exception occurred
15471             */
15472            public int countByC_C_S(long classNameId, long classPK, int status)
15473                    throws SystemException {
15474                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
15475    
15476                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
15477    
15478                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15479                                    this);
15480    
15481                    if (count == null) {
15482                            StringBundler query = new StringBundler(4);
15483    
15484                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15485    
15486                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15487    
15488                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15489    
15490                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15491    
15492                            String sql = query.toString();
15493    
15494                            Session session = null;
15495    
15496                            try {
15497                                    session = openSession();
15498    
15499                                    Query q = session.createQuery(sql);
15500    
15501                                    QueryPos qPos = QueryPos.getInstance(q);
15502    
15503                                    qPos.add(classNameId);
15504    
15505                                    qPos.add(classPK);
15506    
15507                                    qPos.add(status);
15508    
15509                                    count = (Long)q.uniqueResult();
15510    
15511                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15512                            }
15513                            catch (Exception e) {
15514                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15515    
15516                                    throw processException(e);
15517                            }
15518                            finally {
15519                                    closeSession(session);
15520                            }
15521                    }
15522    
15523                    return count.intValue();
15524            }
15525    
15526            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15527            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
15528            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
15529            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15530                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15531                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
15532                            new String[] {
15533                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15534                                    Boolean.class.getName(),
15535                                    
15536                            Integer.class.getName(), Integer.class.getName(),
15537                                    OrderByComparator.class.getName()
15538                            });
15539            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
15540                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15541                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15542                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
15543                            new String[] {
15544                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15545                                    Boolean.class.getName()
15546                            },
15547                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
15548                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
15549                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
15550                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
15551                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15552            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15553                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15554                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
15555                            new String[] {
15556                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15557                                    Boolean.class.getName()
15558                            });
15559    
15560            /**
15561             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15562             *
15563             * @param groupId the group ID
15564             * @param categoryId the category ID
15565             * @param threadId the thread ID
15566             * @param answer the answer
15567             * @return the matching message-boards messages
15568             * @throws SystemException if a system exception occurred
15569             */
15570            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15571                    long threadId, boolean answer) throws SystemException {
15572                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
15573                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15574            }
15575    
15576            /**
15577             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15578             *
15579             * <p>
15580             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15581             * </p>
15582             *
15583             * @param groupId the group ID
15584             * @param categoryId the category ID
15585             * @param threadId the thread ID
15586             * @param answer the answer
15587             * @param start the lower bound of the range of message-boards messages
15588             * @param end the upper bound of the range of message-boards messages (not inclusive)
15589             * @return the range of matching message-boards messages
15590             * @throws SystemException if a system exception occurred
15591             */
15592            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15593                    long threadId, boolean answer, int start, int end)
15594                    throws SystemException {
15595                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
15596                            null);
15597            }
15598    
15599            /**
15600             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15601             *
15602             * <p>
15603             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
15604             * </p>
15605             *
15606             * @param groupId the group ID
15607             * @param categoryId the category ID
15608             * @param threadId the thread ID
15609             * @param answer the answer
15610             * @param start the lower bound of the range of message-boards messages
15611             * @param end the upper bound of the range of message-boards messages (not inclusive)
15612             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15613             * @return the ordered range of matching message-boards messages
15614             * @throws SystemException if a system exception occurred
15615             */
15616            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
15617                    long threadId, boolean answer, int start, int end,
15618                    OrderByComparator orderByComparator) throws SystemException {
15619                    boolean pagination = true;
15620                    FinderPath finderPath = null;
15621                    Object[] finderArgs = null;
15622    
15623                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15624                                    (orderByComparator == null)) {
15625                            pagination = false;
15626                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
15627                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
15628                    }
15629                    else {
15630                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
15631                            finderArgs = new Object[] {
15632                                            groupId, categoryId, threadId, answer,
15633                                            
15634                                            start, end, orderByComparator
15635                                    };
15636                    }
15637    
15638                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15639                                    finderArgs, this);
15640    
15641                    if ((list != null) && !list.isEmpty()) {
15642                            for (MBMessage mbMessage : list) {
15643                                    if ((groupId != mbMessage.getGroupId()) ||
15644                                                    (categoryId != mbMessage.getCategoryId()) ||
15645                                                    (threadId != mbMessage.getThreadId()) ||
15646                                                    (answer != mbMessage.getAnswer())) {
15647                                            list = null;
15648    
15649                                            break;
15650                                    }
15651                            }
15652                    }
15653    
15654                    if (list == null) {
15655                            StringBundler query = null;
15656    
15657                            if (orderByComparator != null) {
15658                                    query = new StringBundler(6 +
15659                                                    (orderByComparator.getOrderByFields().length * 3));
15660                            }
15661                            else {
15662                                    query = new StringBundler(6);
15663                            }
15664    
15665                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15666    
15667                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15668    
15669                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15670    
15671                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15672    
15673                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15674    
15675                            if (orderByComparator != null) {
15676                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15677                                            orderByComparator);
15678                            }
15679                            else
15680                             if (pagination) {
15681                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15682                            }
15683    
15684                            String sql = query.toString();
15685    
15686                            Session session = null;
15687    
15688                            try {
15689                                    session = openSession();
15690    
15691                                    Query q = session.createQuery(sql);
15692    
15693                                    QueryPos qPos = QueryPos.getInstance(q);
15694    
15695                                    qPos.add(groupId);
15696    
15697                                    qPos.add(categoryId);
15698    
15699                                    qPos.add(threadId);
15700    
15701                                    qPos.add(answer);
15702    
15703                                    if (!pagination) {
15704                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15705                                                            start, end, false);
15706    
15707                                            Collections.sort(list);
15708    
15709                                            list = new UnmodifiableList<MBMessage>(list);
15710                                    }
15711                                    else {
15712                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15713                                                            start, end);
15714                                    }
15715    
15716                                    cacheResult(list);
15717    
15718                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15719                            }
15720                            catch (Exception e) {
15721                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15722    
15723                                    throw processException(e);
15724                            }
15725                            finally {
15726                                    closeSession(session);
15727                            }
15728                    }
15729    
15730                    return list;
15731            }
15732    
15733            /**
15734             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15735             *
15736             * @param groupId the group ID
15737             * @param categoryId the category ID
15738             * @param threadId the thread ID
15739             * @param answer the answer
15740             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15741             * @return the first matching message-boards message
15742             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15743             * @throws SystemException if a system exception occurred
15744             */
15745            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
15746                    long threadId, boolean answer, OrderByComparator orderByComparator)
15747                    throws NoSuchMessageException, SystemException {
15748                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
15749                                    threadId, answer, orderByComparator);
15750    
15751                    if (mbMessage != null) {
15752                            return mbMessage;
15753                    }
15754    
15755                    StringBundler msg = new StringBundler(10);
15756    
15757                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15758    
15759                    msg.append("groupId=");
15760                    msg.append(groupId);
15761    
15762                    msg.append(", categoryId=");
15763                    msg.append(categoryId);
15764    
15765                    msg.append(", threadId=");
15766                    msg.append(threadId);
15767    
15768                    msg.append(", answer=");
15769                    msg.append(answer);
15770    
15771                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15772    
15773                    throw new NoSuchMessageException(msg.toString());
15774            }
15775    
15776            /**
15777             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15778             *
15779             * @param groupId the group ID
15780             * @param categoryId the category ID
15781             * @param threadId the thread ID
15782             * @param answer the answer
15783             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15784             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15785             * @throws SystemException if a system exception occurred
15786             */
15787            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
15788                    long threadId, boolean answer, OrderByComparator orderByComparator)
15789                    throws SystemException {
15790                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15791                                    answer, 0, 1, orderByComparator);
15792    
15793                    if (!list.isEmpty()) {
15794                            return list.get(0);
15795                    }
15796    
15797                    return null;
15798            }
15799    
15800            /**
15801             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15802             *
15803             * @param groupId the group ID
15804             * @param categoryId the category ID
15805             * @param threadId the thread ID
15806             * @param answer the answer
15807             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15808             * @return the last matching message-boards message
15809             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15810             * @throws SystemException if a system exception occurred
15811             */
15812            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
15813                    long threadId, boolean answer, OrderByComparator orderByComparator)
15814                    throws NoSuchMessageException, SystemException {
15815                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
15816                                    threadId, answer, orderByComparator);
15817    
15818                    if (mbMessage != null) {
15819                            return mbMessage;
15820                    }
15821    
15822                    StringBundler msg = new StringBundler(10);
15823    
15824                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15825    
15826                    msg.append("groupId=");
15827                    msg.append(groupId);
15828    
15829                    msg.append(", categoryId=");
15830                    msg.append(categoryId);
15831    
15832                    msg.append(", threadId=");
15833                    msg.append(threadId);
15834    
15835                    msg.append(", answer=");
15836                    msg.append(answer);
15837    
15838                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15839    
15840                    throw new NoSuchMessageException(msg.toString());
15841            }
15842    
15843            /**
15844             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15845             *
15846             * @param groupId the group ID
15847             * @param categoryId the category ID
15848             * @param threadId the thread ID
15849             * @param answer the answer
15850             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15851             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15852             * @throws SystemException if a system exception occurred
15853             */
15854            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
15855                    long threadId, boolean answer, OrderByComparator orderByComparator)
15856                    throws SystemException {
15857                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
15858    
15859                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
15860                                    answer, count - 1, count, orderByComparator);
15861    
15862                    if (!list.isEmpty()) {
15863                            return list.get(0);
15864                    }
15865    
15866                    return null;
15867            }
15868    
15869            /**
15870             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
15871             *
15872             * @param messageId the primary key of the current message-boards message
15873             * @param groupId the group ID
15874             * @param categoryId the category ID
15875             * @param threadId the thread ID
15876             * @param answer the answer
15877             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15878             * @return the previous, current, and next message-boards message
15879             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15880             * @throws SystemException if a system exception occurred
15881             */
15882            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
15883                    long categoryId, long threadId, boolean answer,
15884                    OrderByComparator orderByComparator)
15885                    throws NoSuchMessageException, SystemException {
15886                    MBMessage mbMessage = findByPrimaryKey(messageId);
15887    
15888                    Session session = null;
15889    
15890                    try {
15891                            session = openSession();
15892    
15893                            MBMessage[] array = new MBMessageImpl[3];
15894    
15895                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15896                                            categoryId, threadId, answer, orderByComparator, true);
15897    
15898                            array[1] = mbMessage;
15899    
15900                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
15901                                            categoryId, threadId, answer, orderByComparator, false);
15902    
15903                            return array;
15904                    }
15905                    catch (Exception e) {
15906                            throw processException(e);
15907                    }
15908                    finally {
15909                            closeSession(session);
15910                    }
15911            }
15912    
15913            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
15914                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
15915                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
15916                    StringBundler query = null;
15917    
15918                    if (orderByComparator != null) {
15919                            query = new StringBundler(6 +
15920                                            (orderByComparator.getOrderByFields().length * 6));
15921                    }
15922                    else {
15923                            query = new StringBundler(3);
15924                    }
15925    
15926                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15927    
15928                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
15929    
15930                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
15931    
15932                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
15933    
15934                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
15935    
15936                    if (orderByComparator != null) {
15937                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15938    
15939                            if (orderByConditionFields.length > 0) {
15940                                    query.append(WHERE_AND);
15941                            }
15942    
15943                            for (int i = 0; i < orderByConditionFields.length; i++) {
15944                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15945                                    query.append(orderByConditionFields[i]);
15946    
15947                                    if ((i + 1) < orderByConditionFields.length) {
15948                                            if (orderByComparator.isAscending() ^ previous) {
15949                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15950                                            }
15951                                            else {
15952                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15953                                            }
15954                                    }
15955                                    else {
15956                                            if (orderByComparator.isAscending() ^ previous) {
15957                                                    query.append(WHERE_GREATER_THAN);
15958                                            }
15959                                            else {
15960                                                    query.append(WHERE_LESSER_THAN);
15961                                            }
15962                                    }
15963                            }
15964    
15965                            query.append(ORDER_BY_CLAUSE);
15966    
15967                            String[] orderByFields = orderByComparator.getOrderByFields();
15968    
15969                            for (int i = 0; i < orderByFields.length; i++) {
15970                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15971                                    query.append(orderByFields[i]);
15972    
15973                                    if ((i + 1) < orderByFields.length) {
15974                                            if (orderByComparator.isAscending() ^ previous) {
15975                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15976                                            }
15977                                            else {
15978                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15979                                            }
15980                                    }
15981                                    else {
15982                                            if (orderByComparator.isAscending() ^ previous) {
15983                                                    query.append(ORDER_BY_ASC);
15984                                            }
15985                                            else {
15986                                                    query.append(ORDER_BY_DESC);
15987                                            }
15988                                    }
15989                            }
15990                    }
15991                    else {
15992                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15993                    }
15994    
15995                    String sql = query.toString();
15996    
15997                    Query q = session.createQuery(sql);
15998    
15999                    q.setFirstResult(0);
16000                    q.setMaxResults(2);
16001    
16002                    QueryPos qPos = QueryPos.getInstance(q);
16003    
16004                    qPos.add(groupId);
16005    
16006                    qPos.add(categoryId);
16007    
16008                    qPos.add(threadId);
16009    
16010                    qPos.add(answer);
16011    
16012                    if (orderByComparator != null) {
16013                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16014    
16015                            for (Object value : values) {
16016                                    qPos.add(value);
16017                            }
16018                    }
16019    
16020                    List<MBMessage> list = q.list();
16021    
16022                    if (list.size() == 2) {
16023                            return list.get(1);
16024                    }
16025                    else {
16026                            return null;
16027                    }
16028            }
16029    
16030            /**
16031             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16032             *
16033             * @param groupId the group ID
16034             * @param categoryId the category ID
16035             * @param threadId the thread ID
16036             * @param answer the answer
16037             * @return the matching message-boards messages that the user has permission to view
16038             * @throws SystemException if a system exception occurred
16039             */
16040            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16041                    long threadId, boolean answer) throws SystemException {
16042                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16043                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16044            }
16045    
16046            /**
16047             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16048             *
16049             * <p>
16050             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16051             * </p>
16052             *
16053             * @param groupId the group ID
16054             * @param categoryId the category ID
16055             * @param threadId the thread ID
16056             * @param answer the answer
16057             * @param start the lower bound of the range of message-boards messages
16058             * @param end the upper bound of the range of message-boards messages (not inclusive)
16059             * @return the range of matching message-boards messages that the user has permission to view
16060             * @throws SystemException if a system exception occurred
16061             */
16062            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16063                    long threadId, boolean answer, int start, int end)
16064                    throws SystemException {
16065                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
16066                            start, end, null);
16067            }
16068    
16069            /**
16070             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16071             *
16072             * <p>
16073             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16074             * </p>
16075             *
16076             * @param groupId the group ID
16077             * @param categoryId the category ID
16078             * @param threadId the thread ID
16079             * @param answer the answer
16080             * @param start the lower bound of the range of message-boards messages
16081             * @param end the upper bound of the range of message-boards messages (not inclusive)
16082             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16083             * @return the ordered range of matching message-boards messages that the user has permission to view
16084             * @throws SystemException if a system exception occurred
16085             */
16086            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
16087                    long threadId, boolean answer, int start, int end,
16088                    OrderByComparator orderByComparator) throws SystemException {
16089                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16090                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
16091                                    end, orderByComparator);
16092                    }
16093    
16094                    StringBundler query = null;
16095    
16096                    if (orderByComparator != null) {
16097                            query = new StringBundler(6 +
16098                                            (orderByComparator.getOrderByFields().length * 3));
16099                    }
16100                    else {
16101                            query = new StringBundler(6);
16102                    }
16103    
16104                    if (getDB().isSupportsInlineDistinct()) {
16105                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16106                    }
16107                    else {
16108                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16109                    }
16110    
16111                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16112    
16113                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16114    
16115                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16116    
16117                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16118    
16119                    if (!getDB().isSupportsInlineDistinct()) {
16120                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16121                    }
16122    
16123                    if (orderByComparator != null) {
16124                            if (getDB().isSupportsInlineDistinct()) {
16125                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16126                                            orderByComparator);
16127                            }
16128                            else {
16129                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16130                                            orderByComparator);
16131                            }
16132                    }
16133                    else {
16134                            if (getDB().isSupportsInlineDistinct()) {
16135                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16136                            }
16137                            else {
16138                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16139                            }
16140                    }
16141    
16142                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16143                                    MBMessage.class.getName(),
16144                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16145    
16146                    Session session = null;
16147    
16148                    try {
16149                            session = openSession();
16150    
16151                            SQLQuery q = session.createSQLQuery(sql);
16152    
16153                            if (getDB().isSupportsInlineDistinct()) {
16154                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16155                            }
16156                            else {
16157                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16158                            }
16159    
16160                            QueryPos qPos = QueryPos.getInstance(q);
16161    
16162                            qPos.add(groupId);
16163    
16164                            qPos.add(categoryId);
16165    
16166                            qPos.add(threadId);
16167    
16168                            qPos.add(answer);
16169    
16170                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16171                    }
16172                    catch (Exception e) {
16173                            throw processException(e);
16174                    }
16175                    finally {
16176                            closeSession(session);
16177                    }
16178            }
16179    
16180            /**
16181             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16182             *
16183             * @param messageId the primary key of the current message-boards message
16184             * @param groupId the group ID
16185             * @param categoryId the category ID
16186             * @param threadId the thread ID
16187             * @param answer the answer
16188             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16189             * @return the previous, current, and next message-boards message
16190             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16191             * @throws SystemException if a system exception occurred
16192             */
16193            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
16194                    long groupId, long categoryId, long threadId, boolean answer,
16195                    OrderByComparator orderByComparator)
16196                    throws NoSuchMessageException, SystemException {
16197                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16198                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
16199                                    threadId, answer, orderByComparator);
16200                    }
16201    
16202                    MBMessage mbMessage = findByPrimaryKey(messageId);
16203    
16204                    Session session = null;
16205    
16206                    try {
16207                            session = openSession();
16208    
16209                            MBMessage[] array = new MBMessageImpl[3];
16210    
16211                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16212                                            groupId, categoryId, threadId, answer, orderByComparator,
16213                                            true);
16214    
16215                            array[1] = mbMessage;
16216    
16217                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
16218                                            groupId, categoryId, threadId, answer, orderByComparator,
16219                                            false);
16220    
16221                            return array;
16222                    }
16223                    catch (Exception e) {
16224                            throw processException(e);
16225                    }
16226                    finally {
16227                            closeSession(session);
16228                    }
16229            }
16230    
16231            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
16232                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16233                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
16234                    StringBundler query = null;
16235    
16236                    if (orderByComparator != null) {
16237                            query = new StringBundler(6 +
16238                                            (orderByComparator.getOrderByFields().length * 6));
16239                    }
16240                    else {
16241                            query = new StringBundler(3);
16242                    }
16243    
16244                    if (getDB().isSupportsInlineDistinct()) {
16245                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16246                    }
16247                    else {
16248                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16249                    }
16250    
16251                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16252    
16253                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16254    
16255                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16256    
16257                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16258    
16259                    if (!getDB().isSupportsInlineDistinct()) {
16260                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16261                    }
16262    
16263                    if (orderByComparator != null) {
16264                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16265    
16266                            if (orderByConditionFields.length > 0) {
16267                                    query.append(WHERE_AND);
16268                            }
16269    
16270                            for (int i = 0; i < orderByConditionFields.length; i++) {
16271                                    if (getDB().isSupportsInlineDistinct()) {
16272                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16273                                    }
16274                                    else {
16275                                            query.append(_ORDER_BY_ENTITY_TABLE);
16276                                    }
16277    
16278                                    query.append(orderByConditionFields[i]);
16279    
16280                                    if ((i + 1) < orderByConditionFields.length) {
16281                                            if (orderByComparator.isAscending() ^ previous) {
16282                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16283                                            }
16284                                            else {
16285                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16286                                            }
16287                                    }
16288                                    else {
16289                                            if (orderByComparator.isAscending() ^ previous) {
16290                                                    query.append(WHERE_GREATER_THAN);
16291                                            }
16292                                            else {
16293                                                    query.append(WHERE_LESSER_THAN);
16294                                            }
16295                                    }
16296                            }
16297    
16298                            query.append(ORDER_BY_CLAUSE);
16299    
16300                            String[] orderByFields = orderByComparator.getOrderByFields();
16301    
16302                            for (int i = 0; i < orderByFields.length; i++) {
16303                                    if (getDB().isSupportsInlineDistinct()) {
16304                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16305                                    }
16306                                    else {
16307                                            query.append(_ORDER_BY_ENTITY_TABLE);
16308                                    }
16309    
16310                                    query.append(orderByFields[i]);
16311    
16312                                    if ((i + 1) < orderByFields.length) {
16313                                            if (orderByComparator.isAscending() ^ previous) {
16314                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16315                                            }
16316                                            else {
16317                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16318                                            }
16319                                    }
16320                                    else {
16321                                            if (orderByComparator.isAscending() ^ previous) {
16322                                                    query.append(ORDER_BY_ASC);
16323                                            }
16324                                            else {
16325                                                    query.append(ORDER_BY_DESC);
16326                                            }
16327                                    }
16328                            }
16329                    }
16330                    else {
16331                            if (getDB().isSupportsInlineDistinct()) {
16332                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16333                            }
16334                            else {
16335                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16336                            }
16337                    }
16338    
16339                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16340                                    MBMessage.class.getName(),
16341                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16342    
16343                    SQLQuery q = session.createSQLQuery(sql);
16344    
16345                    q.setFirstResult(0);
16346                    q.setMaxResults(2);
16347    
16348                    if (getDB().isSupportsInlineDistinct()) {
16349                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16350                    }
16351                    else {
16352                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16353                    }
16354    
16355                    QueryPos qPos = QueryPos.getInstance(q);
16356    
16357                    qPos.add(groupId);
16358    
16359                    qPos.add(categoryId);
16360    
16361                    qPos.add(threadId);
16362    
16363                    qPos.add(answer);
16364    
16365                    if (orderByComparator != null) {
16366                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16367    
16368                            for (Object value : values) {
16369                                    qPos.add(value);
16370                            }
16371                    }
16372    
16373                    List<MBMessage> list = q.list();
16374    
16375                    if (list.size() == 2) {
16376                            return list.get(1);
16377                    }
16378                    else {
16379                            return null;
16380                    }
16381            }
16382    
16383            /**
16384             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
16385             *
16386             * @param groupId the group ID
16387             * @param categoryId the category ID
16388             * @param threadId the thread ID
16389             * @param answer the answer
16390             * @throws SystemException if a system exception occurred
16391             */
16392            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
16393                    boolean answer) throws SystemException {
16394                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
16395                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16396                            remove(mbMessage);
16397                    }
16398            }
16399    
16400            /**
16401             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16402             *
16403             * @param groupId the group ID
16404             * @param categoryId the category ID
16405             * @param threadId the thread ID
16406             * @param answer the answer
16407             * @return the number of matching message-boards messages
16408             * @throws SystemException if a system exception occurred
16409             */
16410            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
16411                    boolean answer) throws SystemException {
16412                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
16413    
16414                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
16415    
16416                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16417                                    this);
16418    
16419                    if (count == null) {
16420                            StringBundler query = new StringBundler(5);
16421    
16422                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16423    
16424                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16425    
16426                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16427    
16428                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16429    
16430                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16431    
16432                            String sql = query.toString();
16433    
16434                            Session session = null;
16435    
16436                            try {
16437                                    session = openSession();
16438    
16439                                    Query q = session.createQuery(sql);
16440    
16441                                    QueryPos qPos = QueryPos.getInstance(q);
16442    
16443                                    qPos.add(groupId);
16444    
16445                                    qPos.add(categoryId);
16446    
16447                                    qPos.add(threadId);
16448    
16449                                    qPos.add(answer);
16450    
16451                                    count = (Long)q.uniqueResult();
16452    
16453                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16454                            }
16455                            catch (Exception e) {
16456                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16457    
16458                                    throw processException(e);
16459                            }
16460                            finally {
16461                                    closeSession(session);
16462                            }
16463                    }
16464    
16465                    return count.intValue();
16466            }
16467    
16468            /**
16469             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
16470             *
16471             * @param groupId the group ID
16472             * @param categoryId the category ID
16473             * @param threadId the thread ID
16474             * @param answer the answer
16475             * @return the number of matching message-boards messages that the user has permission to view
16476             * @throws SystemException if a system exception occurred
16477             */
16478            public int filterCountByG_C_T_A(long groupId, long categoryId,
16479                    long threadId, boolean answer) throws SystemException {
16480                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16481                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
16482                    }
16483    
16484                    StringBundler query = new StringBundler(5);
16485    
16486                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
16487    
16488                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
16489    
16490                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
16491    
16492                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
16493    
16494                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
16495    
16496                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16497                                    MBMessage.class.getName(),
16498                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16499    
16500                    Session session = null;
16501    
16502                    try {
16503                            session = openSession();
16504    
16505                            SQLQuery q = session.createSQLQuery(sql);
16506    
16507                            q.addScalar(COUNT_COLUMN_NAME,
16508                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
16509    
16510                            QueryPos qPos = QueryPos.getInstance(q);
16511    
16512                            qPos.add(groupId);
16513    
16514                            qPos.add(categoryId);
16515    
16516                            qPos.add(threadId);
16517    
16518                            qPos.add(answer);
16519    
16520                            Long count = (Long)q.uniqueResult();
16521    
16522                            return count.intValue();
16523                    }
16524                    catch (Exception e) {
16525                            throw processException(e);
16526                    }
16527                    finally {
16528                            closeSession(session);
16529                    }
16530            }
16531    
16532            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
16533            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
16534            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
16535            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
16536            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16537                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16538                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
16539                            new String[] {
16540                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16541                                    Integer.class.getName(),
16542                                    
16543                            Integer.class.getName(), Integer.class.getName(),
16544                                    OrderByComparator.class.getName()
16545                            });
16546            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
16547                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16548                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
16549                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
16550                            new String[] {
16551                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16552                                    Integer.class.getName()
16553                            },
16554                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
16555                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
16556                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
16557                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
16558                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
16559            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
16560                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
16561                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
16562                            new String[] {
16563                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
16564                                    Integer.class.getName()
16565                            });
16566    
16567            /**
16568             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16569             *
16570             * @param groupId the group ID
16571             * @param categoryId the category ID
16572             * @param threadId the thread ID
16573             * @param status the status
16574             * @return the matching message-boards messages
16575             * @throws SystemException if a system exception occurred
16576             */
16577            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16578                    long threadId, int status) throws SystemException {
16579                    return findByG_C_T_S(groupId, categoryId, threadId, status,
16580                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16581            }
16582    
16583            /**
16584             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16585             *
16586             * <p>
16587             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16588             * </p>
16589             *
16590             * @param groupId the group ID
16591             * @param categoryId the category ID
16592             * @param threadId the thread ID
16593             * @param status the status
16594             * @param start the lower bound of the range of message-boards messages
16595             * @param end the upper bound of the range of message-boards messages (not inclusive)
16596             * @return the range of matching message-boards messages
16597             * @throws SystemException if a system exception occurred
16598             */
16599            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16600                    long threadId, int status, int start, int end)
16601                    throws SystemException {
16602                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
16603                            null);
16604            }
16605    
16606            /**
16607             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16608             *
16609             * <p>
16610             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
16611             * </p>
16612             *
16613             * @param groupId the group ID
16614             * @param categoryId the category ID
16615             * @param threadId the thread ID
16616             * @param status the status
16617             * @param start the lower bound of the range of message-boards messages
16618             * @param end the upper bound of the range of message-boards messages (not inclusive)
16619             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16620             * @return the ordered range of matching message-boards messages
16621             * @throws SystemException if a system exception occurred
16622             */
16623            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
16624                    long threadId, int status, int start, int end,
16625                    OrderByComparator orderByComparator) throws SystemException {
16626                    boolean pagination = true;
16627                    FinderPath finderPath = null;
16628                    Object[] finderArgs = null;
16629    
16630                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16631                                    (orderByComparator == null)) {
16632                            pagination = false;
16633                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
16634                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
16635                    }
16636                    else {
16637                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
16638                            finderArgs = new Object[] {
16639                                            groupId, categoryId, threadId, status,
16640                                            
16641                                            start, end, orderByComparator
16642                                    };
16643                    }
16644    
16645                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
16646                                    finderArgs, this);
16647    
16648                    if ((list != null) && !list.isEmpty()) {
16649                            for (MBMessage mbMessage : list) {
16650                                    if ((groupId != mbMessage.getGroupId()) ||
16651                                                    (categoryId != mbMessage.getCategoryId()) ||
16652                                                    (threadId != mbMessage.getThreadId()) ||
16653                                                    (status != mbMessage.getStatus())) {
16654                                            list = null;
16655    
16656                                            break;
16657                                    }
16658                            }
16659                    }
16660    
16661                    if (list == null) {
16662                            StringBundler query = null;
16663    
16664                            if (orderByComparator != null) {
16665                                    query = new StringBundler(6 +
16666                                                    (orderByComparator.getOrderByFields().length * 3));
16667                            }
16668                            else {
16669                                    query = new StringBundler(6);
16670                            }
16671    
16672                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16673    
16674                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16675    
16676                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16677    
16678                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16679    
16680                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16681    
16682                            if (orderByComparator != null) {
16683                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16684                                            orderByComparator);
16685                            }
16686                            else
16687                             if (pagination) {
16688                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16689                            }
16690    
16691                            String sql = query.toString();
16692    
16693                            Session session = null;
16694    
16695                            try {
16696                                    session = openSession();
16697    
16698                                    Query q = session.createQuery(sql);
16699    
16700                                    QueryPos qPos = QueryPos.getInstance(q);
16701    
16702                                    qPos.add(groupId);
16703    
16704                                    qPos.add(categoryId);
16705    
16706                                    qPos.add(threadId);
16707    
16708                                    qPos.add(status);
16709    
16710                                    if (!pagination) {
16711                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16712                                                            start, end, false);
16713    
16714                                            Collections.sort(list);
16715    
16716                                            list = new UnmodifiableList<MBMessage>(list);
16717                                    }
16718                                    else {
16719                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16720                                                            start, end);
16721                                    }
16722    
16723                                    cacheResult(list);
16724    
16725                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
16726                            }
16727                            catch (Exception e) {
16728                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16729    
16730                                    throw processException(e);
16731                            }
16732                            finally {
16733                                    closeSession(session);
16734                            }
16735                    }
16736    
16737                    return list;
16738            }
16739    
16740            /**
16741             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16742             *
16743             * @param groupId the group ID
16744             * @param categoryId the category ID
16745             * @param threadId the thread ID
16746             * @param status the status
16747             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16748             * @return the first matching message-boards message
16749             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16750             * @throws SystemException if a system exception occurred
16751             */
16752            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
16753                    long threadId, int status, OrderByComparator orderByComparator)
16754                    throws NoSuchMessageException, SystemException {
16755                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
16756                                    threadId, status, orderByComparator);
16757    
16758                    if (mbMessage != null) {
16759                            return mbMessage;
16760                    }
16761    
16762                    StringBundler msg = new StringBundler(10);
16763    
16764                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16765    
16766                    msg.append("groupId=");
16767                    msg.append(groupId);
16768    
16769                    msg.append(", categoryId=");
16770                    msg.append(categoryId);
16771    
16772                    msg.append(", threadId=");
16773                    msg.append(threadId);
16774    
16775                    msg.append(", status=");
16776                    msg.append(status);
16777    
16778                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16779    
16780                    throw new NoSuchMessageException(msg.toString());
16781            }
16782    
16783            /**
16784             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16785             *
16786             * @param groupId the group ID
16787             * @param categoryId the category ID
16788             * @param threadId the thread ID
16789             * @param status the status
16790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16791             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16792             * @throws SystemException if a system exception occurred
16793             */
16794            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
16795                    long threadId, int status, OrderByComparator orderByComparator)
16796                    throws SystemException {
16797                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16798                                    status, 0, 1, orderByComparator);
16799    
16800                    if (!list.isEmpty()) {
16801                            return list.get(0);
16802                    }
16803    
16804                    return null;
16805            }
16806    
16807            /**
16808             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16809             *
16810             * @param groupId the group ID
16811             * @param categoryId the category ID
16812             * @param threadId the thread ID
16813             * @param status the status
16814             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16815             * @return the last matching message-boards message
16816             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
16817             * @throws SystemException if a system exception occurred
16818             */
16819            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
16820                    long threadId, int status, OrderByComparator orderByComparator)
16821                    throws NoSuchMessageException, SystemException {
16822                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
16823                                    threadId, status, orderByComparator);
16824    
16825                    if (mbMessage != null) {
16826                            return mbMessage;
16827                    }
16828    
16829                    StringBundler msg = new StringBundler(10);
16830    
16831                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
16832    
16833                    msg.append("groupId=");
16834                    msg.append(groupId);
16835    
16836                    msg.append(", categoryId=");
16837                    msg.append(categoryId);
16838    
16839                    msg.append(", threadId=");
16840                    msg.append(threadId);
16841    
16842                    msg.append(", status=");
16843                    msg.append(status);
16844    
16845                    msg.append(StringPool.CLOSE_CURLY_BRACE);
16846    
16847                    throw new NoSuchMessageException(msg.toString());
16848            }
16849    
16850            /**
16851             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16852             *
16853             * @param groupId the group ID
16854             * @param categoryId the category ID
16855             * @param threadId the thread ID
16856             * @param status the status
16857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16858             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
16859             * @throws SystemException if a system exception occurred
16860             */
16861            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
16862                    long threadId, int status, OrderByComparator orderByComparator)
16863                    throws SystemException {
16864                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
16865    
16866                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
16867                                    status, count - 1, count, orderByComparator);
16868    
16869                    if (!list.isEmpty()) {
16870                            return list.get(0);
16871                    }
16872    
16873                    return null;
16874            }
16875    
16876            /**
16877             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
16878             *
16879             * @param messageId the primary key of the current message-boards message
16880             * @param groupId the group ID
16881             * @param categoryId the category ID
16882             * @param threadId the thread ID
16883             * @param status the status
16884             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16885             * @return the previous, current, and next message-boards message
16886             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16887             * @throws SystemException if a system exception occurred
16888             */
16889            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
16890                    long categoryId, long threadId, int status,
16891                    OrderByComparator orderByComparator)
16892                    throws NoSuchMessageException, SystemException {
16893                    MBMessage mbMessage = findByPrimaryKey(messageId);
16894    
16895                    Session session = null;
16896    
16897                    try {
16898                            session = openSession();
16899    
16900                            MBMessage[] array = new MBMessageImpl[3];
16901    
16902                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16903                                            categoryId, threadId, status, orderByComparator, true);
16904    
16905                            array[1] = mbMessage;
16906    
16907                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
16908                                            categoryId, threadId, status, orderByComparator, false);
16909    
16910                            return array;
16911                    }
16912                    catch (Exception e) {
16913                            throw processException(e);
16914                    }
16915                    finally {
16916                            closeSession(session);
16917                    }
16918            }
16919    
16920            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
16921                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
16922                    int status, OrderByComparator orderByComparator, boolean previous) {
16923                    StringBundler query = null;
16924    
16925                    if (orderByComparator != null) {
16926                            query = new StringBundler(6 +
16927                                            (orderByComparator.getOrderByFields().length * 6));
16928                    }
16929                    else {
16930                            query = new StringBundler(3);
16931                    }
16932    
16933                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16934    
16935                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
16936    
16937                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
16938    
16939                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
16940    
16941                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
16942    
16943                    if (orderByComparator != null) {
16944                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16945    
16946                            if (orderByConditionFields.length > 0) {
16947                                    query.append(WHERE_AND);
16948                            }
16949    
16950                            for (int i = 0; i < orderByConditionFields.length; i++) {
16951                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16952                                    query.append(orderByConditionFields[i]);
16953    
16954                                    if ((i + 1) < orderByConditionFields.length) {
16955                                            if (orderByComparator.isAscending() ^ previous) {
16956                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16957                                            }
16958                                            else {
16959                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16960                                            }
16961                                    }
16962                                    else {
16963                                            if (orderByComparator.isAscending() ^ previous) {
16964                                                    query.append(WHERE_GREATER_THAN);
16965                                            }
16966                                            else {
16967                                                    query.append(WHERE_LESSER_THAN);
16968                                            }
16969                                    }
16970                            }
16971    
16972                            query.append(ORDER_BY_CLAUSE);
16973    
16974                            String[] orderByFields = orderByComparator.getOrderByFields();
16975    
16976                            for (int i = 0; i < orderByFields.length; i++) {
16977                                    query.append(_ORDER_BY_ENTITY_ALIAS);
16978                                    query.append(orderByFields[i]);
16979    
16980                                    if ((i + 1) < orderByFields.length) {
16981                                            if (orderByComparator.isAscending() ^ previous) {
16982                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16983                                            }
16984                                            else {
16985                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16986                                            }
16987                                    }
16988                                    else {
16989                                            if (orderByComparator.isAscending() ^ previous) {
16990                                                    query.append(ORDER_BY_ASC);
16991                                            }
16992                                            else {
16993                                                    query.append(ORDER_BY_DESC);
16994                                            }
16995                                    }
16996                            }
16997                    }
16998                    else {
16999                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17000                    }
17001    
17002                    String sql = query.toString();
17003    
17004                    Query q = session.createQuery(sql);
17005    
17006                    q.setFirstResult(0);
17007                    q.setMaxResults(2);
17008    
17009                    QueryPos qPos = QueryPos.getInstance(q);
17010    
17011                    qPos.add(groupId);
17012    
17013                    qPos.add(categoryId);
17014    
17015                    qPos.add(threadId);
17016    
17017                    qPos.add(status);
17018    
17019                    if (orderByComparator != null) {
17020                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17021    
17022                            for (Object value : values) {
17023                                    qPos.add(value);
17024                            }
17025                    }
17026    
17027                    List<MBMessage> list = q.list();
17028    
17029                    if (list.size() == 2) {
17030                            return list.get(1);
17031                    }
17032                    else {
17033                            return null;
17034                    }
17035            }
17036    
17037            /**
17038             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17039             *
17040             * @param groupId the group ID
17041             * @param categoryId the category ID
17042             * @param threadId the thread ID
17043             * @param status the status
17044             * @return the matching message-boards messages that the user has permission to view
17045             * @throws SystemException if a system exception occurred
17046             */
17047            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17048                    long threadId, int status) throws SystemException {
17049                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17050                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17051            }
17052    
17053            /**
17054             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17055             *
17056             * <p>
17057             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17058             * </p>
17059             *
17060             * @param groupId the group ID
17061             * @param categoryId the category ID
17062             * @param threadId the thread ID
17063             * @param status the status
17064             * @param start the lower bound of the range of message-boards messages
17065             * @param end the upper bound of the range of message-boards messages (not inclusive)
17066             * @return the range of matching message-boards messages that the user has permission to view
17067             * @throws SystemException if a system exception occurred
17068             */
17069            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17070                    long threadId, int status, int start, int end)
17071                    throws SystemException {
17072                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
17073                            start, end, null);
17074            }
17075    
17076            /**
17077             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17078             *
17079             * <p>
17080             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17081             * </p>
17082             *
17083             * @param groupId the group ID
17084             * @param categoryId the category ID
17085             * @param threadId the thread ID
17086             * @param status the status
17087             * @param start the lower bound of the range of message-boards messages
17088             * @param end the upper bound of the range of message-boards messages (not inclusive)
17089             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17090             * @return the ordered range of matching message-boards messages that the user has permission to view
17091             * @throws SystemException if a system exception occurred
17092             */
17093            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
17094                    long threadId, int status, int start, int end,
17095                    OrderByComparator orderByComparator) throws SystemException {
17096                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17097                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
17098                                    end, orderByComparator);
17099                    }
17100    
17101                    StringBundler query = null;
17102    
17103                    if (orderByComparator != null) {
17104                            query = new StringBundler(6 +
17105                                            (orderByComparator.getOrderByFields().length * 3));
17106                    }
17107                    else {
17108                            query = new StringBundler(6);
17109                    }
17110    
17111                    if (getDB().isSupportsInlineDistinct()) {
17112                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17113                    }
17114                    else {
17115                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17116                    }
17117    
17118                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17119    
17120                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17121    
17122                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17123    
17124                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17125    
17126                    if (!getDB().isSupportsInlineDistinct()) {
17127                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17128                    }
17129    
17130                    if (orderByComparator != null) {
17131                            if (getDB().isSupportsInlineDistinct()) {
17132                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17133                                            orderByComparator);
17134                            }
17135                            else {
17136                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17137                                            orderByComparator);
17138                            }
17139                    }
17140                    else {
17141                            if (getDB().isSupportsInlineDistinct()) {
17142                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17143                            }
17144                            else {
17145                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17146                            }
17147                    }
17148    
17149                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17150                                    MBMessage.class.getName(),
17151                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17152    
17153                    Session session = null;
17154    
17155                    try {
17156                            session = openSession();
17157    
17158                            SQLQuery q = session.createSQLQuery(sql);
17159    
17160                            if (getDB().isSupportsInlineDistinct()) {
17161                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17162                            }
17163                            else {
17164                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17165                            }
17166    
17167                            QueryPos qPos = QueryPos.getInstance(q);
17168    
17169                            qPos.add(groupId);
17170    
17171                            qPos.add(categoryId);
17172    
17173                            qPos.add(threadId);
17174    
17175                            qPos.add(status);
17176    
17177                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17178                    }
17179                    catch (Exception e) {
17180                            throw processException(e);
17181                    }
17182                    finally {
17183                            closeSession(session);
17184                    }
17185            }
17186    
17187            /**
17188             * Returns the message-boards messages before and after the current message-boards message in the ordered set of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17189             *
17190             * @param messageId the primary key of the current message-boards message
17191             * @param groupId the group ID
17192             * @param categoryId the category ID
17193             * @param threadId the thread ID
17194             * @param status the status
17195             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17196             * @return the previous, current, and next message-boards message
17197             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17198             * @throws SystemException if a system exception occurred
17199             */
17200            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
17201                    long groupId, long categoryId, long threadId, int status,
17202                    OrderByComparator orderByComparator)
17203                    throws NoSuchMessageException, SystemException {
17204                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17205                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
17206                                    threadId, status, orderByComparator);
17207                    }
17208    
17209                    MBMessage mbMessage = findByPrimaryKey(messageId);
17210    
17211                    Session session = null;
17212    
17213                    try {
17214                            session = openSession();
17215    
17216                            MBMessage[] array = new MBMessageImpl[3];
17217    
17218                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17219                                            groupId, categoryId, threadId, status, orderByComparator,
17220                                            true);
17221    
17222                            array[1] = mbMessage;
17223    
17224                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
17225                                            groupId, categoryId, threadId, status, orderByComparator,
17226                                            false);
17227    
17228                            return array;
17229                    }
17230                    catch (Exception e) {
17231                            throw processException(e);
17232                    }
17233                    finally {
17234                            closeSession(session);
17235                    }
17236            }
17237    
17238            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
17239                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17240                    int status, OrderByComparator orderByComparator, boolean previous) {
17241                    StringBundler query = null;
17242    
17243                    if (orderByComparator != null) {
17244                            query = new StringBundler(6 +
17245                                            (orderByComparator.getOrderByFields().length * 6));
17246                    }
17247                    else {
17248                            query = new StringBundler(3);
17249                    }
17250    
17251                    if (getDB().isSupportsInlineDistinct()) {
17252                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17253                    }
17254                    else {
17255                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17256                    }
17257    
17258                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17259    
17260                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17261    
17262                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17263    
17264                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17265    
17266                    if (!getDB().isSupportsInlineDistinct()) {
17267                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17268                    }
17269    
17270                    if (orderByComparator != null) {
17271                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17272    
17273                            if (orderByConditionFields.length > 0) {
17274                                    query.append(WHERE_AND);
17275                            }
17276    
17277                            for (int i = 0; i < orderByConditionFields.length; i++) {
17278                                    if (getDB().isSupportsInlineDistinct()) {
17279                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17280                                    }
17281                                    else {
17282                                            query.append(_ORDER_BY_ENTITY_TABLE);
17283                                    }
17284    
17285                                    query.append(orderByConditionFields[i]);
17286    
17287                                    if ((i + 1) < orderByConditionFields.length) {
17288                                            if (orderByComparator.isAscending() ^ previous) {
17289                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17290                                            }
17291                                            else {
17292                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17293                                            }
17294                                    }
17295                                    else {
17296                                            if (orderByComparator.isAscending() ^ previous) {
17297                                                    query.append(WHERE_GREATER_THAN);
17298                                            }
17299                                            else {
17300                                                    query.append(WHERE_LESSER_THAN);
17301                                            }
17302                                    }
17303                            }
17304    
17305                            query.append(ORDER_BY_CLAUSE);
17306    
17307                            String[] orderByFields = orderByComparator.getOrderByFields();
17308    
17309                            for (int i = 0; i < orderByFields.length; i++) {
17310                                    if (getDB().isSupportsInlineDistinct()) {
17311                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17312                                    }
17313                                    else {
17314                                            query.append(_ORDER_BY_ENTITY_TABLE);
17315                                    }
17316    
17317                                    query.append(orderByFields[i]);
17318    
17319                                    if ((i + 1) < orderByFields.length) {
17320                                            if (orderByComparator.isAscending() ^ previous) {
17321                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17322                                            }
17323                                            else {
17324                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17325                                            }
17326                                    }
17327                                    else {
17328                                            if (orderByComparator.isAscending() ^ previous) {
17329                                                    query.append(ORDER_BY_ASC);
17330                                            }
17331                                            else {
17332                                                    query.append(ORDER_BY_DESC);
17333                                            }
17334                                    }
17335                            }
17336                    }
17337                    else {
17338                            if (getDB().isSupportsInlineDistinct()) {
17339                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17340                            }
17341                            else {
17342                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17343                            }
17344                    }
17345    
17346                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17347                                    MBMessage.class.getName(),
17348                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17349    
17350                    SQLQuery q = session.createSQLQuery(sql);
17351    
17352                    q.setFirstResult(0);
17353                    q.setMaxResults(2);
17354    
17355                    if (getDB().isSupportsInlineDistinct()) {
17356                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17357                    }
17358                    else {
17359                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17360                    }
17361    
17362                    QueryPos qPos = QueryPos.getInstance(q);
17363    
17364                    qPos.add(groupId);
17365    
17366                    qPos.add(categoryId);
17367    
17368                    qPos.add(threadId);
17369    
17370                    qPos.add(status);
17371    
17372                    if (orderByComparator != null) {
17373                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17374    
17375                            for (Object value : values) {
17376                                    qPos.add(value);
17377                            }
17378                    }
17379    
17380                    List<MBMessage> list = q.list();
17381    
17382                    if (list.size() == 2) {
17383                            return list.get(1);
17384                    }
17385                    else {
17386                            return null;
17387                    }
17388            }
17389    
17390            /**
17391             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
17392             *
17393             * @param groupId the group ID
17394             * @param categoryId the category ID
17395             * @param threadId the thread ID
17396             * @param status the status
17397             * @throws SystemException if a system exception occurred
17398             */
17399            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
17400                    int status) throws SystemException {
17401                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
17402                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
17403                            remove(mbMessage);
17404                    }
17405            }
17406    
17407            /**
17408             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17409             *
17410             * @param groupId the group ID
17411             * @param categoryId the category ID
17412             * @param threadId the thread ID
17413             * @param status the status
17414             * @return the number of matching message-boards messages
17415             * @throws SystemException if a system exception occurred
17416             */
17417            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
17418                    int status) throws SystemException {
17419                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
17420    
17421                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
17422    
17423                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
17424                                    this);
17425    
17426                    if (count == null) {
17427                            StringBundler query = new StringBundler(5);
17428    
17429                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
17430    
17431                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17432    
17433                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17434    
17435                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17436    
17437                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17438    
17439                            String sql = query.toString();
17440    
17441                            Session session = null;
17442    
17443                            try {
17444                                    session = openSession();
17445    
17446                                    Query q = session.createQuery(sql);
17447    
17448                                    QueryPos qPos = QueryPos.getInstance(q);
17449    
17450                                    qPos.add(groupId);
17451    
17452                                    qPos.add(categoryId);
17453    
17454                                    qPos.add(threadId);
17455    
17456                                    qPos.add(status);
17457    
17458                                    count = (Long)q.uniqueResult();
17459    
17460                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
17461                            }
17462                            catch (Exception e) {
17463                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17464    
17465                                    throw processException(e);
17466                            }
17467                            finally {
17468                                    closeSession(session);
17469                            }
17470                    }
17471    
17472                    return count.intValue();
17473            }
17474    
17475            /**
17476             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
17477             *
17478             * @param groupId the group ID
17479             * @param categoryId the category ID
17480             * @param threadId the thread ID
17481             * @param status the status
17482             * @return the number of matching message-boards messages that the user has permission to view
17483             * @throws SystemException if a system exception occurred
17484             */
17485            public int filterCountByG_C_T_S(long groupId, long categoryId,
17486                    long threadId, int status) throws SystemException {
17487                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17488                            return countByG_C_T_S(groupId, categoryId, threadId, status);
17489                    }
17490    
17491                    StringBundler query = new StringBundler(5);
17492    
17493                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17494    
17495                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
17496    
17497                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
17498    
17499                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
17500    
17501                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
17502    
17503                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17504                                    MBMessage.class.getName(),
17505                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17506    
17507                    Session session = null;
17508    
17509                    try {
17510                            session = openSession();
17511    
17512                            SQLQuery q = session.createSQLQuery(sql);
17513    
17514                            q.addScalar(COUNT_COLUMN_NAME,
17515                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17516    
17517                            QueryPos qPos = QueryPos.getInstance(q);
17518    
17519                            qPos.add(groupId);
17520    
17521                            qPos.add(categoryId);
17522    
17523                            qPos.add(threadId);
17524    
17525                            qPos.add(status);
17526    
17527                            Long count = (Long)q.uniqueResult();
17528    
17529                            return count.intValue();
17530                    }
17531                    catch (Exception e) {
17532                            throw processException(e);
17533                    }
17534                    finally {
17535                            closeSession(session);
17536                    }
17537            }
17538    
17539            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17540            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17541            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
17542            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
17543            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17544                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17545                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
17546                            new String[] {
17547                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17548                                    Integer.class.getName(),
17549                                    
17550                            Integer.class.getName(), Integer.class.getName(),
17551                                    OrderByComparator.class.getName()
17552                            });
17553            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
17554                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17555                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17556                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
17557                            new String[] {
17558                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17559                                    Integer.class.getName()
17560                            },
17561                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
17562                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
17563                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
17564                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
17565                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17566            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17567                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17568                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
17569                            new String[] {
17570                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17571                                    Integer.class.getName()
17572                            });
17573    
17574            /**
17575             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17576             *
17577             * @param userId the user ID
17578             * @param classNameId the class name ID
17579             * @param classPK the class p k
17580             * @param status the status
17581             * @return the matching message-boards messages
17582             * @throws SystemException if a system exception occurred
17583             */
17584            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17585                    long classPK, int status) throws SystemException {
17586                    return findByU_C_C_S(userId, classNameId, classPK, status,
17587                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17588            }
17589    
17590            /**
17591             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17592             *
17593             * <p>
17594             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17595             * </p>
17596             *
17597             * @param userId the user ID
17598             * @param classNameId the class name ID
17599             * @param classPK the class p k
17600             * @param status the status
17601             * @param start the lower bound of the range of message-boards messages
17602             * @param end the upper bound of the range of message-boards messages (not inclusive)
17603             * @return the range of matching message-boards messages
17604             * @throws SystemException if a system exception occurred
17605             */
17606            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17607                    long classPK, int status, int start, int end) throws SystemException {
17608                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
17609                            null);
17610            }
17611    
17612            /**
17613             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17614             *
17615             * <p>
17616             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
17617             * </p>
17618             *
17619             * @param userId the user ID
17620             * @param classNameId the class name ID
17621             * @param classPK the class p k
17622             * @param status the status
17623             * @param start the lower bound of the range of message-boards messages
17624             * @param end the upper bound of the range of message-boards messages (not inclusive)
17625             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17626             * @return the ordered range of matching message-boards messages
17627             * @throws SystemException if a system exception occurred
17628             */
17629            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
17630                    long classPK, int status, int start, int end,
17631                    OrderByComparator orderByComparator) throws SystemException {
17632                    boolean pagination = true;
17633                    FinderPath finderPath = null;
17634                    Object[] finderArgs = null;
17635    
17636                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17637                                    (orderByComparator == null)) {
17638                            pagination = false;
17639                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
17640                            finderArgs = new Object[] { userId, classNameId, classPK, status };
17641                    }
17642                    else {
17643                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
17644                            finderArgs = new Object[] {
17645                                            userId, classNameId, classPK, status,
17646                                            
17647                                            start, end, orderByComparator
17648                                    };
17649                    }
17650    
17651                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
17652                                    finderArgs, this);
17653    
17654                    if ((list != null) && !list.isEmpty()) {
17655                            for (MBMessage mbMessage : list) {
17656                                    if ((userId != mbMessage.getUserId()) ||
17657                                                    (classNameId != mbMessage.getClassNameId()) ||
17658                                                    (classPK != mbMessage.getClassPK()) ||
17659                                                    (status != mbMessage.getStatus())) {
17660                                            list = null;
17661    
17662                                            break;
17663                                    }
17664                            }
17665                    }
17666    
17667                    if (list == null) {
17668                            StringBundler query = null;
17669    
17670                            if (orderByComparator != null) {
17671                                    query = new StringBundler(6 +
17672                                                    (orderByComparator.getOrderByFields().length * 3));
17673                            }
17674                            else {
17675                                    query = new StringBundler(6);
17676                            }
17677    
17678                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17679    
17680                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17681    
17682                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17683    
17684                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17685    
17686                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17687    
17688                            if (orderByComparator != null) {
17689                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17690                                            orderByComparator);
17691                            }
17692                            else
17693                             if (pagination) {
17694                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17695                            }
17696    
17697                            String sql = query.toString();
17698    
17699                            Session session = null;
17700    
17701                            try {
17702                                    session = openSession();
17703    
17704                                    Query q = session.createQuery(sql);
17705    
17706                                    QueryPos qPos = QueryPos.getInstance(q);
17707    
17708                                    qPos.add(userId);
17709    
17710                                    qPos.add(classNameId);
17711    
17712                                    qPos.add(classPK);
17713    
17714                                    qPos.add(status);
17715    
17716                                    if (!pagination) {
17717                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17718                                                            start, end, false);
17719    
17720                                            Collections.sort(list);
17721    
17722                                            list = new UnmodifiableList<MBMessage>(list);
17723                                    }
17724                                    else {
17725                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17726                                                            start, end);
17727                                    }
17728    
17729                                    cacheResult(list);
17730    
17731                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17732                            }
17733                            catch (Exception e) {
17734                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17735    
17736                                    throw processException(e);
17737                            }
17738                            finally {
17739                                    closeSession(session);
17740                            }
17741                    }
17742    
17743                    return list;
17744            }
17745    
17746            /**
17747             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17748             *
17749             * @param userId the user ID
17750             * @param classNameId the class name ID
17751             * @param classPK the class p k
17752             * @param status the status
17753             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17754             * @return the first matching message-boards message
17755             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17756             * @throws SystemException if a system exception occurred
17757             */
17758            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
17759                    long classPK, int status, OrderByComparator orderByComparator)
17760                    throws NoSuchMessageException, SystemException {
17761                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
17762                                    classPK, status, orderByComparator);
17763    
17764                    if (mbMessage != null) {
17765                            return mbMessage;
17766                    }
17767    
17768                    StringBundler msg = new StringBundler(10);
17769    
17770                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17771    
17772                    msg.append("userId=");
17773                    msg.append(userId);
17774    
17775                    msg.append(", classNameId=");
17776                    msg.append(classNameId);
17777    
17778                    msg.append(", classPK=");
17779                    msg.append(classPK);
17780    
17781                    msg.append(", status=");
17782                    msg.append(status);
17783    
17784                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17785    
17786                    throw new NoSuchMessageException(msg.toString());
17787            }
17788    
17789            /**
17790             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17791             *
17792             * @param userId the user ID
17793             * @param classNameId the class name ID
17794             * @param classPK the class p k
17795             * @param status the status
17796             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17797             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17798             * @throws SystemException if a system exception occurred
17799             */
17800            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
17801                    long classPK, int status, OrderByComparator orderByComparator)
17802                    throws SystemException {
17803                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17804                                    status, 0, 1, orderByComparator);
17805    
17806                    if (!list.isEmpty()) {
17807                            return list.get(0);
17808                    }
17809    
17810                    return null;
17811            }
17812    
17813            /**
17814             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17815             *
17816             * @param userId the user ID
17817             * @param classNameId the class name ID
17818             * @param classPK the class p k
17819             * @param status the status
17820             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17821             * @return the last matching message-boards message
17822             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17823             * @throws SystemException if a system exception occurred
17824             */
17825            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
17826                    long classPK, int status, OrderByComparator orderByComparator)
17827                    throws NoSuchMessageException, SystemException {
17828                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
17829                                    status, orderByComparator);
17830    
17831                    if (mbMessage != null) {
17832                            return mbMessage;
17833                    }
17834    
17835                    StringBundler msg = new StringBundler(10);
17836    
17837                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17838    
17839                    msg.append("userId=");
17840                    msg.append(userId);
17841    
17842                    msg.append(", classNameId=");
17843                    msg.append(classNameId);
17844    
17845                    msg.append(", classPK=");
17846                    msg.append(classPK);
17847    
17848                    msg.append(", status=");
17849                    msg.append(status);
17850    
17851                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17852    
17853                    throw new NoSuchMessageException(msg.toString());
17854            }
17855    
17856            /**
17857             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17858             *
17859             * @param userId the user ID
17860             * @param classNameId the class name ID
17861             * @param classPK the class p k
17862             * @param status the status
17863             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17864             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17865             * @throws SystemException if a system exception occurred
17866             */
17867            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
17868                    long classPK, int status, OrderByComparator orderByComparator)
17869                    throws SystemException {
17870                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
17871    
17872                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
17873                                    status, count - 1, count, orderByComparator);
17874    
17875                    if (!list.isEmpty()) {
17876                            return list.get(0);
17877                    }
17878    
17879                    return null;
17880            }
17881    
17882            /**
17883             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
17884             *
17885             * @param messageId the primary key of the current message-boards message
17886             * @param userId the user ID
17887             * @param classNameId the class name ID
17888             * @param classPK the class p k
17889             * @param status the status
17890             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17891             * @return the previous, current, and next message-boards message
17892             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17893             * @throws SystemException if a system exception occurred
17894             */
17895            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
17896                    long classNameId, long classPK, int status,
17897                    OrderByComparator orderByComparator)
17898                    throws NoSuchMessageException, SystemException {
17899                    MBMessage mbMessage = findByPrimaryKey(messageId);
17900    
17901                    Session session = null;
17902    
17903                    try {
17904                            session = openSession();
17905    
17906                            MBMessage[] array = new MBMessageImpl[3];
17907    
17908                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17909                                            classNameId, classPK, status, orderByComparator, true);
17910    
17911                            array[1] = mbMessage;
17912    
17913                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
17914                                            classNameId, classPK, status, orderByComparator, false);
17915    
17916                            return array;
17917                    }
17918                    catch (Exception e) {
17919                            throw processException(e);
17920                    }
17921                    finally {
17922                            closeSession(session);
17923                    }
17924            }
17925    
17926            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
17927                    MBMessage mbMessage, long userId, long classNameId, long classPK,
17928                    int status, OrderByComparator orderByComparator, boolean previous) {
17929                    StringBundler query = null;
17930    
17931                    if (orderByComparator != null) {
17932                            query = new StringBundler(6 +
17933                                            (orderByComparator.getOrderByFields().length * 6));
17934                    }
17935                    else {
17936                            query = new StringBundler(3);
17937                    }
17938    
17939                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17940    
17941                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
17942    
17943                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
17944    
17945                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
17946    
17947                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
17948    
17949                    if (orderByComparator != null) {
17950                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17951    
17952                            if (orderByConditionFields.length > 0) {
17953                                    query.append(WHERE_AND);
17954                            }
17955    
17956                            for (int i = 0; i < orderByConditionFields.length; i++) {
17957                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17958                                    query.append(orderByConditionFields[i]);
17959    
17960                                    if ((i + 1) < orderByConditionFields.length) {
17961                                            if (orderByComparator.isAscending() ^ previous) {
17962                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17963                                            }
17964                                            else {
17965                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17966                                            }
17967                                    }
17968                                    else {
17969                                            if (orderByComparator.isAscending() ^ previous) {
17970                                                    query.append(WHERE_GREATER_THAN);
17971                                            }
17972                                            else {
17973                                                    query.append(WHERE_LESSER_THAN);
17974                                            }
17975                                    }
17976                            }
17977    
17978                            query.append(ORDER_BY_CLAUSE);
17979    
17980                            String[] orderByFields = orderByComparator.getOrderByFields();
17981    
17982                            for (int i = 0; i < orderByFields.length; i++) {
17983                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17984                                    query.append(orderByFields[i]);
17985    
17986                                    if ((i + 1) < orderByFields.length) {
17987                                            if (orderByComparator.isAscending() ^ previous) {
17988                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17989                                            }
17990                                            else {
17991                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17992                                            }
17993                                    }
17994                                    else {
17995                                            if (orderByComparator.isAscending() ^ previous) {
17996                                                    query.append(ORDER_BY_ASC);
17997                                            }
17998                                            else {
17999                                                    query.append(ORDER_BY_DESC);
18000                                            }
18001                                    }
18002                            }
18003                    }
18004                    else {
18005                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18006                    }
18007    
18008                    String sql = query.toString();
18009    
18010                    Query q = session.createQuery(sql);
18011    
18012                    q.setFirstResult(0);
18013                    q.setMaxResults(2);
18014    
18015                    QueryPos qPos = QueryPos.getInstance(q);
18016    
18017                    qPos.add(userId);
18018    
18019                    qPos.add(classNameId);
18020    
18021                    qPos.add(classPK);
18022    
18023                    qPos.add(status);
18024    
18025                    if (orderByComparator != null) {
18026                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18027    
18028                            for (Object value : values) {
18029                                    qPos.add(value);
18030                            }
18031                    }
18032    
18033                    List<MBMessage> list = q.list();
18034    
18035                    if (list.size() == 2) {
18036                            return list.get(1);
18037                    }
18038                    else {
18039                            return null;
18040                    }
18041            }
18042    
18043            /**
18044             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
18045             *
18046             * @param userId the user ID
18047             * @param classNameId the class name ID
18048             * @param classPK the class p k
18049             * @param status the status
18050             * @throws SystemException if a system exception occurred
18051             */
18052            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
18053                    int status) throws SystemException {
18054                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
18055                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18056                            remove(mbMessage);
18057                    }
18058            }
18059    
18060            /**
18061             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
18062             *
18063             * @param userId the user ID
18064             * @param classNameId the class name ID
18065             * @param classPK the class p k
18066             * @param status the status
18067             * @return the number of matching message-boards messages
18068             * @throws SystemException if a system exception occurred
18069             */
18070            public int countByU_C_C_S(long userId, long classNameId, long classPK,
18071                    int status) throws SystemException {
18072                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
18073    
18074                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
18075    
18076                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18077                                    this);
18078    
18079                    if (count == null) {
18080                            StringBundler query = new StringBundler(5);
18081    
18082                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18083    
18084                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
18085    
18086                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
18087    
18088                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
18089    
18090                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
18091    
18092                            String sql = query.toString();
18093    
18094                            Session session = null;
18095    
18096                            try {
18097                                    session = openSession();
18098    
18099                                    Query q = session.createQuery(sql);
18100    
18101                                    QueryPos qPos = QueryPos.getInstance(q);
18102    
18103                                    qPos.add(userId);
18104    
18105                                    qPos.add(classNameId);
18106    
18107                                    qPos.add(classPK);
18108    
18109                                    qPos.add(status);
18110    
18111                                    count = (Long)q.uniqueResult();
18112    
18113                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18114                            }
18115                            catch (Exception e) {
18116                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18117    
18118                                    throw processException(e);
18119                            }
18120                            finally {
18121                                    closeSession(session);
18122                            }
18123                    }
18124    
18125                    return count.intValue();
18126            }
18127    
18128            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
18129            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
18130            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
18131            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
18132    
18133            /**
18134             * Caches the message-boards message in the entity cache if it is enabled.
18135             *
18136             * @param mbMessage the message-boards message
18137             */
18138            public void cacheResult(MBMessage mbMessage) {
18139                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18140                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18141    
18142                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
18143                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
18144                            mbMessage);
18145    
18146                    mbMessage.resetOriginalValues();
18147            }
18148    
18149            /**
18150             * Caches the message-boards messages in the entity cache if it is enabled.
18151             *
18152             * @param mbMessages the message-boards messages
18153             */
18154            public void cacheResult(List<MBMessage> mbMessages) {
18155                    for (MBMessage mbMessage : mbMessages) {
18156                            if (EntityCacheUtil.getResult(
18157                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18158                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
18159                                    cacheResult(mbMessage);
18160                            }
18161                            else {
18162                                    mbMessage.resetOriginalValues();
18163                            }
18164                    }
18165            }
18166    
18167            /**
18168             * Clears the cache for all message-boards messages.
18169             *
18170             * <p>
18171             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18172             * </p>
18173             */
18174            @Override
18175            public void clearCache() {
18176                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
18177                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
18178                    }
18179    
18180                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
18181    
18182                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
18183                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18184                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18185            }
18186    
18187            /**
18188             * Clears the cache for the message-boards message.
18189             *
18190             * <p>
18191             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
18192             * </p>
18193             */
18194            @Override
18195            public void clearCache(MBMessage mbMessage) {
18196                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18197                            MBMessageImpl.class, mbMessage.getPrimaryKey());
18198    
18199                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18200                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18201    
18202                    clearUniqueFindersCache(mbMessage);
18203            }
18204    
18205            @Override
18206            public void clearCache(List<MBMessage> mbMessages) {
18207                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18208                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18209    
18210                    for (MBMessage mbMessage : mbMessages) {
18211                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18212                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
18213    
18214                            clearUniqueFindersCache(mbMessage);
18215                    }
18216            }
18217    
18218            protected void cacheUniqueFindersCache(MBMessage mbMessage) {
18219                    if (mbMessage.isNew()) {
18220                            Object[] args = new Object[] {
18221                                            mbMessage.getUuid(), mbMessage.getGroupId()
18222                                    };
18223    
18224                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18225                                    Long.valueOf(1));
18226                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18227                                    mbMessage);
18228                    }
18229                    else {
18230                            MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18231    
18232                            if ((mbMessageModelImpl.getColumnBitmask() &
18233                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18234                                    Object[] args = new Object[] {
18235                                                    mbMessage.getUuid(), mbMessage.getGroupId()
18236                                            };
18237    
18238                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
18239                                            Long.valueOf(1));
18240                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
18241                                            mbMessage);
18242                            }
18243                    }
18244            }
18245    
18246            protected void clearUniqueFindersCache(MBMessage mbMessage) {
18247                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18248    
18249                    Object[] args = new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() };
18250    
18251                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18252                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18253    
18254                    if ((mbMessageModelImpl.getColumnBitmask() &
18255                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
18256                            args = new Object[] {
18257                                            mbMessageModelImpl.getOriginalUuid(),
18258                                            mbMessageModelImpl.getOriginalGroupId()
18259                                    };
18260    
18261                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
18262                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
18263                    }
18264            }
18265    
18266            /**
18267             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
18268             *
18269             * @param messageId the primary key for the new message-boards message
18270             * @return the new message-boards message
18271             */
18272            public MBMessage create(long messageId) {
18273                    MBMessage mbMessage = new MBMessageImpl();
18274    
18275                    mbMessage.setNew(true);
18276                    mbMessage.setPrimaryKey(messageId);
18277    
18278                    String uuid = PortalUUIDUtil.generate();
18279    
18280                    mbMessage.setUuid(uuid);
18281    
18282                    return mbMessage;
18283            }
18284    
18285            /**
18286             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18287             *
18288             * @param messageId the primary key of the message-boards message
18289             * @return the message-boards message that was removed
18290             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18291             * @throws SystemException if a system exception occurred
18292             */
18293            public MBMessage remove(long messageId)
18294                    throws NoSuchMessageException, SystemException {
18295                    return remove((Serializable)messageId);
18296            }
18297    
18298            /**
18299             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
18300             *
18301             * @param primaryKey the primary key of the message-boards message
18302             * @return the message-boards message that was removed
18303             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18304             * @throws SystemException if a system exception occurred
18305             */
18306            @Override
18307            public MBMessage remove(Serializable primaryKey)
18308                    throws NoSuchMessageException, SystemException {
18309                    Session session = null;
18310    
18311                    try {
18312                            session = openSession();
18313    
18314                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18315                                            primaryKey);
18316    
18317                            if (mbMessage == null) {
18318                                    if (_log.isWarnEnabled()) {
18319                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
18320                                    }
18321    
18322                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
18323                                            primaryKey);
18324                            }
18325    
18326                            return remove(mbMessage);
18327                    }
18328                    catch (NoSuchMessageException nsee) {
18329                            throw nsee;
18330                    }
18331                    catch (Exception e) {
18332                            throw processException(e);
18333                    }
18334                    finally {
18335                            closeSession(session);
18336                    }
18337            }
18338    
18339            @Override
18340            protected MBMessage removeImpl(MBMessage mbMessage)
18341                    throws SystemException {
18342                    mbMessage = toUnwrappedModel(mbMessage);
18343    
18344                    Session session = null;
18345    
18346                    try {
18347                            session = openSession();
18348    
18349                            if (!session.contains(mbMessage)) {
18350                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
18351                                                    mbMessage.getPrimaryKeyObj());
18352                            }
18353    
18354                            if (mbMessage != null) {
18355                                    session.delete(mbMessage);
18356                            }
18357                    }
18358                    catch (Exception e) {
18359                            throw processException(e);
18360                    }
18361                    finally {
18362                            closeSession(session);
18363                    }
18364    
18365                    if (mbMessage != null) {
18366                            clearCache(mbMessage);
18367                    }
18368    
18369                    return mbMessage;
18370            }
18371    
18372            @Override
18373            public MBMessage updateImpl(
18374                    com.liferay.portlet.messageboards.model.MBMessage mbMessage)
18375                    throws SystemException {
18376                    mbMessage = toUnwrappedModel(mbMessage);
18377    
18378                    boolean isNew = mbMessage.isNew();
18379    
18380                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
18381    
18382                    if (Validator.isNull(mbMessage.getUuid())) {
18383                            String uuid = PortalUUIDUtil.generate();
18384    
18385                            mbMessage.setUuid(uuid);
18386                    }
18387    
18388                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
18389    
18390                    if (userId > 0) {
18391                            long companyId = mbMessage.getCompanyId();
18392    
18393                            long groupId = mbMessage.getGroupId();
18394    
18395                            long messageId = 0;
18396    
18397                            if (!isNew) {
18398                                    messageId = mbMessage.getPrimaryKey();
18399                            }
18400    
18401                            try {
18402                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
18403                                                    userId,
18404                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
18405                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
18406                                                    mbMessage.getSubject(), null));
18407                            }
18408                            catch (SanitizerException se) {
18409                                    throw new SystemException(se);
18410                            }
18411                    }
18412    
18413                    Session session = null;
18414    
18415                    try {
18416                            session = openSession();
18417    
18418                            if (mbMessage.isNew()) {
18419                                    session.save(mbMessage);
18420    
18421                                    mbMessage.setNew(false);
18422                            }
18423                            else {
18424                                    session.merge(mbMessage);
18425                            }
18426                    }
18427                    catch (Exception e) {
18428                            throw processException(e);
18429                    }
18430                    finally {
18431                            closeSession(session);
18432                    }
18433    
18434                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
18435    
18436                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
18437                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
18438                    }
18439    
18440                    else {
18441                            if ((mbMessageModelImpl.getColumnBitmask() &
18442                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
18443                                    Object[] args = new Object[] {
18444                                                    mbMessageModelImpl.getOriginalUuid()
18445                                            };
18446    
18447                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18448                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18449                                            args);
18450    
18451                                    args = new Object[] { mbMessageModelImpl.getUuid() };
18452    
18453                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
18454                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
18455                                            args);
18456                            }
18457    
18458                            if ((mbMessageModelImpl.getColumnBitmask() &
18459                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
18460                                    Object[] args = new Object[] {
18461                                                    mbMessageModelImpl.getOriginalUuid(),
18462                                                    mbMessageModelImpl.getOriginalCompanyId()
18463                                            };
18464    
18465                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18466                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18467                                            args);
18468    
18469                                    args = new Object[] {
18470                                                    mbMessageModelImpl.getUuid(),
18471                                                    mbMessageModelImpl.getCompanyId()
18472                                            };
18473    
18474                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
18475                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
18476                                            args);
18477                            }
18478    
18479                            if ((mbMessageModelImpl.getColumnBitmask() &
18480                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
18481                                    Object[] args = new Object[] {
18482                                                    mbMessageModelImpl.getOriginalGroupId()
18483                                            };
18484    
18485                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18486                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18487                                            args);
18488    
18489                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
18490    
18491                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
18492                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
18493                                            args);
18494                            }
18495    
18496                            if ((mbMessageModelImpl.getColumnBitmask() &
18497                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
18498                                    Object[] args = new Object[] {
18499                                                    mbMessageModelImpl.getOriginalCompanyId()
18500                                            };
18501    
18502                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18503                                            args);
18504                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18505                                            args);
18506    
18507                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
18508    
18509                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
18510                                            args);
18511                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
18512                                            args);
18513                            }
18514    
18515                            if ((mbMessageModelImpl.getColumnBitmask() &
18516                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
18517                                    Object[] args = new Object[] {
18518                                                    mbMessageModelImpl.getOriginalThreadId()
18519                                            };
18520    
18521                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18522                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18523                                            args);
18524    
18525                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
18526    
18527                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
18528                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
18529                                            args);
18530                            }
18531    
18532                            if ((mbMessageModelImpl.getColumnBitmask() &
18533                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
18534                                    Object[] args = new Object[] {
18535                                                    mbMessageModelImpl.getOriginalThreadId()
18536                                            };
18537    
18538                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18539                                            args);
18540                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18541                                            args);
18542    
18543                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
18544    
18545                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
18546                                            args);
18547                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
18548                                            args);
18549                            }
18550    
18551                            if ((mbMessageModelImpl.getColumnBitmask() &
18552                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
18553                                    Object[] args = new Object[] {
18554                                                    mbMessageModelImpl.getOriginalUserId()
18555                                            };
18556    
18557                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18558                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18559                                            args);
18560    
18561                                    args = new Object[] { mbMessageModelImpl.getUserId() };
18562    
18563                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
18564                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
18565                                            args);
18566                            }
18567    
18568                            if ((mbMessageModelImpl.getColumnBitmask() &
18569                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
18570                                    Object[] args = new Object[] {
18571                                                    mbMessageModelImpl.getOriginalGroupId(),
18572                                                    mbMessageModelImpl.getOriginalUserId()
18573                                            };
18574    
18575                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18576                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18577                                            args);
18578    
18579                                    args = new Object[] {
18580                                                    mbMessageModelImpl.getGroupId(),
18581                                                    mbMessageModelImpl.getUserId()
18582                                            };
18583    
18584                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
18585                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
18586                                            args);
18587                            }
18588    
18589                            if ((mbMessageModelImpl.getColumnBitmask() &
18590                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
18591                                    Object[] args = new Object[] {
18592                                                    mbMessageModelImpl.getOriginalGroupId(),
18593                                                    mbMessageModelImpl.getOriginalCategoryId()
18594                                            };
18595    
18596                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18597                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18598                                            args);
18599    
18600                                    args = new Object[] {
18601                                                    mbMessageModelImpl.getGroupId(),
18602                                                    mbMessageModelImpl.getCategoryId()
18603                                            };
18604    
18605                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
18606                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
18607                                            args);
18608                            }
18609    
18610                            if ((mbMessageModelImpl.getColumnBitmask() &
18611                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
18612                                    Object[] args = new Object[] {
18613                                                    mbMessageModelImpl.getOriginalGroupId(),
18614                                                    mbMessageModelImpl.getOriginalStatus()
18615                                            };
18616    
18617                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18618                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18619                                            args);
18620    
18621                                    args = new Object[] {
18622                                                    mbMessageModelImpl.getGroupId(),
18623                                                    mbMessageModelImpl.getStatus()
18624                                            };
18625    
18626                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
18627                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
18628                                            args);
18629                            }
18630    
18631                            if ((mbMessageModelImpl.getColumnBitmask() &
18632                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
18633                                    Object[] args = new Object[] {
18634                                                    mbMessageModelImpl.getOriginalCompanyId(),
18635                                                    mbMessageModelImpl.getOriginalStatus()
18636                                            };
18637    
18638                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18639                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18640                                            args);
18641    
18642                                    args = new Object[] {
18643                                                    mbMessageModelImpl.getCompanyId(),
18644                                                    mbMessageModelImpl.getStatus()
18645                                            };
18646    
18647                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
18648                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
18649                                            args);
18650                            }
18651    
18652                            if ((mbMessageModelImpl.getColumnBitmask() &
18653                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
18654                                    Object[] args = new Object[] {
18655                                                    mbMessageModelImpl.getOriginalUserId(),
18656                                                    mbMessageModelImpl.getOriginalClassNameId()
18657                                            };
18658    
18659                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18660                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18661                                            args);
18662    
18663                                    args = new Object[] {
18664                                                    mbMessageModelImpl.getUserId(),
18665                                                    mbMessageModelImpl.getClassNameId()
18666                                            };
18667    
18668                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
18669                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
18670                                            args);
18671                            }
18672    
18673                            if ((mbMessageModelImpl.getColumnBitmask() &
18674                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
18675                                    Object[] args = new Object[] {
18676                                                    mbMessageModelImpl.getOriginalClassNameId(),
18677                                                    mbMessageModelImpl.getOriginalClassPK()
18678                                            };
18679    
18680                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18681                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18682                                            args);
18683    
18684                                    args = new Object[] {
18685                                                    mbMessageModelImpl.getClassNameId(),
18686                                                    mbMessageModelImpl.getClassPK()
18687                                            };
18688    
18689                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
18690                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
18691                                            args);
18692                            }
18693    
18694                            if ((mbMessageModelImpl.getColumnBitmask() &
18695                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
18696                                    Object[] args = new Object[] {
18697                                                    mbMessageModelImpl.getOriginalThreadId(),
18698                                                    mbMessageModelImpl.getOriginalParentMessageId()
18699                                            };
18700    
18701                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18702                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18703                                            args);
18704    
18705                                    args = new Object[] {
18706                                                    mbMessageModelImpl.getThreadId(),
18707                                                    mbMessageModelImpl.getParentMessageId()
18708                                            };
18709    
18710                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
18711                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
18712                                            args);
18713                            }
18714    
18715                            if ((mbMessageModelImpl.getColumnBitmask() &
18716                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
18717                                    Object[] args = new Object[] {
18718                                                    mbMessageModelImpl.getOriginalThreadId(),
18719                                                    mbMessageModelImpl.getOriginalAnswer()
18720                                            };
18721    
18722                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18723                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18724                                            args);
18725    
18726                                    args = new Object[] {
18727                                                    mbMessageModelImpl.getThreadId(),
18728                                                    mbMessageModelImpl.getAnswer()
18729                                            };
18730    
18731                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
18732                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
18733                                            args);
18734                            }
18735    
18736                            if ((mbMessageModelImpl.getColumnBitmask() &
18737                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
18738                                    Object[] args = new Object[] {
18739                                                    mbMessageModelImpl.getOriginalThreadId(),
18740                                                    mbMessageModelImpl.getOriginalStatus()
18741                                            };
18742    
18743                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18744                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18745                                            args);
18746    
18747                                    args = new Object[] {
18748                                                    mbMessageModelImpl.getThreadId(),
18749                                                    mbMessageModelImpl.getStatus()
18750                                            };
18751    
18752                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
18753                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
18754                                            args);
18755                            }
18756    
18757                            if ((mbMessageModelImpl.getColumnBitmask() &
18758                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
18759                                    Object[] args = new Object[] {
18760                                                    mbMessageModelImpl.getOriginalThreadId(),
18761                                                    mbMessageModelImpl.getOriginalStatus()
18762                                            };
18763    
18764                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18765                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18766                                            args);
18767    
18768                                    args = new Object[] {
18769                                                    mbMessageModelImpl.getThreadId(),
18770                                                    mbMessageModelImpl.getStatus()
18771                                            };
18772    
18773                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
18774                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
18775                                            args);
18776                            }
18777    
18778                            if ((mbMessageModelImpl.getColumnBitmask() &
18779                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
18780                                    Object[] args = new Object[] {
18781                                                    mbMessageModelImpl.getOriginalGroupId(),
18782                                                    mbMessageModelImpl.getOriginalUserId(),
18783                                                    mbMessageModelImpl.getOriginalStatus()
18784                                            };
18785    
18786                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18787                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18788                                            args);
18789    
18790                                    args = new Object[] {
18791                                                    mbMessageModelImpl.getGroupId(),
18792                                                    mbMessageModelImpl.getUserId(),
18793                                                    mbMessageModelImpl.getStatus()
18794                                            };
18795    
18796                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
18797                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
18798                                            args);
18799                            }
18800    
18801                            if ((mbMessageModelImpl.getColumnBitmask() &
18802                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
18803                                    Object[] args = new Object[] {
18804                                                    mbMessageModelImpl.getOriginalGroupId(),
18805                                                    mbMessageModelImpl.getOriginalCategoryId(),
18806                                                    mbMessageModelImpl.getOriginalThreadId()
18807                                            };
18808    
18809                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18810                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18811                                            args);
18812    
18813                                    args = new Object[] {
18814                                                    mbMessageModelImpl.getGroupId(),
18815                                                    mbMessageModelImpl.getCategoryId(),
18816                                                    mbMessageModelImpl.getThreadId()
18817                                            };
18818    
18819                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
18820                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
18821                                            args);
18822                            }
18823    
18824                            if ((mbMessageModelImpl.getColumnBitmask() &
18825                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
18826                                    Object[] args = new Object[] {
18827                                                    mbMessageModelImpl.getOriginalGroupId(),
18828                                                    mbMessageModelImpl.getOriginalCategoryId(),
18829                                                    mbMessageModelImpl.getOriginalStatus()
18830                                            };
18831    
18832                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18833                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18834                                            args);
18835    
18836                                    args = new Object[] {
18837                                                    mbMessageModelImpl.getGroupId(),
18838                                                    mbMessageModelImpl.getCategoryId(),
18839                                                    mbMessageModelImpl.getStatus()
18840                                            };
18841    
18842                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
18843                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
18844                                            args);
18845                            }
18846    
18847                            if ((mbMessageModelImpl.getColumnBitmask() &
18848                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
18849                                    Object[] args = new Object[] {
18850                                                    mbMessageModelImpl.getOriginalUserId(),
18851                                                    mbMessageModelImpl.getOriginalClassNameId(),
18852                                                    mbMessageModelImpl.getOriginalClassPK()
18853                                            };
18854    
18855                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18856                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18857                                            args);
18858    
18859                                    args = new Object[] {
18860                                                    mbMessageModelImpl.getUserId(),
18861                                                    mbMessageModelImpl.getClassNameId(),
18862                                                    mbMessageModelImpl.getClassPK()
18863                                            };
18864    
18865                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
18866                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
18867                                            args);
18868                            }
18869    
18870                            if ((mbMessageModelImpl.getColumnBitmask() &
18871                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
18872                                    Object[] args = new Object[] {
18873                                                    mbMessageModelImpl.getOriginalUserId(),
18874                                                    mbMessageModelImpl.getOriginalClassNameId(),
18875                                                    mbMessageModelImpl.getOriginalStatus()
18876                                            };
18877    
18878                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18879                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18880                                            args);
18881    
18882                                    args = new Object[] {
18883                                                    mbMessageModelImpl.getUserId(),
18884                                                    mbMessageModelImpl.getClassNameId(),
18885                                                    mbMessageModelImpl.getStatus()
18886                                            };
18887    
18888                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
18889                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
18890                                            args);
18891                            }
18892    
18893                            if ((mbMessageModelImpl.getColumnBitmask() &
18894                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
18895                                    Object[] args = new Object[] {
18896                                                    mbMessageModelImpl.getOriginalClassNameId(),
18897                                                    mbMessageModelImpl.getOriginalClassPK(),
18898                                                    mbMessageModelImpl.getOriginalStatus()
18899                                            };
18900    
18901                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18902                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18903                                            args);
18904    
18905                                    args = new Object[] {
18906                                                    mbMessageModelImpl.getClassNameId(),
18907                                                    mbMessageModelImpl.getClassPK(),
18908                                                    mbMessageModelImpl.getStatus()
18909                                            };
18910    
18911                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
18912                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
18913                                            args);
18914                            }
18915    
18916                            if ((mbMessageModelImpl.getColumnBitmask() &
18917                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
18918                                    Object[] args = new Object[] {
18919                                                    mbMessageModelImpl.getOriginalGroupId(),
18920                                                    mbMessageModelImpl.getOriginalCategoryId(),
18921                                                    mbMessageModelImpl.getOriginalThreadId(),
18922                                                    mbMessageModelImpl.getOriginalAnswer()
18923                                            };
18924    
18925                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18926                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18927                                            args);
18928    
18929                                    args = new Object[] {
18930                                                    mbMessageModelImpl.getGroupId(),
18931                                                    mbMessageModelImpl.getCategoryId(),
18932                                                    mbMessageModelImpl.getThreadId(),
18933                                                    mbMessageModelImpl.getAnswer()
18934                                            };
18935    
18936                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
18937                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
18938                                            args);
18939                            }
18940    
18941                            if ((mbMessageModelImpl.getColumnBitmask() &
18942                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
18943                                    Object[] args = new Object[] {
18944                                                    mbMessageModelImpl.getOriginalGroupId(),
18945                                                    mbMessageModelImpl.getOriginalCategoryId(),
18946                                                    mbMessageModelImpl.getOriginalThreadId(),
18947                                                    mbMessageModelImpl.getOriginalStatus()
18948                                            };
18949    
18950                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18951                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18952                                            args);
18953    
18954                                    args = new Object[] {
18955                                                    mbMessageModelImpl.getGroupId(),
18956                                                    mbMessageModelImpl.getCategoryId(),
18957                                                    mbMessageModelImpl.getThreadId(),
18958                                                    mbMessageModelImpl.getStatus()
18959                                            };
18960    
18961                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
18962                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
18963                                            args);
18964                            }
18965    
18966                            if ((mbMessageModelImpl.getColumnBitmask() &
18967                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
18968                                    Object[] args = new Object[] {
18969                                                    mbMessageModelImpl.getOriginalUserId(),
18970                                                    mbMessageModelImpl.getOriginalClassNameId(),
18971                                                    mbMessageModelImpl.getOriginalClassPK(),
18972                                                    mbMessageModelImpl.getOriginalStatus()
18973                                            };
18974    
18975                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18976                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18977                                            args);
18978    
18979                                    args = new Object[] {
18980                                                    mbMessageModelImpl.getUserId(),
18981                                                    mbMessageModelImpl.getClassNameId(),
18982                                                    mbMessageModelImpl.getClassPK(),
18983                                                    mbMessageModelImpl.getStatus()
18984                                            };
18985    
18986                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
18987                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
18988                                            args);
18989                            }
18990                    }
18991    
18992                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18993                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
18994    
18995                    clearUniqueFindersCache(mbMessage);
18996                    cacheUniqueFindersCache(mbMessage);
18997    
18998                    return mbMessage;
18999            }
19000    
19001            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
19002                    if (mbMessage instanceof MBMessageImpl) {
19003                            return mbMessage;
19004                    }
19005    
19006                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
19007    
19008                    mbMessageImpl.setNew(mbMessage.isNew());
19009                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
19010    
19011                    mbMessageImpl.setUuid(mbMessage.getUuid());
19012                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
19013                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
19014                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
19015                    mbMessageImpl.setUserId(mbMessage.getUserId());
19016                    mbMessageImpl.setUserName(mbMessage.getUserName());
19017                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
19018                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
19019                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
19020                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
19021                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
19022                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
19023                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
19024                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
19025                    mbMessageImpl.setSubject(mbMessage.getSubject());
19026                    mbMessageImpl.setBody(mbMessage.getBody());
19027                    mbMessageImpl.setFormat(mbMessage.getFormat());
19028                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
19029                    mbMessageImpl.setPriority(mbMessage.getPriority());
19030                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
19031                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
19032                    mbMessageImpl.setStatus(mbMessage.getStatus());
19033                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
19034                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
19035                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
19036    
19037                    return mbMessageImpl;
19038            }
19039    
19040            /**
19041             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
19042             *
19043             * @param primaryKey the primary key of the message-boards message
19044             * @return the message-boards message
19045             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19046             * @throws SystemException if a system exception occurred
19047             */
19048            @Override
19049            public MBMessage findByPrimaryKey(Serializable primaryKey)
19050                    throws NoSuchMessageException, SystemException {
19051                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
19052    
19053                    if (mbMessage == null) {
19054                            if (_log.isWarnEnabled()) {
19055                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19056                            }
19057    
19058                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19059                                    primaryKey);
19060                    }
19061    
19062                    return mbMessage;
19063            }
19064    
19065            /**
19066             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
19067             *
19068             * @param messageId the primary key of the message-boards message
19069             * @return the message-boards message
19070             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19071             * @throws SystemException if a system exception occurred
19072             */
19073            public MBMessage findByPrimaryKey(long messageId)
19074                    throws NoSuchMessageException, SystemException {
19075                    return findByPrimaryKey((Serializable)messageId);
19076            }
19077    
19078            /**
19079             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19080             *
19081             * @param primaryKey the primary key of the message-boards message
19082             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19083             * @throws SystemException if a system exception occurred
19084             */
19085            @Override
19086            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
19087                    throws SystemException {
19088                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19089                                    MBMessageImpl.class, primaryKey);
19090    
19091                    if (mbMessage == _nullMBMessage) {
19092                            return null;
19093                    }
19094    
19095                    if (mbMessage == null) {
19096                            Session session = null;
19097    
19098                            try {
19099                                    session = openSession();
19100    
19101                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19102                                                    primaryKey);
19103    
19104                                    if (mbMessage != null) {
19105                                            cacheResult(mbMessage);
19106                                    }
19107                                    else {
19108                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19109                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
19110                                    }
19111                            }
19112                            catch (Exception e) {
19113                                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19114                                            MBMessageImpl.class, primaryKey);
19115    
19116                                    throw processException(e);
19117                            }
19118                            finally {
19119                                    closeSession(session);
19120                            }
19121                    }
19122    
19123                    return mbMessage;
19124            }
19125    
19126            /**
19127             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
19128             *
19129             * @param messageId the primary key of the message-boards message
19130             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
19131             * @throws SystemException if a system exception occurred
19132             */
19133            public MBMessage fetchByPrimaryKey(long messageId)
19134                    throws SystemException {
19135                    return fetchByPrimaryKey((Serializable)messageId);
19136            }
19137    
19138            /**
19139             * Returns all the message-boards messages.
19140             *
19141             * @return the message-boards messages
19142             * @throws SystemException if a system exception occurred
19143             */
19144            public List<MBMessage> findAll() throws SystemException {
19145                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19146            }
19147    
19148            /**
19149             * Returns a range of all the message-boards messages.
19150             *
19151             * <p>
19152             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19153             * </p>
19154             *
19155             * @param start the lower bound of the range of message-boards messages
19156             * @param end the upper bound of the range of message-boards messages (not inclusive)
19157             * @return the range of message-boards messages
19158             * @throws SystemException if a system exception occurred
19159             */
19160            public List<MBMessage> findAll(int start, int end)
19161                    throws SystemException {
19162                    return findAll(start, end, null);
19163            }
19164    
19165            /**
19166             * Returns an ordered range of all the message-boards messages.
19167             *
19168             * <p>
19169             * 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. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
19170             * </p>
19171             *
19172             * @param start the lower bound of the range of message-boards messages
19173             * @param end the upper bound of the range of message-boards messages (not inclusive)
19174             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19175             * @return the ordered range of message-boards messages
19176             * @throws SystemException if a system exception occurred
19177             */
19178            public List<MBMessage> findAll(int start, int end,
19179                    OrderByComparator orderByComparator) throws SystemException {
19180                    boolean pagination = true;
19181                    FinderPath finderPath = null;
19182                    Object[] finderArgs = null;
19183    
19184                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19185                                    (orderByComparator == null)) {
19186                            pagination = false;
19187                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
19188                            finderArgs = FINDER_ARGS_EMPTY;
19189                    }
19190                    else {
19191                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
19192                            finderArgs = new Object[] { start, end, orderByComparator };
19193                    }
19194    
19195                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
19196                                    finderArgs, this);
19197    
19198                    if (list == null) {
19199                            StringBundler query = null;
19200                            String sql = null;
19201    
19202                            if (orderByComparator != null) {
19203                                    query = new StringBundler(2 +
19204                                                    (orderByComparator.getOrderByFields().length * 3));
19205    
19206                                    query.append(_SQL_SELECT_MBMESSAGE);
19207    
19208                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19209                                            orderByComparator);
19210    
19211                                    sql = query.toString();
19212                            }
19213                            else {
19214                                    sql = _SQL_SELECT_MBMESSAGE;
19215    
19216                                    if (pagination) {
19217                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
19218                                    }
19219                            }
19220    
19221                            Session session = null;
19222    
19223                            try {
19224                                    session = openSession();
19225    
19226                                    Query q = session.createQuery(sql);
19227    
19228                                    if (!pagination) {
19229                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19230                                                            start, end, false);
19231    
19232                                            Collections.sort(list);
19233    
19234                                            list = new UnmodifiableList<MBMessage>(list);
19235                                    }
19236                                    else {
19237                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19238                                                            start, end);
19239                                    }
19240    
19241                                    cacheResult(list);
19242    
19243                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19244                            }
19245                            catch (Exception e) {
19246                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19247    
19248                                    throw processException(e);
19249                            }
19250                            finally {
19251                                    closeSession(session);
19252                            }
19253                    }
19254    
19255                    return list;
19256            }
19257    
19258            /**
19259             * Removes all the message-boards messages from the database.
19260             *
19261             * @throws SystemException if a system exception occurred
19262             */
19263            public void removeAll() throws SystemException {
19264                    for (MBMessage mbMessage : findAll()) {
19265                            remove(mbMessage);
19266                    }
19267            }
19268    
19269            /**
19270             * Returns the number of message-boards messages.
19271             *
19272             * @return the number of message-boards messages
19273             * @throws SystemException if a system exception occurred
19274             */
19275            public int countAll() throws SystemException {
19276                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
19277                                    FINDER_ARGS_EMPTY, this);
19278    
19279                    if (count == null) {
19280                            Session session = null;
19281    
19282                            try {
19283                                    session = openSession();
19284    
19285                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
19286    
19287                                    count = (Long)q.uniqueResult();
19288    
19289                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
19290                                            FINDER_ARGS_EMPTY, count);
19291                            }
19292                            catch (Exception e) {
19293                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
19294                                            FINDER_ARGS_EMPTY);
19295    
19296                                    throw processException(e);
19297                            }
19298                            finally {
19299                                    closeSession(session);
19300                            }
19301                    }
19302    
19303                    return count.intValue();
19304            }
19305    
19306            /**
19307             * Initializes the message-boards message persistence.
19308             */
19309            public void afterPropertiesSet() {
19310                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
19311                                            com.liferay.portal.util.PropsUtil.get(
19312                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
19313    
19314                    if (listenerClassNames.length > 0) {
19315                            try {
19316                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
19317    
19318                                    for (String listenerClassName : listenerClassNames) {
19319                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
19320                                                            listenerClassName));
19321                                    }
19322    
19323                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
19324                            }
19325                            catch (Exception e) {
19326                                    _log.error(e);
19327                            }
19328                    }
19329            }
19330    
19331            public void destroy() {
19332                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
19333                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
19334                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19335                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19336            }
19337    
19338            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
19339            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
19340            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
19341            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
19342            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
19343            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
19344            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
19345                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
19346            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
19347                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
19348            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
19349            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
19350            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
19351            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
19352            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
19353            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
19354            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
19355            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
19356            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
19357            private static MBMessage _nullMBMessage = new MBMessageImpl() {
19358                            @Override
19359                            public Object clone() {
19360                                    return this;
19361                            }
19362    
19363                            @Override
19364                            public CacheModel<MBMessage> toCacheModel() {
19365                                    return _nullMBMessageCacheModel;
19366                            }
19367                    };
19368    
19369            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
19370                            public MBMessage toEntityModel() {
19371                                    return _nullMBMessage;
19372                            }
19373                    };
19374    }