001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.messageboards.service.persistence;
016    
017    import com.liferay.portal.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.SetUtil;
038    import com.liferay.portal.kernel.util.StringBundler;
039    import com.liferay.portal.kernel.util.StringPool;
040    import com.liferay.portal.kernel.util.StringUtil;
041    import com.liferay.portal.kernel.util.UnmodifiableList;
042    import com.liferay.portal.kernel.util.Validator;
043    import com.liferay.portal.kernel.uuid.PortalUUIDUtil;
044    import com.liferay.portal.model.CacheModel;
045    import com.liferay.portal.model.ModelListener;
046    import com.liferay.portal.security.auth.PrincipalThreadLocal;
047    import com.liferay.portal.security.permission.InlineSQLHelperUtil;
048    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
049    
050    import com.liferay.portlet.messageboards.NoSuchMessageException;
051    import com.liferay.portlet.messageboards.model.MBMessage;
052    import com.liferay.portlet.messageboards.model.impl.MBMessageImpl;
053    import com.liferay.portlet.messageboards.model.impl.MBMessageModelImpl;
054    
055    import java.io.Serializable;
056    
057    import java.util.ArrayList;
058    import java.util.Collections;
059    import java.util.List;
060    import java.util.Set;
061    
062    /**
063     * The persistence implementation for the message-boards message service.
064     *
065     * <p>
066     * Caching information and settings can be found in <code>portal.properties</code>
067     * </p>
068     *
069     * @author Brian Wing Shun Chan
070     * @see MBMessagePersistence
071     * @see MBMessageUtil
072     * @generated
073     */
074    public class MBMessagePersistenceImpl extends BasePersistenceImpl<MBMessage>
075            implements MBMessagePersistence {
076            /*
077             * NOTE FOR DEVELOPERS:
078             *
079             * 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.
080             */
081            public static final String FINDER_CLASS_NAME_ENTITY = MBMessageImpl.class.getName();
082            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
083                    ".List1";
084            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085                    ".List2";
086            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
087                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
089            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
090                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
091                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
092            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
093                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
095            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
096                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
097                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid",
098                            new String[] {
099                                    String.class.getName(),
100                                    
101                            Integer.class.getName(), Integer.class.getName(),
102                                    OrderByComparator.class.getName()
103                            });
104            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
105                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
106                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid",
107                            new String[] { String.class.getName() },
108                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
109                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
110            public static final FinderPath FINDER_PATH_COUNT_BY_UUID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
111                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
112                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid",
113                            new String[] { String.class.getName() });
114    
115            /**
116             * Returns all the message-boards messages where uuid = &#63;.
117             *
118             * @param uuid the uuid
119             * @return the matching message-boards messages
120             * @throws SystemException if a system exception occurred
121             */
122            public List<MBMessage> findByUuid(String uuid) throws SystemException {
123                    return findByUuid(uuid, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
124            }
125    
126            /**
127             * Returns a range of all the message-boards messages where uuid = &#63;.
128             *
129             * <p>
130             * 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.
131             * </p>
132             *
133             * @param uuid the uuid
134             * @param start the lower bound of the range of message-boards messages
135             * @param end the upper bound of the range of message-boards messages (not inclusive)
136             * @return the range of matching message-boards messages
137             * @throws SystemException if a system exception occurred
138             */
139            public List<MBMessage> findByUuid(String uuid, int start, int end)
140                    throws SystemException {
141                    return findByUuid(uuid, start, end, null);
142            }
143    
144            /**
145             * Returns an ordered range of all the message-boards messages where uuid = &#63;.
146             *
147             * <p>
148             * 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.
149             * </p>
150             *
151             * @param uuid the uuid
152             * @param start the lower bound of the range of message-boards messages
153             * @param end the upper bound of the range of message-boards messages (not inclusive)
154             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
155             * @return the ordered range of matching message-boards messages
156             * @throws SystemException if a system exception occurred
157             */
158            public List<MBMessage> findByUuid(String uuid, int start, int end,
159                    OrderByComparator orderByComparator) throws SystemException {
160                    boolean pagination = true;
161                    FinderPath finderPath = null;
162                    Object[] finderArgs = null;
163    
164                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
165                                    (orderByComparator == null)) {
166                            pagination = false;
167                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID;
168                            finderArgs = new Object[] { uuid };
169                    }
170                    else {
171                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID;
172                            finderArgs = new Object[] { uuid, start, end, orderByComparator };
173                    }
174    
175                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
176                                    finderArgs, this);
177    
178                    if ((list != null) && !list.isEmpty()) {
179                            for (MBMessage mbMessage : list) {
180                                    if (!Validator.equals(uuid, mbMessage.getUuid())) {
181                                            list = null;
182    
183                                            break;
184                                    }
185                            }
186                    }
187    
188                    if (list == null) {
189                            StringBundler query = null;
190    
191                            if (orderByComparator != null) {
192                                    query = new StringBundler(3 +
193                                                    (orderByComparator.getOrderByFields().length * 3));
194                            }
195                            else {
196                                    query = new StringBundler(3);
197                            }
198    
199                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
200    
201                            boolean bindUuid = false;
202    
203                            if (uuid == null) {
204                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
205                            }
206                            else if (uuid.equals(StringPool.BLANK)) {
207                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
208                            }
209                            else {
210                                    bindUuid = true;
211    
212                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
213                            }
214    
215                            if (orderByComparator != null) {
216                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
217                                            orderByComparator);
218                            }
219                            else
220                             if (pagination) {
221                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
222                            }
223    
224                            String sql = query.toString();
225    
226                            Session session = null;
227    
228                            try {
229                                    session = openSession();
230    
231                                    Query q = session.createQuery(sql);
232    
233                                    QueryPos qPos = QueryPos.getInstance(q);
234    
235                                    if (bindUuid) {
236                                            qPos.add(uuid);
237                                    }
238    
239                                    if (!pagination) {
240                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
241                                                            start, end, false);
242    
243                                            Collections.sort(list);
244    
245                                            list = new UnmodifiableList<MBMessage>(list);
246                                    }
247                                    else {
248                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
249                                                            start, end);
250                                    }
251    
252                                    cacheResult(list);
253    
254                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
255                            }
256                            catch (Exception e) {
257                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
258    
259                                    throw processException(e);
260                            }
261                            finally {
262                                    closeSession(session);
263                            }
264                    }
265    
266                    return list;
267            }
268    
269            /**
270             * Returns the first message-boards message in the ordered set where uuid = &#63;.
271             *
272             * @param uuid the uuid
273             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
274             * @return the first matching message-boards message
275             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
276             * @throws SystemException if a system exception occurred
277             */
278            public MBMessage findByUuid_First(String uuid,
279                    OrderByComparator orderByComparator)
280                    throws NoSuchMessageException, SystemException {
281                    MBMessage mbMessage = fetchByUuid_First(uuid, orderByComparator);
282    
283                    if (mbMessage != null) {
284                            return mbMessage;
285                    }
286    
287                    StringBundler msg = new StringBundler(4);
288    
289                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
290    
291                    msg.append("uuid=");
292                    msg.append(uuid);
293    
294                    msg.append(StringPool.CLOSE_CURLY_BRACE);
295    
296                    throw new NoSuchMessageException(msg.toString());
297            }
298    
299            /**
300             * Returns the first message-boards message in the ordered set where uuid = &#63;.
301             *
302             * @param uuid the uuid
303             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
304             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
305             * @throws SystemException if a system exception occurred
306             */
307            public MBMessage fetchByUuid_First(String uuid,
308                    OrderByComparator orderByComparator) throws SystemException {
309                    List<MBMessage> list = findByUuid(uuid, 0, 1, orderByComparator);
310    
311                    if (!list.isEmpty()) {
312                            return list.get(0);
313                    }
314    
315                    return null;
316            }
317    
318            /**
319             * Returns the last message-boards message in the ordered set where uuid = &#63;.
320             *
321             * @param uuid the uuid
322             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
323             * @return the last matching message-boards message
324             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
325             * @throws SystemException if a system exception occurred
326             */
327            public MBMessage findByUuid_Last(String uuid,
328                    OrderByComparator orderByComparator)
329                    throws NoSuchMessageException, SystemException {
330                    MBMessage mbMessage = fetchByUuid_Last(uuid, orderByComparator);
331    
332                    if (mbMessage != null) {
333                            return mbMessage;
334                    }
335    
336                    StringBundler msg = new StringBundler(4);
337    
338                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
339    
340                    msg.append("uuid=");
341                    msg.append(uuid);
342    
343                    msg.append(StringPool.CLOSE_CURLY_BRACE);
344    
345                    throw new NoSuchMessageException(msg.toString());
346            }
347    
348            /**
349             * Returns the last message-boards message in the ordered set where uuid = &#63;.
350             *
351             * @param uuid the uuid
352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
353             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
354             * @throws SystemException if a system exception occurred
355             */
356            public MBMessage fetchByUuid_Last(String uuid,
357                    OrderByComparator orderByComparator) throws SystemException {
358                    int count = countByUuid(uuid);
359    
360                    List<MBMessage> list = findByUuid(uuid, count - 1, count,
361                                    orderByComparator);
362    
363                    if (!list.isEmpty()) {
364                            return list.get(0);
365                    }
366    
367                    return null;
368            }
369    
370            /**
371             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63;.
372             *
373             * @param messageId the primary key of the current message-boards message
374             * @param uuid the uuid
375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
376             * @return the previous, current, and next message-boards message
377             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
378             * @throws SystemException if a system exception occurred
379             */
380            public MBMessage[] findByUuid_PrevAndNext(long messageId, String uuid,
381                    OrderByComparator orderByComparator)
382                    throws NoSuchMessageException, SystemException {
383                    MBMessage mbMessage = findByPrimaryKey(messageId);
384    
385                    Session session = null;
386    
387                    try {
388                            session = openSession();
389    
390                            MBMessage[] array = new MBMessageImpl[3];
391    
392                            array[0] = getByUuid_PrevAndNext(session, mbMessage, uuid,
393                                            orderByComparator, true);
394    
395                            array[1] = mbMessage;
396    
397                            array[2] = getByUuid_PrevAndNext(session, mbMessage, uuid,
398                                            orderByComparator, false);
399    
400                            return array;
401                    }
402                    catch (Exception e) {
403                            throw processException(e);
404                    }
405                    finally {
406                            closeSession(session);
407                    }
408            }
409    
410            protected MBMessage getByUuid_PrevAndNext(Session session,
411                    MBMessage mbMessage, String uuid, OrderByComparator orderByComparator,
412                    boolean previous) {
413                    StringBundler query = null;
414    
415                    if (orderByComparator != null) {
416                            query = new StringBundler(6 +
417                                            (orderByComparator.getOrderByFields().length * 6));
418                    }
419                    else {
420                            query = new StringBundler(3);
421                    }
422    
423                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
424    
425                    boolean bindUuid = false;
426    
427                    if (uuid == null) {
428                            query.append(_FINDER_COLUMN_UUID_UUID_1);
429                    }
430                    else if (uuid.equals(StringPool.BLANK)) {
431                            query.append(_FINDER_COLUMN_UUID_UUID_3);
432                    }
433                    else {
434                            bindUuid = true;
435    
436                            query.append(_FINDER_COLUMN_UUID_UUID_2);
437                    }
438    
439                    if (orderByComparator != null) {
440                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
441    
442                            if (orderByConditionFields.length > 0) {
443                                    query.append(WHERE_AND);
444                            }
445    
446                            for (int i = 0; i < orderByConditionFields.length; i++) {
447                                    query.append(_ORDER_BY_ENTITY_ALIAS);
448                                    query.append(orderByConditionFields[i]);
449    
450                                    if ((i + 1) < orderByConditionFields.length) {
451                                            if (orderByComparator.isAscending() ^ previous) {
452                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
453                                            }
454                                            else {
455                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
456                                            }
457                                    }
458                                    else {
459                                            if (orderByComparator.isAscending() ^ previous) {
460                                                    query.append(WHERE_GREATER_THAN);
461                                            }
462                                            else {
463                                                    query.append(WHERE_LESSER_THAN);
464                                            }
465                                    }
466                            }
467    
468                            query.append(ORDER_BY_CLAUSE);
469    
470                            String[] orderByFields = orderByComparator.getOrderByFields();
471    
472                            for (int i = 0; i < orderByFields.length; i++) {
473                                    query.append(_ORDER_BY_ENTITY_ALIAS);
474                                    query.append(orderByFields[i]);
475    
476                                    if ((i + 1) < orderByFields.length) {
477                                            if (orderByComparator.isAscending() ^ previous) {
478                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
479                                            }
480                                            else {
481                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
482                                            }
483                                    }
484                                    else {
485                                            if (orderByComparator.isAscending() ^ previous) {
486                                                    query.append(ORDER_BY_ASC);
487                                            }
488                                            else {
489                                                    query.append(ORDER_BY_DESC);
490                                            }
491                                    }
492                            }
493                    }
494                    else {
495                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
496                    }
497    
498                    String sql = query.toString();
499    
500                    Query q = session.createQuery(sql);
501    
502                    q.setFirstResult(0);
503                    q.setMaxResults(2);
504    
505                    QueryPos qPos = QueryPos.getInstance(q);
506    
507                    if (bindUuid) {
508                            qPos.add(uuid);
509                    }
510    
511                    if (orderByComparator != null) {
512                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
513    
514                            for (Object value : values) {
515                                    qPos.add(value);
516                            }
517                    }
518    
519                    List<MBMessage> list = q.list();
520    
521                    if (list.size() == 2) {
522                            return list.get(1);
523                    }
524                    else {
525                            return null;
526                    }
527            }
528    
529            /**
530             * Removes all the message-boards messages where uuid = &#63; from the database.
531             *
532             * @param uuid the uuid
533             * @throws SystemException if a system exception occurred
534             */
535            public void removeByUuid(String uuid) throws SystemException {
536                    for (MBMessage mbMessage : findByUuid(uuid, QueryUtil.ALL_POS,
537                                    QueryUtil.ALL_POS, null)) {
538                            remove(mbMessage);
539                    }
540            }
541    
542            /**
543             * Returns the number of message-boards messages where uuid = &#63;.
544             *
545             * @param uuid the uuid
546             * @return the number of matching message-boards messages
547             * @throws SystemException if a system exception occurred
548             */
549            public int countByUuid(String uuid) throws SystemException {
550                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID;
551    
552                    Object[] finderArgs = new Object[] { uuid };
553    
554                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
555                                    this);
556    
557                    if (count == null) {
558                            StringBundler query = new StringBundler(2);
559    
560                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
561    
562                            boolean bindUuid = false;
563    
564                            if (uuid == null) {
565                                    query.append(_FINDER_COLUMN_UUID_UUID_1);
566                            }
567                            else if (uuid.equals(StringPool.BLANK)) {
568                                    query.append(_FINDER_COLUMN_UUID_UUID_3);
569                            }
570                            else {
571                                    bindUuid = true;
572    
573                                    query.append(_FINDER_COLUMN_UUID_UUID_2);
574                            }
575    
576                            String sql = query.toString();
577    
578                            Session session = null;
579    
580                            try {
581                                    session = openSession();
582    
583                                    Query q = session.createQuery(sql);
584    
585                                    QueryPos qPos = QueryPos.getInstance(q);
586    
587                                    if (bindUuid) {
588                                            qPos.add(uuid);
589                                    }
590    
591                                    count = (Long)q.uniqueResult();
592    
593                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
594                            }
595                            catch (Exception e) {
596                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
597    
598                                    throw processException(e);
599                            }
600                            finally {
601                                    closeSession(session);
602                            }
603                    }
604    
605                    return count.intValue();
606            }
607    
608            private static final String _FINDER_COLUMN_UUID_UUID_1 = "mbMessage.uuid IS NULL";
609            private static final String _FINDER_COLUMN_UUID_UUID_2 = "mbMessage.uuid = ?";
610            private static final String _FINDER_COLUMN_UUID_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '')";
611            public static final FinderPath FINDER_PATH_FETCH_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
612                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
613                            FINDER_CLASS_NAME_ENTITY, "fetchByUUID_G",
614                            new String[] { String.class.getName(), Long.class.getName() },
615                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
616                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK);
617            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_G = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
618                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
619                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUUID_G",
620                            new String[] { String.class.getName(), Long.class.getName() });
621    
622            /**
623             * 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.
624             *
625             * @param uuid the uuid
626             * @param groupId the group ID
627             * @return the matching message-boards message
628             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
629             * @throws SystemException if a system exception occurred
630             */
631            public MBMessage findByUUID_G(String uuid, long groupId)
632                    throws NoSuchMessageException, SystemException {
633                    MBMessage mbMessage = fetchByUUID_G(uuid, groupId);
634    
635                    if (mbMessage == null) {
636                            StringBundler msg = new StringBundler(6);
637    
638                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
639    
640                            msg.append("uuid=");
641                            msg.append(uuid);
642    
643                            msg.append(", groupId=");
644                            msg.append(groupId);
645    
646                            msg.append(StringPool.CLOSE_CURLY_BRACE);
647    
648                            if (_log.isWarnEnabled()) {
649                                    _log.warn(msg.toString());
650                            }
651    
652                            throw new NoSuchMessageException(msg.toString());
653                    }
654    
655                    return mbMessage;
656            }
657    
658            /**
659             * 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.
660             *
661             * @param uuid the uuid
662             * @param groupId the group ID
663             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
664             * @throws SystemException if a system exception occurred
665             */
666            public MBMessage fetchByUUID_G(String uuid, long groupId)
667                    throws SystemException {
668                    return fetchByUUID_G(uuid, groupId, true);
669            }
670    
671            /**
672             * 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.
673             *
674             * @param uuid the uuid
675             * @param groupId the group ID
676             * @param retrieveFromCache whether to use the finder cache
677             * @return the matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
678             * @throws SystemException if a system exception occurred
679             */
680            public MBMessage fetchByUUID_G(String uuid, long groupId,
681                    boolean retrieveFromCache) throws SystemException {
682                    Object[] finderArgs = new Object[] { uuid, groupId };
683    
684                    Object result = null;
685    
686                    if (retrieveFromCache) {
687                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G,
688                                            finderArgs, this);
689                    }
690    
691                    if (result instanceof MBMessage) {
692                            MBMessage mbMessage = (MBMessage)result;
693    
694                            if (!Validator.equals(uuid, mbMessage.getUuid()) ||
695                                            (groupId != mbMessage.getGroupId())) {
696                                    result = null;
697                            }
698                    }
699    
700                    if (result == null) {
701                            StringBundler query = new StringBundler(4);
702    
703                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
704    
705                            boolean bindUuid = false;
706    
707                            if (uuid == null) {
708                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
709                            }
710                            else if (uuid.equals(StringPool.BLANK)) {
711                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
712                            }
713                            else {
714                                    bindUuid = true;
715    
716                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
717                            }
718    
719                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
720    
721                            String sql = query.toString();
722    
723                            Session session = null;
724    
725                            try {
726                                    session = openSession();
727    
728                                    Query q = session.createQuery(sql);
729    
730                                    QueryPos qPos = QueryPos.getInstance(q);
731    
732                                    if (bindUuid) {
733                                            qPos.add(uuid);
734                                    }
735    
736                                    qPos.add(groupId);
737    
738                                    List<MBMessage> list = q.list();
739    
740                                    if (list.isEmpty()) {
741                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
742                                                    finderArgs, list);
743                                    }
744                                    else {
745                                            MBMessage mbMessage = list.get(0);
746    
747                                            result = mbMessage;
748    
749                                            cacheResult(mbMessage);
750    
751                                            if ((mbMessage.getUuid() == null) ||
752                                                            !mbMessage.getUuid().equals(uuid) ||
753                                                            (mbMessage.getGroupId() != groupId)) {
754                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
755                                                            finderArgs, mbMessage);
756                                            }
757                                    }
758                            }
759                            catch (Exception e) {
760                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G,
761                                            finderArgs);
762    
763                                    throw processException(e);
764                            }
765                            finally {
766                                    closeSession(session);
767                            }
768                    }
769    
770                    if (result instanceof List<?>) {
771                            return null;
772                    }
773                    else {
774                            return (MBMessage)result;
775                    }
776            }
777    
778            /**
779             * Removes the message-boards message where uuid = &#63; and groupId = &#63; from the database.
780             *
781             * @param uuid the uuid
782             * @param groupId the group ID
783             * @return the message-boards message that was removed
784             * @throws SystemException if a system exception occurred
785             */
786            public MBMessage removeByUUID_G(String uuid, long groupId)
787                    throws NoSuchMessageException, SystemException {
788                    MBMessage mbMessage = findByUUID_G(uuid, groupId);
789    
790                    return remove(mbMessage);
791            }
792    
793            /**
794             * Returns the number of message-boards messages where uuid = &#63; and groupId = &#63;.
795             *
796             * @param uuid the uuid
797             * @param groupId the group ID
798             * @return the number of matching message-boards messages
799             * @throws SystemException if a system exception occurred
800             */
801            public int countByUUID_G(String uuid, long groupId)
802                    throws SystemException {
803                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_G;
804    
805                    Object[] finderArgs = new Object[] { uuid, groupId };
806    
807                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
808                                    this);
809    
810                    if (count == null) {
811                            StringBundler query = new StringBundler(3);
812    
813                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
814    
815                            boolean bindUuid = false;
816    
817                            if (uuid == null) {
818                                    query.append(_FINDER_COLUMN_UUID_G_UUID_1);
819                            }
820                            else if (uuid.equals(StringPool.BLANK)) {
821                                    query.append(_FINDER_COLUMN_UUID_G_UUID_3);
822                            }
823                            else {
824                                    bindUuid = true;
825    
826                                    query.append(_FINDER_COLUMN_UUID_G_UUID_2);
827                            }
828    
829                            query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
830    
831                            String sql = query.toString();
832    
833                            Session session = null;
834    
835                            try {
836                                    session = openSession();
837    
838                                    Query q = session.createQuery(sql);
839    
840                                    QueryPos qPos = QueryPos.getInstance(q);
841    
842                                    if (bindUuid) {
843                                            qPos.add(uuid);
844                                    }
845    
846                                    qPos.add(groupId);
847    
848                                    count = (Long)q.uniqueResult();
849    
850                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
851                            }
852                            catch (Exception e) {
853                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
854    
855                                    throw processException(e);
856                            }
857                            finally {
858                                    closeSession(session);
859                            }
860                    }
861    
862                    return count.intValue();
863            }
864    
865            private static final String _FINDER_COLUMN_UUID_G_UUID_1 = "mbMessage.uuid IS NULL AND ";
866            private static final String _FINDER_COLUMN_UUID_G_UUID_2 = "mbMessage.uuid = ? AND ";
867            private static final String _FINDER_COLUMN_UUID_G_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
868            private static final String _FINDER_COLUMN_UUID_G_GROUPID_2 = "mbMessage.groupId = ?";
869            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
870                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
871                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUuid_C",
872                            new String[] {
873                                    String.class.getName(), Long.class.getName(),
874                                    
875                            Integer.class.getName(), Integer.class.getName(),
876                                    OrderByComparator.class.getName()
877                            });
878            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C =
879                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
880                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
881                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUuid_C",
882                            new String[] { String.class.getName(), Long.class.getName() },
883                            MBMessageModelImpl.UUID_COLUMN_BITMASK |
884                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
885                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
886            public static final FinderPath FINDER_PATH_COUNT_BY_UUID_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
887                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
888                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUuid_C",
889                            new String[] { String.class.getName(), Long.class.getName() });
890    
891            /**
892             * Returns all the message-boards messages where uuid = &#63; and companyId = &#63;.
893             *
894             * @param uuid the uuid
895             * @param companyId the company ID
896             * @return the matching message-boards messages
897             * @throws SystemException if a system exception occurred
898             */
899            public List<MBMessage> findByUuid_C(String uuid, long companyId)
900                    throws SystemException {
901                    return findByUuid_C(uuid, companyId, QueryUtil.ALL_POS,
902                            QueryUtil.ALL_POS, null);
903            }
904    
905            /**
906             * Returns a range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
907             *
908             * <p>
909             * 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.
910             * </p>
911             *
912             * @param uuid the uuid
913             * @param companyId the company ID
914             * @param start the lower bound of the range of message-boards messages
915             * @param end the upper bound of the range of message-boards messages (not inclusive)
916             * @return the range of matching message-boards messages
917             * @throws SystemException if a system exception occurred
918             */
919            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
920                    int end) throws SystemException {
921                    return findByUuid_C(uuid, companyId, start, end, null);
922            }
923    
924            /**
925             * Returns an ordered range of all the message-boards messages where uuid = &#63; and companyId = &#63;.
926             *
927             * <p>
928             * 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.
929             * </p>
930             *
931             * @param uuid the uuid
932             * @param companyId the company ID
933             * @param start the lower bound of the range of message-boards messages
934             * @param end the upper bound of the range of message-boards messages (not inclusive)
935             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
936             * @return the ordered range of matching message-boards messages
937             * @throws SystemException if a system exception occurred
938             */
939            public List<MBMessage> findByUuid_C(String uuid, long companyId, int start,
940                    int end, OrderByComparator orderByComparator) throws SystemException {
941                    boolean pagination = true;
942                    FinderPath finderPath = null;
943                    Object[] finderArgs = null;
944    
945                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
946                                    (orderByComparator == null)) {
947                            pagination = false;
948                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C;
949                            finderArgs = new Object[] { uuid, companyId };
950                    }
951                    else {
952                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_UUID_C;
953                            finderArgs = new Object[] {
954                                            uuid, companyId,
955                                            
956                                            start, end, orderByComparator
957                                    };
958                    }
959    
960                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
961                                    finderArgs, this);
962    
963                    if ((list != null) && !list.isEmpty()) {
964                            for (MBMessage mbMessage : list) {
965                                    if (!Validator.equals(uuid, mbMessage.getUuid()) ||
966                                                    (companyId != mbMessage.getCompanyId())) {
967                                            list = null;
968    
969                                            break;
970                                    }
971                            }
972                    }
973    
974                    if (list == null) {
975                            StringBundler query = null;
976    
977                            if (orderByComparator != null) {
978                                    query = new StringBundler(4 +
979                                                    (orderByComparator.getOrderByFields().length * 3));
980                            }
981                            else {
982                                    query = new StringBundler(4);
983                            }
984    
985                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
986    
987                            boolean bindUuid = false;
988    
989                            if (uuid == null) {
990                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
991                            }
992                            else if (uuid.equals(StringPool.BLANK)) {
993                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
994                            }
995                            else {
996                                    bindUuid = true;
997    
998                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
999                            }
1000    
1001                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1002    
1003                            if (orderByComparator != null) {
1004                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1005                                            orderByComparator);
1006                            }
1007                            else
1008                             if (pagination) {
1009                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1010                            }
1011    
1012                            String sql = query.toString();
1013    
1014                            Session session = null;
1015    
1016                            try {
1017                                    session = openSession();
1018    
1019                                    Query q = session.createQuery(sql);
1020    
1021                                    QueryPos qPos = QueryPos.getInstance(q);
1022    
1023                                    if (bindUuid) {
1024                                            qPos.add(uuid);
1025                                    }
1026    
1027                                    qPos.add(companyId);
1028    
1029                                    if (!pagination) {
1030                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1031                                                            start, end, false);
1032    
1033                                            Collections.sort(list);
1034    
1035                                            list = new UnmodifiableList<MBMessage>(list);
1036                                    }
1037                                    else {
1038                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1039                                                            start, end);
1040                                    }
1041    
1042                                    cacheResult(list);
1043    
1044                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1045                            }
1046                            catch (Exception e) {
1047                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1048    
1049                                    throw processException(e);
1050                            }
1051                            finally {
1052                                    closeSession(session);
1053                            }
1054                    }
1055    
1056                    return list;
1057            }
1058    
1059            /**
1060             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1061             *
1062             * @param uuid the uuid
1063             * @param companyId the company ID
1064             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1065             * @return the first matching message-boards message
1066             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1067             * @throws SystemException if a system exception occurred
1068             */
1069            public MBMessage findByUuid_C_First(String uuid, long companyId,
1070                    OrderByComparator orderByComparator)
1071                    throws NoSuchMessageException, SystemException {
1072                    MBMessage mbMessage = fetchByUuid_C_First(uuid, companyId,
1073                                    orderByComparator);
1074    
1075                    if (mbMessage != null) {
1076                            return mbMessage;
1077                    }
1078    
1079                    StringBundler msg = new StringBundler(6);
1080    
1081                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1082    
1083                    msg.append("uuid=");
1084                    msg.append(uuid);
1085    
1086                    msg.append(", companyId=");
1087                    msg.append(companyId);
1088    
1089                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1090    
1091                    throw new NoSuchMessageException(msg.toString());
1092            }
1093    
1094            /**
1095             * Returns the first message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1096             *
1097             * @param uuid the uuid
1098             * @param companyId the company ID
1099             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1100             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1101             * @throws SystemException if a system exception occurred
1102             */
1103            public MBMessage fetchByUuid_C_First(String uuid, long companyId,
1104                    OrderByComparator orderByComparator) throws SystemException {
1105                    List<MBMessage> list = findByUuid_C(uuid, companyId, 0, 1,
1106                                    orderByComparator);
1107    
1108                    if (!list.isEmpty()) {
1109                            return list.get(0);
1110                    }
1111    
1112                    return null;
1113            }
1114    
1115            /**
1116             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1117             *
1118             * @param uuid the uuid
1119             * @param companyId the company ID
1120             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1121             * @return the last matching message-boards message
1122             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1123             * @throws SystemException if a system exception occurred
1124             */
1125            public MBMessage findByUuid_C_Last(String uuid, long companyId,
1126                    OrderByComparator orderByComparator)
1127                    throws NoSuchMessageException, SystemException {
1128                    MBMessage mbMessage = fetchByUuid_C_Last(uuid, companyId,
1129                                    orderByComparator);
1130    
1131                    if (mbMessage != null) {
1132                            return mbMessage;
1133                    }
1134    
1135                    StringBundler msg = new StringBundler(6);
1136    
1137                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1138    
1139                    msg.append("uuid=");
1140                    msg.append(uuid);
1141    
1142                    msg.append(", companyId=");
1143                    msg.append(companyId);
1144    
1145                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1146    
1147                    throw new NoSuchMessageException(msg.toString());
1148            }
1149    
1150            /**
1151             * Returns the last message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1152             *
1153             * @param uuid the uuid
1154             * @param companyId the company ID
1155             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1156             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1157             * @throws SystemException if a system exception occurred
1158             */
1159            public MBMessage fetchByUuid_C_Last(String uuid, long companyId,
1160                    OrderByComparator orderByComparator) throws SystemException {
1161                    int count = countByUuid_C(uuid, companyId);
1162    
1163                    List<MBMessage> list = findByUuid_C(uuid, companyId, count - 1, count,
1164                                    orderByComparator);
1165    
1166                    if (!list.isEmpty()) {
1167                            return list.get(0);
1168                    }
1169    
1170                    return null;
1171            }
1172    
1173            /**
1174             * Returns the message-boards messages before and after the current message-boards message in the ordered set where uuid = &#63; and companyId = &#63;.
1175             *
1176             * @param messageId the primary key of the current message-boards message
1177             * @param uuid the uuid
1178             * @param companyId the company ID
1179             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1180             * @return the previous, current, and next message-boards message
1181             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1182             * @throws SystemException if a system exception occurred
1183             */
1184            public MBMessage[] findByUuid_C_PrevAndNext(long messageId, String uuid,
1185                    long companyId, OrderByComparator orderByComparator)
1186                    throws NoSuchMessageException, SystemException {
1187                    MBMessage mbMessage = findByPrimaryKey(messageId);
1188    
1189                    Session session = null;
1190    
1191                    try {
1192                            session = openSession();
1193    
1194                            MBMessage[] array = new MBMessageImpl[3];
1195    
1196                            array[0] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1197                                            companyId, orderByComparator, true);
1198    
1199                            array[1] = mbMessage;
1200    
1201                            array[2] = getByUuid_C_PrevAndNext(session, mbMessage, uuid,
1202                                            companyId, orderByComparator, false);
1203    
1204                            return array;
1205                    }
1206                    catch (Exception e) {
1207                            throw processException(e);
1208                    }
1209                    finally {
1210                            closeSession(session);
1211                    }
1212            }
1213    
1214            protected MBMessage getByUuid_C_PrevAndNext(Session session,
1215                    MBMessage mbMessage, String uuid, long companyId,
1216                    OrderByComparator orderByComparator, boolean previous) {
1217                    StringBundler query = null;
1218    
1219                    if (orderByComparator != null) {
1220                            query = new StringBundler(6 +
1221                                            (orderByComparator.getOrderByFields().length * 6));
1222                    }
1223                    else {
1224                            query = new StringBundler(3);
1225                    }
1226    
1227                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1228    
1229                    boolean bindUuid = false;
1230    
1231                    if (uuid == null) {
1232                            query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1233                    }
1234                    else if (uuid.equals(StringPool.BLANK)) {
1235                            query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1236                    }
1237                    else {
1238                            bindUuid = true;
1239    
1240                            query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1241                    }
1242    
1243                    query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1244    
1245                    if (orderByComparator != null) {
1246                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1247    
1248                            if (orderByConditionFields.length > 0) {
1249                                    query.append(WHERE_AND);
1250                            }
1251    
1252                            for (int i = 0; i < orderByConditionFields.length; i++) {
1253                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1254                                    query.append(orderByConditionFields[i]);
1255    
1256                                    if ((i + 1) < orderByConditionFields.length) {
1257                                            if (orderByComparator.isAscending() ^ previous) {
1258                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1259                                            }
1260                                            else {
1261                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1262                                            }
1263                                    }
1264                                    else {
1265                                            if (orderByComparator.isAscending() ^ previous) {
1266                                                    query.append(WHERE_GREATER_THAN);
1267                                            }
1268                                            else {
1269                                                    query.append(WHERE_LESSER_THAN);
1270                                            }
1271                                    }
1272                            }
1273    
1274                            query.append(ORDER_BY_CLAUSE);
1275    
1276                            String[] orderByFields = orderByComparator.getOrderByFields();
1277    
1278                            for (int i = 0; i < orderByFields.length; i++) {
1279                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1280                                    query.append(orderByFields[i]);
1281    
1282                                    if ((i + 1) < orderByFields.length) {
1283                                            if (orderByComparator.isAscending() ^ previous) {
1284                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1285                                            }
1286                                            else {
1287                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1288                                            }
1289                                    }
1290                                    else {
1291                                            if (orderByComparator.isAscending() ^ previous) {
1292                                                    query.append(ORDER_BY_ASC);
1293                                            }
1294                                            else {
1295                                                    query.append(ORDER_BY_DESC);
1296                                            }
1297                                    }
1298                            }
1299                    }
1300                    else {
1301                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1302                    }
1303    
1304                    String sql = query.toString();
1305    
1306                    Query q = session.createQuery(sql);
1307    
1308                    q.setFirstResult(0);
1309                    q.setMaxResults(2);
1310    
1311                    QueryPos qPos = QueryPos.getInstance(q);
1312    
1313                    if (bindUuid) {
1314                            qPos.add(uuid);
1315                    }
1316    
1317                    qPos.add(companyId);
1318    
1319                    if (orderByComparator != null) {
1320                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1321    
1322                            for (Object value : values) {
1323                                    qPos.add(value);
1324                            }
1325                    }
1326    
1327                    List<MBMessage> list = q.list();
1328    
1329                    if (list.size() == 2) {
1330                            return list.get(1);
1331                    }
1332                    else {
1333                            return null;
1334                    }
1335            }
1336    
1337            /**
1338             * Removes all the message-boards messages where uuid = &#63; and companyId = &#63; from the database.
1339             *
1340             * @param uuid the uuid
1341             * @param companyId the company ID
1342             * @throws SystemException if a system exception occurred
1343             */
1344            public void removeByUuid_C(String uuid, long companyId)
1345                    throws SystemException {
1346                    for (MBMessage mbMessage : findByUuid_C(uuid, companyId,
1347                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
1348                            remove(mbMessage);
1349                    }
1350            }
1351    
1352            /**
1353             * Returns the number of message-boards messages where uuid = &#63; and companyId = &#63;.
1354             *
1355             * @param uuid the uuid
1356             * @param companyId the company ID
1357             * @return the number of matching message-boards messages
1358             * @throws SystemException if a system exception occurred
1359             */
1360            public int countByUuid_C(String uuid, long companyId)
1361                    throws SystemException {
1362                    FinderPath finderPath = FINDER_PATH_COUNT_BY_UUID_C;
1363    
1364                    Object[] finderArgs = new Object[] { uuid, companyId };
1365    
1366                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
1367                                    this);
1368    
1369                    if (count == null) {
1370                            StringBundler query = new StringBundler(3);
1371    
1372                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
1373    
1374                            boolean bindUuid = false;
1375    
1376                            if (uuid == null) {
1377                                    query.append(_FINDER_COLUMN_UUID_C_UUID_1);
1378                            }
1379                            else if (uuid.equals(StringPool.BLANK)) {
1380                                    query.append(_FINDER_COLUMN_UUID_C_UUID_3);
1381                            }
1382                            else {
1383                                    bindUuid = true;
1384    
1385                                    query.append(_FINDER_COLUMN_UUID_C_UUID_2);
1386                            }
1387    
1388                            query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
1389    
1390                            String sql = query.toString();
1391    
1392                            Session session = null;
1393    
1394                            try {
1395                                    session = openSession();
1396    
1397                                    Query q = session.createQuery(sql);
1398    
1399                                    QueryPos qPos = QueryPos.getInstance(q);
1400    
1401                                    if (bindUuid) {
1402                                            qPos.add(uuid);
1403                                    }
1404    
1405                                    qPos.add(companyId);
1406    
1407                                    count = (Long)q.uniqueResult();
1408    
1409                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
1410                            }
1411                            catch (Exception e) {
1412                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1413    
1414                                    throw processException(e);
1415                            }
1416                            finally {
1417                                    closeSession(session);
1418                            }
1419                    }
1420    
1421                    return count.intValue();
1422            }
1423    
1424            private static final String _FINDER_COLUMN_UUID_C_UUID_1 = "mbMessage.uuid IS NULL AND ";
1425            private static final String _FINDER_COLUMN_UUID_C_UUID_2 = "mbMessage.uuid = ? AND ";
1426            private static final String _FINDER_COLUMN_UUID_C_UUID_3 = "(mbMessage.uuid IS NULL OR mbMessage.uuid = '') AND ";
1427            private static final String _FINDER_COLUMN_UUID_C_COMPANYID_2 = "mbMessage.companyId = ?";
1428            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1429                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1430                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByGroupId",
1431                            new String[] {
1432                                    Long.class.getName(),
1433                                    
1434                            Integer.class.getName(), Integer.class.getName(),
1435                                    OrderByComparator.class.getName()
1436                            });
1437            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID =
1438                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1439                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
1440                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByGroupId",
1441                            new String[] { Long.class.getName() },
1442                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
1443                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
1444            public static final FinderPath FINDER_PATH_COUNT_BY_GROUPID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
1445                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
1446                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByGroupId",
1447                            new String[] { Long.class.getName() });
1448    
1449            /**
1450             * Returns all the message-boards messages where groupId = &#63;.
1451             *
1452             * @param groupId the group ID
1453             * @return the matching message-boards messages
1454             * @throws SystemException if a system exception occurred
1455             */
1456            public List<MBMessage> findByGroupId(long groupId)
1457                    throws SystemException {
1458                    return findByGroupId(groupId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1459            }
1460    
1461            /**
1462             * Returns a range of all the message-boards messages where groupId = &#63;.
1463             *
1464             * <p>
1465             * 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.
1466             * </p>
1467             *
1468             * @param groupId the group ID
1469             * @param start the lower bound of the range of message-boards messages
1470             * @param end the upper bound of the range of message-boards messages (not inclusive)
1471             * @return the range of matching message-boards messages
1472             * @throws SystemException if a system exception occurred
1473             */
1474            public List<MBMessage> findByGroupId(long groupId, int start, int end)
1475                    throws SystemException {
1476                    return findByGroupId(groupId, start, end, null);
1477            }
1478    
1479            /**
1480             * Returns an ordered range of all the message-boards messages where groupId = &#63;.
1481             *
1482             * <p>
1483             * 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.
1484             * </p>
1485             *
1486             * @param groupId the group ID
1487             * @param start the lower bound of the range of message-boards messages
1488             * @param end the upper bound of the range of message-boards messages (not inclusive)
1489             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1490             * @return the ordered range of matching message-boards messages
1491             * @throws SystemException if a system exception occurred
1492             */
1493            public List<MBMessage> findByGroupId(long groupId, int start, int end,
1494                    OrderByComparator orderByComparator) throws SystemException {
1495                    boolean pagination = true;
1496                    FinderPath finderPath = null;
1497                    Object[] finderArgs = null;
1498    
1499                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1500                                    (orderByComparator == null)) {
1501                            pagination = false;
1502                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID;
1503                            finderArgs = new Object[] { groupId };
1504                    }
1505                    else {
1506                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_GROUPID;
1507                            finderArgs = new Object[] { groupId, start, end, orderByComparator };
1508                    }
1509    
1510                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
1511                                    finderArgs, this);
1512    
1513                    if ((list != null) && !list.isEmpty()) {
1514                            for (MBMessage mbMessage : list) {
1515                                    if ((groupId != mbMessage.getGroupId())) {
1516                                            list = null;
1517    
1518                                            break;
1519                                    }
1520                            }
1521                    }
1522    
1523                    if (list == null) {
1524                            StringBundler query = null;
1525    
1526                            if (orderByComparator != null) {
1527                                    query = new StringBundler(3 +
1528                                                    (orderByComparator.getOrderByFields().length * 3));
1529                            }
1530                            else {
1531                                    query = new StringBundler(3);
1532                            }
1533    
1534                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1535    
1536                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1537    
1538                            if (orderByComparator != null) {
1539                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1540                                            orderByComparator);
1541                            }
1542                            else
1543                             if (pagination) {
1544                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1545                            }
1546    
1547                            String sql = query.toString();
1548    
1549                            Session session = null;
1550    
1551                            try {
1552                                    session = openSession();
1553    
1554                                    Query q = session.createQuery(sql);
1555    
1556                                    QueryPos qPos = QueryPos.getInstance(q);
1557    
1558                                    qPos.add(groupId);
1559    
1560                                    if (!pagination) {
1561                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1562                                                            start, end, false);
1563    
1564                                            Collections.sort(list);
1565    
1566                                            list = new UnmodifiableList<MBMessage>(list);
1567                                    }
1568                                    else {
1569                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
1570                                                            start, end);
1571                                    }
1572    
1573                                    cacheResult(list);
1574    
1575                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
1576                            }
1577                            catch (Exception e) {
1578                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
1579    
1580                                    throw processException(e);
1581                            }
1582                            finally {
1583                                    closeSession(session);
1584                            }
1585                    }
1586    
1587                    return list;
1588            }
1589    
1590            /**
1591             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1592             *
1593             * @param groupId the group ID
1594             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1595             * @return the first matching message-boards message
1596             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1597             * @throws SystemException if a system exception occurred
1598             */
1599            public MBMessage findByGroupId_First(long groupId,
1600                    OrderByComparator orderByComparator)
1601                    throws NoSuchMessageException, SystemException {
1602                    MBMessage mbMessage = fetchByGroupId_First(groupId, orderByComparator);
1603    
1604                    if (mbMessage != null) {
1605                            return mbMessage;
1606                    }
1607    
1608                    StringBundler msg = new StringBundler(4);
1609    
1610                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1611    
1612                    msg.append("groupId=");
1613                    msg.append(groupId);
1614    
1615                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1616    
1617                    throw new NoSuchMessageException(msg.toString());
1618            }
1619    
1620            /**
1621             * Returns the first message-boards message in the ordered set where groupId = &#63;.
1622             *
1623             * @param groupId the group ID
1624             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1625             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1626             * @throws SystemException if a system exception occurred
1627             */
1628            public MBMessage fetchByGroupId_First(long groupId,
1629                    OrderByComparator orderByComparator) throws SystemException {
1630                    List<MBMessage> list = findByGroupId(groupId, 0, 1, orderByComparator);
1631    
1632                    if (!list.isEmpty()) {
1633                            return list.get(0);
1634                    }
1635    
1636                    return null;
1637            }
1638    
1639            /**
1640             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1641             *
1642             * @param groupId the group ID
1643             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1644             * @return the last matching message-boards message
1645             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
1646             * @throws SystemException if a system exception occurred
1647             */
1648            public MBMessage findByGroupId_Last(long groupId,
1649                    OrderByComparator orderByComparator)
1650                    throws NoSuchMessageException, SystemException {
1651                    MBMessage mbMessage = fetchByGroupId_Last(groupId, orderByComparator);
1652    
1653                    if (mbMessage != null) {
1654                            return mbMessage;
1655                    }
1656    
1657                    StringBundler msg = new StringBundler(4);
1658    
1659                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1660    
1661                    msg.append("groupId=");
1662                    msg.append(groupId);
1663    
1664                    msg.append(StringPool.CLOSE_CURLY_BRACE);
1665    
1666                    throw new NoSuchMessageException(msg.toString());
1667            }
1668    
1669            /**
1670             * Returns the last message-boards message in the ordered set where groupId = &#63;.
1671             *
1672             * @param groupId the group ID
1673             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1674             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
1675             * @throws SystemException if a system exception occurred
1676             */
1677            public MBMessage fetchByGroupId_Last(long groupId,
1678                    OrderByComparator orderByComparator) throws SystemException {
1679                    int count = countByGroupId(groupId);
1680    
1681                    List<MBMessage> list = findByGroupId(groupId, count - 1, count,
1682                                    orderByComparator);
1683    
1684                    if (!list.isEmpty()) {
1685                            return list.get(0);
1686                    }
1687    
1688                    return null;
1689            }
1690    
1691            /**
1692             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63;.
1693             *
1694             * @param messageId the primary key of the current message-boards message
1695             * @param groupId the group ID
1696             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1697             * @return the previous, current, and next message-boards message
1698             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1699             * @throws SystemException if a system exception occurred
1700             */
1701            public MBMessage[] findByGroupId_PrevAndNext(long messageId, long groupId,
1702                    OrderByComparator orderByComparator)
1703                    throws NoSuchMessageException, SystemException {
1704                    MBMessage mbMessage = findByPrimaryKey(messageId);
1705    
1706                    Session session = null;
1707    
1708                    try {
1709                            session = openSession();
1710    
1711                            MBMessage[] array = new MBMessageImpl[3];
1712    
1713                            array[0] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1714                                            orderByComparator, true);
1715    
1716                            array[1] = mbMessage;
1717    
1718                            array[2] = getByGroupId_PrevAndNext(session, mbMessage, groupId,
1719                                            orderByComparator, false);
1720    
1721                            return array;
1722                    }
1723                    catch (Exception e) {
1724                            throw processException(e);
1725                    }
1726                    finally {
1727                            closeSession(session);
1728                    }
1729            }
1730    
1731            protected MBMessage getByGroupId_PrevAndNext(Session session,
1732                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
1733                    boolean previous) {
1734                    StringBundler query = null;
1735    
1736                    if (orderByComparator != null) {
1737                            query = new StringBundler(6 +
1738                                            (orderByComparator.getOrderByFields().length * 6));
1739                    }
1740                    else {
1741                            query = new StringBundler(3);
1742                    }
1743    
1744                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
1745    
1746                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1747    
1748                    if (orderByComparator != null) {
1749                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
1750    
1751                            if (orderByConditionFields.length > 0) {
1752                                    query.append(WHERE_AND);
1753                            }
1754    
1755                            for (int i = 0; i < orderByConditionFields.length; i++) {
1756                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1757                                    query.append(orderByConditionFields[i]);
1758    
1759                                    if ((i + 1) < orderByConditionFields.length) {
1760                                            if (orderByComparator.isAscending() ^ previous) {
1761                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
1762                                            }
1763                                            else {
1764                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
1765                                            }
1766                                    }
1767                                    else {
1768                                            if (orderByComparator.isAscending() ^ previous) {
1769                                                    query.append(WHERE_GREATER_THAN);
1770                                            }
1771                                            else {
1772                                                    query.append(WHERE_LESSER_THAN);
1773                                            }
1774                                    }
1775                            }
1776    
1777                            query.append(ORDER_BY_CLAUSE);
1778    
1779                            String[] orderByFields = orderByComparator.getOrderByFields();
1780    
1781                            for (int i = 0; i < orderByFields.length; i++) {
1782                                    query.append(_ORDER_BY_ENTITY_ALIAS);
1783                                    query.append(orderByFields[i]);
1784    
1785                                    if ((i + 1) < orderByFields.length) {
1786                                            if (orderByComparator.isAscending() ^ previous) {
1787                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
1788                                            }
1789                                            else {
1790                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
1791                                            }
1792                                    }
1793                                    else {
1794                                            if (orderByComparator.isAscending() ^ previous) {
1795                                                    query.append(ORDER_BY_ASC);
1796                                            }
1797                                            else {
1798                                                    query.append(ORDER_BY_DESC);
1799                                            }
1800                                    }
1801                            }
1802                    }
1803                    else {
1804                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1805                    }
1806    
1807                    String sql = query.toString();
1808    
1809                    Query q = session.createQuery(sql);
1810    
1811                    q.setFirstResult(0);
1812                    q.setMaxResults(2);
1813    
1814                    QueryPos qPos = QueryPos.getInstance(q);
1815    
1816                    qPos.add(groupId);
1817    
1818                    if (orderByComparator != null) {
1819                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
1820    
1821                            for (Object value : values) {
1822                                    qPos.add(value);
1823                            }
1824                    }
1825    
1826                    List<MBMessage> list = q.list();
1827    
1828                    if (list.size() == 2) {
1829                            return list.get(1);
1830                    }
1831                    else {
1832                            return null;
1833                    }
1834            }
1835    
1836            /**
1837             * Returns all the message-boards messages that the user has permission to view where groupId = &#63;.
1838             *
1839             * @param groupId the group ID
1840             * @return the matching message-boards messages that the user has permission to view
1841             * @throws SystemException if a system exception occurred
1842             */
1843            public List<MBMessage> filterFindByGroupId(long groupId)
1844                    throws SystemException {
1845                    return filterFindByGroupId(groupId, QueryUtil.ALL_POS,
1846                            QueryUtil.ALL_POS, null);
1847            }
1848    
1849            /**
1850             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63;.
1851             *
1852             * <p>
1853             * 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.
1854             * </p>
1855             *
1856             * @param groupId the group ID
1857             * @param start the lower bound of the range of message-boards messages
1858             * @param end the upper bound of the range of message-boards messages (not inclusive)
1859             * @return the range of matching message-boards messages that the user has permission to view
1860             * @throws SystemException if a system exception occurred
1861             */
1862            public List<MBMessage> filterFindByGroupId(long groupId, int start, int end)
1863                    throws SystemException {
1864                    return filterFindByGroupId(groupId, start, end, null);
1865            }
1866    
1867            /**
1868             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63;.
1869             *
1870             * <p>
1871             * 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.
1872             * </p>
1873             *
1874             * @param groupId the group ID
1875             * @param start the lower bound of the range of message-boards messages
1876             * @param end the upper bound of the range of message-boards messages (not inclusive)
1877             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1878             * @return the ordered range of matching message-boards messages that the user has permission to view
1879             * @throws SystemException if a system exception occurred
1880             */
1881            public List<MBMessage> filterFindByGroupId(long groupId, int start,
1882                    int end, OrderByComparator orderByComparator) throws SystemException {
1883                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1884                            return findByGroupId(groupId, start, end, orderByComparator);
1885                    }
1886    
1887                    StringBundler query = null;
1888    
1889                    if (orderByComparator != null) {
1890                            query = new StringBundler(3 +
1891                                            (orderByComparator.getOrderByFields().length * 3));
1892                    }
1893                    else {
1894                            query = new StringBundler(3);
1895                    }
1896    
1897                    if (getDB().isSupportsInlineDistinct()) {
1898                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
1899                    }
1900                    else {
1901                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
1902                    }
1903    
1904                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
1905    
1906                    if (!getDB().isSupportsInlineDistinct()) {
1907                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
1908                    }
1909    
1910                    if (orderByComparator != null) {
1911                            if (getDB().isSupportsInlineDistinct()) {
1912                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1913                                            orderByComparator, true);
1914                            }
1915                            else {
1916                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
1917                                            orderByComparator, true);
1918                            }
1919                    }
1920                    else {
1921                            if (getDB().isSupportsInlineDistinct()) {
1922                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
1923                            }
1924                            else {
1925                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
1926                            }
1927                    }
1928    
1929                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1930                                    MBMessage.class.getName(),
1931                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
1932    
1933                    Session session = null;
1934    
1935                    try {
1936                            session = openSession();
1937    
1938                            SQLQuery q = session.createSQLQuery(sql);
1939    
1940                            if (getDB().isSupportsInlineDistinct()) {
1941                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
1942                            }
1943                            else {
1944                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
1945                            }
1946    
1947                            QueryPos qPos = QueryPos.getInstance(q);
1948    
1949                            qPos.add(groupId);
1950    
1951                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
1952                    }
1953                    catch (Exception e) {
1954                            throw processException(e);
1955                    }
1956                    finally {
1957                            closeSession(session);
1958                    }
1959            }
1960    
1961            /**
1962             * 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;.
1963             *
1964             * @param messageId the primary key of the current message-boards message
1965             * @param groupId the group ID
1966             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
1967             * @return the previous, current, and next message-boards message
1968             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
1969             * @throws SystemException if a system exception occurred
1970             */
1971            public MBMessage[] filterFindByGroupId_PrevAndNext(long messageId,
1972                    long groupId, OrderByComparator orderByComparator)
1973                    throws NoSuchMessageException, SystemException {
1974                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
1975                            return findByGroupId_PrevAndNext(messageId, groupId,
1976                                    orderByComparator);
1977                    }
1978    
1979                    MBMessage mbMessage = findByPrimaryKey(messageId);
1980    
1981                    Session session = null;
1982    
1983                    try {
1984                            session = openSession();
1985    
1986                            MBMessage[] array = new MBMessageImpl[3];
1987    
1988                            array[0] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1989                                            groupId, orderByComparator, true);
1990    
1991                            array[1] = mbMessage;
1992    
1993                            array[2] = filterGetByGroupId_PrevAndNext(session, mbMessage,
1994                                            groupId, orderByComparator, false);
1995    
1996                            return array;
1997                    }
1998                    catch (Exception e) {
1999                            throw processException(e);
2000                    }
2001                    finally {
2002                            closeSession(session);
2003                    }
2004            }
2005    
2006            protected MBMessage filterGetByGroupId_PrevAndNext(Session session,
2007                    MBMessage mbMessage, long groupId, OrderByComparator orderByComparator,
2008                    boolean previous) {
2009                    StringBundler query = null;
2010    
2011                    if (orderByComparator != null) {
2012                            query = new StringBundler(6 +
2013                                            (orderByComparator.getOrderByFields().length * 6));
2014                    }
2015                    else {
2016                            query = new StringBundler(3);
2017                    }
2018    
2019                    if (getDB().isSupportsInlineDistinct()) {
2020                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
2021                    }
2022                    else {
2023                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
2024                    }
2025    
2026                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2027    
2028                    if (!getDB().isSupportsInlineDistinct()) {
2029                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
2030                    }
2031    
2032                    if (orderByComparator != null) {
2033                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2034    
2035                            if (orderByConditionFields.length > 0) {
2036                                    query.append(WHERE_AND);
2037                            }
2038    
2039                            for (int i = 0; i < orderByConditionFields.length; i++) {
2040                                    if (getDB().isSupportsInlineDistinct()) {
2041                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2042                                    }
2043                                    else {
2044                                            query.append(_ORDER_BY_ENTITY_TABLE);
2045                                    }
2046    
2047                                    query.append(orderByConditionFields[i]);
2048    
2049                                    if ((i + 1) < orderByConditionFields.length) {
2050                                            if (orderByComparator.isAscending() ^ previous) {
2051                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2052                                            }
2053                                            else {
2054                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2055                                            }
2056                                    }
2057                                    else {
2058                                            if (orderByComparator.isAscending() ^ previous) {
2059                                                    query.append(WHERE_GREATER_THAN);
2060                                            }
2061                                            else {
2062                                                    query.append(WHERE_LESSER_THAN);
2063                                            }
2064                                    }
2065                            }
2066    
2067                            query.append(ORDER_BY_CLAUSE);
2068    
2069                            String[] orderByFields = orderByComparator.getOrderByFields();
2070    
2071                            for (int i = 0; i < orderByFields.length; i++) {
2072                                    if (getDB().isSupportsInlineDistinct()) {
2073                                            query.append(_ORDER_BY_ENTITY_ALIAS);
2074                                    }
2075                                    else {
2076                                            query.append(_ORDER_BY_ENTITY_TABLE);
2077                                    }
2078    
2079                                    query.append(orderByFields[i]);
2080    
2081                                    if ((i + 1) < orderByFields.length) {
2082                                            if (orderByComparator.isAscending() ^ previous) {
2083                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2084                                            }
2085                                            else {
2086                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2087                                            }
2088                                    }
2089                                    else {
2090                                            if (orderByComparator.isAscending() ^ previous) {
2091                                                    query.append(ORDER_BY_ASC);
2092                                            }
2093                                            else {
2094                                                    query.append(ORDER_BY_DESC);
2095                                            }
2096                                    }
2097                            }
2098                    }
2099                    else {
2100                            if (getDB().isSupportsInlineDistinct()) {
2101                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2102                            }
2103                            else {
2104                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
2105                            }
2106                    }
2107    
2108                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2109                                    MBMessage.class.getName(),
2110                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2111    
2112                    SQLQuery q = session.createSQLQuery(sql);
2113    
2114                    q.setFirstResult(0);
2115                    q.setMaxResults(2);
2116    
2117                    if (getDB().isSupportsInlineDistinct()) {
2118                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
2119                    }
2120                    else {
2121                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
2122                    }
2123    
2124                    QueryPos qPos = QueryPos.getInstance(q);
2125    
2126                    qPos.add(groupId);
2127    
2128                    if (orderByComparator != null) {
2129                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2130    
2131                            for (Object value : values) {
2132                                    qPos.add(value);
2133                            }
2134                    }
2135    
2136                    List<MBMessage> list = q.list();
2137    
2138                    if (list.size() == 2) {
2139                            return list.get(1);
2140                    }
2141                    else {
2142                            return null;
2143                    }
2144            }
2145    
2146            /**
2147             * Removes all the message-boards messages where groupId = &#63; from the database.
2148             *
2149             * @param groupId the group ID
2150             * @throws SystemException if a system exception occurred
2151             */
2152            public void removeByGroupId(long groupId) throws SystemException {
2153                    for (MBMessage mbMessage : findByGroupId(groupId, QueryUtil.ALL_POS,
2154                                    QueryUtil.ALL_POS, null)) {
2155                            remove(mbMessage);
2156                    }
2157            }
2158    
2159            /**
2160             * Returns the number of message-boards messages where groupId = &#63;.
2161             *
2162             * @param groupId the group ID
2163             * @return the number of matching message-boards messages
2164             * @throws SystemException if a system exception occurred
2165             */
2166            public int countByGroupId(long groupId) throws SystemException {
2167                    FinderPath finderPath = FINDER_PATH_COUNT_BY_GROUPID;
2168    
2169                    Object[] finderArgs = new Object[] { groupId };
2170    
2171                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2172                                    this);
2173    
2174                    if (count == null) {
2175                            StringBundler query = new StringBundler(2);
2176    
2177                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2178    
2179                            query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2180    
2181                            String sql = query.toString();
2182    
2183                            Session session = null;
2184    
2185                            try {
2186                                    session = openSession();
2187    
2188                                    Query q = session.createQuery(sql);
2189    
2190                                    QueryPos qPos = QueryPos.getInstance(q);
2191    
2192                                    qPos.add(groupId);
2193    
2194                                    count = (Long)q.uniqueResult();
2195    
2196                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2197                            }
2198                            catch (Exception e) {
2199                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2200    
2201                                    throw processException(e);
2202                            }
2203                            finally {
2204                                    closeSession(session);
2205                            }
2206                    }
2207    
2208                    return count.intValue();
2209            }
2210    
2211            /**
2212             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63;.
2213             *
2214             * @param groupId the group ID
2215             * @return the number of matching message-boards messages that the user has permission to view
2216             * @throws SystemException if a system exception occurred
2217             */
2218            public int filterCountByGroupId(long groupId) throws SystemException {
2219                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
2220                            return countByGroupId(groupId);
2221                    }
2222    
2223                    StringBundler query = new StringBundler(2);
2224    
2225                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
2226    
2227                    query.append(_FINDER_COLUMN_GROUPID_GROUPID_2);
2228    
2229                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
2230                                    MBMessage.class.getName(),
2231                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
2232    
2233                    Session session = null;
2234    
2235                    try {
2236                            session = openSession();
2237    
2238                            SQLQuery q = session.createSQLQuery(sql);
2239    
2240                            q.addScalar(COUNT_COLUMN_NAME,
2241                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
2242    
2243                            QueryPos qPos = QueryPos.getInstance(q);
2244    
2245                            qPos.add(groupId);
2246    
2247                            Long count = (Long)q.uniqueResult();
2248    
2249                            return count.intValue();
2250                    }
2251                    catch (Exception e) {
2252                            throw processException(e);
2253                    }
2254                    finally {
2255                            closeSession(session);
2256                    }
2257            }
2258    
2259            private static final String _FINDER_COLUMN_GROUPID_GROUPID_2 = "mbMessage.groupId = ? AND mbMessage.categoryId != -1";
2260            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID =
2261                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2262                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2263                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByCompanyId",
2264                            new String[] {
2265                                    Long.class.getName(),
2266                                    
2267                            Integer.class.getName(), Integer.class.getName(),
2268                                    OrderByComparator.class.getName()
2269                            });
2270            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID =
2271                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2272                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2273                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByCompanyId",
2274                            new String[] { Long.class.getName() },
2275                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
2276                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2277            public static final FinderPath FINDER_PATH_COUNT_BY_COMPANYID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2278                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2279                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByCompanyId",
2280                            new String[] { Long.class.getName() });
2281    
2282            /**
2283             * Returns all the message-boards messages where companyId = &#63;.
2284             *
2285             * @param companyId the company ID
2286             * @return the matching message-boards messages
2287             * @throws SystemException if a system exception occurred
2288             */
2289            public List<MBMessage> findByCompanyId(long companyId)
2290                    throws SystemException {
2291                    return findByCompanyId(companyId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2292                            null);
2293            }
2294    
2295            /**
2296             * Returns a range of all the message-boards messages where companyId = &#63;.
2297             *
2298             * <p>
2299             * 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.
2300             * </p>
2301             *
2302             * @param companyId the company ID
2303             * @param start the lower bound of the range of message-boards messages
2304             * @param end the upper bound of the range of message-boards messages (not inclusive)
2305             * @return the range of matching message-boards messages
2306             * @throws SystemException if a system exception occurred
2307             */
2308            public List<MBMessage> findByCompanyId(long companyId, int start, int end)
2309                    throws SystemException {
2310                    return findByCompanyId(companyId, start, end, null);
2311            }
2312    
2313            /**
2314             * Returns an ordered range of all the message-boards messages where companyId = &#63;.
2315             *
2316             * <p>
2317             * 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.
2318             * </p>
2319             *
2320             * @param companyId the company ID
2321             * @param start the lower bound of the range of message-boards messages
2322             * @param end the upper bound of the range of message-boards messages (not inclusive)
2323             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2324             * @return the ordered range of matching message-boards messages
2325             * @throws SystemException if a system exception occurred
2326             */
2327            public List<MBMessage> findByCompanyId(long companyId, int start, int end,
2328                    OrderByComparator orderByComparator) throws SystemException {
2329                    boolean pagination = true;
2330                    FinderPath finderPath = null;
2331                    Object[] finderArgs = null;
2332    
2333                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2334                                    (orderByComparator == null)) {
2335                            pagination = false;
2336                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID;
2337                            finderArgs = new Object[] { companyId };
2338                    }
2339                    else {
2340                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_COMPANYID;
2341                            finderArgs = new Object[] { companyId, start, end, orderByComparator };
2342                    }
2343    
2344                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2345                                    finderArgs, this);
2346    
2347                    if ((list != null) && !list.isEmpty()) {
2348                            for (MBMessage mbMessage : list) {
2349                                    if ((companyId != mbMessage.getCompanyId())) {
2350                                            list = null;
2351    
2352                                            break;
2353                                    }
2354                            }
2355                    }
2356    
2357                    if (list == null) {
2358                            StringBundler query = null;
2359    
2360                            if (orderByComparator != null) {
2361                                    query = new StringBundler(3 +
2362                                                    (orderByComparator.getOrderByFields().length * 3));
2363                            }
2364                            else {
2365                                    query = new StringBundler(3);
2366                            }
2367    
2368                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2369    
2370                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2371    
2372                            if (orderByComparator != null) {
2373                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2374                                            orderByComparator);
2375                            }
2376                            else
2377                             if (pagination) {
2378                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2379                            }
2380    
2381                            String sql = query.toString();
2382    
2383                            Session session = null;
2384    
2385                            try {
2386                                    session = openSession();
2387    
2388                                    Query q = session.createQuery(sql);
2389    
2390                                    QueryPos qPos = QueryPos.getInstance(q);
2391    
2392                                    qPos.add(companyId);
2393    
2394                                    if (!pagination) {
2395                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2396                                                            start, end, false);
2397    
2398                                            Collections.sort(list);
2399    
2400                                            list = new UnmodifiableList<MBMessage>(list);
2401                                    }
2402                                    else {
2403                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2404                                                            start, end);
2405                                    }
2406    
2407                                    cacheResult(list);
2408    
2409                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2410                            }
2411                            catch (Exception e) {
2412                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2413    
2414                                    throw processException(e);
2415                            }
2416                            finally {
2417                                    closeSession(session);
2418                            }
2419                    }
2420    
2421                    return list;
2422            }
2423    
2424            /**
2425             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2426             *
2427             * @param companyId the company ID
2428             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2429             * @return the first matching message-boards message
2430             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2431             * @throws SystemException if a system exception occurred
2432             */
2433            public MBMessage findByCompanyId_First(long companyId,
2434                    OrderByComparator orderByComparator)
2435                    throws NoSuchMessageException, SystemException {
2436                    MBMessage mbMessage = fetchByCompanyId_First(companyId,
2437                                    orderByComparator);
2438    
2439                    if (mbMessage != null) {
2440                            return mbMessage;
2441                    }
2442    
2443                    StringBundler msg = new StringBundler(4);
2444    
2445                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2446    
2447                    msg.append("companyId=");
2448                    msg.append(companyId);
2449    
2450                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2451    
2452                    throw new NoSuchMessageException(msg.toString());
2453            }
2454    
2455            /**
2456             * Returns the first message-boards message in the ordered set where companyId = &#63;.
2457             *
2458             * @param companyId the company ID
2459             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2460             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2461             * @throws SystemException if a system exception occurred
2462             */
2463            public MBMessage fetchByCompanyId_First(long companyId,
2464                    OrderByComparator orderByComparator) throws SystemException {
2465                    List<MBMessage> list = findByCompanyId(companyId, 0, 1,
2466                                    orderByComparator);
2467    
2468                    if (!list.isEmpty()) {
2469                            return list.get(0);
2470                    }
2471    
2472                    return null;
2473            }
2474    
2475            /**
2476             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2477             *
2478             * @param companyId the company ID
2479             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2480             * @return the last matching message-boards message
2481             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2482             * @throws SystemException if a system exception occurred
2483             */
2484            public MBMessage findByCompanyId_Last(long companyId,
2485                    OrderByComparator orderByComparator)
2486                    throws NoSuchMessageException, SystemException {
2487                    MBMessage mbMessage = fetchByCompanyId_Last(companyId, orderByComparator);
2488    
2489                    if (mbMessage != null) {
2490                            return mbMessage;
2491                    }
2492    
2493                    StringBundler msg = new StringBundler(4);
2494    
2495                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2496    
2497                    msg.append("companyId=");
2498                    msg.append(companyId);
2499    
2500                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2501    
2502                    throw new NoSuchMessageException(msg.toString());
2503            }
2504    
2505            /**
2506             * Returns the last message-boards message in the ordered set where companyId = &#63;.
2507             *
2508             * @param companyId the company ID
2509             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2510             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2511             * @throws SystemException if a system exception occurred
2512             */
2513            public MBMessage fetchByCompanyId_Last(long companyId,
2514                    OrderByComparator orderByComparator) throws SystemException {
2515                    int count = countByCompanyId(companyId);
2516    
2517                    List<MBMessage> list = findByCompanyId(companyId, count - 1, count,
2518                                    orderByComparator);
2519    
2520                    if (!list.isEmpty()) {
2521                            return list.get(0);
2522                    }
2523    
2524                    return null;
2525            }
2526    
2527            /**
2528             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63;.
2529             *
2530             * @param messageId the primary key of the current message-boards message
2531             * @param companyId the company ID
2532             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2533             * @return the previous, current, and next message-boards message
2534             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
2535             * @throws SystemException if a system exception occurred
2536             */
2537            public MBMessage[] findByCompanyId_PrevAndNext(long messageId,
2538                    long companyId, OrderByComparator orderByComparator)
2539                    throws NoSuchMessageException, SystemException {
2540                    MBMessage mbMessage = findByPrimaryKey(messageId);
2541    
2542                    Session session = null;
2543    
2544                    try {
2545                            session = openSession();
2546    
2547                            MBMessage[] array = new MBMessageImpl[3];
2548    
2549                            array[0] = getByCompanyId_PrevAndNext(session, mbMessage,
2550                                            companyId, orderByComparator, true);
2551    
2552                            array[1] = mbMessage;
2553    
2554                            array[2] = getByCompanyId_PrevAndNext(session, mbMessage,
2555                                            companyId, orderByComparator, false);
2556    
2557                            return array;
2558                    }
2559                    catch (Exception e) {
2560                            throw processException(e);
2561                    }
2562                    finally {
2563                            closeSession(session);
2564                    }
2565            }
2566    
2567            protected MBMessage getByCompanyId_PrevAndNext(Session session,
2568                    MBMessage mbMessage, long companyId,
2569                    OrderByComparator orderByComparator, boolean previous) {
2570                    StringBundler query = null;
2571    
2572                    if (orderByComparator != null) {
2573                            query = new StringBundler(6 +
2574                                            (orderByComparator.getOrderByFields().length * 6));
2575                    }
2576                    else {
2577                            query = new StringBundler(3);
2578                    }
2579    
2580                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2581    
2582                    query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2583    
2584                    if (orderByComparator != null) {
2585                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
2586    
2587                            if (orderByConditionFields.length > 0) {
2588                                    query.append(WHERE_AND);
2589                            }
2590    
2591                            for (int i = 0; i < orderByConditionFields.length; i++) {
2592                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2593                                    query.append(orderByConditionFields[i]);
2594    
2595                                    if ((i + 1) < orderByConditionFields.length) {
2596                                            if (orderByComparator.isAscending() ^ previous) {
2597                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
2598                                            }
2599                                            else {
2600                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
2601                                            }
2602                                    }
2603                                    else {
2604                                            if (orderByComparator.isAscending() ^ previous) {
2605                                                    query.append(WHERE_GREATER_THAN);
2606                                            }
2607                                            else {
2608                                                    query.append(WHERE_LESSER_THAN);
2609                                            }
2610                                    }
2611                            }
2612    
2613                            query.append(ORDER_BY_CLAUSE);
2614    
2615                            String[] orderByFields = orderByComparator.getOrderByFields();
2616    
2617                            for (int i = 0; i < orderByFields.length; i++) {
2618                                    query.append(_ORDER_BY_ENTITY_ALIAS);
2619                                    query.append(orderByFields[i]);
2620    
2621                                    if ((i + 1) < orderByFields.length) {
2622                                            if (orderByComparator.isAscending() ^ previous) {
2623                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
2624                                            }
2625                                            else {
2626                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
2627                                            }
2628                                    }
2629                                    else {
2630                                            if (orderByComparator.isAscending() ^ previous) {
2631                                                    query.append(ORDER_BY_ASC);
2632                                            }
2633                                            else {
2634                                                    query.append(ORDER_BY_DESC);
2635                                            }
2636                                    }
2637                            }
2638                    }
2639                    else {
2640                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2641                    }
2642    
2643                    String sql = query.toString();
2644    
2645                    Query q = session.createQuery(sql);
2646    
2647                    q.setFirstResult(0);
2648                    q.setMaxResults(2);
2649    
2650                    QueryPos qPos = QueryPos.getInstance(q);
2651    
2652                    qPos.add(companyId);
2653    
2654                    if (orderByComparator != null) {
2655                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
2656    
2657                            for (Object value : values) {
2658                                    qPos.add(value);
2659                            }
2660                    }
2661    
2662                    List<MBMessage> list = q.list();
2663    
2664                    if (list.size() == 2) {
2665                            return list.get(1);
2666                    }
2667                    else {
2668                            return null;
2669                    }
2670            }
2671    
2672            /**
2673             * Removes all the message-boards messages where companyId = &#63; from the database.
2674             *
2675             * @param companyId the company ID
2676             * @throws SystemException if a system exception occurred
2677             */
2678            public void removeByCompanyId(long companyId) throws SystemException {
2679                    for (MBMessage mbMessage : findByCompanyId(companyId,
2680                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
2681                            remove(mbMessage);
2682                    }
2683            }
2684    
2685            /**
2686             * Returns the number of message-boards messages where companyId = &#63;.
2687             *
2688             * @param companyId the company ID
2689             * @return the number of matching message-boards messages
2690             * @throws SystemException if a system exception occurred
2691             */
2692            public int countByCompanyId(long companyId) throws SystemException {
2693                    FinderPath finderPath = FINDER_PATH_COUNT_BY_COMPANYID;
2694    
2695                    Object[] finderArgs = new Object[] { companyId };
2696    
2697                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
2698                                    this);
2699    
2700                    if (count == null) {
2701                            StringBundler query = new StringBundler(2);
2702    
2703                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
2704    
2705                            query.append(_FINDER_COLUMN_COMPANYID_COMPANYID_2);
2706    
2707                            String sql = query.toString();
2708    
2709                            Session session = null;
2710    
2711                            try {
2712                                    session = openSession();
2713    
2714                                    Query q = session.createQuery(sql);
2715    
2716                                    QueryPos qPos = QueryPos.getInstance(q);
2717    
2718                                    qPos.add(companyId);
2719    
2720                                    count = (Long)q.uniqueResult();
2721    
2722                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
2723                            }
2724                            catch (Exception e) {
2725                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2726    
2727                                    throw processException(e);
2728                            }
2729                            finally {
2730                                    closeSession(session);
2731                            }
2732                    }
2733    
2734                    return count.intValue();
2735            }
2736    
2737            private static final String _FINDER_COLUMN_COMPANYID_COMPANYID_2 = "mbMessage.companyId = ? AND mbMessage.categoryId != -1";
2738            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2739                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2740                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadId",
2741                            new String[] {
2742                                    Long.class.getName(),
2743                                    
2744                            Integer.class.getName(), Integer.class.getName(),
2745                                    OrderByComparator.class.getName()
2746                            });
2747            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID =
2748                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2749                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
2750                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadId",
2751                            new String[] { Long.class.getName() },
2752                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
2753                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
2754            public static final FinderPath FINDER_PATH_COUNT_BY_THREADID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
2755                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
2756                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadId",
2757                            new String[] { Long.class.getName() });
2758    
2759            /**
2760             * Returns all the message-boards messages where threadId = &#63;.
2761             *
2762             * @param threadId the thread ID
2763             * @return the matching message-boards messages
2764             * @throws SystemException if a system exception occurred
2765             */
2766            public List<MBMessage> findByThreadId(long threadId)
2767                    throws SystemException {
2768                    return findByThreadId(threadId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
2769                            null);
2770            }
2771    
2772            /**
2773             * Returns a range of all the message-boards messages where threadId = &#63;.
2774             *
2775             * <p>
2776             * 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.
2777             * </p>
2778             *
2779             * @param threadId the thread ID
2780             * @param start the lower bound of the range of message-boards messages
2781             * @param end the upper bound of the range of message-boards messages (not inclusive)
2782             * @return the range of matching message-boards messages
2783             * @throws SystemException if a system exception occurred
2784             */
2785            public List<MBMessage> findByThreadId(long threadId, int start, int end)
2786                    throws SystemException {
2787                    return findByThreadId(threadId, start, end, null);
2788            }
2789    
2790            /**
2791             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
2792             *
2793             * <p>
2794             * 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.
2795             * </p>
2796             *
2797             * @param threadId the thread ID
2798             * @param start the lower bound of the range of message-boards messages
2799             * @param end the upper bound of the range of message-boards messages (not inclusive)
2800             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2801             * @return the ordered range of matching message-boards messages
2802             * @throws SystemException if a system exception occurred
2803             */
2804            public List<MBMessage> findByThreadId(long threadId, int start, int end,
2805                    OrderByComparator orderByComparator) throws SystemException {
2806                    boolean pagination = true;
2807                    FinderPath finderPath = null;
2808                    Object[] finderArgs = null;
2809    
2810                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2811                                    (orderByComparator == null)) {
2812                            pagination = false;
2813                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID;
2814                            finderArgs = new Object[] { threadId };
2815                    }
2816                    else {
2817                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADID;
2818                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
2819                    }
2820    
2821                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
2822                                    finderArgs, this);
2823    
2824                    if ((list != null) && !list.isEmpty()) {
2825                            for (MBMessage mbMessage : list) {
2826                                    if ((threadId != mbMessage.getThreadId())) {
2827                                            list = null;
2828    
2829                                            break;
2830                                    }
2831                            }
2832                    }
2833    
2834                    if (list == null) {
2835                            StringBundler query = null;
2836    
2837                            if (orderByComparator != null) {
2838                                    query = new StringBundler(3 +
2839                                                    (orderByComparator.getOrderByFields().length * 3));
2840                            }
2841                            else {
2842                                    query = new StringBundler(3);
2843                            }
2844    
2845                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
2846    
2847                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
2848    
2849                            if (orderByComparator != null) {
2850                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2851                                            orderByComparator);
2852                            }
2853                            else
2854                             if (pagination) {
2855                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
2856                            }
2857    
2858                            String sql = query.toString();
2859    
2860                            Session session = null;
2861    
2862                            try {
2863                                    session = openSession();
2864    
2865                                    Query q = session.createQuery(sql);
2866    
2867                                    QueryPos qPos = QueryPos.getInstance(q);
2868    
2869                                    qPos.add(threadId);
2870    
2871                                    if (!pagination) {
2872                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2873                                                            start, end, false);
2874    
2875                                            Collections.sort(list);
2876    
2877                                            list = new UnmodifiableList<MBMessage>(list);
2878                                    }
2879                                    else {
2880                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
2881                                                            start, end);
2882                                    }
2883    
2884                                    cacheResult(list);
2885    
2886                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
2887                            }
2888                            catch (Exception e) {
2889                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
2890    
2891                                    throw processException(e);
2892                            }
2893                            finally {
2894                                    closeSession(session);
2895                            }
2896                    }
2897    
2898                    return list;
2899            }
2900    
2901            /**
2902             * Returns the first message-boards message in the ordered set where threadId = &#63;.
2903             *
2904             * @param threadId the thread ID
2905             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2906             * @return the first matching message-boards message
2907             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2908             * @throws SystemException if a system exception occurred
2909             */
2910            public MBMessage findByThreadId_First(long threadId,
2911                    OrderByComparator orderByComparator)
2912                    throws NoSuchMessageException, SystemException {
2913                    MBMessage mbMessage = fetchByThreadId_First(threadId, orderByComparator);
2914    
2915                    if (mbMessage != null) {
2916                            return mbMessage;
2917                    }
2918    
2919                    StringBundler msg = new StringBundler(4);
2920    
2921                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2922    
2923                    msg.append("threadId=");
2924                    msg.append(threadId);
2925    
2926                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2927    
2928                    throw new NoSuchMessageException(msg.toString());
2929            }
2930    
2931            /**
2932             * Returns the first message-boards message in the ordered set where threadId = &#63;.
2933             *
2934             * @param threadId the thread ID
2935             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2936             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2937             * @throws SystemException if a system exception occurred
2938             */
2939            public MBMessage fetchByThreadId_First(long threadId,
2940                    OrderByComparator orderByComparator) throws SystemException {
2941                    List<MBMessage> list = findByThreadId(threadId, 0, 1, orderByComparator);
2942    
2943                    if (!list.isEmpty()) {
2944                            return list.get(0);
2945                    }
2946    
2947                    return null;
2948            }
2949    
2950            /**
2951             * Returns the last message-boards message in the ordered set where threadId = &#63;.
2952             *
2953             * @param threadId the thread ID
2954             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2955             * @return the last matching message-boards message
2956             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
2957             * @throws SystemException if a system exception occurred
2958             */
2959            public MBMessage findByThreadId_Last(long threadId,
2960                    OrderByComparator orderByComparator)
2961                    throws NoSuchMessageException, SystemException {
2962                    MBMessage mbMessage = fetchByThreadId_Last(threadId, orderByComparator);
2963    
2964                    if (mbMessage != null) {
2965                            return mbMessage;
2966                    }
2967    
2968                    StringBundler msg = new StringBundler(4);
2969    
2970                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
2971    
2972                    msg.append("threadId=");
2973                    msg.append(threadId);
2974    
2975                    msg.append(StringPool.CLOSE_CURLY_BRACE);
2976    
2977                    throw new NoSuchMessageException(msg.toString());
2978            }
2979    
2980            /**
2981             * Returns the last message-boards message in the ordered set where threadId = &#63;.
2982             *
2983             * @param threadId the thread ID
2984             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
2985             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
2986             * @throws SystemException if a system exception occurred
2987             */
2988            public MBMessage fetchByThreadId_Last(long threadId,
2989                    OrderByComparator orderByComparator) throws SystemException {
2990                    int count = countByThreadId(threadId);
2991    
2992                    List<MBMessage> list = findByThreadId(threadId, count - 1, count,
2993                                    orderByComparator);
2994    
2995                    if (!list.isEmpty()) {
2996                            return list.get(0);
2997                    }
2998    
2999                    return null;
3000            }
3001    
3002            /**
3003             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3004             *
3005             * @param messageId the primary key of the current message-boards message
3006             * @param threadId the thread ID
3007             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3008             * @return the previous, current, and next message-boards message
3009             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3010             * @throws SystemException if a system exception occurred
3011             */
3012            public MBMessage[] findByThreadId_PrevAndNext(long messageId,
3013                    long threadId, OrderByComparator orderByComparator)
3014                    throws NoSuchMessageException, SystemException {
3015                    MBMessage mbMessage = findByPrimaryKey(messageId);
3016    
3017                    Session session = null;
3018    
3019                    try {
3020                            session = openSession();
3021    
3022                            MBMessage[] array = new MBMessageImpl[3];
3023    
3024                            array[0] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3025                                            orderByComparator, true);
3026    
3027                            array[1] = mbMessage;
3028    
3029                            array[2] = getByThreadId_PrevAndNext(session, mbMessage, threadId,
3030                                            orderByComparator, false);
3031    
3032                            return array;
3033                    }
3034                    catch (Exception e) {
3035                            throw processException(e);
3036                    }
3037                    finally {
3038                            closeSession(session);
3039                    }
3040            }
3041    
3042            protected MBMessage getByThreadId_PrevAndNext(Session session,
3043                    MBMessage mbMessage, long threadId,
3044                    OrderByComparator orderByComparator, boolean previous) {
3045                    StringBundler query = null;
3046    
3047                    if (orderByComparator != null) {
3048                            query = new StringBundler(6 +
3049                                            (orderByComparator.getOrderByFields().length * 6));
3050                    }
3051                    else {
3052                            query = new StringBundler(3);
3053                    }
3054    
3055                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3056    
3057                    query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3058    
3059                    if (orderByComparator != null) {
3060                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3061    
3062                            if (orderByConditionFields.length > 0) {
3063                                    query.append(WHERE_AND);
3064                            }
3065    
3066                            for (int i = 0; i < orderByConditionFields.length; i++) {
3067                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3068                                    query.append(orderByConditionFields[i]);
3069    
3070                                    if ((i + 1) < orderByConditionFields.length) {
3071                                            if (orderByComparator.isAscending() ^ previous) {
3072                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3073                                            }
3074                                            else {
3075                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3076                                            }
3077                                    }
3078                                    else {
3079                                            if (orderByComparator.isAscending() ^ previous) {
3080                                                    query.append(WHERE_GREATER_THAN);
3081                                            }
3082                                            else {
3083                                                    query.append(WHERE_LESSER_THAN);
3084                                            }
3085                                    }
3086                            }
3087    
3088                            query.append(ORDER_BY_CLAUSE);
3089    
3090                            String[] orderByFields = orderByComparator.getOrderByFields();
3091    
3092                            for (int i = 0; i < orderByFields.length; i++) {
3093                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3094                                    query.append(orderByFields[i]);
3095    
3096                                    if ((i + 1) < orderByFields.length) {
3097                                            if (orderByComparator.isAscending() ^ previous) {
3098                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3099                                            }
3100                                            else {
3101                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3102                                            }
3103                                    }
3104                                    else {
3105                                            if (orderByComparator.isAscending() ^ previous) {
3106                                                    query.append(ORDER_BY_ASC);
3107                                            }
3108                                            else {
3109                                                    query.append(ORDER_BY_DESC);
3110                                            }
3111                                    }
3112                            }
3113                    }
3114                    else {
3115                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3116                    }
3117    
3118                    String sql = query.toString();
3119    
3120                    Query q = session.createQuery(sql);
3121    
3122                    q.setFirstResult(0);
3123                    q.setMaxResults(2);
3124    
3125                    QueryPos qPos = QueryPos.getInstance(q);
3126    
3127                    qPos.add(threadId);
3128    
3129                    if (orderByComparator != null) {
3130                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3131    
3132                            for (Object value : values) {
3133                                    qPos.add(value);
3134                            }
3135                    }
3136    
3137                    List<MBMessage> list = q.list();
3138    
3139                    if (list.size() == 2) {
3140                            return list.get(1);
3141                    }
3142                    else {
3143                            return null;
3144                    }
3145            }
3146    
3147            /**
3148             * Removes all the message-boards messages where threadId = &#63; from the database.
3149             *
3150             * @param threadId the thread ID
3151             * @throws SystemException if a system exception occurred
3152             */
3153            public void removeByThreadId(long threadId) throws SystemException {
3154                    for (MBMessage mbMessage : findByThreadId(threadId, QueryUtil.ALL_POS,
3155                                    QueryUtil.ALL_POS, null)) {
3156                            remove(mbMessage);
3157                    }
3158            }
3159    
3160            /**
3161             * Returns the number of message-boards messages where threadId = &#63;.
3162             *
3163             * @param threadId the thread ID
3164             * @return the number of matching message-boards messages
3165             * @throws SystemException if a system exception occurred
3166             */
3167            public int countByThreadId(long threadId) throws SystemException {
3168                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADID;
3169    
3170                    Object[] finderArgs = new Object[] { threadId };
3171    
3172                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3173                                    this);
3174    
3175                    if (count == null) {
3176                            StringBundler query = new StringBundler(2);
3177    
3178                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3179    
3180                            query.append(_FINDER_COLUMN_THREADID_THREADID_2);
3181    
3182                            String sql = query.toString();
3183    
3184                            Session session = null;
3185    
3186                            try {
3187                                    session = openSession();
3188    
3189                                    Query q = session.createQuery(sql);
3190    
3191                                    QueryPos qPos = QueryPos.getInstance(q);
3192    
3193                                    qPos.add(threadId);
3194    
3195                                    count = (Long)q.uniqueResult();
3196    
3197                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3198                            }
3199                            catch (Exception e) {
3200                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3201    
3202                                    throw processException(e);
3203                            }
3204                            finally {
3205                                    closeSession(session);
3206                            }
3207                    }
3208    
3209                    return count.intValue();
3210            }
3211    
3212            private static final String _FINDER_COLUMN_THREADID_THREADID_2 = "mbMessage.threadId = ?";
3213            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES =
3214                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3215                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3216                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByThreadReplies",
3217                            new String[] {
3218                                    Long.class.getName(),
3219                                    
3220                            Integer.class.getName(), Integer.class.getName(),
3221                                    OrderByComparator.class.getName()
3222                            });
3223            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES =
3224                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3225                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3226                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByThreadReplies",
3227                            new String[] { Long.class.getName() },
3228                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
3229                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3230            public static final FinderPath FINDER_PATH_COUNT_BY_THREADREPLIES = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3231                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3232                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByThreadReplies",
3233                            new String[] { Long.class.getName() });
3234    
3235            /**
3236             * Returns all the message-boards messages where threadId = &#63;.
3237             *
3238             * @param threadId the thread ID
3239             * @return the matching message-boards messages
3240             * @throws SystemException if a system exception occurred
3241             */
3242            public List<MBMessage> findByThreadReplies(long threadId)
3243                    throws SystemException {
3244                    return findByThreadReplies(threadId, QueryUtil.ALL_POS,
3245                            QueryUtil.ALL_POS, null);
3246            }
3247    
3248            /**
3249             * Returns a range of all the message-boards messages where threadId = &#63;.
3250             *
3251             * <p>
3252             * 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.
3253             * </p>
3254             *
3255             * @param threadId the thread ID
3256             * @param start the lower bound of the range of message-boards messages
3257             * @param end the upper bound of the range of message-boards messages (not inclusive)
3258             * @return the range of matching message-boards messages
3259             * @throws SystemException if a system exception occurred
3260             */
3261            public List<MBMessage> findByThreadReplies(long threadId, int start, int end)
3262                    throws SystemException {
3263                    return findByThreadReplies(threadId, start, end, null);
3264            }
3265    
3266            /**
3267             * Returns an ordered range of all the message-boards messages where threadId = &#63;.
3268             *
3269             * <p>
3270             * 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.
3271             * </p>
3272             *
3273             * @param threadId the thread ID
3274             * @param start the lower bound of the range of message-boards messages
3275             * @param end the upper bound of the range of message-boards messages (not inclusive)
3276             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3277             * @return the ordered range of matching message-boards messages
3278             * @throws SystemException if a system exception occurred
3279             */
3280            public List<MBMessage> findByThreadReplies(long threadId, int start,
3281                    int end, OrderByComparator orderByComparator) throws SystemException {
3282                    boolean pagination = true;
3283                    FinderPath finderPath = null;
3284                    Object[] finderArgs = null;
3285    
3286                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3287                                    (orderByComparator == null)) {
3288                            pagination = false;
3289                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES;
3290                            finderArgs = new Object[] { threadId };
3291                    }
3292                    else {
3293                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_THREADREPLIES;
3294                            finderArgs = new Object[] { threadId, start, end, orderByComparator };
3295                    }
3296    
3297                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3298                                    finderArgs, this);
3299    
3300                    if ((list != null) && !list.isEmpty()) {
3301                            for (MBMessage mbMessage : list) {
3302                                    if ((threadId != mbMessage.getThreadId())) {
3303                                            list = null;
3304    
3305                                            break;
3306                                    }
3307                            }
3308                    }
3309    
3310                    if (list == null) {
3311                            StringBundler query = null;
3312    
3313                            if (orderByComparator != null) {
3314                                    query = new StringBundler(3 +
3315                                                    (orderByComparator.getOrderByFields().length * 3));
3316                            }
3317                            else {
3318                                    query = new StringBundler(3);
3319                            }
3320    
3321                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3322    
3323                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3324    
3325                            if (orderByComparator != null) {
3326                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3327                                            orderByComparator);
3328                            }
3329                            else
3330                             if (pagination) {
3331                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3332                            }
3333    
3334                            String sql = query.toString();
3335    
3336                            Session session = null;
3337    
3338                            try {
3339                                    session = openSession();
3340    
3341                                    Query q = session.createQuery(sql);
3342    
3343                                    QueryPos qPos = QueryPos.getInstance(q);
3344    
3345                                    qPos.add(threadId);
3346    
3347                                    if (!pagination) {
3348                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3349                                                            start, end, false);
3350    
3351                                            Collections.sort(list);
3352    
3353                                            list = new UnmodifiableList<MBMessage>(list);
3354                                    }
3355                                    else {
3356                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3357                                                            start, end);
3358                                    }
3359    
3360                                    cacheResult(list);
3361    
3362                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3363                            }
3364                            catch (Exception e) {
3365                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3366    
3367                                    throw processException(e);
3368                            }
3369                            finally {
3370                                    closeSession(session);
3371                            }
3372                    }
3373    
3374                    return list;
3375            }
3376    
3377            /**
3378             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3379             *
3380             * @param threadId the thread ID
3381             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3382             * @return the first matching message-boards message
3383             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3384             * @throws SystemException if a system exception occurred
3385             */
3386            public MBMessage findByThreadReplies_First(long threadId,
3387                    OrderByComparator orderByComparator)
3388                    throws NoSuchMessageException, SystemException {
3389                    MBMessage mbMessage = fetchByThreadReplies_First(threadId,
3390                                    orderByComparator);
3391    
3392                    if (mbMessage != null) {
3393                            return mbMessage;
3394                    }
3395    
3396                    StringBundler msg = new StringBundler(4);
3397    
3398                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3399    
3400                    msg.append("threadId=");
3401                    msg.append(threadId);
3402    
3403                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3404    
3405                    throw new NoSuchMessageException(msg.toString());
3406            }
3407    
3408            /**
3409             * Returns the first message-boards message in the ordered set where threadId = &#63;.
3410             *
3411             * @param threadId the thread ID
3412             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3413             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3414             * @throws SystemException if a system exception occurred
3415             */
3416            public MBMessage fetchByThreadReplies_First(long threadId,
3417                    OrderByComparator orderByComparator) throws SystemException {
3418                    List<MBMessage> list = findByThreadReplies(threadId, 0, 1,
3419                                    orderByComparator);
3420    
3421                    if (!list.isEmpty()) {
3422                            return list.get(0);
3423                    }
3424    
3425                    return null;
3426            }
3427    
3428            /**
3429             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3430             *
3431             * @param threadId the thread ID
3432             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3433             * @return the last matching message-boards message
3434             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3435             * @throws SystemException if a system exception occurred
3436             */
3437            public MBMessage findByThreadReplies_Last(long threadId,
3438                    OrderByComparator orderByComparator)
3439                    throws NoSuchMessageException, SystemException {
3440                    MBMessage mbMessage = fetchByThreadReplies_Last(threadId,
3441                                    orderByComparator);
3442    
3443                    if (mbMessage != null) {
3444                            return mbMessage;
3445                    }
3446    
3447                    StringBundler msg = new StringBundler(4);
3448    
3449                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3450    
3451                    msg.append("threadId=");
3452                    msg.append(threadId);
3453    
3454                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3455    
3456                    throw new NoSuchMessageException(msg.toString());
3457            }
3458    
3459            /**
3460             * Returns the last message-boards message in the ordered set where threadId = &#63;.
3461             *
3462             * @param threadId the thread ID
3463             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3464             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3465             * @throws SystemException if a system exception occurred
3466             */
3467            public MBMessage fetchByThreadReplies_Last(long threadId,
3468                    OrderByComparator orderByComparator) throws SystemException {
3469                    int count = countByThreadReplies(threadId);
3470    
3471                    List<MBMessage> list = findByThreadReplies(threadId, count - 1, count,
3472                                    orderByComparator);
3473    
3474                    if (!list.isEmpty()) {
3475                            return list.get(0);
3476                    }
3477    
3478                    return null;
3479            }
3480    
3481            /**
3482             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63;.
3483             *
3484             * @param messageId the primary key of the current message-boards message
3485             * @param threadId the thread ID
3486             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3487             * @return the previous, current, and next message-boards message
3488             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3489             * @throws SystemException if a system exception occurred
3490             */
3491            public MBMessage[] findByThreadReplies_PrevAndNext(long messageId,
3492                    long threadId, OrderByComparator orderByComparator)
3493                    throws NoSuchMessageException, SystemException {
3494                    MBMessage mbMessage = findByPrimaryKey(messageId);
3495    
3496                    Session session = null;
3497    
3498                    try {
3499                            session = openSession();
3500    
3501                            MBMessage[] array = new MBMessageImpl[3];
3502    
3503                            array[0] = getByThreadReplies_PrevAndNext(session, mbMessage,
3504                                            threadId, orderByComparator, true);
3505    
3506                            array[1] = mbMessage;
3507    
3508                            array[2] = getByThreadReplies_PrevAndNext(session, mbMessage,
3509                                            threadId, orderByComparator, false);
3510    
3511                            return array;
3512                    }
3513                    catch (Exception e) {
3514                            throw processException(e);
3515                    }
3516                    finally {
3517                            closeSession(session);
3518                    }
3519            }
3520    
3521            protected MBMessage getByThreadReplies_PrevAndNext(Session session,
3522                    MBMessage mbMessage, long threadId,
3523                    OrderByComparator orderByComparator, boolean previous) {
3524                    StringBundler query = null;
3525    
3526                    if (orderByComparator != null) {
3527                            query = new StringBundler(6 +
3528                                            (orderByComparator.getOrderByFields().length * 6));
3529                    }
3530                    else {
3531                            query = new StringBundler(3);
3532                    }
3533    
3534                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3535    
3536                    query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3537    
3538                    if (orderByComparator != null) {
3539                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
3540    
3541                            if (orderByConditionFields.length > 0) {
3542                                    query.append(WHERE_AND);
3543                            }
3544    
3545                            for (int i = 0; i < orderByConditionFields.length; i++) {
3546                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3547                                    query.append(orderByConditionFields[i]);
3548    
3549                                    if ((i + 1) < orderByConditionFields.length) {
3550                                            if (orderByComparator.isAscending() ^ previous) {
3551                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
3552                                            }
3553                                            else {
3554                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
3555                                            }
3556                                    }
3557                                    else {
3558                                            if (orderByComparator.isAscending() ^ previous) {
3559                                                    query.append(WHERE_GREATER_THAN);
3560                                            }
3561                                            else {
3562                                                    query.append(WHERE_LESSER_THAN);
3563                                            }
3564                                    }
3565                            }
3566    
3567                            query.append(ORDER_BY_CLAUSE);
3568    
3569                            String[] orderByFields = orderByComparator.getOrderByFields();
3570    
3571                            for (int i = 0; i < orderByFields.length; i++) {
3572                                    query.append(_ORDER_BY_ENTITY_ALIAS);
3573                                    query.append(orderByFields[i]);
3574    
3575                                    if ((i + 1) < orderByFields.length) {
3576                                            if (orderByComparator.isAscending() ^ previous) {
3577                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
3578                                            }
3579                                            else {
3580                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
3581                                            }
3582                                    }
3583                                    else {
3584                                            if (orderByComparator.isAscending() ^ previous) {
3585                                                    query.append(ORDER_BY_ASC);
3586                                            }
3587                                            else {
3588                                                    query.append(ORDER_BY_DESC);
3589                                            }
3590                                    }
3591                            }
3592                    }
3593                    else {
3594                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3595                    }
3596    
3597                    String sql = query.toString();
3598    
3599                    Query q = session.createQuery(sql);
3600    
3601                    q.setFirstResult(0);
3602                    q.setMaxResults(2);
3603    
3604                    QueryPos qPos = QueryPos.getInstance(q);
3605    
3606                    qPos.add(threadId);
3607    
3608                    if (orderByComparator != null) {
3609                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
3610    
3611                            for (Object value : values) {
3612                                    qPos.add(value);
3613                            }
3614                    }
3615    
3616                    List<MBMessage> list = q.list();
3617    
3618                    if (list.size() == 2) {
3619                            return list.get(1);
3620                    }
3621                    else {
3622                            return null;
3623                    }
3624            }
3625    
3626            /**
3627             * Removes all the message-boards messages where threadId = &#63; from the database.
3628             *
3629             * @param threadId the thread ID
3630             * @throws SystemException if a system exception occurred
3631             */
3632            public void removeByThreadReplies(long threadId) throws SystemException {
3633                    for (MBMessage mbMessage : findByThreadReplies(threadId,
3634                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
3635                            remove(mbMessage);
3636                    }
3637            }
3638    
3639            /**
3640             * Returns the number of message-boards messages where threadId = &#63;.
3641             *
3642             * @param threadId the thread ID
3643             * @return the number of matching message-boards messages
3644             * @throws SystemException if a system exception occurred
3645             */
3646            public int countByThreadReplies(long threadId) throws SystemException {
3647                    FinderPath finderPath = FINDER_PATH_COUNT_BY_THREADREPLIES;
3648    
3649                    Object[] finderArgs = new Object[] { threadId };
3650    
3651                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
3652                                    this);
3653    
3654                    if (count == null) {
3655                            StringBundler query = new StringBundler(2);
3656    
3657                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
3658    
3659                            query.append(_FINDER_COLUMN_THREADREPLIES_THREADID_2);
3660    
3661                            String sql = query.toString();
3662    
3663                            Session session = null;
3664    
3665                            try {
3666                                    session = openSession();
3667    
3668                                    Query q = session.createQuery(sql);
3669    
3670                                    QueryPos qPos = QueryPos.getInstance(q);
3671    
3672                                    qPos.add(threadId);
3673    
3674                                    count = (Long)q.uniqueResult();
3675    
3676                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
3677                            }
3678                            catch (Exception e) {
3679                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3680    
3681                                    throw processException(e);
3682                            }
3683                            finally {
3684                                    closeSession(session);
3685                            }
3686                    }
3687    
3688                    return count.intValue();
3689            }
3690    
3691            private static final String _FINDER_COLUMN_THREADREPLIES_THREADID_2 = "mbMessage.threadId = ? AND mbMessage.parentMessageId != 0";
3692            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3693                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3694                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByUserId",
3695                            new String[] {
3696                                    Long.class.getName(),
3697                                    
3698                            Integer.class.getName(), Integer.class.getName(),
3699                                    OrderByComparator.class.getName()
3700                            });
3701            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID =
3702                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3703                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
3704                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByUserId",
3705                            new String[] { Long.class.getName() },
3706                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
3707                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
3708            public static final FinderPath FINDER_PATH_COUNT_BY_USERID = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
3709                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
3710                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByUserId",
3711                            new String[] { Long.class.getName() });
3712    
3713            /**
3714             * Returns all the message-boards messages where userId = &#63;.
3715             *
3716             * @param userId the user ID
3717             * @return the matching message-boards messages
3718             * @throws SystemException if a system exception occurred
3719             */
3720            public List<MBMessage> findByUserId(long userId) throws SystemException {
3721                    return findByUserId(userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
3722            }
3723    
3724            /**
3725             * Returns a range of all the message-boards messages where userId = &#63;.
3726             *
3727             * <p>
3728             * 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.
3729             * </p>
3730             *
3731             * @param userId the user ID
3732             * @param start the lower bound of the range of message-boards messages
3733             * @param end the upper bound of the range of message-boards messages (not inclusive)
3734             * @return the range of matching message-boards messages
3735             * @throws SystemException if a system exception occurred
3736             */
3737            public List<MBMessage> findByUserId(long userId, int start, int end)
3738                    throws SystemException {
3739                    return findByUserId(userId, start, end, null);
3740            }
3741    
3742            /**
3743             * Returns an ordered range of all the message-boards messages where userId = &#63;.
3744             *
3745             * <p>
3746             * 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.
3747             * </p>
3748             *
3749             * @param userId the user ID
3750             * @param start the lower bound of the range of message-boards messages
3751             * @param end the upper bound of the range of message-boards messages (not inclusive)
3752             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
3753             * @return the ordered range of matching message-boards messages
3754             * @throws SystemException if a system exception occurred
3755             */
3756            public List<MBMessage> findByUserId(long userId, int start, int end,
3757                    OrderByComparator orderByComparator) throws SystemException {
3758                    boolean pagination = true;
3759                    FinderPath finderPath = null;
3760                    Object[] finderArgs = null;
3761    
3762                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
3763                                    (orderByComparator == null)) {
3764                            pagination = false;
3765                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID;
3766                            finderArgs = new Object[] { userId };
3767                    }
3768                    else {
3769                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_USERID;
3770                            finderArgs = new Object[] { userId, start, end, orderByComparator };
3771                    }
3772    
3773                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
3774                                    finderArgs, this);
3775    
3776                    if ((list != null) && !list.isEmpty()) {
3777                            for (MBMessage mbMessage : list) {
3778                                    if ((userId != mbMessage.getUserId())) {
3779                                            list = null;
3780    
3781                                            break;
3782                                    }
3783                            }
3784                    }
3785    
3786                    if (list == null) {
3787                            StringBundler query = null;
3788    
3789                            if (orderByComparator != null) {
3790                                    query = new StringBundler(3 +
3791                                                    (orderByComparator.getOrderByFields().length * 3));
3792                            }
3793                            else {
3794                                    query = new StringBundler(3);
3795                            }
3796    
3797                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
3798    
3799                            query.append(_FINDER_COLUMN_USERID_USERID_2);
3800    
3801                            if (orderByComparator != null) {
3802                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
3803                                            orderByComparator);
3804                            }
3805                            else
3806                             if (pagination) {
3807                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
3808                            }
3809    
3810                            String sql = query.toString();
3811    
3812                            Session session = null;
3813    
3814                            try {
3815                                    session = openSession();
3816    
3817                                    Query q = session.createQuery(sql);
3818    
3819                                    QueryPos qPos = QueryPos.getInstance(q);
3820    
3821                                    qPos.add(userId);
3822    
3823                                    if (!pagination) {
3824                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3825                                                            start, end, false);
3826    
3827                                            Collections.sort(list);
3828    
3829                                            list = new UnmodifiableList<MBMessage>(list);
3830                                    }
3831                                    else {
3832                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
3833                                                            start, end);
3834                                    }
3835    
3836                                    cacheResult(list);
3837    
3838                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
3839                            }
3840                            catch (Exception e) {
3841                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
3842    
3843                                    throw processException(e);
3844                            }
3845                            finally {
3846                                    closeSession(session);
3847                            }
3848                    }
3849    
3850                    return list;
3851            }
3852    
3853            /**
3854             * Returns the first message-boards message in the ordered set where userId = &#63;.
3855             *
3856             * @param userId the user ID
3857             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3858             * @return the first matching message-boards message
3859             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3860             * @throws SystemException if a system exception occurred
3861             */
3862            public MBMessage findByUserId_First(long userId,
3863                    OrderByComparator orderByComparator)
3864                    throws NoSuchMessageException, SystemException {
3865                    MBMessage mbMessage = fetchByUserId_First(userId, orderByComparator);
3866    
3867                    if (mbMessage != null) {
3868                            return mbMessage;
3869                    }
3870    
3871                    StringBundler msg = new StringBundler(4);
3872    
3873                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3874    
3875                    msg.append("userId=");
3876                    msg.append(userId);
3877    
3878                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3879    
3880                    throw new NoSuchMessageException(msg.toString());
3881            }
3882    
3883            /**
3884             * Returns the first message-boards message in the ordered set where userId = &#63;.
3885             *
3886             * @param userId the user ID
3887             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3888             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3889             * @throws SystemException if a system exception occurred
3890             */
3891            public MBMessage fetchByUserId_First(long userId,
3892                    OrderByComparator orderByComparator) throws SystemException {
3893                    List<MBMessage> list = findByUserId(userId, 0, 1, orderByComparator);
3894    
3895                    if (!list.isEmpty()) {
3896                            return list.get(0);
3897                    }
3898    
3899                    return null;
3900            }
3901    
3902            /**
3903             * Returns the last message-boards message in the ordered set where userId = &#63;.
3904             *
3905             * @param userId the user ID
3906             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3907             * @return the last matching message-boards message
3908             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
3909             * @throws SystemException if a system exception occurred
3910             */
3911            public MBMessage findByUserId_Last(long userId,
3912                    OrderByComparator orderByComparator)
3913                    throws NoSuchMessageException, SystemException {
3914                    MBMessage mbMessage = fetchByUserId_Last(userId, orderByComparator);
3915    
3916                    if (mbMessage != null) {
3917                            return mbMessage;
3918                    }
3919    
3920                    StringBundler msg = new StringBundler(4);
3921    
3922                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
3923    
3924                    msg.append("userId=");
3925                    msg.append(userId);
3926    
3927                    msg.append(StringPool.CLOSE_CURLY_BRACE);
3928    
3929                    throw new NoSuchMessageException(msg.toString());
3930            }
3931    
3932            /**
3933             * Returns the last message-boards message in the ordered set where userId = &#63;.
3934             *
3935             * @param userId the user ID
3936             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3937             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
3938             * @throws SystemException if a system exception occurred
3939             */
3940            public MBMessage fetchByUserId_Last(long userId,
3941                    OrderByComparator orderByComparator) throws SystemException {
3942                    int count = countByUserId(userId);
3943    
3944                    List<MBMessage> list = findByUserId(userId, count - 1, count,
3945                                    orderByComparator);
3946    
3947                    if (!list.isEmpty()) {
3948                            return list.get(0);
3949                    }
3950    
3951                    return null;
3952            }
3953    
3954            /**
3955             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63;.
3956             *
3957             * @param messageId the primary key of the current message-boards message
3958             * @param userId the user ID
3959             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
3960             * @return the previous, current, and next message-boards message
3961             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
3962             * @throws SystemException if a system exception occurred
3963             */
3964            public MBMessage[] findByUserId_PrevAndNext(long messageId, long userId,
3965                    OrderByComparator orderByComparator)
3966                    throws NoSuchMessageException, SystemException {
3967                    MBMessage mbMessage = findByPrimaryKey(messageId);
3968    
3969                    Session session = null;
3970    
3971                    try {
3972                            session = openSession();
3973    
3974                            MBMessage[] array = new MBMessageImpl[3];
3975    
3976                            array[0] = getByUserId_PrevAndNext(session, mbMessage, userId,
3977                                            orderByComparator, true);
3978    
3979                            array[1] = mbMessage;
3980    
3981                            array[2] = getByUserId_PrevAndNext(session, mbMessage, userId,
3982                                            orderByComparator, false);
3983    
3984                            return array;
3985                    }
3986                    catch (Exception e) {
3987                            throw processException(e);
3988                    }
3989                    finally {
3990                            closeSession(session);
3991                    }
3992            }
3993    
3994            protected MBMessage getByUserId_PrevAndNext(Session session,
3995                    MBMessage mbMessage, long userId, OrderByComparator orderByComparator,
3996                    boolean previous) {
3997                    StringBundler query = null;
3998    
3999                    if (orderByComparator != null) {
4000                            query = new StringBundler(6 +
4001                                            (orderByComparator.getOrderByFields().length * 6));
4002                    }
4003                    else {
4004                            query = new StringBundler(3);
4005                    }
4006    
4007                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4008    
4009                    query.append(_FINDER_COLUMN_USERID_USERID_2);
4010    
4011                    if (orderByComparator != null) {
4012                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4013    
4014                            if (orderByConditionFields.length > 0) {
4015                                    query.append(WHERE_AND);
4016                            }
4017    
4018                            for (int i = 0; i < orderByConditionFields.length; i++) {
4019                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4020                                    query.append(orderByConditionFields[i]);
4021    
4022                                    if ((i + 1) < orderByConditionFields.length) {
4023                                            if (orderByComparator.isAscending() ^ previous) {
4024                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4025                                            }
4026                                            else {
4027                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4028                                            }
4029                                    }
4030                                    else {
4031                                            if (orderByComparator.isAscending() ^ previous) {
4032                                                    query.append(WHERE_GREATER_THAN);
4033                                            }
4034                                            else {
4035                                                    query.append(WHERE_LESSER_THAN);
4036                                            }
4037                                    }
4038                            }
4039    
4040                            query.append(ORDER_BY_CLAUSE);
4041    
4042                            String[] orderByFields = orderByComparator.getOrderByFields();
4043    
4044                            for (int i = 0; i < orderByFields.length; i++) {
4045                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4046                                    query.append(orderByFields[i]);
4047    
4048                                    if ((i + 1) < orderByFields.length) {
4049                                            if (orderByComparator.isAscending() ^ previous) {
4050                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4051                                            }
4052                                            else {
4053                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4054                                            }
4055                                    }
4056                                    else {
4057                                            if (orderByComparator.isAscending() ^ previous) {
4058                                                    query.append(ORDER_BY_ASC);
4059                                            }
4060                                            else {
4061                                                    query.append(ORDER_BY_DESC);
4062                                            }
4063                                    }
4064                            }
4065                    }
4066                    else {
4067                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4068                    }
4069    
4070                    String sql = query.toString();
4071    
4072                    Query q = session.createQuery(sql);
4073    
4074                    q.setFirstResult(0);
4075                    q.setMaxResults(2);
4076    
4077                    QueryPos qPos = QueryPos.getInstance(q);
4078    
4079                    qPos.add(userId);
4080    
4081                    if (orderByComparator != null) {
4082                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4083    
4084                            for (Object value : values) {
4085                                    qPos.add(value);
4086                            }
4087                    }
4088    
4089                    List<MBMessage> list = q.list();
4090    
4091                    if (list.size() == 2) {
4092                            return list.get(1);
4093                    }
4094                    else {
4095                            return null;
4096                    }
4097            }
4098    
4099            /**
4100             * Removes all the message-boards messages where userId = &#63; from the database.
4101             *
4102             * @param userId the user ID
4103             * @throws SystemException if a system exception occurred
4104             */
4105            public void removeByUserId(long userId) throws SystemException {
4106                    for (MBMessage mbMessage : findByUserId(userId, QueryUtil.ALL_POS,
4107                                    QueryUtil.ALL_POS, null)) {
4108                            remove(mbMessage);
4109                    }
4110            }
4111    
4112            /**
4113             * Returns the number of message-boards messages where userId = &#63;.
4114             *
4115             * @param userId the user ID
4116             * @return the number of matching message-boards messages
4117             * @throws SystemException if a system exception occurred
4118             */
4119            public int countByUserId(long userId) throws SystemException {
4120                    FinderPath finderPath = FINDER_PATH_COUNT_BY_USERID;
4121    
4122                    Object[] finderArgs = new Object[] { userId };
4123    
4124                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4125                                    this);
4126    
4127                    if (count == null) {
4128                            StringBundler query = new StringBundler(2);
4129    
4130                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4131    
4132                            query.append(_FINDER_COLUMN_USERID_USERID_2);
4133    
4134                            String sql = query.toString();
4135    
4136                            Session session = null;
4137    
4138                            try {
4139                                    session = openSession();
4140    
4141                                    Query q = session.createQuery(sql);
4142    
4143                                    QueryPos qPos = QueryPos.getInstance(q);
4144    
4145                                    qPos.add(userId);
4146    
4147                                    count = (Long)q.uniqueResult();
4148    
4149                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4150                            }
4151                            catch (Exception e) {
4152                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4153    
4154                                    throw processException(e);
4155                            }
4156                            finally {
4157                                    closeSession(session);
4158                            }
4159                    }
4160    
4161                    return count.intValue();
4162            }
4163    
4164            private static final String _FINDER_COLUMN_USERID_USERID_2 = "mbMessage.userId = ? AND mbMessage.categoryId != -1";
4165            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4166                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4167                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U",
4168                            new String[] {
4169                                    Long.class.getName(), Long.class.getName(),
4170                                    
4171                            Integer.class.getName(), Integer.class.getName(),
4172                                    OrderByComparator.class.getName()
4173                            });
4174            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4175                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
4176                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U",
4177                            new String[] { Long.class.getName(), Long.class.getName() },
4178                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
4179                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
4180                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
4181            public static final FinderPath FINDER_PATH_COUNT_BY_G_U = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
4182                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
4183                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U",
4184                            new String[] { Long.class.getName(), Long.class.getName() });
4185    
4186            /**
4187             * Returns all the message-boards messages where groupId = &#63; and userId = &#63;.
4188             *
4189             * @param groupId the group ID
4190             * @param userId the user ID
4191             * @return the matching message-boards messages
4192             * @throws SystemException if a system exception occurred
4193             */
4194            public List<MBMessage> findByG_U(long groupId, long userId)
4195                    throws SystemException {
4196                    return findByG_U(groupId, userId, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
4197                            null);
4198            }
4199    
4200            /**
4201             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4202             *
4203             * <p>
4204             * 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.
4205             * </p>
4206             *
4207             * @param groupId the group ID
4208             * @param userId the user ID
4209             * @param start the lower bound of the range of message-boards messages
4210             * @param end the upper bound of the range of message-boards messages (not inclusive)
4211             * @return the range of matching message-boards messages
4212             * @throws SystemException if a system exception occurred
4213             */
4214            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4215                    int end) throws SystemException {
4216                    return findByG_U(groupId, userId, start, end, null);
4217            }
4218    
4219            /**
4220             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63;.
4221             *
4222             * <p>
4223             * 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.
4224             * </p>
4225             *
4226             * @param groupId the group ID
4227             * @param userId the user ID
4228             * @param start the lower bound of the range of message-boards messages
4229             * @param end the upper bound of the range of message-boards messages (not inclusive)
4230             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4231             * @return the ordered range of matching message-boards messages
4232             * @throws SystemException if a system exception occurred
4233             */
4234            public List<MBMessage> findByG_U(long groupId, long userId, int start,
4235                    int end, OrderByComparator orderByComparator) throws SystemException {
4236                    boolean pagination = true;
4237                    FinderPath finderPath = null;
4238                    Object[] finderArgs = null;
4239    
4240                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
4241                                    (orderByComparator == null)) {
4242                            pagination = false;
4243                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U;
4244                            finderArgs = new Object[] { groupId, userId };
4245                    }
4246                    else {
4247                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U;
4248                            finderArgs = new Object[] {
4249                                            groupId, userId,
4250                                            
4251                                            start, end, orderByComparator
4252                                    };
4253                    }
4254    
4255                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
4256                                    finderArgs, this);
4257    
4258                    if ((list != null) && !list.isEmpty()) {
4259                            for (MBMessage mbMessage : list) {
4260                                    if ((groupId != mbMessage.getGroupId()) ||
4261                                                    (userId != mbMessage.getUserId())) {
4262                                            list = null;
4263    
4264                                            break;
4265                                    }
4266                            }
4267                    }
4268    
4269                    if (list == null) {
4270                            StringBundler query = null;
4271    
4272                            if (orderByComparator != null) {
4273                                    query = new StringBundler(4 +
4274                                                    (orderByComparator.getOrderByFields().length * 3));
4275                            }
4276                            else {
4277                                    query = new StringBundler(4);
4278                            }
4279    
4280                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4281    
4282                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4283    
4284                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4285    
4286                            if (orderByComparator != null) {
4287                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4288                                            orderByComparator);
4289                            }
4290                            else
4291                             if (pagination) {
4292                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4293                            }
4294    
4295                            String sql = query.toString();
4296    
4297                            Session session = null;
4298    
4299                            try {
4300                                    session = openSession();
4301    
4302                                    Query q = session.createQuery(sql);
4303    
4304                                    QueryPos qPos = QueryPos.getInstance(q);
4305    
4306                                    qPos.add(groupId);
4307    
4308                                    qPos.add(userId);
4309    
4310                                    if (!pagination) {
4311                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4312                                                            start, end, false);
4313    
4314                                            Collections.sort(list);
4315    
4316                                            list = new UnmodifiableList<MBMessage>(list);
4317                                    }
4318                                    else {
4319                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
4320                                                            start, end);
4321                                    }
4322    
4323                                    cacheResult(list);
4324    
4325                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
4326                            }
4327                            catch (Exception e) {
4328                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4329    
4330                                    throw processException(e);
4331                            }
4332                            finally {
4333                                    closeSession(session);
4334                            }
4335                    }
4336    
4337                    return list;
4338            }
4339    
4340            /**
4341             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4342             *
4343             * @param groupId the group ID
4344             * @param userId the user ID
4345             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4346             * @return the first matching message-boards message
4347             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4348             * @throws SystemException if a system exception occurred
4349             */
4350            public MBMessage findByG_U_First(long groupId, long userId,
4351                    OrderByComparator orderByComparator)
4352                    throws NoSuchMessageException, SystemException {
4353                    MBMessage mbMessage = fetchByG_U_First(groupId, userId,
4354                                    orderByComparator);
4355    
4356                    if (mbMessage != null) {
4357                            return mbMessage;
4358                    }
4359    
4360                    StringBundler msg = new StringBundler(6);
4361    
4362                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4363    
4364                    msg.append("groupId=");
4365                    msg.append(groupId);
4366    
4367                    msg.append(", userId=");
4368                    msg.append(userId);
4369    
4370                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4371    
4372                    throw new NoSuchMessageException(msg.toString());
4373            }
4374    
4375            /**
4376             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4377             *
4378             * @param groupId the group ID
4379             * @param userId the user ID
4380             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4381             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4382             * @throws SystemException if a system exception occurred
4383             */
4384            public MBMessage fetchByG_U_First(long groupId, long userId,
4385                    OrderByComparator orderByComparator) throws SystemException {
4386                    List<MBMessage> list = findByG_U(groupId, userId, 0, 1,
4387                                    orderByComparator);
4388    
4389                    if (!list.isEmpty()) {
4390                            return list.get(0);
4391                    }
4392    
4393                    return null;
4394            }
4395    
4396            /**
4397             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4398             *
4399             * @param groupId the group ID
4400             * @param userId the user ID
4401             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4402             * @return the last matching message-boards message
4403             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
4404             * @throws SystemException if a system exception occurred
4405             */
4406            public MBMessage findByG_U_Last(long groupId, long userId,
4407                    OrderByComparator orderByComparator)
4408                    throws NoSuchMessageException, SystemException {
4409                    MBMessage mbMessage = fetchByG_U_Last(groupId, userId, orderByComparator);
4410    
4411                    if (mbMessage != null) {
4412                            return mbMessage;
4413                    }
4414    
4415                    StringBundler msg = new StringBundler(6);
4416    
4417                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
4418    
4419                    msg.append("groupId=");
4420                    msg.append(groupId);
4421    
4422                    msg.append(", userId=");
4423                    msg.append(userId);
4424    
4425                    msg.append(StringPool.CLOSE_CURLY_BRACE);
4426    
4427                    throw new NoSuchMessageException(msg.toString());
4428            }
4429    
4430            /**
4431             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4432             *
4433             * @param groupId the group ID
4434             * @param userId the user ID
4435             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4436             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
4437             * @throws SystemException if a system exception occurred
4438             */
4439            public MBMessage fetchByG_U_Last(long groupId, long userId,
4440                    OrderByComparator orderByComparator) throws SystemException {
4441                    int count = countByG_U(groupId, userId);
4442    
4443                    List<MBMessage> list = findByG_U(groupId, userId, count - 1, count,
4444                                    orderByComparator);
4445    
4446                    if (!list.isEmpty()) {
4447                            return list.get(0);
4448                    }
4449    
4450                    return null;
4451            }
4452    
4453            /**
4454             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63;.
4455             *
4456             * @param messageId the primary key of the current message-boards message
4457             * @param groupId the group ID
4458             * @param userId the user ID
4459             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4460             * @return the previous, current, and next message-boards message
4461             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4462             * @throws SystemException if a system exception occurred
4463             */
4464            public MBMessage[] findByG_U_PrevAndNext(long messageId, long groupId,
4465                    long userId, OrderByComparator orderByComparator)
4466                    throws NoSuchMessageException, SystemException {
4467                    MBMessage mbMessage = findByPrimaryKey(messageId);
4468    
4469                    Session session = null;
4470    
4471                    try {
4472                            session = openSession();
4473    
4474                            MBMessage[] array = new MBMessageImpl[3];
4475    
4476                            array[0] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4477                                            userId, orderByComparator, true);
4478    
4479                            array[1] = mbMessage;
4480    
4481                            array[2] = getByG_U_PrevAndNext(session, mbMessage, groupId,
4482                                            userId, orderByComparator, false);
4483    
4484                            return array;
4485                    }
4486                    catch (Exception e) {
4487                            throw processException(e);
4488                    }
4489                    finally {
4490                            closeSession(session);
4491                    }
4492            }
4493    
4494            protected MBMessage getByG_U_PrevAndNext(Session session,
4495                    MBMessage mbMessage, long groupId, long userId,
4496                    OrderByComparator orderByComparator, boolean previous) {
4497                    StringBundler query = null;
4498    
4499                    if (orderByComparator != null) {
4500                            query = new StringBundler(6 +
4501                                            (orderByComparator.getOrderByFields().length * 6));
4502                    }
4503                    else {
4504                            query = new StringBundler(3);
4505                    }
4506    
4507                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
4508    
4509                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4510    
4511                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4512    
4513                    if (orderByComparator != null) {
4514                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4515    
4516                            if (orderByConditionFields.length > 0) {
4517                                    query.append(WHERE_AND);
4518                            }
4519    
4520                            for (int i = 0; i < orderByConditionFields.length; i++) {
4521                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4522                                    query.append(orderByConditionFields[i]);
4523    
4524                                    if ((i + 1) < orderByConditionFields.length) {
4525                                            if (orderByComparator.isAscending() ^ previous) {
4526                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4527                                            }
4528                                            else {
4529                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4530                                            }
4531                                    }
4532                                    else {
4533                                            if (orderByComparator.isAscending() ^ previous) {
4534                                                    query.append(WHERE_GREATER_THAN);
4535                                            }
4536                                            else {
4537                                                    query.append(WHERE_LESSER_THAN);
4538                                            }
4539                                    }
4540                            }
4541    
4542                            query.append(ORDER_BY_CLAUSE);
4543    
4544                            String[] orderByFields = orderByComparator.getOrderByFields();
4545    
4546                            for (int i = 0; i < orderByFields.length; i++) {
4547                                    query.append(_ORDER_BY_ENTITY_ALIAS);
4548                                    query.append(orderByFields[i]);
4549    
4550                                    if ((i + 1) < orderByFields.length) {
4551                                            if (orderByComparator.isAscending() ^ previous) {
4552                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4553                                            }
4554                                            else {
4555                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4556                                            }
4557                                    }
4558                                    else {
4559                                            if (orderByComparator.isAscending() ^ previous) {
4560                                                    query.append(ORDER_BY_ASC);
4561                                            }
4562                                            else {
4563                                                    query.append(ORDER_BY_DESC);
4564                                            }
4565                                    }
4566                            }
4567                    }
4568                    else {
4569                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4570                    }
4571    
4572                    String sql = query.toString();
4573    
4574                    Query q = session.createQuery(sql);
4575    
4576                    q.setFirstResult(0);
4577                    q.setMaxResults(2);
4578    
4579                    QueryPos qPos = QueryPos.getInstance(q);
4580    
4581                    qPos.add(groupId);
4582    
4583                    qPos.add(userId);
4584    
4585                    if (orderByComparator != null) {
4586                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4587    
4588                            for (Object value : values) {
4589                                    qPos.add(value);
4590                            }
4591                    }
4592    
4593                    List<MBMessage> list = q.list();
4594    
4595                    if (list.size() == 2) {
4596                            return list.get(1);
4597                    }
4598                    else {
4599                            return null;
4600                    }
4601            }
4602    
4603            /**
4604             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4605             *
4606             * @param groupId the group ID
4607             * @param userId the user ID
4608             * @return the matching message-boards messages that the user has permission to view
4609             * @throws SystemException if a system exception occurred
4610             */
4611            public List<MBMessage> filterFindByG_U(long groupId, long userId)
4612                    throws SystemException {
4613                    return filterFindByG_U(groupId, userId, QueryUtil.ALL_POS,
4614                            QueryUtil.ALL_POS, null);
4615            }
4616    
4617            /**
4618             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
4619             *
4620             * <p>
4621             * 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.
4622             * </p>
4623             *
4624             * @param groupId the group ID
4625             * @param userId the user ID
4626             * @param start the lower bound of the range of message-boards messages
4627             * @param end the upper bound of the range of message-boards messages (not inclusive)
4628             * @return the range of matching message-boards messages that the user has permission to view
4629             * @throws SystemException if a system exception occurred
4630             */
4631            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4632                    int start, int end) throws SystemException {
4633                    return filterFindByG_U(groupId, userId, start, end, null);
4634            }
4635    
4636            /**
4637             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63;.
4638             *
4639             * <p>
4640             * 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.
4641             * </p>
4642             *
4643             * @param groupId the group ID
4644             * @param userId the user ID
4645             * @param start the lower bound of the range of message-boards messages
4646             * @param end the upper bound of the range of message-boards messages (not inclusive)
4647             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
4648             * @return the ordered range of matching message-boards messages that the user has permission to view
4649             * @throws SystemException if a system exception occurred
4650             */
4651            public List<MBMessage> filterFindByG_U(long groupId, long userId,
4652                    int start, int end, OrderByComparator orderByComparator)
4653                    throws SystemException {
4654                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4655                            return findByG_U(groupId, userId, start, end, orderByComparator);
4656                    }
4657    
4658                    StringBundler query = null;
4659    
4660                    if (orderByComparator != null) {
4661                            query = new StringBundler(4 +
4662                                            (orderByComparator.getOrderByFields().length * 3));
4663                    }
4664                    else {
4665                            query = new StringBundler(4);
4666                    }
4667    
4668                    if (getDB().isSupportsInlineDistinct()) {
4669                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4670                    }
4671                    else {
4672                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4673                    }
4674    
4675                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4676    
4677                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4678    
4679                    if (!getDB().isSupportsInlineDistinct()) {
4680                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4681                    }
4682    
4683                    if (orderByComparator != null) {
4684                            if (getDB().isSupportsInlineDistinct()) {
4685                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
4686                                            orderByComparator, true);
4687                            }
4688                            else {
4689                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
4690                                            orderByComparator, true);
4691                            }
4692                    }
4693                    else {
4694                            if (getDB().isSupportsInlineDistinct()) {
4695                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4696                            }
4697                            else {
4698                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4699                            }
4700                    }
4701    
4702                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4703                                    MBMessage.class.getName(),
4704                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4705    
4706                    Session session = null;
4707    
4708                    try {
4709                            session = openSession();
4710    
4711                            SQLQuery q = session.createSQLQuery(sql);
4712    
4713                            if (getDB().isSupportsInlineDistinct()) {
4714                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4715                            }
4716                            else {
4717                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4718                            }
4719    
4720                            QueryPos qPos = QueryPos.getInstance(q);
4721    
4722                            qPos.add(groupId);
4723    
4724                            qPos.add(userId);
4725    
4726                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
4727                    }
4728                    catch (Exception e) {
4729                            throw processException(e);
4730                    }
4731                    finally {
4732                            closeSession(session);
4733                    }
4734            }
4735    
4736            /**
4737             * 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;.
4738             *
4739             * @param messageId the primary key of the current message-boards message
4740             * @param groupId the group ID
4741             * @param userId the user ID
4742             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
4743             * @return the previous, current, and next message-boards message
4744             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
4745             * @throws SystemException if a system exception occurred
4746             */
4747            public MBMessage[] filterFindByG_U_PrevAndNext(long messageId,
4748                    long groupId, long userId, OrderByComparator orderByComparator)
4749                    throws NoSuchMessageException, SystemException {
4750                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
4751                            return findByG_U_PrevAndNext(messageId, groupId, userId,
4752                                    orderByComparator);
4753                    }
4754    
4755                    MBMessage mbMessage = findByPrimaryKey(messageId);
4756    
4757                    Session session = null;
4758    
4759                    try {
4760                            session = openSession();
4761    
4762                            MBMessage[] array = new MBMessageImpl[3];
4763    
4764                            array[0] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4765                                            userId, orderByComparator, true);
4766    
4767                            array[1] = mbMessage;
4768    
4769                            array[2] = filterGetByG_U_PrevAndNext(session, mbMessage, groupId,
4770                                            userId, orderByComparator, false);
4771    
4772                            return array;
4773                    }
4774                    catch (Exception e) {
4775                            throw processException(e);
4776                    }
4777                    finally {
4778                            closeSession(session);
4779                    }
4780            }
4781    
4782            protected MBMessage filterGetByG_U_PrevAndNext(Session session,
4783                    MBMessage mbMessage, long groupId, long userId,
4784                    OrderByComparator orderByComparator, boolean previous) {
4785                    StringBundler query = null;
4786    
4787                    if (orderByComparator != null) {
4788                            query = new StringBundler(6 +
4789                                            (orderByComparator.getOrderByFields().length * 6));
4790                    }
4791                    else {
4792                            query = new StringBundler(3);
4793                    }
4794    
4795                    if (getDB().isSupportsInlineDistinct()) {
4796                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
4797                    }
4798                    else {
4799                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
4800                    }
4801    
4802                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4803    
4804                    query.append(_FINDER_COLUMN_G_U_USERID_2);
4805    
4806                    if (!getDB().isSupportsInlineDistinct()) {
4807                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
4808                    }
4809    
4810                    if (orderByComparator != null) {
4811                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
4812    
4813                            if (orderByConditionFields.length > 0) {
4814                                    query.append(WHERE_AND);
4815                            }
4816    
4817                            for (int i = 0; i < orderByConditionFields.length; i++) {
4818                                    if (getDB().isSupportsInlineDistinct()) {
4819                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4820                                    }
4821                                    else {
4822                                            query.append(_ORDER_BY_ENTITY_TABLE);
4823                                    }
4824    
4825                                    query.append(orderByConditionFields[i]);
4826    
4827                                    if ((i + 1) < orderByConditionFields.length) {
4828                                            if (orderByComparator.isAscending() ^ previous) {
4829                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
4830                                            }
4831                                            else {
4832                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
4833                                            }
4834                                    }
4835                                    else {
4836                                            if (orderByComparator.isAscending() ^ previous) {
4837                                                    query.append(WHERE_GREATER_THAN);
4838                                            }
4839                                            else {
4840                                                    query.append(WHERE_LESSER_THAN);
4841                                            }
4842                                    }
4843                            }
4844    
4845                            query.append(ORDER_BY_CLAUSE);
4846    
4847                            String[] orderByFields = orderByComparator.getOrderByFields();
4848    
4849                            for (int i = 0; i < orderByFields.length; i++) {
4850                                    if (getDB().isSupportsInlineDistinct()) {
4851                                            query.append(_ORDER_BY_ENTITY_ALIAS);
4852                                    }
4853                                    else {
4854                                            query.append(_ORDER_BY_ENTITY_TABLE);
4855                                    }
4856    
4857                                    query.append(orderByFields[i]);
4858    
4859                                    if ((i + 1) < orderByFields.length) {
4860                                            if (orderByComparator.isAscending() ^ previous) {
4861                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
4862                                            }
4863                                            else {
4864                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
4865                                            }
4866                                    }
4867                                    else {
4868                                            if (orderByComparator.isAscending() ^ previous) {
4869                                                    query.append(ORDER_BY_ASC);
4870                                            }
4871                                            else {
4872                                                    query.append(ORDER_BY_DESC);
4873                                            }
4874                                    }
4875                            }
4876                    }
4877                    else {
4878                            if (getDB().isSupportsInlineDistinct()) {
4879                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
4880                            }
4881                            else {
4882                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
4883                            }
4884                    }
4885    
4886                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
4887                                    MBMessage.class.getName(),
4888                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
4889    
4890                    SQLQuery q = session.createSQLQuery(sql);
4891    
4892                    q.setFirstResult(0);
4893                    q.setMaxResults(2);
4894    
4895                    if (getDB().isSupportsInlineDistinct()) {
4896                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
4897                    }
4898                    else {
4899                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
4900                    }
4901    
4902                    QueryPos qPos = QueryPos.getInstance(q);
4903    
4904                    qPos.add(groupId);
4905    
4906                    qPos.add(userId);
4907    
4908                    if (orderByComparator != null) {
4909                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
4910    
4911                            for (Object value : values) {
4912                                    qPos.add(value);
4913                            }
4914                    }
4915    
4916                    List<MBMessage> list = q.list();
4917    
4918                    if (list.size() == 2) {
4919                            return list.get(1);
4920                    }
4921                    else {
4922                            return null;
4923                    }
4924            }
4925    
4926            /**
4927             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; from the database.
4928             *
4929             * @param groupId the group ID
4930             * @param userId the user ID
4931             * @throws SystemException if a system exception occurred
4932             */
4933            public void removeByG_U(long groupId, long userId)
4934                    throws SystemException {
4935                    for (MBMessage mbMessage : findByG_U(groupId, userId,
4936                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
4937                            remove(mbMessage);
4938                    }
4939            }
4940    
4941            /**
4942             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63;.
4943             *
4944             * @param groupId the group ID
4945             * @param userId the user ID
4946             * @return the number of matching message-boards messages
4947             * @throws SystemException if a system exception occurred
4948             */
4949            public int countByG_U(long groupId, long userId) throws SystemException {
4950                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U;
4951    
4952                    Object[] finderArgs = new Object[] { groupId, userId };
4953    
4954                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
4955                                    this);
4956    
4957                    if (count == null) {
4958                            StringBundler query = new StringBundler(3);
4959    
4960                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
4961    
4962                            query.append(_FINDER_COLUMN_G_U_GROUPID_2);
4963    
4964                            query.append(_FINDER_COLUMN_G_U_USERID_2);
4965    
4966                            String sql = query.toString();
4967    
4968                            Session session = null;
4969    
4970                            try {
4971                                    session = openSession();
4972    
4973                                    Query q = session.createQuery(sql);
4974    
4975                                    QueryPos qPos = QueryPos.getInstance(q);
4976    
4977                                    qPos.add(groupId);
4978    
4979                                    qPos.add(userId);
4980    
4981                                    count = (Long)q.uniqueResult();
4982    
4983                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
4984                            }
4985                            catch (Exception e) {
4986                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
4987    
4988                                    throw processException(e);
4989                            }
4990                            finally {
4991                                    closeSession(session);
4992                            }
4993                    }
4994    
4995                    return count.intValue();
4996            }
4997    
4998            /**
4999             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63;.
5000             *
5001             * @param groupId the group ID
5002             * @param userId the user ID
5003             * @return the number of matching message-boards messages that the user has permission to view
5004             * @throws SystemException if a system exception occurred
5005             */
5006            public int filterCountByG_U(long groupId, long userId)
5007                    throws SystemException {
5008                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5009                            return countByG_U(groupId, userId);
5010                    }
5011    
5012                    StringBundler query = new StringBundler(3);
5013    
5014                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5015    
5016                    query.append(_FINDER_COLUMN_G_U_GROUPID_2);
5017    
5018                    query.append(_FINDER_COLUMN_G_U_USERID_2);
5019    
5020                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5021                                    MBMessage.class.getName(),
5022                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5023    
5024                    Session session = null;
5025    
5026                    try {
5027                            session = openSession();
5028    
5029                            SQLQuery q = session.createSQLQuery(sql);
5030    
5031                            q.addScalar(COUNT_COLUMN_NAME,
5032                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5033    
5034                            QueryPos qPos = QueryPos.getInstance(q);
5035    
5036                            qPos.add(groupId);
5037    
5038                            qPos.add(userId);
5039    
5040                            Long count = (Long)q.uniqueResult();
5041    
5042                            return count.intValue();
5043                    }
5044                    catch (Exception e) {
5045                            throw processException(e);
5046                    }
5047                    finally {
5048                            closeSession(session);
5049                    }
5050            }
5051    
5052            private static final String _FINDER_COLUMN_G_U_GROUPID_2 = "mbMessage.groupId = ? AND ";
5053            private static final String _FINDER_COLUMN_G_U_USERID_2 = "mbMessage.userId = ? AND (mbMessage.categoryId != -1) AND (mbMessage.anonymous = [$FALSE$])";
5054            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5055                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5056                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C",
5057                            new String[] {
5058                                    Long.class.getName(), Long.class.getName(),
5059                                    
5060                            Integer.class.getName(), Integer.class.getName(),
5061                                    OrderByComparator.class.getName()
5062                            });
5063            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5064                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5065                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C",
5066                            new String[] { Long.class.getName(), Long.class.getName() },
5067                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5068                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
5069                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5070            public static final FinderPath FINDER_PATH_COUNT_BY_G_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5071                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5072                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C",
5073                            new String[] { Long.class.getName(), Long.class.getName() });
5074    
5075            /**
5076             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5077             *
5078             * @param groupId the group ID
5079             * @param categoryId the category ID
5080             * @return the matching message-boards messages
5081             * @throws SystemException if a system exception occurred
5082             */
5083            public List<MBMessage> findByG_C(long groupId, long categoryId)
5084                    throws SystemException {
5085                    return findByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5086                            QueryUtil.ALL_POS, null);
5087            }
5088    
5089            /**
5090             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5091             *
5092             * <p>
5093             * 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.
5094             * </p>
5095             *
5096             * @param groupId the group ID
5097             * @param categoryId the category ID
5098             * @param start the lower bound of the range of message-boards messages
5099             * @param end the upper bound of the range of message-boards messages (not inclusive)
5100             * @return the range of matching message-boards messages
5101             * @throws SystemException if a system exception occurred
5102             */
5103            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5104                    int end) throws SystemException {
5105                    return findByG_C(groupId, categoryId, start, end, null);
5106            }
5107    
5108            /**
5109             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63;.
5110             *
5111             * <p>
5112             * 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.
5113             * </p>
5114             *
5115             * @param groupId the group ID
5116             * @param categoryId the category ID
5117             * @param start the lower bound of the range of message-boards messages
5118             * @param end the upper bound of the range of message-boards messages (not inclusive)
5119             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5120             * @return the ordered range of matching message-boards messages
5121             * @throws SystemException if a system exception occurred
5122             */
5123            public List<MBMessage> findByG_C(long groupId, long categoryId, int start,
5124                    int end, OrderByComparator orderByComparator) throws SystemException {
5125                    boolean pagination = true;
5126                    FinderPath finderPath = null;
5127                    Object[] finderArgs = null;
5128    
5129                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
5130                                    (orderByComparator == null)) {
5131                            pagination = false;
5132                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C;
5133                            finderArgs = new Object[] { groupId, categoryId };
5134                    }
5135                    else {
5136                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C;
5137                            finderArgs = new Object[] {
5138                                            groupId, categoryId,
5139                                            
5140                                            start, end, orderByComparator
5141                                    };
5142                    }
5143    
5144                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
5145                                    finderArgs, this);
5146    
5147                    if ((list != null) && !list.isEmpty()) {
5148                            for (MBMessage mbMessage : list) {
5149                                    if ((groupId != mbMessage.getGroupId()) ||
5150                                                    (categoryId != mbMessage.getCategoryId())) {
5151                                            list = null;
5152    
5153                                            break;
5154                                    }
5155                            }
5156                    }
5157    
5158                    if (list == null) {
5159                            StringBundler query = null;
5160    
5161                            if (orderByComparator != null) {
5162                                    query = new StringBundler(4 +
5163                                                    (orderByComparator.getOrderByFields().length * 3));
5164                            }
5165                            else {
5166                                    query = new StringBundler(4);
5167                            }
5168    
5169                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5170    
5171                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5172    
5173                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5174    
5175                            if (orderByComparator != null) {
5176                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5177                                            orderByComparator);
5178                            }
5179                            else
5180                             if (pagination) {
5181                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5182                            }
5183    
5184                            String sql = query.toString();
5185    
5186                            Session session = null;
5187    
5188                            try {
5189                                    session = openSession();
5190    
5191                                    Query q = session.createQuery(sql);
5192    
5193                                    QueryPos qPos = QueryPos.getInstance(q);
5194    
5195                                    qPos.add(groupId);
5196    
5197                                    qPos.add(categoryId);
5198    
5199                                    if (!pagination) {
5200                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5201                                                            start, end, false);
5202    
5203                                            Collections.sort(list);
5204    
5205                                            list = new UnmodifiableList<MBMessage>(list);
5206                                    }
5207                                    else {
5208                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
5209                                                            start, end);
5210                                    }
5211    
5212                                    cacheResult(list);
5213    
5214                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
5215                            }
5216                            catch (Exception e) {
5217                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5218    
5219                                    throw processException(e);
5220                            }
5221                            finally {
5222                                    closeSession(session);
5223                            }
5224                    }
5225    
5226                    return list;
5227            }
5228    
5229            /**
5230             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5231             *
5232             * @param groupId the group ID
5233             * @param categoryId the category ID
5234             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5235             * @return the first matching message-boards message
5236             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5237             * @throws SystemException if a system exception occurred
5238             */
5239            public MBMessage findByG_C_First(long groupId, long categoryId,
5240                    OrderByComparator orderByComparator)
5241                    throws NoSuchMessageException, SystemException {
5242                    MBMessage mbMessage = fetchByG_C_First(groupId, categoryId,
5243                                    orderByComparator);
5244    
5245                    if (mbMessage != null) {
5246                            return mbMessage;
5247                    }
5248    
5249                    StringBundler msg = new StringBundler(6);
5250    
5251                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5252    
5253                    msg.append("groupId=");
5254                    msg.append(groupId);
5255    
5256                    msg.append(", categoryId=");
5257                    msg.append(categoryId);
5258    
5259                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5260    
5261                    throw new NoSuchMessageException(msg.toString());
5262            }
5263    
5264            /**
5265             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5266             *
5267             * @param groupId the group ID
5268             * @param categoryId the category ID
5269             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5270             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5271             * @throws SystemException if a system exception occurred
5272             */
5273            public MBMessage fetchByG_C_First(long groupId, long categoryId,
5274                    OrderByComparator orderByComparator) throws SystemException {
5275                    List<MBMessage> list = findByG_C(groupId, categoryId, 0, 1,
5276                                    orderByComparator);
5277    
5278                    if (!list.isEmpty()) {
5279                            return list.get(0);
5280                    }
5281    
5282                    return null;
5283            }
5284    
5285            /**
5286             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5287             *
5288             * @param groupId the group ID
5289             * @param categoryId the category ID
5290             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5291             * @return the last matching message-boards message
5292             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
5293             * @throws SystemException if a system exception occurred
5294             */
5295            public MBMessage findByG_C_Last(long groupId, long categoryId,
5296                    OrderByComparator orderByComparator)
5297                    throws NoSuchMessageException, SystemException {
5298                    MBMessage mbMessage = fetchByG_C_Last(groupId, categoryId,
5299                                    orderByComparator);
5300    
5301                    if (mbMessage != null) {
5302                            return mbMessage;
5303                    }
5304    
5305                    StringBundler msg = new StringBundler(6);
5306    
5307                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
5308    
5309                    msg.append("groupId=");
5310                    msg.append(groupId);
5311    
5312                    msg.append(", categoryId=");
5313                    msg.append(categoryId);
5314    
5315                    msg.append(StringPool.CLOSE_CURLY_BRACE);
5316    
5317                    throw new NoSuchMessageException(msg.toString());
5318            }
5319    
5320            /**
5321             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5322             *
5323             * @param groupId the group ID
5324             * @param categoryId the category ID
5325             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5326             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
5327             * @throws SystemException if a system exception occurred
5328             */
5329            public MBMessage fetchByG_C_Last(long groupId, long categoryId,
5330                    OrderByComparator orderByComparator) throws SystemException {
5331                    int count = countByG_C(groupId, categoryId);
5332    
5333                    List<MBMessage> list = findByG_C(groupId, categoryId, count - 1, count,
5334                                    orderByComparator);
5335    
5336                    if (!list.isEmpty()) {
5337                            return list.get(0);
5338                    }
5339    
5340                    return null;
5341            }
5342    
5343            /**
5344             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and categoryId = &#63;.
5345             *
5346             * @param messageId the primary key of the current message-boards message
5347             * @param groupId the group ID
5348             * @param categoryId the category ID
5349             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5350             * @return the previous, current, and next message-boards message
5351             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5352             * @throws SystemException if a system exception occurred
5353             */
5354            public MBMessage[] findByG_C_PrevAndNext(long messageId, long groupId,
5355                    long categoryId, OrderByComparator orderByComparator)
5356                    throws NoSuchMessageException, SystemException {
5357                    MBMessage mbMessage = findByPrimaryKey(messageId);
5358    
5359                    Session session = null;
5360    
5361                    try {
5362                            session = openSession();
5363    
5364                            MBMessage[] array = new MBMessageImpl[3];
5365    
5366                            array[0] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5367                                            categoryId, orderByComparator, true);
5368    
5369                            array[1] = mbMessage;
5370    
5371                            array[2] = getByG_C_PrevAndNext(session, mbMessage, groupId,
5372                                            categoryId, orderByComparator, false);
5373    
5374                            return array;
5375                    }
5376                    catch (Exception e) {
5377                            throw processException(e);
5378                    }
5379                    finally {
5380                            closeSession(session);
5381                    }
5382            }
5383    
5384            protected MBMessage getByG_C_PrevAndNext(Session session,
5385                    MBMessage mbMessage, long groupId, long categoryId,
5386                    OrderByComparator orderByComparator, boolean previous) {
5387                    StringBundler query = null;
5388    
5389                    if (orderByComparator != null) {
5390                            query = new StringBundler(6 +
5391                                            (orderByComparator.getOrderByFields().length * 6));
5392                    }
5393                    else {
5394                            query = new StringBundler(3);
5395                    }
5396    
5397                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
5398    
5399                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5400    
5401                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5402    
5403                    if (orderByComparator != null) {
5404                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5405    
5406                            if (orderByConditionFields.length > 0) {
5407                                    query.append(WHERE_AND);
5408                            }
5409    
5410                            for (int i = 0; i < orderByConditionFields.length; i++) {
5411                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5412                                    query.append(orderByConditionFields[i]);
5413    
5414                                    if ((i + 1) < orderByConditionFields.length) {
5415                                            if (orderByComparator.isAscending() ^ previous) {
5416                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5417                                            }
5418                                            else {
5419                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5420                                            }
5421                                    }
5422                                    else {
5423                                            if (orderByComparator.isAscending() ^ previous) {
5424                                                    query.append(WHERE_GREATER_THAN);
5425                                            }
5426                                            else {
5427                                                    query.append(WHERE_LESSER_THAN);
5428                                            }
5429                                    }
5430                            }
5431    
5432                            query.append(ORDER_BY_CLAUSE);
5433    
5434                            String[] orderByFields = orderByComparator.getOrderByFields();
5435    
5436                            for (int i = 0; i < orderByFields.length; i++) {
5437                                    query.append(_ORDER_BY_ENTITY_ALIAS);
5438                                    query.append(orderByFields[i]);
5439    
5440                                    if ((i + 1) < orderByFields.length) {
5441                                            if (orderByComparator.isAscending() ^ previous) {
5442                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5443                                            }
5444                                            else {
5445                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5446                                            }
5447                                    }
5448                                    else {
5449                                            if (orderByComparator.isAscending() ^ previous) {
5450                                                    query.append(ORDER_BY_ASC);
5451                                            }
5452                                            else {
5453                                                    query.append(ORDER_BY_DESC);
5454                                            }
5455                                    }
5456                            }
5457                    }
5458                    else {
5459                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5460                    }
5461    
5462                    String sql = query.toString();
5463    
5464                    Query q = session.createQuery(sql);
5465    
5466                    q.setFirstResult(0);
5467                    q.setMaxResults(2);
5468    
5469                    QueryPos qPos = QueryPos.getInstance(q);
5470    
5471                    qPos.add(groupId);
5472    
5473                    qPos.add(categoryId);
5474    
5475                    if (orderByComparator != null) {
5476                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5477    
5478                            for (Object value : values) {
5479                                    qPos.add(value);
5480                            }
5481                    }
5482    
5483                    List<MBMessage> list = q.list();
5484    
5485                    if (list.size() == 2) {
5486                            return list.get(1);
5487                    }
5488                    else {
5489                            return null;
5490                    }
5491            }
5492    
5493            /**
5494             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5495             *
5496             * @param groupId the group ID
5497             * @param categoryId the category ID
5498             * @return the matching message-boards messages that the user has permission to view
5499             * @throws SystemException if a system exception occurred
5500             */
5501            public List<MBMessage> filterFindByG_C(long groupId, long categoryId)
5502                    throws SystemException {
5503                    return filterFindByG_C(groupId, categoryId, QueryUtil.ALL_POS,
5504                            QueryUtil.ALL_POS, null);
5505            }
5506    
5507            /**
5508             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5509             *
5510             * <p>
5511             * 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.
5512             * </p>
5513             *
5514             * @param groupId the group ID
5515             * @param categoryId the category ID
5516             * @param start the lower bound of the range of message-boards messages
5517             * @param end the upper bound of the range of message-boards messages (not inclusive)
5518             * @return the range of matching message-boards messages that the user has permission to view
5519             * @throws SystemException if a system exception occurred
5520             */
5521            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5522                    int start, int end) throws SystemException {
5523                    return filterFindByG_C(groupId, categoryId, start, end, null);
5524            }
5525    
5526            /**
5527             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and categoryId = &#63;.
5528             *
5529             * <p>
5530             * 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.
5531             * </p>
5532             *
5533             * @param groupId the group ID
5534             * @param categoryId the category ID
5535             * @param start the lower bound of the range of message-boards messages
5536             * @param end the upper bound of the range of message-boards messages (not inclusive)
5537             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
5538             * @return the ordered range of matching message-boards messages that the user has permission to view
5539             * @throws SystemException if a system exception occurred
5540             */
5541            public List<MBMessage> filterFindByG_C(long groupId, long categoryId,
5542                    int start, int end, OrderByComparator orderByComparator)
5543                    throws SystemException {
5544                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5545                            return findByG_C(groupId, categoryId, start, end, orderByComparator);
5546                    }
5547    
5548                    StringBundler query = null;
5549    
5550                    if (orderByComparator != null) {
5551                            query = new StringBundler(4 +
5552                                            (orderByComparator.getOrderByFields().length * 3));
5553                    }
5554                    else {
5555                            query = new StringBundler(4);
5556                    }
5557    
5558                    if (getDB().isSupportsInlineDistinct()) {
5559                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5560                    }
5561                    else {
5562                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5563                    }
5564    
5565                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5566    
5567                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5568    
5569                    if (!getDB().isSupportsInlineDistinct()) {
5570                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5571                    }
5572    
5573                    if (orderByComparator != null) {
5574                            if (getDB().isSupportsInlineDistinct()) {
5575                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
5576                                            orderByComparator, true);
5577                            }
5578                            else {
5579                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
5580                                            orderByComparator, true);
5581                            }
5582                    }
5583                    else {
5584                            if (getDB().isSupportsInlineDistinct()) {
5585                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5586                            }
5587                            else {
5588                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5589                            }
5590                    }
5591    
5592                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5593                                    MBMessage.class.getName(),
5594                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5595    
5596                    Session session = null;
5597    
5598                    try {
5599                            session = openSession();
5600    
5601                            SQLQuery q = session.createSQLQuery(sql);
5602    
5603                            if (getDB().isSupportsInlineDistinct()) {
5604                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5605                            }
5606                            else {
5607                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5608                            }
5609    
5610                            QueryPos qPos = QueryPos.getInstance(q);
5611    
5612                            qPos.add(groupId);
5613    
5614                            qPos.add(categoryId);
5615    
5616                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
5617                    }
5618                    catch (Exception e) {
5619                            throw processException(e);
5620                    }
5621                    finally {
5622                            closeSession(session);
5623                    }
5624            }
5625    
5626            /**
5627             * 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;.
5628             *
5629             * @param messageId the primary key of the current message-boards message
5630             * @param groupId the group ID
5631             * @param categoryId the category ID
5632             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
5633             * @return the previous, current, and next message-boards message
5634             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
5635             * @throws SystemException if a system exception occurred
5636             */
5637            public MBMessage[] filterFindByG_C_PrevAndNext(long messageId,
5638                    long groupId, long categoryId, OrderByComparator orderByComparator)
5639                    throws NoSuchMessageException, SystemException {
5640                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5641                            return findByG_C_PrevAndNext(messageId, groupId, categoryId,
5642                                    orderByComparator);
5643                    }
5644    
5645                    MBMessage mbMessage = findByPrimaryKey(messageId);
5646    
5647                    Session session = null;
5648    
5649                    try {
5650                            session = openSession();
5651    
5652                            MBMessage[] array = new MBMessageImpl[3];
5653    
5654                            array[0] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5655                                            categoryId, orderByComparator, true);
5656    
5657                            array[1] = mbMessage;
5658    
5659                            array[2] = filterGetByG_C_PrevAndNext(session, mbMessage, groupId,
5660                                            categoryId, orderByComparator, false);
5661    
5662                            return array;
5663                    }
5664                    catch (Exception e) {
5665                            throw processException(e);
5666                    }
5667                    finally {
5668                            closeSession(session);
5669                    }
5670            }
5671    
5672            protected MBMessage filterGetByG_C_PrevAndNext(Session session,
5673                    MBMessage mbMessage, long groupId, long categoryId,
5674                    OrderByComparator orderByComparator, boolean previous) {
5675                    StringBundler query = null;
5676    
5677                    if (orderByComparator != null) {
5678                            query = new StringBundler(6 +
5679                                            (orderByComparator.getOrderByFields().length * 6));
5680                    }
5681                    else {
5682                            query = new StringBundler(3);
5683                    }
5684    
5685                    if (getDB().isSupportsInlineDistinct()) {
5686                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
5687                    }
5688                    else {
5689                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
5690                    }
5691    
5692                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5693    
5694                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5695    
5696                    if (!getDB().isSupportsInlineDistinct()) {
5697                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
5698                    }
5699    
5700                    if (orderByComparator != null) {
5701                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
5702    
5703                            if (orderByConditionFields.length > 0) {
5704                                    query.append(WHERE_AND);
5705                            }
5706    
5707                            for (int i = 0; i < orderByConditionFields.length; i++) {
5708                                    if (getDB().isSupportsInlineDistinct()) {
5709                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5710                                    }
5711                                    else {
5712                                            query.append(_ORDER_BY_ENTITY_TABLE);
5713                                    }
5714    
5715                                    query.append(orderByConditionFields[i]);
5716    
5717                                    if ((i + 1) < orderByConditionFields.length) {
5718                                            if (orderByComparator.isAscending() ^ previous) {
5719                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
5720                                            }
5721                                            else {
5722                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
5723                                            }
5724                                    }
5725                                    else {
5726                                            if (orderByComparator.isAscending() ^ previous) {
5727                                                    query.append(WHERE_GREATER_THAN);
5728                                            }
5729                                            else {
5730                                                    query.append(WHERE_LESSER_THAN);
5731                                            }
5732                                    }
5733                            }
5734    
5735                            query.append(ORDER_BY_CLAUSE);
5736    
5737                            String[] orderByFields = orderByComparator.getOrderByFields();
5738    
5739                            for (int i = 0; i < orderByFields.length; i++) {
5740                                    if (getDB().isSupportsInlineDistinct()) {
5741                                            query.append(_ORDER_BY_ENTITY_ALIAS);
5742                                    }
5743                                    else {
5744                                            query.append(_ORDER_BY_ENTITY_TABLE);
5745                                    }
5746    
5747                                    query.append(orderByFields[i]);
5748    
5749                                    if ((i + 1) < orderByFields.length) {
5750                                            if (orderByComparator.isAscending() ^ previous) {
5751                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
5752                                            }
5753                                            else {
5754                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
5755                                            }
5756                                    }
5757                                    else {
5758                                            if (orderByComparator.isAscending() ^ previous) {
5759                                                    query.append(ORDER_BY_ASC);
5760                                            }
5761                                            else {
5762                                                    query.append(ORDER_BY_DESC);
5763                                            }
5764                                    }
5765                            }
5766                    }
5767                    else {
5768                            if (getDB().isSupportsInlineDistinct()) {
5769                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
5770                            }
5771                            else {
5772                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
5773                            }
5774                    }
5775    
5776                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5777                                    MBMessage.class.getName(),
5778                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5779    
5780                    SQLQuery q = session.createSQLQuery(sql);
5781    
5782                    q.setFirstResult(0);
5783                    q.setMaxResults(2);
5784    
5785                    if (getDB().isSupportsInlineDistinct()) {
5786                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
5787                    }
5788                    else {
5789                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
5790                    }
5791    
5792                    QueryPos qPos = QueryPos.getInstance(q);
5793    
5794                    qPos.add(groupId);
5795    
5796                    qPos.add(categoryId);
5797    
5798                    if (orderByComparator != null) {
5799                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
5800    
5801                            for (Object value : values) {
5802                                    qPos.add(value);
5803                            }
5804                    }
5805    
5806                    List<MBMessage> list = q.list();
5807    
5808                    if (list.size() == 2) {
5809                            return list.get(1);
5810                    }
5811                    else {
5812                            return null;
5813                    }
5814            }
5815    
5816            /**
5817             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; from the database.
5818             *
5819             * @param groupId the group ID
5820             * @param categoryId the category ID
5821             * @throws SystemException if a system exception occurred
5822             */
5823            public void removeByG_C(long groupId, long categoryId)
5824                    throws SystemException {
5825                    for (MBMessage mbMessage : findByG_C(groupId, categoryId,
5826                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
5827                            remove(mbMessage);
5828                    }
5829            }
5830    
5831            /**
5832             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63;.
5833             *
5834             * @param groupId the group ID
5835             * @param categoryId the category ID
5836             * @return the number of matching message-boards messages
5837             * @throws SystemException if a system exception occurred
5838             */
5839            public int countByG_C(long groupId, long categoryId)
5840                    throws SystemException {
5841                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C;
5842    
5843                    Object[] finderArgs = new Object[] { groupId, categoryId };
5844    
5845                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
5846                                    this);
5847    
5848                    if (count == null) {
5849                            StringBundler query = new StringBundler(3);
5850    
5851                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
5852    
5853                            query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5854    
5855                            query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5856    
5857                            String sql = query.toString();
5858    
5859                            Session session = null;
5860    
5861                            try {
5862                                    session = openSession();
5863    
5864                                    Query q = session.createQuery(sql);
5865    
5866                                    QueryPos qPos = QueryPos.getInstance(q);
5867    
5868                                    qPos.add(groupId);
5869    
5870                                    qPos.add(categoryId);
5871    
5872                                    count = (Long)q.uniqueResult();
5873    
5874                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
5875                            }
5876                            catch (Exception e) {
5877                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
5878    
5879                                    throw processException(e);
5880                            }
5881                            finally {
5882                                    closeSession(session);
5883                            }
5884                    }
5885    
5886                    return count.intValue();
5887            }
5888    
5889            /**
5890             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63;.
5891             *
5892             * @param groupId the group ID
5893             * @param categoryId the category ID
5894             * @return the number of matching message-boards messages that the user has permission to view
5895             * @throws SystemException if a system exception occurred
5896             */
5897            public int filterCountByG_C(long groupId, long categoryId)
5898                    throws SystemException {
5899                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
5900                            return countByG_C(groupId, categoryId);
5901                    }
5902    
5903                    StringBundler query = new StringBundler(3);
5904    
5905                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
5906    
5907                    query.append(_FINDER_COLUMN_G_C_GROUPID_2);
5908    
5909                    query.append(_FINDER_COLUMN_G_C_CATEGORYID_2);
5910    
5911                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
5912                                    MBMessage.class.getName(),
5913                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
5914    
5915                    Session session = null;
5916    
5917                    try {
5918                            session = openSession();
5919    
5920                            SQLQuery q = session.createSQLQuery(sql);
5921    
5922                            q.addScalar(COUNT_COLUMN_NAME,
5923                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
5924    
5925                            QueryPos qPos = QueryPos.getInstance(q);
5926    
5927                            qPos.add(groupId);
5928    
5929                            qPos.add(categoryId);
5930    
5931                            Long count = (Long)q.uniqueResult();
5932    
5933                            return count.intValue();
5934                    }
5935                    catch (Exception e) {
5936                            throw processException(e);
5937                    }
5938                    finally {
5939                            closeSession(session);
5940                    }
5941            }
5942    
5943            private static final String _FINDER_COLUMN_G_C_GROUPID_2 = "mbMessage.groupId = ? AND ";
5944            private static final String _FINDER_COLUMN_G_C_CATEGORYID_2 = "mbMessage.categoryId = ?";
5945            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5946                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5947                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_S",
5948                            new String[] {
5949                                    Long.class.getName(), Integer.class.getName(),
5950                                    
5951                            Integer.class.getName(), Integer.class.getName(),
5952                                    OrderByComparator.class.getName()
5953                            });
5954            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5955                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
5956                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_S",
5957                            new String[] { Long.class.getName(), Integer.class.getName() },
5958                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
5959                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
5960                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
5961            public static final FinderPath FINDER_PATH_COUNT_BY_G_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
5962                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
5963                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_S",
5964                            new String[] { Long.class.getName(), Integer.class.getName() });
5965    
5966            /**
5967             * Returns all the message-boards messages where groupId = &#63; and status = &#63;.
5968             *
5969             * @param groupId the group ID
5970             * @param status the status
5971             * @return the matching message-boards messages
5972             * @throws SystemException if a system exception occurred
5973             */
5974            public List<MBMessage> findByG_S(long groupId, int status)
5975                    throws SystemException {
5976                    return findByG_S(groupId, status, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
5977                            null);
5978            }
5979    
5980            /**
5981             * Returns a range of all the message-boards messages where groupId = &#63; and status = &#63;.
5982             *
5983             * <p>
5984             * 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.
5985             * </p>
5986             *
5987             * @param groupId the group ID
5988             * @param status the status
5989             * @param start the lower bound of the range of message-boards messages
5990             * @param end the upper bound of the range of message-boards messages (not inclusive)
5991             * @return the range of matching message-boards messages
5992             * @throws SystemException if a system exception occurred
5993             */
5994            public List<MBMessage> findByG_S(long groupId, int status, int start,
5995                    int end) throws SystemException {
5996                    return findByG_S(groupId, status, start, end, null);
5997            }
5998    
5999            /**
6000             * Returns an ordered range of all the message-boards messages where groupId = &#63; and status = &#63;.
6001             *
6002             * <p>
6003             * 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.
6004             * </p>
6005             *
6006             * @param groupId the group ID
6007             * @param status the status
6008             * @param start the lower bound of the range of message-boards messages
6009             * @param end the upper bound of the range of message-boards messages (not inclusive)
6010             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6011             * @return the ordered range of matching message-boards messages
6012             * @throws SystemException if a system exception occurred
6013             */
6014            public List<MBMessage> findByG_S(long groupId, int status, int start,
6015                    int end, OrderByComparator orderByComparator) throws SystemException {
6016                    boolean pagination = true;
6017                    FinderPath finderPath = null;
6018                    Object[] finderArgs = null;
6019    
6020                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6021                                    (orderByComparator == null)) {
6022                            pagination = false;
6023                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S;
6024                            finderArgs = new Object[] { groupId, status };
6025                    }
6026                    else {
6027                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_S;
6028                            finderArgs = new Object[] {
6029                                            groupId, status,
6030                                            
6031                                            start, end, orderByComparator
6032                                    };
6033                    }
6034    
6035                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6036                                    finderArgs, this);
6037    
6038                    if ((list != null) && !list.isEmpty()) {
6039                            for (MBMessage mbMessage : list) {
6040                                    if ((groupId != mbMessage.getGroupId()) ||
6041                                                    (status != mbMessage.getStatus())) {
6042                                            list = null;
6043    
6044                                            break;
6045                                    }
6046                            }
6047                    }
6048    
6049                    if (list == null) {
6050                            StringBundler query = null;
6051    
6052                            if (orderByComparator != null) {
6053                                    query = new StringBundler(4 +
6054                                                    (orderByComparator.getOrderByFields().length * 3));
6055                            }
6056                            else {
6057                                    query = new StringBundler(4);
6058                            }
6059    
6060                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6061    
6062                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6063    
6064                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6065    
6066                            if (orderByComparator != null) {
6067                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6068                                            orderByComparator);
6069                            }
6070                            else
6071                             if (pagination) {
6072                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6073                            }
6074    
6075                            String sql = query.toString();
6076    
6077                            Session session = null;
6078    
6079                            try {
6080                                    session = openSession();
6081    
6082                                    Query q = session.createQuery(sql);
6083    
6084                                    QueryPos qPos = QueryPos.getInstance(q);
6085    
6086                                    qPos.add(groupId);
6087    
6088                                    qPos.add(status);
6089    
6090                                    if (!pagination) {
6091                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6092                                                            start, end, false);
6093    
6094                                            Collections.sort(list);
6095    
6096                                            list = new UnmodifiableList<MBMessage>(list);
6097                                    }
6098                                    else {
6099                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6100                                                            start, end);
6101                                    }
6102    
6103                                    cacheResult(list);
6104    
6105                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6106                            }
6107                            catch (Exception e) {
6108                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6109    
6110                                    throw processException(e);
6111                            }
6112                            finally {
6113                                    closeSession(session);
6114                            }
6115                    }
6116    
6117                    return list;
6118            }
6119    
6120            /**
6121             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6122             *
6123             * @param groupId the group ID
6124             * @param status the status
6125             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6126             * @return the first matching message-boards message
6127             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6128             * @throws SystemException if a system exception occurred
6129             */
6130            public MBMessage findByG_S_First(long groupId, int status,
6131                    OrderByComparator orderByComparator)
6132                    throws NoSuchMessageException, SystemException {
6133                    MBMessage mbMessage = fetchByG_S_First(groupId, status,
6134                                    orderByComparator);
6135    
6136                    if (mbMessage != null) {
6137                            return mbMessage;
6138                    }
6139    
6140                    StringBundler msg = new StringBundler(6);
6141    
6142                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6143    
6144                    msg.append("groupId=");
6145                    msg.append(groupId);
6146    
6147                    msg.append(", status=");
6148                    msg.append(status);
6149    
6150                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6151    
6152                    throw new NoSuchMessageException(msg.toString());
6153            }
6154    
6155            /**
6156             * Returns the first message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6157             *
6158             * @param groupId the group ID
6159             * @param status the status
6160             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6161             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6162             * @throws SystemException if a system exception occurred
6163             */
6164            public MBMessage fetchByG_S_First(long groupId, int status,
6165                    OrderByComparator orderByComparator) throws SystemException {
6166                    List<MBMessage> list = findByG_S(groupId, status, 0, 1,
6167                                    orderByComparator);
6168    
6169                    if (!list.isEmpty()) {
6170                            return list.get(0);
6171                    }
6172    
6173                    return null;
6174            }
6175    
6176            /**
6177             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6178             *
6179             * @param groupId the group ID
6180             * @param status the status
6181             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6182             * @return the last matching message-boards message
6183             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
6184             * @throws SystemException if a system exception occurred
6185             */
6186            public MBMessage findByG_S_Last(long groupId, int status,
6187                    OrderByComparator orderByComparator)
6188                    throws NoSuchMessageException, SystemException {
6189                    MBMessage mbMessage = fetchByG_S_Last(groupId, status, orderByComparator);
6190    
6191                    if (mbMessage != null) {
6192                            return mbMessage;
6193                    }
6194    
6195                    StringBundler msg = new StringBundler(6);
6196    
6197                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
6198    
6199                    msg.append("groupId=");
6200                    msg.append(groupId);
6201    
6202                    msg.append(", status=");
6203                    msg.append(status);
6204    
6205                    msg.append(StringPool.CLOSE_CURLY_BRACE);
6206    
6207                    throw new NoSuchMessageException(msg.toString());
6208            }
6209    
6210            /**
6211             * Returns the last message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6212             *
6213             * @param groupId the group ID
6214             * @param status the status
6215             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6216             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
6217             * @throws SystemException if a system exception occurred
6218             */
6219            public MBMessage fetchByG_S_Last(long groupId, int status,
6220                    OrderByComparator orderByComparator) throws SystemException {
6221                    int count = countByG_S(groupId, status);
6222    
6223                    List<MBMessage> list = findByG_S(groupId, status, count - 1, count,
6224                                    orderByComparator);
6225    
6226                    if (!list.isEmpty()) {
6227                            return list.get(0);
6228                    }
6229    
6230                    return null;
6231            }
6232    
6233            /**
6234             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and status = &#63;.
6235             *
6236             * @param messageId the primary key of the current message-boards message
6237             * @param groupId the group ID
6238             * @param status the status
6239             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6240             * @return the previous, current, and next message-boards message
6241             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6242             * @throws SystemException if a system exception occurred
6243             */
6244            public MBMessage[] findByG_S_PrevAndNext(long messageId, long groupId,
6245                    int status, OrderByComparator orderByComparator)
6246                    throws NoSuchMessageException, SystemException {
6247                    MBMessage mbMessage = findByPrimaryKey(messageId);
6248    
6249                    Session session = null;
6250    
6251                    try {
6252                            session = openSession();
6253    
6254                            MBMessage[] array = new MBMessageImpl[3];
6255    
6256                            array[0] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6257                                            status, orderByComparator, true);
6258    
6259                            array[1] = mbMessage;
6260    
6261                            array[2] = getByG_S_PrevAndNext(session, mbMessage, groupId,
6262                                            status, orderByComparator, false);
6263    
6264                            return array;
6265                    }
6266                    catch (Exception e) {
6267                            throw processException(e);
6268                    }
6269                    finally {
6270                            closeSession(session);
6271                    }
6272            }
6273    
6274            protected MBMessage getByG_S_PrevAndNext(Session session,
6275                    MBMessage mbMessage, long groupId, int status,
6276                    OrderByComparator orderByComparator, boolean previous) {
6277                    StringBundler query = null;
6278    
6279                    if (orderByComparator != null) {
6280                            query = new StringBundler(6 +
6281                                            (orderByComparator.getOrderByFields().length * 6));
6282                    }
6283                    else {
6284                            query = new StringBundler(3);
6285                    }
6286    
6287                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6288    
6289                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6290    
6291                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6292    
6293                    if (orderByComparator != null) {
6294                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6295    
6296                            if (orderByConditionFields.length > 0) {
6297                                    query.append(WHERE_AND);
6298                            }
6299    
6300                            for (int i = 0; i < orderByConditionFields.length; i++) {
6301                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6302                                    query.append(orderByConditionFields[i]);
6303    
6304                                    if ((i + 1) < orderByConditionFields.length) {
6305                                            if (orderByComparator.isAscending() ^ previous) {
6306                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6307                                            }
6308                                            else {
6309                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6310                                            }
6311                                    }
6312                                    else {
6313                                            if (orderByComparator.isAscending() ^ previous) {
6314                                                    query.append(WHERE_GREATER_THAN);
6315                                            }
6316                                            else {
6317                                                    query.append(WHERE_LESSER_THAN);
6318                                            }
6319                                    }
6320                            }
6321    
6322                            query.append(ORDER_BY_CLAUSE);
6323    
6324                            String[] orderByFields = orderByComparator.getOrderByFields();
6325    
6326                            for (int i = 0; i < orderByFields.length; i++) {
6327                                    query.append(_ORDER_BY_ENTITY_ALIAS);
6328                                    query.append(orderByFields[i]);
6329    
6330                                    if ((i + 1) < orderByFields.length) {
6331                                            if (orderByComparator.isAscending() ^ previous) {
6332                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6333                                            }
6334                                            else {
6335                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6336                                            }
6337                                    }
6338                                    else {
6339                                            if (orderByComparator.isAscending() ^ previous) {
6340                                                    query.append(ORDER_BY_ASC);
6341                                            }
6342                                            else {
6343                                                    query.append(ORDER_BY_DESC);
6344                                            }
6345                                    }
6346                            }
6347                    }
6348                    else {
6349                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6350                    }
6351    
6352                    String sql = query.toString();
6353    
6354                    Query q = session.createQuery(sql);
6355    
6356                    q.setFirstResult(0);
6357                    q.setMaxResults(2);
6358    
6359                    QueryPos qPos = QueryPos.getInstance(q);
6360    
6361                    qPos.add(groupId);
6362    
6363                    qPos.add(status);
6364    
6365                    if (orderByComparator != null) {
6366                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6367    
6368                            for (Object value : values) {
6369                                    qPos.add(value);
6370                            }
6371                    }
6372    
6373                    List<MBMessage> list = q.list();
6374    
6375                    if (list.size() == 2) {
6376                            return list.get(1);
6377                    }
6378                    else {
6379                            return null;
6380                    }
6381            }
6382    
6383            /**
6384             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6385             *
6386             * @param groupId the group ID
6387             * @param status the status
6388             * @return the matching message-boards messages that the user has permission to view
6389             * @throws SystemException if a system exception occurred
6390             */
6391            public List<MBMessage> filterFindByG_S(long groupId, int status)
6392                    throws SystemException {
6393                    return filterFindByG_S(groupId, status, QueryUtil.ALL_POS,
6394                            QueryUtil.ALL_POS, null);
6395            }
6396    
6397            /**
6398             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6399             *
6400             * <p>
6401             * 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.
6402             * </p>
6403             *
6404             * @param groupId the group ID
6405             * @param status the status
6406             * @param start the lower bound of the range of message-boards messages
6407             * @param end the upper bound of the range of message-boards messages (not inclusive)
6408             * @return the range of matching message-boards messages that the user has permission to view
6409             * @throws SystemException if a system exception occurred
6410             */
6411            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6412                    int end) throws SystemException {
6413                    return filterFindByG_S(groupId, status, start, end, null);
6414            }
6415    
6416            /**
6417             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and status = &#63;.
6418             *
6419             * <p>
6420             * 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.
6421             * </p>
6422             *
6423             * @param groupId the group ID
6424             * @param status the status
6425             * @param start the lower bound of the range of message-boards messages
6426             * @param end the upper bound of the range of message-boards messages (not inclusive)
6427             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6428             * @return the ordered range of matching message-boards messages that the user has permission to view
6429             * @throws SystemException if a system exception occurred
6430             */
6431            public List<MBMessage> filterFindByG_S(long groupId, int status, int start,
6432                    int end, OrderByComparator orderByComparator) throws SystemException {
6433                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6434                            return findByG_S(groupId, status, start, end, orderByComparator);
6435                    }
6436    
6437                    StringBundler query = null;
6438    
6439                    if (orderByComparator != null) {
6440                            query = new StringBundler(4 +
6441                                            (orderByComparator.getOrderByFields().length * 3));
6442                    }
6443                    else {
6444                            query = new StringBundler(4);
6445                    }
6446    
6447                    if (getDB().isSupportsInlineDistinct()) {
6448                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6449                    }
6450                    else {
6451                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6452                    }
6453    
6454                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6455    
6456                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6457    
6458                    if (!getDB().isSupportsInlineDistinct()) {
6459                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6460                    }
6461    
6462                    if (orderByComparator != null) {
6463                            if (getDB().isSupportsInlineDistinct()) {
6464                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6465                                            orderByComparator, true);
6466                            }
6467                            else {
6468                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
6469                                            orderByComparator, true);
6470                            }
6471                    }
6472                    else {
6473                            if (getDB().isSupportsInlineDistinct()) {
6474                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6475                            }
6476                            else {
6477                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6478                            }
6479                    }
6480    
6481                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6482                                    MBMessage.class.getName(),
6483                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6484    
6485                    Session session = null;
6486    
6487                    try {
6488                            session = openSession();
6489    
6490                            SQLQuery q = session.createSQLQuery(sql);
6491    
6492                            if (getDB().isSupportsInlineDistinct()) {
6493                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6494                            }
6495                            else {
6496                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6497                            }
6498    
6499                            QueryPos qPos = QueryPos.getInstance(q);
6500    
6501                            qPos.add(groupId);
6502    
6503                            qPos.add(status);
6504    
6505                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
6506                    }
6507                    catch (Exception e) {
6508                            throw processException(e);
6509                    }
6510                    finally {
6511                            closeSession(session);
6512                    }
6513            }
6514    
6515            /**
6516             * 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;.
6517             *
6518             * @param messageId the primary key of the current message-boards message
6519             * @param groupId the group ID
6520             * @param status the status
6521             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
6522             * @return the previous, current, and next message-boards message
6523             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
6524             * @throws SystemException if a system exception occurred
6525             */
6526            public MBMessage[] filterFindByG_S_PrevAndNext(long messageId,
6527                    long groupId, int status, OrderByComparator orderByComparator)
6528                    throws NoSuchMessageException, SystemException {
6529                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6530                            return findByG_S_PrevAndNext(messageId, groupId, status,
6531                                    orderByComparator);
6532                    }
6533    
6534                    MBMessage mbMessage = findByPrimaryKey(messageId);
6535    
6536                    Session session = null;
6537    
6538                    try {
6539                            session = openSession();
6540    
6541                            MBMessage[] array = new MBMessageImpl[3];
6542    
6543                            array[0] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6544                                            status, orderByComparator, true);
6545    
6546                            array[1] = mbMessage;
6547    
6548                            array[2] = filterGetByG_S_PrevAndNext(session, mbMessage, groupId,
6549                                            status, orderByComparator, false);
6550    
6551                            return array;
6552                    }
6553                    catch (Exception e) {
6554                            throw processException(e);
6555                    }
6556                    finally {
6557                            closeSession(session);
6558                    }
6559            }
6560    
6561            protected MBMessage filterGetByG_S_PrevAndNext(Session session,
6562                    MBMessage mbMessage, long groupId, int status,
6563                    OrderByComparator orderByComparator, boolean previous) {
6564                    StringBundler query = null;
6565    
6566                    if (orderByComparator != null) {
6567                            query = new StringBundler(6 +
6568                                            (orderByComparator.getOrderByFields().length * 6));
6569                    }
6570                    else {
6571                            query = new StringBundler(3);
6572                    }
6573    
6574                    if (getDB().isSupportsInlineDistinct()) {
6575                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
6576                    }
6577                    else {
6578                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
6579                    }
6580    
6581                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6582    
6583                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6584    
6585                    if (!getDB().isSupportsInlineDistinct()) {
6586                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
6587                    }
6588    
6589                    if (orderByComparator != null) {
6590                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
6591    
6592                            if (orderByConditionFields.length > 0) {
6593                                    query.append(WHERE_AND);
6594                            }
6595    
6596                            for (int i = 0; i < orderByConditionFields.length; i++) {
6597                                    if (getDB().isSupportsInlineDistinct()) {
6598                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6599                                    }
6600                                    else {
6601                                            query.append(_ORDER_BY_ENTITY_TABLE);
6602                                    }
6603    
6604                                    query.append(orderByConditionFields[i]);
6605    
6606                                    if ((i + 1) < orderByConditionFields.length) {
6607                                            if (orderByComparator.isAscending() ^ previous) {
6608                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
6609                                            }
6610                                            else {
6611                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
6612                                            }
6613                                    }
6614                                    else {
6615                                            if (orderByComparator.isAscending() ^ previous) {
6616                                                    query.append(WHERE_GREATER_THAN);
6617                                            }
6618                                            else {
6619                                                    query.append(WHERE_LESSER_THAN);
6620                                            }
6621                                    }
6622                            }
6623    
6624                            query.append(ORDER_BY_CLAUSE);
6625    
6626                            String[] orderByFields = orderByComparator.getOrderByFields();
6627    
6628                            for (int i = 0; i < orderByFields.length; i++) {
6629                                    if (getDB().isSupportsInlineDistinct()) {
6630                                            query.append(_ORDER_BY_ENTITY_ALIAS);
6631                                    }
6632                                    else {
6633                                            query.append(_ORDER_BY_ENTITY_TABLE);
6634                                    }
6635    
6636                                    query.append(orderByFields[i]);
6637    
6638                                    if ((i + 1) < orderByFields.length) {
6639                                            if (orderByComparator.isAscending() ^ previous) {
6640                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
6641                                            }
6642                                            else {
6643                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
6644                                            }
6645                                    }
6646                                    else {
6647                                            if (orderByComparator.isAscending() ^ previous) {
6648                                                    query.append(ORDER_BY_ASC);
6649                                            }
6650                                            else {
6651                                                    query.append(ORDER_BY_DESC);
6652                                            }
6653                                    }
6654                            }
6655                    }
6656                    else {
6657                            if (getDB().isSupportsInlineDistinct()) {
6658                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6659                            }
6660                            else {
6661                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
6662                            }
6663                    }
6664    
6665                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6666                                    MBMessage.class.getName(),
6667                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6668    
6669                    SQLQuery q = session.createSQLQuery(sql);
6670    
6671                    q.setFirstResult(0);
6672                    q.setMaxResults(2);
6673    
6674                    if (getDB().isSupportsInlineDistinct()) {
6675                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
6676                    }
6677                    else {
6678                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
6679                    }
6680    
6681                    QueryPos qPos = QueryPos.getInstance(q);
6682    
6683                    qPos.add(groupId);
6684    
6685                    qPos.add(status);
6686    
6687                    if (orderByComparator != null) {
6688                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
6689    
6690                            for (Object value : values) {
6691                                    qPos.add(value);
6692                            }
6693                    }
6694    
6695                    List<MBMessage> list = q.list();
6696    
6697                    if (list.size() == 2) {
6698                            return list.get(1);
6699                    }
6700                    else {
6701                            return null;
6702                    }
6703            }
6704    
6705            /**
6706             * Removes all the message-boards messages where groupId = &#63; and status = &#63; from the database.
6707             *
6708             * @param groupId the group ID
6709             * @param status the status
6710             * @throws SystemException if a system exception occurred
6711             */
6712            public void removeByG_S(long groupId, int status) throws SystemException {
6713                    for (MBMessage mbMessage : findByG_S(groupId, status,
6714                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
6715                            remove(mbMessage);
6716                    }
6717            }
6718    
6719            /**
6720             * Returns the number of message-boards messages where groupId = &#63; and status = &#63;.
6721             *
6722             * @param groupId the group ID
6723             * @param status the status
6724             * @return the number of matching message-boards messages
6725             * @throws SystemException if a system exception occurred
6726             */
6727            public int countByG_S(long groupId, int status) throws SystemException {
6728                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_S;
6729    
6730                    Object[] finderArgs = new Object[] { groupId, status };
6731    
6732                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
6733                                    this);
6734    
6735                    if (count == null) {
6736                            StringBundler query = new StringBundler(3);
6737    
6738                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
6739    
6740                            query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6741    
6742                            query.append(_FINDER_COLUMN_G_S_STATUS_2);
6743    
6744                            String sql = query.toString();
6745    
6746                            Session session = null;
6747    
6748                            try {
6749                                    session = openSession();
6750    
6751                                    Query q = session.createQuery(sql);
6752    
6753                                    QueryPos qPos = QueryPos.getInstance(q);
6754    
6755                                    qPos.add(groupId);
6756    
6757                                    qPos.add(status);
6758    
6759                                    count = (Long)q.uniqueResult();
6760    
6761                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
6762                            }
6763                            catch (Exception e) {
6764                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6765    
6766                                    throw processException(e);
6767                            }
6768                            finally {
6769                                    closeSession(session);
6770                            }
6771                    }
6772    
6773                    return count.intValue();
6774            }
6775    
6776            /**
6777             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and status = &#63;.
6778             *
6779             * @param groupId the group ID
6780             * @param status the status
6781             * @return the number of matching message-boards messages that the user has permission to view
6782             * @throws SystemException if a system exception occurred
6783             */
6784            public int filterCountByG_S(long groupId, int status)
6785                    throws SystemException {
6786                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
6787                            return countByG_S(groupId, status);
6788                    }
6789    
6790                    StringBundler query = new StringBundler(3);
6791    
6792                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
6793    
6794                    query.append(_FINDER_COLUMN_G_S_GROUPID_2);
6795    
6796                    query.append(_FINDER_COLUMN_G_S_STATUS_2);
6797    
6798                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
6799                                    MBMessage.class.getName(),
6800                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
6801    
6802                    Session session = null;
6803    
6804                    try {
6805                            session = openSession();
6806    
6807                            SQLQuery q = session.createSQLQuery(sql);
6808    
6809                            q.addScalar(COUNT_COLUMN_NAME,
6810                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
6811    
6812                            QueryPos qPos = QueryPos.getInstance(q);
6813    
6814                            qPos.add(groupId);
6815    
6816                            qPos.add(status);
6817    
6818                            Long count = (Long)q.uniqueResult();
6819    
6820                            return count.intValue();
6821                    }
6822                    catch (Exception e) {
6823                            throw processException(e);
6824                    }
6825                    finally {
6826                            closeSession(session);
6827                    }
6828            }
6829    
6830            private static final String _FINDER_COLUMN_G_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
6831            private static final String _FINDER_COLUMN_G_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
6832            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6833                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6834                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_S",
6835                            new String[] {
6836                                    Long.class.getName(), Integer.class.getName(),
6837                                    
6838                            Integer.class.getName(), Integer.class.getName(),
6839                                    OrderByComparator.class.getName()
6840                            });
6841            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6842                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
6843                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_S",
6844                            new String[] { Long.class.getName(), Integer.class.getName() },
6845                            MBMessageModelImpl.COMPANYID_COLUMN_BITMASK |
6846                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
6847                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
6848            public static final FinderPath FINDER_PATH_COUNT_BY_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
6849                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
6850                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_S",
6851                            new String[] { Long.class.getName(), Integer.class.getName() });
6852    
6853            /**
6854             * Returns all the message-boards messages where companyId = &#63; and status = &#63;.
6855             *
6856             * @param companyId the company ID
6857             * @param status the status
6858             * @return the matching message-boards messages
6859             * @throws SystemException if a system exception occurred
6860             */
6861            public List<MBMessage> findByC_S(long companyId, int status)
6862                    throws SystemException {
6863                    return findByC_S(companyId, status, QueryUtil.ALL_POS,
6864                            QueryUtil.ALL_POS, null);
6865            }
6866    
6867            /**
6868             * Returns a range of all the message-boards messages where companyId = &#63; and status = &#63;.
6869             *
6870             * <p>
6871             * 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.
6872             * </p>
6873             *
6874             * @param companyId the company ID
6875             * @param status the status
6876             * @param start the lower bound of the range of message-boards messages
6877             * @param end the upper bound of the range of message-boards messages (not inclusive)
6878             * @return the range of matching message-boards messages
6879             * @throws SystemException if a system exception occurred
6880             */
6881            public List<MBMessage> findByC_S(long companyId, int status, int start,
6882                    int end) throws SystemException {
6883                    return findByC_S(companyId, status, start, end, null);
6884            }
6885    
6886            /**
6887             * Returns an ordered range of all the message-boards messages where companyId = &#63; and status = &#63;.
6888             *
6889             * <p>
6890             * 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.
6891             * </p>
6892             *
6893             * @param companyId the company ID
6894             * @param status the status
6895             * @param start the lower bound of the range of message-boards messages
6896             * @param end the upper bound of the range of message-boards messages (not inclusive)
6897             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
6898             * @return the ordered range of matching message-boards messages
6899             * @throws SystemException if a system exception occurred
6900             */
6901            public List<MBMessage> findByC_S(long companyId, int status, int start,
6902                    int end, OrderByComparator orderByComparator) throws SystemException {
6903                    boolean pagination = true;
6904                    FinderPath finderPath = null;
6905                    Object[] finderArgs = null;
6906    
6907                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
6908                                    (orderByComparator == null)) {
6909                            pagination = false;
6910                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S;
6911                            finderArgs = new Object[] { companyId, status };
6912                    }
6913                    else {
6914                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_S;
6915                            finderArgs = new Object[] {
6916                                            companyId, status,
6917                                            
6918                                            start, end, orderByComparator
6919                                    };
6920                    }
6921    
6922                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
6923                                    finderArgs, this);
6924    
6925                    if ((list != null) && !list.isEmpty()) {
6926                            for (MBMessage mbMessage : list) {
6927                                    if ((companyId != mbMessage.getCompanyId()) ||
6928                                                    (status != mbMessage.getStatus())) {
6929                                            list = null;
6930    
6931                                            break;
6932                                    }
6933                            }
6934                    }
6935    
6936                    if (list == null) {
6937                            StringBundler query = null;
6938    
6939                            if (orderByComparator != null) {
6940                                    query = new StringBundler(4 +
6941                                                    (orderByComparator.getOrderByFields().length * 3));
6942                            }
6943                            else {
6944                                    query = new StringBundler(4);
6945                            }
6946    
6947                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
6948    
6949                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
6950    
6951                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
6952    
6953                            if (orderByComparator != null) {
6954                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
6955                                            orderByComparator);
6956                            }
6957                            else
6958                             if (pagination) {
6959                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
6960                            }
6961    
6962                            String sql = query.toString();
6963    
6964                            Session session = null;
6965    
6966                            try {
6967                                    session = openSession();
6968    
6969                                    Query q = session.createQuery(sql);
6970    
6971                                    QueryPos qPos = QueryPos.getInstance(q);
6972    
6973                                    qPos.add(companyId);
6974    
6975                                    qPos.add(status);
6976    
6977                                    if (!pagination) {
6978                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6979                                                            start, end, false);
6980    
6981                                            Collections.sort(list);
6982    
6983                                            list = new UnmodifiableList<MBMessage>(list);
6984                                    }
6985                                    else {
6986                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
6987                                                            start, end);
6988                                    }
6989    
6990                                    cacheResult(list);
6991    
6992                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
6993                            }
6994                            catch (Exception e) {
6995                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
6996    
6997                                    throw processException(e);
6998                            }
6999                            finally {
7000                                    closeSession(session);
7001                            }
7002                    }
7003    
7004                    return list;
7005            }
7006    
7007            /**
7008             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7009             *
7010             * @param companyId the company ID
7011             * @param status the status
7012             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7013             * @return the first matching message-boards message
7014             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7015             * @throws SystemException if a system exception occurred
7016             */
7017            public MBMessage findByC_S_First(long companyId, int status,
7018                    OrderByComparator orderByComparator)
7019                    throws NoSuchMessageException, SystemException {
7020                    MBMessage mbMessage = fetchByC_S_First(companyId, status,
7021                                    orderByComparator);
7022    
7023                    if (mbMessage != null) {
7024                            return mbMessage;
7025                    }
7026    
7027                    StringBundler msg = new StringBundler(6);
7028    
7029                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7030    
7031                    msg.append("companyId=");
7032                    msg.append(companyId);
7033    
7034                    msg.append(", status=");
7035                    msg.append(status);
7036    
7037                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7038    
7039                    throw new NoSuchMessageException(msg.toString());
7040            }
7041    
7042            /**
7043             * Returns the first message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7044             *
7045             * @param companyId the company ID
7046             * @param status the status
7047             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7048             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7049             * @throws SystemException if a system exception occurred
7050             */
7051            public MBMessage fetchByC_S_First(long companyId, int status,
7052                    OrderByComparator orderByComparator) throws SystemException {
7053                    List<MBMessage> list = findByC_S(companyId, status, 0, 1,
7054                                    orderByComparator);
7055    
7056                    if (!list.isEmpty()) {
7057                            return list.get(0);
7058                    }
7059    
7060                    return null;
7061            }
7062    
7063            /**
7064             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7065             *
7066             * @param companyId the company ID
7067             * @param status the status
7068             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7069             * @return the last matching message-boards message
7070             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7071             * @throws SystemException if a system exception occurred
7072             */
7073            public MBMessage findByC_S_Last(long companyId, int status,
7074                    OrderByComparator orderByComparator)
7075                    throws NoSuchMessageException, SystemException {
7076                    MBMessage mbMessage = fetchByC_S_Last(companyId, status,
7077                                    orderByComparator);
7078    
7079                    if (mbMessage != null) {
7080                            return mbMessage;
7081                    }
7082    
7083                    StringBundler msg = new StringBundler(6);
7084    
7085                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7086    
7087                    msg.append("companyId=");
7088                    msg.append(companyId);
7089    
7090                    msg.append(", status=");
7091                    msg.append(status);
7092    
7093                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7094    
7095                    throw new NoSuchMessageException(msg.toString());
7096            }
7097    
7098            /**
7099             * Returns the last message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7100             *
7101             * @param companyId the company ID
7102             * @param status the status
7103             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7104             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7105             * @throws SystemException if a system exception occurred
7106             */
7107            public MBMessage fetchByC_S_Last(long companyId, int status,
7108                    OrderByComparator orderByComparator) throws SystemException {
7109                    int count = countByC_S(companyId, status);
7110    
7111                    List<MBMessage> list = findByC_S(companyId, status, count - 1, count,
7112                                    orderByComparator);
7113    
7114                    if (!list.isEmpty()) {
7115                            return list.get(0);
7116                    }
7117    
7118                    return null;
7119            }
7120    
7121            /**
7122             * Returns the message-boards messages before and after the current message-boards message in the ordered set where companyId = &#63; and status = &#63;.
7123             *
7124             * @param messageId the primary key of the current message-boards message
7125             * @param companyId the company ID
7126             * @param status the status
7127             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7128             * @return the previous, current, and next message-boards message
7129             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7130             * @throws SystemException if a system exception occurred
7131             */
7132            public MBMessage[] findByC_S_PrevAndNext(long messageId, long companyId,
7133                    int status, OrderByComparator orderByComparator)
7134                    throws NoSuchMessageException, SystemException {
7135                    MBMessage mbMessage = findByPrimaryKey(messageId);
7136    
7137                    Session session = null;
7138    
7139                    try {
7140                            session = openSession();
7141    
7142                            MBMessage[] array = new MBMessageImpl[3];
7143    
7144                            array[0] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7145                                            status, orderByComparator, true);
7146    
7147                            array[1] = mbMessage;
7148    
7149                            array[2] = getByC_S_PrevAndNext(session, mbMessage, companyId,
7150                                            status, orderByComparator, false);
7151    
7152                            return array;
7153                    }
7154                    catch (Exception e) {
7155                            throw processException(e);
7156                    }
7157                    finally {
7158                            closeSession(session);
7159                    }
7160            }
7161    
7162            protected MBMessage getByC_S_PrevAndNext(Session session,
7163                    MBMessage mbMessage, long companyId, int status,
7164                    OrderByComparator orderByComparator, boolean previous) {
7165                    StringBundler query = null;
7166    
7167                    if (orderByComparator != null) {
7168                            query = new StringBundler(6 +
7169                                            (orderByComparator.getOrderByFields().length * 6));
7170                    }
7171                    else {
7172                            query = new StringBundler(3);
7173                    }
7174    
7175                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7176    
7177                    query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7178    
7179                    query.append(_FINDER_COLUMN_C_S_STATUS_2);
7180    
7181                    if (orderByComparator != null) {
7182                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7183    
7184                            if (orderByConditionFields.length > 0) {
7185                                    query.append(WHERE_AND);
7186                            }
7187    
7188                            for (int i = 0; i < orderByConditionFields.length; i++) {
7189                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7190                                    query.append(orderByConditionFields[i]);
7191    
7192                                    if ((i + 1) < orderByConditionFields.length) {
7193                                            if (orderByComparator.isAscending() ^ previous) {
7194                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7195                                            }
7196                                            else {
7197                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7198                                            }
7199                                    }
7200                                    else {
7201                                            if (orderByComparator.isAscending() ^ previous) {
7202                                                    query.append(WHERE_GREATER_THAN);
7203                                            }
7204                                            else {
7205                                                    query.append(WHERE_LESSER_THAN);
7206                                            }
7207                                    }
7208                            }
7209    
7210                            query.append(ORDER_BY_CLAUSE);
7211    
7212                            String[] orderByFields = orderByComparator.getOrderByFields();
7213    
7214                            for (int i = 0; i < orderByFields.length; i++) {
7215                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7216                                    query.append(orderByFields[i]);
7217    
7218                                    if ((i + 1) < orderByFields.length) {
7219                                            if (orderByComparator.isAscending() ^ previous) {
7220                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7221                                            }
7222                                            else {
7223                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7224                                            }
7225                                    }
7226                                    else {
7227                                            if (orderByComparator.isAscending() ^ previous) {
7228                                                    query.append(ORDER_BY_ASC);
7229                                            }
7230                                            else {
7231                                                    query.append(ORDER_BY_DESC);
7232                                            }
7233                                    }
7234                            }
7235                    }
7236                    else {
7237                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7238                    }
7239    
7240                    String sql = query.toString();
7241    
7242                    Query q = session.createQuery(sql);
7243    
7244                    q.setFirstResult(0);
7245                    q.setMaxResults(2);
7246    
7247                    QueryPos qPos = QueryPos.getInstance(q);
7248    
7249                    qPos.add(companyId);
7250    
7251                    qPos.add(status);
7252    
7253                    if (orderByComparator != null) {
7254                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7255    
7256                            for (Object value : values) {
7257                                    qPos.add(value);
7258                            }
7259                    }
7260    
7261                    List<MBMessage> list = q.list();
7262    
7263                    if (list.size() == 2) {
7264                            return list.get(1);
7265                    }
7266                    else {
7267                            return null;
7268                    }
7269            }
7270    
7271            /**
7272             * Removes all the message-boards messages where companyId = &#63; and status = &#63; from the database.
7273             *
7274             * @param companyId the company ID
7275             * @param status the status
7276             * @throws SystemException if a system exception occurred
7277             */
7278            public void removeByC_S(long companyId, int status)
7279                    throws SystemException {
7280                    for (MBMessage mbMessage : findByC_S(companyId, status,
7281                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7282                            remove(mbMessage);
7283                    }
7284            }
7285    
7286            /**
7287             * Returns the number of message-boards messages where companyId = &#63; and status = &#63;.
7288             *
7289             * @param companyId the company ID
7290             * @param status the status
7291             * @return the number of matching message-boards messages
7292             * @throws SystemException if a system exception occurred
7293             */
7294            public int countByC_S(long companyId, int status) throws SystemException {
7295                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_S;
7296    
7297                    Object[] finderArgs = new Object[] { companyId, status };
7298    
7299                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
7300                                    this);
7301    
7302                    if (count == null) {
7303                            StringBundler query = new StringBundler(3);
7304    
7305                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
7306    
7307                            query.append(_FINDER_COLUMN_C_S_COMPANYID_2);
7308    
7309                            query.append(_FINDER_COLUMN_C_S_STATUS_2);
7310    
7311                            String sql = query.toString();
7312    
7313                            Session session = null;
7314    
7315                            try {
7316                                    session = openSession();
7317    
7318                                    Query q = session.createQuery(sql);
7319    
7320                                    QueryPos qPos = QueryPos.getInstance(q);
7321    
7322                                    qPos.add(companyId);
7323    
7324                                    qPos.add(status);
7325    
7326                                    count = (Long)q.uniqueResult();
7327    
7328                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
7329                            }
7330                            catch (Exception e) {
7331                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7332    
7333                                    throw processException(e);
7334                            }
7335                            finally {
7336                                    closeSession(session);
7337                            }
7338                    }
7339    
7340                    return count.intValue();
7341            }
7342    
7343            private static final String _FINDER_COLUMN_C_S_COMPANYID_2 = "mbMessage.companyId = ? AND ";
7344            private static final String _FINDER_COLUMN_C_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
7345            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7346                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7347                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C",
7348                            new String[] {
7349                                    Long.class.getName(), Long.class.getName(),
7350                                    
7351                            Integer.class.getName(), Integer.class.getName(),
7352                                    OrderByComparator.class.getName()
7353                            });
7354            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7355                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
7356                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C",
7357                            new String[] { Long.class.getName(), Long.class.getName() },
7358                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
7359                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
7360                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
7361            public static final FinderPath FINDER_PATH_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7362                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7363                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C",
7364                            new String[] { Long.class.getName(), Long.class.getName() });
7365            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
7366                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
7367                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C",
7368                            new String[] { Long.class.getName(), Long.class.getName() });
7369    
7370            /**
7371             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63;.
7372             *
7373             * @param userId the user ID
7374             * @param classNameId the class name ID
7375             * @return the matching message-boards messages
7376             * @throws SystemException if a system exception occurred
7377             */
7378            public List<MBMessage> findByU_C(long userId, long classNameId)
7379                    throws SystemException {
7380                    return findByU_C(userId, classNameId, QueryUtil.ALL_POS,
7381                            QueryUtil.ALL_POS, null);
7382            }
7383    
7384            /**
7385             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7386             *
7387             * <p>
7388             * 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.
7389             * </p>
7390             *
7391             * @param userId the user ID
7392             * @param classNameId the class name ID
7393             * @param start the lower bound of the range of message-boards messages
7394             * @param end the upper bound of the range of message-boards messages (not inclusive)
7395             * @return the range of matching message-boards messages
7396             * @throws SystemException if a system exception occurred
7397             */
7398            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7399                    int end) throws SystemException {
7400                    return findByU_C(userId, classNameId, start, end, null);
7401            }
7402    
7403            /**
7404             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63;.
7405             *
7406             * <p>
7407             * 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.
7408             * </p>
7409             *
7410             * @param userId the user ID
7411             * @param classNameId the class name ID
7412             * @param start the lower bound of the range of message-boards messages
7413             * @param end the upper bound of the range of message-boards messages (not inclusive)
7414             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7415             * @return the ordered range of matching message-boards messages
7416             * @throws SystemException if a system exception occurred
7417             */
7418            public List<MBMessage> findByU_C(long userId, long classNameId, int start,
7419                    int end, OrderByComparator orderByComparator) throws SystemException {
7420                    boolean pagination = true;
7421                    FinderPath finderPath = null;
7422                    Object[] finderArgs = null;
7423    
7424                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7425                                    (orderByComparator == null)) {
7426                            pagination = false;
7427                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C;
7428                            finderArgs = new Object[] { userId, classNameId };
7429                    }
7430                    else {
7431                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C;
7432                            finderArgs = new Object[] {
7433                                            userId, classNameId,
7434                                            
7435                                            start, end, orderByComparator
7436                                    };
7437                    }
7438    
7439                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
7440                                    finderArgs, this);
7441    
7442                    if ((list != null) && !list.isEmpty()) {
7443                            for (MBMessage mbMessage : list) {
7444                                    if ((userId != mbMessage.getUserId()) ||
7445                                                    (classNameId != mbMessage.getClassNameId())) {
7446                                            list = null;
7447    
7448                                            break;
7449                                    }
7450                            }
7451                    }
7452    
7453                    if (list == null) {
7454                            StringBundler query = null;
7455    
7456                            if (orderByComparator != null) {
7457                                    query = new StringBundler(4 +
7458                                                    (orderByComparator.getOrderByFields().length * 3));
7459                            }
7460                            else {
7461                                    query = new StringBundler(4);
7462                            }
7463    
7464                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7465    
7466                            query.append(_FINDER_COLUMN_U_C_USERID_2);
7467    
7468                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7469    
7470                            if (orderByComparator != null) {
7471                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7472                                            orderByComparator);
7473                            }
7474                            else
7475                             if (pagination) {
7476                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7477                            }
7478    
7479                            String sql = query.toString();
7480    
7481                            Session session = null;
7482    
7483                            try {
7484                                    session = openSession();
7485    
7486                                    Query q = session.createQuery(sql);
7487    
7488                                    QueryPos qPos = QueryPos.getInstance(q);
7489    
7490                                    qPos.add(userId);
7491    
7492                                    qPos.add(classNameId);
7493    
7494                                    if (!pagination) {
7495                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7496                                                            start, end, false);
7497    
7498                                            Collections.sort(list);
7499    
7500                                            list = new UnmodifiableList<MBMessage>(list);
7501                                    }
7502                                    else {
7503                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7504                                                            start, end);
7505                                    }
7506    
7507                                    cacheResult(list);
7508    
7509                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
7510                            }
7511                            catch (Exception e) {
7512                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
7513    
7514                                    throw processException(e);
7515                            }
7516                            finally {
7517                                    closeSession(session);
7518                            }
7519                    }
7520    
7521                    return list;
7522            }
7523    
7524            /**
7525             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7526             *
7527             * @param userId the user ID
7528             * @param classNameId the class name ID
7529             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7530             * @return the first matching message-boards message
7531             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7532             * @throws SystemException if a system exception occurred
7533             */
7534            public MBMessage findByU_C_First(long userId, long classNameId,
7535                    OrderByComparator orderByComparator)
7536                    throws NoSuchMessageException, SystemException {
7537                    MBMessage mbMessage = fetchByU_C_First(userId, classNameId,
7538                                    orderByComparator);
7539    
7540                    if (mbMessage != null) {
7541                            return mbMessage;
7542                    }
7543    
7544                    StringBundler msg = new StringBundler(6);
7545    
7546                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7547    
7548                    msg.append("userId=");
7549                    msg.append(userId);
7550    
7551                    msg.append(", classNameId=");
7552                    msg.append(classNameId);
7553    
7554                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7555    
7556                    throw new NoSuchMessageException(msg.toString());
7557            }
7558    
7559            /**
7560             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7561             *
7562             * @param userId the user ID
7563             * @param classNameId the class name ID
7564             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7565             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7566             * @throws SystemException if a system exception occurred
7567             */
7568            public MBMessage fetchByU_C_First(long userId, long classNameId,
7569                    OrderByComparator orderByComparator) throws SystemException {
7570                    List<MBMessage> list = findByU_C(userId, classNameId, 0, 1,
7571                                    orderByComparator);
7572    
7573                    if (!list.isEmpty()) {
7574                            return list.get(0);
7575                    }
7576    
7577                    return null;
7578            }
7579    
7580            /**
7581             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7582             *
7583             * @param userId the user ID
7584             * @param classNameId the class name ID
7585             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7586             * @return the last matching message-boards message
7587             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
7588             * @throws SystemException if a system exception occurred
7589             */
7590            public MBMessage findByU_C_Last(long userId, long classNameId,
7591                    OrderByComparator orderByComparator)
7592                    throws NoSuchMessageException, SystemException {
7593                    MBMessage mbMessage = fetchByU_C_Last(userId, classNameId,
7594                                    orderByComparator);
7595    
7596                    if (mbMessage != null) {
7597                            return mbMessage;
7598                    }
7599    
7600                    StringBundler msg = new StringBundler(6);
7601    
7602                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
7603    
7604                    msg.append("userId=");
7605                    msg.append(userId);
7606    
7607                    msg.append(", classNameId=");
7608                    msg.append(classNameId);
7609    
7610                    msg.append(StringPool.CLOSE_CURLY_BRACE);
7611    
7612                    throw new NoSuchMessageException(msg.toString());
7613            }
7614    
7615            /**
7616             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7617             *
7618             * @param userId the user ID
7619             * @param classNameId the class name ID
7620             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7621             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
7622             * @throws SystemException if a system exception occurred
7623             */
7624            public MBMessage fetchByU_C_Last(long userId, long classNameId,
7625                    OrderByComparator orderByComparator) throws SystemException {
7626                    int count = countByU_C(userId, classNameId);
7627    
7628                    List<MBMessage> list = findByU_C(userId, classNameId, count - 1, count,
7629                                    orderByComparator);
7630    
7631                    if (!list.isEmpty()) {
7632                            return list.get(0);
7633                    }
7634    
7635                    return null;
7636            }
7637    
7638            /**
7639             * Returns the message-boards messages before and after the current message-boards message in the ordered set where userId = &#63; and classNameId = &#63;.
7640             *
7641             * @param messageId the primary key of the current message-boards message
7642             * @param userId the user ID
7643             * @param classNameId the class name ID
7644             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
7645             * @return the previous, current, and next message-boards message
7646             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
7647             * @throws SystemException if a system exception occurred
7648             */
7649            public MBMessage[] findByU_C_PrevAndNext(long messageId, long userId,
7650                    long classNameId, OrderByComparator orderByComparator)
7651                    throws NoSuchMessageException, SystemException {
7652                    MBMessage mbMessage = findByPrimaryKey(messageId);
7653    
7654                    Session session = null;
7655    
7656                    try {
7657                            session = openSession();
7658    
7659                            MBMessage[] array = new MBMessageImpl[3];
7660    
7661                            array[0] = getByU_C_PrevAndNext(session, mbMessage, userId,
7662                                            classNameId, orderByComparator, true);
7663    
7664                            array[1] = mbMessage;
7665    
7666                            array[2] = getByU_C_PrevAndNext(session, mbMessage, userId,
7667                                            classNameId, orderByComparator, false);
7668    
7669                            return array;
7670                    }
7671                    catch (Exception e) {
7672                            throw processException(e);
7673                    }
7674                    finally {
7675                            closeSession(session);
7676                    }
7677            }
7678    
7679            protected MBMessage getByU_C_PrevAndNext(Session session,
7680                    MBMessage mbMessage, long userId, long classNameId,
7681                    OrderByComparator orderByComparator, boolean previous) {
7682                    StringBundler query = null;
7683    
7684                    if (orderByComparator != null) {
7685                            query = new StringBundler(6 +
7686                                            (orderByComparator.getOrderByFields().length * 6));
7687                    }
7688                    else {
7689                            query = new StringBundler(3);
7690                    }
7691    
7692                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7693    
7694                    query.append(_FINDER_COLUMN_U_C_USERID_2);
7695    
7696                    query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
7697    
7698                    if (orderByComparator != null) {
7699                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
7700    
7701                            if (orderByConditionFields.length > 0) {
7702                                    query.append(WHERE_AND);
7703                            }
7704    
7705                            for (int i = 0; i < orderByConditionFields.length; i++) {
7706                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7707                                    query.append(orderByConditionFields[i]);
7708    
7709                                    if ((i + 1) < orderByConditionFields.length) {
7710                                            if (orderByComparator.isAscending() ^ previous) {
7711                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
7712                                            }
7713                                            else {
7714                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
7715                                            }
7716                                    }
7717                                    else {
7718                                            if (orderByComparator.isAscending() ^ previous) {
7719                                                    query.append(WHERE_GREATER_THAN);
7720                                            }
7721                                            else {
7722                                                    query.append(WHERE_LESSER_THAN);
7723                                            }
7724                                    }
7725                            }
7726    
7727                            query.append(ORDER_BY_CLAUSE);
7728    
7729                            String[] orderByFields = orderByComparator.getOrderByFields();
7730    
7731                            for (int i = 0; i < orderByFields.length; i++) {
7732                                    query.append(_ORDER_BY_ENTITY_ALIAS);
7733                                    query.append(orderByFields[i]);
7734    
7735                                    if ((i + 1) < orderByFields.length) {
7736                                            if (orderByComparator.isAscending() ^ previous) {
7737                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
7738                                            }
7739                                            else {
7740                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
7741                                            }
7742                                    }
7743                                    else {
7744                                            if (orderByComparator.isAscending() ^ previous) {
7745                                                    query.append(ORDER_BY_ASC);
7746                                            }
7747                                            else {
7748                                                    query.append(ORDER_BY_DESC);
7749                                            }
7750                                    }
7751                            }
7752                    }
7753                    else {
7754                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7755                    }
7756    
7757                    String sql = query.toString();
7758    
7759                    Query q = session.createQuery(sql);
7760    
7761                    q.setFirstResult(0);
7762                    q.setMaxResults(2);
7763    
7764                    QueryPos qPos = QueryPos.getInstance(q);
7765    
7766                    qPos.add(userId);
7767    
7768                    qPos.add(classNameId);
7769    
7770                    if (orderByComparator != null) {
7771                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
7772    
7773                            for (Object value : values) {
7774                                    qPos.add(value);
7775                            }
7776                    }
7777    
7778                    List<MBMessage> list = q.list();
7779    
7780                    if (list.size() == 2) {
7781                            return list.get(1);
7782                    }
7783                    else {
7784                            return null;
7785                    }
7786            }
7787    
7788            /**
7789             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7790             *
7791             * <p>
7792             * 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.
7793             * </p>
7794             *
7795             * @param userId the user ID
7796             * @param classNameIds the class name IDs
7797             * @return the matching message-boards messages
7798             * @throws SystemException if a system exception occurred
7799             */
7800            public List<MBMessage> findByU_C(long userId, long[] classNameIds)
7801                    throws SystemException {
7802                    return findByU_C(userId, classNameIds, QueryUtil.ALL_POS,
7803                            QueryUtil.ALL_POS, null);
7804            }
7805    
7806            /**
7807             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7808             *
7809             * <p>
7810             * 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.
7811             * </p>
7812             *
7813             * @param userId the user ID
7814             * @param classNameIds the class name IDs
7815             * @param start the lower bound of the range of message-boards messages
7816             * @param end the upper bound of the range of message-boards messages (not inclusive)
7817             * @return the range of matching message-boards messages
7818             * @throws SystemException if a system exception occurred
7819             */
7820            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7821                    int start, int end) throws SystemException {
7822                    return findByU_C(userId, classNameIds, start, end, null);
7823            }
7824    
7825            /**
7826             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63;.
7827             *
7828             * <p>
7829             * 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.
7830             * </p>
7831             *
7832             * @param userId the user ID
7833             * @param classNameIds the class name IDs
7834             * @param start the lower bound of the range of message-boards messages
7835             * @param end the upper bound of the range of message-boards messages (not inclusive)
7836             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
7837             * @return the ordered range of matching message-boards messages
7838             * @throws SystemException if a system exception occurred
7839             */
7840            public List<MBMessage> findByU_C(long userId, long[] classNameIds,
7841                    int start, int end, OrderByComparator orderByComparator)
7842                    throws SystemException {
7843                    if ((classNameIds != null) && (classNameIds.length == 1)) {
7844                            return findByU_C(userId, classNameIds[0], start, end,
7845                                    orderByComparator);
7846                    }
7847    
7848                    boolean pagination = true;
7849                    Object[] finderArgs = null;
7850    
7851                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
7852                                    (orderByComparator == null)) {
7853                            pagination = false;
7854                            finderArgs = new Object[] { userId, StringUtil.merge(classNameIds) };
7855                    }
7856                    else {
7857                            finderArgs = new Object[] {
7858                                            userId, StringUtil.merge(classNameIds),
7859                                            
7860                                            start, end, orderByComparator
7861                                    };
7862                    }
7863    
7864                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7865                                    finderArgs, this);
7866    
7867                    if ((list != null) && !list.isEmpty()) {
7868                            for (MBMessage mbMessage : list) {
7869                                    if ((userId != mbMessage.getUserId()) ||
7870                                                    !ArrayUtil.contains(classNameIds,
7871                                                            mbMessage.getClassNameId())) {
7872                                            list = null;
7873    
7874                                            break;
7875                                    }
7876                            }
7877                    }
7878    
7879                    if (list == null) {
7880                            StringBundler query = new StringBundler();
7881    
7882                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
7883    
7884                            boolean conjunctionable = false;
7885    
7886                            if (conjunctionable) {
7887                                    query.append(WHERE_AND);
7888                            }
7889    
7890                            query.append(_FINDER_COLUMN_U_C_USERID_5);
7891    
7892                            conjunctionable = true;
7893    
7894                            if ((classNameIds == null) || (classNameIds.length > 0)) {
7895                                    if (conjunctionable) {
7896                                            query.append(WHERE_AND);
7897                                    }
7898    
7899                                    query.append(StringPool.OPEN_PARENTHESIS);
7900    
7901                                    for (int i = 0; i < classNameIds.length; i++) {
7902                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
7903    
7904                                            if ((i + 1) < classNameIds.length) {
7905                                                    query.append(WHERE_OR);
7906                                            }
7907                                    }
7908    
7909                                    query.append(StringPool.CLOSE_PARENTHESIS);
7910    
7911                                    conjunctionable = true;
7912                            }
7913    
7914                            if (orderByComparator != null) {
7915                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
7916                                            orderByComparator);
7917                            }
7918                            else
7919                             if (pagination) {
7920                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
7921                            }
7922    
7923                            String sql = query.toString();
7924    
7925                            Session session = null;
7926    
7927                            try {
7928                                    session = openSession();
7929    
7930                                    Query q = session.createQuery(sql);
7931    
7932                                    QueryPos qPos = QueryPos.getInstance(q);
7933    
7934                                    qPos.add(userId);
7935    
7936                                    if (classNameIds != null) {
7937                                            qPos.add(classNameIds);
7938                                    }
7939    
7940                                    if (!pagination) {
7941                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7942                                                            start, end, false);
7943    
7944                                            Collections.sort(list);
7945    
7946                                            list = new UnmodifiableList<MBMessage>(list);
7947                                    }
7948                                    else {
7949                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
7950                                                            start, end);
7951                                    }
7952    
7953                                    cacheResult(list);
7954    
7955                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7956                                            finderArgs, list);
7957                            }
7958                            catch (Exception e) {
7959                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C,
7960                                            finderArgs);
7961    
7962                                    throw processException(e);
7963                            }
7964                            finally {
7965                                    closeSession(session);
7966                            }
7967                    }
7968    
7969                    return list;
7970            }
7971    
7972            /**
7973             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; from the database.
7974             *
7975             * @param userId the user ID
7976             * @param classNameId the class name ID
7977             * @throws SystemException if a system exception occurred
7978             */
7979            public void removeByU_C(long userId, long classNameId)
7980                    throws SystemException {
7981                    for (MBMessage mbMessage : findByU_C(userId, classNameId,
7982                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
7983                            remove(mbMessage);
7984                    }
7985            }
7986    
7987            /**
7988             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63;.
7989             *
7990             * @param userId the user ID
7991             * @param classNameId the class name ID
7992             * @return the number of matching message-boards messages
7993             * @throws SystemException if a system exception occurred
7994             */
7995            public int countByU_C(long userId, long classNameId)
7996                    throws SystemException {
7997                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C;
7998    
7999                    Object[] finderArgs = new Object[] { userId, classNameId };
8000    
8001                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8002                                    this);
8003    
8004                    if (count == null) {
8005                            StringBundler query = new StringBundler(3);
8006    
8007                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8008    
8009                            query.append(_FINDER_COLUMN_U_C_USERID_2);
8010    
8011                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_2);
8012    
8013                            String sql = query.toString();
8014    
8015                            Session session = null;
8016    
8017                            try {
8018                                    session = openSession();
8019    
8020                                    Query q = session.createQuery(sql);
8021    
8022                                    QueryPos qPos = QueryPos.getInstance(q);
8023    
8024                                    qPos.add(userId);
8025    
8026                                    qPos.add(classNameId);
8027    
8028                                    count = (Long)q.uniqueResult();
8029    
8030                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8031                            }
8032                            catch (Exception e) {
8033                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8034    
8035                                    throw processException(e);
8036                            }
8037                            finally {
8038                                    closeSession(session);
8039                            }
8040                    }
8041    
8042                    return count.intValue();
8043            }
8044    
8045            /**
8046             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63;.
8047             *
8048             * @param userId the user ID
8049             * @param classNameIds the class name IDs
8050             * @return the number of matching message-boards messages
8051             * @throws SystemException if a system exception occurred
8052             */
8053            public int countByU_C(long userId, long[] classNameIds)
8054                    throws SystemException {
8055                    Object[] finderArgs = new Object[] {
8056                                    userId, StringUtil.merge(classNameIds)
8057                            };
8058    
8059                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8060                                    finderArgs, this);
8061    
8062                    if (count == null) {
8063                            StringBundler query = new StringBundler();
8064    
8065                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8066    
8067                            boolean conjunctionable = false;
8068    
8069                            if (conjunctionable) {
8070                                    query.append(WHERE_AND);
8071                            }
8072    
8073                            query.append(_FINDER_COLUMN_U_C_USERID_5);
8074    
8075                            conjunctionable = true;
8076    
8077                            if ((classNameIds == null) || (classNameIds.length > 0)) {
8078                                    if (conjunctionable) {
8079                                            query.append(WHERE_AND);
8080                                    }
8081    
8082                                    query.append(StringPool.OPEN_PARENTHESIS);
8083    
8084                                    for (int i = 0; i < classNameIds.length; i++) {
8085                                            query.append(_FINDER_COLUMN_U_C_CLASSNAMEID_5);
8086    
8087                                            if ((i + 1) < classNameIds.length) {
8088                                                    query.append(WHERE_OR);
8089                                            }
8090                                    }
8091    
8092                                    query.append(StringPool.CLOSE_PARENTHESIS);
8093    
8094                                    conjunctionable = true;
8095                            }
8096    
8097                            String sql = query.toString();
8098    
8099                            Session session = null;
8100    
8101                            try {
8102                                    session = openSession();
8103    
8104                                    Query q = session.createQuery(sql);
8105    
8106                                    QueryPos qPos = QueryPos.getInstance(q);
8107    
8108                                    qPos.add(userId);
8109    
8110                                    if (classNameIds != null) {
8111                                            qPos.add(classNameIds);
8112                                    }
8113    
8114                                    count = (Long)q.uniqueResult();
8115    
8116                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8117                                            finderArgs, count);
8118                            }
8119                            catch (Exception e) {
8120                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C,
8121                                            finderArgs);
8122    
8123                                    throw processException(e);
8124                            }
8125                            finally {
8126                                    closeSession(session);
8127                            }
8128                    }
8129    
8130                    return count.intValue();
8131            }
8132    
8133            private static final String _FINDER_COLUMN_U_C_USERID_2 = "mbMessage.userId = ? AND ";
8134            private static final String _FINDER_COLUMN_U_C_USERID_5 = "(" +
8135                    removeConjunction(_FINDER_COLUMN_U_C_USERID_2) + ")";
8136            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_2 = "mbMessage.classNameId = ?";
8137            private static final String _FINDER_COLUMN_U_C_CLASSNAMEID_5 = "(" +
8138                    removeConjunction(_FINDER_COLUMN_U_C_CLASSNAMEID_2) + ")";
8139            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8140                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8141                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
8142                            new String[] {
8143                                    Long.class.getName(), Long.class.getName(),
8144                                    
8145                            Integer.class.getName(), Integer.class.getName(),
8146                                    OrderByComparator.class.getName()
8147                            });
8148            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8149                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8150                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
8151                            new String[] { Long.class.getName(), Long.class.getName() },
8152                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
8153                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
8154                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8155            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8156                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8157                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
8158                            new String[] { Long.class.getName(), Long.class.getName() });
8159    
8160            /**
8161             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8162             *
8163             * @param classNameId the class name ID
8164             * @param classPK the class p k
8165             * @return the matching message-boards messages
8166             * @throws SystemException if a system exception occurred
8167             */
8168            public List<MBMessage> findByC_C(long classNameId, long classPK)
8169                    throws SystemException {
8170                    return findByC_C(classNameId, classPK, QueryUtil.ALL_POS,
8171                            QueryUtil.ALL_POS, null);
8172            }
8173    
8174            /**
8175             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8176             *
8177             * <p>
8178             * 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.
8179             * </p>
8180             *
8181             * @param classNameId the class name ID
8182             * @param classPK the class p k
8183             * @param start the lower bound of the range of message-boards messages
8184             * @param end the upper bound of the range of message-boards messages (not inclusive)
8185             * @return the range of matching message-boards messages
8186             * @throws SystemException if a system exception occurred
8187             */
8188            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8189                    int end) throws SystemException {
8190                    return findByC_C(classNameId, classPK, start, end, null);
8191            }
8192    
8193            /**
8194             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63;.
8195             *
8196             * <p>
8197             * 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.
8198             * </p>
8199             *
8200             * @param classNameId the class name ID
8201             * @param classPK the class p k
8202             * @param start the lower bound of the range of message-boards messages
8203             * @param end the upper bound of the range of message-boards messages (not inclusive)
8204             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8205             * @return the ordered range of matching message-boards messages
8206             * @throws SystemException if a system exception occurred
8207             */
8208            public List<MBMessage> findByC_C(long classNameId, long classPK, int start,
8209                    int end, OrderByComparator orderByComparator) throws SystemException {
8210                    boolean pagination = true;
8211                    FinderPath finderPath = null;
8212                    Object[] finderArgs = null;
8213    
8214                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8215                                    (orderByComparator == null)) {
8216                            pagination = false;
8217                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
8218                            finderArgs = new Object[] { classNameId, classPK };
8219                    }
8220                    else {
8221                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
8222                            finderArgs = new Object[] {
8223                                            classNameId, classPK,
8224                                            
8225                                            start, end, orderByComparator
8226                                    };
8227                    }
8228    
8229                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8230                                    finderArgs, this);
8231    
8232                    if ((list != null) && !list.isEmpty()) {
8233                            for (MBMessage mbMessage : list) {
8234                                    if ((classNameId != mbMessage.getClassNameId()) ||
8235                                                    (classPK != mbMessage.getClassPK())) {
8236                                            list = null;
8237    
8238                                            break;
8239                                    }
8240                            }
8241                    }
8242    
8243                    if (list == null) {
8244                            StringBundler query = null;
8245    
8246                            if (orderByComparator != null) {
8247                                    query = new StringBundler(4 +
8248                                                    (orderByComparator.getOrderByFields().length * 3));
8249                            }
8250                            else {
8251                                    query = new StringBundler(4);
8252                            }
8253    
8254                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8255    
8256                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8257    
8258                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8259    
8260                            if (orderByComparator != null) {
8261                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8262                                            orderByComparator);
8263                            }
8264                            else
8265                             if (pagination) {
8266                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8267                            }
8268    
8269                            String sql = query.toString();
8270    
8271                            Session session = null;
8272    
8273                            try {
8274                                    session = openSession();
8275    
8276                                    Query q = session.createQuery(sql);
8277    
8278                                    QueryPos qPos = QueryPos.getInstance(q);
8279    
8280                                    qPos.add(classNameId);
8281    
8282                                    qPos.add(classPK);
8283    
8284                                    if (!pagination) {
8285                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8286                                                            start, end, false);
8287    
8288                                            Collections.sort(list);
8289    
8290                                            list = new UnmodifiableList<MBMessage>(list);
8291                                    }
8292                                    else {
8293                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8294                                                            start, end);
8295                                    }
8296    
8297                                    cacheResult(list);
8298    
8299                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8300                            }
8301                            catch (Exception e) {
8302                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8303    
8304                                    throw processException(e);
8305                            }
8306                            finally {
8307                                    closeSession(session);
8308                            }
8309                    }
8310    
8311                    return list;
8312            }
8313    
8314            /**
8315             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8316             *
8317             * @param classNameId the class name ID
8318             * @param classPK the class p k
8319             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8320             * @return the first matching message-boards message
8321             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8322             * @throws SystemException if a system exception occurred
8323             */
8324            public MBMessage findByC_C_First(long classNameId, long classPK,
8325                    OrderByComparator orderByComparator)
8326                    throws NoSuchMessageException, SystemException {
8327                    MBMessage mbMessage = fetchByC_C_First(classNameId, classPK,
8328                                    orderByComparator);
8329    
8330                    if (mbMessage != null) {
8331                            return mbMessage;
8332                    }
8333    
8334                    StringBundler msg = new StringBundler(6);
8335    
8336                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8337    
8338                    msg.append("classNameId=");
8339                    msg.append(classNameId);
8340    
8341                    msg.append(", classPK=");
8342                    msg.append(classPK);
8343    
8344                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8345    
8346                    throw new NoSuchMessageException(msg.toString());
8347            }
8348    
8349            /**
8350             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8351             *
8352             * @param classNameId the class name ID
8353             * @param classPK the class p k
8354             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8355             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8356             * @throws SystemException if a system exception occurred
8357             */
8358            public MBMessage fetchByC_C_First(long classNameId, long classPK,
8359                    OrderByComparator orderByComparator) throws SystemException {
8360                    List<MBMessage> list = findByC_C(classNameId, classPK, 0, 1,
8361                                    orderByComparator);
8362    
8363                    if (!list.isEmpty()) {
8364                            return list.get(0);
8365                    }
8366    
8367                    return null;
8368            }
8369    
8370            /**
8371             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8372             *
8373             * @param classNameId the class name ID
8374             * @param classPK the class p k
8375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8376             * @return the last matching message-boards message
8377             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8378             * @throws SystemException if a system exception occurred
8379             */
8380            public MBMessage findByC_C_Last(long classNameId, long classPK,
8381                    OrderByComparator orderByComparator)
8382                    throws NoSuchMessageException, SystemException {
8383                    MBMessage mbMessage = fetchByC_C_Last(classNameId, classPK,
8384                                    orderByComparator);
8385    
8386                    if (mbMessage != null) {
8387                            return mbMessage;
8388                    }
8389    
8390                    StringBundler msg = new StringBundler(6);
8391    
8392                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8393    
8394                    msg.append("classNameId=");
8395                    msg.append(classNameId);
8396    
8397                    msg.append(", classPK=");
8398                    msg.append(classPK);
8399    
8400                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8401    
8402                    throw new NoSuchMessageException(msg.toString());
8403            }
8404    
8405            /**
8406             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8407             *
8408             * @param classNameId the class name ID
8409             * @param classPK the class p k
8410             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8411             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8412             * @throws SystemException if a system exception occurred
8413             */
8414            public MBMessage fetchByC_C_Last(long classNameId, long classPK,
8415                    OrderByComparator orderByComparator) throws SystemException {
8416                    int count = countByC_C(classNameId, classPK);
8417    
8418                    List<MBMessage> list = findByC_C(classNameId, classPK, count - 1,
8419                                    count, orderByComparator);
8420    
8421                    if (!list.isEmpty()) {
8422                            return list.get(0);
8423                    }
8424    
8425                    return null;
8426            }
8427    
8428            /**
8429             * Returns the message-boards messages before and after the current message-boards message in the ordered set where classNameId = &#63; and classPK = &#63;.
8430             *
8431             * @param messageId the primary key of the current message-boards message
8432             * @param classNameId the class name ID
8433             * @param classPK the class p k
8434             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8435             * @return the previous, current, and next message-boards message
8436             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8437             * @throws SystemException if a system exception occurred
8438             */
8439            public MBMessage[] findByC_C_PrevAndNext(long messageId, long classNameId,
8440                    long classPK, OrderByComparator orderByComparator)
8441                    throws NoSuchMessageException, SystemException {
8442                    MBMessage mbMessage = findByPrimaryKey(messageId);
8443    
8444                    Session session = null;
8445    
8446                    try {
8447                            session = openSession();
8448    
8449                            MBMessage[] array = new MBMessageImpl[3];
8450    
8451                            array[0] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8452                                            classPK, orderByComparator, true);
8453    
8454                            array[1] = mbMessage;
8455    
8456                            array[2] = getByC_C_PrevAndNext(session, mbMessage, classNameId,
8457                                            classPK, orderByComparator, false);
8458    
8459                            return array;
8460                    }
8461                    catch (Exception e) {
8462                            throw processException(e);
8463                    }
8464                    finally {
8465                            closeSession(session);
8466                    }
8467            }
8468    
8469            protected MBMessage getByC_C_PrevAndNext(Session session,
8470                    MBMessage mbMessage, long classNameId, long classPK,
8471                    OrderByComparator orderByComparator, boolean previous) {
8472                    StringBundler query = null;
8473    
8474                    if (orderByComparator != null) {
8475                            query = new StringBundler(6 +
8476                                            (orderByComparator.getOrderByFields().length * 6));
8477                    }
8478                    else {
8479                            query = new StringBundler(3);
8480                    }
8481    
8482                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8483    
8484                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8485    
8486                    query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8487    
8488                    if (orderByComparator != null) {
8489                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
8490    
8491                            if (orderByConditionFields.length > 0) {
8492                                    query.append(WHERE_AND);
8493                            }
8494    
8495                            for (int i = 0; i < orderByConditionFields.length; i++) {
8496                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8497                                    query.append(orderByConditionFields[i]);
8498    
8499                                    if ((i + 1) < orderByConditionFields.length) {
8500                                            if (orderByComparator.isAscending() ^ previous) {
8501                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
8502                                            }
8503                                            else {
8504                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
8505                                            }
8506                                    }
8507                                    else {
8508                                            if (orderByComparator.isAscending() ^ previous) {
8509                                                    query.append(WHERE_GREATER_THAN);
8510                                            }
8511                                            else {
8512                                                    query.append(WHERE_LESSER_THAN);
8513                                            }
8514                                    }
8515                            }
8516    
8517                            query.append(ORDER_BY_CLAUSE);
8518    
8519                            String[] orderByFields = orderByComparator.getOrderByFields();
8520    
8521                            for (int i = 0; i < orderByFields.length; i++) {
8522                                    query.append(_ORDER_BY_ENTITY_ALIAS);
8523                                    query.append(orderByFields[i]);
8524    
8525                                    if ((i + 1) < orderByFields.length) {
8526                                            if (orderByComparator.isAscending() ^ previous) {
8527                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
8528                                            }
8529                                            else {
8530                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
8531                                            }
8532                                    }
8533                                    else {
8534                                            if (orderByComparator.isAscending() ^ previous) {
8535                                                    query.append(ORDER_BY_ASC);
8536                                            }
8537                                            else {
8538                                                    query.append(ORDER_BY_DESC);
8539                                            }
8540                                    }
8541                            }
8542                    }
8543                    else {
8544                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8545                    }
8546    
8547                    String sql = query.toString();
8548    
8549                    Query q = session.createQuery(sql);
8550    
8551                    q.setFirstResult(0);
8552                    q.setMaxResults(2);
8553    
8554                    QueryPos qPos = QueryPos.getInstance(q);
8555    
8556                    qPos.add(classNameId);
8557    
8558                    qPos.add(classPK);
8559    
8560                    if (orderByComparator != null) {
8561                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
8562    
8563                            for (Object value : values) {
8564                                    qPos.add(value);
8565                            }
8566                    }
8567    
8568                    List<MBMessage> list = q.list();
8569    
8570                    if (list.size() == 2) {
8571                            return list.get(1);
8572                    }
8573                    else {
8574                            return null;
8575                    }
8576            }
8577    
8578            /**
8579             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; from the database.
8580             *
8581             * @param classNameId the class name ID
8582             * @param classPK the class p k
8583             * @throws SystemException if a system exception occurred
8584             */
8585            public void removeByC_C(long classNameId, long classPK)
8586                    throws SystemException {
8587                    for (MBMessage mbMessage : findByC_C(classNameId, classPK,
8588                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
8589                            remove(mbMessage);
8590                    }
8591            }
8592    
8593            /**
8594             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63;.
8595             *
8596             * @param classNameId the class name ID
8597             * @param classPK the class p k
8598             * @return the number of matching message-boards messages
8599             * @throws SystemException if a system exception occurred
8600             */
8601            public int countByC_C(long classNameId, long classPK)
8602                    throws SystemException {
8603                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C;
8604    
8605                    Object[] finderArgs = new Object[] { classNameId, classPK };
8606    
8607                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
8608                                    this);
8609    
8610                    if (count == null) {
8611                            StringBundler query = new StringBundler(3);
8612    
8613                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
8614    
8615                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
8616    
8617                            query.append(_FINDER_COLUMN_C_C_CLASSPK_2);
8618    
8619                            String sql = query.toString();
8620    
8621                            Session session = null;
8622    
8623                            try {
8624                                    session = openSession();
8625    
8626                                    Query q = session.createQuery(sql);
8627    
8628                                    QueryPos qPos = QueryPos.getInstance(q);
8629    
8630                                    qPos.add(classNameId);
8631    
8632                                    qPos.add(classPK);
8633    
8634                                    count = (Long)q.uniqueResult();
8635    
8636                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
8637                            }
8638                            catch (Exception e) {
8639                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8640    
8641                                    throw processException(e);
8642                            }
8643                            finally {
8644                                    closeSession(session);
8645                            }
8646                    }
8647    
8648                    return count.intValue();
8649            }
8650    
8651            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
8652            private static final String _FINDER_COLUMN_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
8653            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8654                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8655                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_P",
8656                            new String[] {
8657                                    Long.class.getName(), Long.class.getName(),
8658                                    
8659                            Integer.class.getName(), Integer.class.getName(),
8660                                    OrderByComparator.class.getName()
8661                            });
8662            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8663                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
8664                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_P",
8665                            new String[] { Long.class.getName(), Long.class.getName() },
8666                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
8667                            MBMessageModelImpl.PARENTMESSAGEID_COLUMN_BITMASK |
8668                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
8669            public static final FinderPath FINDER_PATH_COUNT_BY_T_P = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
8670                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
8671                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_P",
8672                            new String[] { Long.class.getName(), Long.class.getName() });
8673    
8674            /**
8675             * Returns all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8676             *
8677             * @param threadId the thread ID
8678             * @param parentMessageId the parent message ID
8679             * @return the matching message-boards messages
8680             * @throws SystemException if a system exception occurred
8681             */
8682            public List<MBMessage> findByT_P(long threadId, long parentMessageId)
8683                    throws SystemException {
8684                    return findByT_P(threadId, parentMessageId, QueryUtil.ALL_POS,
8685                            QueryUtil.ALL_POS, null);
8686            }
8687    
8688            /**
8689             * Returns a range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8690             *
8691             * <p>
8692             * 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.
8693             * </p>
8694             *
8695             * @param threadId the thread ID
8696             * @param parentMessageId the parent message ID
8697             * @param start the lower bound of the range of message-boards messages
8698             * @param end the upper bound of the range of message-boards messages (not inclusive)
8699             * @return the range of matching message-boards messages
8700             * @throws SystemException if a system exception occurred
8701             */
8702            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8703                    int start, int end) throws SystemException {
8704                    return findByT_P(threadId, parentMessageId, start, end, null);
8705            }
8706    
8707            /**
8708             * Returns an ordered range of all the message-boards messages where threadId = &#63; and parentMessageId = &#63;.
8709             *
8710             * <p>
8711             * 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.
8712             * </p>
8713             *
8714             * @param threadId the thread ID
8715             * @param parentMessageId the parent message ID
8716             * @param start the lower bound of the range of message-boards messages
8717             * @param end the upper bound of the range of message-boards messages (not inclusive)
8718             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
8719             * @return the ordered range of matching message-boards messages
8720             * @throws SystemException if a system exception occurred
8721             */
8722            public List<MBMessage> findByT_P(long threadId, long parentMessageId,
8723                    int start, int end, OrderByComparator orderByComparator)
8724                    throws SystemException {
8725                    boolean pagination = true;
8726                    FinderPath finderPath = null;
8727                    Object[] finderArgs = null;
8728    
8729                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
8730                                    (orderByComparator == null)) {
8731                            pagination = false;
8732                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P;
8733                            finderArgs = new Object[] { threadId, parentMessageId };
8734                    }
8735                    else {
8736                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_P;
8737                            finderArgs = new Object[] {
8738                                            threadId, parentMessageId,
8739                                            
8740                                            start, end, orderByComparator
8741                                    };
8742                    }
8743    
8744                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
8745                                    finderArgs, this);
8746    
8747                    if ((list != null) && !list.isEmpty()) {
8748                            for (MBMessage mbMessage : list) {
8749                                    if ((threadId != mbMessage.getThreadId()) ||
8750                                                    (parentMessageId != mbMessage.getParentMessageId())) {
8751                                            list = null;
8752    
8753                                            break;
8754                                    }
8755                            }
8756                    }
8757    
8758                    if (list == null) {
8759                            StringBundler query = null;
8760    
8761                            if (orderByComparator != null) {
8762                                    query = new StringBundler(4 +
8763                                                    (orderByComparator.getOrderByFields().length * 3));
8764                            }
8765                            else {
8766                                    query = new StringBundler(4);
8767                            }
8768    
8769                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8770    
8771                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
8772    
8773                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
8774    
8775                            if (orderByComparator != null) {
8776                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
8777                                            orderByComparator);
8778                            }
8779                            else
8780                             if (pagination) {
8781                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
8782                            }
8783    
8784                            String sql = query.toString();
8785    
8786                            Session session = null;
8787    
8788                            try {
8789                                    session = openSession();
8790    
8791                                    Query q = session.createQuery(sql);
8792    
8793                                    QueryPos qPos = QueryPos.getInstance(q);
8794    
8795                                    qPos.add(threadId);
8796    
8797                                    qPos.add(parentMessageId);
8798    
8799                                    if (!pagination) {
8800                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8801                                                            start, end, false);
8802    
8803                                            Collections.sort(list);
8804    
8805                                            list = new UnmodifiableList<MBMessage>(list);
8806                                    }
8807                                    else {
8808                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
8809                                                            start, end);
8810                                    }
8811    
8812                                    cacheResult(list);
8813    
8814                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
8815                            }
8816                            catch (Exception e) {
8817                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
8818    
8819                                    throw processException(e);
8820                            }
8821                            finally {
8822                                    closeSession(session);
8823                            }
8824                    }
8825    
8826                    return list;
8827            }
8828    
8829            /**
8830             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8831             *
8832             * @param threadId the thread ID
8833             * @param parentMessageId the parent message ID
8834             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8835             * @return the first matching message-boards message
8836             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8837             * @throws SystemException if a system exception occurred
8838             */
8839            public MBMessage findByT_P_First(long threadId, long parentMessageId,
8840                    OrderByComparator orderByComparator)
8841                    throws NoSuchMessageException, SystemException {
8842                    MBMessage mbMessage = fetchByT_P_First(threadId, parentMessageId,
8843                                    orderByComparator);
8844    
8845                    if (mbMessage != null) {
8846                            return mbMessage;
8847                    }
8848    
8849                    StringBundler msg = new StringBundler(6);
8850    
8851                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8852    
8853                    msg.append("threadId=");
8854                    msg.append(threadId);
8855    
8856                    msg.append(", parentMessageId=");
8857                    msg.append(parentMessageId);
8858    
8859                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8860    
8861                    throw new NoSuchMessageException(msg.toString());
8862            }
8863    
8864            /**
8865             * Returns the first message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8866             *
8867             * @param threadId the thread ID
8868             * @param parentMessageId the parent message ID
8869             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8870             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8871             * @throws SystemException if a system exception occurred
8872             */
8873            public MBMessage fetchByT_P_First(long threadId, long parentMessageId,
8874                    OrderByComparator orderByComparator) throws SystemException {
8875                    List<MBMessage> list = findByT_P(threadId, parentMessageId, 0, 1,
8876                                    orderByComparator);
8877    
8878                    if (!list.isEmpty()) {
8879                            return list.get(0);
8880                    }
8881    
8882                    return null;
8883            }
8884    
8885            /**
8886             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8887             *
8888             * @param threadId the thread ID
8889             * @param parentMessageId the parent message ID
8890             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8891             * @return the last matching message-boards message
8892             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
8893             * @throws SystemException if a system exception occurred
8894             */
8895            public MBMessage findByT_P_Last(long threadId, long parentMessageId,
8896                    OrderByComparator orderByComparator)
8897                    throws NoSuchMessageException, SystemException {
8898                    MBMessage mbMessage = fetchByT_P_Last(threadId, parentMessageId,
8899                                    orderByComparator);
8900    
8901                    if (mbMessage != null) {
8902                            return mbMessage;
8903                    }
8904    
8905                    StringBundler msg = new StringBundler(6);
8906    
8907                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
8908    
8909                    msg.append("threadId=");
8910                    msg.append(threadId);
8911    
8912                    msg.append(", parentMessageId=");
8913                    msg.append(parentMessageId);
8914    
8915                    msg.append(StringPool.CLOSE_CURLY_BRACE);
8916    
8917                    throw new NoSuchMessageException(msg.toString());
8918            }
8919    
8920            /**
8921             * Returns the last message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8922             *
8923             * @param threadId the thread ID
8924             * @param parentMessageId the parent message ID
8925             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8926             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
8927             * @throws SystemException if a system exception occurred
8928             */
8929            public MBMessage fetchByT_P_Last(long threadId, long parentMessageId,
8930                    OrderByComparator orderByComparator) throws SystemException {
8931                    int count = countByT_P(threadId, parentMessageId);
8932    
8933                    List<MBMessage> list = findByT_P(threadId, parentMessageId, count - 1,
8934                                    count, orderByComparator);
8935    
8936                    if (!list.isEmpty()) {
8937                            return list.get(0);
8938                    }
8939    
8940                    return null;
8941            }
8942    
8943            /**
8944             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and parentMessageId = &#63;.
8945             *
8946             * @param messageId the primary key of the current message-boards message
8947             * @param threadId the thread ID
8948             * @param parentMessageId the parent message ID
8949             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
8950             * @return the previous, current, and next message-boards message
8951             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
8952             * @throws SystemException if a system exception occurred
8953             */
8954            public MBMessage[] findByT_P_PrevAndNext(long messageId, long threadId,
8955                    long parentMessageId, OrderByComparator orderByComparator)
8956                    throws NoSuchMessageException, SystemException {
8957                    MBMessage mbMessage = findByPrimaryKey(messageId);
8958    
8959                    Session session = null;
8960    
8961                    try {
8962                            session = openSession();
8963    
8964                            MBMessage[] array = new MBMessageImpl[3];
8965    
8966                            array[0] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8967                                            parentMessageId, orderByComparator, true);
8968    
8969                            array[1] = mbMessage;
8970    
8971                            array[2] = getByT_P_PrevAndNext(session, mbMessage, threadId,
8972                                            parentMessageId, orderByComparator, false);
8973    
8974                            return array;
8975                    }
8976                    catch (Exception e) {
8977                            throw processException(e);
8978                    }
8979                    finally {
8980                            closeSession(session);
8981                    }
8982            }
8983    
8984            protected MBMessage getByT_P_PrevAndNext(Session session,
8985                    MBMessage mbMessage, long threadId, long parentMessageId,
8986                    OrderByComparator orderByComparator, boolean previous) {
8987                    StringBundler query = null;
8988    
8989                    if (orderByComparator != null) {
8990                            query = new StringBundler(6 +
8991                                            (orderByComparator.getOrderByFields().length * 6));
8992                    }
8993                    else {
8994                            query = new StringBundler(3);
8995                    }
8996    
8997                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
8998    
8999                    query.append(_FINDER_COLUMN_T_P_THREADID_2);
9000    
9001                    query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9002    
9003                    if (orderByComparator != null) {
9004                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9005    
9006                            if (orderByConditionFields.length > 0) {
9007                                    query.append(WHERE_AND);
9008                            }
9009    
9010                            for (int i = 0; i < orderByConditionFields.length; i++) {
9011                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9012                                    query.append(orderByConditionFields[i]);
9013    
9014                                    if ((i + 1) < orderByConditionFields.length) {
9015                                            if (orderByComparator.isAscending() ^ previous) {
9016                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9017                                            }
9018                                            else {
9019                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9020                                            }
9021                                    }
9022                                    else {
9023                                            if (orderByComparator.isAscending() ^ previous) {
9024                                                    query.append(WHERE_GREATER_THAN);
9025                                            }
9026                                            else {
9027                                                    query.append(WHERE_LESSER_THAN);
9028                                            }
9029                                    }
9030                            }
9031    
9032                            query.append(ORDER_BY_CLAUSE);
9033    
9034                            String[] orderByFields = orderByComparator.getOrderByFields();
9035    
9036                            for (int i = 0; i < orderByFields.length; i++) {
9037                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9038                                    query.append(orderByFields[i]);
9039    
9040                                    if ((i + 1) < orderByFields.length) {
9041                                            if (orderByComparator.isAscending() ^ previous) {
9042                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9043                                            }
9044                                            else {
9045                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9046                                            }
9047                                    }
9048                                    else {
9049                                            if (orderByComparator.isAscending() ^ previous) {
9050                                                    query.append(ORDER_BY_ASC);
9051                                            }
9052                                            else {
9053                                                    query.append(ORDER_BY_DESC);
9054                                            }
9055                                    }
9056                            }
9057                    }
9058                    else {
9059                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9060                    }
9061    
9062                    String sql = query.toString();
9063    
9064                    Query q = session.createQuery(sql);
9065    
9066                    q.setFirstResult(0);
9067                    q.setMaxResults(2);
9068    
9069                    QueryPos qPos = QueryPos.getInstance(q);
9070    
9071                    qPos.add(threadId);
9072    
9073                    qPos.add(parentMessageId);
9074    
9075                    if (orderByComparator != null) {
9076                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9077    
9078                            for (Object value : values) {
9079                                    qPos.add(value);
9080                            }
9081                    }
9082    
9083                    List<MBMessage> list = q.list();
9084    
9085                    if (list.size() == 2) {
9086                            return list.get(1);
9087                    }
9088                    else {
9089                            return null;
9090                    }
9091            }
9092    
9093            /**
9094             * Removes all the message-boards messages where threadId = &#63; and parentMessageId = &#63; from the database.
9095             *
9096             * @param threadId the thread ID
9097             * @param parentMessageId the parent message ID
9098             * @throws SystemException if a system exception occurred
9099             */
9100            public void removeByT_P(long threadId, long parentMessageId)
9101                    throws SystemException {
9102                    for (MBMessage mbMessage : findByT_P(threadId, parentMessageId,
9103                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9104                            remove(mbMessage);
9105                    }
9106            }
9107    
9108            /**
9109             * Returns the number of message-boards messages where threadId = &#63; and parentMessageId = &#63;.
9110             *
9111             * @param threadId the thread ID
9112             * @param parentMessageId the parent message ID
9113             * @return the number of matching message-boards messages
9114             * @throws SystemException if a system exception occurred
9115             */
9116            public int countByT_P(long threadId, long parentMessageId)
9117                    throws SystemException {
9118                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_P;
9119    
9120                    Object[] finderArgs = new Object[] { threadId, parentMessageId };
9121    
9122                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9123                                    this);
9124    
9125                    if (count == null) {
9126                            StringBundler query = new StringBundler(3);
9127    
9128                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9129    
9130                            query.append(_FINDER_COLUMN_T_P_THREADID_2);
9131    
9132                            query.append(_FINDER_COLUMN_T_P_PARENTMESSAGEID_2);
9133    
9134                            String sql = query.toString();
9135    
9136                            Session session = null;
9137    
9138                            try {
9139                                    session = openSession();
9140    
9141                                    Query q = session.createQuery(sql);
9142    
9143                                    QueryPos qPos = QueryPos.getInstance(q);
9144    
9145                                    qPos.add(threadId);
9146    
9147                                    qPos.add(parentMessageId);
9148    
9149                                    count = (Long)q.uniqueResult();
9150    
9151                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9152                            }
9153                            catch (Exception e) {
9154                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9155    
9156                                    throw processException(e);
9157                            }
9158                            finally {
9159                                    closeSession(session);
9160                            }
9161                    }
9162    
9163                    return count.intValue();
9164            }
9165    
9166            private static final String _FINDER_COLUMN_T_P_THREADID_2 = "mbMessage.threadId = ? AND ";
9167            private static final String _FINDER_COLUMN_T_P_PARENTMESSAGEID_2 = "mbMessage.parentMessageId = ?";
9168            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9169                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9170                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_A",
9171                            new String[] {
9172                                    Long.class.getName(), Boolean.class.getName(),
9173                                    
9174                            Integer.class.getName(), Integer.class.getName(),
9175                                    OrderByComparator.class.getName()
9176                            });
9177            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9178                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9179                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_A",
9180                            new String[] { Long.class.getName(), Boolean.class.getName() },
9181                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9182                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
9183                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9184            public static final FinderPath FINDER_PATH_COUNT_BY_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9185                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9186                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_A",
9187                            new String[] { Long.class.getName(), Boolean.class.getName() });
9188    
9189            /**
9190             * Returns all the message-boards messages where threadId = &#63; and answer = &#63;.
9191             *
9192             * @param threadId the thread ID
9193             * @param answer the answer
9194             * @return the matching message-boards messages
9195             * @throws SystemException if a system exception occurred
9196             */
9197            public List<MBMessage> findByT_A(long threadId, boolean answer)
9198                    throws SystemException {
9199                    return findByT_A(threadId, answer, QueryUtil.ALL_POS,
9200                            QueryUtil.ALL_POS, null);
9201            }
9202    
9203            /**
9204             * Returns a range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9205             *
9206             * <p>
9207             * 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.
9208             * </p>
9209             *
9210             * @param threadId the thread ID
9211             * @param answer the answer
9212             * @param start the lower bound of the range of message-boards messages
9213             * @param end the upper bound of the range of message-boards messages (not inclusive)
9214             * @return the range of matching message-boards messages
9215             * @throws SystemException if a system exception occurred
9216             */
9217            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9218                    int end) throws SystemException {
9219                    return findByT_A(threadId, answer, start, end, null);
9220            }
9221    
9222            /**
9223             * Returns an ordered range of all the message-boards messages where threadId = &#63; and answer = &#63;.
9224             *
9225             * <p>
9226             * 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.
9227             * </p>
9228             *
9229             * @param threadId the thread ID
9230             * @param answer the answer
9231             * @param start the lower bound of the range of message-boards messages
9232             * @param end the upper bound of the range of message-boards messages (not inclusive)
9233             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9234             * @return the ordered range of matching message-boards messages
9235             * @throws SystemException if a system exception occurred
9236             */
9237            public List<MBMessage> findByT_A(long threadId, boolean answer, int start,
9238                    int end, OrderByComparator orderByComparator) throws SystemException {
9239                    boolean pagination = true;
9240                    FinderPath finderPath = null;
9241                    Object[] finderArgs = null;
9242    
9243                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9244                                    (orderByComparator == null)) {
9245                            pagination = false;
9246                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A;
9247                            finderArgs = new Object[] { threadId, answer };
9248                    }
9249                    else {
9250                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_A;
9251                            finderArgs = new Object[] {
9252                                            threadId, answer,
9253                                            
9254                                            start, end, orderByComparator
9255                                    };
9256                    }
9257    
9258                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9259                                    finderArgs, this);
9260    
9261                    if ((list != null) && !list.isEmpty()) {
9262                            for (MBMessage mbMessage : list) {
9263                                    if ((threadId != mbMessage.getThreadId()) ||
9264                                                    (answer != mbMessage.getAnswer())) {
9265                                            list = null;
9266    
9267                                            break;
9268                                    }
9269                            }
9270                    }
9271    
9272                    if (list == null) {
9273                            StringBundler query = null;
9274    
9275                            if (orderByComparator != null) {
9276                                    query = new StringBundler(4 +
9277                                                    (orderByComparator.getOrderByFields().length * 3));
9278                            }
9279                            else {
9280                                    query = new StringBundler(4);
9281                            }
9282    
9283                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9284    
9285                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9286    
9287                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9288    
9289                            if (orderByComparator != null) {
9290                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9291                                            orderByComparator);
9292                            }
9293                            else
9294                             if (pagination) {
9295                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9296                            }
9297    
9298                            String sql = query.toString();
9299    
9300                            Session session = null;
9301    
9302                            try {
9303                                    session = openSession();
9304    
9305                                    Query q = session.createQuery(sql);
9306    
9307                                    QueryPos qPos = QueryPos.getInstance(q);
9308    
9309                                    qPos.add(threadId);
9310    
9311                                    qPos.add(answer);
9312    
9313                                    if (!pagination) {
9314                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9315                                                            start, end, false);
9316    
9317                                            Collections.sort(list);
9318    
9319                                            list = new UnmodifiableList<MBMessage>(list);
9320                                    }
9321                                    else {
9322                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9323                                                            start, end);
9324                                    }
9325    
9326                                    cacheResult(list);
9327    
9328                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9329                            }
9330                            catch (Exception e) {
9331                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9332    
9333                                    throw processException(e);
9334                            }
9335                            finally {
9336                                    closeSession(session);
9337                            }
9338                    }
9339    
9340                    return list;
9341            }
9342    
9343            /**
9344             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9345             *
9346             * @param threadId the thread ID
9347             * @param answer the answer
9348             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9349             * @return the first matching message-boards message
9350             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9351             * @throws SystemException if a system exception occurred
9352             */
9353            public MBMessage findByT_A_First(long threadId, boolean answer,
9354                    OrderByComparator orderByComparator)
9355                    throws NoSuchMessageException, SystemException {
9356                    MBMessage mbMessage = fetchByT_A_First(threadId, answer,
9357                                    orderByComparator);
9358    
9359                    if (mbMessage != null) {
9360                            return mbMessage;
9361                    }
9362    
9363                    StringBundler msg = new StringBundler(6);
9364    
9365                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9366    
9367                    msg.append("threadId=");
9368                    msg.append(threadId);
9369    
9370                    msg.append(", answer=");
9371                    msg.append(answer);
9372    
9373                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9374    
9375                    throw new NoSuchMessageException(msg.toString());
9376            }
9377    
9378            /**
9379             * Returns the first message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9380             *
9381             * @param threadId the thread ID
9382             * @param answer the answer
9383             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9384             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9385             * @throws SystemException if a system exception occurred
9386             */
9387            public MBMessage fetchByT_A_First(long threadId, boolean answer,
9388                    OrderByComparator orderByComparator) throws SystemException {
9389                    List<MBMessage> list = findByT_A(threadId, answer, 0, 1,
9390                                    orderByComparator);
9391    
9392                    if (!list.isEmpty()) {
9393                            return list.get(0);
9394                    }
9395    
9396                    return null;
9397            }
9398    
9399            /**
9400             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9401             *
9402             * @param threadId the thread ID
9403             * @param answer the answer
9404             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9405             * @return the last matching message-boards message
9406             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9407             * @throws SystemException if a system exception occurred
9408             */
9409            public MBMessage findByT_A_Last(long threadId, boolean answer,
9410                    OrderByComparator orderByComparator)
9411                    throws NoSuchMessageException, SystemException {
9412                    MBMessage mbMessage = fetchByT_A_Last(threadId, answer,
9413                                    orderByComparator);
9414    
9415                    if (mbMessage != null) {
9416                            return mbMessage;
9417                    }
9418    
9419                    StringBundler msg = new StringBundler(6);
9420    
9421                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9422    
9423                    msg.append("threadId=");
9424                    msg.append(threadId);
9425    
9426                    msg.append(", answer=");
9427                    msg.append(answer);
9428    
9429                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9430    
9431                    throw new NoSuchMessageException(msg.toString());
9432            }
9433    
9434            /**
9435             * Returns the last message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9436             *
9437             * @param threadId the thread ID
9438             * @param answer the answer
9439             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9440             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9441             * @throws SystemException if a system exception occurred
9442             */
9443            public MBMessage fetchByT_A_Last(long threadId, boolean answer,
9444                    OrderByComparator orderByComparator) throws SystemException {
9445                    int count = countByT_A(threadId, answer);
9446    
9447                    List<MBMessage> list = findByT_A(threadId, answer, count - 1, count,
9448                                    orderByComparator);
9449    
9450                    if (!list.isEmpty()) {
9451                            return list.get(0);
9452                    }
9453    
9454                    return null;
9455            }
9456    
9457            /**
9458             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and answer = &#63;.
9459             *
9460             * @param messageId the primary key of the current message-boards message
9461             * @param threadId the thread ID
9462             * @param answer the answer
9463             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9464             * @return the previous, current, and next message-boards message
9465             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9466             * @throws SystemException if a system exception occurred
9467             */
9468            public MBMessage[] findByT_A_PrevAndNext(long messageId, long threadId,
9469                    boolean answer, OrderByComparator orderByComparator)
9470                    throws NoSuchMessageException, SystemException {
9471                    MBMessage mbMessage = findByPrimaryKey(messageId);
9472    
9473                    Session session = null;
9474    
9475                    try {
9476                            session = openSession();
9477    
9478                            MBMessage[] array = new MBMessageImpl[3];
9479    
9480                            array[0] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9481                                            answer, orderByComparator, true);
9482    
9483                            array[1] = mbMessage;
9484    
9485                            array[2] = getByT_A_PrevAndNext(session, mbMessage, threadId,
9486                                            answer, orderByComparator, false);
9487    
9488                            return array;
9489                    }
9490                    catch (Exception e) {
9491                            throw processException(e);
9492                    }
9493                    finally {
9494                            closeSession(session);
9495                    }
9496            }
9497    
9498            protected MBMessage getByT_A_PrevAndNext(Session session,
9499                    MBMessage mbMessage, long threadId, boolean answer,
9500                    OrderByComparator orderByComparator, boolean previous) {
9501                    StringBundler query = null;
9502    
9503                    if (orderByComparator != null) {
9504                            query = new StringBundler(6 +
9505                                            (orderByComparator.getOrderByFields().length * 6));
9506                    }
9507                    else {
9508                            query = new StringBundler(3);
9509                    }
9510    
9511                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9512    
9513                    query.append(_FINDER_COLUMN_T_A_THREADID_2);
9514    
9515                    query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9516    
9517                    if (orderByComparator != null) {
9518                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
9519    
9520                            if (orderByConditionFields.length > 0) {
9521                                    query.append(WHERE_AND);
9522                            }
9523    
9524                            for (int i = 0; i < orderByConditionFields.length; i++) {
9525                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9526                                    query.append(orderByConditionFields[i]);
9527    
9528                                    if ((i + 1) < orderByConditionFields.length) {
9529                                            if (orderByComparator.isAscending() ^ previous) {
9530                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
9531                                            }
9532                                            else {
9533                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
9534                                            }
9535                                    }
9536                                    else {
9537                                            if (orderByComparator.isAscending() ^ previous) {
9538                                                    query.append(WHERE_GREATER_THAN);
9539                                            }
9540                                            else {
9541                                                    query.append(WHERE_LESSER_THAN);
9542                                            }
9543                                    }
9544                            }
9545    
9546                            query.append(ORDER_BY_CLAUSE);
9547    
9548                            String[] orderByFields = orderByComparator.getOrderByFields();
9549    
9550                            for (int i = 0; i < orderByFields.length; i++) {
9551                                    query.append(_ORDER_BY_ENTITY_ALIAS);
9552                                    query.append(orderByFields[i]);
9553    
9554                                    if ((i + 1) < orderByFields.length) {
9555                                            if (orderByComparator.isAscending() ^ previous) {
9556                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
9557                                            }
9558                                            else {
9559                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
9560                                            }
9561                                    }
9562                                    else {
9563                                            if (orderByComparator.isAscending() ^ previous) {
9564                                                    query.append(ORDER_BY_ASC);
9565                                            }
9566                                            else {
9567                                                    query.append(ORDER_BY_DESC);
9568                                            }
9569                                    }
9570                            }
9571                    }
9572                    else {
9573                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9574                    }
9575    
9576                    String sql = query.toString();
9577    
9578                    Query q = session.createQuery(sql);
9579    
9580                    q.setFirstResult(0);
9581                    q.setMaxResults(2);
9582    
9583                    QueryPos qPos = QueryPos.getInstance(q);
9584    
9585                    qPos.add(threadId);
9586    
9587                    qPos.add(answer);
9588    
9589                    if (orderByComparator != null) {
9590                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
9591    
9592                            for (Object value : values) {
9593                                    qPos.add(value);
9594                            }
9595                    }
9596    
9597                    List<MBMessage> list = q.list();
9598    
9599                    if (list.size() == 2) {
9600                            return list.get(1);
9601                    }
9602                    else {
9603                            return null;
9604                    }
9605            }
9606    
9607            /**
9608             * Removes all the message-boards messages where threadId = &#63; and answer = &#63; from the database.
9609             *
9610             * @param threadId the thread ID
9611             * @param answer the answer
9612             * @throws SystemException if a system exception occurred
9613             */
9614            public void removeByT_A(long threadId, boolean answer)
9615                    throws SystemException {
9616                    for (MBMessage mbMessage : findByT_A(threadId, answer,
9617                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
9618                            remove(mbMessage);
9619                    }
9620            }
9621    
9622            /**
9623             * Returns the number of message-boards messages where threadId = &#63; and answer = &#63;.
9624             *
9625             * @param threadId the thread ID
9626             * @param answer the answer
9627             * @return the number of matching message-boards messages
9628             * @throws SystemException if a system exception occurred
9629             */
9630            public int countByT_A(long threadId, boolean answer)
9631                    throws SystemException {
9632                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_A;
9633    
9634                    Object[] finderArgs = new Object[] { threadId, answer };
9635    
9636                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
9637                                    this);
9638    
9639                    if (count == null) {
9640                            StringBundler query = new StringBundler(3);
9641    
9642                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
9643    
9644                            query.append(_FINDER_COLUMN_T_A_THREADID_2);
9645    
9646                            query.append(_FINDER_COLUMN_T_A_ANSWER_2);
9647    
9648                            String sql = query.toString();
9649    
9650                            Session session = null;
9651    
9652                            try {
9653                                    session = openSession();
9654    
9655                                    Query q = session.createQuery(sql);
9656    
9657                                    QueryPos qPos = QueryPos.getInstance(q);
9658    
9659                                    qPos.add(threadId);
9660    
9661                                    qPos.add(answer);
9662    
9663                                    count = (Long)q.uniqueResult();
9664    
9665                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
9666                            }
9667                            catch (Exception e) {
9668                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9669    
9670                                    throw processException(e);
9671                            }
9672                            finally {
9673                                    closeSession(session);
9674                            }
9675                    }
9676    
9677                    return count.intValue();
9678            }
9679    
9680            private static final String _FINDER_COLUMN_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
9681            private static final String _FINDER_COLUMN_T_A_ANSWER_2 = "mbMessage.answer = ?";
9682            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9683                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9684                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByT_S",
9685                            new String[] {
9686                                    Long.class.getName(), Integer.class.getName(),
9687                                    
9688                            Integer.class.getName(), Integer.class.getName(),
9689                                    OrderByComparator.class.getName()
9690                            });
9691            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9692                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
9693                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByT_S",
9694                            new String[] { Long.class.getName(), Integer.class.getName() },
9695                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
9696                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
9697                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
9698            public static final FinderPath FINDER_PATH_COUNT_BY_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
9699                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
9700                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_S",
9701                            new String[] { Long.class.getName(), Integer.class.getName() });
9702    
9703            /**
9704             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
9705             *
9706             * @param threadId the thread ID
9707             * @param status the status
9708             * @return the matching message-boards messages
9709             * @throws SystemException if a system exception occurred
9710             */
9711            public List<MBMessage> findByT_S(long threadId, int status)
9712                    throws SystemException {
9713                    return findByT_S(threadId, status, QueryUtil.ALL_POS,
9714                            QueryUtil.ALL_POS, null);
9715            }
9716    
9717            /**
9718             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
9719             *
9720             * <p>
9721             * 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.
9722             * </p>
9723             *
9724             * @param threadId the thread ID
9725             * @param status the status
9726             * @param start the lower bound of the range of message-boards messages
9727             * @param end the upper bound of the range of message-boards messages (not inclusive)
9728             * @return the range of matching message-boards messages
9729             * @throws SystemException if a system exception occurred
9730             */
9731            public List<MBMessage> findByT_S(long threadId, int status, int start,
9732                    int end) throws SystemException {
9733                    return findByT_S(threadId, status, start, end, null);
9734            }
9735    
9736            /**
9737             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
9738             *
9739             * <p>
9740             * 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.
9741             * </p>
9742             *
9743             * @param threadId the thread ID
9744             * @param status the status
9745             * @param start the lower bound of the range of message-boards messages
9746             * @param end the upper bound of the range of message-boards messages (not inclusive)
9747             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
9748             * @return the ordered range of matching message-boards messages
9749             * @throws SystemException if a system exception occurred
9750             */
9751            public List<MBMessage> findByT_S(long threadId, int status, int start,
9752                    int end, OrderByComparator orderByComparator) throws SystemException {
9753                    boolean pagination = true;
9754                    FinderPath finderPath = null;
9755                    Object[] finderArgs = null;
9756    
9757                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
9758                                    (orderByComparator == null)) {
9759                            pagination = false;
9760                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S;
9761                            finderArgs = new Object[] { threadId, status };
9762                    }
9763                    else {
9764                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_T_S;
9765                            finderArgs = new Object[] {
9766                                            threadId, status,
9767                                            
9768                                            start, end, orderByComparator
9769                                    };
9770                    }
9771    
9772                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
9773                                    finderArgs, this);
9774    
9775                    if ((list != null) && !list.isEmpty()) {
9776                            for (MBMessage mbMessage : list) {
9777                                    if ((threadId != mbMessage.getThreadId()) ||
9778                                                    (status != mbMessage.getStatus())) {
9779                                            list = null;
9780    
9781                                            break;
9782                                    }
9783                            }
9784                    }
9785    
9786                    if (list == null) {
9787                            StringBundler query = null;
9788    
9789                            if (orderByComparator != null) {
9790                                    query = new StringBundler(4 +
9791                                                    (orderByComparator.getOrderByFields().length * 3));
9792                            }
9793                            else {
9794                                    query = new StringBundler(4);
9795                            }
9796    
9797                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
9798    
9799                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
9800    
9801                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
9802    
9803                            if (orderByComparator != null) {
9804                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
9805                                            orderByComparator);
9806                            }
9807                            else
9808                             if (pagination) {
9809                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
9810                            }
9811    
9812                            String sql = query.toString();
9813    
9814                            Session session = null;
9815    
9816                            try {
9817                                    session = openSession();
9818    
9819                                    Query q = session.createQuery(sql);
9820    
9821                                    QueryPos qPos = QueryPos.getInstance(q);
9822    
9823                                    qPos.add(threadId);
9824    
9825                                    qPos.add(status);
9826    
9827                                    if (!pagination) {
9828                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9829                                                            start, end, false);
9830    
9831                                            Collections.sort(list);
9832    
9833                                            list = new UnmodifiableList<MBMessage>(list);
9834                                    }
9835                                    else {
9836                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
9837                                                            start, end);
9838                                    }
9839    
9840                                    cacheResult(list);
9841    
9842                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
9843                            }
9844                            catch (Exception e) {
9845                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
9846    
9847                                    throw processException(e);
9848                            }
9849                            finally {
9850                                    closeSession(session);
9851                            }
9852                    }
9853    
9854                    return list;
9855            }
9856    
9857            /**
9858             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9859             *
9860             * @param threadId the thread ID
9861             * @param status the status
9862             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9863             * @return the first matching message-boards message
9864             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9865             * @throws SystemException if a system exception occurred
9866             */
9867            public MBMessage findByT_S_First(long threadId, int status,
9868                    OrderByComparator orderByComparator)
9869                    throws NoSuchMessageException, SystemException {
9870                    MBMessage mbMessage = fetchByT_S_First(threadId, status,
9871                                    orderByComparator);
9872    
9873                    if (mbMessage != null) {
9874                            return mbMessage;
9875                    }
9876    
9877                    StringBundler msg = new StringBundler(6);
9878    
9879                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9880    
9881                    msg.append("threadId=");
9882                    msg.append(threadId);
9883    
9884                    msg.append(", status=");
9885                    msg.append(status);
9886    
9887                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9888    
9889                    throw new NoSuchMessageException(msg.toString());
9890            }
9891    
9892            /**
9893             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9894             *
9895             * @param threadId the thread ID
9896             * @param status the status
9897             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9898             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9899             * @throws SystemException if a system exception occurred
9900             */
9901            public MBMessage fetchByT_S_First(long threadId, int status,
9902                    OrderByComparator orderByComparator) throws SystemException {
9903                    List<MBMessage> list = findByT_S(threadId, status, 0, 1,
9904                                    orderByComparator);
9905    
9906                    if (!list.isEmpty()) {
9907                            return list.get(0);
9908                    }
9909    
9910                    return null;
9911            }
9912    
9913            /**
9914             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9915             *
9916             * @param threadId the thread ID
9917             * @param status the status
9918             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9919             * @return the last matching message-boards message
9920             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
9921             * @throws SystemException if a system exception occurred
9922             */
9923            public MBMessage findByT_S_Last(long threadId, int status,
9924                    OrderByComparator orderByComparator)
9925                    throws NoSuchMessageException, SystemException {
9926                    MBMessage mbMessage = fetchByT_S_Last(threadId, status,
9927                                    orderByComparator);
9928    
9929                    if (mbMessage != null) {
9930                            return mbMessage;
9931                    }
9932    
9933                    StringBundler msg = new StringBundler(6);
9934    
9935                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
9936    
9937                    msg.append("threadId=");
9938                    msg.append(threadId);
9939    
9940                    msg.append(", status=");
9941                    msg.append(status);
9942    
9943                    msg.append(StringPool.CLOSE_CURLY_BRACE);
9944    
9945                    throw new NoSuchMessageException(msg.toString());
9946            }
9947    
9948            /**
9949             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9950             *
9951             * @param threadId the thread ID
9952             * @param status the status
9953             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9954             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
9955             * @throws SystemException if a system exception occurred
9956             */
9957            public MBMessage fetchByT_S_Last(long threadId, int status,
9958                    OrderByComparator orderByComparator) throws SystemException {
9959                    int count = countByT_S(threadId, status);
9960    
9961                    List<MBMessage> list = findByT_S(threadId, status, count - 1, count,
9962                                    orderByComparator);
9963    
9964                    if (!list.isEmpty()) {
9965                            return list.get(0);
9966                    }
9967    
9968                    return null;
9969            }
9970    
9971            /**
9972             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
9973             *
9974             * @param messageId the primary key of the current message-boards message
9975             * @param threadId the thread ID
9976             * @param status the status
9977             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
9978             * @return the previous, current, and next message-boards message
9979             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
9980             * @throws SystemException if a system exception occurred
9981             */
9982            public MBMessage[] findByT_S_PrevAndNext(long messageId, long threadId,
9983                    int status, OrderByComparator orderByComparator)
9984                    throws NoSuchMessageException, SystemException {
9985                    MBMessage mbMessage = findByPrimaryKey(messageId);
9986    
9987                    Session session = null;
9988    
9989                    try {
9990                            session = openSession();
9991    
9992                            MBMessage[] array = new MBMessageImpl[3];
9993    
9994                            array[0] = getByT_S_PrevAndNext(session, mbMessage, threadId,
9995                                            status, orderByComparator, true);
9996    
9997                            array[1] = mbMessage;
9998    
9999                            array[2] = getByT_S_PrevAndNext(session, mbMessage, threadId,
10000                                            status, orderByComparator, false);
10001    
10002                            return array;
10003                    }
10004                    catch (Exception e) {
10005                            throw processException(e);
10006                    }
10007                    finally {
10008                            closeSession(session);
10009                    }
10010            }
10011    
10012            protected MBMessage getByT_S_PrevAndNext(Session session,
10013                    MBMessage mbMessage, long threadId, int status,
10014                    OrderByComparator orderByComparator, boolean previous) {
10015                    StringBundler query = null;
10016    
10017                    if (orderByComparator != null) {
10018                            query = new StringBundler(6 +
10019                                            (orderByComparator.getOrderByFields().length * 6));
10020                    }
10021                    else {
10022                            query = new StringBundler(3);
10023                    }
10024    
10025                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10026    
10027                    query.append(_FINDER_COLUMN_T_S_THREADID_2);
10028    
10029                    query.append(_FINDER_COLUMN_T_S_STATUS_2);
10030    
10031                    if (orderByComparator != null) {
10032                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10033    
10034                            if (orderByConditionFields.length > 0) {
10035                                    query.append(WHERE_AND);
10036                            }
10037    
10038                            for (int i = 0; i < orderByConditionFields.length; i++) {
10039                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10040                                    query.append(orderByConditionFields[i]);
10041    
10042                                    if ((i + 1) < orderByConditionFields.length) {
10043                                            if (orderByComparator.isAscending() ^ previous) {
10044                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10045                                            }
10046                                            else {
10047                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10048                                            }
10049                                    }
10050                                    else {
10051                                            if (orderByComparator.isAscending() ^ previous) {
10052                                                    query.append(WHERE_GREATER_THAN);
10053                                            }
10054                                            else {
10055                                                    query.append(WHERE_LESSER_THAN);
10056                                            }
10057                                    }
10058                            }
10059    
10060                            query.append(ORDER_BY_CLAUSE);
10061    
10062                            String[] orderByFields = orderByComparator.getOrderByFields();
10063    
10064                            for (int i = 0; i < orderByFields.length; i++) {
10065                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10066                                    query.append(orderByFields[i]);
10067    
10068                                    if ((i + 1) < orderByFields.length) {
10069                                            if (orderByComparator.isAscending() ^ previous) {
10070                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10071                                            }
10072                                            else {
10073                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10074                                            }
10075                                    }
10076                                    else {
10077                                            if (orderByComparator.isAscending() ^ previous) {
10078                                                    query.append(ORDER_BY_ASC);
10079                                            }
10080                                            else {
10081                                                    query.append(ORDER_BY_DESC);
10082                                            }
10083                                    }
10084                            }
10085                    }
10086                    else {
10087                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10088                    }
10089    
10090                    String sql = query.toString();
10091    
10092                    Query q = session.createQuery(sql);
10093    
10094                    q.setFirstResult(0);
10095                    q.setMaxResults(2);
10096    
10097                    QueryPos qPos = QueryPos.getInstance(q);
10098    
10099                    qPos.add(threadId);
10100    
10101                    qPos.add(status);
10102    
10103                    if (orderByComparator != null) {
10104                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10105    
10106                            for (Object value : values) {
10107                                    qPos.add(value);
10108                            }
10109                    }
10110    
10111                    List<MBMessage> list = q.list();
10112    
10113                    if (list.size() == 2) {
10114                            return list.get(1);
10115                    }
10116                    else {
10117                            return null;
10118                    }
10119            }
10120    
10121            /**
10122             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10123             *
10124             * @param threadId the thread ID
10125             * @param status the status
10126             * @throws SystemException if a system exception occurred
10127             */
10128            public void removeByT_S(long threadId, int status)
10129                    throws SystemException {
10130                    for (MBMessage mbMessage : findByT_S(threadId, status,
10131                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10132                            remove(mbMessage);
10133                    }
10134            }
10135    
10136            /**
10137             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10138             *
10139             * @param threadId the thread ID
10140             * @param status the status
10141             * @return the number of matching message-boards messages
10142             * @throws SystemException if a system exception occurred
10143             */
10144            public int countByT_S(long threadId, int status) throws SystemException {
10145                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_S;
10146    
10147                    Object[] finderArgs = new Object[] { threadId, status };
10148    
10149                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10150                                    this);
10151    
10152                    if (count == null) {
10153                            StringBundler query = new StringBundler(3);
10154    
10155                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10156    
10157                            query.append(_FINDER_COLUMN_T_S_THREADID_2);
10158    
10159                            query.append(_FINDER_COLUMN_T_S_STATUS_2);
10160    
10161                            String sql = query.toString();
10162    
10163                            Session session = null;
10164    
10165                            try {
10166                                    session = openSession();
10167    
10168                                    Query q = session.createQuery(sql);
10169    
10170                                    QueryPos qPos = QueryPos.getInstance(q);
10171    
10172                                    qPos.add(threadId);
10173    
10174                                    qPos.add(status);
10175    
10176                                    count = (Long)q.uniqueResult();
10177    
10178                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10179                            }
10180                            catch (Exception e) {
10181                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10182    
10183                                    throw processException(e);
10184                            }
10185                            finally {
10186                                    closeSession(session);
10187                            }
10188                    }
10189    
10190                    return count.intValue();
10191            }
10192    
10193            private static final String _FINDER_COLUMN_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10194            private static final String _FINDER_COLUMN_T_S_STATUS_2 = "mbMessage.status = ?";
10195            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10196                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10197                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByTR_S",
10198                            new String[] {
10199                                    Long.class.getName(), Integer.class.getName(),
10200                                    
10201                            Integer.class.getName(), Integer.class.getName(),
10202                                    OrderByComparator.class.getName()
10203                            });
10204            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10205                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10206                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByTR_S",
10207                            new String[] { Long.class.getName(), Integer.class.getName() },
10208                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
10209                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10210                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10211            public static final FinderPath FINDER_PATH_COUNT_BY_TR_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10212                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10213                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTR_S",
10214                            new String[] { Long.class.getName(), Integer.class.getName() });
10215    
10216            /**
10217             * Returns all the message-boards messages where threadId = &#63; and status = &#63;.
10218             *
10219             * @param threadId the thread ID
10220             * @param status the status
10221             * @return the matching message-boards messages
10222             * @throws SystemException if a system exception occurred
10223             */
10224            public List<MBMessage> findByTR_S(long threadId, int status)
10225                    throws SystemException {
10226                    return findByTR_S(threadId, status, QueryUtil.ALL_POS,
10227                            QueryUtil.ALL_POS, null);
10228            }
10229    
10230            /**
10231             * Returns a range of all the message-boards messages where threadId = &#63; and status = &#63;.
10232             *
10233             * <p>
10234             * 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.
10235             * </p>
10236             *
10237             * @param threadId the thread ID
10238             * @param status the status
10239             * @param start the lower bound of the range of message-boards messages
10240             * @param end the upper bound of the range of message-boards messages (not inclusive)
10241             * @return the range of matching message-boards messages
10242             * @throws SystemException if a system exception occurred
10243             */
10244            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10245                    int end) throws SystemException {
10246                    return findByTR_S(threadId, status, start, end, null);
10247            }
10248    
10249            /**
10250             * Returns an ordered range of all the message-boards messages where threadId = &#63; and status = &#63;.
10251             *
10252             * <p>
10253             * 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.
10254             * </p>
10255             *
10256             * @param threadId the thread ID
10257             * @param status the status
10258             * @param start the lower bound of the range of message-boards messages
10259             * @param end the upper bound of the range of message-boards messages (not inclusive)
10260             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10261             * @return the ordered range of matching message-boards messages
10262             * @throws SystemException if a system exception occurred
10263             */
10264            public List<MBMessage> findByTR_S(long threadId, int status, int start,
10265                    int end, OrderByComparator orderByComparator) throws SystemException {
10266                    boolean pagination = true;
10267                    FinderPath finderPath = null;
10268                    Object[] finderArgs = null;
10269    
10270                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10271                                    (orderByComparator == null)) {
10272                            pagination = false;
10273                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S;
10274                            finderArgs = new Object[] { threadId, status };
10275                    }
10276                    else {
10277                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TR_S;
10278                            finderArgs = new Object[] {
10279                                            threadId, status,
10280                                            
10281                                            start, end, orderByComparator
10282                                    };
10283                    }
10284    
10285                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10286                                    finderArgs, this);
10287    
10288                    if ((list != null) && !list.isEmpty()) {
10289                            for (MBMessage mbMessage : list) {
10290                                    if ((threadId != mbMessage.getThreadId()) ||
10291                                                    (status != mbMessage.getStatus())) {
10292                                            list = null;
10293    
10294                                            break;
10295                                    }
10296                            }
10297                    }
10298    
10299                    if (list == null) {
10300                            StringBundler query = null;
10301    
10302                            if (orderByComparator != null) {
10303                                    query = new StringBundler(4 +
10304                                                    (orderByComparator.getOrderByFields().length * 3));
10305                            }
10306                            else {
10307                                    query = new StringBundler(4);
10308                            }
10309    
10310                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10311    
10312                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10313    
10314                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10315    
10316                            if (orderByComparator != null) {
10317                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10318                                            orderByComparator);
10319                            }
10320                            else
10321                             if (pagination) {
10322                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10323                            }
10324    
10325                            String sql = query.toString();
10326    
10327                            Session session = null;
10328    
10329                            try {
10330                                    session = openSession();
10331    
10332                                    Query q = session.createQuery(sql);
10333    
10334                                    QueryPos qPos = QueryPos.getInstance(q);
10335    
10336                                    qPos.add(threadId);
10337    
10338                                    qPos.add(status);
10339    
10340                                    if (!pagination) {
10341                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10342                                                            start, end, false);
10343    
10344                                            Collections.sort(list);
10345    
10346                                            list = new UnmodifiableList<MBMessage>(list);
10347                                    }
10348                                    else {
10349                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10350                                                            start, end);
10351                                    }
10352    
10353                                    cacheResult(list);
10354    
10355                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10356                            }
10357                            catch (Exception e) {
10358                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10359    
10360                                    throw processException(e);
10361                            }
10362                            finally {
10363                                    closeSession(session);
10364                            }
10365                    }
10366    
10367                    return list;
10368            }
10369    
10370            /**
10371             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10372             *
10373             * @param threadId the thread ID
10374             * @param status the status
10375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10376             * @return the first matching message-boards message
10377             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10378             * @throws SystemException if a system exception occurred
10379             */
10380            public MBMessage findByTR_S_First(long threadId, int status,
10381                    OrderByComparator orderByComparator)
10382                    throws NoSuchMessageException, SystemException {
10383                    MBMessage mbMessage = fetchByTR_S_First(threadId, status,
10384                                    orderByComparator);
10385    
10386                    if (mbMessage != null) {
10387                            return mbMessage;
10388                    }
10389    
10390                    StringBundler msg = new StringBundler(6);
10391    
10392                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10393    
10394                    msg.append("threadId=");
10395                    msg.append(threadId);
10396    
10397                    msg.append(", status=");
10398                    msg.append(status);
10399    
10400                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10401    
10402                    throw new NoSuchMessageException(msg.toString());
10403            }
10404    
10405            /**
10406             * Returns the first message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10407             *
10408             * @param threadId the thread ID
10409             * @param status the status
10410             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10411             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10412             * @throws SystemException if a system exception occurred
10413             */
10414            public MBMessage fetchByTR_S_First(long threadId, int status,
10415                    OrderByComparator orderByComparator) throws SystemException {
10416                    List<MBMessage> list = findByTR_S(threadId, status, 0, 1,
10417                                    orderByComparator);
10418    
10419                    if (!list.isEmpty()) {
10420                            return list.get(0);
10421                    }
10422    
10423                    return null;
10424            }
10425    
10426            /**
10427             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10428             *
10429             * @param threadId the thread ID
10430             * @param status the status
10431             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10432             * @return the last matching message-boards message
10433             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10434             * @throws SystemException if a system exception occurred
10435             */
10436            public MBMessage findByTR_S_Last(long threadId, int status,
10437                    OrderByComparator orderByComparator)
10438                    throws NoSuchMessageException, SystemException {
10439                    MBMessage mbMessage = fetchByTR_S_Last(threadId, status,
10440                                    orderByComparator);
10441    
10442                    if (mbMessage != null) {
10443                            return mbMessage;
10444                    }
10445    
10446                    StringBundler msg = new StringBundler(6);
10447    
10448                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10449    
10450                    msg.append("threadId=");
10451                    msg.append(threadId);
10452    
10453                    msg.append(", status=");
10454                    msg.append(status);
10455    
10456                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10457    
10458                    throw new NoSuchMessageException(msg.toString());
10459            }
10460    
10461            /**
10462             * Returns the last message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10463             *
10464             * @param threadId the thread ID
10465             * @param status the status
10466             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10467             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10468             * @throws SystemException if a system exception occurred
10469             */
10470            public MBMessage fetchByTR_S_Last(long threadId, int status,
10471                    OrderByComparator orderByComparator) throws SystemException {
10472                    int count = countByTR_S(threadId, status);
10473    
10474                    List<MBMessage> list = findByTR_S(threadId, status, count - 1, count,
10475                                    orderByComparator);
10476    
10477                    if (!list.isEmpty()) {
10478                            return list.get(0);
10479                    }
10480    
10481                    return null;
10482            }
10483    
10484            /**
10485             * Returns the message-boards messages before and after the current message-boards message in the ordered set where threadId = &#63; and status = &#63;.
10486             *
10487             * @param messageId the primary key of the current message-boards message
10488             * @param threadId the thread ID
10489             * @param status the status
10490             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10491             * @return the previous, current, and next message-boards message
10492             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
10493             * @throws SystemException if a system exception occurred
10494             */
10495            public MBMessage[] findByTR_S_PrevAndNext(long messageId, long threadId,
10496                    int status, OrderByComparator orderByComparator)
10497                    throws NoSuchMessageException, SystemException {
10498                    MBMessage mbMessage = findByPrimaryKey(messageId);
10499    
10500                    Session session = null;
10501    
10502                    try {
10503                            session = openSession();
10504    
10505                            MBMessage[] array = new MBMessageImpl[3];
10506    
10507                            array[0] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10508                                            status, orderByComparator, true);
10509    
10510                            array[1] = mbMessage;
10511    
10512                            array[2] = getByTR_S_PrevAndNext(session, mbMessage, threadId,
10513                                            status, orderByComparator, false);
10514    
10515                            return array;
10516                    }
10517                    catch (Exception e) {
10518                            throw processException(e);
10519                    }
10520                    finally {
10521                            closeSession(session);
10522                    }
10523            }
10524    
10525            protected MBMessage getByTR_S_PrevAndNext(Session session,
10526                    MBMessage mbMessage, long threadId, int status,
10527                    OrderByComparator orderByComparator, boolean previous) {
10528                    StringBundler query = null;
10529    
10530                    if (orderByComparator != null) {
10531                            query = new StringBundler(6 +
10532                                            (orderByComparator.getOrderByFields().length * 6));
10533                    }
10534                    else {
10535                            query = new StringBundler(3);
10536                    }
10537    
10538                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10539    
10540                    query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10541    
10542                    query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10543    
10544                    if (orderByComparator != null) {
10545                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
10546    
10547                            if (orderByConditionFields.length > 0) {
10548                                    query.append(WHERE_AND);
10549                            }
10550    
10551                            for (int i = 0; i < orderByConditionFields.length; i++) {
10552                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10553                                    query.append(orderByConditionFields[i]);
10554    
10555                                    if ((i + 1) < orderByConditionFields.length) {
10556                                            if (orderByComparator.isAscending() ^ previous) {
10557                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
10558                                            }
10559                                            else {
10560                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
10561                                            }
10562                                    }
10563                                    else {
10564                                            if (orderByComparator.isAscending() ^ previous) {
10565                                                    query.append(WHERE_GREATER_THAN);
10566                                            }
10567                                            else {
10568                                                    query.append(WHERE_LESSER_THAN);
10569                                            }
10570                                    }
10571                            }
10572    
10573                            query.append(ORDER_BY_CLAUSE);
10574    
10575                            String[] orderByFields = orderByComparator.getOrderByFields();
10576    
10577                            for (int i = 0; i < orderByFields.length; i++) {
10578                                    query.append(_ORDER_BY_ENTITY_ALIAS);
10579                                    query.append(orderByFields[i]);
10580    
10581                                    if ((i + 1) < orderByFields.length) {
10582                                            if (orderByComparator.isAscending() ^ previous) {
10583                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
10584                                            }
10585                                            else {
10586                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
10587                                            }
10588                                    }
10589                                    else {
10590                                            if (orderByComparator.isAscending() ^ previous) {
10591                                                    query.append(ORDER_BY_ASC);
10592                                            }
10593                                            else {
10594                                                    query.append(ORDER_BY_DESC);
10595                                            }
10596                                    }
10597                            }
10598                    }
10599                    else {
10600                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10601                    }
10602    
10603                    String sql = query.toString();
10604    
10605                    Query q = session.createQuery(sql);
10606    
10607                    q.setFirstResult(0);
10608                    q.setMaxResults(2);
10609    
10610                    QueryPos qPos = QueryPos.getInstance(q);
10611    
10612                    qPos.add(threadId);
10613    
10614                    qPos.add(status);
10615    
10616                    if (orderByComparator != null) {
10617                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
10618    
10619                            for (Object value : values) {
10620                                    qPos.add(value);
10621                            }
10622                    }
10623    
10624                    List<MBMessage> list = q.list();
10625    
10626                    if (list.size() == 2) {
10627                            return list.get(1);
10628                    }
10629                    else {
10630                            return null;
10631                    }
10632            }
10633    
10634            /**
10635             * Removes all the message-boards messages where threadId = &#63; and status = &#63; from the database.
10636             *
10637             * @param threadId the thread ID
10638             * @param status the status
10639             * @throws SystemException if a system exception occurred
10640             */
10641            public void removeByTR_S(long threadId, int status)
10642                    throws SystemException {
10643                    for (MBMessage mbMessage : findByTR_S(threadId, status,
10644                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
10645                            remove(mbMessage);
10646                    }
10647            }
10648    
10649            /**
10650             * Returns the number of message-boards messages where threadId = &#63; and status = &#63;.
10651             *
10652             * @param threadId the thread ID
10653             * @param status the status
10654             * @return the number of matching message-boards messages
10655             * @throws SystemException if a system exception occurred
10656             */
10657            public int countByTR_S(long threadId, int status) throws SystemException {
10658                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TR_S;
10659    
10660                    Object[] finderArgs = new Object[] { threadId, status };
10661    
10662                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
10663                                    this);
10664    
10665                    if (count == null) {
10666                            StringBundler query = new StringBundler(3);
10667    
10668                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
10669    
10670                            query.append(_FINDER_COLUMN_TR_S_THREADID_2);
10671    
10672                            query.append(_FINDER_COLUMN_TR_S_STATUS_2);
10673    
10674                            String sql = query.toString();
10675    
10676                            Session session = null;
10677    
10678                            try {
10679                                    session = openSession();
10680    
10681                                    Query q = session.createQuery(sql);
10682    
10683                                    QueryPos qPos = QueryPos.getInstance(q);
10684    
10685                                    qPos.add(threadId);
10686    
10687                                    qPos.add(status);
10688    
10689                                    count = (Long)q.uniqueResult();
10690    
10691                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
10692                            }
10693                            catch (Exception e) {
10694                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10695    
10696                                    throw processException(e);
10697                            }
10698                            finally {
10699                                    closeSession(session);
10700                            }
10701                    }
10702    
10703                    return count.intValue();
10704            }
10705    
10706            private static final String _FINDER_COLUMN_TR_S_THREADID_2 = "mbMessage.threadId = ? AND ";
10707            private static final String _FINDER_COLUMN_TR_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.parentMessageId != 0";
10708            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10709                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10710                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_S",
10711                            new String[] {
10712                                    Long.class.getName(), Long.class.getName(),
10713                                    Integer.class.getName(),
10714                                    
10715                            Integer.class.getName(), Integer.class.getName(),
10716                                    OrderByComparator.class.getName()
10717                            });
10718            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10719                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
10720                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_S",
10721                            new String[] {
10722                                    Long.class.getName(), Long.class.getName(),
10723                                    Integer.class.getName()
10724                            },
10725                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
10726                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
10727                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
10728                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
10729            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
10730                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
10731                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_S",
10732                            new String[] {
10733                                    Long.class.getName(), Long.class.getName(),
10734                                    Integer.class.getName()
10735                            });
10736    
10737            /**
10738             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10739             *
10740             * @param groupId the group ID
10741             * @param userId the user ID
10742             * @param status the status
10743             * @return the matching message-boards messages
10744             * @throws SystemException if a system exception occurred
10745             */
10746            public List<MBMessage> findByG_U_S(long groupId, long userId, int status)
10747                    throws SystemException {
10748                    return findByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
10749                            QueryUtil.ALL_POS, null);
10750            }
10751    
10752            /**
10753             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10754             *
10755             * <p>
10756             * 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.
10757             * </p>
10758             *
10759             * @param groupId the group ID
10760             * @param userId the user ID
10761             * @param status the status
10762             * @param start the lower bound of the range of message-boards messages
10763             * @param end the upper bound of the range of message-boards messages (not inclusive)
10764             * @return the range of matching message-boards messages
10765             * @throws SystemException if a system exception occurred
10766             */
10767            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10768                    int start, int end) throws SystemException {
10769                    return findByG_U_S(groupId, userId, status, start, end, null);
10770            }
10771    
10772            /**
10773             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
10774             *
10775             * <p>
10776             * 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.
10777             * </p>
10778             *
10779             * @param groupId the group ID
10780             * @param userId the user ID
10781             * @param status the status
10782             * @param start the lower bound of the range of message-boards messages
10783             * @param end the upper bound of the range of message-boards messages (not inclusive)
10784             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
10785             * @return the ordered range of matching message-boards messages
10786             * @throws SystemException if a system exception occurred
10787             */
10788            public List<MBMessage> findByG_U_S(long groupId, long userId, int status,
10789                    int start, int end, OrderByComparator orderByComparator)
10790                    throws SystemException {
10791                    boolean pagination = true;
10792                    FinderPath finderPath = null;
10793                    Object[] finderArgs = null;
10794    
10795                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
10796                                    (orderByComparator == null)) {
10797                            pagination = false;
10798                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S;
10799                            finderArgs = new Object[] { groupId, userId, status };
10800                    }
10801                    else {
10802                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_S;
10803                            finderArgs = new Object[] {
10804                                            groupId, userId, status,
10805                                            
10806                                            start, end, orderByComparator
10807                                    };
10808                    }
10809    
10810                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
10811                                    finderArgs, this);
10812    
10813                    if ((list != null) && !list.isEmpty()) {
10814                            for (MBMessage mbMessage : list) {
10815                                    if ((groupId != mbMessage.getGroupId()) ||
10816                                                    (userId != mbMessage.getUserId()) ||
10817                                                    (status != mbMessage.getStatus())) {
10818                                            list = null;
10819    
10820                                            break;
10821                                    }
10822                            }
10823                    }
10824    
10825                    if (list == null) {
10826                            StringBundler query = null;
10827    
10828                            if (orderByComparator != null) {
10829                                    query = new StringBundler(5 +
10830                                                    (orderByComparator.getOrderByFields().length * 3));
10831                            }
10832                            else {
10833                                    query = new StringBundler(5);
10834                            }
10835    
10836                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
10837    
10838                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
10839    
10840                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
10841    
10842                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
10843    
10844                            if (orderByComparator != null) {
10845                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
10846                                            orderByComparator);
10847                            }
10848                            else
10849                             if (pagination) {
10850                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
10851                            }
10852    
10853                            String sql = query.toString();
10854    
10855                            Session session = null;
10856    
10857                            try {
10858                                    session = openSession();
10859    
10860                                    Query q = session.createQuery(sql);
10861    
10862                                    QueryPos qPos = QueryPos.getInstance(q);
10863    
10864                                    qPos.add(groupId);
10865    
10866                                    qPos.add(userId);
10867    
10868                                    qPos.add(status);
10869    
10870                                    if (!pagination) {
10871                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10872                                                            start, end, false);
10873    
10874                                            Collections.sort(list);
10875    
10876                                            list = new UnmodifiableList<MBMessage>(list);
10877                                    }
10878                                    else {
10879                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
10880                                                            start, end);
10881                                    }
10882    
10883                                    cacheResult(list);
10884    
10885                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
10886                            }
10887                            catch (Exception e) {
10888                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
10889    
10890                                    throw processException(e);
10891                            }
10892                            finally {
10893                                    closeSession(session);
10894                            }
10895                    }
10896    
10897                    return list;
10898            }
10899    
10900            /**
10901             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10902             *
10903             * @param groupId the group ID
10904             * @param userId the user ID
10905             * @param status the status
10906             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10907             * @return the first matching message-boards message
10908             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10909             * @throws SystemException if a system exception occurred
10910             */
10911            public MBMessage findByG_U_S_First(long groupId, long userId, int status,
10912                    OrderByComparator orderByComparator)
10913                    throws NoSuchMessageException, SystemException {
10914                    MBMessage mbMessage = fetchByG_U_S_First(groupId, userId, status,
10915                                    orderByComparator);
10916    
10917                    if (mbMessage != null) {
10918                            return mbMessage;
10919                    }
10920    
10921                    StringBundler msg = new StringBundler(8);
10922    
10923                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10924    
10925                    msg.append("groupId=");
10926                    msg.append(groupId);
10927    
10928                    msg.append(", userId=");
10929                    msg.append(userId);
10930    
10931                    msg.append(", status=");
10932                    msg.append(status);
10933    
10934                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10935    
10936                    throw new NoSuchMessageException(msg.toString());
10937            }
10938    
10939            /**
10940             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10941             *
10942             * @param groupId the group ID
10943             * @param userId the user ID
10944             * @param status the status
10945             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10946             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
10947             * @throws SystemException if a system exception occurred
10948             */
10949            public MBMessage fetchByG_U_S_First(long groupId, long userId, int status,
10950                    OrderByComparator orderByComparator) throws SystemException {
10951                    List<MBMessage> list = findByG_U_S(groupId, userId, status, 0, 1,
10952                                    orderByComparator);
10953    
10954                    if (!list.isEmpty()) {
10955                            return list.get(0);
10956                    }
10957    
10958                    return null;
10959            }
10960    
10961            /**
10962             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
10963             *
10964             * @param groupId the group ID
10965             * @param userId the user ID
10966             * @param status the status
10967             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
10968             * @return the last matching message-boards message
10969             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
10970             * @throws SystemException if a system exception occurred
10971             */
10972            public MBMessage findByG_U_S_Last(long groupId, long userId, int status,
10973                    OrderByComparator orderByComparator)
10974                    throws NoSuchMessageException, SystemException {
10975                    MBMessage mbMessage = fetchByG_U_S_Last(groupId, userId, status,
10976                                    orderByComparator);
10977    
10978                    if (mbMessage != null) {
10979                            return mbMessage;
10980                    }
10981    
10982                    StringBundler msg = new StringBundler(8);
10983    
10984                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
10985    
10986                    msg.append("groupId=");
10987                    msg.append(groupId);
10988    
10989                    msg.append(", userId=");
10990                    msg.append(userId);
10991    
10992                    msg.append(", status=");
10993                    msg.append(status);
10994    
10995                    msg.append(StringPool.CLOSE_CURLY_BRACE);
10996    
10997                    throw new NoSuchMessageException(msg.toString());
10998            }
10999    
11000            /**
11001             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and status = &#63;.
11002             *
11003             * @param groupId the group ID
11004             * @param userId the user ID
11005             * @param status the status
11006             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11007             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11008             * @throws SystemException if a system exception occurred
11009             */
11010            public MBMessage fetchByG_U_S_Last(long groupId, long userId, int status,
11011                    OrderByComparator orderByComparator) throws SystemException {
11012                    int count = countByG_U_S(groupId, userId, status);
11013    
11014                    List<MBMessage> list = findByG_U_S(groupId, userId, status, count - 1,
11015                                    count, orderByComparator);
11016    
11017                    if (!list.isEmpty()) {
11018                            return list.get(0);
11019                    }
11020    
11021                    return null;
11022            }
11023    
11024            /**
11025             * 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;.
11026             *
11027             * @param messageId the primary key of the current message-boards message
11028             * @param groupId the group ID
11029             * @param userId the user ID
11030             * @param status the status
11031             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11032             * @return the previous, current, and next message-boards message
11033             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11034             * @throws SystemException if a system exception occurred
11035             */
11036            public MBMessage[] findByG_U_S_PrevAndNext(long messageId, long groupId,
11037                    long userId, int status, OrderByComparator orderByComparator)
11038                    throws NoSuchMessageException, SystemException {
11039                    MBMessage mbMessage = findByPrimaryKey(messageId);
11040    
11041                    Session session = null;
11042    
11043                    try {
11044                            session = openSession();
11045    
11046                            MBMessage[] array = new MBMessageImpl[3];
11047    
11048                            array[0] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11049                                            userId, status, orderByComparator, true);
11050    
11051                            array[1] = mbMessage;
11052    
11053                            array[2] = getByG_U_S_PrevAndNext(session, mbMessage, groupId,
11054                                            userId, status, orderByComparator, false);
11055    
11056                            return array;
11057                    }
11058                    catch (Exception e) {
11059                            throw processException(e);
11060                    }
11061                    finally {
11062                            closeSession(session);
11063                    }
11064            }
11065    
11066            protected MBMessage getByG_U_S_PrevAndNext(Session session,
11067                    MBMessage mbMessage, long groupId, long userId, int status,
11068                    OrderByComparator orderByComparator, boolean previous) {
11069                    StringBundler query = null;
11070    
11071                    if (orderByComparator != null) {
11072                            query = new StringBundler(6 +
11073                                            (orderByComparator.getOrderByFields().length * 6));
11074                    }
11075                    else {
11076                            query = new StringBundler(3);
11077                    }
11078    
11079                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11080    
11081                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11082    
11083                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11084    
11085                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11086    
11087                    if (orderByComparator != null) {
11088                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11089    
11090                            if (orderByConditionFields.length > 0) {
11091                                    query.append(WHERE_AND);
11092                            }
11093    
11094                            for (int i = 0; i < orderByConditionFields.length; i++) {
11095                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11096                                    query.append(orderByConditionFields[i]);
11097    
11098                                    if ((i + 1) < orderByConditionFields.length) {
11099                                            if (orderByComparator.isAscending() ^ previous) {
11100                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11101                                            }
11102                                            else {
11103                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11104                                            }
11105                                    }
11106                                    else {
11107                                            if (orderByComparator.isAscending() ^ previous) {
11108                                                    query.append(WHERE_GREATER_THAN);
11109                                            }
11110                                            else {
11111                                                    query.append(WHERE_LESSER_THAN);
11112                                            }
11113                                    }
11114                            }
11115    
11116                            query.append(ORDER_BY_CLAUSE);
11117    
11118                            String[] orderByFields = orderByComparator.getOrderByFields();
11119    
11120                            for (int i = 0; i < orderByFields.length; i++) {
11121                                    query.append(_ORDER_BY_ENTITY_ALIAS);
11122                                    query.append(orderByFields[i]);
11123    
11124                                    if ((i + 1) < orderByFields.length) {
11125                                            if (orderByComparator.isAscending() ^ previous) {
11126                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11127                                            }
11128                                            else {
11129                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11130                                            }
11131                                    }
11132                                    else {
11133                                            if (orderByComparator.isAscending() ^ previous) {
11134                                                    query.append(ORDER_BY_ASC);
11135                                            }
11136                                            else {
11137                                                    query.append(ORDER_BY_DESC);
11138                                            }
11139                                    }
11140                            }
11141                    }
11142                    else {
11143                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11144                    }
11145    
11146                    String sql = query.toString();
11147    
11148                    Query q = session.createQuery(sql);
11149    
11150                    q.setFirstResult(0);
11151                    q.setMaxResults(2);
11152    
11153                    QueryPos qPos = QueryPos.getInstance(q);
11154    
11155                    qPos.add(groupId);
11156    
11157                    qPos.add(userId);
11158    
11159                    qPos.add(status);
11160    
11161                    if (orderByComparator != null) {
11162                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11163    
11164                            for (Object value : values) {
11165                                    qPos.add(value);
11166                            }
11167                    }
11168    
11169                    List<MBMessage> list = q.list();
11170    
11171                    if (list.size() == 2) {
11172                            return list.get(1);
11173                    }
11174                    else {
11175                            return null;
11176                    }
11177            }
11178    
11179            /**
11180             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11181             *
11182             * @param groupId the group ID
11183             * @param userId the user ID
11184             * @param status the status
11185             * @return the matching message-boards messages that the user has permission to view
11186             * @throws SystemException if a system exception occurred
11187             */
11188            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11189                    int status) throws SystemException {
11190                    return filterFindByG_U_S(groupId, userId, status, QueryUtil.ALL_POS,
11191                            QueryUtil.ALL_POS, null);
11192            }
11193    
11194            /**
11195             * 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;.
11196             *
11197             * <p>
11198             * 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.
11199             * </p>
11200             *
11201             * @param groupId the group ID
11202             * @param userId the user ID
11203             * @param status the status
11204             * @param start the lower bound of the range of message-boards messages
11205             * @param end the upper bound of the range of message-boards messages (not inclusive)
11206             * @return the range of matching message-boards messages that the user has permission to view
11207             * @throws SystemException if a system exception occurred
11208             */
11209            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11210                    int status, int start, int end) throws SystemException {
11211                    return filterFindByG_U_S(groupId, userId, status, start, end, null);
11212            }
11213    
11214            /**
11215             * 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;.
11216             *
11217             * <p>
11218             * 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.
11219             * </p>
11220             *
11221             * @param groupId the group ID
11222             * @param userId the user ID
11223             * @param status the status
11224             * @param start the lower bound of the range of message-boards messages
11225             * @param end the upper bound of the range of message-boards messages (not inclusive)
11226             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11227             * @return the ordered range of matching message-boards messages that the user has permission to view
11228             * @throws SystemException if a system exception occurred
11229             */
11230            public List<MBMessage> filterFindByG_U_S(long groupId, long userId,
11231                    int status, int start, int end, OrderByComparator orderByComparator)
11232                    throws SystemException {
11233                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11234                            return findByG_U_S(groupId, userId, status, start, end,
11235                                    orderByComparator);
11236                    }
11237    
11238                    StringBundler query = null;
11239    
11240                    if (orderByComparator != null) {
11241                            query = new StringBundler(5 +
11242                                            (orderByComparator.getOrderByFields().length * 3));
11243                    }
11244                    else {
11245                            query = new StringBundler(5);
11246                    }
11247    
11248                    if (getDB().isSupportsInlineDistinct()) {
11249                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11250                    }
11251                    else {
11252                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11253                    }
11254    
11255                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11256    
11257                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11258    
11259                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11260    
11261                    if (!getDB().isSupportsInlineDistinct()) {
11262                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11263                    }
11264    
11265                    if (orderByComparator != null) {
11266                            if (getDB().isSupportsInlineDistinct()) {
11267                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11268                                            orderByComparator, true);
11269                            }
11270                            else {
11271                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
11272                                            orderByComparator, true);
11273                            }
11274                    }
11275                    else {
11276                            if (getDB().isSupportsInlineDistinct()) {
11277                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11278                            }
11279                            else {
11280                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11281                            }
11282                    }
11283    
11284                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11285                                    MBMessage.class.getName(),
11286                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11287    
11288                    Session session = null;
11289    
11290                    try {
11291                            session = openSession();
11292    
11293                            SQLQuery q = session.createSQLQuery(sql);
11294    
11295                            if (getDB().isSupportsInlineDistinct()) {
11296                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11297                            }
11298                            else {
11299                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11300                            }
11301    
11302                            QueryPos qPos = QueryPos.getInstance(q);
11303    
11304                            qPos.add(groupId);
11305    
11306                            qPos.add(userId);
11307    
11308                            qPos.add(status);
11309    
11310                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
11311                    }
11312                    catch (Exception e) {
11313                            throw processException(e);
11314                    }
11315                    finally {
11316                            closeSession(session);
11317                    }
11318            }
11319    
11320            /**
11321             * 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;.
11322             *
11323             * @param messageId the primary key of the current message-boards message
11324             * @param groupId the group ID
11325             * @param userId the user ID
11326             * @param status the status
11327             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11328             * @return the previous, current, and next message-boards message
11329             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11330             * @throws SystemException if a system exception occurred
11331             */
11332            public MBMessage[] filterFindByG_U_S_PrevAndNext(long messageId,
11333                    long groupId, long userId, int status,
11334                    OrderByComparator orderByComparator)
11335                    throws NoSuchMessageException, SystemException {
11336                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11337                            return findByG_U_S_PrevAndNext(messageId, groupId, userId, status,
11338                                    orderByComparator);
11339                    }
11340    
11341                    MBMessage mbMessage = findByPrimaryKey(messageId);
11342    
11343                    Session session = null;
11344    
11345                    try {
11346                            session = openSession();
11347    
11348                            MBMessage[] array = new MBMessageImpl[3];
11349    
11350                            array[0] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11351                                            groupId, userId, status, orderByComparator, true);
11352    
11353                            array[1] = mbMessage;
11354    
11355                            array[2] = filterGetByG_U_S_PrevAndNext(session, mbMessage,
11356                                            groupId, userId, status, orderByComparator, false);
11357    
11358                            return array;
11359                    }
11360                    catch (Exception e) {
11361                            throw processException(e);
11362                    }
11363                    finally {
11364                            closeSession(session);
11365                    }
11366            }
11367    
11368            protected MBMessage filterGetByG_U_S_PrevAndNext(Session session,
11369                    MBMessage mbMessage, long groupId, long userId, int status,
11370                    OrderByComparator orderByComparator, boolean previous) {
11371                    StringBundler query = null;
11372    
11373                    if (orderByComparator != null) {
11374                            query = new StringBundler(6 +
11375                                            (orderByComparator.getOrderByFields().length * 6));
11376                    }
11377                    else {
11378                            query = new StringBundler(3);
11379                    }
11380    
11381                    if (getDB().isSupportsInlineDistinct()) {
11382                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
11383                    }
11384                    else {
11385                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
11386                    }
11387    
11388                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11389    
11390                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11391    
11392                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11393    
11394                    if (!getDB().isSupportsInlineDistinct()) {
11395                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
11396                    }
11397    
11398                    if (orderByComparator != null) {
11399                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
11400    
11401                            if (orderByConditionFields.length > 0) {
11402                                    query.append(WHERE_AND);
11403                            }
11404    
11405                            for (int i = 0; i < orderByConditionFields.length; i++) {
11406                                    if (getDB().isSupportsInlineDistinct()) {
11407                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11408                                    }
11409                                    else {
11410                                            query.append(_ORDER_BY_ENTITY_TABLE);
11411                                    }
11412    
11413                                    query.append(orderByConditionFields[i]);
11414    
11415                                    if ((i + 1) < orderByConditionFields.length) {
11416                                            if (orderByComparator.isAscending() ^ previous) {
11417                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
11418                                            }
11419                                            else {
11420                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
11421                                            }
11422                                    }
11423                                    else {
11424                                            if (orderByComparator.isAscending() ^ previous) {
11425                                                    query.append(WHERE_GREATER_THAN);
11426                                            }
11427                                            else {
11428                                                    query.append(WHERE_LESSER_THAN);
11429                                            }
11430                                    }
11431                            }
11432    
11433                            query.append(ORDER_BY_CLAUSE);
11434    
11435                            String[] orderByFields = orderByComparator.getOrderByFields();
11436    
11437                            for (int i = 0; i < orderByFields.length; i++) {
11438                                    if (getDB().isSupportsInlineDistinct()) {
11439                                            query.append(_ORDER_BY_ENTITY_ALIAS);
11440                                    }
11441                                    else {
11442                                            query.append(_ORDER_BY_ENTITY_TABLE);
11443                                    }
11444    
11445                                    query.append(orderByFields[i]);
11446    
11447                                    if ((i + 1) < orderByFields.length) {
11448                                            if (orderByComparator.isAscending() ^ previous) {
11449                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
11450                                            }
11451                                            else {
11452                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
11453                                            }
11454                                    }
11455                                    else {
11456                                            if (orderByComparator.isAscending() ^ previous) {
11457                                                    query.append(ORDER_BY_ASC);
11458                                            }
11459                                            else {
11460                                                    query.append(ORDER_BY_DESC);
11461                                            }
11462                                    }
11463                            }
11464                    }
11465                    else {
11466                            if (getDB().isSupportsInlineDistinct()) {
11467                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11468                            }
11469                            else {
11470                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
11471                            }
11472                    }
11473    
11474                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11475                                    MBMessage.class.getName(),
11476                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11477    
11478                    SQLQuery q = session.createSQLQuery(sql);
11479    
11480                    q.setFirstResult(0);
11481                    q.setMaxResults(2);
11482    
11483                    if (getDB().isSupportsInlineDistinct()) {
11484                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
11485                    }
11486                    else {
11487                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
11488                    }
11489    
11490                    QueryPos qPos = QueryPos.getInstance(q);
11491    
11492                    qPos.add(groupId);
11493    
11494                    qPos.add(userId);
11495    
11496                    qPos.add(status);
11497    
11498                    if (orderByComparator != null) {
11499                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
11500    
11501                            for (Object value : values) {
11502                                    qPos.add(value);
11503                            }
11504                    }
11505    
11506                    List<MBMessage> list = q.list();
11507    
11508                    if (list.size() == 2) {
11509                            return list.get(1);
11510                    }
11511                    else {
11512                            return null;
11513                    }
11514            }
11515    
11516            /**
11517             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and status = &#63; from the database.
11518             *
11519             * @param groupId the group ID
11520             * @param userId the user ID
11521             * @param status the status
11522             * @throws SystemException if a system exception occurred
11523             */
11524            public void removeByG_U_S(long groupId, long userId, int status)
11525                    throws SystemException {
11526                    for (MBMessage mbMessage : findByG_U_S(groupId, userId, status,
11527                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
11528                            remove(mbMessage);
11529                    }
11530            }
11531    
11532            /**
11533             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and status = &#63;.
11534             *
11535             * @param groupId the group ID
11536             * @param userId the user ID
11537             * @param status the status
11538             * @return the number of matching message-boards messages
11539             * @throws SystemException if a system exception occurred
11540             */
11541            public int countByG_U_S(long groupId, long userId, int status)
11542                    throws SystemException {
11543                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_S;
11544    
11545                    Object[] finderArgs = new Object[] { groupId, userId, status };
11546    
11547                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
11548                                    this);
11549    
11550                    if (count == null) {
11551                            StringBundler query = new StringBundler(4);
11552    
11553                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
11554    
11555                            query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11556    
11557                            query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11558    
11559                            query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11560    
11561                            String sql = query.toString();
11562    
11563                            Session session = null;
11564    
11565                            try {
11566                                    session = openSession();
11567    
11568                                    Query q = session.createQuery(sql);
11569    
11570                                    QueryPos qPos = QueryPos.getInstance(q);
11571    
11572                                    qPos.add(groupId);
11573    
11574                                    qPos.add(userId);
11575    
11576                                    qPos.add(status);
11577    
11578                                    count = (Long)q.uniqueResult();
11579    
11580                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
11581                            }
11582                            catch (Exception e) {
11583                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11584    
11585                                    throw processException(e);
11586                            }
11587                            finally {
11588                                    closeSession(session);
11589                            }
11590                    }
11591    
11592                    return count.intValue();
11593            }
11594    
11595            /**
11596             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and status = &#63;.
11597             *
11598             * @param groupId the group ID
11599             * @param userId the user ID
11600             * @param status the status
11601             * @return the number of matching message-boards messages that the user has permission to view
11602             * @throws SystemException if a system exception occurred
11603             */
11604            public int filterCountByG_U_S(long groupId, long userId, int status)
11605                    throws SystemException {
11606                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
11607                            return countByG_U_S(groupId, userId, status);
11608                    }
11609    
11610                    StringBundler query = new StringBundler(4);
11611    
11612                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
11613    
11614                    query.append(_FINDER_COLUMN_G_U_S_GROUPID_2);
11615    
11616                    query.append(_FINDER_COLUMN_G_U_S_USERID_2);
11617    
11618                    query.append(_FINDER_COLUMN_G_U_S_STATUS_2);
11619    
11620                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
11621                                    MBMessage.class.getName(),
11622                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
11623    
11624                    Session session = null;
11625    
11626                    try {
11627                            session = openSession();
11628    
11629                            SQLQuery q = session.createSQLQuery(sql);
11630    
11631                            q.addScalar(COUNT_COLUMN_NAME,
11632                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
11633    
11634                            QueryPos qPos = QueryPos.getInstance(q);
11635    
11636                            qPos.add(groupId);
11637    
11638                            qPos.add(userId);
11639    
11640                            qPos.add(status);
11641    
11642                            Long count = (Long)q.uniqueResult();
11643    
11644                            return count.intValue();
11645                    }
11646                    catch (Exception e) {
11647                            throw processException(e);
11648                    }
11649                    finally {
11650                            closeSession(session);
11651                    }
11652            }
11653    
11654            private static final String _FINDER_COLUMN_G_U_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
11655            private static final String _FINDER_COLUMN_G_U_S_USERID_2 = "mbMessage.userId = ? AND ";
11656            private static final String _FINDER_COLUMN_G_U_S_STATUS_2 = "mbMessage.status = ? AND mbMessage.categoryId != -1";
11657            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11658                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11659                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T",
11660                            new String[] {
11661                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
11662                                    
11663                            Integer.class.getName(), Integer.class.getName(),
11664                                    OrderByComparator.class.getName()
11665                            });
11666            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11667                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
11668                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T",
11669                            new String[] {
11670                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11671                            },
11672                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
11673                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
11674                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
11675                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
11676            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
11677                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
11678                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T",
11679                            new String[] {
11680                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
11681                            });
11682    
11683            /**
11684             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11685             *
11686             * @param groupId the group ID
11687             * @param categoryId the category ID
11688             * @param threadId the thread ID
11689             * @return the matching message-boards messages
11690             * @throws SystemException if a system exception occurred
11691             */
11692            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11693                    long threadId) throws SystemException {
11694                    return findByG_C_T(groupId, categoryId, threadId, QueryUtil.ALL_POS,
11695                            QueryUtil.ALL_POS, null);
11696            }
11697    
11698            /**
11699             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11700             *
11701             * <p>
11702             * 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.
11703             * </p>
11704             *
11705             * @param groupId the group ID
11706             * @param categoryId the category ID
11707             * @param threadId the thread ID
11708             * @param start the lower bound of the range of message-boards messages
11709             * @param end the upper bound of the range of message-boards messages (not inclusive)
11710             * @return the range of matching message-boards messages
11711             * @throws SystemException if a system exception occurred
11712             */
11713            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11714                    long threadId, int start, int end) throws SystemException {
11715                    return findByG_C_T(groupId, categoryId, threadId, start, end, null);
11716            }
11717    
11718            /**
11719             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11720             *
11721             * <p>
11722             * 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.
11723             * </p>
11724             *
11725             * @param groupId the group ID
11726             * @param categoryId the category ID
11727             * @param threadId the thread ID
11728             * @param start the lower bound of the range of message-boards messages
11729             * @param end the upper bound of the range of message-boards messages (not inclusive)
11730             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
11731             * @return the ordered range of matching message-boards messages
11732             * @throws SystemException if a system exception occurred
11733             */
11734            public List<MBMessage> findByG_C_T(long groupId, long categoryId,
11735                    long threadId, int start, int end, OrderByComparator orderByComparator)
11736                    throws SystemException {
11737                    boolean pagination = true;
11738                    FinderPath finderPath = null;
11739                    Object[] finderArgs = null;
11740    
11741                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
11742                                    (orderByComparator == null)) {
11743                            pagination = false;
11744                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T;
11745                            finderArgs = new Object[] { groupId, categoryId, threadId };
11746                    }
11747                    else {
11748                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T;
11749                            finderArgs = new Object[] {
11750                                            groupId, categoryId, threadId,
11751                                            
11752                                            start, end, orderByComparator
11753                                    };
11754                    }
11755    
11756                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
11757                                    finderArgs, this);
11758    
11759                    if ((list != null) && !list.isEmpty()) {
11760                            for (MBMessage mbMessage : list) {
11761                                    if ((groupId != mbMessage.getGroupId()) ||
11762                                                    (categoryId != mbMessage.getCategoryId()) ||
11763                                                    (threadId != mbMessage.getThreadId())) {
11764                                            list = null;
11765    
11766                                            break;
11767                                    }
11768                            }
11769                    }
11770    
11771                    if (list == null) {
11772                            StringBundler query = null;
11773    
11774                            if (orderByComparator != null) {
11775                                    query = new StringBundler(5 +
11776                                                    (orderByComparator.getOrderByFields().length * 3));
11777                            }
11778                            else {
11779                                    query = new StringBundler(5);
11780                            }
11781    
11782                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
11783    
11784                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
11785    
11786                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
11787    
11788                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
11789    
11790                            if (orderByComparator != null) {
11791                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
11792                                            orderByComparator);
11793                            }
11794                            else
11795                             if (pagination) {
11796                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
11797                            }
11798    
11799                            String sql = query.toString();
11800    
11801                            Session session = null;
11802    
11803                            try {
11804                                    session = openSession();
11805    
11806                                    Query q = session.createQuery(sql);
11807    
11808                                    QueryPos qPos = QueryPos.getInstance(q);
11809    
11810                                    qPos.add(groupId);
11811    
11812                                    qPos.add(categoryId);
11813    
11814                                    qPos.add(threadId);
11815    
11816                                    if (!pagination) {
11817                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11818                                                            start, end, false);
11819    
11820                                            Collections.sort(list);
11821    
11822                                            list = new UnmodifiableList<MBMessage>(list);
11823                                    }
11824                                    else {
11825                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
11826                                                            start, end);
11827                                    }
11828    
11829                                    cacheResult(list);
11830    
11831                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
11832                            }
11833                            catch (Exception e) {
11834                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
11835    
11836                                    throw processException(e);
11837                            }
11838                            finally {
11839                                    closeSession(session);
11840                            }
11841                    }
11842    
11843                    return list;
11844            }
11845    
11846            /**
11847             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11848             *
11849             * @param groupId the group ID
11850             * @param categoryId the category ID
11851             * @param threadId the thread ID
11852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11853             * @return the first matching message-boards message
11854             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11855             * @throws SystemException if a system exception occurred
11856             */
11857            public MBMessage findByG_C_T_First(long groupId, long categoryId,
11858                    long threadId, OrderByComparator orderByComparator)
11859                    throws NoSuchMessageException, SystemException {
11860                    MBMessage mbMessage = fetchByG_C_T_First(groupId, categoryId, threadId,
11861                                    orderByComparator);
11862    
11863                    if (mbMessage != null) {
11864                            return mbMessage;
11865                    }
11866    
11867                    StringBundler msg = new StringBundler(8);
11868    
11869                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11870    
11871                    msg.append("groupId=");
11872                    msg.append(groupId);
11873    
11874                    msg.append(", categoryId=");
11875                    msg.append(categoryId);
11876    
11877                    msg.append(", threadId=");
11878                    msg.append(threadId);
11879    
11880                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11881    
11882                    throw new NoSuchMessageException(msg.toString());
11883            }
11884    
11885            /**
11886             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11887             *
11888             * @param groupId the group ID
11889             * @param categoryId the category ID
11890             * @param threadId the thread ID
11891             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11892             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11893             * @throws SystemException if a system exception occurred
11894             */
11895            public MBMessage fetchByG_C_T_First(long groupId, long categoryId,
11896                    long threadId, OrderByComparator orderByComparator)
11897                    throws SystemException {
11898                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId, 0, 1,
11899                                    orderByComparator);
11900    
11901                    if (!list.isEmpty()) {
11902                            return list.get(0);
11903                    }
11904    
11905                    return null;
11906            }
11907    
11908            /**
11909             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11910             *
11911             * @param groupId the group ID
11912             * @param categoryId the category ID
11913             * @param threadId the thread ID
11914             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11915             * @return the last matching message-boards message
11916             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
11917             * @throws SystemException if a system exception occurred
11918             */
11919            public MBMessage findByG_C_T_Last(long groupId, long categoryId,
11920                    long threadId, OrderByComparator orderByComparator)
11921                    throws NoSuchMessageException, SystemException {
11922                    MBMessage mbMessage = fetchByG_C_T_Last(groupId, categoryId, threadId,
11923                                    orderByComparator);
11924    
11925                    if (mbMessage != null) {
11926                            return mbMessage;
11927                    }
11928    
11929                    StringBundler msg = new StringBundler(8);
11930    
11931                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
11932    
11933                    msg.append("groupId=");
11934                    msg.append(groupId);
11935    
11936                    msg.append(", categoryId=");
11937                    msg.append(categoryId);
11938    
11939                    msg.append(", threadId=");
11940                    msg.append(threadId);
11941    
11942                    msg.append(StringPool.CLOSE_CURLY_BRACE);
11943    
11944                    throw new NoSuchMessageException(msg.toString());
11945            }
11946    
11947            /**
11948             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
11949             *
11950             * @param groupId the group ID
11951             * @param categoryId the category ID
11952             * @param threadId the thread ID
11953             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11954             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
11955             * @throws SystemException if a system exception occurred
11956             */
11957            public MBMessage fetchByG_C_T_Last(long groupId, long categoryId,
11958                    long threadId, OrderByComparator orderByComparator)
11959                    throws SystemException {
11960                    int count = countByG_C_T(groupId, categoryId, threadId);
11961    
11962                    List<MBMessage> list = findByG_C_T(groupId, categoryId, threadId,
11963                                    count - 1, count, orderByComparator);
11964    
11965                    if (!list.isEmpty()) {
11966                            return list.get(0);
11967                    }
11968    
11969                    return null;
11970            }
11971    
11972            /**
11973             * 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;.
11974             *
11975             * @param messageId the primary key of the current message-boards message
11976             * @param groupId the group ID
11977             * @param categoryId the category ID
11978             * @param threadId the thread ID
11979             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
11980             * @return the previous, current, and next message-boards message
11981             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
11982             * @throws SystemException if a system exception occurred
11983             */
11984            public MBMessage[] findByG_C_T_PrevAndNext(long messageId, long groupId,
11985                    long categoryId, long threadId, OrderByComparator orderByComparator)
11986                    throws NoSuchMessageException, SystemException {
11987                    MBMessage mbMessage = findByPrimaryKey(messageId);
11988    
11989                    Session session = null;
11990    
11991                    try {
11992                            session = openSession();
11993    
11994                            MBMessage[] array = new MBMessageImpl[3];
11995    
11996                            array[0] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
11997                                            categoryId, threadId, orderByComparator, true);
11998    
11999                            array[1] = mbMessage;
12000    
12001                            array[2] = getByG_C_T_PrevAndNext(session, mbMessage, groupId,
12002                                            categoryId, threadId, orderByComparator, false);
12003    
12004                            return array;
12005                    }
12006                    catch (Exception e) {
12007                            throw processException(e);
12008                    }
12009                    finally {
12010                            closeSession(session);
12011                    }
12012            }
12013    
12014            protected MBMessage getByG_C_T_PrevAndNext(Session session,
12015                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12016                    OrderByComparator orderByComparator, boolean previous) {
12017                    StringBundler query = null;
12018    
12019                    if (orderByComparator != null) {
12020                            query = new StringBundler(6 +
12021                                            (orderByComparator.getOrderByFields().length * 6));
12022                    }
12023                    else {
12024                            query = new StringBundler(3);
12025                    }
12026    
12027                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12028    
12029                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12030    
12031                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12032    
12033                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12034    
12035                    if (orderByComparator != null) {
12036                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12037    
12038                            if (orderByConditionFields.length > 0) {
12039                                    query.append(WHERE_AND);
12040                            }
12041    
12042                            for (int i = 0; i < orderByConditionFields.length; i++) {
12043                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12044                                    query.append(orderByConditionFields[i]);
12045    
12046                                    if ((i + 1) < orderByConditionFields.length) {
12047                                            if (orderByComparator.isAscending() ^ previous) {
12048                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12049                                            }
12050                                            else {
12051                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12052                                            }
12053                                    }
12054                                    else {
12055                                            if (orderByComparator.isAscending() ^ previous) {
12056                                                    query.append(WHERE_GREATER_THAN);
12057                                            }
12058                                            else {
12059                                                    query.append(WHERE_LESSER_THAN);
12060                                            }
12061                                    }
12062                            }
12063    
12064                            query.append(ORDER_BY_CLAUSE);
12065    
12066                            String[] orderByFields = orderByComparator.getOrderByFields();
12067    
12068                            for (int i = 0; i < orderByFields.length; i++) {
12069                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12070                                    query.append(orderByFields[i]);
12071    
12072                                    if ((i + 1) < orderByFields.length) {
12073                                            if (orderByComparator.isAscending() ^ previous) {
12074                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12075                                            }
12076                                            else {
12077                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12078                                            }
12079                                    }
12080                                    else {
12081                                            if (orderByComparator.isAscending() ^ previous) {
12082                                                    query.append(ORDER_BY_ASC);
12083                                            }
12084                                            else {
12085                                                    query.append(ORDER_BY_DESC);
12086                                            }
12087                                    }
12088                            }
12089                    }
12090                    else {
12091                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12092                    }
12093    
12094                    String sql = query.toString();
12095    
12096                    Query q = session.createQuery(sql);
12097    
12098                    q.setFirstResult(0);
12099                    q.setMaxResults(2);
12100    
12101                    QueryPos qPos = QueryPos.getInstance(q);
12102    
12103                    qPos.add(groupId);
12104    
12105                    qPos.add(categoryId);
12106    
12107                    qPos.add(threadId);
12108    
12109                    if (orderByComparator != null) {
12110                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12111    
12112                            for (Object value : values) {
12113                                    qPos.add(value);
12114                            }
12115                    }
12116    
12117                    List<MBMessage> list = q.list();
12118    
12119                    if (list.size() == 2) {
12120                            return list.get(1);
12121                    }
12122                    else {
12123                            return null;
12124                    }
12125            }
12126    
12127            /**
12128             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12129             *
12130             * @param groupId the group ID
12131             * @param categoryId the category ID
12132             * @param threadId the thread ID
12133             * @return the matching message-boards messages that the user has permission to view
12134             * @throws SystemException if a system exception occurred
12135             */
12136            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12137                    long threadId) throws SystemException {
12138                    return filterFindByG_C_T(groupId, categoryId, threadId,
12139                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
12140            }
12141    
12142            /**
12143             * 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;.
12144             *
12145             * <p>
12146             * 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.
12147             * </p>
12148             *
12149             * @param groupId the group ID
12150             * @param categoryId the category ID
12151             * @param threadId the thread ID
12152             * @param start the lower bound of the range of message-boards messages
12153             * @param end the upper bound of the range of message-boards messages (not inclusive)
12154             * @return the range of matching message-boards messages that the user has permission to view
12155             * @throws SystemException if a system exception occurred
12156             */
12157            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12158                    long threadId, int start, int end) throws SystemException {
12159                    return filterFindByG_C_T(groupId, categoryId, threadId, start, end, null);
12160            }
12161    
12162            /**
12163             * 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;.
12164             *
12165             * <p>
12166             * 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.
12167             * </p>
12168             *
12169             * @param groupId the group ID
12170             * @param categoryId the category ID
12171             * @param threadId the thread ID
12172             * @param start the lower bound of the range of message-boards messages
12173             * @param end the upper bound of the range of message-boards messages (not inclusive)
12174             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12175             * @return the ordered range of matching message-boards messages that the user has permission to view
12176             * @throws SystemException if a system exception occurred
12177             */
12178            public List<MBMessage> filterFindByG_C_T(long groupId, long categoryId,
12179                    long threadId, int start, int end, OrderByComparator orderByComparator)
12180                    throws SystemException {
12181                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12182                            return findByG_C_T(groupId, categoryId, threadId, start, end,
12183                                    orderByComparator);
12184                    }
12185    
12186                    StringBundler query = null;
12187    
12188                    if (orderByComparator != null) {
12189                            query = new StringBundler(5 +
12190                                            (orderByComparator.getOrderByFields().length * 3));
12191                    }
12192                    else {
12193                            query = new StringBundler(5);
12194                    }
12195    
12196                    if (getDB().isSupportsInlineDistinct()) {
12197                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12198                    }
12199                    else {
12200                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12201                    }
12202    
12203                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12204    
12205                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12206    
12207                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12208    
12209                    if (!getDB().isSupportsInlineDistinct()) {
12210                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12211                    }
12212    
12213                    if (orderByComparator != null) {
12214                            if (getDB().isSupportsInlineDistinct()) {
12215                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12216                                            orderByComparator, true);
12217                            }
12218                            else {
12219                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
12220                                            orderByComparator, true);
12221                            }
12222                    }
12223                    else {
12224                            if (getDB().isSupportsInlineDistinct()) {
12225                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12226                            }
12227                            else {
12228                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12229                            }
12230                    }
12231    
12232                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12233                                    MBMessage.class.getName(),
12234                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12235    
12236                    Session session = null;
12237    
12238                    try {
12239                            session = openSession();
12240    
12241                            SQLQuery q = session.createSQLQuery(sql);
12242    
12243                            if (getDB().isSupportsInlineDistinct()) {
12244                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12245                            }
12246                            else {
12247                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12248                            }
12249    
12250                            QueryPos qPos = QueryPos.getInstance(q);
12251    
12252                            qPos.add(groupId);
12253    
12254                            qPos.add(categoryId);
12255    
12256                            qPos.add(threadId);
12257    
12258                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
12259                    }
12260                    catch (Exception e) {
12261                            throw processException(e);
12262                    }
12263                    finally {
12264                            closeSession(session);
12265                    }
12266            }
12267    
12268            /**
12269             * 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;.
12270             *
12271             * @param messageId the primary key of the current message-boards message
12272             * @param groupId the group ID
12273             * @param categoryId the category ID
12274             * @param threadId the thread ID
12275             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12276             * @return the previous, current, and next message-boards message
12277             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12278             * @throws SystemException if a system exception occurred
12279             */
12280            public MBMessage[] filterFindByG_C_T_PrevAndNext(long messageId,
12281                    long groupId, long categoryId, long threadId,
12282                    OrderByComparator orderByComparator)
12283                    throws NoSuchMessageException, SystemException {
12284                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12285                            return findByG_C_T_PrevAndNext(messageId, groupId, categoryId,
12286                                    threadId, orderByComparator);
12287                    }
12288    
12289                    MBMessage mbMessage = findByPrimaryKey(messageId);
12290    
12291                    Session session = null;
12292    
12293                    try {
12294                            session = openSession();
12295    
12296                            MBMessage[] array = new MBMessageImpl[3];
12297    
12298                            array[0] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12299                                            groupId, categoryId, threadId, orderByComparator, true);
12300    
12301                            array[1] = mbMessage;
12302    
12303                            array[2] = filterGetByG_C_T_PrevAndNext(session, mbMessage,
12304                                            groupId, categoryId, threadId, orderByComparator, false);
12305    
12306                            return array;
12307                    }
12308                    catch (Exception e) {
12309                            throw processException(e);
12310                    }
12311                    finally {
12312                            closeSession(session);
12313                    }
12314            }
12315    
12316            protected MBMessage filterGetByG_C_T_PrevAndNext(Session session,
12317                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
12318                    OrderByComparator orderByComparator, boolean previous) {
12319                    StringBundler query = null;
12320    
12321                    if (orderByComparator != null) {
12322                            query = new StringBundler(6 +
12323                                            (orderByComparator.getOrderByFields().length * 6));
12324                    }
12325                    else {
12326                            query = new StringBundler(3);
12327                    }
12328    
12329                    if (getDB().isSupportsInlineDistinct()) {
12330                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
12331                    }
12332                    else {
12333                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
12334                    }
12335    
12336                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12337    
12338                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12339    
12340                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12341    
12342                    if (!getDB().isSupportsInlineDistinct()) {
12343                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
12344                    }
12345    
12346                    if (orderByComparator != null) {
12347                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12348    
12349                            if (orderByConditionFields.length > 0) {
12350                                    query.append(WHERE_AND);
12351                            }
12352    
12353                            for (int i = 0; i < orderByConditionFields.length; i++) {
12354                                    if (getDB().isSupportsInlineDistinct()) {
12355                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12356                                    }
12357                                    else {
12358                                            query.append(_ORDER_BY_ENTITY_TABLE);
12359                                    }
12360    
12361                                    query.append(orderByConditionFields[i]);
12362    
12363                                    if ((i + 1) < orderByConditionFields.length) {
12364                                            if (orderByComparator.isAscending() ^ previous) {
12365                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
12366                                            }
12367                                            else {
12368                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
12369                                            }
12370                                    }
12371                                    else {
12372                                            if (orderByComparator.isAscending() ^ previous) {
12373                                                    query.append(WHERE_GREATER_THAN);
12374                                            }
12375                                            else {
12376                                                    query.append(WHERE_LESSER_THAN);
12377                                            }
12378                                    }
12379                            }
12380    
12381                            query.append(ORDER_BY_CLAUSE);
12382    
12383                            String[] orderByFields = orderByComparator.getOrderByFields();
12384    
12385                            for (int i = 0; i < orderByFields.length; i++) {
12386                                    if (getDB().isSupportsInlineDistinct()) {
12387                                            query.append(_ORDER_BY_ENTITY_ALIAS);
12388                                    }
12389                                    else {
12390                                            query.append(_ORDER_BY_ENTITY_TABLE);
12391                                    }
12392    
12393                                    query.append(orderByFields[i]);
12394    
12395                                    if ((i + 1) < orderByFields.length) {
12396                                            if (orderByComparator.isAscending() ^ previous) {
12397                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
12398                                            }
12399                                            else {
12400                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
12401                                            }
12402                                    }
12403                                    else {
12404                                            if (orderByComparator.isAscending() ^ previous) {
12405                                                    query.append(ORDER_BY_ASC);
12406                                            }
12407                                            else {
12408                                                    query.append(ORDER_BY_DESC);
12409                                            }
12410                                    }
12411                            }
12412                    }
12413                    else {
12414                            if (getDB().isSupportsInlineDistinct()) {
12415                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12416                            }
12417                            else {
12418                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
12419                            }
12420                    }
12421    
12422                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12423                                    MBMessage.class.getName(),
12424                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12425    
12426                    SQLQuery q = session.createSQLQuery(sql);
12427    
12428                    q.setFirstResult(0);
12429                    q.setMaxResults(2);
12430    
12431                    if (getDB().isSupportsInlineDistinct()) {
12432                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
12433                    }
12434                    else {
12435                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
12436                    }
12437    
12438                    QueryPos qPos = QueryPos.getInstance(q);
12439    
12440                    qPos.add(groupId);
12441    
12442                    qPos.add(categoryId);
12443    
12444                    qPos.add(threadId);
12445    
12446                    if (orderByComparator != null) {
12447                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
12448    
12449                            for (Object value : values) {
12450                                    qPos.add(value);
12451                            }
12452                    }
12453    
12454                    List<MBMessage> list = q.list();
12455    
12456                    if (list.size() == 2) {
12457                            return list.get(1);
12458                    }
12459                    else {
12460                            return null;
12461                    }
12462            }
12463    
12464            /**
12465             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; from the database.
12466             *
12467             * @param groupId the group ID
12468             * @param categoryId the category ID
12469             * @param threadId the thread ID
12470             * @throws SystemException if a system exception occurred
12471             */
12472            public void removeByG_C_T(long groupId, long categoryId, long threadId)
12473                    throws SystemException {
12474                    for (MBMessage mbMessage : findByG_C_T(groupId, categoryId, threadId,
12475                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
12476                            remove(mbMessage);
12477                    }
12478            }
12479    
12480            /**
12481             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12482             *
12483             * @param groupId the group ID
12484             * @param categoryId the category ID
12485             * @param threadId the thread ID
12486             * @return the number of matching message-boards messages
12487             * @throws SystemException if a system exception occurred
12488             */
12489            public int countByG_C_T(long groupId, long categoryId, long threadId)
12490                    throws SystemException {
12491                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T;
12492    
12493                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId };
12494    
12495                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
12496                                    this);
12497    
12498                    if (count == null) {
12499                            StringBundler query = new StringBundler(4);
12500    
12501                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
12502    
12503                            query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12504    
12505                            query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12506    
12507                            query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12508    
12509                            String sql = query.toString();
12510    
12511                            Session session = null;
12512    
12513                            try {
12514                                    session = openSession();
12515    
12516                                    Query q = session.createQuery(sql);
12517    
12518                                    QueryPos qPos = QueryPos.getInstance(q);
12519    
12520                                    qPos.add(groupId);
12521    
12522                                    qPos.add(categoryId);
12523    
12524                                    qPos.add(threadId);
12525    
12526                                    count = (Long)q.uniqueResult();
12527    
12528                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
12529                            }
12530                            catch (Exception e) {
12531                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12532    
12533                                    throw processException(e);
12534                            }
12535                            finally {
12536                                    closeSession(session);
12537                            }
12538                    }
12539    
12540                    return count.intValue();
12541            }
12542    
12543            /**
12544             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and threadId = &#63;.
12545             *
12546             * @param groupId the group ID
12547             * @param categoryId the category ID
12548             * @param threadId the thread ID
12549             * @return the number of matching message-boards messages that the user has permission to view
12550             * @throws SystemException if a system exception occurred
12551             */
12552            public int filterCountByG_C_T(long groupId, long categoryId, long threadId)
12553                    throws SystemException {
12554                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
12555                            return countByG_C_T(groupId, categoryId, threadId);
12556                    }
12557    
12558                    StringBundler query = new StringBundler(4);
12559    
12560                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
12561    
12562                    query.append(_FINDER_COLUMN_G_C_T_GROUPID_2);
12563    
12564                    query.append(_FINDER_COLUMN_G_C_T_CATEGORYID_2);
12565    
12566                    query.append(_FINDER_COLUMN_G_C_T_THREADID_2);
12567    
12568                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
12569                                    MBMessage.class.getName(),
12570                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
12571    
12572                    Session session = null;
12573    
12574                    try {
12575                            session = openSession();
12576    
12577                            SQLQuery q = session.createSQLQuery(sql);
12578    
12579                            q.addScalar(COUNT_COLUMN_NAME,
12580                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
12581    
12582                            QueryPos qPos = QueryPos.getInstance(q);
12583    
12584                            qPos.add(groupId);
12585    
12586                            qPos.add(categoryId);
12587    
12588                            qPos.add(threadId);
12589    
12590                            Long count = (Long)q.uniqueResult();
12591    
12592                            return count.intValue();
12593                    }
12594                    catch (Exception e) {
12595                            throw processException(e);
12596                    }
12597                    finally {
12598                            closeSession(session);
12599                    }
12600            }
12601    
12602            private static final String _FINDER_COLUMN_G_C_T_GROUPID_2 = "mbMessage.groupId = ? AND ";
12603            private static final String _FINDER_COLUMN_G_C_T_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
12604            private static final String _FINDER_COLUMN_G_C_T_THREADID_2 = "mbMessage.threadId = ?";
12605            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12606                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12607                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_S",
12608                            new String[] {
12609                                    Long.class.getName(), Long.class.getName(),
12610                                    Integer.class.getName(),
12611                                    
12612                            Integer.class.getName(), Integer.class.getName(),
12613                                    OrderByComparator.class.getName()
12614                            });
12615            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12616                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
12617                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_S",
12618                            new String[] {
12619                                    Long.class.getName(), Long.class.getName(),
12620                                    Integer.class.getName()
12621                            },
12622                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
12623                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
12624                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
12625                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
12626            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
12627                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
12628                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_S",
12629                            new String[] {
12630                                    Long.class.getName(), Long.class.getName(),
12631                                    Integer.class.getName()
12632                            });
12633    
12634            /**
12635             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12636             *
12637             * @param groupId the group ID
12638             * @param categoryId the category ID
12639             * @param status the status
12640             * @return the matching message-boards messages
12641             * @throws SystemException if a system exception occurred
12642             */
12643            public List<MBMessage> findByG_C_S(long groupId, long categoryId, int status)
12644                    throws SystemException {
12645                    return findByG_C_S(groupId, categoryId, status, QueryUtil.ALL_POS,
12646                            QueryUtil.ALL_POS, null);
12647            }
12648    
12649            /**
12650             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12651             *
12652             * <p>
12653             * 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.
12654             * </p>
12655             *
12656             * @param groupId the group ID
12657             * @param categoryId the category ID
12658             * @param status the status
12659             * @param start the lower bound of the range of message-boards messages
12660             * @param end the upper bound of the range of message-boards messages (not inclusive)
12661             * @return the range of matching message-boards messages
12662             * @throws SystemException if a system exception occurred
12663             */
12664            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12665                    int status, int start, int end) throws SystemException {
12666                    return findByG_C_S(groupId, categoryId, status, start, end, null);
12667            }
12668    
12669            /**
12670             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
12671             *
12672             * <p>
12673             * 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.
12674             * </p>
12675             *
12676             * @param groupId the group ID
12677             * @param categoryId the category ID
12678             * @param status the status
12679             * @param start the lower bound of the range of message-boards messages
12680             * @param end the upper bound of the range of message-boards messages (not inclusive)
12681             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
12682             * @return the ordered range of matching message-boards messages
12683             * @throws SystemException if a system exception occurred
12684             */
12685            public List<MBMessage> findByG_C_S(long groupId, long categoryId,
12686                    int status, int start, int end, OrderByComparator orderByComparator)
12687                    throws SystemException {
12688                    boolean pagination = true;
12689                    FinderPath finderPath = null;
12690                    Object[] finderArgs = null;
12691    
12692                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
12693                                    (orderByComparator == null)) {
12694                            pagination = false;
12695                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S;
12696                            finderArgs = new Object[] { groupId, categoryId, status };
12697                    }
12698                    else {
12699                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_S;
12700                            finderArgs = new Object[] {
12701                                            groupId, categoryId, status,
12702                                            
12703                                            start, end, orderByComparator
12704                                    };
12705                    }
12706    
12707                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
12708                                    finderArgs, this);
12709    
12710                    if ((list != null) && !list.isEmpty()) {
12711                            for (MBMessage mbMessage : list) {
12712                                    if ((groupId != mbMessage.getGroupId()) ||
12713                                                    (categoryId != mbMessage.getCategoryId()) ||
12714                                                    (status != mbMessage.getStatus())) {
12715                                            list = null;
12716    
12717                                            break;
12718                                    }
12719                            }
12720                    }
12721    
12722                    if (list == null) {
12723                            StringBundler query = null;
12724    
12725                            if (orderByComparator != null) {
12726                                    query = new StringBundler(5 +
12727                                                    (orderByComparator.getOrderByFields().length * 3));
12728                            }
12729                            else {
12730                                    query = new StringBundler(5);
12731                            }
12732    
12733                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12734    
12735                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12736    
12737                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12738    
12739                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12740    
12741                            if (orderByComparator != null) {
12742                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
12743                                            orderByComparator);
12744                            }
12745                            else
12746                             if (pagination) {
12747                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
12748                            }
12749    
12750                            String sql = query.toString();
12751    
12752                            Session session = null;
12753    
12754                            try {
12755                                    session = openSession();
12756    
12757                                    Query q = session.createQuery(sql);
12758    
12759                                    QueryPos qPos = QueryPos.getInstance(q);
12760    
12761                                    qPos.add(groupId);
12762    
12763                                    qPos.add(categoryId);
12764    
12765                                    qPos.add(status);
12766    
12767                                    if (!pagination) {
12768                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12769                                                            start, end, false);
12770    
12771                                            Collections.sort(list);
12772    
12773                                            list = new UnmodifiableList<MBMessage>(list);
12774                                    }
12775                                    else {
12776                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
12777                                                            start, end);
12778                                    }
12779    
12780                                    cacheResult(list);
12781    
12782                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
12783                            }
12784                            catch (Exception e) {
12785                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
12786    
12787                                    throw processException(e);
12788                            }
12789                            finally {
12790                                    closeSession(session);
12791                            }
12792                    }
12793    
12794                    return list;
12795            }
12796    
12797            /**
12798             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12799             *
12800             * @param groupId the group ID
12801             * @param categoryId the category ID
12802             * @param status the status
12803             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12804             * @return the first matching message-boards message
12805             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12806             * @throws SystemException if a system exception occurred
12807             */
12808            public MBMessage findByG_C_S_First(long groupId, long categoryId,
12809                    int status, OrderByComparator orderByComparator)
12810                    throws NoSuchMessageException, SystemException {
12811                    MBMessage mbMessage = fetchByG_C_S_First(groupId, categoryId, status,
12812                                    orderByComparator);
12813    
12814                    if (mbMessage != null) {
12815                            return mbMessage;
12816                    }
12817    
12818                    StringBundler msg = new StringBundler(8);
12819    
12820                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12821    
12822                    msg.append("groupId=");
12823                    msg.append(groupId);
12824    
12825                    msg.append(", categoryId=");
12826                    msg.append(categoryId);
12827    
12828                    msg.append(", status=");
12829                    msg.append(status);
12830    
12831                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12832    
12833                    throw new NoSuchMessageException(msg.toString());
12834            }
12835    
12836            /**
12837             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12838             *
12839             * @param groupId the group ID
12840             * @param categoryId the category ID
12841             * @param status the status
12842             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12843             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12844             * @throws SystemException if a system exception occurred
12845             */
12846            public MBMessage fetchByG_C_S_First(long groupId, long categoryId,
12847                    int status, OrderByComparator orderByComparator)
12848                    throws SystemException {
12849                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status, 0, 1,
12850                                    orderByComparator);
12851    
12852                    if (!list.isEmpty()) {
12853                            return list.get(0);
12854                    }
12855    
12856                    return null;
12857            }
12858    
12859            /**
12860             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12861             *
12862             * @param groupId the group ID
12863             * @param categoryId the category ID
12864             * @param status the status
12865             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12866             * @return the last matching message-boards message
12867             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
12868             * @throws SystemException if a system exception occurred
12869             */
12870            public MBMessage findByG_C_S_Last(long groupId, long categoryId,
12871                    int status, OrderByComparator orderByComparator)
12872                    throws NoSuchMessageException, SystemException {
12873                    MBMessage mbMessage = fetchByG_C_S_Last(groupId, categoryId, status,
12874                                    orderByComparator);
12875    
12876                    if (mbMessage != null) {
12877                            return mbMessage;
12878                    }
12879    
12880                    StringBundler msg = new StringBundler(8);
12881    
12882                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
12883    
12884                    msg.append("groupId=");
12885                    msg.append(groupId);
12886    
12887                    msg.append(", categoryId=");
12888                    msg.append(categoryId);
12889    
12890                    msg.append(", status=");
12891                    msg.append(status);
12892    
12893                    msg.append(StringPool.CLOSE_CURLY_BRACE);
12894    
12895                    throw new NoSuchMessageException(msg.toString());
12896            }
12897    
12898            /**
12899             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and status = &#63;.
12900             *
12901             * @param groupId the group ID
12902             * @param categoryId the category ID
12903             * @param status the status
12904             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12905             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
12906             * @throws SystemException if a system exception occurred
12907             */
12908            public MBMessage fetchByG_C_S_Last(long groupId, long categoryId,
12909                    int status, OrderByComparator orderByComparator)
12910                    throws SystemException {
12911                    int count = countByG_C_S(groupId, categoryId, status);
12912    
12913                    List<MBMessage> list = findByG_C_S(groupId, categoryId, status,
12914                                    count - 1, count, orderByComparator);
12915    
12916                    if (!list.isEmpty()) {
12917                            return list.get(0);
12918                    }
12919    
12920                    return null;
12921            }
12922    
12923            /**
12924             * 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;.
12925             *
12926             * @param messageId the primary key of the current message-boards message
12927             * @param groupId the group ID
12928             * @param categoryId the category ID
12929             * @param status the status
12930             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
12931             * @return the previous, current, and next message-boards message
12932             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
12933             * @throws SystemException if a system exception occurred
12934             */
12935            public MBMessage[] findByG_C_S_PrevAndNext(long messageId, long groupId,
12936                    long categoryId, int status, OrderByComparator orderByComparator)
12937                    throws NoSuchMessageException, SystemException {
12938                    MBMessage mbMessage = findByPrimaryKey(messageId);
12939    
12940                    Session session = null;
12941    
12942                    try {
12943                            session = openSession();
12944    
12945                            MBMessage[] array = new MBMessageImpl[3];
12946    
12947                            array[0] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12948                                            categoryId, status, orderByComparator, true);
12949    
12950                            array[1] = mbMessage;
12951    
12952                            array[2] = getByG_C_S_PrevAndNext(session, mbMessage, groupId,
12953                                            categoryId, status, orderByComparator, false);
12954    
12955                            return array;
12956                    }
12957                    catch (Exception e) {
12958                            throw processException(e);
12959                    }
12960                    finally {
12961                            closeSession(session);
12962                    }
12963            }
12964    
12965            protected MBMessage getByG_C_S_PrevAndNext(Session session,
12966                    MBMessage mbMessage, long groupId, long categoryId, int status,
12967                    OrderByComparator orderByComparator, boolean previous) {
12968                    StringBundler query = null;
12969    
12970                    if (orderByComparator != null) {
12971                            query = new StringBundler(6 +
12972                                            (orderByComparator.getOrderByFields().length * 6));
12973                    }
12974                    else {
12975                            query = new StringBundler(3);
12976                    }
12977    
12978                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
12979    
12980                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
12981    
12982                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
12983    
12984                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
12985    
12986                    if (orderByComparator != null) {
12987                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
12988    
12989                            if (orderByConditionFields.length > 0) {
12990                                    query.append(WHERE_AND);
12991                            }
12992    
12993                            for (int i = 0; i < orderByConditionFields.length; i++) {
12994                                    query.append(_ORDER_BY_ENTITY_ALIAS);
12995                                    query.append(orderByConditionFields[i]);
12996    
12997                                    if ((i + 1) < orderByConditionFields.length) {
12998                                            if (orderByComparator.isAscending() ^ previous) {
12999                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13000                                            }
13001                                            else {
13002                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13003                                            }
13004                                    }
13005                                    else {
13006                                            if (orderByComparator.isAscending() ^ previous) {
13007                                                    query.append(WHERE_GREATER_THAN);
13008                                            }
13009                                            else {
13010                                                    query.append(WHERE_LESSER_THAN);
13011                                            }
13012                                    }
13013                            }
13014    
13015                            query.append(ORDER_BY_CLAUSE);
13016    
13017                            String[] orderByFields = orderByComparator.getOrderByFields();
13018    
13019                            for (int i = 0; i < orderByFields.length; i++) {
13020                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13021                                    query.append(orderByFields[i]);
13022    
13023                                    if ((i + 1) < orderByFields.length) {
13024                                            if (orderByComparator.isAscending() ^ previous) {
13025                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13026                                            }
13027                                            else {
13028                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13029                                            }
13030                                    }
13031                                    else {
13032                                            if (orderByComparator.isAscending() ^ previous) {
13033                                                    query.append(ORDER_BY_ASC);
13034                                            }
13035                                            else {
13036                                                    query.append(ORDER_BY_DESC);
13037                                            }
13038                                    }
13039                            }
13040                    }
13041                    else {
13042                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13043                    }
13044    
13045                    String sql = query.toString();
13046    
13047                    Query q = session.createQuery(sql);
13048    
13049                    q.setFirstResult(0);
13050                    q.setMaxResults(2);
13051    
13052                    QueryPos qPos = QueryPos.getInstance(q);
13053    
13054                    qPos.add(groupId);
13055    
13056                    qPos.add(categoryId);
13057    
13058                    qPos.add(status);
13059    
13060                    if (orderByComparator != null) {
13061                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13062    
13063                            for (Object value : values) {
13064                                    qPos.add(value);
13065                            }
13066                    }
13067    
13068                    List<MBMessage> list = q.list();
13069    
13070                    if (list.size() == 2) {
13071                            return list.get(1);
13072                    }
13073                    else {
13074                            return null;
13075                    }
13076            }
13077    
13078            /**
13079             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13080             *
13081             * @param groupId the group ID
13082             * @param categoryId the category ID
13083             * @param status the status
13084             * @return the matching message-boards messages that the user has permission to view
13085             * @throws SystemException if a system exception occurred
13086             */
13087            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13088                    int status) throws SystemException {
13089                    return filterFindByG_C_S(groupId, categoryId, status,
13090                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
13091            }
13092    
13093            /**
13094             * 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;.
13095             *
13096             * <p>
13097             * 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.
13098             * </p>
13099             *
13100             * @param groupId the group ID
13101             * @param categoryId the category ID
13102             * @param status the status
13103             * @param start the lower bound of the range of message-boards messages
13104             * @param end the upper bound of the range of message-boards messages (not inclusive)
13105             * @return the range of matching message-boards messages that the user has permission to view
13106             * @throws SystemException if a system exception occurred
13107             */
13108            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13109                    int status, int start, int end) throws SystemException {
13110                    return filterFindByG_C_S(groupId, categoryId, status, start, end, null);
13111            }
13112    
13113            /**
13114             * 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;.
13115             *
13116             * <p>
13117             * 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.
13118             * </p>
13119             *
13120             * @param groupId the group ID
13121             * @param categoryId the category ID
13122             * @param status the status
13123             * @param start the lower bound of the range of message-boards messages
13124             * @param end the upper bound of the range of message-boards messages (not inclusive)
13125             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13126             * @return the ordered range of matching message-boards messages that the user has permission to view
13127             * @throws SystemException if a system exception occurred
13128             */
13129            public List<MBMessage> filterFindByG_C_S(long groupId, long categoryId,
13130                    int status, int start, int end, OrderByComparator orderByComparator)
13131                    throws SystemException {
13132                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13133                            return findByG_C_S(groupId, categoryId, status, start, end,
13134                                    orderByComparator);
13135                    }
13136    
13137                    StringBundler query = null;
13138    
13139                    if (orderByComparator != null) {
13140                            query = new StringBundler(5 +
13141                                            (orderByComparator.getOrderByFields().length * 3));
13142                    }
13143                    else {
13144                            query = new StringBundler(5);
13145                    }
13146    
13147                    if (getDB().isSupportsInlineDistinct()) {
13148                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13149                    }
13150                    else {
13151                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13152                    }
13153    
13154                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13155    
13156                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13157    
13158                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13159    
13160                    if (!getDB().isSupportsInlineDistinct()) {
13161                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13162                    }
13163    
13164                    if (orderByComparator != null) {
13165                            if (getDB().isSupportsInlineDistinct()) {
13166                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13167                                            orderByComparator, true);
13168                            }
13169                            else {
13170                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
13171                                            orderByComparator, true);
13172                            }
13173                    }
13174                    else {
13175                            if (getDB().isSupportsInlineDistinct()) {
13176                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13177                            }
13178                            else {
13179                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13180                            }
13181                    }
13182    
13183                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13184                                    MBMessage.class.getName(),
13185                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13186    
13187                    Session session = null;
13188    
13189                    try {
13190                            session = openSession();
13191    
13192                            SQLQuery q = session.createSQLQuery(sql);
13193    
13194                            if (getDB().isSupportsInlineDistinct()) {
13195                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13196                            }
13197                            else {
13198                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13199                            }
13200    
13201                            QueryPos qPos = QueryPos.getInstance(q);
13202    
13203                            qPos.add(groupId);
13204    
13205                            qPos.add(categoryId);
13206    
13207                            qPos.add(status);
13208    
13209                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
13210                    }
13211                    catch (Exception e) {
13212                            throw processException(e);
13213                    }
13214                    finally {
13215                            closeSession(session);
13216                    }
13217            }
13218    
13219            /**
13220             * 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;.
13221             *
13222             * @param messageId the primary key of the current message-boards message
13223             * @param groupId the group ID
13224             * @param categoryId the category ID
13225             * @param status the status
13226             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13227             * @return the previous, current, and next message-boards message
13228             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13229             * @throws SystemException if a system exception occurred
13230             */
13231            public MBMessage[] filterFindByG_C_S_PrevAndNext(long messageId,
13232                    long groupId, long categoryId, int status,
13233                    OrderByComparator orderByComparator)
13234                    throws NoSuchMessageException, SystemException {
13235                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13236                            return findByG_C_S_PrevAndNext(messageId, groupId, categoryId,
13237                                    status, orderByComparator);
13238                    }
13239    
13240                    MBMessage mbMessage = findByPrimaryKey(messageId);
13241    
13242                    Session session = null;
13243    
13244                    try {
13245                            session = openSession();
13246    
13247                            MBMessage[] array = new MBMessageImpl[3];
13248    
13249                            array[0] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13250                                            groupId, categoryId, status, orderByComparator, true);
13251    
13252                            array[1] = mbMessage;
13253    
13254                            array[2] = filterGetByG_C_S_PrevAndNext(session, mbMessage,
13255                                            groupId, categoryId, status, orderByComparator, false);
13256    
13257                            return array;
13258                    }
13259                    catch (Exception e) {
13260                            throw processException(e);
13261                    }
13262                    finally {
13263                            closeSession(session);
13264                    }
13265            }
13266    
13267            protected MBMessage filterGetByG_C_S_PrevAndNext(Session session,
13268                    MBMessage mbMessage, long groupId, long categoryId, int status,
13269                    OrderByComparator orderByComparator, boolean previous) {
13270                    StringBundler query = null;
13271    
13272                    if (orderByComparator != null) {
13273                            query = new StringBundler(6 +
13274                                            (orderByComparator.getOrderByFields().length * 6));
13275                    }
13276                    else {
13277                            query = new StringBundler(3);
13278                    }
13279    
13280                    if (getDB().isSupportsInlineDistinct()) {
13281                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
13282                    }
13283                    else {
13284                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
13285                    }
13286    
13287                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13288    
13289                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13290    
13291                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13292    
13293                    if (!getDB().isSupportsInlineDistinct()) {
13294                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
13295                    }
13296    
13297                    if (orderByComparator != null) {
13298                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13299    
13300                            if (orderByConditionFields.length > 0) {
13301                                    query.append(WHERE_AND);
13302                            }
13303    
13304                            for (int i = 0; i < orderByConditionFields.length; i++) {
13305                                    if (getDB().isSupportsInlineDistinct()) {
13306                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13307                                    }
13308                                    else {
13309                                            query.append(_ORDER_BY_ENTITY_TABLE);
13310                                    }
13311    
13312                                    query.append(orderByConditionFields[i]);
13313    
13314                                    if ((i + 1) < orderByConditionFields.length) {
13315                                            if (orderByComparator.isAscending() ^ previous) {
13316                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13317                                            }
13318                                            else {
13319                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13320                                            }
13321                                    }
13322                                    else {
13323                                            if (orderByComparator.isAscending() ^ previous) {
13324                                                    query.append(WHERE_GREATER_THAN);
13325                                            }
13326                                            else {
13327                                                    query.append(WHERE_LESSER_THAN);
13328                                            }
13329                                    }
13330                            }
13331    
13332                            query.append(ORDER_BY_CLAUSE);
13333    
13334                            String[] orderByFields = orderByComparator.getOrderByFields();
13335    
13336                            for (int i = 0; i < orderByFields.length; i++) {
13337                                    if (getDB().isSupportsInlineDistinct()) {
13338                                            query.append(_ORDER_BY_ENTITY_ALIAS);
13339                                    }
13340                                    else {
13341                                            query.append(_ORDER_BY_ENTITY_TABLE);
13342                                    }
13343    
13344                                    query.append(orderByFields[i]);
13345    
13346                                    if ((i + 1) < orderByFields.length) {
13347                                            if (orderByComparator.isAscending() ^ previous) {
13348                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13349                                            }
13350                                            else {
13351                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13352                                            }
13353                                    }
13354                                    else {
13355                                            if (orderByComparator.isAscending() ^ previous) {
13356                                                    query.append(ORDER_BY_ASC);
13357                                            }
13358                                            else {
13359                                                    query.append(ORDER_BY_DESC);
13360                                            }
13361                                    }
13362                            }
13363                    }
13364                    else {
13365                            if (getDB().isSupportsInlineDistinct()) {
13366                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13367                            }
13368                            else {
13369                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
13370                            }
13371                    }
13372    
13373                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13374                                    MBMessage.class.getName(),
13375                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13376    
13377                    SQLQuery q = session.createSQLQuery(sql);
13378    
13379                    q.setFirstResult(0);
13380                    q.setMaxResults(2);
13381    
13382                    if (getDB().isSupportsInlineDistinct()) {
13383                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
13384                    }
13385                    else {
13386                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
13387                    }
13388    
13389                    QueryPos qPos = QueryPos.getInstance(q);
13390    
13391                    qPos.add(groupId);
13392    
13393                    qPos.add(categoryId);
13394    
13395                    qPos.add(status);
13396    
13397                    if (orderByComparator != null) {
13398                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
13399    
13400                            for (Object value : values) {
13401                                    qPos.add(value);
13402                            }
13403                    }
13404    
13405                    List<MBMessage> list = q.list();
13406    
13407                    if (list.size() == 2) {
13408                            return list.get(1);
13409                    }
13410                    else {
13411                            return null;
13412                    }
13413            }
13414    
13415            /**
13416             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63; from the database.
13417             *
13418             * @param groupId the group ID
13419             * @param categoryId the category ID
13420             * @param status the status
13421             * @throws SystemException if a system exception occurred
13422             */
13423            public void removeByG_C_S(long groupId, long categoryId, int status)
13424                    throws SystemException {
13425                    for (MBMessage mbMessage : findByG_C_S(groupId, categoryId, status,
13426                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
13427                            remove(mbMessage);
13428                    }
13429            }
13430    
13431            /**
13432             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and status = &#63;.
13433             *
13434             * @param groupId the group ID
13435             * @param categoryId the category ID
13436             * @param status the status
13437             * @return the number of matching message-boards messages
13438             * @throws SystemException if a system exception occurred
13439             */
13440            public int countByG_C_S(long groupId, long categoryId, int status)
13441                    throws SystemException {
13442                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_S;
13443    
13444                    Object[] finderArgs = new Object[] { groupId, categoryId, status };
13445    
13446                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
13447                                    this);
13448    
13449                    if (count == null) {
13450                            StringBundler query = new StringBundler(4);
13451    
13452                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
13453    
13454                            query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13455    
13456                            query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13457    
13458                            query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13459    
13460                            String sql = query.toString();
13461    
13462                            Session session = null;
13463    
13464                            try {
13465                                    session = openSession();
13466    
13467                                    Query q = session.createQuery(sql);
13468    
13469                                    QueryPos qPos = QueryPos.getInstance(q);
13470    
13471                                    qPos.add(groupId);
13472    
13473                                    qPos.add(categoryId);
13474    
13475                                    qPos.add(status);
13476    
13477                                    count = (Long)q.uniqueResult();
13478    
13479                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
13480                            }
13481                            catch (Exception e) {
13482                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13483    
13484                                    throw processException(e);
13485                            }
13486                            finally {
13487                                    closeSession(session);
13488                            }
13489                    }
13490    
13491                    return count.intValue();
13492            }
13493    
13494            /**
13495             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and categoryId = &#63; and status = &#63;.
13496             *
13497             * @param groupId the group ID
13498             * @param categoryId the category ID
13499             * @param status the status
13500             * @return the number of matching message-boards messages that the user has permission to view
13501             * @throws SystemException if a system exception occurred
13502             */
13503            public int filterCountByG_C_S(long groupId, long categoryId, int status)
13504                    throws SystemException {
13505                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
13506                            return countByG_C_S(groupId, categoryId, status);
13507                    }
13508    
13509                    StringBundler query = new StringBundler(4);
13510    
13511                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
13512    
13513                    query.append(_FINDER_COLUMN_G_C_S_GROUPID_2);
13514    
13515                    query.append(_FINDER_COLUMN_G_C_S_CATEGORYID_2);
13516    
13517                    query.append(_FINDER_COLUMN_G_C_S_STATUS_2);
13518    
13519                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
13520                                    MBMessage.class.getName(),
13521                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
13522    
13523                    Session session = null;
13524    
13525                    try {
13526                            session = openSession();
13527    
13528                            SQLQuery q = session.createSQLQuery(sql);
13529    
13530                            q.addScalar(COUNT_COLUMN_NAME,
13531                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
13532    
13533                            QueryPos qPos = QueryPos.getInstance(q);
13534    
13535                            qPos.add(groupId);
13536    
13537                            qPos.add(categoryId);
13538    
13539                            qPos.add(status);
13540    
13541                            Long count = (Long)q.uniqueResult();
13542    
13543                            return count.intValue();
13544                    }
13545                    catch (Exception e) {
13546                            throw processException(e);
13547                    }
13548                    finally {
13549                            closeSession(session);
13550                    }
13551            }
13552    
13553            private static final String _FINDER_COLUMN_G_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
13554            private static final String _FINDER_COLUMN_G_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
13555            private static final String _FINDER_COLUMN_G_C_S_STATUS_2 = "mbMessage.status = ?";
13556            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13557                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13558                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C",
13559                            new String[] {
13560                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
13561                                    
13562                            Integer.class.getName(), Integer.class.getName(),
13563                                    OrderByComparator.class.getName()
13564                            });
13565            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13566                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
13567                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C",
13568                            new String[] {
13569                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13570                            },
13571                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
13572                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
13573                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
13574                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
13575            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
13576                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
13577                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C",
13578                            new String[] {
13579                                    Long.class.getName(), Long.class.getName(), Long.class.getName()
13580                            });
13581    
13582            /**
13583             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13584             *
13585             * @param userId the user ID
13586             * @param classNameId the class name ID
13587             * @param classPK the class p k
13588             * @return the matching message-boards messages
13589             * @throws SystemException if a system exception occurred
13590             */
13591            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13592                    long classPK) throws SystemException {
13593                    return findByU_C_C(userId, classNameId, classPK, QueryUtil.ALL_POS,
13594                            QueryUtil.ALL_POS, null);
13595            }
13596    
13597            /**
13598             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13599             *
13600             * <p>
13601             * 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.
13602             * </p>
13603             *
13604             * @param userId the user ID
13605             * @param classNameId the class name ID
13606             * @param classPK the class p k
13607             * @param start the lower bound of the range of message-boards messages
13608             * @param end the upper bound of the range of message-boards messages (not inclusive)
13609             * @return the range of matching message-boards messages
13610             * @throws SystemException if a system exception occurred
13611             */
13612            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13613                    long classPK, int start, int end) throws SystemException {
13614                    return findByU_C_C(userId, classNameId, classPK, start, end, null);
13615            }
13616    
13617            /**
13618             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13619             *
13620             * <p>
13621             * 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.
13622             * </p>
13623             *
13624             * @param userId the user ID
13625             * @param classNameId the class name ID
13626             * @param classPK the class p k
13627             * @param start the lower bound of the range of message-boards messages
13628             * @param end the upper bound of the range of message-boards messages (not inclusive)
13629             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
13630             * @return the ordered range of matching message-boards messages
13631             * @throws SystemException if a system exception occurred
13632             */
13633            public List<MBMessage> findByU_C_C(long userId, long classNameId,
13634                    long classPK, int start, int end, OrderByComparator orderByComparator)
13635                    throws SystemException {
13636                    boolean pagination = true;
13637                    FinderPath finderPath = null;
13638                    Object[] finderArgs = null;
13639    
13640                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
13641                                    (orderByComparator == null)) {
13642                            pagination = false;
13643                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C;
13644                            finderArgs = new Object[] { userId, classNameId, classPK };
13645                    }
13646                    else {
13647                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C;
13648                            finderArgs = new Object[] {
13649                                            userId, classNameId, classPK,
13650                                            
13651                                            start, end, orderByComparator
13652                                    };
13653                    }
13654    
13655                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
13656                                    finderArgs, this);
13657    
13658                    if ((list != null) && !list.isEmpty()) {
13659                            for (MBMessage mbMessage : list) {
13660                                    if ((userId != mbMessage.getUserId()) ||
13661                                                    (classNameId != mbMessage.getClassNameId()) ||
13662                                                    (classPK != mbMessage.getClassPK())) {
13663                                            list = null;
13664    
13665                                            break;
13666                                    }
13667                            }
13668                    }
13669    
13670                    if (list == null) {
13671                            StringBundler query = null;
13672    
13673                            if (orderByComparator != null) {
13674                                    query = new StringBundler(5 +
13675                                                    (orderByComparator.getOrderByFields().length * 3));
13676                            }
13677                            else {
13678                                    query = new StringBundler(5);
13679                            }
13680    
13681                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13682    
13683                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13684    
13685                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13686    
13687                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13688    
13689                            if (orderByComparator != null) {
13690                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
13691                                            orderByComparator);
13692                            }
13693                            else
13694                             if (pagination) {
13695                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13696                            }
13697    
13698                            String sql = query.toString();
13699    
13700                            Session session = null;
13701    
13702                            try {
13703                                    session = openSession();
13704    
13705                                    Query q = session.createQuery(sql);
13706    
13707                                    QueryPos qPos = QueryPos.getInstance(q);
13708    
13709                                    qPos.add(userId);
13710    
13711                                    qPos.add(classNameId);
13712    
13713                                    qPos.add(classPK);
13714    
13715                                    if (!pagination) {
13716                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13717                                                            start, end, false);
13718    
13719                                            Collections.sort(list);
13720    
13721                                            list = new UnmodifiableList<MBMessage>(list);
13722                                    }
13723                                    else {
13724                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
13725                                                            start, end);
13726                                    }
13727    
13728                                    cacheResult(list);
13729    
13730                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
13731                            }
13732                            catch (Exception e) {
13733                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
13734    
13735                                    throw processException(e);
13736                            }
13737                            finally {
13738                                    closeSession(session);
13739                            }
13740                    }
13741    
13742                    return list;
13743            }
13744    
13745            /**
13746             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13747             *
13748             * @param userId the user ID
13749             * @param classNameId the class name ID
13750             * @param classPK the class p k
13751             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13752             * @return the first matching message-boards message
13753             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13754             * @throws SystemException if a system exception occurred
13755             */
13756            public MBMessage findByU_C_C_First(long userId, long classNameId,
13757                    long classPK, OrderByComparator orderByComparator)
13758                    throws NoSuchMessageException, SystemException {
13759                    MBMessage mbMessage = fetchByU_C_C_First(userId, classNameId, classPK,
13760                                    orderByComparator);
13761    
13762                    if (mbMessage != null) {
13763                            return mbMessage;
13764                    }
13765    
13766                    StringBundler msg = new StringBundler(8);
13767    
13768                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13769    
13770                    msg.append("userId=");
13771                    msg.append(userId);
13772    
13773                    msg.append(", classNameId=");
13774                    msg.append(classNameId);
13775    
13776                    msg.append(", classPK=");
13777                    msg.append(classPK);
13778    
13779                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13780    
13781                    throw new NoSuchMessageException(msg.toString());
13782            }
13783    
13784            /**
13785             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13786             *
13787             * @param userId the user ID
13788             * @param classNameId the class name ID
13789             * @param classPK the class p k
13790             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13791             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13792             * @throws SystemException if a system exception occurred
13793             */
13794            public MBMessage fetchByU_C_C_First(long userId, long classNameId,
13795                    long classPK, OrderByComparator orderByComparator)
13796                    throws SystemException {
13797                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK, 0, 1,
13798                                    orderByComparator);
13799    
13800                    if (!list.isEmpty()) {
13801                            return list.get(0);
13802                    }
13803    
13804                    return null;
13805            }
13806    
13807            /**
13808             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13809             *
13810             * @param userId the user ID
13811             * @param classNameId the class name ID
13812             * @param classPK the class p k
13813             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13814             * @return the last matching message-boards message
13815             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
13816             * @throws SystemException if a system exception occurred
13817             */
13818            public MBMessage findByU_C_C_Last(long userId, long classNameId,
13819                    long classPK, OrderByComparator orderByComparator)
13820                    throws NoSuchMessageException, SystemException {
13821                    MBMessage mbMessage = fetchByU_C_C_Last(userId, classNameId, classPK,
13822                                    orderByComparator);
13823    
13824                    if (mbMessage != null) {
13825                            return mbMessage;
13826                    }
13827    
13828                    StringBundler msg = new StringBundler(8);
13829    
13830                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
13831    
13832                    msg.append("userId=");
13833                    msg.append(userId);
13834    
13835                    msg.append(", classNameId=");
13836                    msg.append(classNameId);
13837    
13838                    msg.append(", classPK=");
13839                    msg.append(classPK);
13840    
13841                    msg.append(StringPool.CLOSE_CURLY_BRACE);
13842    
13843                    throw new NoSuchMessageException(msg.toString());
13844            }
13845    
13846            /**
13847             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63;.
13848             *
13849             * @param userId the user ID
13850             * @param classNameId the class name ID
13851             * @param classPK the class p k
13852             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13853             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
13854             * @throws SystemException if a system exception occurred
13855             */
13856            public MBMessage fetchByU_C_C_Last(long userId, long classNameId,
13857                    long classPK, OrderByComparator orderByComparator)
13858                    throws SystemException {
13859                    int count = countByU_C_C(userId, classNameId, classPK);
13860    
13861                    List<MBMessage> list = findByU_C_C(userId, classNameId, classPK,
13862                                    count - 1, count, orderByComparator);
13863    
13864                    if (!list.isEmpty()) {
13865                            return list.get(0);
13866                    }
13867    
13868                    return null;
13869            }
13870    
13871            /**
13872             * 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;.
13873             *
13874             * @param messageId the primary key of the current message-boards message
13875             * @param userId the user ID
13876             * @param classNameId the class name ID
13877             * @param classPK the class p k
13878             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
13879             * @return the previous, current, and next message-boards message
13880             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
13881             * @throws SystemException if a system exception occurred
13882             */
13883            public MBMessage[] findByU_C_C_PrevAndNext(long messageId, long userId,
13884                    long classNameId, long classPK, OrderByComparator orderByComparator)
13885                    throws NoSuchMessageException, SystemException {
13886                    MBMessage mbMessage = findByPrimaryKey(messageId);
13887    
13888                    Session session = null;
13889    
13890                    try {
13891                            session = openSession();
13892    
13893                            MBMessage[] array = new MBMessageImpl[3];
13894    
13895                            array[0] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13896                                            classNameId, classPK, orderByComparator, true);
13897    
13898                            array[1] = mbMessage;
13899    
13900                            array[2] = getByU_C_C_PrevAndNext(session, mbMessage, userId,
13901                                            classNameId, classPK, orderByComparator, false);
13902    
13903                            return array;
13904                    }
13905                    catch (Exception e) {
13906                            throw processException(e);
13907                    }
13908                    finally {
13909                            closeSession(session);
13910                    }
13911            }
13912    
13913            protected MBMessage getByU_C_C_PrevAndNext(Session session,
13914                    MBMessage mbMessage, long userId, long classNameId, long classPK,
13915                    OrderByComparator orderByComparator, boolean previous) {
13916                    StringBundler query = null;
13917    
13918                    if (orderByComparator != null) {
13919                            query = new StringBundler(6 +
13920                                            (orderByComparator.getOrderByFields().length * 6));
13921                    }
13922                    else {
13923                            query = new StringBundler(3);
13924                    }
13925    
13926                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
13927    
13928                    query.append(_FINDER_COLUMN_U_C_C_USERID_2);
13929    
13930                    query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
13931    
13932                    query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
13933    
13934                    if (orderByComparator != null) {
13935                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
13936    
13937                            if (orderByConditionFields.length > 0) {
13938                                    query.append(WHERE_AND);
13939                            }
13940    
13941                            for (int i = 0; i < orderByConditionFields.length; i++) {
13942                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13943                                    query.append(orderByConditionFields[i]);
13944    
13945                                    if ((i + 1) < orderByConditionFields.length) {
13946                                            if (orderByComparator.isAscending() ^ previous) {
13947                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
13948                                            }
13949                                            else {
13950                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
13951                                            }
13952                                    }
13953                                    else {
13954                                            if (orderByComparator.isAscending() ^ previous) {
13955                                                    query.append(WHERE_GREATER_THAN);
13956                                            }
13957                                            else {
13958                                                    query.append(WHERE_LESSER_THAN);
13959                                            }
13960                                    }
13961                            }
13962    
13963                            query.append(ORDER_BY_CLAUSE);
13964    
13965                            String[] orderByFields = orderByComparator.getOrderByFields();
13966    
13967                            for (int i = 0; i < orderByFields.length; i++) {
13968                                    query.append(_ORDER_BY_ENTITY_ALIAS);
13969                                    query.append(orderByFields[i]);
13970    
13971                                    if ((i + 1) < orderByFields.length) {
13972                                            if (orderByComparator.isAscending() ^ previous) {
13973                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
13974                                            }
13975                                            else {
13976                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
13977                                            }
13978                                    }
13979                                    else {
13980                                            if (orderByComparator.isAscending() ^ previous) {
13981                                                    query.append(ORDER_BY_ASC);
13982                                            }
13983                                            else {
13984                                                    query.append(ORDER_BY_DESC);
13985                                            }
13986                                    }
13987                            }
13988                    }
13989                    else {
13990                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
13991                    }
13992    
13993                    String sql = query.toString();
13994    
13995                    Query q = session.createQuery(sql);
13996    
13997                    q.setFirstResult(0);
13998                    q.setMaxResults(2);
13999    
14000                    QueryPos qPos = QueryPos.getInstance(q);
14001    
14002                    qPos.add(userId);
14003    
14004                    qPos.add(classNameId);
14005    
14006                    qPos.add(classPK);
14007    
14008                    if (orderByComparator != null) {
14009                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14010    
14011                            for (Object value : values) {
14012                                    qPos.add(value);
14013                            }
14014                    }
14015    
14016                    List<MBMessage> list = q.list();
14017    
14018                    if (list.size() == 2) {
14019                            return list.get(1);
14020                    }
14021                    else {
14022                            return null;
14023                    }
14024            }
14025    
14026            /**
14027             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; from the database.
14028             *
14029             * @param userId the user ID
14030             * @param classNameId the class name ID
14031             * @param classPK the class p k
14032             * @throws SystemException if a system exception occurred
14033             */
14034            public void removeByU_C_C(long userId, long classNameId, long classPK)
14035                    throws SystemException {
14036                    for (MBMessage mbMessage : findByU_C_C(userId, classNameId, classPK,
14037                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14038                            remove(mbMessage);
14039                    }
14040            }
14041    
14042            /**
14043             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63;.
14044             *
14045             * @param userId the user ID
14046             * @param classNameId the class name ID
14047             * @param classPK the class p k
14048             * @return the number of matching message-boards messages
14049             * @throws SystemException if a system exception occurred
14050             */
14051            public int countByU_C_C(long userId, long classNameId, long classPK)
14052                    throws SystemException {
14053                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C;
14054    
14055                    Object[] finderArgs = new Object[] { userId, classNameId, classPK };
14056    
14057                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14058                                    this);
14059    
14060                    if (count == null) {
14061                            StringBundler query = new StringBundler(4);
14062    
14063                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14064    
14065                            query.append(_FINDER_COLUMN_U_C_C_USERID_2);
14066    
14067                            query.append(_FINDER_COLUMN_U_C_C_CLASSNAMEID_2);
14068    
14069                            query.append(_FINDER_COLUMN_U_C_C_CLASSPK_2);
14070    
14071                            String sql = query.toString();
14072    
14073                            Session session = null;
14074    
14075                            try {
14076                                    session = openSession();
14077    
14078                                    Query q = session.createQuery(sql);
14079    
14080                                    QueryPos qPos = QueryPos.getInstance(q);
14081    
14082                                    qPos.add(userId);
14083    
14084                                    qPos.add(classNameId);
14085    
14086                                    qPos.add(classPK);
14087    
14088                                    count = (Long)q.uniqueResult();
14089    
14090                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14091                            }
14092                            catch (Exception e) {
14093                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14094    
14095                                    throw processException(e);
14096                            }
14097                            finally {
14098                                    closeSession(session);
14099                            }
14100                    }
14101    
14102                    return count.intValue();
14103            }
14104    
14105            private static final String _FINDER_COLUMN_U_C_C_USERID_2 = "mbMessage.userId = ? AND ";
14106            private static final String _FINDER_COLUMN_U_C_C_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14107            private static final String _FINDER_COLUMN_U_C_C_CLASSPK_2 = "mbMessage.classPK = ?";
14108            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14109                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14110                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_S",
14111                            new String[] {
14112                                    Long.class.getName(), Long.class.getName(),
14113                                    Integer.class.getName(),
14114                                    
14115                            Integer.class.getName(), Integer.class.getName(),
14116                                    OrderByComparator.class.getName()
14117                            });
14118            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14119                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14120                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_S",
14121                            new String[] {
14122                                    Long.class.getName(), Long.class.getName(),
14123                                    Integer.class.getName()
14124                            },
14125                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
14126                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14127                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14128                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14129            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14130                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14131                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_S",
14132                            new String[] {
14133                                    Long.class.getName(), Long.class.getName(),
14134                                    Integer.class.getName()
14135                            });
14136            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14137                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14138                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByU_C_S",
14139                            new String[] {
14140                                    Long.class.getName(), Long.class.getName(),
14141                                    Integer.class.getName()
14142                            });
14143    
14144            /**
14145             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14146             *
14147             * @param userId the user ID
14148             * @param classNameId the class name ID
14149             * @param status the status
14150             * @return the matching message-boards messages
14151             * @throws SystemException if a system exception occurred
14152             */
14153            public List<MBMessage> findByU_C_S(long userId, long classNameId, int status)
14154                    throws SystemException {
14155                    return findByU_C_S(userId, classNameId, status, QueryUtil.ALL_POS,
14156                            QueryUtil.ALL_POS, null);
14157            }
14158    
14159            /**
14160             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14161             *
14162             * <p>
14163             * 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.
14164             * </p>
14165             *
14166             * @param userId the user ID
14167             * @param classNameId the class name ID
14168             * @param status the status
14169             * @param start the lower bound of the range of message-boards messages
14170             * @param end the upper bound of the range of message-boards messages (not inclusive)
14171             * @return the range of matching message-boards messages
14172             * @throws SystemException if a system exception occurred
14173             */
14174            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14175                    int status, int start, int end) throws SystemException {
14176                    return findByU_C_S(userId, classNameId, status, start, end, null);
14177            }
14178    
14179            /**
14180             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14181             *
14182             * <p>
14183             * 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.
14184             * </p>
14185             *
14186             * @param userId the user ID
14187             * @param classNameId the class name ID
14188             * @param status the status
14189             * @param start the lower bound of the range of message-boards messages
14190             * @param end the upper bound of the range of message-boards messages (not inclusive)
14191             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14192             * @return the ordered range of matching message-boards messages
14193             * @throws SystemException if a system exception occurred
14194             */
14195            public List<MBMessage> findByU_C_S(long userId, long classNameId,
14196                    int status, int start, int end, OrderByComparator orderByComparator)
14197                    throws SystemException {
14198                    boolean pagination = true;
14199                    FinderPath finderPath = null;
14200                    Object[] finderArgs = null;
14201    
14202                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14203                                    (orderByComparator == null)) {
14204                            pagination = false;
14205                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S;
14206                            finderArgs = new Object[] { userId, classNameId, status };
14207                    }
14208                    else {
14209                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S;
14210                            finderArgs = new Object[] {
14211                                            userId, classNameId, status,
14212                                            
14213                                            start, end, orderByComparator
14214                                    };
14215                    }
14216    
14217                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
14218                                    finderArgs, this);
14219    
14220                    if ((list != null) && !list.isEmpty()) {
14221                            for (MBMessage mbMessage : list) {
14222                                    if ((userId != mbMessage.getUserId()) ||
14223                                                    (classNameId != mbMessage.getClassNameId()) ||
14224                                                    (status != mbMessage.getStatus())) {
14225                                            list = null;
14226    
14227                                            break;
14228                                    }
14229                            }
14230                    }
14231    
14232                    if (list == null) {
14233                            StringBundler query = null;
14234    
14235                            if (orderByComparator != null) {
14236                                    query = new StringBundler(5 +
14237                                                    (orderByComparator.getOrderByFields().length * 3));
14238                            }
14239                            else {
14240                                    query = new StringBundler(5);
14241                            }
14242    
14243                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14244    
14245                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14246    
14247                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14248    
14249                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14250    
14251                            if (orderByComparator != null) {
14252                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14253                                            orderByComparator);
14254                            }
14255                            else
14256                             if (pagination) {
14257                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14258                            }
14259    
14260                            String sql = query.toString();
14261    
14262                            Session session = null;
14263    
14264                            try {
14265                                    session = openSession();
14266    
14267                                    Query q = session.createQuery(sql);
14268    
14269                                    QueryPos qPos = QueryPos.getInstance(q);
14270    
14271                                    qPos.add(userId);
14272    
14273                                    qPos.add(classNameId);
14274    
14275                                    qPos.add(status);
14276    
14277                                    if (!pagination) {
14278                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14279                                                            start, end, false);
14280    
14281                                            Collections.sort(list);
14282    
14283                                            list = new UnmodifiableList<MBMessage>(list);
14284                                    }
14285                                    else {
14286                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14287                                                            start, end);
14288                                    }
14289    
14290                                    cacheResult(list);
14291    
14292                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
14293                            }
14294                            catch (Exception e) {
14295                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14296    
14297                                    throw processException(e);
14298                            }
14299                            finally {
14300                                    closeSession(session);
14301                            }
14302                    }
14303    
14304                    return list;
14305            }
14306    
14307            /**
14308             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14309             *
14310             * @param userId the user ID
14311             * @param classNameId the class name ID
14312             * @param status the status
14313             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14314             * @return the first matching message-boards message
14315             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14316             * @throws SystemException if a system exception occurred
14317             */
14318            public MBMessage findByU_C_S_First(long userId, long classNameId,
14319                    int status, OrderByComparator orderByComparator)
14320                    throws NoSuchMessageException, SystemException {
14321                    MBMessage mbMessage = fetchByU_C_S_First(userId, classNameId, status,
14322                                    orderByComparator);
14323    
14324                    if (mbMessage != null) {
14325                            return mbMessage;
14326                    }
14327    
14328                    StringBundler msg = new StringBundler(8);
14329    
14330                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14331    
14332                    msg.append("userId=");
14333                    msg.append(userId);
14334    
14335                    msg.append(", classNameId=");
14336                    msg.append(classNameId);
14337    
14338                    msg.append(", status=");
14339                    msg.append(status);
14340    
14341                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14342    
14343                    throw new NoSuchMessageException(msg.toString());
14344            }
14345    
14346            /**
14347             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14348             *
14349             * @param userId the user ID
14350             * @param classNameId the class name ID
14351             * @param status the status
14352             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14353             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14354             * @throws SystemException if a system exception occurred
14355             */
14356            public MBMessage fetchByU_C_S_First(long userId, long classNameId,
14357                    int status, OrderByComparator orderByComparator)
14358                    throws SystemException {
14359                    List<MBMessage> list = findByU_C_S(userId, classNameId, status, 0, 1,
14360                                    orderByComparator);
14361    
14362                    if (!list.isEmpty()) {
14363                            return list.get(0);
14364                    }
14365    
14366                    return null;
14367            }
14368    
14369            /**
14370             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14371             *
14372             * @param userId the user ID
14373             * @param classNameId the class name ID
14374             * @param status the status
14375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14376             * @return the last matching message-boards message
14377             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
14378             * @throws SystemException if a system exception occurred
14379             */
14380            public MBMessage findByU_C_S_Last(long userId, long classNameId,
14381                    int status, OrderByComparator orderByComparator)
14382                    throws NoSuchMessageException, SystemException {
14383                    MBMessage mbMessage = fetchByU_C_S_Last(userId, classNameId, status,
14384                                    orderByComparator);
14385    
14386                    if (mbMessage != null) {
14387                            return mbMessage;
14388                    }
14389    
14390                    StringBundler msg = new StringBundler(8);
14391    
14392                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
14393    
14394                    msg.append("userId=");
14395                    msg.append(userId);
14396    
14397                    msg.append(", classNameId=");
14398                    msg.append(classNameId);
14399    
14400                    msg.append(", status=");
14401                    msg.append(status);
14402    
14403                    msg.append(StringPool.CLOSE_CURLY_BRACE);
14404    
14405                    throw new NoSuchMessageException(msg.toString());
14406            }
14407    
14408            /**
14409             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and status = &#63;.
14410             *
14411             * @param userId the user ID
14412             * @param classNameId the class name ID
14413             * @param status the status
14414             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14415             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
14416             * @throws SystemException if a system exception occurred
14417             */
14418            public MBMessage fetchByU_C_S_Last(long userId, long classNameId,
14419                    int status, OrderByComparator orderByComparator)
14420                    throws SystemException {
14421                    int count = countByU_C_S(userId, classNameId, status);
14422    
14423                    List<MBMessage> list = findByU_C_S(userId, classNameId, status,
14424                                    count - 1, count, orderByComparator);
14425    
14426                    if (!list.isEmpty()) {
14427                            return list.get(0);
14428                    }
14429    
14430                    return null;
14431            }
14432    
14433            /**
14434             * 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;.
14435             *
14436             * @param messageId the primary key of the current message-boards message
14437             * @param userId the user ID
14438             * @param classNameId the class name ID
14439             * @param status the status
14440             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
14441             * @return the previous, current, and next message-boards message
14442             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
14443             * @throws SystemException if a system exception occurred
14444             */
14445            public MBMessage[] findByU_C_S_PrevAndNext(long messageId, long userId,
14446                    long classNameId, int status, OrderByComparator orderByComparator)
14447                    throws NoSuchMessageException, SystemException {
14448                    MBMessage mbMessage = findByPrimaryKey(messageId);
14449    
14450                    Session session = null;
14451    
14452                    try {
14453                            session = openSession();
14454    
14455                            MBMessage[] array = new MBMessageImpl[3];
14456    
14457                            array[0] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14458                                            classNameId, status, orderByComparator, true);
14459    
14460                            array[1] = mbMessage;
14461    
14462                            array[2] = getByU_C_S_PrevAndNext(session, mbMessage, userId,
14463                                            classNameId, status, orderByComparator, false);
14464    
14465                            return array;
14466                    }
14467                    catch (Exception e) {
14468                            throw processException(e);
14469                    }
14470                    finally {
14471                            closeSession(session);
14472                    }
14473            }
14474    
14475            protected MBMessage getByU_C_S_PrevAndNext(Session session,
14476                    MBMessage mbMessage, long userId, long classNameId, int status,
14477                    OrderByComparator orderByComparator, boolean previous) {
14478                    StringBundler query = null;
14479    
14480                    if (orderByComparator != null) {
14481                            query = new StringBundler(6 +
14482                                            (orderByComparator.getOrderByFields().length * 6));
14483                    }
14484                    else {
14485                            query = new StringBundler(3);
14486                    }
14487    
14488                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14489    
14490                    query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14491    
14492                    query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14493    
14494                    query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14495    
14496                    if (orderByComparator != null) {
14497                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
14498    
14499                            if (orderByConditionFields.length > 0) {
14500                                    query.append(WHERE_AND);
14501                            }
14502    
14503                            for (int i = 0; i < orderByConditionFields.length; i++) {
14504                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14505                                    query.append(orderByConditionFields[i]);
14506    
14507                                    if ((i + 1) < orderByConditionFields.length) {
14508                                            if (orderByComparator.isAscending() ^ previous) {
14509                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
14510                                            }
14511                                            else {
14512                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
14513                                            }
14514                                    }
14515                                    else {
14516                                            if (orderByComparator.isAscending() ^ previous) {
14517                                                    query.append(WHERE_GREATER_THAN);
14518                                            }
14519                                            else {
14520                                                    query.append(WHERE_LESSER_THAN);
14521                                            }
14522                                    }
14523                            }
14524    
14525                            query.append(ORDER_BY_CLAUSE);
14526    
14527                            String[] orderByFields = orderByComparator.getOrderByFields();
14528    
14529                            for (int i = 0; i < orderByFields.length; i++) {
14530                                    query.append(_ORDER_BY_ENTITY_ALIAS);
14531                                    query.append(orderByFields[i]);
14532    
14533                                    if ((i + 1) < orderByFields.length) {
14534                                            if (orderByComparator.isAscending() ^ previous) {
14535                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
14536                                            }
14537                                            else {
14538                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
14539                                            }
14540                                    }
14541                                    else {
14542                                            if (orderByComparator.isAscending() ^ previous) {
14543                                                    query.append(ORDER_BY_ASC);
14544                                            }
14545                                            else {
14546                                                    query.append(ORDER_BY_DESC);
14547                                            }
14548                                    }
14549                            }
14550                    }
14551                    else {
14552                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14553                    }
14554    
14555                    String sql = query.toString();
14556    
14557                    Query q = session.createQuery(sql);
14558    
14559                    q.setFirstResult(0);
14560                    q.setMaxResults(2);
14561    
14562                    QueryPos qPos = QueryPos.getInstance(q);
14563    
14564                    qPos.add(userId);
14565    
14566                    qPos.add(classNameId);
14567    
14568                    qPos.add(status);
14569    
14570                    if (orderByComparator != null) {
14571                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
14572    
14573                            for (Object value : values) {
14574                                    qPos.add(value);
14575                            }
14576                    }
14577    
14578                    List<MBMessage> list = q.list();
14579    
14580                    if (list.size() == 2) {
14581                            return list.get(1);
14582                    }
14583                    else {
14584                            return null;
14585                    }
14586            }
14587    
14588            /**
14589             * Returns all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14590             *
14591             * <p>
14592             * 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.
14593             * </p>
14594             *
14595             * @param userId the user ID
14596             * @param classNameIds the class name IDs
14597             * @param status the status
14598             * @return the matching message-boards messages
14599             * @throws SystemException if a system exception occurred
14600             */
14601            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14602                    int status) throws SystemException {
14603                    return findByU_C_S(userId, classNameIds, status, QueryUtil.ALL_POS,
14604                            QueryUtil.ALL_POS, null);
14605            }
14606    
14607            /**
14608             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14609             *
14610             * <p>
14611             * 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.
14612             * </p>
14613             *
14614             * @param userId the user ID
14615             * @param classNameIds the class name IDs
14616             * @param status the status
14617             * @param start the lower bound of the range of message-boards messages
14618             * @param end the upper bound of the range of message-boards messages (not inclusive)
14619             * @return the range of matching message-boards messages
14620             * @throws SystemException if a system exception occurred
14621             */
14622            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14623                    int status, int start, int end) throws SystemException {
14624                    return findByU_C_S(userId, classNameIds, status, start, end, null);
14625            }
14626    
14627            /**
14628             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14629             *
14630             * <p>
14631             * 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.
14632             * </p>
14633             *
14634             * @param userId the user ID
14635             * @param classNameIds the class name IDs
14636             * @param status the status
14637             * @param start the lower bound of the range of message-boards messages
14638             * @param end the upper bound of the range of message-boards messages (not inclusive)
14639             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
14640             * @return the ordered range of matching message-boards messages
14641             * @throws SystemException if a system exception occurred
14642             */
14643            public List<MBMessage> findByU_C_S(long userId, long[] classNameIds,
14644                    int status, int start, int end, OrderByComparator orderByComparator)
14645                    throws SystemException {
14646                    if ((classNameIds != null) && (classNameIds.length == 1)) {
14647                            return findByU_C_S(userId, classNameIds[0], status, start, end,
14648                                    orderByComparator);
14649                    }
14650    
14651                    boolean pagination = true;
14652                    Object[] finderArgs = null;
14653    
14654                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
14655                                    (orderByComparator == null)) {
14656                            pagination = false;
14657                            finderArgs = new Object[] {
14658                                            userId, StringUtil.merge(classNameIds), status
14659                                    };
14660                    }
14661                    else {
14662                            finderArgs = new Object[] {
14663                                            userId, StringUtil.merge(classNameIds), status,
14664                                            
14665                                            start, end, orderByComparator
14666                                    };
14667                    }
14668    
14669                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14670                                    finderArgs, this);
14671    
14672                    if ((list != null) && !list.isEmpty()) {
14673                            for (MBMessage mbMessage : list) {
14674                                    if ((userId != mbMessage.getUserId()) ||
14675                                                    !ArrayUtil.contains(classNameIds,
14676                                                            mbMessage.getClassNameId()) ||
14677                                                    (status != mbMessage.getStatus())) {
14678                                            list = null;
14679    
14680                                            break;
14681                                    }
14682                            }
14683                    }
14684    
14685                    if (list == null) {
14686                            StringBundler query = new StringBundler();
14687    
14688                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
14689    
14690                            boolean conjunctionable = false;
14691    
14692                            if (conjunctionable) {
14693                                    query.append(WHERE_AND);
14694                            }
14695    
14696                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
14697    
14698                            conjunctionable = true;
14699    
14700                            if ((classNameIds == null) || (classNameIds.length > 0)) {
14701                                    if (conjunctionable) {
14702                                            query.append(WHERE_AND);
14703                                    }
14704    
14705                                    query.append(StringPool.OPEN_PARENTHESIS);
14706    
14707                                    for (int i = 0; i < classNameIds.length; i++) {
14708                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
14709    
14710                                            if ((i + 1) < classNameIds.length) {
14711                                                    query.append(WHERE_OR);
14712                                            }
14713                                    }
14714    
14715                                    query.append(StringPool.CLOSE_PARENTHESIS);
14716    
14717                                    conjunctionable = true;
14718                            }
14719    
14720                            if (conjunctionable) {
14721                                    query.append(WHERE_AND);
14722                            }
14723    
14724                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
14725    
14726                            conjunctionable = true;
14727    
14728                            if (orderByComparator != null) {
14729                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
14730                                            orderByComparator);
14731                            }
14732                            else
14733                             if (pagination) {
14734                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
14735                            }
14736    
14737                            String sql = query.toString();
14738    
14739                            Session session = null;
14740    
14741                            try {
14742                                    session = openSession();
14743    
14744                                    Query q = session.createQuery(sql);
14745    
14746                                    QueryPos qPos = QueryPos.getInstance(q);
14747    
14748                                    qPos.add(userId);
14749    
14750                                    if (classNameIds != null) {
14751                                            qPos.add(classNameIds);
14752                                    }
14753    
14754                                    qPos.add(status);
14755    
14756                                    if (!pagination) {
14757                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14758                                                            start, end, false);
14759    
14760                                            Collections.sort(list);
14761    
14762                                            list = new UnmodifiableList<MBMessage>(list);
14763                                    }
14764                                    else {
14765                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
14766                                                            start, end);
14767                                    }
14768    
14769                                    cacheResult(list);
14770    
14771                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14772                                            finderArgs, list);
14773                            }
14774                            catch (Exception e) {
14775                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_S,
14776                                            finderArgs);
14777    
14778                                    throw processException(e);
14779                            }
14780                            finally {
14781                                    closeSession(session);
14782                            }
14783                    }
14784    
14785                    return list;
14786            }
14787    
14788            /**
14789             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63; from the database.
14790             *
14791             * @param userId the user ID
14792             * @param classNameId the class name ID
14793             * @param status the status
14794             * @throws SystemException if a system exception occurred
14795             */
14796            public void removeByU_C_S(long userId, long classNameId, int status)
14797                    throws SystemException {
14798                    for (MBMessage mbMessage : findByU_C_S(userId, classNameId, status,
14799                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
14800                            remove(mbMessage);
14801                    }
14802            }
14803    
14804            /**
14805             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and status = &#63;.
14806             *
14807             * @param userId the user ID
14808             * @param classNameId the class name ID
14809             * @param status the status
14810             * @return the number of matching message-boards messages
14811             * @throws SystemException if a system exception occurred
14812             */
14813            public int countByU_C_S(long userId, long classNameId, int status)
14814                    throws SystemException {
14815                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_S;
14816    
14817                    Object[] finderArgs = new Object[] { userId, classNameId, status };
14818    
14819                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
14820                                    this);
14821    
14822                    if (count == null) {
14823                            StringBundler query = new StringBundler(4);
14824    
14825                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14826    
14827                            query.append(_FINDER_COLUMN_U_C_S_USERID_2);
14828    
14829                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2);
14830    
14831                            query.append(_FINDER_COLUMN_U_C_S_STATUS_2);
14832    
14833                            String sql = query.toString();
14834    
14835                            Session session = null;
14836    
14837                            try {
14838                                    session = openSession();
14839    
14840                                    Query q = session.createQuery(sql);
14841    
14842                                    QueryPos qPos = QueryPos.getInstance(q);
14843    
14844                                    qPos.add(userId);
14845    
14846                                    qPos.add(classNameId);
14847    
14848                                    qPos.add(status);
14849    
14850                                    count = (Long)q.uniqueResult();
14851    
14852                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
14853                            }
14854                            catch (Exception e) {
14855                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
14856    
14857                                    throw processException(e);
14858                            }
14859                            finally {
14860                                    closeSession(session);
14861                            }
14862                    }
14863    
14864                    return count.intValue();
14865            }
14866    
14867            /**
14868             * Returns the number of message-boards messages where userId = &#63; and classNameId = any &#63; and status = &#63;.
14869             *
14870             * @param userId the user ID
14871             * @param classNameIds the class name IDs
14872             * @param status the status
14873             * @return the number of matching message-boards messages
14874             * @throws SystemException if a system exception occurred
14875             */
14876            public int countByU_C_S(long userId, long[] classNameIds, int status)
14877                    throws SystemException {
14878                    Object[] finderArgs = new Object[] {
14879                                    userId, StringUtil.merge(classNameIds), status
14880                            };
14881    
14882                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14883                                    finderArgs, this);
14884    
14885                    if (count == null) {
14886                            StringBundler query = new StringBundler();
14887    
14888                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
14889    
14890                            boolean conjunctionable = false;
14891    
14892                            if (conjunctionable) {
14893                                    query.append(WHERE_AND);
14894                            }
14895    
14896                            query.append(_FINDER_COLUMN_U_C_S_USERID_5);
14897    
14898                            conjunctionable = true;
14899    
14900                            if ((classNameIds == null) || (classNameIds.length > 0)) {
14901                                    if (conjunctionable) {
14902                                            query.append(WHERE_AND);
14903                                    }
14904    
14905                                    query.append(StringPool.OPEN_PARENTHESIS);
14906    
14907                                    for (int i = 0; i < classNameIds.length; i++) {
14908                                            query.append(_FINDER_COLUMN_U_C_S_CLASSNAMEID_5);
14909    
14910                                            if ((i + 1) < classNameIds.length) {
14911                                                    query.append(WHERE_OR);
14912                                            }
14913                                    }
14914    
14915                                    query.append(StringPool.CLOSE_PARENTHESIS);
14916    
14917                                    conjunctionable = true;
14918                            }
14919    
14920                            if (conjunctionable) {
14921                                    query.append(WHERE_AND);
14922                            }
14923    
14924                            query.append(_FINDER_COLUMN_U_C_S_STATUS_5);
14925    
14926                            conjunctionable = true;
14927    
14928                            String sql = query.toString();
14929    
14930                            Session session = null;
14931    
14932                            try {
14933                                    session = openSession();
14934    
14935                                    Query q = session.createQuery(sql);
14936    
14937                                    QueryPos qPos = QueryPos.getInstance(q);
14938    
14939                                    qPos.add(userId);
14940    
14941                                    if (classNameIds != null) {
14942                                            qPos.add(classNameIds);
14943                                    }
14944    
14945                                    qPos.add(status);
14946    
14947                                    count = (Long)q.uniqueResult();
14948    
14949                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14950                                            finderArgs, count);
14951                            }
14952                            catch (Exception e) {
14953                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_U_C_S,
14954                                            finderArgs);
14955    
14956                                    throw processException(e);
14957                            }
14958                            finally {
14959                                    closeSession(session);
14960                            }
14961                    }
14962    
14963                    return count.intValue();
14964            }
14965    
14966            private static final String _FINDER_COLUMN_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
14967            private static final String _FINDER_COLUMN_U_C_S_USERID_5 = "(" +
14968                    removeConjunction(_FINDER_COLUMN_U_C_S_USERID_2) + ")";
14969            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
14970            private static final String _FINDER_COLUMN_U_C_S_CLASSNAMEID_5 = "(" +
14971                    removeConjunction(_FINDER_COLUMN_U_C_S_CLASSNAMEID_2) + ")";
14972            private static final String _FINDER_COLUMN_U_C_S_STATUS_2 = "mbMessage.status = ?";
14973            private static final String _FINDER_COLUMN_U_C_S_STATUS_5 = "(" +
14974                    removeConjunction(_FINDER_COLUMN_U_C_S_STATUS_2) + ")";
14975            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14976                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14977                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C_S",
14978                            new String[] {
14979                                    Long.class.getName(), Long.class.getName(),
14980                                    Integer.class.getName(),
14981                                    
14982                            Integer.class.getName(), Integer.class.getName(),
14983                                    OrderByComparator.class.getName()
14984                            });
14985            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14986                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
14987                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C_S",
14988                            new String[] {
14989                                    Long.class.getName(), Long.class.getName(),
14990                                    Integer.class.getName()
14991                            },
14992                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
14993                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
14994                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
14995                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
14996            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
14997                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
14998                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_S",
14999                            new String[] {
15000                                    Long.class.getName(), Long.class.getName(),
15001                                    Integer.class.getName()
15002                            });
15003    
15004            /**
15005             * Returns all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15006             *
15007             * @param classNameId the class name ID
15008             * @param classPK the class p k
15009             * @param status the status
15010             * @return the matching message-boards messages
15011             * @throws SystemException if a system exception occurred
15012             */
15013            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15014                    int status) throws SystemException {
15015                    return findByC_C_S(classNameId, classPK, status, QueryUtil.ALL_POS,
15016                            QueryUtil.ALL_POS, null);
15017            }
15018    
15019            /**
15020             * Returns a range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15021             *
15022             * <p>
15023             * 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.
15024             * </p>
15025             *
15026             * @param classNameId the class name ID
15027             * @param classPK the class p k
15028             * @param status the status
15029             * @param start the lower bound of the range of message-boards messages
15030             * @param end the upper bound of the range of message-boards messages (not inclusive)
15031             * @return the range of matching message-boards messages
15032             * @throws SystemException if a system exception occurred
15033             */
15034            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15035                    int status, int start, int end) throws SystemException {
15036                    return findByC_C_S(classNameId, classPK, status, start, end, null);
15037            }
15038    
15039            /**
15040             * Returns an ordered range of all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15041             *
15042             * <p>
15043             * 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.
15044             * </p>
15045             *
15046             * @param classNameId the class name ID
15047             * @param classPK the class p k
15048             * @param status the status
15049             * @param start the lower bound of the range of message-boards messages
15050             * @param end the upper bound of the range of message-boards messages (not inclusive)
15051             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15052             * @return the ordered range of matching message-boards messages
15053             * @throws SystemException if a system exception occurred
15054             */
15055            public List<MBMessage> findByC_C_S(long classNameId, long classPK,
15056                    int status, int start, int end, OrderByComparator orderByComparator)
15057                    throws SystemException {
15058                    boolean pagination = true;
15059                    FinderPath finderPath = null;
15060                    Object[] finderArgs = null;
15061    
15062                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15063                                    (orderByComparator == null)) {
15064                            pagination = false;
15065                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S;
15066                            finderArgs = new Object[] { classNameId, classPK, status };
15067                    }
15068                    else {
15069                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C_S;
15070                            finderArgs = new Object[] {
15071                                            classNameId, classPK, status,
15072                                            
15073                                            start, end, orderByComparator
15074                                    };
15075                    }
15076    
15077                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15078                                    finderArgs, this);
15079    
15080                    if ((list != null) && !list.isEmpty()) {
15081                            for (MBMessage mbMessage : list) {
15082                                    if ((classNameId != mbMessage.getClassNameId()) ||
15083                                                    (classPK != mbMessage.getClassPK()) ||
15084                                                    (status != mbMessage.getStatus())) {
15085                                            list = null;
15086    
15087                                            break;
15088                                    }
15089                            }
15090                    }
15091    
15092                    if (list == null) {
15093                            StringBundler query = null;
15094    
15095                            if (orderByComparator != null) {
15096                                    query = new StringBundler(5 +
15097                                                    (orderByComparator.getOrderByFields().length * 3));
15098                            }
15099                            else {
15100                                    query = new StringBundler(5);
15101                            }
15102    
15103                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15104    
15105                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15106    
15107                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15108    
15109                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15110    
15111                            if (orderByComparator != null) {
15112                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15113                                            orderByComparator);
15114                            }
15115                            else
15116                             if (pagination) {
15117                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15118                            }
15119    
15120                            String sql = query.toString();
15121    
15122                            Session session = null;
15123    
15124                            try {
15125                                    session = openSession();
15126    
15127                                    Query q = session.createQuery(sql);
15128    
15129                                    QueryPos qPos = QueryPos.getInstance(q);
15130    
15131                                    qPos.add(classNameId);
15132    
15133                                    qPos.add(classPK);
15134    
15135                                    qPos.add(status);
15136    
15137                                    if (!pagination) {
15138                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15139                                                            start, end, false);
15140    
15141                                            Collections.sort(list);
15142    
15143                                            list = new UnmodifiableList<MBMessage>(list);
15144                                    }
15145                                    else {
15146                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15147                                                            start, end);
15148                                    }
15149    
15150                                    cacheResult(list);
15151    
15152                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15153                            }
15154                            catch (Exception e) {
15155                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15156    
15157                                    throw processException(e);
15158                            }
15159                            finally {
15160                                    closeSession(session);
15161                            }
15162                    }
15163    
15164                    return list;
15165            }
15166    
15167            /**
15168             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15169             *
15170             * @param classNameId the class name ID
15171             * @param classPK the class p k
15172             * @param status the status
15173             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15174             * @return the first matching message-boards message
15175             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15176             * @throws SystemException if a system exception occurred
15177             */
15178            public MBMessage findByC_C_S_First(long classNameId, long classPK,
15179                    int status, OrderByComparator orderByComparator)
15180                    throws NoSuchMessageException, SystemException {
15181                    MBMessage mbMessage = fetchByC_C_S_First(classNameId, classPK, status,
15182                                    orderByComparator);
15183    
15184                    if (mbMessage != null) {
15185                            return mbMessage;
15186                    }
15187    
15188                    StringBundler msg = new StringBundler(8);
15189    
15190                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15191    
15192                    msg.append("classNameId=");
15193                    msg.append(classNameId);
15194    
15195                    msg.append(", classPK=");
15196                    msg.append(classPK);
15197    
15198                    msg.append(", status=");
15199                    msg.append(status);
15200    
15201                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15202    
15203                    throw new NoSuchMessageException(msg.toString());
15204            }
15205    
15206            /**
15207             * Returns the first message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15208             *
15209             * @param classNameId the class name ID
15210             * @param classPK the class p k
15211             * @param status the status
15212             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15213             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15214             * @throws SystemException if a system exception occurred
15215             */
15216            public MBMessage fetchByC_C_S_First(long classNameId, long classPK,
15217                    int status, OrderByComparator orderByComparator)
15218                    throws SystemException {
15219                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status, 0, 1,
15220                                    orderByComparator);
15221    
15222                    if (!list.isEmpty()) {
15223                            return list.get(0);
15224                    }
15225    
15226                    return null;
15227            }
15228    
15229            /**
15230             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15231             *
15232             * @param classNameId the class name ID
15233             * @param classPK the class p k
15234             * @param status the status
15235             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15236             * @return the last matching message-boards message
15237             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15238             * @throws SystemException if a system exception occurred
15239             */
15240            public MBMessage findByC_C_S_Last(long classNameId, long classPK,
15241                    int status, OrderByComparator orderByComparator)
15242                    throws NoSuchMessageException, SystemException {
15243                    MBMessage mbMessage = fetchByC_C_S_Last(classNameId, classPK, status,
15244                                    orderByComparator);
15245    
15246                    if (mbMessage != null) {
15247                            return mbMessage;
15248                    }
15249    
15250                    StringBundler msg = new StringBundler(8);
15251    
15252                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15253    
15254                    msg.append("classNameId=");
15255                    msg.append(classNameId);
15256    
15257                    msg.append(", classPK=");
15258                    msg.append(classPK);
15259    
15260                    msg.append(", status=");
15261                    msg.append(status);
15262    
15263                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15264    
15265                    throw new NoSuchMessageException(msg.toString());
15266            }
15267    
15268            /**
15269             * Returns the last message-boards message in the ordered set where classNameId = &#63; and classPK = &#63; and status = &#63;.
15270             *
15271             * @param classNameId the class name ID
15272             * @param classPK the class p k
15273             * @param status the status
15274             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15275             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15276             * @throws SystemException if a system exception occurred
15277             */
15278            public MBMessage fetchByC_C_S_Last(long classNameId, long classPK,
15279                    int status, OrderByComparator orderByComparator)
15280                    throws SystemException {
15281                    int count = countByC_C_S(classNameId, classPK, status);
15282    
15283                    List<MBMessage> list = findByC_C_S(classNameId, classPK, status,
15284                                    count - 1, count, orderByComparator);
15285    
15286                    if (!list.isEmpty()) {
15287                            return list.get(0);
15288                    }
15289    
15290                    return null;
15291            }
15292    
15293            /**
15294             * 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;.
15295             *
15296             * @param messageId the primary key of the current message-boards message
15297             * @param classNameId the class name ID
15298             * @param classPK the class p k
15299             * @param status the status
15300             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15301             * @return the previous, current, and next message-boards message
15302             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15303             * @throws SystemException if a system exception occurred
15304             */
15305            public MBMessage[] findByC_C_S_PrevAndNext(long messageId,
15306                    long classNameId, long classPK, int status,
15307                    OrderByComparator orderByComparator)
15308                    throws NoSuchMessageException, SystemException {
15309                    MBMessage mbMessage = findByPrimaryKey(messageId);
15310    
15311                    Session session = null;
15312    
15313                    try {
15314                            session = openSession();
15315    
15316                            MBMessage[] array = new MBMessageImpl[3];
15317    
15318                            array[0] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15319                                            classPK, status, orderByComparator, true);
15320    
15321                            array[1] = mbMessage;
15322    
15323                            array[2] = getByC_C_S_PrevAndNext(session, mbMessage, classNameId,
15324                                            classPK, status, orderByComparator, false);
15325    
15326                            return array;
15327                    }
15328                    catch (Exception e) {
15329                            throw processException(e);
15330                    }
15331                    finally {
15332                            closeSession(session);
15333                    }
15334            }
15335    
15336            protected MBMessage getByC_C_S_PrevAndNext(Session session,
15337                    MBMessage mbMessage, long classNameId, long classPK, int status,
15338                    OrderByComparator orderByComparator, boolean previous) {
15339                    StringBundler query = null;
15340    
15341                    if (orderByComparator != null) {
15342                            query = new StringBundler(6 +
15343                                            (orderByComparator.getOrderByFields().length * 6));
15344                    }
15345                    else {
15346                            query = new StringBundler(3);
15347                    }
15348    
15349                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15350    
15351                    query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15352    
15353                    query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15354    
15355                    query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15356    
15357                    if (orderByComparator != null) {
15358                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15359    
15360                            if (orderByConditionFields.length > 0) {
15361                                    query.append(WHERE_AND);
15362                            }
15363    
15364                            for (int i = 0; i < orderByConditionFields.length; i++) {
15365                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15366                                    query.append(orderByConditionFields[i]);
15367    
15368                                    if ((i + 1) < orderByConditionFields.length) {
15369                                            if (orderByComparator.isAscending() ^ previous) {
15370                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15371                                            }
15372                                            else {
15373                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15374                                            }
15375                                    }
15376                                    else {
15377                                            if (orderByComparator.isAscending() ^ previous) {
15378                                                    query.append(WHERE_GREATER_THAN);
15379                                            }
15380                                            else {
15381                                                    query.append(WHERE_LESSER_THAN);
15382                                            }
15383                                    }
15384                            }
15385    
15386                            query.append(ORDER_BY_CLAUSE);
15387    
15388                            String[] orderByFields = orderByComparator.getOrderByFields();
15389    
15390                            for (int i = 0; i < orderByFields.length; i++) {
15391                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15392                                    query.append(orderByFields[i]);
15393    
15394                                    if ((i + 1) < orderByFields.length) {
15395                                            if (orderByComparator.isAscending() ^ previous) {
15396                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15397                                            }
15398                                            else {
15399                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15400                                            }
15401                                    }
15402                                    else {
15403                                            if (orderByComparator.isAscending() ^ previous) {
15404                                                    query.append(ORDER_BY_ASC);
15405                                            }
15406                                            else {
15407                                                    query.append(ORDER_BY_DESC);
15408                                            }
15409                                    }
15410                            }
15411                    }
15412                    else {
15413                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15414                    }
15415    
15416                    String sql = query.toString();
15417    
15418                    Query q = session.createQuery(sql);
15419    
15420                    q.setFirstResult(0);
15421                    q.setMaxResults(2);
15422    
15423                    QueryPos qPos = QueryPos.getInstance(q);
15424    
15425                    qPos.add(classNameId);
15426    
15427                    qPos.add(classPK);
15428    
15429                    qPos.add(status);
15430    
15431                    if (orderByComparator != null) {
15432                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
15433    
15434                            for (Object value : values) {
15435                                    qPos.add(value);
15436                            }
15437                    }
15438    
15439                    List<MBMessage> list = q.list();
15440    
15441                    if (list.size() == 2) {
15442                            return list.get(1);
15443                    }
15444                    else {
15445                            return null;
15446                    }
15447            }
15448    
15449            /**
15450             * Removes all the message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
15451             *
15452             * @param classNameId the class name ID
15453             * @param classPK the class p k
15454             * @param status the status
15455             * @throws SystemException if a system exception occurred
15456             */
15457            public void removeByC_C_S(long classNameId, long classPK, int status)
15458                    throws SystemException {
15459                    for (MBMessage mbMessage : findByC_C_S(classNameId, classPK, status,
15460                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
15461                            remove(mbMessage);
15462                    }
15463            }
15464    
15465            /**
15466             * Returns the number of message-boards messages where classNameId = &#63; and classPK = &#63; and status = &#63;.
15467             *
15468             * @param classNameId the class name ID
15469             * @param classPK the class p k
15470             * @param status the status
15471             * @return the number of matching message-boards messages
15472             * @throws SystemException if a system exception occurred
15473             */
15474            public int countByC_C_S(long classNameId, long classPK, int status)
15475                    throws SystemException {
15476                    FinderPath finderPath = FINDER_PATH_COUNT_BY_C_C_S;
15477    
15478                    Object[] finderArgs = new Object[] { classNameId, classPK, status };
15479    
15480                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
15481                                    this);
15482    
15483                    if (count == null) {
15484                            StringBundler query = new StringBundler(4);
15485    
15486                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
15487    
15488                            query.append(_FINDER_COLUMN_C_C_S_CLASSNAMEID_2);
15489    
15490                            query.append(_FINDER_COLUMN_C_C_S_CLASSPK_2);
15491    
15492                            query.append(_FINDER_COLUMN_C_C_S_STATUS_2);
15493    
15494                            String sql = query.toString();
15495    
15496                            Session session = null;
15497    
15498                            try {
15499                                    session = openSession();
15500    
15501                                    Query q = session.createQuery(sql);
15502    
15503                                    QueryPos qPos = QueryPos.getInstance(q);
15504    
15505                                    qPos.add(classNameId);
15506    
15507                                    qPos.add(classPK);
15508    
15509                                    qPos.add(status);
15510    
15511                                    count = (Long)q.uniqueResult();
15512    
15513                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
15514                            }
15515                            catch (Exception e) {
15516                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15517    
15518                                    throw processException(e);
15519                            }
15520                            finally {
15521                                    closeSession(session);
15522                            }
15523                    }
15524    
15525                    return count.intValue();
15526            }
15527    
15528            private static final String _FINDER_COLUMN_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
15529            private static final String _FINDER_COLUMN_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
15530            private static final String _FINDER_COLUMN_C_C_S_STATUS_2 = "mbMessage.status = ?";
15531            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15532                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15533                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_U_C_S",
15534                            new String[] {
15535                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15536                                    Integer.class.getName(),
15537                                    
15538                            Integer.class.getName(), Integer.class.getName(),
15539                                    OrderByComparator.class.getName()
15540                            });
15541            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_S =
15542                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15543                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
15544                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_U_C_S",
15545                            new String[] {
15546                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15547                                    Integer.class.getName()
15548                            },
15549                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
15550                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
15551                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
15552                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
15553                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
15554            public static final FinderPath FINDER_PATH_COUNT_BY_G_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15555                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15556                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_U_C_S",
15557                            new String[] {
15558                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15559                                    Integer.class.getName()
15560                            });
15561            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
15562                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
15563                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByG_U_C_S",
15564                            new String[] {
15565                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
15566                                    Integer.class.getName()
15567                            });
15568    
15569            /**
15570             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15571             *
15572             * @param groupId the group ID
15573             * @param userId the user ID
15574             * @param categoryId the category ID
15575             * @param status the status
15576             * @return the matching message-boards messages
15577             * @throws SystemException if a system exception occurred
15578             */
15579            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
15580                    long categoryId, int status) throws SystemException {
15581                    return findByG_U_C_S(groupId, userId, categoryId, status,
15582                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
15583            }
15584    
15585            /**
15586             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15587             *
15588             * <p>
15589             * 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.
15590             * </p>
15591             *
15592             * @param groupId the group ID
15593             * @param userId the user ID
15594             * @param categoryId the category ID
15595             * @param status the status
15596             * @param start the lower bound of the range of message-boards messages
15597             * @param end the upper bound of the range of message-boards messages (not inclusive)
15598             * @return the range of matching message-boards messages
15599             * @throws SystemException if a system exception occurred
15600             */
15601            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
15602                    long categoryId, int status, int start, int end)
15603                    throws SystemException {
15604                    return findByG_U_C_S(groupId, userId, categoryId, status, start, end,
15605                            null);
15606            }
15607    
15608            /**
15609             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15610             *
15611             * <p>
15612             * 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.
15613             * </p>
15614             *
15615             * @param groupId the group ID
15616             * @param userId the user ID
15617             * @param categoryId the category ID
15618             * @param status the status
15619             * @param start the lower bound of the range of message-boards messages
15620             * @param end the upper bound of the range of message-boards messages (not inclusive)
15621             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
15622             * @return the ordered range of matching message-boards messages
15623             * @throws SystemException if a system exception occurred
15624             */
15625            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
15626                    long categoryId, int status, int start, int end,
15627                    OrderByComparator orderByComparator) throws SystemException {
15628                    boolean pagination = true;
15629                    FinderPath finderPath = null;
15630                    Object[] finderArgs = null;
15631    
15632                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
15633                                    (orderByComparator == null)) {
15634                            pagination = false;
15635                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_S;
15636                            finderArgs = new Object[] { groupId, userId, categoryId, status };
15637                    }
15638                    else {
15639                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_S;
15640                            finderArgs = new Object[] {
15641                                            groupId, userId, categoryId, status,
15642                                            
15643                                            start, end, orderByComparator
15644                                    };
15645                    }
15646    
15647                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
15648                                    finderArgs, this);
15649    
15650                    if ((list != null) && !list.isEmpty()) {
15651                            for (MBMessage mbMessage : list) {
15652                                    if ((groupId != mbMessage.getGroupId()) ||
15653                                                    (userId != mbMessage.getUserId()) ||
15654                                                    (categoryId != mbMessage.getCategoryId()) ||
15655                                                    (status != mbMessage.getStatus())) {
15656                                            list = null;
15657    
15658                                            break;
15659                                    }
15660                            }
15661                    }
15662    
15663                    if (list == null) {
15664                            StringBundler query = null;
15665    
15666                            if (orderByComparator != null) {
15667                                    query = new StringBundler(6 +
15668                                                    (orderByComparator.getOrderByFields().length * 3));
15669                            }
15670                            else {
15671                                    query = new StringBundler(6);
15672                            }
15673    
15674                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15675    
15676                            query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
15677    
15678                            query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
15679    
15680                            query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
15681    
15682                            query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
15683    
15684                            if (orderByComparator != null) {
15685                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
15686                                            orderByComparator);
15687                            }
15688                            else
15689                             if (pagination) {
15690                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
15691                            }
15692    
15693                            String sql = query.toString();
15694    
15695                            Session session = null;
15696    
15697                            try {
15698                                    session = openSession();
15699    
15700                                    Query q = session.createQuery(sql);
15701    
15702                                    QueryPos qPos = QueryPos.getInstance(q);
15703    
15704                                    qPos.add(groupId);
15705    
15706                                    qPos.add(userId);
15707    
15708                                    qPos.add(categoryId);
15709    
15710                                    qPos.add(status);
15711    
15712                                    if (!pagination) {
15713                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15714                                                            start, end, false);
15715    
15716                                            Collections.sort(list);
15717    
15718                                            list = new UnmodifiableList<MBMessage>(list);
15719                                    }
15720                                    else {
15721                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
15722                                                            start, end);
15723                                    }
15724    
15725                                    cacheResult(list);
15726    
15727                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
15728                            }
15729                            catch (Exception e) {
15730                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
15731    
15732                                    throw processException(e);
15733                            }
15734                            finally {
15735                                    closeSession(session);
15736                            }
15737                    }
15738    
15739                    return list;
15740            }
15741    
15742            /**
15743             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15744             *
15745             * @param groupId the group ID
15746             * @param userId the user ID
15747             * @param categoryId the category ID
15748             * @param status the status
15749             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15750             * @return the first matching message-boards message
15751             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15752             * @throws SystemException if a system exception occurred
15753             */
15754            public MBMessage findByG_U_C_S_First(long groupId, long userId,
15755                    long categoryId, int status, OrderByComparator orderByComparator)
15756                    throws NoSuchMessageException, SystemException {
15757                    MBMessage mbMessage = fetchByG_U_C_S_First(groupId, userId, categoryId,
15758                                    status, orderByComparator);
15759    
15760                    if (mbMessage != null) {
15761                            return mbMessage;
15762                    }
15763    
15764                    StringBundler msg = new StringBundler(10);
15765    
15766                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15767    
15768                    msg.append("groupId=");
15769                    msg.append(groupId);
15770    
15771                    msg.append(", userId=");
15772                    msg.append(userId);
15773    
15774                    msg.append(", categoryId=");
15775                    msg.append(categoryId);
15776    
15777                    msg.append(", status=");
15778                    msg.append(status);
15779    
15780                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15781    
15782                    throw new NoSuchMessageException(msg.toString());
15783            }
15784    
15785            /**
15786             * Returns the first message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15787             *
15788             * @param groupId the group ID
15789             * @param userId the user ID
15790             * @param categoryId the category ID
15791             * @param status the status
15792             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15793             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15794             * @throws SystemException if a system exception occurred
15795             */
15796            public MBMessage fetchByG_U_C_S_First(long groupId, long userId,
15797                    long categoryId, int status, OrderByComparator orderByComparator)
15798                    throws SystemException {
15799                    List<MBMessage> list = findByG_U_C_S(groupId, userId, categoryId,
15800                                    status, 0, 1, orderByComparator);
15801    
15802                    if (!list.isEmpty()) {
15803                            return list.get(0);
15804                    }
15805    
15806                    return null;
15807            }
15808    
15809            /**
15810             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15811             *
15812             * @param groupId the group ID
15813             * @param userId the user ID
15814             * @param categoryId the category ID
15815             * @param status the status
15816             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15817             * @return the last matching message-boards message
15818             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
15819             * @throws SystemException if a system exception occurred
15820             */
15821            public MBMessage findByG_U_C_S_Last(long groupId, long userId,
15822                    long categoryId, int status, OrderByComparator orderByComparator)
15823                    throws NoSuchMessageException, SystemException {
15824                    MBMessage mbMessage = fetchByG_U_C_S_Last(groupId, userId, categoryId,
15825                                    status, orderByComparator);
15826    
15827                    if (mbMessage != null) {
15828                            return mbMessage;
15829                    }
15830    
15831                    StringBundler msg = new StringBundler(10);
15832    
15833                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
15834    
15835                    msg.append("groupId=");
15836                    msg.append(groupId);
15837    
15838                    msg.append(", userId=");
15839                    msg.append(userId);
15840    
15841                    msg.append(", categoryId=");
15842                    msg.append(categoryId);
15843    
15844                    msg.append(", status=");
15845                    msg.append(status);
15846    
15847                    msg.append(StringPool.CLOSE_CURLY_BRACE);
15848    
15849                    throw new NoSuchMessageException(msg.toString());
15850            }
15851    
15852            /**
15853             * Returns the last message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15854             *
15855             * @param groupId the group ID
15856             * @param userId the user ID
15857             * @param categoryId the category ID
15858             * @param status the status
15859             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15860             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
15861             * @throws SystemException if a system exception occurred
15862             */
15863            public MBMessage fetchByG_U_C_S_Last(long groupId, long userId,
15864                    long categoryId, int status, OrderByComparator orderByComparator)
15865                    throws SystemException {
15866                    int count = countByG_U_C_S(groupId, userId, categoryId, status);
15867    
15868                    List<MBMessage> list = findByG_U_C_S(groupId, userId, categoryId,
15869                                    status, count - 1, count, orderByComparator);
15870    
15871                    if (!list.isEmpty()) {
15872                            return list.get(0);
15873                    }
15874    
15875                    return null;
15876            }
15877    
15878            /**
15879             * Returns the message-boards messages before and after the current message-boards message in the ordered set where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
15880             *
15881             * @param messageId the primary key of the current message-boards message
15882             * @param groupId the group ID
15883             * @param userId the user ID
15884             * @param categoryId the category ID
15885             * @param status the status
15886             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
15887             * @return the previous, current, and next message-boards message
15888             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
15889             * @throws SystemException if a system exception occurred
15890             */
15891            public MBMessage[] findByG_U_C_S_PrevAndNext(long messageId, long groupId,
15892                    long userId, long categoryId, int status,
15893                    OrderByComparator orderByComparator)
15894                    throws NoSuchMessageException, SystemException {
15895                    MBMessage mbMessage = findByPrimaryKey(messageId);
15896    
15897                    Session session = null;
15898    
15899                    try {
15900                            session = openSession();
15901    
15902                            MBMessage[] array = new MBMessageImpl[3];
15903    
15904                            array[0] = getByG_U_C_S_PrevAndNext(session, mbMessage, groupId,
15905                                            userId, categoryId, status, orderByComparator, true);
15906    
15907                            array[1] = mbMessage;
15908    
15909                            array[2] = getByG_U_C_S_PrevAndNext(session, mbMessage, groupId,
15910                                            userId, categoryId, status, orderByComparator, false);
15911    
15912                            return array;
15913                    }
15914                    catch (Exception e) {
15915                            throw processException(e);
15916                    }
15917                    finally {
15918                            closeSession(session);
15919                    }
15920            }
15921    
15922            protected MBMessage getByG_U_C_S_PrevAndNext(Session session,
15923                    MBMessage mbMessage, long groupId, long userId, long categoryId,
15924                    int status, OrderByComparator orderByComparator, boolean previous) {
15925                    StringBundler query = null;
15926    
15927                    if (orderByComparator != null) {
15928                            query = new StringBundler(6 +
15929                                            (orderByComparator.getOrderByFields().length * 6));
15930                    }
15931                    else {
15932                            query = new StringBundler(3);
15933                    }
15934    
15935                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
15936    
15937                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
15938    
15939                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
15940    
15941                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
15942    
15943                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
15944    
15945                    if (orderByComparator != null) {
15946                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
15947    
15948                            if (orderByConditionFields.length > 0) {
15949                                    query.append(WHERE_AND);
15950                            }
15951    
15952                            for (int i = 0; i < orderByConditionFields.length; i++) {
15953                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15954                                    query.append(orderByConditionFields[i]);
15955    
15956                                    if ((i + 1) < orderByConditionFields.length) {
15957                                            if (orderByComparator.isAscending() ^ previous) {
15958                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
15959                                            }
15960                                            else {
15961                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
15962                                            }
15963                                    }
15964                                    else {
15965                                            if (orderByComparator.isAscending() ^ previous) {
15966                                                    query.append(WHERE_GREATER_THAN);
15967                                            }
15968                                            else {
15969                                                    query.append(WHERE_LESSER_THAN);
15970                                            }
15971                                    }
15972                            }
15973    
15974                            query.append(ORDER_BY_CLAUSE);
15975    
15976                            String[] orderByFields = orderByComparator.getOrderByFields();
15977    
15978                            for (int i = 0; i < orderByFields.length; i++) {
15979                                    query.append(_ORDER_BY_ENTITY_ALIAS);
15980                                    query.append(orderByFields[i]);
15981    
15982                                    if ((i + 1) < orderByFields.length) {
15983                                            if (orderByComparator.isAscending() ^ previous) {
15984                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
15985                                            }
15986                                            else {
15987                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
15988                                            }
15989                                    }
15990                                    else {
15991                                            if (orderByComparator.isAscending() ^ previous) {
15992                                                    query.append(ORDER_BY_ASC);
15993                                            }
15994                                            else {
15995                                                    query.append(ORDER_BY_DESC);
15996                                            }
15997                                    }
15998                            }
15999                    }
16000                    else {
16001                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16002                    }
16003    
16004                    String sql = query.toString();
16005    
16006                    Query q = session.createQuery(sql);
16007    
16008                    q.setFirstResult(0);
16009                    q.setMaxResults(2);
16010    
16011                    QueryPos qPos = QueryPos.getInstance(q);
16012    
16013                    qPos.add(groupId);
16014    
16015                    qPos.add(userId);
16016    
16017                    qPos.add(categoryId);
16018    
16019                    qPos.add(status);
16020    
16021                    if (orderByComparator != null) {
16022                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16023    
16024                            for (Object value : values) {
16025                                    qPos.add(value);
16026                            }
16027                    }
16028    
16029                    List<MBMessage> list = q.list();
16030    
16031                    if (list.size() == 2) {
16032                            return list.get(1);
16033                    }
16034                    else {
16035                            return null;
16036                    }
16037            }
16038    
16039            /**
16040             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16041             *
16042             * @param groupId the group ID
16043             * @param userId the user ID
16044             * @param categoryId the category ID
16045             * @param status the status
16046             * @return the matching message-boards messages that the user has permission to view
16047             * @throws SystemException if a system exception occurred
16048             */
16049            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16050                    long categoryId, int status) throws SystemException {
16051                    return filterFindByG_U_C_S(groupId, userId, categoryId, status,
16052                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16053            }
16054    
16055            /**
16056             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16057             *
16058             * <p>
16059             * 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.
16060             * </p>
16061             *
16062             * @param groupId the group ID
16063             * @param userId the user ID
16064             * @param categoryId the category ID
16065             * @param status the status
16066             * @param start the lower bound of the range of message-boards messages
16067             * @param end the upper bound of the range of message-boards messages (not inclusive)
16068             * @return the range of matching message-boards messages that the user has permission to view
16069             * @throws SystemException if a system exception occurred
16070             */
16071            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16072                    long categoryId, int status, int start, int end)
16073                    throws SystemException {
16074                    return filterFindByG_U_C_S(groupId, userId, categoryId, status, start,
16075                            end, null);
16076            }
16077    
16078            /**
16079             * Returns an ordered range of all the message-boards messages that the user has permissions to view where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16080             *
16081             * <p>
16082             * 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.
16083             * </p>
16084             *
16085             * @param groupId the group ID
16086             * @param userId the user ID
16087             * @param categoryId the category ID
16088             * @param status the status
16089             * @param start the lower bound of the range of message-boards messages
16090             * @param end the upper bound of the range of message-boards messages (not inclusive)
16091             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16092             * @return the ordered range of matching message-boards messages that the user has permission to view
16093             * @throws SystemException if a system exception occurred
16094             */
16095            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16096                    long categoryId, int status, int start, int end,
16097                    OrderByComparator orderByComparator) throws SystemException {
16098                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16099                            return findByG_U_C_S(groupId, userId, categoryId, status, start,
16100                                    end, orderByComparator);
16101                    }
16102    
16103                    StringBundler query = null;
16104    
16105                    if (orderByComparator != null) {
16106                            query = new StringBundler(6 +
16107                                            (orderByComparator.getOrderByFields().length * 3));
16108                    }
16109                    else {
16110                            query = new StringBundler(6);
16111                    }
16112    
16113                    if (getDB().isSupportsInlineDistinct()) {
16114                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16115                    }
16116                    else {
16117                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16118                    }
16119    
16120                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
16121    
16122                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
16123    
16124                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
16125    
16126                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
16127    
16128                    if (!getDB().isSupportsInlineDistinct()) {
16129                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16130                    }
16131    
16132                    if (orderByComparator != null) {
16133                            if (getDB().isSupportsInlineDistinct()) {
16134                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16135                                            orderByComparator, true);
16136                            }
16137                            else {
16138                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16139                                            orderByComparator, true);
16140                            }
16141                    }
16142                    else {
16143                            if (getDB().isSupportsInlineDistinct()) {
16144                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16145                            }
16146                            else {
16147                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16148                            }
16149                    }
16150    
16151                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16152                                    MBMessage.class.getName(),
16153                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16154    
16155                    Session session = null;
16156    
16157                    try {
16158                            session = openSession();
16159    
16160                            SQLQuery q = session.createSQLQuery(sql);
16161    
16162                            if (getDB().isSupportsInlineDistinct()) {
16163                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16164                            }
16165                            else {
16166                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16167                            }
16168    
16169                            QueryPos qPos = QueryPos.getInstance(q);
16170    
16171                            qPos.add(groupId);
16172    
16173                            qPos.add(userId);
16174    
16175                            qPos.add(categoryId);
16176    
16177                            qPos.add(status);
16178    
16179                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16180                    }
16181                    catch (Exception e) {
16182                            throw processException(e);
16183                    }
16184                    finally {
16185                            closeSession(session);
16186                    }
16187            }
16188    
16189            /**
16190             * 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 categoryId = &#63; and status = &#63;.
16191             *
16192             * @param messageId the primary key of the current message-boards message
16193             * @param groupId the group ID
16194             * @param userId the user ID
16195             * @param categoryId the category ID
16196             * @param status the status
16197             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
16198             * @return the previous, current, and next message-boards message
16199             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
16200             * @throws SystemException if a system exception occurred
16201             */
16202            public MBMessage[] filterFindByG_U_C_S_PrevAndNext(long messageId,
16203                    long groupId, long userId, long categoryId, int status,
16204                    OrderByComparator orderByComparator)
16205                    throws NoSuchMessageException, SystemException {
16206                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16207                            return findByG_U_C_S_PrevAndNext(messageId, groupId, userId,
16208                                    categoryId, status, orderByComparator);
16209                    }
16210    
16211                    MBMessage mbMessage = findByPrimaryKey(messageId);
16212    
16213                    Session session = null;
16214    
16215                    try {
16216                            session = openSession();
16217    
16218                            MBMessage[] array = new MBMessageImpl[3];
16219    
16220                            array[0] = filterGetByG_U_C_S_PrevAndNext(session, mbMessage,
16221                                            groupId, userId, categoryId, status, orderByComparator, true);
16222    
16223                            array[1] = mbMessage;
16224    
16225                            array[2] = filterGetByG_U_C_S_PrevAndNext(session, mbMessage,
16226                                            groupId, userId, categoryId, status, orderByComparator,
16227                                            false);
16228    
16229                            return array;
16230                    }
16231                    catch (Exception e) {
16232                            throw processException(e);
16233                    }
16234                    finally {
16235                            closeSession(session);
16236                    }
16237            }
16238    
16239            protected MBMessage filterGetByG_U_C_S_PrevAndNext(Session session,
16240                    MBMessage mbMessage, long groupId, long userId, long categoryId,
16241                    int status, OrderByComparator orderByComparator, boolean previous) {
16242                    StringBundler query = null;
16243    
16244                    if (orderByComparator != null) {
16245                            query = new StringBundler(6 +
16246                                            (orderByComparator.getOrderByFields().length * 6));
16247                    }
16248                    else {
16249                            query = new StringBundler(3);
16250                    }
16251    
16252                    if (getDB().isSupportsInlineDistinct()) {
16253                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16254                    }
16255                    else {
16256                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16257                    }
16258    
16259                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
16260    
16261                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
16262    
16263                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
16264    
16265                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
16266    
16267                    if (!getDB().isSupportsInlineDistinct()) {
16268                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16269                    }
16270    
16271                    if (orderByComparator != null) {
16272                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
16273    
16274                            if (orderByConditionFields.length > 0) {
16275                                    query.append(WHERE_AND);
16276                            }
16277    
16278                            for (int i = 0; i < orderByConditionFields.length; i++) {
16279                                    if (getDB().isSupportsInlineDistinct()) {
16280                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16281                                    }
16282                                    else {
16283                                            query.append(_ORDER_BY_ENTITY_TABLE);
16284                                    }
16285    
16286                                    query.append(orderByConditionFields[i]);
16287    
16288                                    if ((i + 1) < orderByConditionFields.length) {
16289                                            if (orderByComparator.isAscending() ^ previous) {
16290                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
16291                                            }
16292                                            else {
16293                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
16294                                            }
16295                                    }
16296                                    else {
16297                                            if (orderByComparator.isAscending() ^ previous) {
16298                                                    query.append(WHERE_GREATER_THAN);
16299                                            }
16300                                            else {
16301                                                    query.append(WHERE_LESSER_THAN);
16302                                            }
16303                                    }
16304                            }
16305    
16306                            query.append(ORDER_BY_CLAUSE);
16307    
16308                            String[] orderByFields = orderByComparator.getOrderByFields();
16309    
16310                            for (int i = 0; i < orderByFields.length; i++) {
16311                                    if (getDB().isSupportsInlineDistinct()) {
16312                                            query.append(_ORDER_BY_ENTITY_ALIAS);
16313                                    }
16314                                    else {
16315                                            query.append(_ORDER_BY_ENTITY_TABLE);
16316                                    }
16317    
16318                                    query.append(orderByFields[i]);
16319    
16320                                    if ((i + 1) < orderByFields.length) {
16321                                            if (orderByComparator.isAscending() ^ previous) {
16322                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
16323                                            }
16324                                            else {
16325                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
16326                                            }
16327                                    }
16328                                    else {
16329                                            if (orderByComparator.isAscending() ^ previous) {
16330                                                    query.append(ORDER_BY_ASC);
16331                                            }
16332                                            else {
16333                                                    query.append(ORDER_BY_DESC);
16334                                            }
16335                                    }
16336                            }
16337                    }
16338                    else {
16339                            if (getDB().isSupportsInlineDistinct()) {
16340                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16341                            }
16342                            else {
16343                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16344                            }
16345                    }
16346    
16347                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16348                                    MBMessage.class.getName(),
16349                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16350    
16351                    SQLQuery q = session.createSQLQuery(sql);
16352    
16353                    q.setFirstResult(0);
16354                    q.setMaxResults(2);
16355    
16356                    if (getDB().isSupportsInlineDistinct()) {
16357                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16358                    }
16359                    else {
16360                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16361                    }
16362    
16363                    QueryPos qPos = QueryPos.getInstance(q);
16364    
16365                    qPos.add(groupId);
16366    
16367                    qPos.add(userId);
16368    
16369                    qPos.add(categoryId);
16370    
16371                    qPos.add(status);
16372    
16373                    if (orderByComparator != null) {
16374                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
16375    
16376                            for (Object value : values) {
16377                                    qPos.add(value);
16378                            }
16379                    }
16380    
16381                    List<MBMessage> list = q.list();
16382    
16383                    if (list.size() == 2) {
16384                            return list.get(1);
16385                    }
16386                    else {
16387                            return null;
16388                    }
16389            }
16390    
16391            /**
16392             * Returns all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16393             *
16394             * @param groupId the group ID
16395             * @param userId the user ID
16396             * @param categoryIds the category IDs
16397             * @param status the status
16398             * @return the matching message-boards messages that the user has permission to view
16399             * @throws SystemException if a system exception occurred
16400             */
16401            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16402                    long[] categoryIds, int status) throws SystemException {
16403                    return filterFindByG_U_C_S(groupId, userId, categoryIds, status,
16404                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16405            }
16406    
16407            /**
16408             * Returns a range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16409             *
16410             * <p>
16411             * 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.
16412             * </p>
16413             *
16414             * @param groupId the group ID
16415             * @param userId the user ID
16416             * @param categoryIds the category IDs
16417             * @param status the status
16418             * @param start the lower bound of the range of message-boards messages
16419             * @param end the upper bound of the range of message-boards messages (not inclusive)
16420             * @return the range of matching message-boards messages that the user has permission to view
16421             * @throws SystemException if a system exception occurred
16422             */
16423            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16424                    long[] categoryIds, int status, int start, int end)
16425                    throws SystemException {
16426                    return filterFindByG_U_C_S(groupId, userId, categoryIds, status, start,
16427                            end, null);
16428            }
16429    
16430            /**
16431             * Returns an ordered range of all the message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16432             *
16433             * <p>
16434             * 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.
16435             * </p>
16436             *
16437             * @param groupId the group ID
16438             * @param userId the user ID
16439             * @param categoryIds the category IDs
16440             * @param status the status
16441             * @param start the lower bound of the range of message-boards messages
16442             * @param end the upper bound of the range of message-boards messages (not inclusive)
16443             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16444             * @return the ordered range of matching message-boards messages that the user has permission to view
16445             * @throws SystemException if a system exception occurred
16446             */
16447            public List<MBMessage> filterFindByG_U_C_S(long groupId, long userId,
16448                    long[] categoryIds, int status, int start, int end,
16449                    OrderByComparator orderByComparator) throws SystemException {
16450                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16451                            return findByG_U_C_S(groupId, userId, categoryIds, status, start,
16452                                    end, orderByComparator);
16453                    }
16454    
16455                    StringBundler query = new StringBundler();
16456    
16457                    if (getDB().isSupportsInlineDistinct()) {
16458                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
16459                    }
16460                    else {
16461                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
16462                    }
16463    
16464                    boolean conjunctionable = false;
16465    
16466                    if (conjunctionable) {
16467                            query.append(WHERE_AND);
16468                    }
16469    
16470                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_5);
16471    
16472                    conjunctionable = true;
16473    
16474                    if (conjunctionable) {
16475                            query.append(WHERE_AND);
16476                    }
16477    
16478                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_5);
16479    
16480                    conjunctionable = true;
16481    
16482                    if ((categoryIds == null) || (categoryIds.length > 0)) {
16483                            if (conjunctionable) {
16484                                    query.append(WHERE_AND);
16485                            }
16486    
16487                            query.append(StringPool.OPEN_PARENTHESIS);
16488    
16489                            for (int i = 0; i < categoryIds.length; i++) {
16490                                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_5);
16491    
16492                                    if ((i + 1) < categoryIds.length) {
16493                                            query.append(WHERE_OR);
16494                                    }
16495                            }
16496    
16497                            query.append(StringPool.CLOSE_PARENTHESIS);
16498    
16499                            conjunctionable = true;
16500                    }
16501    
16502                    if (conjunctionable) {
16503                            query.append(WHERE_AND);
16504                    }
16505    
16506                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_5);
16507    
16508                    conjunctionable = true;
16509    
16510                    if (!getDB().isSupportsInlineDistinct()) {
16511                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
16512                    }
16513    
16514                    if (orderByComparator != null) {
16515                            if (getDB().isSupportsInlineDistinct()) {
16516                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16517                                            orderByComparator, true);
16518                            }
16519                            else {
16520                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
16521                                            orderByComparator, true);
16522                            }
16523                    }
16524                    else {
16525                            if (getDB().isSupportsInlineDistinct()) {
16526                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16527                            }
16528                            else {
16529                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
16530                            }
16531                    }
16532    
16533                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
16534                                    MBMessage.class.getName(),
16535                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
16536    
16537                    Session session = null;
16538    
16539                    try {
16540                            session = openSession();
16541    
16542                            SQLQuery q = session.createSQLQuery(sql);
16543    
16544                            if (getDB().isSupportsInlineDistinct()) {
16545                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
16546                            }
16547                            else {
16548                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
16549                            }
16550    
16551                            QueryPos qPos = QueryPos.getInstance(q);
16552    
16553                            qPos.add(groupId);
16554    
16555                            qPos.add(userId);
16556    
16557                            if (categoryIds != null) {
16558                                    qPos.add(categoryIds);
16559                            }
16560    
16561                            qPos.add(status);
16562    
16563                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
16564                    }
16565                    catch (Exception e) {
16566                            throw processException(e);
16567                    }
16568                    finally {
16569                            closeSession(session);
16570                    }
16571            }
16572    
16573            /**
16574             * Returns all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16575             *
16576             * <p>
16577             * 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.
16578             * </p>
16579             *
16580             * @param groupId the group ID
16581             * @param userId the user ID
16582             * @param categoryIds the category IDs
16583             * @param status the status
16584             * @return the matching message-boards messages
16585             * @throws SystemException if a system exception occurred
16586             */
16587            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
16588                    long[] categoryIds, int status) throws SystemException {
16589                    return findByG_U_C_S(groupId, userId, categoryIds, status,
16590                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
16591            }
16592    
16593            /**
16594             * Returns a range of all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16595             *
16596             * <p>
16597             * 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.
16598             * </p>
16599             *
16600             * @param groupId the group ID
16601             * @param userId the user ID
16602             * @param categoryIds the category IDs
16603             * @param status the status
16604             * @param start the lower bound of the range of message-boards messages
16605             * @param end the upper bound of the range of message-boards messages (not inclusive)
16606             * @return the range of matching message-boards messages
16607             * @throws SystemException if a system exception occurred
16608             */
16609            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
16610                    long[] categoryIds, int status, int start, int end)
16611                    throws SystemException {
16612                    return findByG_U_C_S(groupId, userId, categoryIds, status, start, end,
16613                            null);
16614            }
16615    
16616            /**
16617             * Returns an ordered range of all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16618             *
16619             * <p>
16620             * 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.
16621             * </p>
16622             *
16623             * @param groupId the group ID
16624             * @param userId the user ID
16625             * @param categoryIds the category IDs
16626             * @param status the status
16627             * @param start the lower bound of the range of message-boards messages
16628             * @param end the upper bound of the range of message-boards messages (not inclusive)
16629             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
16630             * @return the ordered range of matching message-boards messages
16631             * @throws SystemException if a system exception occurred
16632             */
16633            public List<MBMessage> findByG_U_C_S(long groupId, long userId,
16634                    long[] categoryIds, int status, int start, int end,
16635                    OrderByComparator orderByComparator) throws SystemException {
16636                    if ((categoryIds != null) && (categoryIds.length == 1)) {
16637                            return findByG_U_C_S(groupId, userId, categoryIds[0], status,
16638                                    start, end, orderByComparator);
16639                    }
16640    
16641                    boolean pagination = true;
16642                    Object[] finderArgs = null;
16643    
16644                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
16645                                    (orderByComparator == null)) {
16646                            pagination = false;
16647                            finderArgs = new Object[] {
16648                                            groupId, userId, StringUtil.merge(categoryIds), status
16649                                    };
16650                    }
16651                    else {
16652                            finderArgs = new Object[] {
16653                                            groupId, userId, StringUtil.merge(categoryIds), status,
16654                                            
16655                                            start, end, orderByComparator
16656                                    };
16657                    }
16658    
16659                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_S,
16660                                    finderArgs, this);
16661    
16662                    if ((list != null) && !list.isEmpty()) {
16663                            for (MBMessage mbMessage : list) {
16664                                    if ((groupId != mbMessage.getGroupId()) ||
16665                                                    (userId != mbMessage.getUserId()) ||
16666                                                    !ArrayUtil.contains(categoryIds,
16667                                                            mbMessage.getCategoryId()) ||
16668                                                    (status != mbMessage.getStatus())) {
16669                                            list = null;
16670    
16671                                            break;
16672                                    }
16673                            }
16674                    }
16675    
16676                    if (list == null) {
16677                            StringBundler query = new StringBundler();
16678    
16679                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
16680    
16681                            boolean conjunctionable = false;
16682    
16683                            if (conjunctionable) {
16684                                    query.append(WHERE_AND);
16685                            }
16686    
16687                            query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_5);
16688    
16689                            conjunctionable = true;
16690    
16691                            if (conjunctionable) {
16692                                    query.append(WHERE_AND);
16693                            }
16694    
16695                            query.append(_FINDER_COLUMN_G_U_C_S_USERID_5);
16696    
16697                            conjunctionable = true;
16698    
16699                            if ((categoryIds == null) || (categoryIds.length > 0)) {
16700                                    if (conjunctionable) {
16701                                            query.append(WHERE_AND);
16702                                    }
16703    
16704                                    query.append(StringPool.OPEN_PARENTHESIS);
16705    
16706                                    for (int i = 0; i < categoryIds.length; i++) {
16707                                            query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_5);
16708    
16709                                            if ((i + 1) < categoryIds.length) {
16710                                                    query.append(WHERE_OR);
16711                                            }
16712                                    }
16713    
16714                                    query.append(StringPool.CLOSE_PARENTHESIS);
16715    
16716                                    conjunctionable = true;
16717                            }
16718    
16719                            if (conjunctionable) {
16720                                    query.append(WHERE_AND);
16721                            }
16722    
16723                            query.append(_FINDER_COLUMN_G_U_C_S_STATUS_5);
16724    
16725                            conjunctionable = true;
16726    
16727                            if (orderByComparator != null) {
16728                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
16729                                            orderByComparator);
16730                            }
16731                            else
16732                             if (pagination) {
16733                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
16734                            }
16735    
16736                            String sql = query.toString();
16737    
16738                            Session session = null;
16739    
16740                            try {
16741                                    session = openSession();
16742    
16743                                    Query q = session.createQuery(sql);
16744    
16745                                    QueryPos qPos = QueryPos.getInstance(q);
16746    
16747                                    qPos.add(groupId);
16748    
16749                                    qPos.add(userId);
16750    
16751                                    if (categoryIds != null) {
16752                                            qPos.add(categoryIds);
16753                                    }
16754    
16755                                    qPos.add(status);
16756    
16757                                    if (!pagination) {
16758                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16759                                                            start, end, false);
16760    
16761                                            Collections.sort(list);
16762    
16763                                            list = new UnmodifiableList<MBMessage>(list);
16764                                    }
16765                                    else {
16766                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
16767                                                            start, end);
16768                                    }
16769    
16770                                    cacheResult(list);
16771    
16772                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_S,
16773                                            finderArgs, list);
16774                            }
16775                            catch (Exception e) {
16776                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_U_C_S,
16777                                            finderArgs);
16778    
16779                                    throw processException(e);
16780                            }
16781                            finally {
16782                                    closeSession(session);
16783                            }
16784                    }
16785    
16786                    return list;
16787            }
16788    
16789            /**
16790             * Removes all the message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63; from the database.
16791             *
16792             * @param groupId the group ID
16793             * @param userId the user ID
16794             * @param categoryId the category ID
16795             * @param status the status
16796             * @throws SystemException if a system exception occurred
16797             */
16798            public void removeByG_U_C_S(long groupId, long userId, long categoryId,
16799                    int status) throws SystemException {
16800                    for (MBMessage mbMessage : findByG_U_C_S(groupId, userId, categoryId,
16801                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
16802                            remove(mbMessage);
16803                    }
16804            }
16805    
16806            /**
16807             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16808             *
16809             * @param groupId the group ID
16810             * @param userId the user ID
16811             * @param categoryId the category ID
16812             * @param status the status
16813             * @return the number of matching message-boards messages
16814             * @throws SystemException if a system exception occurred
16815             */
16816            public int countByG_U_C_S(long groupId, long userId, long categoryId,
16817                    int status) throws SystemException {
16818                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_U_C_S;
16819    
16820                    Object[] finderArgs = new Object[] { groupId, userId, categoryId, status };
16821    
16822                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
16823                                    this);
16824    
16825                    if (count == null) {
16826                            StringBundler query = new StringBundler(5);
16827    
16828                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16829    
16830                            query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
16831    
16832                            query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
16833    
16834                            query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
16835    
16836                            query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
16837    
16838                            String sql = query.toString();
16839    
16840                            Session session = null;
16841    
16842                            try {
16843                                    session = openSession();
16844    
16845                                    Query q = session.createQuery(sql);
16846    
16847                                    QueryPos qPos = QueryPos.getInstance(q);
16848    
16849                                    qPos.add(groupId);
16850    
16851                                    qPos.add(userId);
16852    
16853                                    qPos.add(categoryId);
16854    
16855                                    qPos.add(status);
16856    
16857                                    count = (Long)q.uniqueResult();
16858    
16859                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
16860                            }
16861                            catch (Exception e) {
16862                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
16863    
16864                                    throw processException(e);
16865                            }
16866                            finally {
16867                                    closeSession(session);
16868                            }
16869                    }
16870    
16871                    return count.intValue();
16872            }
16873    
16874            /**
16875             * Returns the number of message-boards messages where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
16876             *
16877             * @param groupId the group ID
16878             * @param userId the user ID
16879             * @param categoryIds the category IDs
16880             * @param status the status
16881             * @return the number of matching message-boards messages
16882             * @throws SystemException if a system exception occurred
16883             */
16884            public int countByG_U_C_S(long groupId, long userId, long[] categoryIds,
16885                    int status) throws SystemException {
16886                    Object[] finderArgs = new Object[] {
16887                                    groupId, userId, StringUtil.merge(categoryIds), status
16888                            };
16889    
16890                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_C_S,
16891                                    finderArgs, this);
16892    
16893                    if (count == null) {
16894                            StringBundler query = new StringBundler();
16895    
16896                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
16897    
16898                            boolean conjunctionable = false;
16899    
16900                            if (conjunctionable) {
16901                                    query.append(WHERE_AND);
16902                            }
16903    
16904                            query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_5);
16905    
16906                            conjunctionable = true;
16907    
16908                            if (conjunctionable) {
16909                                    query.append(WHERE_AND);
16910                            }
16911    
16912                            query.append(_FINDER_COLUMN_G_U_C_S_USERID_5);
16913    
16914                            conjunctionable = true;
16915    
16916                            if ((categoryIds == null) || (categoryIds.length > 0)) {
16917                                    if (conjunctionable) {
16918                                            query.append(WHERE_AND);
16919                                    }
16920    
16921                                    query.append(StringPool.OPEN_PARENTHESIS);
16922    
16923                                    for (int i = 0; i < categoryIds.length; i++) {
16924                                            query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_5);
16925    
16926                                            if ((i + 1) < categoryIds.length) {
16927                                                    query.append(WHERE_OR);
16928                                            }
16929                                    }
16930    
16931                                    query.append(StringPool.CLOSE_PARENTHESIS);
16932    
16933                                    conjunctionable = true;
16934                            }
16935    
16936                            if (conjunctionable) {
16937                                    query.append(WHERE_AND);
16938                            }
16939    
16940                            query.append(_FINDER_COLUMN_G_U_C_S_STATUS_5);
16941    
16942                            conjunctionable = true;
16943    
16944                            String sql = query.toString();
16945    
16946                            Session session = null;
16947    
16948                            try {
16949                                    session = openSession();
16950    
16951                                    Query q = session.createQuery(sql);
16952    
16953                                    QueryPos qPos = QueryPos.getInstance(q);
16954    
16955                                    qPos.add(groupId);
16956    
16957                                    qPos.add(userId);
16958    
16959                                    if (categoryIds != null) {
16960                                            qPos.add(categoryIds);
16961                                    }
16962    
16963                                    qPos.add(status);
16964    
16965                                    count = (Long)q.uniqueResult();
16966    
16967                                    FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_C_S,
16968                                            finderArgs, count);
16969                            }
16970                            catch (Exception e) {
16971                                    FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_U_C_S,
16972                                            finderArgs);
16973    
16974                                    throw processException(e);
16975                            }
16976                            finally {
16977                                    closeSession(session);
16978                            }
16979                    }
16980    
16981                    return count.intValue();
16982            }
16983    
16984            /**
16985             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = &#63; and status = &#63;.
16986             *
16987             * @param groupId the group ID
16988             * @param userId the user ID
16989             * @param categoryId the category ID
16990             * @param status the status
16991             * @return the number of matching message-boards messages that the user has permission to view
16992             * @throws SystemException if a system exception occurred
16993             */
16994            public int filterCountByG_U_C_S(long groupId, long userId, long categoryId,
16995                    int status) throws SystemException {
16996                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
16997                            return countByG_U_C_S(groupId, userId, categoryId, status);
16998                    }
16999    
17000                    StringBundler query = new StringBundler(5);
17001    
17002                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17003    
17004                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_2);
17005    
17006                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_2);
17007    
17008                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2);
17009    
17010                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_2);
17011    
17012                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17013                                    MBMessage.class.getName(),
17014                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17015    
17016                    Session session = null;
17017    
17018                    try {
17019                            session = openSession();
17020    
17021                            SQLQuery q = session.createSQLQuery(sql);
17022    
17023                            q.addScalar(COUNT_COLUMN_NAME,
17024                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17025    
17026                            QueryPos qPos = QueryPos.getInstance(q);
17027    
17028                            qPos.add(groupId);
17029    
17030                            qPos.add(userId);
17031    
17032                            qPos.add(categoryId);
17033    
17034                            qPos.add(status);
17035    
17036                            Long count = (Long)q.uniqueResult();
17037    
17038                            return count.intValue();
17039                    }
17040                    catch (Exception e) {
17041                            throw processException(e);
17042                    }
17043                    finally {
17044                            closeSession(session);
17045                    }
17046            }
17047    
17048            /**
17049             * Returns the number of message-boards messages that the user has permission to view where groupId = &#63; and userId = &#63; and categoryId = any &#63; and status = &#63;.
17050             *
17051             * @param groupId the group ID
17052             * @param userId the user ID
17053             * @param categoryIds the category IDs
17054             * @param status the status
17055             * @return the number of matching message-boards messages that the user has permission to view
17056             * @throws SystemException if a system exception occurred
17057             */
17058            public int filterCountByG_U_C_S(long groupId, long userId,
17059                    long[] categoryIds, int status) throws SystemException {
17060                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17061                            return countByG_U_C_S(groupId, userId, categoryIds, status);
17062                    }
17063    
17064                    StringBundler query = new StringBundler();
17065    
17066                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
17067    
17068                    boolean conjunctionable = false;
17069    
17070                    if (conjunctionable) {
17071                            query.append(WHERE_AND);
17072                    }
17073    
17074                    query.append(_FINDER_COLUMN_G_U_C_S_GROUPID_5);
17075    
17076                    conjunctionable = true;
17077    
17078                    if (conjunctionable) {
17079                            query.append(WHERE_AND);
17080                    }
17081    
17082                    query.append(_FINDER_COLUMN_G_U_C_S_USERID_5);
17083    
17084                    conjunctionable = true;
17085    
17086                    if ((categoryIds == null) || (categoryIds.length > 0)) {
17087                            if (conjunctionable) {
17088                                    query.append(WHERE_AND);
17089                            }
17090    
17091                            query.append(StringPool.OPEN_PARENTHESIS);
17092    
17093                            for (int i = 0; i < categoryIds.length; i++) {
17094                                    query.append(_FINDER_COLUMN_G_U_C_S_CATEGORYID_5);
17095    
17096                                    if ((i + 1) < categoryIds.length) {
17097                                            query.append(WHERE_OR);
17098                                    }
17099                            }
17100    
17101                            query.append(StringPool.CLOSE_PARENTHESIS);
17102    
17103                            conjunctionable = true;
17104                    }
17105    
17106                    if (conjunctionable) {
17107                            query.append(WHERE_AND);
17108                    }
17109    
17110                    query.append(_FINDER_COLUMN_G_U_C_S_STATUS_5);
17111    
17112                    conjunctionable = true;
17113    
17114                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17115                                    MBMessage.class.getName(),
17116                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17117    
17118                    Session session = null;
17119    
17120                    try {
17121                            session = openSession();
17122    
17123                            SQLQuery q = session.createSQLQuery(sql);
17124    
17125                            q.addScalar(COUNT_COLUMN_NAME,
17126                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
17127    
17128                            QueryPos qPos = QueryPos.getInstance(q);
17129    
17130                            qPos.add(groupId);
17131    
17132                            qPos.add(userId);
17133    
17134                            if (categoryIds != null) {
17135                                    qPos.add(categoryIds);
17136                            }
17137    
17138                            qPos.add(status);
17139    
17140                            Long count = (Long)q.uniqueResult();
17141    
17142                            return count.intValue();
17143                    }
17144                    catch (Exception e) {
17145                            throw processException(e);
17146                    }
17147                    finally {
17148                            closeSession(session);
17149                    }
17150            }
17151    
17152            private static final String _FINDER_COLUMN_G_U_C_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
17153            private static final String _FINDER_COLUMN_G_U_C_S_GROUPID_5 = "(" +
17154                    removeConjunction(_FINDER_COLUMN_G_U_C_S_GROUPID_2) + ")";
17155            private static final String _FINDER_COLUMN_G_U_C_S_USERID_2 = "mbMessage.userId = ? AND ";
17156            private static final String _FINDER_COLUMN_G_U_C_S_USERID_5 = "(" +
17157                    removeConjunction(_FINDER_COLUMN_G_U_C_S_USERID_2) + ")";
17158            private static final String _FINDER_COLUMN_G_U_C_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
17159            private static final String _FINDER_COLUMN_G_U_C_S_CATEGORYID_5 = "(" +
17160                    removeConjunction(_FINDER_COLUMN_G_U_C_S_CATEGORYID_2) + ")";
17161            private static final String _FINDER_COLUMN_G_U_C_S_STATUS_2 = "mbMessage.status = ?";
17162            private static final String _FINDER_COLUMN_G_U_C_S_STATUS_5 = "(" +
17163                    removeConjunction(_FINDER_COLUMN_G_U_C_S_STATUS_2) + ")";
17164            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17165                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17166                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_A",
17167                            new String[] {
17168                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17169                                    Boolean.class.getName(),
17170                                    
17171                            Integer.class.getName(), Integer.class.getName(),
17172                                    OrderByComparator.class.getName()
17173                            });
17174            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A =
17175                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17176                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
17177                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_A",
17178                            new String[] {
17179                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17180                                    Boolean.class.getName()
17181                            },
17182                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
17183                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
17184                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
17185                            MBMessageModelImpl.ANSWER_COLUMN_BITMASK |
17186                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
17187            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_A = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
17188                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
17189                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_A",
17190                            new String[] {
17191                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
17192                                    Boolean.class.getName()
17193                            });
17194    
17195            /**
17196             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17197             *
17198             * @param groupId the group ID
17199             * @param categoryId the category ID
17200             * @param threadId the thread ID
17201             * @param answer the answer
17202             * @return the matching message-boards messages
17203             * @throws SystemException if a system exception occurred
17204             */
17205            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
17206                    long threadId, boolean answer) throws SystemException {
17207                    return findByG_C_T_A(groupId, categoryId, threadId, answer,
17208                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17209            }
17210    
17211            /**
17212             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17213             *
17214             * <p>
17215             * 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.
17216             * </p>
17217             *
17218             * @param groupId the group ID
17219             * @param categoryId the category ID
17220             * @param threadId the thread ID
17221             * @param answer the answer
17222             * @param start the lower bound of the range of message-boards messages
17223             * @param end the upper bound of the range of message-boards messages (not inclusive)
17224             * @return the range of matching message-boards messages
17225             * @throws SystemException if a system exception occurred
17226             */
17227            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
17228                    long threadId, boolean answer, int start, int end)
17229                    throws SystemException {
17230                    return findByG_C_T_A(groupId, categoryId, threadId, answer, start, end,
17231                            null);
17232            }
17233    
17234            /**
17235             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17236             *
17237             * <p>
17238             * 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.
17239             * </p>
17240             *
17241             * @param groupId the group ID
17242             * @param categoryId the category ID
17243             * @param threadId the thread ID
17244             * @param answer the answer
17245             * @param start the lower bound of the range of message-boards messages
17246             * @param end the upper bound of the range of message-boards messages (not inclusive)
17247             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17248             * @return the ordered range of matching message-boards messages
17249             * @throws SystemException if a system exception occurred
17250             */
17251            public List<MBMessage> findByG_C_T_A(long groupId, long categoryId,
17252                    long threadId, boolean answer, int start, int end,
17253                    OrderByComparator orderByComparator) throws SystemException {
17254                    boolean pagination = true;
17255                    FinderPath finderPath = null;
17256                    Object[] finderArgs = null;
17257    
17258                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
17259                                    (orderByComparator == null)) {
17260                            pagination = false;
17261                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A;
17262                            finderArgs = new Object[] { groupId, categoryId, threadId, answer };
17263                    }
17264                    else {
17265                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_A;
17266                            finderArgs = new Object[] {
17267                                            groupId, categoryId, threadId, answer,
17268                                            
17269                                            start, end, orderByComparator
17270                                    };
17271                    }
17272    
17273                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
17274                                    finderArgs, this);
17275    
17276                    if ((list != null) && !list.isEmpty()) {
17277                            for (MBMessage mbMessage : list) {
17278                                    if ((groupId != mbMessage.getGroupId()) ||
17279                                                    (categoryId != mbMessage.getCategoryId()) ||
17280                                                    (threadId != mbMessage.getThreadId()) ||
17281                                                    (answer != mbMessage.getAnswer())) {
17282                                            list = null;
17283    
17284                                            break;
17285                                    }
17286                            }
17287                    }
17288    
17289                    if (list == null) {
17290                            StringBundler query = null;
17291    
17292                            if (orderByComparator != null) {
17293                                    query = new StringBundler(6 +
17294                                                    (orderByComparator.getOrderByFields().length * 3));
17295                            }
17296                            else {
17297                                    query = new StringBundler(6);
17298                            }
17299    
17300                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17301    
17302                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17303    
17304                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17305    
17306                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17307    
17308                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17309    
17310                            if (orderByComparator != null) {
17311                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17312                                            orderByComparator);
17313                            }
17314                            else
17315                             if (pagination) {
17316                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17317                            }
17318    
17319                            String sql = query.toString();
17320    
17321                            Session session = null;
17322    
17323                            try {
17324                                    session = openSession();
17325    
17326                                    Query q = session.createQuery(sql);
17327    
17328                                    QueryPos qPos = QueryPos.getInstance(q);
17329    
17330                                    qPos.add(groupId);
17331    
17332                                    qPos.add(categoryId);
17333    
17334                                    qPos.add(threadId);
17335    
17336                                    qPos.add(answer);
17337    
17338                                    if (!pagination) {
17339                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17340                                                            start, end, false);
17341    
17342                                            Collections.sort(list);
17343    
17344                                            list = new UnmodifiableList<MBMessage>(list);
17345                                    }
17346                                    else {
17347                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
17348                                                            start, end);
17349                                    }
17350    
17351                                    cacheResult(list);
17352    
17353                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
17354                            }
17355                            catch (Exception e) {
17356                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
17357    
17358                                    throw processException(e);
17359                            }
17360                            finally {
17361                                    closeSession(session);
17362                            }
17363                    }
17364    
17365                    return list;
17366            }
17367    
17368            /**
17369             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17370             *
17371             * @param groupId the group ID
17372             * @param categoryId the category ID
17373             * @param threadId the thread ID
17374             * @param answer the answer
17375             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17376             * @return the first matching message-boards message
17377             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17378             * @throws SystemException if a system exception occurred
17379             */
17380            public MBMessage findByG_C_T_A_First(long groupId, long categoryId,
17381                    long threadId, boolean answer, OrderByComparator orderByComparator)
17382                    throws NoSuchMessageException, SystemException {
17383                    MBMessage mbMessage = fetchByG_C_T_A_First(groupId, categoryId,
17384                                    threadId, answer, orderByComparator);
17385    
17386                    if (mbMessage != null) {
17387                            return mbMessage;
17388                    }
17389    
17390                    StringBundler msg = new StringBundler(10);
17391    
17392                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17393    
17394                    msg.append("groupId=");
17395                    msg.append(groupId);
17396    
17397                    msg.append(", categoryId=");
17398                    msg.append(categoryId);
17399    
17400                    msg.append(", threadId=");
17401                    msg.append(threadId);
17402    
17403                    msg.append(", answer=");
17404                    msg.append(answer);
17405    
17406                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17407    
17408                    throw new NoSuchMessageException(msg.toString());
17409            }
17410    
17411            /**
17412             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17413             *
17414             * @param groupId the group ID
17415             * @param categoryId the category ID
17416             * @param threadId the thread ID
17417             * @param answer the answer
17418             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17419             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17420             * @throws SystemException if a system exception occurred
17421             */
17422            public MBMessage fetchByG_C_T_A_First(long groupId, long categoryId,
17423                    long threadId, boolean answer, OrderByComparator orderByComparator)
17424                    throws SystemException {
17425                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
17426                                    answer, 0, 1, orderByComparator);
17427    
17428                    if (!list.isEmpty()) {
17429                            return list.get(0);
17430                    }
17431    
17432                    return null;
17433            }
17434    
17435            /**
17436             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17437             *
17438             * @param groupId the group ID
17439             * @param categoryId the category ID
17440             * @param threadId the thread ID
17441             * @param answer the answer
17442             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17443             * @return the last matching message-boards message
17444             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
17445             * @throws SystemException if a system exception occurred
17446             */
17447            public MBMessage findByG_C_T_A_Last(long groupId, long categoryId,
17448                    long threadId, boolean answer, OrderByComparator orderByComparator)
17449                    throws NoSuchMessageException, SystemException {
17450                    MBMessage mbMessage = fetchByG_C_T_A_Last(groupId, categoryId,
17451                                    threadId, answer, orderByComparator);
17452    
17453                    if (mbMessage != null) {
17454                            return mbMessage;
17455                    }
17456    
17457                    StringBundler msg = new StringBundler(10);
17458    
17459                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
17460    
17461                    msg.append("groupId=");
17462                    msg.append(groupId);
17463    
17464                    msg.append(", categoryId=");
17465                    msg.append(categoryId);
17466    
17467                    msg.append(", threadId=");
17468                    msg.append(threadId);
17469    
17470                    msg.append(", answer=");
17471                    msg.append(answer);
17472    
17473                    msg.append(StringPool.CLOSE_CURLY_BRACE);
17474    
17475                    throw new NoSuchMessageException(msg.toString());
17476            }
17477    
17478            /**
17479             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
17480             *
17481             * @param groupId the group ID
17482             * @param categoryId the category ID
17483             * @param threadId the thread ID
17484             * @param answer the answer
17485             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17486             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
17487             * @throws SystemException if a system exception occurred
17488             */
17489            public MBMessage fetchByG_C_T_A_Last(long groupId, long categoryId,
17490                    long threadId, boolean answer, OrderByComparator orderByComparator)
17491                    throws SystemException {
17492                    int count = countByG_C_T_A(groupId, categoryId, threadId, answer);
17493    
17494                    List<MBMessage> list = findByG_C_T_A(groupId, categoryId, threadId,
17495                                    answer, count - 1, count, orderByComparator);
17496    
17497                    if (!list.isEmpty()) {
17498                            return list.get(0);
17499                    }
17500    
17501                    return null;
17502            }
17503    
17504            /**
17505             * 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;.
17506             *
17507             * @param messageId the primary key of the current message-boards message
17508             * @param groupId the group ID
17509             * @param categoryId the category ID
17510             * @param threadId the thread ID
17511             * @param answer the answer
17512             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17513             * @return the previous, current, and next message-boards message
17514             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17515             * @throws SystemException if a system exception occurred
17516             */
17517            public MBMessage[] findByG_C_T_A_PrevAndNext(long messageId, long groupId,
17518                    long categoryId, long threadId, boolean answer,
17519                    OrderByComparator orderByComparator)
17520                    throws NoSuchMessageException, SystemException {
17521                    MBMessage mbMessage = findByPrimaryKey(messageId);
17522    
17523                    Session session = null;
17524    
17525                    try {
17526                            session = openSession();
17527    
17528                            MBMessage[] array = new MBMessageImpl[3];
17529    
17530                            array[0] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
17531                                            categoryId, threadId, answer, orderByComparator, true);
17532    
17533                            array[1] = mbMessage;
17534    
17535                            array[2] = getByG_C_T_A_PrevAndNext(session, mbMessage, groupId,
17536                                            categoryId, threadId, answer, orderByComparator, false);
17537    
17538                            return array;
17539                    }
17540                    catch (Exception e) {
17541                            throw processException(e);
17542                    }
17543                    finally {
17544                            closeSession(session);
17545                    }
17546            }
17547    
17548            protected MBMessage getByG_C_T_A_PrevAndNext(Session session,
17549                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17550                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
17551                    StringBundler query = null;
17552    
17553                    if (orderByComparator != null) {
17554                            query = new StringBundler(6 +
17555                                            (orderByComparator.getOrderByFields().length * 6));
17556                    }
17557                    else {
17558                            query = new StringBundler(3);
17559                    }
17560    
17561                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
17562    
17563                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17564    
17565                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17566    
17567                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17568    
17569                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17570    
17571                    if (orderByComparator != null) {
17572                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17573    
17574                            if (orderByConditionFields.length > 0) {
17575                                    query.append(WHERE_AND);
17576                            }
17577    
17578                            for (int i = 0; i < orderByConditionFields.length; i++) {
17579                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17580                                    query.append(orderByConditionFields[i]);
17581    
17582                                    if ((i + 1) < orderByConditionFields.length) {
17583                                            if (orderByComparator.isAscending() ^ previous) {
17584                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17585                                            }
17586                                            else {
17587                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17588                                            }
17589                                    }
17590                                    else {
17591                                            if (orderByComparator.isAscending() ^ previous) {
17592                                                    query.append(WHERE_GREATER_THAN);
17593                                            }
17594                                            else {
17595                                                    query.append(WHERE_LESSER_THAN);
17596                                            }
17597                                    }
17598                            }
17599    
17600                            query.append(ORDER_BY_CLAUSE);
17601    
17602                            String[] orderByFields = orderByComparator.getOrderByFields();
17603    
17604                            for (int i = 0; i < orderByFields.length; i++) {
17605                                    query.append(_ORDER_BY_ENTITY_ALIAS);
17606                                    query.append(orderByFields[i]);
17607    
17608                                    if ((i + 1) < orderByFields.length) {
17609                                            if (orderByComparator.isAscending() ^ previous) {
17610                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17611                                            }
17612                                            else {
17613                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17614                                            }
17615                                    }
17616                                    else {
17617                                            if (orderByComparator.isAscending() ^ previous) {
17618                                                    query.append(ORDER_BY_ASC);
17619                                            }
17620                                            else {
17621                                                    query.append(ORDER_BY_DESC);
17622                                            }
17623                                    }
17624                            }
17625                    }
17626                    else {
17627                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17628                    }
17629    
17630                    String sql = query.toString();
17631    
17632                    Query q = session.createQuery(sql);
17633    
17634                    q.setFirstResult(0);
17635                    q.setMaxResults(2);
17636    
17637                    QueryPos qPos = QueryPos.getInstance(q);
17638    
17639                    qPos.add(groupId);
17640    
17641                    qPos.add(categoryId);
17642    
17643                    qPos.add(threadId);
17644    
17645                    qPos.add(answer);
17646    
17647                    if (orderByComparator != null) {
17648                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
17649    
17650                            for (Object value : values) {
17651                                    qPos.add(value);
17652                            }
17653                    }
17654    
17655                    List<MBMessage> list = q.list();
17656    
17657                    if (list.size() == 2) {
17658                            return list.get(1);
17659                    }
17660                    else {
17661                            return null;
17662                    }
17663            }
17664    
17665            /**
17666             * 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;.
17667             *
17668             * @param groupId the group ID
17669             * @param categoryId the category ID
17670             * @param threadId the thread ID
17671             * @param answer the answer
17672             * @return the matching message-boards messages that the user has permission to view
17673             * @throws SystemException if a system exception occurred
17674             */
17675            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
17676                    long threadId, boolean answer) throws SystemException {
17677                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
17678                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
17679            }
17680    
17681            /**
17682             * 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;.
17683             *
17684             * <p>
17685             * 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.
17686             * </p>
17687             *
17688             * @param groupId the group ID
17689             * @param categoryId the category ID
17690             * @param threadId the thread ID
17691             * @param answer the answer
17692             * @param start the lower bound of the range of message-boards messages
17693             * @param end the upper bound of the range of message-boards messages (not inclusive)
17694             * @return the range of matching message-boards messages that the user has permission to view
17695             * @throws SystemException if a system exception occurred
17696             */
17697            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
17698                    long threadId, boolean answer, int start, int end)
17699                    throws SystemException {
17700                    return filterFindByG_C_T_A(groupId, categoryId, threadId, answer,
17701                            start, end, null);
17702            }
17703    
17704            /**
17705             * 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;.
17706             *
17707             * <p>
17708             * 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.
17709             * </p>
17710             *
17711             * @param groupId the group ID
17712             * @param categoryId the category ID
17713             * @param threadId the thread ID
17714             * @param answer the answer
17715             * @param start the lower bound of the range of message-boards messages
17716             * @param end the upper bound of the range of message-boards messages (not inclusive)
17717             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
17718             * @return the ordered range of matching message-boards messages that the user has permission to view
17719             * @throws SystemException if a system exception occurred
17720             */
17721            public List<MBMessage> filterFindByG_C_T_A(long groupId, long categoryId,
17722                    long threadId, boolean answer, int start, int end,
17723                    OrderByComparator orderByComparator) throws SystemException {
17724                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17725                            return findByG_C_T_A(groupId, categoryId, threadId, answer, start,
17726                                    end, orderByComparator);
17727                    }
17728    
17729                    StringBundler query = null;
17730    
17731                    if (orderByComparator != null) {
17732                            query = new StringBundler(6 +
17733                                            (orderByComparator.getOrderByFields().length * 3));
17734                    }
17735                    else {
17736                            query = new StringBundler(6);
17737                    }
17738    
17739                    if (getDB().isSupportsInlineDistinct()) {
17740                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17741                    }
17742                    else {
17743                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17744                    }
17745    
17746                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17747    
17748                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17749    
17750                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17751    
17752                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17753    
17754                    if (!getDB().isSupportsInlineDistinct()) {
17755                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17756                    }
17757    
17758                    if (orderByComparator != null) {
17759                            if (getDB().isSupportsInlineDistinct()) {
17760                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
17761                                            orderByComparator, true);
17762                            }
17763                            else {
17764                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
17765                                            orderByComparator, true);
17766                            }
17767                    }
17768                    else {
17769                            if (getDB().isSupportsInlineDistinct()) {
17770                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17771                            }
17772                            else {
17773                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17774                            }
17775                    }
17776    
17777                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17778                                    MBMessage.class.getName(),
17779                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17780    
17781                    Session session = null;
17782    
17783                    try {
17784                            session = openSession();
17785    
17786                            SQLQuery q = session.createSQLQuery(sql);
17787    
17788                            if (getDB().isSupportsInlineDistinct()) {
17789                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17790                            }
17791                            else {
17792                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17793                            }
17794    
17795                            QueryPos qPos = QueryPos.getInstance(q);
17796    
17797                            qPos.add(groupId);
17798    
17799                            qPos.add(categoryId);
17800    
17801                            qPos.add(threadId);
17802    
17803                            qPos.add(answer);
17804    
17805                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
17806                    }
17807                    catch (Exception e) {
17808                            throw processException(e);
17809                    }
17810                    finally {
17811                            closeSession(session);
17812                    }
17813            }
17814    
17815            /**
17816             * 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;.
17817             *
17818             * @param messageId the primary key of the current message-boards message
17819             * @param groupId the group ID
17820             * @param categoryId the category ID
17821             * @param threadId the thread ID
17822             * @param answer the answer
17823             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
17824             * @return the previous, current, and next message-boards message
17825             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
17826             * @throws SystemException if a system exception occurred
17827             */
17828            public MBMessage[] filterFindByG_C_T_A_PrevAndNext(long messageId,
17829                    long groupId, long categoryId, long threadId, boolean answer,
17830                    OrderByComparator orderByComparator)
17831                    throws NoSuchMessageException, SystemException {
17832                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
17833                            return findByG_C_T_A_PrevAndNext(messageId, groupId, categoryId,
17834                                    threadId, answer, orderByComparator);
17835                    }
17836    
17837                    MBMessage mbMessage = findByPrimaryKey(messageId);
17838    
17839                    Session session = null;
17840    
17841                    try {
17842                            session = openSession();
17843    
17844                            MBMessage[] array = new MBMessageImpl[3];
17845    
17846                            array[0] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
17847                                            groupId, categoryId, threadId, answer, orderByComparator,
17848                                            true);
17849    
17850                            array[1] = mbMessage;
17851    
17852                            array[2] = filterGetByG_C_T_A_PrevAndNext(session, mbMessage,
17853                                            groupId, categoryId, threadId, answer, orderByComparator,
17854                                            false);
17855    
17856                            return array;
17857                    }
17858                    catch (Exception e) {
17859                            throw processException(e);
17860                    }
17861                    finally {
17862                            closeSession(session);
17863                    }
17864            }
17865    
17866            protected MBMessage filterGetByG_C_T_A_PrevAndNext(Session session,
17867                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
17868                    boolean answer, OrderByComparator orderByComparator, boolean previous) {
17869                    StringBundler query = null;
17870    
17871                    if (orderByComparator != null) {
17872                            query = new StringBundler(6 +
17873                                            (orderByComparator.getOrderByFields().length * 6));
17874                    }
17875                    else {
17876                            query = new StringBundler(3);
17877                    }
17878    
17879                    if (getDB().isSupportsInlineDistinct()) {
17880                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
17881                    }
17882                    else {
17883                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
17884                    }
17885    
17886                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
17887    
17888                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
17889    
17890                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
17891    
17892                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
17893    
17894                    if (!getDB().isSupportsInlineDistinct()) {
17895                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
17896                    }
17897    
17898                    if (orderByComparator != null) {
17899                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
17900    
17901                            if (orderByConditionFields.length > 0) {
17902                                    query.append(WHERE_AND);
17903                            }
17904    
17905                            for (int i = 0; i < orderByConditionFields.length; i++) {
17906                                    if (getDB().isSupportsInlineDistinct()) {
17907                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17908                                    }
17909                                    else {
17910                                            query.append(_ORDER_BY_ENTITY_TABLE);
17911                                    }
17912    
17913                                    query.append(orderByConditionFields[i]);
17914    
17915                                    if ((i + 1) < orderByConditionFields.length) {
17916                                            if (orderByComparator.isAscending() ^ previous) {
17917                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
17918                                            }
17919                                            else {
17920                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
17921                                            }
17922                                    }
17923                                    else {
17924                                            if (orderByComparator.isAscending() ^ previous) {
17925                                                    query.append(WHERE_GREATER_THAN);
17926                                            }
17927                                            else {
17928                                                    query.append(WHERE_LESSER_THAN);
17929                                            }
17930                                    }
17931                            }
17932    
17933                            query.append(ORDER_BY_CLAUSE);
17934    
17935                            String[] orderByFields = orderByComparator.getOrderByFields();
17936    
17937                            for (int i = 0; i < orderByFields.length; i++) {
17938                                    if (getDB().isSupportsInlineDistinct()) {
17939                                            query.append(_ORDER_BY_ENTITY_ALIAS);
17940                                    }
17941                                    else {
17942                                            query.append(_ORDER_BY_ENTITY_TABLE);
17943                                    }
17944    
17945                                    query.append(orderByFields[i]);
17946    
17947                                    if ((i + 1) < orderByFields.length) {
17948                                            if (orderByComparator.isAscending() ^ previous) {
17949                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
17950                                            }
17951                                            else {
17952                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
17953                                            }
17954                                    }
17955                                    else {
17956                                            if (orderByComparator.isAscending() ^ previous) {
17957                                                    query.append(ORDER_BY_ASC);
17958                                            }
17959                                            else {
17960                                                    query.append(ORDER_BY_DESC);
17961                                            }
17962                                    }
17963                            }
17964                    }
17965                    else {
17966                            if (getDB().isSupportsInlineDistinct()) {
17967                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
17968                            }
17969                            else {
17970                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
17971                            }
17972                    }
17973    
17974                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
17975                                    MBMessage.class.getName(),
17976                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
17977    
17978                    SQLQuery q = session.createSQLQuery(sql);
17979    
17980                    q.setFirstResult(0);
17981                    q.setMaxResults(2);
17982    
17983                    if (getDB().isSupportsInlineDistinct()) {
17984                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
17985                    }
17986                    else {
17987                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
17988                    }
17989    
17990                    QueryPos qPos = QueryPos.getInstance(q);
17991    
17992                    qPos.add(groupId);
17993    
17994                    qPos.add(categoryId);
17995    
17996                    qPos.add(threadId);
17997    
17998                    qPos.add(answer);
17999    
18000                    if (orderByComparator != null) {
18001                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18002    
18003                            for (Object value : values) {
18004                                    qPos.add(value);
18005                            }
18006                    }
18007    
18008                    List<MBMessage> list = q.list();
18009    
18010                    if (list.size() == 2) {
18011                            return list.get(1);
18012                    }
18013                    else {
18014                            return null;
18015                    }
18016            }
18017    
18018            /**
18019             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63; from the database.
18020             *
18021             * @param groupId the group ID
18022             * @param categoryId the category ID
18023             * @param threadId the thread ID
18024             * @param answer the answer
18025             * @throws SystemException if a system exception occurred
18026             */
18027            public void removeByG_C_T_A(long groupId, long categoryId, long threadId,
18028                    boolean answer) throws SystemException {
18029                    for (MBMessage mbMessage : findByG_C_T_A(groupId, categoryId, threadId,
18030                                    answer, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
18031                            remove(mbMessage);
18032                    }
18033            }
18034    
18035            /**
18036             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and answer = &#63;.
18037             *
18038             * @param groupId the group ID
18039             * @param categoryId the category ID
18040             * @param threadId the thread ID
18041             * @param answer the answer
18042             * @return the number of matching message-boards messages
18043             * @throws SystemException if a system exception occurred
18044             */
18045            public int countByG_C_T_A(long groupId, long categoryId, long threadId,
18046                    boolean answer) throws SystemException {
18047                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_A;
18048    
18049                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, answer };
18050    
18051                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
18052                                    this);
18053    
18054                    if (count == null) {
18055                            StringBundler query = new StringBundler(5);
18056    
18057                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
18058    
18059                            query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18060    
18061                            query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18062    
18063                            query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18064    
18065                            query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18066    
18067                            String sql = query.toString();
18068    
18069                            Session session = null;
18070    
18071                            try {
18072                                    session = openSession();
18073    
18074                                    Query q = session.createQuery(sql);
18075    
18076                                    QueryPos qPos = QueryPos.getInstance(q);
18077    
18078                                    qPos.add(groupId);
18079    
18080                                    qPos.add(categoryId);
18081    
18082                                    qPos.add(threadId);
18083    
18084                                    qPos.add(answer);
18085    
18086                                    count = (Long)q.uniqueResult();
18087    
18088                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
18089                            }
18090                            catch (Exception e) {
18091                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18092    
18093                                    throw processException(e);
18094                            }
18095                            finally {
18096                                    closeSession(session);
18097                            }
18098                    }
18099    
18100                    return count.intValue();
18101            }
18102    
18103            /**
18104             * 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;.
18105             *
18106             * @param groupId the group ID
18107             * @param categoryId the category ID
18108             * @param threadId the thread ID
18109             * @param answer the answer
18110             * @return the number of matching message-boards messages that the user has permission to view
18111             * @throws SystemException if a system exception occurred
18112             */
18113            public int filterCountByG_C_T_A(long groupId, long categoryId,
18114                    long threadId, boolean answer) throws SystemException {
18115                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18116                            return countByG_C_T_A(groupId, categoryId, threadId, answer);
18117                    }
18118    
18119                    StringBundler query = new StringBundler(5);
18120    
18121                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
18122    
18123                    query.append(_FINDER_COLUMN_G_C_T_A_GROUPID_2);
18124    
18125                    query.append(_FINDER_COLUMN_G_C_T_A_CATEGORYID_2);
18126    
18127                    query.append(_FINDER_COLUMN_G_C_T_A_THREADID_2);
18128    
18129                    query.append(_FINDER_COLUMN_G_C_T_A_ANSWER_2);
18130    
18131                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18132                                    MBMessage.class.getName(),
18133                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18134    
18135                    Session session = null;
18136    
18137                    try {
18138                            session = openSession();
18139    
18140                            SQLQuery q = session.createSQLQuery(sql);
18141    
18142                            q.addScalar(COUNT_COLUMN_NAME,
18143                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
18144    
18145                            QueryPos qPos = QueryPos.getInstance(q);
18146    
18147                            qPos.add(groupId);
18148    
18149                            qPos.add(categoryId);
18150    
18151                            qPos.add(threadId);
18152    
18153                            qPos.add(answer);
18154    
18155                            Long count = (Long)q.uniqueResult();
18156    
18157                            return count.intValue();
18158                    }
18159                    catch (Exception e) {
18160                            throw processException(e);
18161                    }
18162                    finally {
18163                            closeSession(session);
18164                    }
18165            }
18166    
18167            private static final String _FINDER_COLUMN_G_C_T_A_GROUPID_2 = "mbMessage.groupId = ? AND ";
18168            private static final String _FINDER_COLUMN_G_C_T_A_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
18169            private static final String _FINDER_COLUMN_G_C_T_A_THREADID_2 = "mbMessage.threadId = ? AND ";
18170            private static final String _FINDER_COLUMN_G_C_T_A_ANSWER_2 = "mbMessage.answer = ?";
18171            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18172                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18173                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByG_C_T_S",
18174                            new String[] {
18175                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18176                                    Integer.class.getName(),
18177                                    
18178                            Integer.class.getName(), Integer.class.getName(),
18179                                    OrderByComparator.class.getName()
18180                            });
18181            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S =
18182                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18183                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
18184                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByG_C_T_S",
18185                            new String[] {
18186                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18187                                    Integer.class.getName()
18188                            },
18189                            MBMessageModelImpl.GROUPID_COLUMN_BITMASK |
18190                            MBMessageModelImpl.CATEGORYID_COLUMN_BITMASK |
18191                            MBMessageModelImpl.THREADID_COLUMN_BITMASK |
18192                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
18193                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
18194            public static final FinderPath FINDER_PATH_COUNT_BY_G_C_T_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
18195                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
18196                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByG_C_T_S",
18197                            new String[] {
18198                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
18199                                    Integer.class.getName()
18200                            });
18201    
18202            /**
18203             * Returns all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18204             *
18205             * @param groupId the group ID
18206             * @param categoryId the category ID
18207             * @param threadId the thread ID
18208             * @param status the status
18209             * @return the matching message-boards messages
18210             * @throws SystemException if a system exception occurred
18211             */
18212            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
18213                    long threadId, int status) throws SystemException {
18214                    return findByG_C_T_S(groupId, categoryId, threadId, status,
18215                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18216            }
18217    
18218            /**
18219             * Returns a range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18220             *
18221             * <p>
18222             * 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.
18223             * </p>
18224             *
18225             * @param groupId the group ID
18226             * @param categoryId the category ID
18227             * @param threadId the thread ID
18228             * @param status the status
18229             * @param start the lower bound of the range of message-boards messages
18230             * @param end the upper bound of the range of message-boards messages (not inclusive)
18231             * @return the range of matching message-boards messages
18232             * @throws SystemException if a system exception occurred
18233             */
18234            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
18235                    long threadId, int status, int start, int end)
18236                    throws SystemException {
18237                    return findByG_C_T_S(groupId, categoryId, threadId, status, start, end,
18238                            null);
18239            }
18240    
18241            /**
18242             * Returns an ordered range of all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18243             *
18244             * <p>
18245             * 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.
18246             * </p>
18247             *
18248             * @param groupId the group ID
18249             * @param categoryId the category ID
18250             * @param threadId the thread ID
18251             * @param status the status
18252             * @param start the lower bound of the range of message-boards messages
18253             * @param end the upper bound of the range of message-boards messages (not inclusive)
18254             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18255             * @return the ordered range of matching message-boards messages
18256             * @throws SystemException if a system exception occurred
18257             */
18258            public List<MBMessage> findByG_C_T_S(long groupId, long categoryId,
18259                    long threadId, int status, int start, int end,
18260                    OrderByComparator orderByComparator) throws SystemException {
18261                    boolean pagination = true;
18262                    FinderPath finderPath = null;
18263                    Object[] finderArgs = null;
18264    
18265                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
18266                                    (orderByComparator == null)) {
18267                            pagination = false;
18268                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S;
18269                            finderArgs = new Object[] { groupId, categoryId, threadId, status };
18270                    }
18271                    else {
18272                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_G_C_T_S;
18273                            finderArgs = new Object[] {
18274                                            groupId, categoryId, threadId, status,
18275                                            
18276                                            start, end, orderByComparator
18277                                    };
18278                    }
18279    
18280                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
18281                                    finderArgs, this);
18282    
18283                    if ((list != null) && !list.isEmpty()) {
18284                            for (MBMessage mbMessage : list) {
18285                                    if ((groupId != mbMessage.getGroupId()) ||
18286                                                    (categoryId != mbMessage.getCategoryId()) ||
18287                                                    (threadId != mbMessage.getThreadId()) ||
18288                                                    (status != mbMessage.getStatus())) {
18289                                            list = null;
18290    
18291                                            break;
18292                                    }
18293                            }
18294                    }
18295    
18296                    if (list == null) {
18297                            StringBundler query = null;
18298    
18299                            if (orderByComparator != null) {
18300                                    query = new StringBundler(6 +
18301                                                    (orderByComparator.getOrderByFields().length * 3));
18302                            }
18303                            else {
18304                                    query = new StringBundler(6);
18305                            }
18306    
18307                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18308    
18309                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18310    
18311                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18312    
18313                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18314    
18315                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18316    
18317                            if (orderByComparator != null) {
18318                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18319                                            orderByComparator);
18320                            }
18321                            else
18322                             if (pagination) {
18323                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18324                            }
18325    
18326                            String sql = query.toString();
18327    
18328                            Session session = null;
18329    
18330                            try {
18331                                    session = openSession();
18332    
18333                                    Query q = session.createQuery(sql);
18334    
18335                                    QueryPos qPos = QueryPos.getInstance(q);
18336    
18337                                    qPos.add(groupId);
18338    
18339                                    qPos.add(categoryId);
18340    
18341                                    qPos.add(threadId);
18342    
18343                                    qPos.add(status);
18344    
18345                                    if (!pagination) {
18346                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18347                                                            start, end, false);
18348    
18349                                            Collections.sort(list);
18350    
18351                                            list = new UnmodifiableList<MBMessage>(list);
18352                                    }
18353                                    else {
18354                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
18355                                                            start, end);
18356                                    }
18357    
18358                                    cacheResult(list);
18359    
18360                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
18361                            }
18362                            catch (Exception e) {
18363                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
18364    
18365                                    throw processException(e);
18366                            }
18367                            finally {
18368                                    closeSession(session);
18369                            }
18370                    }
18371    
18372                    return list;
18373            }
18374    
18375            /**
18376             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18377             *
18378             * @param groupId the group ID
18379             * @param categoryId the category ID
18380             * @param threadId the thread ID
18381             * @param status the status
18382             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18383             * @return the first matching message-boards message
18384             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
18385             * @throws SystemException if a system exception occurred
18386             */
18387            public MBMessage findByG_C_T_S_First(long groupId, long categoryId,
18388                    long threadId, int status, OrderByComparator orderByComparator)
18389                    throws NoSuchMessageException, SystemException {
18390                    MBMessage mbMessage = fetchByG_C_T_S_First(groupId, categoryId,
18391                                    threadId, status, orderByComparator);
18392    
18393                    if (mbMessage != null) {
18394                            return mbMessage;
18395                    }
18396    
18397                    StringBundler msg = new StringBundler(10);
18398    
18399                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18400    
18401                    msg.append("groupId=");
18402                    msg.append(groupId);
18403    
18404                    msg.append(", categoryId=");
18405                    msg.append(categoryId);
18406    
18407                    msg.append(", threadId=");
18408                    msg.append(threadId);
18409    
18410                    msg.append(", status=");
18411                    msg.append(status);
18412    
18413                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18414    
18415                    throw new NoSuchMessageException(msg.toString());
18416            }
18417    
18418            /**
18419             * Returns the first message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18420             *
18421             * @param groupId the group ID
18422             * @param categoryId the category ID
18423             * @param threadId the thread ID
18424             * @param status the status
18425             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18426             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18427             * @throws SystemException if a system exception occurred
18428             */
18429            public MBMessage fetchByG_C_T_S_First(long groupId, long categoryId,
18430                    long threadId, int status, OrderByComparator orderByComparator)
18431                    throws SystemException {
18432                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
18433                                    status, 0, 1, orderByComparator);
18434    
18435                    if (!list.isEmpty()) {
18436                            return list.get(0);
18437                    }
18438    
18439                    return null;
18440            }
18441    
18442            /**
18443             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18444             *
18445             * @param groupId the group ID
18446             * @param categoryId the category ID
18447             * @param threadId the thread ID
18448             * @param status the status
18449             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18450             * @return the last matching message-boards message
18451             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
18452             * @throws SystemException if a system exception occurred
18453             */
18454            public MBMessage findByG_C_T_S_Last(long groupId, long categoryId,
18455                    long threadId, int status, OrderByComparator orderByComparator)
18456                    throws NoSuchMessageException, SystemException {
18457                    MBMessage mbMessage = fetchByG_C_T_S_Last(groupId, categoryId,
18458                                    threadId, status, orderByComparator);
18459    
18460                    if (mbMessage != null) {
18461                            return mbMessage;
18462                    }
18463    
18464                    StringBundler msg = new StringBundler(10);
18465    
18466                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
18467    
18468                    msg.append("groupId=");
18469                    msg.append(groupId);
18470    
18471                    msg.append(", categoryId=");
18472                    msg.append(categoryId);
18473    
18474                    msg.append(", threadId=");
18475                    msg.append(threadId);
18476    
18477                    msg.append(", status=");
18478                    msg.append(status);
18479    
18480                    msg.append(StringPool.CLOSE_CURLY_BRACE);
18481    
18482                    throw new NoSuchMessageException(msg.toString());
18483            }
18484    
18485            /**
18486             * Returns the last message-boards message in the ordered set where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
18487             *
18488             * @param groupId the group ID
18489             * @param categoryId the category ID
18490             * @param threadId the thread ID
18491             * @param status the status
18492             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18493             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
18494             * @throws SystemException if a system exception occurred
18495             */
18496            public MBMessage fetchByG_C_T_S_Last(long groupId, long categoryId,
18497                    long threadId, int status, OrderByComparator orderByComparator)
18498                    throws SystemException {
18499                    int count = countByG_C_T_S(groupId, categoryId, threadId, status);
18500    
18501                    List<MBMessage> list = findByG_C_T_S(groupId, categoryId, threadId,
18502                                    status, count - 1, count, orderByComparator);
18503    
18504                    if (!list.isEmpty()) {
18505                            return list.get(0);
18506                    }
18507    
18508                    return null;
18509            }
18510    
18511            /**
18512             * 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;.
18513             *
18514             * @param messageId the primary key of the current message-boards message
18515             * @param groupId the group ID
18516             * @param categoryId the category ID
18517             * @param threadId the thread ID
18518             * @param status the status
18519             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18520             * @return the previous, current, and next message-boards message
18521             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18522             * @throws SystemException if a system exception occurred
18523             */
18524            public MBMessage[] findByG_C_T_S_PrevAndNext(long messageId, long groupId,
18525                    long categoryId, long threadId, int status,
18526                    OrderByComparator orderByComparator)
18527                    throws NoSuchMessageException, SystemException {
18528                    MBMessage mbMessage = findByPrimaryKey(messageId);
18529    
18530                    Session session = null;
18531    
18532                    try {
18533                            session = openSession();
18534    
18535                            MBMessage[] array = new MBMessageImpl[3];
18536    
18537                            array[0] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
18538                                            categoryId, threadId, status, orderByComparator, true);
18539    
18540                            array[1] = mbMessage;
18541    
18542                            array[2] = getByG_C_T_S_PrevAndNext(session, mbMessage, groupId,
18543                                            categoryId, threadId, status, orderByComparator, false);
18544    
18545                            return array;
18546                    }
18547                    catch (Exception e) {
18548                            throw processException(e);
18549                    }
18550                    finally {
18551                            closeSession(session);
18552                    }
18553            }
18554    
18555            protected MBMessage getByG_C_T_S_PrevAndNext(Session session,
18556                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
18557                    int status, OrderByComparator orderByComparator, boolean previous) {
18558                    StringBundler query = null;
18559    
18560                    if (orderByComparator != null) {
18561                            query = new StringBundler(6 +
18562                                            (orderByComparator.getOrderByFields().length * 6));
18563                    }
18564                    else {
18565                            query = new StringBundler(3);
18566                    }
18567    
18568                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
18569    
18570                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18571    
18572                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18573    
18574                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18575    
18576                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18577    
18578                    if (orderByComparator != null) {
18579                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18580    
18581                            if (orderByConditionFields.length > 0) {
18582                                    query.append(WHERE_AND);
18583                            }
18584    
18585                            for (int i = 0; i < orderByConditionFields.length; i++) {
18586                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18587                                    query.append(orderByConditionFields[i]);
18588    
18589                                    if ((i + 1) < orderByConditionFields.length) {
18590                                            if (orderByComparator.isAscending() ^ previous) {
18591                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18592                                            }
18593                                            else {
18594                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18595                                            }
18596                                    }
18597                                    else {
18598                                            if (orderByComparator.isAscending() ^ previous) {
18599                                                    query.append(WHERE_GREATER_THAN);
18600                                            }
18601                                            else {
18602                                                    query.append(WHERE_LESSER_THAN);
18603                                            }
18604                                    }
18605                            }
18606    
18607                            query.append(ORDER_BY_CLAUSE);
18608    
18609                            String[] orderByFields = orderByComparator.getOrderByFields();
18610    
18611                            for (int i = 0; i < orderByFields.length; i++) {
18612                                    query.append(_ORDER_BY_ENTITY_ALIAS);
18613                                    query.append(orderByFields[i]);
18614    
18615                                    if ((i + 1) < orderByFields.length) {
18616                                            if (orderByComparator.isAscending() ^ previous) {
18617                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18618                                            }
18619                                            else {
18620                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18621                                            }
18622                                    }
18623                                    else {
18624                                            if (orderByComparator.isAscending() ^ previous) {
18625                                                    query.append(ORDER_BY_ASC);
18626                                            }
18627                                            else {
18628                                                    query.append(ORDER_BY_DESC);
18629                                            }
18630                                    }
18631                            }
18632                    }
18633                    else {
18634                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18635                    }
18636    
18637                    String sql = query.toString();
18638    
18639                    Query q = session.createQuery(sql);
18640    
18641                    q.setFirstResult(0);
18642                    q.setMaxResults(2);
18643    
18644                    QueryPos qPos = QueryPos.getInstance(q);
18645    
18646                    qPos.add(groupId);
18647    
18648                    qPos.add(categoryId);
18649    
18650                    qPos.add(threadId);
18651    
18652                    qPos.add(status);
18653    
18654                    if (orderByComparator != null) {
18655                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
18656    
18657                            for (Object value : values) {
18658                                    qPos.add(value);
18659                            }
18660                    }
18661    
18662                    List<MBMessage> list = q.list();
18663    
18664                    if (list.size() == 2) {
18665                            return list.get(1);
18666                    }
18667                    else {
18668                            return null;
18669                    }
18670            }
18671    
18672            /**
18673             * 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;.
18674             *
18675             * @param groupId the group ID
18676             * @param categoryId the category ID
18677             * @param threadId the thread ID
18678             * @param status the status
18679             * @return the matching message-boards messages that the user has permission to view
18680             * @throws SystemException if a system exception occurred
18681             */
18682            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
18683                    long threadId, int status) throws SystemException {
18684                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
18685                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
18686            }
18687    
18688            /**
18689             * 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;.
18690             *
18691             * <p>
18692             * 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.
18693             * </p>
18694             *
18695             * @param groupId the group ID
18696             * @param categoryId the category ID
18697             * @param threadId the thread ID
18698             * @param status the status
18699             * @param start the lower bound of the range of message-boards messages
18700             * @param end the upper bound of the range of message-boards messages (not inclusive)
18701             * @return the range of matching message-boards messages that the user has permission to view
18702             * @throws SystemException if a system exception occurred
18703             */
18704            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
18705                    long threadId, int status, int start, int end)
18706                    throws SystemException {
18707                    return filterFindByG_C_T_S(groupId, categoryId, threadId, status,
18708                            start, end, null);
18709            }
18710    
18711            /**
18712             * 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;.
18713             *
18714             * <p>
18715             * 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.
18716             * </p>
18717             *
18718             * @param groupId the group ID
18719             * @param categoryId the category ID
18720             * @param threadId the thread ID
18721             * @param status the status
18722             * @param start the lower bound of the range of message-boards messages
18723             * @param end the upper bound of the range of message-boards messages (not inclusive)
18724             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
18725             * @return the ordered range of matching message-boards messages that the user has permission to view
18726             * @throws SystemException if a system exception occurred
18727             */
18728            public List<MBMessage> filterFindByG_C_T_S(long groupId, long categoryId,
18729                    long threadId, int status, int start, int end,
18730                    OrderByComparator orderByComparator) throws SystemException {
18731                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18732                            return findByG_C_T_S(groupId, categoryId, threadId, status, start,
18733                                    end, orderByComparator);
18734                    }
18735    
18736                    StringBundler query = null;
18737    
18738                    if (orderByComparator != null) {
18739                            query = new StringBundler(6 +
18740                                            (orderByComparator.getOrderByFields().length * 3));
18741                    }
18742                    else {
18743                            query = new StringBundler(6);
18744                    }
18745    
18746                    if (getDB().isSupportsInlineDistinct()) {
18747                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
18748                    }
18749                    else {
18750                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
18751                    }
18752    
18753                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18754    
18755                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18756    
18757                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18758    
18759                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18760    
18761                    if (!getDB().isSupportsInlineDistinct()) {
18762                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
18763                    }
18764    
18765                    if (orderByComparator != null) {
18766                            if (getDB().isSupportsInlineDistinct()) {
18767                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
18768                                            orderByComparator, true);
18769                            }
18770                            else {
18771                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
18772                                            orderByComparator, true);
18773                            }
18774                    }
18775                    else {
18776                            if (getDB().isSupportsInlineDistinct()) {
18777                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18778                            }
18779                            else {
18780                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18781                            }
18782                    }
18783    
18784                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18785                                    MBMessage.class.getName(),
18786                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18787    
18788                    Session session = null;
18789    
18790                    try {
18791                            session = openSession();
18792    
18793                            SQLQuery q = session.createSQLQuery(sql);
18794    
18795                            if (getDB().isSupportsInlineDistinct()) {
18796                                    q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18797                            }
18798                            else {
18799                                    q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18800                            }
18801    
18802                            QueryPos qPos = QueryPos.getInstance(q);
18803    
18804                            qPos.add(groupId);
18805    
18806                            qPos.add(categoryId);
18807    
18808                            qPos.add(threadId);
18809    
18810                            qPos.add(status);
18811    
18812                            return (List<MBMessage>)QueryUtil.list(q, getDialect(), start, end);
18813                    }
18814                    catch (Exception e) {
18815                            throw processException(e);
18816                    }
18817                    finally {
18818                            closeSession(session);
18819                    }
18820            }
18821    
18822            /**
18823             * 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;.
18824             *
18825             * @param messageId the primary key of the current message-boards message
18826             * @param groupId the group ID
18827             * @param categoryId the category ID
18828             * @param threadId the thread ID
18829             * @param status the status
18830             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
18831             * @return the previous, current, and next message-boards message
18832             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
18833             * @throws SystemException if a system exception occurred
18834             */
18835            public MBMessage[] filterFindByG_C_T_S_PrevAndNext(long messageId,
18836                    long groupId, long categoryId, long threadId, int status,
18837                    OrderByComparator orderByComparator)
18838                    throws NoSuchMessageException, SystemException {
18839                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
18840                            return findByG_C_T_S_PrevAndNext(messageId, groupId, categoryId,
18841                                    threadId, status, orderByComparator);
18842                    }
18843    
18844                    MBMessage mbMessage = findByPrimaryKey(messageId);
18845    
18846                    Session session = null;
18847    
18848                    try {
18849                            session = openSession();
18850    
18851                            MBMessage[] array = new MBMessageImpl[3];
18852    
18853                            array[0] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
18854                                            groupId, categoryId, threadId, status, orderByComparator,
18855                                            true);
18856    
18857                            array[1] = mbMessage;
18858    
18859                            array[2] = filterGetByG_C_T_S_PrevAndNext(session, mbMessage,
18860                                            groupId, categoryId, threadId, status, orderByComparator,
18861                                            false);
18862    
18863                            return array;
18864                    }
18865                    catch (Exception e) {
18866                            throw processException(e);
18867                    }
18868                    finally {
18869                            closeSession(session);
18870                    }
18871            }
18872    
18873            protected MBMessage filterGetByG_C_T_S_PrevAndNext(Session session,
18874                    MBMessage mbMessage, long groupId, long categoryId, long threadId,
18875                    int status, OrderByComparator orderByComparator, boolean previous) {
18876                    StringBundler query = null;
18877    
18878                    if (orderByComparator != null) {
18879                            query = new StringBundler(6 +
18880                                            (orderByComparator.getOrderByFields().length * 6));
18881                    }
18882                    else {
18883                            query = new StringBundler(3);
18884                    }
18885    
18886                    if (getDB().isSupportsInlineDistinct()) {
18887                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_WHERE);
18888                    }
18889                    else {
18890                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1);
18891                    }
18892    
18893                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
18894    
18895                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
18896    
18897                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
18898    
18899                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
18900    
18901                    if (!getDB().isSupportsInlineDistinct()) {
18902                            query.append(_FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2);
18903                    }
18904    
18905                    if (orderByComparator != null) {
18906                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
18907    
18908                            if (orderByConditionFields.length > 0) {
18909                                    query.append(WHERE_AND);
18910                            }
18911    
18912                            for (int i = 0; i < orderByConditionFields.length; i++) {
18913                                    if (getDB().isSupportsInlineDistinct()) {
18914                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18915                                    }
18916                                    else {
18917                                            query.append(_ORDER_BY_ENTITY_TABLE);
18918                                    }
18919    
18920                                    query.append(orderByConditionFields[i]);
18921    
18922                                    if ((i + 1) < orderByConditionFields.length) {
18923                                            if (orderByComparator.isAscending() ^ previous) {
18924                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
18925                                            }
18926                                            else {
18927                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
18928                                            }
18929                                    }
18930                                    else {
18931                                            if (orderByComparator.isAscending() ^ previous) {
18932                                                    query.append(WHERE_GREATER_THAN);
18933                                            }
18934                                            else {
18935                                                    query.append(WHERE_LESSER_THAN);
18936                                            }
18937                                    }
18938                            }
18939    
18940                            query.append(ORDER_BY_CLAUSE);
18941    
18942                            String[] orderByFields = orderByComparator.getOrderByFields();
18943    
18944                            for (int i = 0; i < orderByFields.length; i++) {
18945                                    if (getDB().isSupportsInlineDistinct()) {
18946                                            query.append(_ORDER_BY_ENTITY_ALIAS);
18947                                    }
18948                                    else {
18949                                            query.append(_ORDER_BY_ENTITY_TABLE);
18950                                    }
18951    
18952                                    query.append(orderByFields[i]);
18953    
18954                                    if ((i + 1) < orderByFields.length) {
18955                                            if (orderByComparator.isAscending() ^ previous) {
18956                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
18957                                            }
18958                                            else {
18959                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
18960                                            }
18961                                    }
18962                                    else {
18963                                            if (orderByComparator.isAscending() ^ previous) {
18964                                                    query.append(ORDER_BY_ASC);
18965                                            }
18966                                            else {
18967                                                    query.append(ORDER_BY_DESC);
18968                                            }
18969                                    }
18970                            }
18971                    }
18972                    else {
18973                            if (getDB().isSupportsInlineDistinct()) {
18974                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
18975                            }
18976                            else {
18977                                    query.append(MBMessageModelImpl.ORDER_BY_SQL);
18978                            }
18979                    }
18980    
18981                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
18982                                    MBMessage.class.getName(),
18983                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
18984    
18985                    SQLQuery q = session.createSQLQuery(sql);
18986    
18987                    q.setFirstResult(0);
18988                    q.setMaxResults(2);
18989    
18990                    if (getDB().isSupportsInlineDistinct()) {
18991                            q.addEntity(_FILTER_ENTITY_ALIAS, MBMessageImpl.class);
18992                    }
18993                    else {
18994                            q.addEntity(_FILTER_ENTITY_TABLE, MBMessageImpl.class);
18995                    }
18996    
18997                    QueryPos qPos = QueryPos.getInstance(q);
18998    
18999                    qPos.add(groupId);
19000    
19001                    qPos.add(categoryId);
19002    
19003                    qPos.add(threadId);
19004    
19005                    qPos.add(status);
19006    
19007                    if (orderByComparator != null) {
19008                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
19009    
19010                            for (Object value : values) {
19011                                    qPos.add(value);
19012                            }
19013                    }
19014    
19015                    List<MBMessage> list = q.list();
19016    
19017                    if (list.size() == 2) {
19018                            return list.get(1);
19019                    }
19020                    else {
19021                            return null;
19022                    }
19023            }
19024    
19025            /**
19026             * Removes all the message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63; from the database.
19027             *
19028             * @param groupId the group ID
19029             * @param categoryId the category ID
19030             * @param threadId the thread ID
19031             * @param status the status
19032             * @throws SystemException if a system exception occurred
19033             */
19034            public void removeByG_C_T_S(long groupId, long categoryId, long threadId,
19035                    int status) throws SystemException {
19036                    for (MBMessage mbMessage : findByG_C_T_S(groupId, categoryId, threadId,
19037                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
19038                            remove(mbMessage);
19039                    }
19040            }
19041    
19042            /**
19043             * Returns the number of message-boards messages where groupId = &#63; and categoryId = &#63; and threadId = &#63; and status = &#63;.
19044             *
19045             * @param groupId the group ID
19046             * @param categoryId the category ID
19047             * @param threadId the thread ID
19048             * @param status the status
19049             * @return the number of matching message-boards messages
19050             * @throws SystemException if a system exception occurred
19051             */
19052            public int countByG_C_T_S(long groupId, long categoryId, long threadId,
19053                    int status) throws SystemException {
19054                    FinderPath finderPath = FINDER_PATH_COUNT_BY_G_C_T_S;
19055    
19056                    Object[] finderArgs = new Object[] { groupId, categoryId, threadId, status };
19057    
19058                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
19059                                    this);
19060    
19061                    if (count == null) {
19062                            StringBundler query = new StringBundler(5);
19063    
19064                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
19065    
19066                            query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
19067    
19068                            query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
19069    
19070                            query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
19071    
19072                            query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
19073    
19074                            String sql = query.toString();
19075    
19076                            Session session = null;
19077    
19078                            try {
19079                                    session = openSession();
19080    
19081                                    Query q = session.createQuery(sql);
19082    
19083                                    QueryPos qPos = QueryPos.getInstance(q);
19084    
19085                                    qPos.add(groupId);
19086    
19087                                    qPos.add(categoryId);
19088    
19089                                    qPos.add(threadId);
19090    
19091                                    qPos.add(status);
19092    
19093                                    count = (Long)q.uniqueResult();
19094    
19095                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
19096                            }
19097                            catch (Exception e) {
19098                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19099    
19100                                    throw processException(e);
19101                            }
19102                            finally {
19103                                    closeSession(session);
19104                            }
19105                    }
19106    
19107                    return count.intValue();
19108            }
19109    
19110            /**
19111             * 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;.
19112             *
19113             * @param groupId the group ID
19114             * @param categoryId the category ID
19115             * @param threadId the thread ID
19116             * @param status the status
19117             * @return the number of matching message-boards messages that the user has permission to view
19118             * @throws SystemException if a system exception occurred
19119             */
19120            public int filterCountByG_C_T_S(long groupId, long categoryId,
19121                    long threadId, int status) throws SystemException {
19122                    if (!InlineSQLHelperUtil.isEnabled(groupId)) {
19123                            return countByG_C_T_S(groupId, categoryId, threadId, status);
19124                    }
19125    
19126                    StringBundler query = new StringBundler(5);
19127    
19128                    query.append(_FILTER_SQL_COUNT_MBMESSAGE_WHERE);
19129    
19130                    query.append(_FINDER_COLUMN_G_C_T_S_GROUPID_2);
19131    
19132                    query.append(_FINDER_COLUMN_G_C_T_S_CATEGORYID_2);
19133    
19134                    query.append(_FINDER_COLUMN_G_C_T_S_THREADID_2);
19135    
19136                    query.append(_FINDER_COLUMN_G_C_T_S_STATUS_2);
19137    
19138                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
19139                                    MBMessage.class.getName(),
19140                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
19141    
19142                    Session session = null;
19143    
19144                    try {
19145                            session = openSession();
19146    
19147                            SQLQuery q = session.createSQLQuery(sql);
19148    
19149                            q.addScalar(COUNT_COLUMN_NAME,
19150                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
19151    
19152                            QueryPos qPos = QueryPos.getInstance(q);
19153    
19154                            qPos.add(groupId);
19155    
19156                            qPos.add(categoryId);
19157    
19158                            qPos.add(threadId);
19159    
19160                            qPos.add(status);
19161    
19162                            Long count = (Long)q.uniqueResult();
19163    
19164                            return count.intValue();
19165                    }
19166                    catch (Exception e) {
19167                            throw processException(e);
19168                    }
19169                    finally {
19170                            closeSession(session);
19171                    }
19172            }
19173    
19174            private static final String _FINDER_COLUMN_G_C_T_S_GROUPID_2 = "mbMessage.groupId = ? AND ";
19175            private static final String _FINDER_COLUMN_G_C_T_S_CATEGORYID_2 = "mbMessage.categoryId = ? AND ";
19176            private static final String _FINDER_COLUMN_G_C_T_S_THREADID_2 = "mbMessage.threadId = ? AND ";
19177            private static final String _FINDER_COLUMN_G_C_T_S_STATUS_2 = "mbMessage.status = ?";
19178            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19179                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
19180                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByU_C_C_S",
19181                            new String[] {
19182                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
19183                                    Integer.class.getName(),
19184                                    
19185                            Integer.class.getName(), Integer.class.getName(),
19186                                    OrderByComparator.class.getName()
19187                            });
19188            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S =
19189                    new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19190                            MBMessageModelImpl.FINDER_CACHE_ENABLED, MBMessageImpl.class,
19191                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByU_C_C_S",
19192                            new String[] {
19193                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
19194                                    Integer.class.getName()
19195                            },
19196                            MBMessageModelImpl.USERID_COLUMN_BITMASK |
19197                            MBMessageModelImpl.CLASSNAMEID_COLUMN_BITMASK |
19198                            MBMessageModelImpl.CLASSPK_COLUMN_BITMASK |
19199                            MBMessageModelImpl.STATUS_COLUMN_BITMASK |
19200                            MBMessageModelImpl.CREATEDATE_COLUMN_BITMASK);
19201            public static final FinderPath FINDER_PATH_COUNT_BY_U_C_C_S = new FinderPath(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19202                            MBMessageModelImpl.FINDER_CACHE_ENABLED, Long.class,
19203                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByU_C_C_S",
19204                            new String[] {
19205                                    Long.class.getName(), Long.class.getName(), Long.class.getName(),
19206                                    Integer.class.getName()
19207                            });
19208    
19209            /**
19210             * Returns all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19211             *
19212             * @param userId the user ID
19213             * @param classNameId the class name ID
19214             * @param classPK the class p k
19215             * @param status the status
19216             * @return the matching message-boards messages
19217             * @throws SystemException if a system exception occurred
19218             */
19219            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
19220                    long classPK, int status) throws SystemException {
19221                    return findByU_C_C_S(userId, classNameId, classPK, status,
19222                            QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
19223            }
19224    
19225            /**
19226             * Returns a range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19227             *
19228             * <p>
19229             * 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.
19230             * </p>
19231             *
19232             * @param userId the user ID
19233             * @param classNameId the class name ID
19234             * @param classPK the class p k
19235             * @param status the status
19236             * @param start the lower bound of the range of message-boards messages
19237             * @param end the upper bound of the range of message-boards messages (not inclusive)
19238             * @return the range of matching message-boards messages
19239             * @throws SystemException if a system exception occurred
19240             */
19241            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
19242                    long classPK, int status, int start, int end) throws SystemException {
19243                    return findByU_C_C_S(userId, classNameId, classPK, status, start, end,
19244                            null);
19245            }
19246    
19247            /**
19248             * Returns an ordered range of all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19249             *
19250             * <p>
19251             * 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.
19252             * </p>
19253             *
19254             * @param userId the user ID
19255             * @param classNameId the class name ID
19256             * @param classPK the class p k
19257             * @param status the status
19258             * @param start the lower bound of the range of message-boards messages
19259             * @param end the upper bound of the range of message-boards messages (not inclusive)
19260             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
19261             * @return the ordered range of matching message-boards messages
19262             * @throws SystemException if a system exception occurred
19263             */
19264            public List<MBMessage> findByU_C_C_S(long userId, long classNameId,
19265                    long classPK, int status, int start, int end,
19266                    OrderByComparator orderByComparator) throws SystemException {
19267                    boolean pagination = true;
19268                    FinderPath finderPath = null;
19269                    Object[] finderArgs = null;
19270    
19271                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
19272                                    (orderByComparator == null)) {
19273                            pagination = false;
19274                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S;
19275                            finderArgs = new Object[] { userId, classNameId, classPK, status };
19276                    }
19277                    else {
19278                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_U_C_C_S;
19279                            finderArgs = new Object[] {
19280                                            userId, classNameId, classPK, status,
19281                                            
19282                                            start, end, orderByComparator
19283                                    };
19284                    }
19285    
19286                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
19287                                    finderArgs, this);
19288    
19289                    if ((list != null) && !list.isEmpty()) {
19290                            for (MBMessage mbMessage : list) {
19291                                    if ((userId != mbMessage.getUserId()) ||
19292                                                    (classNameId != mbMessage.getClassNameId()) ||
19293                                                    (classPK != mbMessage.getClassPK()) ||
19294                                                    (status != mbMessage.getStatus())) {
19295                                            list = null;
19296    
19297                                            break;
19298                                    }
19299                            }
19300                    }
19301    
19302                    if (list == null) {
19303                            StringBundler query = null;
19304    
19305                            if (orderByComparator != null) {
19306                                    query = new StringBundler(6 +
19307                                                    (orderByComparator.getOrderByFields().length * 3));
19308                            }
19309                            else {
19310                                    query = new StringBundler(6);
19311                            }
19312    
19313                            query.append(_SQL_SELECT_MBMESSAGE_WHERE);
19314    
19315                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
19316    
19317                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
19318    
19319                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
19320    
19321                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
19322    
19323                            if (orderByComparator != null) {
19324                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
19325                                            orderByComparator);
19326                            }
19327                            else
19328                             if (pagination) {
19329                                    query.append(MBMessageModelImpl.ORDER_BY_JPQL);
19330                            }
19331    
19332                            String sql = query.toString();
19333    
19334                            Session session = null;
19335    
19336                            try {
19337                                    session = openSession();
19338    
19339                                    Query q = session.createQuery(sql);
19340    
19341                                    QueryPos qPos = QueryPos.getInstance(q);
19342    
19343                                    qPos.add(userId);
19344    
19345                                    qPos.add(classNameId);
19346    
19347                                    qPos.add(classPK);
19348    
19349                                    qPos.add(status);
19350    
19351                                    if (!pagination) {
19352                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19353                                                            start, end, false);
19354    
19355                                            Collections.sort(list);
19356    
19357                                            list = new UnmodifiableList<MBMessage>(list);
19358                                    }
19359                                    else {
19360                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
19361                                                            start, end);
19362                                    }
19363    
19364                                    cacheResult(list);
19365    
19366                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
19367                            }
19368                            catch (Exception e) {
19369                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19370    
19371                                    throw processException(e);
19372                            }
19373                            finally {
19374                                    closeSession(session);
19375                            }
19376                    }
19377    
19378                    return list;
19379            }
19380    
19381            /**
19382             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19383             *
19384             * @param userId the user ID
19385             * @param classNameId the class name ID
19386             * @param classPK the class p k
19387             * @param status the status
19388             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19389             * @return the first matching message-boards message
19390             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
19391             * @throws SystemException if a system exception occurred
19392             */
19393            public MBMessage findByU_C_C_S_First(long userId, long classNameId,
19394                    long classPK, int status, OrderByComparator orderByComparator)
19395                    throws NoSuchMessageException, SystemException {
19396                    MBMessage mbMessage = fetchByU_C_C_S_First(userId, classNameId,
19397                                    classPK, status, orderByComparator);
19398    
19399                    if (mbMessage != null) {
19400                            return mbMessage;
19401                    }
19402    
19403                    StringBundler msg = new StringBundler(10);
19404    
19405                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19406    
19407                    msg.append("userId=");
19408                    msg.append(userId);
19409    
19410                    msg.append(", classNameId=");
19411                    msg.append(classNameId);
19412    
19413                    msg.append(", classPK=");
19414                    msg.append(classPK);
19415    
19416                    msg.append(", status=");
19417                    msg.append(status);
19418    
19419                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19420    
19421                    throw new NoSuchMessageException(msg.toString());
19422            }
19423    
19424            /**
19425             * Returns the first message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19426             *
19427             * @param userId the user ID
19428             * @param classNameId the class name ID
19429             * @param classPK the class p k
19430             * @param status the status
19431             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19432             * @return the first matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
19433             * @throws SystemException if a system exception occurred
19434             */
19435            public MBMessage fetchByU_C_C_S_First(long userId, long classNameId,
19436                    long classPK, int status, OrderByComparator orderByComparator)
19437                    throws SystemException {
19438                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
19439                                    status, 0, 1, orderByComparator);
19440    
19441                    if (!list.isEmpty()) {
19442                            return list.get(0);
19443                    }
19444    
19445                    return null;
19446            }
19447    
19448            /**
19449             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19450             *
19451             * @param userId the user ID
19452             * @param classNameId the class name ID
19453             * @param classPK the class p k
19454             * @param status the status
19455             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19456             * @return the last matching message-boards message
19457             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a matching message-boards message could not be found
19458             * @throws SystemException if a system exception occurred
19459             */
19460            public MBMessage findByU_C_C_S_Last(long userId, long classNameId,
19461                    long classPK, int status, OrderByComparator orderByComparator)
19462                    throws NoSuchMessageException, SystemException {
19463                    MBMessage mbMessage = fetchByU_C_C_S_Last(userId, classNameId, classPK,
19464                                    status, orderByComparator);
19465    
19466                    if (mbMessage != null) {
19467                            return mbMessage;
19468                    }
19469    
19470                    StringBundler msg = new StringBundler(10);
19471    
19472                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
19473    
19474                    msg.append("userId=");
19475                    msg.append(userId);
19476    
19477                    msg.append(", classNameId=");
19478                    msg.append(classNameId);
19479    
19480                    msg.append(", classPK=");
19481                    msg.append(classPK);
19482    
19483                    msg.append(", status=");
19484                    msg.append(status);
19485    
19486                    msg.append(StringPool.CLOSE_CURLY_BRACE);
19487    
19488                    throw new NoSuchMessageException(msg.toString());
19489            }
19490    
19491            /**
19492             * Returns the last message-boards message in the ordered set where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19493             *
19494             * @param userId the user ID
19495             * @param classNameId the class name ID
19496             * @param classPK the class p k
19497             * @param status the status
19498             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19499             * @return the last matching message-boards message, or <code>null</code> if a matching message-boards message could not be found
19500             * @throws SystemException if a system exception occurred
19501             */
19502            public MBMessage fetchByU_C_C_S_Last(long userId, long classNameId,
19503                    long classPK, int status, OrderByComparator orderByComparator)
19504                    throws SystemException {
19505                    int count = countByU_C_C_S(userId, classNameId, classPK, status);
19506    
19507                    List<MBMessage> list = findByU_C_C_S(userId, classNameId, classPK,
19508                                    status, count - 1, count, orderByComparator);
19509    
19510                    if (!list.isEmpty()) {
19511                            return list.get(0);
19512                    }
19513    
19514                    return null;
19515            }
19516    
19517            /**
19518             * 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;.
19519             *
19520             * @param messageId the primary key of the current message-boards message
19521             * @param userId the user ID
19522             * @param classNameId the class name ID
19523             * @param classPK the class p k
19524             * @param status the status
19525             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
19526             * @return the previous, current, and next message-boards message
19527             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19528             * @throws SystemException if a system exception occurred
19529             */
19530            public MBMessage[] findByU_C_C_S_PrevAndNext(long messageId, long userId,
19531                    long classNameId, long classPK, int status,
19532                    OrderByComparator orderByComparator)
19533                    throws NoSuchMessageException, SystemException {
19534                    MBMessage mbMessage = findByPrimaryKey(messageId);
19535    
19536                    Session session = null;
19537    
19538                    try {
19539                            session = openSession();
19540    
19541                            MBMessage[] array = new MBMessageImpl[3];
19542    
19543                            array[0] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
19544                                            classNameId, classPK, status, orderByComparator, true);
19545    
19546                            array[1] = mbMessage;
19547    
19548                            array[2] = getByU_C_C_S_PrevAndNext(session, mbMessage, userId,
19549                                            classNameId, classPK, status, orderByComparator, false);
19550    
19551                            return array;
19552                    }
19553                    catch (Exception e) {
19554                            throw processException(e);
19555                    }
19556                    finally {
19557                            closeSession(session);
19558                    }
19559            }
19560    
19561            protected MBMessage getByU_C_C_S_PrevAndNext(Session session,
19562                    MBMessage mbMessage, long userId, long classNameId, long classPK,
19563                    int status, OrderByComparator orderByComparator, boolean previous) {
19564                    StringBundler query = null;
19565    
19566                    if (orderByComparator != null) {
19567                            query = new StringBundler(6 +
19568                                            (orderByComparator.getOrderByFields().length * 6));
19569                    }
19570                    else {
19571                            query = new StringBundler(3);
19572                    }
19573    
19574                    query.append(_SQL_SELECT_MBMESSAGE_WHERE);
19575    
19576                    query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
19577    
19578                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
19579    
19580                    query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
19581    
19582                    query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
19583    
19584                    if (orderByComparator != null) {
19585                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
19586    
19587                            if (orderByConditionFields.length > 0) {
19588                                    query.append(WHERE_AND);
19589                            }
19590    
19591                            for (int i = 0; i < orderByConditionFields.length; i++) {
19592                                    query.append(_ORDER_BY_ENTITY_ALIAS);
19593                                    query.append(orderByConditionFields[i]);
19594    
19595                                    if ((i + 1) < orderByConditionFields.length) {
19596                                            if (orderByComparator.isAscending() ^ previous) {
19597                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
19598                                            }
19599                                            else {
19600                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
19601                                            }
19602                                    }
19603                                    else {
19604                                            if (orderByComparator.isAscending() ^ previous) {
19605                                                    query.append(WHERE_GREATER_THAN);
19606                                            }
19607                                            else {
19608                                                    query.append(WHERE_LESSER_THAN);
19609                                            }
19610                                    }
19611                            }
19612    
19613                            query.append(ORDER_BY_CLAUSE);
19614    
19615                            String[] orderByFields = orderByComparator.getOrderByFields();
19616    
19617                            for (int i = 0; i < orderByFields.length; i++) {
19618                                    query.append(_ORDER_BY_ENTITY_ALIAS);
19619                                    query.append(orderByFields[i]);
19620    
19621                                    if ((i + 1) < orderByFields.length) {
19622                                            if (orderByComparator.isAscending() ^ previous) {
19623                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
19624                                            }
19625                                            else {
19626                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
19627                                            }
19628                                    }
19629                                    else {
19630                                            if (orderByComparator.isAscending() ^ previous) {
19631                                                    query.append(ORDER_BY_ASC);
19632                                            }
19633                                            else {
19634                                                    query.append(ORDER_BY_DESC);
19635                                            }
19636                                    }
19637                            }
19638                    }
19639                    else {
19640                            query.append(MBMessageModelImpl.ORDER_BY_JPQL);
19641                    }
19642    
19643                    String sql = query.toString();
19644    
19645                    Query q = session.createQuery(sql);
19646    
19647                    q.setFirstResult(0);
19648                    q.setMaxResults(2);
19649    
19650                    QueryPos qPos = QueryPos.getInstance(q);
19651    
19652                    qPos.add(userId);
19653    
19654                    qPos.add(classNameId);
19655    
19656                    qPos.add(classPK);
19657    
19658                    qPos.add(status);
19659    
19660                    if (orderByComparator != null) {
19661                            Object[] values = orderByComparator.getOrderByConditionValues(mbMessage);
19662    
19663                            for (Object value : values) {
19664                                    qPos.add(value);
19665                            }
19666                    }
19667    
19668                    List<MBMessage> list = q.list();
19669    
19670                    if (list.size() == 2) {
19671                            return list.get(1);
19672                    }
19673                    else {
19674                            return null;
19675                    }
19676            }
19677    
19678            /**
19679             * Removes all the message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63; from the database.
19680             *
19681             * @param userId the user ID
19682             * @param classNameId the class name ID
19683             * @param classPK the class p k
19684             * @param status the status
19685             * @throws SystemException if a system exception occurred
19686             */
19687            public void removeByU_C_C_S(long userId, long classNameId, long classPK,
19688                    int status) throws SystemException {
19689                    for (MBMessage mbMessage : findByU_C_C_S(userId, classNameId, classPK,
19690                                    status, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
19691                            remove(mbMessage);
19692                    }
19693            }
19694    
19695            /**
19696             * Returns the number of message-boards messages where userId = &#63; and classNameId = &#63; and classPK = &#63; and status = &#63;.
19697             *
19698             * @param userId the user ID
19699             * @param classNameId the class name ID
19700             * @param classPK the class p k
19701             * @param status the status
19702             * @return the number of matching message-boards messages
19703             * @throws SystemException if a system exception occurred
19704             */
19705            public int countByU_C_C_S(long userId, long classNameId, long classPK,
19706                    int status) throws SystemException {
19707                    FinderPath finderPath = FINDER_PATH_COUNT_BY_U_C_C_S;
19708    
19709                    Object[] finderArgs = new Object[] { userId, classNameId, classPK, status };
19710    
19711                    Long count = (Long)FinderCacheUtil.getResult(finderPath, finderArgs,
19712                                    this);
19713    
19714                    if (count == null) {
19715                            StringBundler query = new StringBundler(5);
19716    
19717                            query.append(_SQL_COUNT_MBMESSAGE_WHERE);
19718    
19719                            query.append(_FINDER_COLUMN_U_C_C_S_USERID_2);
19720    
19721                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2);
19722    
19723                            query.append(_FINDER_COLUMN_U_C_C_S_CLASSPK_2);
19724    
19725                            query.append(_FINDER_COLUMN_U_C_C_S_STATUS_2);
19726    
19727                            String sql = query.toString();
19728    
19729                            Session session = null;
19730    
19731                            try {
19732                                    session = openSession();
19733    
19734                                    Query q = session.createQuery(sql);
19735    
19736                                    QueryPos qPos = QueryPos.getInstance(q);
19737    
19738                                    qPos.add(userId);
19739    
19740                                    qPos.add(classNameId);
19741    
19742                                    qPos.add(classPK);
19743    
19744                                    qPos.add(status);
19745    
19746                                    count = (Long)q.uniqueResult();
19747    
19748                                    FinderCacheUtil.putResult(finderPath, finderArgs, count);
19749                            }
19750                            catch (Exception e) {
19751                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
19752    
19753                                    throw processException(e);
19754                            }
19755                            finally {
19756                                    closeSession(session);
19757                            }
19758                    }
19759    
19760                    return count.intValue();
19761            }
19762    
19763            private static final String _FINDER_COLUMN_U_C_C_S_USERID_2 = "mbMessage.userId = ? AND ";
19764            private static final String _FINDER_COLUMN_U_C_C_S_CLASSNAMEID_2 = "mbMessage.classNameId = ? AND ";
19765            private static final String _FINDER_COLUMN_U_C_C_S_CLASSPK_2 = "mbMessage.classPK = ? AND ";
19766            private static final String _FINDER_COLUMN_U_C_C_S_STATUS_2 = "mbMessage.status = ?";
19767    
19768            /**
19769             * Caches the message-boards message in the entity cache if it is enabled.
19770             *
19771             * @param mbMessage the message-boards message
19772             */
19773            public void cacheResult(MBMessage mbMessage) {
19774                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19775                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
19776    
19777                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G,
19778                            new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() },
19779                            mbMessage);
19780    
19781                    mbMessage.resetOriginalValues();
19782            }
19783    
19784            /**
19785             * Caches the message-boards messages in the entity cache if it is enabled.
19786             *
19787             * @param mbMessages the message-boards messages
19788             */
19789            public void cacheResult(List<MBMessage> mbMessages) {
19790                    for (MBMessage mbMessage : mbMessages) {
19791                            if (EntityCacheUtil.getResult(
19792                                                    MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19793                                                    MBMessageImpl.class, mbMessage.getPrimaryKey()) == null) {
19794                                    cacheResult(mbMessage);
19795                            }
19796                            else {
19797                                    mbMessage.resetOriginalValues();
19798                            }
19799                    }
19800            }
19801    
19802            /**
19803             * Clears the cache for all message-boards messages.
19804             *
19805             * <p>
19806             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
19807             * </p>
19808             */
19809            @Override
19810            public void clearCache() {
19811                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
19812                            CacheRegistryUtil.clear(MBMessageImpl.class.getName());
19813                    }
19814    
19815                    EntityCacheUtil.clearCache(MBMessageImpl.class.getName());
19816    
19817                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
19818                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19819                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19820            }
19821    
19822            /**
19823             * Clears the cache for the message-boards message.
19824             *
19825             * <p>
19826             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
19827             * </p>
19828             */
19829            @Override
19830            public void clearCache(MBMessage mbMessage) {
19831                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19832                            MBMessageImpl.class, mbMessage.getPrimaryKey());
19833    
19834                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19835                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19836    
19837                    clearUniqueFindersCache(mbMessage);
19838            }
19839    
19840            @Override
19841            public void clearCache(List<MBMessage> mbMessages) {
19842                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
19843                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
19844    
19845                    for (MBMessage mbMessage : mbMessages) {
19846                            EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
19847                                    MBMessageImpl.class, mbMessage.getPrimaryKey());
19848    
19849                            clearUniqueFindersCache(mbMessage);
19850                    }
19851            }
19852    
19853            protected void cacheUniqueFindersCache(MBMessage mbMessage) {
19854                    if (mbMessage.isNew()) {
19855                            Object[] args = new Object[] {
19856                                            mbMessage.getUuid(), mbMessage.getGroupId()
19857                                    };
19858    
19859                            FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
19860                                    Long.valueOf(1));
19861                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
19862                                    mbMessage);
19863                    }
19864                    else {
19865                            MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
19866    
19867                            if ((mbMessageModelImpl.getColumnBitmask() &
19868                                            FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
19869                                    Object[] args = new Object[] {
19870                                                    mbMessage.getUuid(), mbMessage.getGroupId()
19871                                            };
19872    
19873                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_UUID_G, args,
19874                                            Long.valueOf(1));
19875                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, args,
19876                                            mbMessage);
19877                            }
19878                    }
19879            }
19880    
19881            protected void clearUniqueFindersCache(MBMessage mbMessage) {
19882                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
19883    
19884                    Object[] args = new Object[] { mbMessage.getUuid(), mbMessage.getGroupId() };
19885    
19886                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
19887                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
19888    
19889                    if ((mbMessageModelImpl.getColumnBitmask() &
19890                                    FINDER_PATH_FETCH_BY_UUID_G.getColumnBitmask()) != 0) {
19891                            args = new Object[] {
19892                                            mbMessageModelImpl.getOriginalUuid(),
19893                                            mbMessageModelImpl.getOriginalGroupId()
19894                                    };
19895    
19896                            FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_G, args);
19897                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, args);
19898                    }
19899            }
19900    
19901            /**
19902             * Creates a new message-boards message with the primary key. Does not add the message-boards message to the database.
19903             *
19904             * @param messageId the primary key for the new message-boards message
19905             * @return the new message-boards message
19906             */
19907            public MBMessage create(long messageId) {
19908                    MBMessage mbMessage = new MBMessageImpl();
19909    
19910                    mbMessage.setNew(true);
19911                    mbMessage.setPrimaryKey(messageId);
19912    
19913                    String uuid = PortalUUIDUtil.generate();
19914    
19915                    mbMessage.setUuid(uuid);
19916    
19917                    return mbMessage;
19918            }
19919    
19920            /**
19921             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19922             *
19923             * @param messageId the primary key of the message-boards message
19924             * @return the message-boards message that was removed
19925             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19926             * @throws SystemException if a system exception occurred
19927             */
19928            public MBMessage remove(long messageId)
19929                    throws NoSuchMessageException, SystemException {
19930                    return remove((Serializable)messageId);
19931            }
19932    
19933            /**
19934             * Removes the message-boards message with the primary key from the database. Also notifies the appropriate model listeners.
19935             *
19936             * @param primaryKey the primary key of the message-boards message
19937             * @return the message-boards message that was removed
19938             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
19939             * @throws SystemException if a system exception occurred
19940             */
19941            @Override
19942            public MBMessage remove(Serializable primaryKey)
19943                    throws NoSuchMessageException, SystemException {
19944                    Session session = null;
19945    
19946                    try {
19947                            session = openSession();
19948    
19949                            MBMessage mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19950                                            primaryKey);
19951    
19952                            if (mbMessage == null) {
19953                                    if (_log.isWarnEnabled()) {
19954                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
19955                                    }
19956    
19957                                    throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
19958                                            primaryKey);
19959                            }
19960    
19961                            return remove(mbMessage);
19962                    }
19963                    catch (NoSuchMessageException nsee) {
19964                            throw nsee;
19965                    }
19966                    catch (Exception e) {
19967                            throw processException(e);
19968                    }
19969                    finally {
19970                            closeSession(session);
19971                    }
19972            }
19973    
19974            @Override
19975            protected MBMessage removeImpl(MBMessage mbMessage)
19976                    throws SystemException {
19977                    mbMessage = toUnwrappedModel(mbMessage);
19978    
19979                    Session session = null;
19980    
19981                    try {
19982                            session = openSession();
19983    
19984                            if (!session.contains(mbMessage)) {
19985                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
19986                                                    mbMessage.getPrimaryKeyObj());
19987                            }
19988    
19989                            if (mbMessage != null) {
19990                                    session.delete(mbMessage);
19991                            }
19992                    }
19993                    catch (Exception e) {
19994                            throw processException(e);
19995                    }
19996                    finally {
19997                            closeSession(session);
19998                    }
19999    
20000                    if (mbMessage != null) {
20001                            clearCache(mbMessage);
20002                    }
20003    
20004                    return mbMessage;
20005            }
20006    
20007            @Override
20008            public MBMessage updateImpl(
20009                    com.liferay.portlet.messageboards.model.MBMessage mbMessage)
20010                    throws SystemException {
20011                    mbMessage = toUnwrappedModel(mbMessage);
20012    
20013                    boolean isNew = mbMessage.isNew();
20014    
20015                    MBMessageModelImpl mbMessageModelImpl = (MBMessageModelImpl)mbMessage;
20016    
20017                    if (Validator.isNull(mbMessage.getUuid())) {
20018                            String uuid = PortalUUIDUtil.generate();
20019    
20020                            mbMessage.setUuid(uuid);
20021                    }
20022    
20023                    long userId = GetterUtil.getLong(PrincipalThreadLocal.getName());
20024    
20025                    if (userId > 0) {
20026                            long companyId = mbMessage.getCompanyId();
20027    
20028                            long groupId = mbMessage.getGroupId();
20029    
20030                            long messageId = 0;
20031    
20032                            if (!isNew) {
20033                                    messageId = mbMessage.getPrimaryKey();
20034                            }
20035    
20036                            try {
20037                                    mbMessage.setSubject(SanitizerUtil.sanitize(companyId, groupId,
20038                                                    userId,
20039                                                    com.liferay.portlet.messageboards.model.MBMessage.class.getName(),
20040                                                    messageId, ContentTypes.TEXT_PLAIN, Sanitizer.MODE_ALL,
20041                                                    mbMessage.getSubject(), null));
20042                            }
20043                            catch (SanitizerException se) {
20044                                    throw new SystemException(se);
20045                            }
20046                    }
20047    
20048                    Session session = null;
20049    
20050                    try {
20051                            session = openSession();
20052    
20053                            if (mbMessage.isNew()) {
20054                                    session.save(mbMessage);
20055    
20056                                    mbMessage.setNew(false);
20057                            }
20058                            else {
20059                                    session.merge(mbMessage);
20060                            }
20061                    }
20062                    catch (Exception e) {
20063                            throw processException(e);
20064                    }
20065                    finally {
20066                            closeSession(session);
20067                    }
20068    
20069                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
20070    
20071                    if (isNew || !MBMessageModelImpl.COLUMN_BITMASK_ENABLED) {
20072                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
20073                    }
20074    
20075                    else {
20076                            if ((mbMessageModelImpl.getColumnBitmask() &
20077                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID.getColumnBitmask()) != 0) {
20078                                    Object[] args = new Object[] {
20079                                                    mbMessageModelImpl.getOriginalUuid()
20080                                            };
20081    
20082                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
20083                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
20084                                            args);
20085    
20086                                    args = new Object[] { mbMessageModelImpl.getUuid() };
20087    
20088                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID, args);
20089                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID,
20090                                            args);
20091                            }
20092    
20093                            if ((mbMessageModelImpl.getColumnBitmask() &
20094                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C.getColumnBitmask()) != 0) {
20095                                    Object[] args = new Object[] {
20096                                                    mbMessageModelImpl.getOriginalUuid(),
20097                                                    mbMessageModelImpl.getOriginalCompanyId()
20098                                            };
20099    
20100                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
20101                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
20102                                            args);
20103    
20104                                    args = new Object[] {
20105                                                    mbMessageModelImpl.getUuid(),
20106                                                    mbMessageModelImpl.getCompanyId()
20107                                            };
20108    
20109                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_UUID_C, args);
20110                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_UUID_C,
20111                                            args);
20112                            }
20113    
20114                            if ((mbMessageModelImpl.getColumnBitmask() &
20115                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID.getColumnBitmask()) != 0) {
20116                                    Object[] args = new Object[] {
20117                                                    mbMessageModelImpl.getOriginalGroupId()
20118                                            };
20119    
20120                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
20121                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
20122                                            args);
20123    
20124                                    args = new Object[] { mbMessageModelImpl.getGroupId() };
20125    
20126                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_GROUPID, args);
20127                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_GROUPID,
20128                                            args);
20129                            }
20130    
20131                            if ((mbMessageModelImpl.getColumnBitmask() &
20132                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID.getColumnBitmask()) != 0) {
20133                                    Object[] args = new Object[] {
20134                                                    mbMessageModelImpl.getOriginalCompanyId()
20135                                            };
20136    
20137                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
20138                                            args);
20139                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
20140                                            args);
20141    
20142                                    args = new Object[] { mbMessageModelImpl.getCompanyId() };
20143    
20144                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_COMPANYID,
20145                                            args);
20146                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_COMPANYID,
20147                                            args);
20148                            }
20149    
20150                            if ((mbMessageModelImpl.getColumnBitmask() &
20151                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID.getColumnBitmask()) != 0) {
20152                                    Object[] args = new Object[] {
20153                                                    mbMessageModelImpl.getOriginalThreadId()
20154                                            };
20155    
20156                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
20157                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
20158                                            args);
20159    
20160                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
20161    
20162                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADID, args);
20163                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADID,
20164                                            args);
20165                            }
20166    
20167                            if ((mbMessageModelImpl.getColumnBitmask() &
20168                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES.getColumnBitmask()) != 0) {
20169                                    Object[] args = new Object[] {
20170                                                    mbMessageModelImpl.getOriginalThreadId()
20171                                            };
20172    
20173                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
20174                                            args);
20175                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
20176                                            args);
20177    
20178                                    args = new Object[] { mbMessageModelImpl.getThreadId() };
20179    
20180                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_THREADREPLIES,
20181                                            args);
20182                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_THREADREPLIES,
20183                                            args);
20184                            }
20185    
20186                            if ((mbMessageModelImpl.getColumnBitmask() &
20187                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID.getColumnBitmask()) != 0) {
20188                                    Object[] args = new Object[] {
20189                                                    mbMessageModelImpl.getOriginalUserId()
20190                                            };
20191    
20192                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
20193                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
20194                                            args);
20195    
20196                                    args = new Object[] { mbMessageModelImpl.getUserId() };
20197    
20198                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_USERID, args);
20199                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_USERID,
20200                                            args);
20201                            }
20202    
20203                            if ((mbMessageModelImpl.getColumnBitmask() &
20204                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U.getColumnBitmask()) != 0) {
20205                                    Object[] args = new Object[] {
20206                                                    mbMessageModelImpl.getOriginalGroupId(),
20207                                                    mbMessageModelImpl.getOriginalUserId()
20208                                            };
20209    
20210                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
20211                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
20212                                            args);
20213    
20214                                    args = new Object[] {
20215                                                    mbMessageModelImpl.getGroupId(),
20216                                                    mbMessageModelImpl.getUserId()
20217                                            };
20218    
20219                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U, args);
20220                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U,
20221                                            args);
20222                            }
20223    
20224                            if ((mbMessageModelImpl.getColumnBitmask() &
20225                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C.getColumnBitmask()) != 0) {
20226                                    Object[] args = new Object[] {
20227                                                    mbMessageModelImpl.getOriginalGroupId(),
20228                                                    mbMessageModelImpl.getOriginalCategoryId()
20229                                            };
20230    
20231                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
20232                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
20233                                            args);
20234    
20235                                    args = new Object[] {
20236                                                    mbMessageModelImpl.getGroupId(),
20237                                                    mbMessageModelImpl.getCategoryId()
20238                                            };
20239    
20240                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C, args);
20241                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C,
20242                                            args);
20243                            }
20244    
20245                            if ((mbMessageModelImpl.getColumnBitmask() &
20246                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S.getColumnBitmask()) != 0) {
20247                                    Object[] args = new Object[] {
20248                                                    mbMessageModelImpl.getOriginalGroupId(),
20249                                                    mbMessageModelImpl.getOriginalStatus()
20250                                            };
20251    
20252                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
20253                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
20254                                            args);
20255    
20256                                    args = new Object[] {
20257                                                    mbMessageModelImpl.getGroupId(),
20258                                                    mbMessageModelImpl.getStatus()
20259                                            };
20260    
20261                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_S, args);
20262                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_S,
20263                                            args);
20264                            }
20265    
20266                            if ((mbMessageModelImpl.getColumnBitmask() &
20267                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S.getColumnBitmask()) != 0) {
20268                                    Object[] args = new Object[] {
20269                                                    mbMessageModelImpl.getOriginalCompanyId(),
20270                                                    mbMessageModelImpl.getOriginalStatus()
20271                                            };
20272    
20273                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
20274                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
20275                                            args);
20276    
20277                                    args = new Object[] {
20278                                                    mbMessageModelImpl.getCompanyId(),
20279                                                    mbMessageModelImpl.getStatus()
20280                                            };
20281    
20282                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_S, args);
20283                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_S,
20284                                            args);
20285                            }
20286    
20287                            if ((mbMessageModelImpl.getColumnBitmask() &
20288                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C.getColumnBitmask()) != 0) {
20289                                    Object[] args = new Object[] {
20290                                                    mbMessageModelImpl.getOriginalUserId(),
20291                                                    mbMessageModelImpl.getOriginalClassNameId()
20292                                            };
20293    
20294                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
20295                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
20296                                            args);
20297    
20298                                    args = new Object[] {
20299                                                    mbMessageModelImpl.getUserId(),
20300                                                    mbMessageModelImpl.getClassNameId()
20301                                            };
20302    
20303                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C, args);
20304                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C,
20305                                            args);
20306                            }
20307    
20308                            if ((mbMessageModelImpl.getColumnBitmask() &
20309                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
20310                                    Object[] args = new Object[] {
20311                                                    mbMessageModelImpl.getOriginalClassNameId(),
20312                                                    mbMessageModelImpl.getOriginalClassPK()
20313                                            };
20314    
20315                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
20316                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
20317                                            args);
20318    
20319                                    args = new Object[] {
20320                                                    mbMessageModelImpl.getClassNameId(),
20321                                                    mbMessageModelImpl.getClassPK()
20322                                            };
20323    
20324                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
20325                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
20326                                            args);
20327                            }
20328    
20329                            if ((mbMessageModelImpl.getColumnBitmask() &
20330                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P.getColumnBitmask()) != 0) {
20331                                    Object[] args = new Object[] {
20332                                                    mbMessageModelImpl.getOriginalThreadId(),
20333                                                    mbMessageModelImpl.getOriginalParentMessageId()
20334                                            };
20335    
20336                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
20337                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
20338                                            args);
20339    
20340                                    args = new Object[] {
20341                                                    mbMessageModelImpl.getThreadId(),
20342                                                    mbMessageModelImpl.getParentMessageId()
20343                                            };
20344    
20345                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_P, args);
20346                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_P,
20347                                            args);
20348                            }
20349    
20350                            if ((mbMessageModelImpl.getColumnBitmask() &
20351                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A.getColumnBitmask()) != 0) {
20352                                    Object[] args = new Object[] {
20353                                                    mbMessageModelImpl.getOriginalThreadId(),
20354                                                    mbMessageModelImpl.getOriginalAnswer()
20355                                            };
20356    
20357                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
20358                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
20359                                            args);
20360    
20361                                    args = new Object[] {
20362                                                    mbMessageModelImpl.getThreadId(),
20363                                                    mbMessageModelImpl.getAnswer()
20364                                            };
20365    
20366                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_A, args);
20367                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_A,
20368                                            args);
20369                            }
20370    
20371                            if ((mbMessageModelImpl.getColumnBitmask() &
20372                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S.getColumnBitmask()) != 0) {
20373                                    Object[] args = new Object[] {
20374                                                    mbMessageModelImpl.getOriginalThreadId(),
20375                                                    mbMessageModelImpl.getOriginalStatus()
20376                                            };
20377    
20378                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
20379                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
20380                                            args);
20381    
20382                                    args = new Object[] {
20383                                                    mbMessageModelImpl.getThreadId(),
20384                                                    mbMessageModelImpl.getStatus()
20385                                            };
20386    
20387                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_T_S, args);
20388                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_S,
20389                                            args);
20390                            }
20391    
20392                            if ((mbMessageModelImpl.getColumnBitmask() &
20393                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S.getColumnBitmask()) != 0) {
20394                                    Object[] args = new Object[] {
20395                                                    mbMessageModelImpl.getOriginalThreadId(),
20396                                                    mbMessageModelImpl.getOriginalStatus()
20397                                            };
20398    
20399                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
20400                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
20401                                            args);
20402    
20403                                    args = new Object[] {
20404                                                    mbMessageModelImpl.getThreadId(),
20405                                                    mbMessageModelImpl.getStatus()
20406                                            };
20407    
20408                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_TR_S, args);
20409                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TR_S,
20410                                            args);
20411                            }
20412    
20413                            if ((mbMessageModelImpl.getColumnBitmask() &
20414                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S.getColumnBitmask()) != 0) {
20415                                    Object[] args = new Object[] {
20416                                                    mbMessageModelImpl.getOriginalGroupId(),
20417                                                    mbMessageModelImpl.getOriginalUserId(),
20418                                                    mbMessageModelImpl.getOriginalStatus()
20419                                            };
20420    
20421                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
20422                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
20423                                            args);
20424    
20425                                    args = new Object[] {
20426                                                    mbMessageModelImpl.getGroupId(),
20427                                                    mbMessageModelImpl.getUserId(),
20428                                                    mbMessageModelImpl.getStatus()
20429                                            };
20430    
20431                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_S, args);
20432                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_S,
20433                                            args);
20434                            }
20435    
20436                            if ((mbMessageModelImpl.getColumnBitmask() &
20437                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T.getColumnBitmask()) != 0) {
20438                                    Object[] args = new Object[] {
20439                                                    mbMessageModelImpl.getOriginalGroupId(),
20440                                                    mbMessageModelImpl.getOriginalCategoryId(),
20441                                                    mbMessageModelImpl.getOriginalThreadId()
20442                                            };
20443    
20444                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
20445                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
20446                                            args);
20447    
20448                                    args = new Object[] {
20449                                                    mbMessageModelImpl.getGroupId(),
20450                                                    mbMessageModelImpl.getCategoryId(),
20451                                                    mbMessageModelImpl.getThreadId()
20452                                            };
20453    
20454                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T, args);
20455                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T,
20456                                            args);
20457                            }
20458    
20459                            if ((mbMessageModelImpl.getColumnBitmask() &
20460                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S.getColumnBitmask()) != 0) {
20461                                    Object[] args = new Object[] {
20462                                                    mbMessageModelImpl.getOriginalGroupId(),
20463                                                    mbMessageModelImpl.getOriginalCategoryId(),
20464                                                    mbMessageModelImpl.getOriginalStatus()
20465                                            };
20466    
20467                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
20468                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
20469                                            args);
20470    
20471                                    args = new Object[] {
20472                                                    mbMessageModelImpl.getGroupId(),
20473                                                    mbMessageModelImpl.getCategoryId(),
20474                                                    mbMessageModelImpl.getStatus()
20475                                            };
20476    
20477                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_S, args);
20478                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_S,
20479                                            args);
20480                            }
20481    
20482                            if ((mbMessageModelImpl.getColumnBitmask() &
20483                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C.getColumnBitmask()) != 0) {
20484                                    Object[] args = new Object[] {
20485                                                    mbMessageModelImpl.getOriginalUserId(),
20486                                                    mbMessageModelImpl.getOriginalClassNameId(),
20487                                                    mbMessageModelImpl.getOriginalClassPK()
20488                                            };
20489    
20490                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
20491                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
20492                                            args);
20493    
20494                                    args = new Object[] {
20495                                                    mbMessageModelImpl.getUserId(),
20496                                                    mbMessageModelImpl.getClassNameId(),
20497                                                    mbMessageModelImpl.getClassPK()
20498                                            };
20499    
20500                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C, args);
20501                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C,
20502                                            args);
20503                            }
20504    
20505                            if ((mbMessageModelImpl.getColumnBitmask() &
20506                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S.getColumnBitmask()) != 0) {
20507                                    Object[] args = new Object[] {
20508                                                    mbMessageModelImpl.getOriginalUserId(),
20509                                                    mbMessageModelImpl.getOriginalClassNameId(),
20510                                                    mbMessageModelImpl.getOriginalStatus()
20511                                            };
20512    
20513                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
20514                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
20515                                            args);
20516    
20517                                    args = new Object[] {
20518                                                    mbMessageModelImpl.getUserId(),
20519                                                    mbMessageModelImpl.getClassNameId(),
20520                                                    mbMessageModelImpl.getStatus()
20521                                            };
20522    
20523                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_S, args);
20524                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_S,
20525                                            args);
20526                            }
20527    
20528                            if ((mbMessageModelImpl.getColumnBitmask() &
20529                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S.getColumnBitmask()) != 0) {
20530                                    Object[] args = new Object[] {
20531                                                    mbMessageModelImpl.getOriginalClassNameId(),
20532                                                    mbMessageModelImpl.getOriginalClassPK(),
20533                                                    mbMessageModelImpl.getOriginalStatus()
20534                                            };
20535    
20536                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
20537                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
20538                                            args);
20539    
20540                                    args = new Object[] {
20541                                                    mbMessageModelImpl.getClassNameId(),
20542                                                    mbMessageModelImpl.getClassPK(),
20543                                                    mbMessageModelImpl.getStatus()
20544                                            };
20545    
20546                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_S, args);
20547                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C_S,
20548                                            args);
20549                            }
20550    
20551                            if ((mbMessageModelImpl.getColumnBitmask() &
20552                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_S.getColumnBitmask()) != 0) {
20553                                    Object[] args = new Object[] {
20554                                                    mbMessageModelImpl.getOriginalGroupId(),
20555                                                    mbMessageModelImpl.getOriginalUserId(),
20556                                                    mbMessageModelImpl.getOriginalCategoryId(),
20557                                                    mbMessageModelImpl.getOriginalStatus()
20558                                            };
20559    
20560                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_S, args);
20561                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_S,
20562                                            args);
20563    
20564                                    args = new Object[] {
20565                                                    mbMessageModelImpl.getGroupId(),
20566                                                    mbMessageModelImpl.getUserId(),
20567                                                    mbMessageModelImpl.getCategoryId(),
20568                                                    mbMessageModelImpl.getStatus()
20569                                            };
20570    
20571                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_U_C_S, args);
20572                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_U_C_S,
20573                                            args);
20574                            }
20575    
20576                            if ((mbMessageModelImpl.getColumnBitmask() &
20577                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A.getColumnBitmask()) != 0) {
20578                                    Object[] args = new Object[] {
20579                                                    mbMessageModelImpl.getOriginalGroupId(),
20580                                                    mbMessageModelImpl.getOriginalCategoryId(),
20581                                                    mbMessageModelImpl.getOriginalThreadId(),
20582                                                    mbMessageModelImpl.getOriginalAnswer()
20583                                            };
20584    
20585                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
20586                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
20587                                            args);
20588    
20589                                    args = new Object[] {
20590                                                    mbMessageModelImpl.getGroupId(),
20591                                                    mbMessageModelImpl.getCategoryId(),
20592                                                    mbMessageModelImpl.getThreadId(),
20593                                                    mbMessageModelImpl.getAnswer()
20594                                            };
20595    
20596                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_A, args);
20597                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_A,
20598                                            args);
20599                            }
20600    
20601                            if ((mbMessageModelImpl.getColumnBitmask() &
20602                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S.getColumnBitmask()) != 0) {
20603                                    Object[] args = new Object[] {
20604                                                    mbMessageModelImpl.getOriginalGroupId(),
20605                                                    mbMessageModelImpl.getOriginalCategoryId(),
20606                                                    mbMessageModelImpl.getOriginalThreadId(),
20607                                                    mbMessageModelImpl.getOriginalStatus()
20608                                            };
20609    
20610                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
20611                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
20612                                            args);
20613    
20614                                    args = new Object[] {
20615                                                    mbMessageModelImpl.getGroupId(),
20616                                                    mbMessageModelImpl.getCategoryId(),
20617                                                    mbMessageModelImpl.getThreadId(),
20618                                                    mbMessageModelImpl.getStatus()
20619                                            };
20620    
20621                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_G_C_T_S, args);
20622                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_G_C_T_S,
20623                                            args);
20624                            }
20625    
20626                            if ((mbMessageModelImpl.getColumnBitmask() &
20627                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S.getColumnBitmask()) != 0) {
20628                                    Object[] args = new Object[] {
20629                                                    mbMessageModelImpl.getOriginalUserId(),
20630                                                    mbMessageModelImpl.getOriginalClassNameId(),
20631                                                    mbMessageModelImpl.getOriginalClassPK(),
20632                                                    mbMessageModelImpl.getOriginalStatus()
20633                                            };
20634    
20635                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
20636                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
20637                                            args);
20638    
20639                                    args = new Object[] {
20640                                                    mbMessageModelImpl.getUserId(),
20641                                                    mbMessageModelImpl.getClassNameId(),
20642                                                    mbMessageModelImpl.getClassPK(),
20643                                                    mbMessageModelImpl.getStatus()
20644                                            };
20645    
20646                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_U_C_C_S, args);
20647                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_U_C_C_S,
20648                                            args);
20649                            }
20650                    }
20651    
20652                    EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20653                            MBMessageImpl.class, mbMessage.getPrimaryKey(), mbMessage);
20654    
20655                    clearUniqueFindersCache(mbMessage);
20656                    cacheUniqueFindersCache(mbMessage);
20657    
20658                    return mbMessage;
20659            }
20660    
20661            protected MBMessage toUnwrappedModel(MBMessage mbMessage) {
20662                    if (mbMessage instanceof MBMessageImpl) {
20663                            return mbMessage;
20664                    }
20665    
20666                    MBMessageImpl mbMessageImpl = new MBMessageImpl();
20667    
20668                    mbMessageImpl.setNew(mbMessage.isNew());
20669                    mbMessageImpl.setPrimaryKey(mbMessage.getPrimaryKey());
20670    
20671                    mbMessageImpl.setUuid(mbMessage.getUuid());
20672                    mbMessageImpl.setMessageId(mbMessage.getMessageId());
20673                    mbMessageImpl.setGroupId(mbMessage.getGroupId());
20674                    mbMessageImpl.setCompanyId(mbMessage.getCompanyId());
20675                    mbMessageImpl.setUserId(mbMessage.getUserId());
20676                    mbMessageImpl.setUserName(mbMessage.getUserName());
20677                    mbMessageImpl.setCreateDate(mbMessage.getCreateDate());
20678                    mbMessageImpl.setModifiedDate(mbMessage.getModifiedDate());
20679                    mbMessageImpl.setClassNameId(mbMessage.getClassNameId());
20680                    mbMessageImpl.setClassPK(mbMessage.getClassPK());
20681                    mbMessageImpl.setCategoryId(mbMessage.getCategoryId());
20682                    mbMessageImpl.setThreadId(mbMessage.getThreadId());
20683                    mbMessageImpl.setRootMessageId(mbMessage.getRootMessageId());
20684                    mbMessageImpl.setParentMessageId(mbMessage.getParentMessageId());
20685                    mbMessageImpl.setSubject(mbMessage.getSubject());
20686                    mbMessageImpl.setBody(mbMessage.getBody());
20687                    mbMessageImpl.setFormat(mbMessage.getFormat());
20688                    mbMessageImpl.setAnonymous(mbMessage.isAnonymous());
20689                    mbMessageImpl.setPriority(mbMessage.getPriority());
20690                    mbMessageImpl.setAllowPingbacks(mbMessage.isAllowPingbacks());
20691                    mbMessageImpl.setAnswer(mbMessage.isAnswer());
20692                    mbMessageImpl.setStatus(mbMessage.getStatus());
20693                    mbMessageImpl.setStatusByUserId(mbMessage.getStatusByUserId());
20694                    mbMessageImpl.setStatusByUserName(mbMessage.getStatusByUserName());
20695                    mbMessageImpl.setStatusDate(mbMessage.getStatusDate());
20696    
20697                    return mbMessageImpl;
20698            }
20699    
20700            /**
20701             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
20702             *
20703             * @param primaryKey the primary key of the message-boards message
20704             * @return the message-boards message
20705             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
20706             * @throws SystemException if a system exception occurred
20707             */
20708            @Override
20709            public MBMessage findByPrimaryKey(Serializable primaryKey)
20710                    throws NoSuchMessageException, SystemException {
20711                    MBMessage mbMessage = fetchByPrimaryKey(primaryKey);
20712    
20713                    if (mbMessage == null) {
20714                            if (_log.isWarnEnabled()) {
20715                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
20716                            }
20717    
20718                            throw new NoSuchMessageException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
20719                                    primaryKey);
20720                    }
20721    
20722                    return mbMessage;
20723            }
20724    
20725            /**
20726             * Returns the message-boards message with the primary key or throws a {@link com.liferay.portlet.messageboards.NoSuchMessageException} if it could not be found.
20727             *
20728             * @param messageId the primary key of the message-boards message
20729             * @return the message-boards message
20730             * @throws com.liferay.portlet.messageboards.NoSuchMessageException if a message-boards message with the primary key could not be found
20731             * @throws SystemException if a system exception occurred
20732             */
20733            public MBMessage findByPrimaryKey(long messageId)
20734                    throws NoSuchMessageException, SystemException {
20735                    return findByPrimaryKey((Serializable)messageId);
20736            }
20737    
20738            /**
20739             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
20740             *
20741             * @param primaryKey the primary key of the message-boards message
20742             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
20743             * @throws SystemException if a system exception occurred
20744             */
20745            @Override
20746            public MBMessage fetchByPrimaryKey(Serializable primaryKey)
20747                    throws SystemException {
20748                    MBMessage mbMessage = (MBMessage)EntityCacheUtil.getResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20749                                    MBMessageImpl.class, primaryKey);
20750    
20751                    if (mbMessage == _nullMBMessage) {
20752                            return null;
20753                    }
20754    
20755                    if (mbMessage == null) {
20756                            Session session = null;
20757    
20758                            try {
20759                                    session = openSession();
20760    
20761                                    mbMessage = (MBMessage)session.get(MBMessageImpl.class,
20762                                                    primaryKey);
20763    
20764                                    if (mbMessage != null) {
20765                                            cacheResult(mbMessage);
20766                                    }
20767                                    else {
20768                                            EntityCacheUtil.putResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20769                                                    MBMessageImpl.class, primaryKey, _nullMBMessage);
20770                                    }
20771                            }
20772                            catch (Exception e) {
20773                                    EntityCacheUtil.removeResult(MBMessageModelImpl.ENTITY_CACHE_ENABLED,
20774                                            MBMessageImpl.class, primaryKey);
20775    
20776                                    throw processException(e);
20777                            }
20778                            finally {
20779                                    closeSession(session);
20780                            }
20781                    }
20782    
20783                    return mbMessage;
20784            }
20785    
20786            /**
20787             * Returns the message-boards message with the primary key or returns <code>null</code> if it could not be found.
20788             *
20789             * @param messageId the primary key of the message-boards message
20790             * @return the message-boards message, or <code>null</code> if a message-boards message with the primary key could not be found
20791             * @throws SystemException if a system exception occurred
20792             */
20793            public MBMessage fetchByPrimaryKey(long messageId)
20794                    throws SystemException {
20795                    return fetchByPrimaryKey((Serializable)messageId);
20796            }
20797    
20798            /**
20799             * Returns all the message-boards messages.
20800             *
20801             * @return the message-boards messages
20802             * @throws SystemException if a system exception occurred
20803             */
20804            public List<MBMessage> findAll() throws SystemException {
20805                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
20806            }
20807    
20808            /**
20809             * Returns a range of all the message-boards messages.
20810             *
20811             * <p>
20812             * 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.
20813             * </p>
20814             *
20815             * @param start the lower bound of the range of message-boards messages
20816             * @param end the upper bound of the range of message-boards messages (not inclusive)
20817             * @return the range of message-boards messages
20818             * @throws SystemException if a system exception occurred
20819             */
20820            public List<MBMessage> findAll(int start, int end)
20821                    throws SystemException {
20822                    return findAll(start, end, null);
20823            }
20824    
20825            /**
20826             * Returns an ordered range of all the message-boards messages.
20827             *
20828             * <p>
20829             * 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.
20830             * </p>
20831             *
20832             * @param start the lower bound of the range of message-boards messages
20833             * @param end the upper bound of the range of message-boards messages (not inclusive)
20834             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
20835             * @return the ordered range of message-boards messages
20836             * @throws SystemException if a system exception occurred
20837             */
20838            public List<MBMessage> findAll(int start, int end,
20839                    OrderByComparator orderByComparator) throws SystemException {
20840                    boolean pagination = true;
20841                    FinderPath finderPath = null;
20842                    Object[] finderArgs = null;
20843    
20844                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
20845                                    (orderByComparator == null)) {
20846                            pagination = false;
20847                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
20848                            finderArgs = FINDER_ARGS_EMPTY;
20849                    }
20850                    else {
20851                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
20852                            finderArgs = new Object[] { start, end, orderByComparator };
20853                    }
20854    
20855                    List<MBMessage> list = (List<MBMessage>)FinderCacheUtil.getResult(finderPath,
20856                                    finderArgs, this);
20857    
20858                    if (list == null) {
20859                            StringBundler query = null;
20860                            String sql = null;
20861    
20862                            if (orderByComparator != null) {
20863                                    query = new StringBundler(2 +
20864                                                    (orderByComparator.getOrderByFields().length * 3));
20865    
20866                                    query.append(_SQL_SELECT_MBMESSAGE);
20867    
20868                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
20869                                            orderByComparator);
20870    
20871                                    sql = query.toString();
20872                            }
20873                            else {
20874                                    sql = _SQL_SELECT_MBMESSAGE;
20875    
20876                                    if (pagination) {
20877                                            sql = sql.concat(MBMessageModelImpl.ORDER_BY_JPQL);
20878                                    }
20879                            }
20880    
20881                            Session session = null;
20882    
20883                            try {
20884                                    session = openSession();
20885    
20886                                    Query q = session.createQuery(sql);
20887    
20888                                    if (!pagination) {
20889                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20890                                                            start, end, false);
20891    
20892                                            Collections.sort(list);
20893    
20894                                            list = new UnmodifiableList<MBMessage>(list);
20895                                    }
20896                                    else {
20897                                            list = (List<MBMessage>)QueryUtil.list(q, getDialect(),
20898                                                            start, end);
20899                                    }
20900    
20901                                    cacheResult(list);
20902    
20903                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
20904                            }
20905                            catch (Exception e) {
20906                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
20907    
20908                                    throw processException(e);
20909                            }
20910                            finally {
20911                                    closeSession(session);
20912                            }
20913                    }
20914    
20915                    return list;
20916            }
20917    
20918            /**
20919             * Removes all the message-boards messages from the database.
20920             *
20921             * @throws SystemException if a system exception occurred
20922             */
20923            public void removeAll() throws SystemException {
20924                    for (MBMessage mbMessage : findAll()) {
20925                            remove(mbMessage);
20926                    }
20927            }
20928    
20929            /**
20930             * Returns the number of message-boards messages.
20931             *
20932             * @return the number of message-boards messages
20933             * @throws SystemException if a system exception occurred
20934             */
20935            public int countAll() throws SystemException {
20936                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
20937                                    FINDER_ARGS_EMPTY, this);
20938    
20939                    if (count == null) {
20940                            Session session = null;
20941    
20942                            try {
20943                                    session = openSession();
20944    
20945                                    Query q = session.createQuery(_SQL_COUNT_MBMESSAGE);
20946    
20947                                    count = (Long)q.uniqueResult();
20948    
20949                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
20950                                            FINDER_ARGS_EMPTY, count);
20951                            }
20952                            catch (Exception e) {
20953                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
20954                                            FINDER_ARGS_EMPTY);
20955    
20956                                    throw processException(e);
20957                            }
20958                            finally {
20959                                    closeSession(session);
20960                            }
20961                    }
20962    
20963                    return count.intValue();
20964            }
20965    
20966            @Override
20967            protected Set<String> getBadColumnNames() {
20968                    return _badColumnNames;
20969            }
20970    
20971            /**
20972             * Initializes the message-boards message persistence.
20973             */
20974            public void afterPropertiesSet() {
20975                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
20976                                            com.liferay.portal.util.PropsUtil.get(
20977                                                    "value.object.listener.com.liferay.portlet.messageboards.model.MBMessage")));
20978    
20979                    if (listenerClassNames.length > 0) {
20980                            try {
20981                                    List<ModelListener<MBMessage>> listenersList = new ArrayList<ModelListener<MBMessage>>();
20982    
20983                                    for (String listenerClassName : listenerClassNames) {
20984                                            listenersList.add((ModelListener<MBMessage>)InstanceFactory.newInstance(
20985                                                            getClassLoader(), listenerClassName));
20986                                    }
20987    
20988                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
20989                            }
20990                            catch (Exception e) {
20991                                    _log.error(e);
20992                            }
20993                    }
20994            }
20995    
20996            public void destroy() {
20997                    EntityCacheUtil.removeCache(MBMessageImpl.class.getName());
20998                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
20999                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
21000                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
21001            }
21002    
21003            private static final String _SQL_SELECT_MBMESSAGE = "SELECT mbMessage FROM MBMessage mbMessage";
21004            private static final String _SQL_SELECT_MBMESSAGE_WHERE = "SELECT mbMessage FROM MBMessage mbMessage WHERE ";
21005            private static final String _SQL_COUNT_MBMESSAGE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage";
21006            private static final String _SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(mbMessage) FROM MBMessage mbMessage WHERE ";
21007            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "mbMessage.rootMessageId";
21008            private static final String _FILTER_SQL_SELECT_MBMESSAGE_WHERE = "SELECT DISTINCT {mbMessage.*} FROM MBMessage mbMessage WHERE ";
21009            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_1 =
21010                    "SELECT {MBMessage.*} FROM (SELECT DISTINCT mbMessage.messageId FROM MBMessage mbMessage WHERE ";
21011            private static final String _FILTER_SQL_SELECT_MBMESSAGE_NO_INLINE_DISTINCT_WHERE_2 =
21012                    ") TEMP_TABLE INNER JOIN MBMessage ON TEMP_TABLE.messageId = MBMessage.messageId";
21013            private static final String _FILTER_SQL_COUNT_MBMESSAGE_WHERE = "SELECT COUNT(DISTINCT mbMessage.messageId) AS COUNT_VALUE FROM MBMessage mbMessage WHERE ";
21014            private static final String _FILTER_ENTITY_ALIAS = "mbMessage";
21015            private static final String _FILTER_ENTITY_TABLE = "MBMessage";
21016            private static final String _ORDER_BY_ENTITY_ALIAS = "mbMessage.";
21017            private static final String _ORDER_BY_ENTITY_TABLE = "MBMessage.";
21018            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No MBMessage exists with the primary key ";
21019            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No MBMessage exists with the key {";
21020            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
21021            private static Log _log = LogFactoryUtil.getLog(MBMessagePersistenceImpl.class);
21022            private static Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
21023                                    "uuid"
21024                            });
21025            private static MBMessage _nullMBMessage = new MBMessageImpl() {
21026                            @Override
21027                            public Object clone() {
21028                                    return this;
21029                            }
21030    
21031                            @Override
21032                            public CacheModel<MBMessage> toCacheModel() {
21033                                    return _nullMBMessageCacheModel;
21034                            }
21035                    };
21036    
21037            private static CacheModel<MBMessage> _nullMBMessageCacheModel = new CacheModel<MBMessage>() {
21038                            public MBMessage toEntityModel() {
21039                                    return _nullMBMessage;
21040                            }
21041                    };
21042    }